Skip to content

feat(mothership): request ids#3645

Merged
icecrasher321 merged 5 commits intostagingfrom
feat/mothership-rid
Mar 18, 2026
Merged

feat(mothership): request ids#3645
icecrasher321 merged 5 commits intostagingfrom
feat/mothership-rid

Conversation

@Sg312
Copy link
Collaborator

@Sg312 Sg312 commented Mar 18, 2026

Summary

Way to get request ids for copilot/mothership chats.

Type of Change

  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Mar 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 18, 2026 1:21am

Request Review

@icecrasher321 icecrasher321 changed the title [WIP] Feat/mothership rid feat(mothership): request ids Mar 18, 2026
@icecrasher321 icecrasher321 marked this pull request as ready for review March 18, 2026 01:09
@cursor
Copy link

cursor bot commented Mar 18, 2026

PR Summary

Medium Risk
Introduces a new request_id SSE event and threads requestId through orchestrator results, client streaming state, and persisted message schemas; regressions could break streaming updates or stored message compatibility if any producer/consumer misses the new field.

Overview
Adds end-to-end support for Copilot/Mothership request IDs: the orchestrator now captures a request_id SSE event into streaming context and returns it on OrchestratorResult, and the Mothership chat API persists requestId on assistant messages.

Extends message types/storage (ChatMessage, TaskStoredMessage, CopilotMessage, streaming contexts) to carry requestId, updates both Mothership use-chat and Copilot client-SSE handlers to apply it during streaming, and adds a MessageActions dropdown on assistant messages to copy the message text or the requestId.

Written by Cursor Bugbot for commit d748eef. Configure here.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 18, 2026

Greptile Summary

This PR adds requestId tracking for copilot and mothership chat messages, enabling users to copy the upstream request ID directly from the UI via a new "More options" () button on assistant messages.

Key changes:

  • New MessageActions component (home/components/message-actions/) — dropdown that exposes "Copy Message" and "Copy Request ID" actions for any assistant message.
  • SSE pipeline — a new request_id event type is handled at every layer: the orchestrator server handler, the client-side SSE handler (copilot store), and the use-chat hook (home/mothership stream). The ID is stored on the streaming context and propagated to the final persisted message.
  • Type updatesrequestId?: string added to ChatMessage, CopilotMessage, TaskStoredMessage, StreamingContext, and OrchestratorResult.
  • RenderingMessageActions is rendered in both home.tsx (mothership chat) and copilot-message.tsx (workflow copilot panel) once streaming is complete.

One functional inconsistency was found in the copilot panel rendering, and the shared component's placement under the home/ feature directory creates a cross-feature dependency that conflicts with the project's feature-isolation architecture.

Confidence Score: 3/5

  • Safe to merge after fixing the block-only message visibility gap in the copilot panel; the cross-feature import is an architectural debt worth addressing soon.
  • The SSE pipeline changes are well-structured and consistent across all layers. The main risk is a functional gap in copilot-message.tsx where the MessageActions button is invisible for messages composed only of content blocks (tool calls, thinking), meaning the "Copy Request ID" feature doesn't work for that class of messages in the copilot panel. Additionally, MessageActions is placed under the home/ feature but imported cross-feature into copilot/, creating architectural coupling that could become harder to manage over time.
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-message/copilot-message.tsx — both the cross-feature import and the incomplete visibility guard are here.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-message/copilot-message.tsx Adds MessageActions button to assistant messages, but the visibility guard only checks message.content (missing block-only messages), and the import crosses feature boundaries from home/ into copilot/.
apps/sim/app/workspace/[workspaceId]/home/components/message-actions/message-actions.tsx New shared component for copying message text and request IDs via a dropdown. Clean implementation with proper cleanup of timeouts and accessible aria labels.
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Adds request_id SSE event handling that stores the ID in a local variable and calls flush() to propagate it into the streaming message state.
apps/sim/lib/copilot/client-sse/handlers.ts Adds request_id SSE handler that stores the ID on the streaming context; propagates it through flushStreamingUpdates and updateStreamingMessage using ?? to preserve existing values.
apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts Adds server-side request_id SSE handler that writes the ID to the orchestrator's streaming context for later inclusion in the result.
apps/sim/app/api/mothership/chat/route.ts Spreads requestId from the orchestrator result onto the persisted assistant message using a conditional spread, cleanly avoiding an undefined key.
apps/sim/stores/panel/copilot/store.ts Initialises requestId: undefined in the streaming context factory and applies it to the final message on stream completion via ?? fallback.
apps/sim/hooks/queries/tasks.ts Adds optional requestId field to TaskStoredMessage so it can survive persistence and hydration.

Sequence Diagram

sequenceDiagram
    participant Client
    participant MothershipAPI as /api/mothership/chat
    participant Orchestrator
    participant UpstreamSSE as Upstream SSE (copilot/mothership)

    Client->>MothershipAPI: POST chat message
    MothershipAPI->>Orchestrator: orchestrateCopilotStream()
    Orchestrator->>UpstreamSSE: open SSE stream

    UpstreamSSE-->>Orchestrator: event: request_id (data: "<rid>")
    Note over Orchestrator: context.requestId = rid

    UpstreamSSE-->>Orchestrator: event: content (chunks...)
    UpstreamSSE-->>Orchestrator: event: done

    Orchestrator-->>MothershipAPI: OrchestratorResult { requestId, content, ... }
    MothershipAPI-->>Client: SSE stream (re-emits request_id, content events)

    Note over Client: use-chat / copilot store<br/>handle request_id event → store on context
    Note over Client: flush() / updateStreamingMessage()<br/>propagate requestId to message state
    Note over Client: MessageActions renders<br/>Copy Request ID option
Loading

Last reviewed commit: "fix ui"

@icecrasher321
Copy link
Collaborator

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@icecrasher321 icecrasher321 merged commit 168cd58 into staging Mar 18, 2026
12 checks passed
@icecrasher321 icecrasher321 deleted the feat/mothership-rid branch March 18, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants