fix(mothership): async resume and tool result ordering#3735
fix(mothership): async resume and tool result ordering#3735icecrasher321 merged 3 commits intostagingfrom
Conversation
PR SummaryMedium Risk Overview Fixes tool_call/tool_result ordering races by creating placeholder tool state when a Written by Cursor Bugbot for commit 39bc691. Configure here. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThis PR fixes two related async-continuation bugs in the Copilot orchestrator: (1) the resume logic now requires a durable terminal row for all Sim-executed tools before proceeding, and explicitly throws instead of silently dropping continuations it cannot resume; (2) a parallel tool race condition where a Key changes:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Go as Go Backend SSE
participant SL as Stream Loop
participant H as sseHandlers
participant Exec as executeToolAndReport
participant DB as Async Runs DB
Go->>SL: tool_call event
SL->>SL: shouldSkipToolCallEvent = false
SL->>H: dispatch tool_call
H->>Exec: fireToolExecution
Exec->>DB: upsertAsyncToolCall
Exec->>Exec: executeToolServerSide
Exec->>Exec: check terminal state post-exec
Exec->>DB: completeAsyncToolCall
Exec->>Go: markToolComplete
Go->>SL: duplicate tool_result SSE
SL->>SL: shouldSkipToolResultEvent = true, skip
Note over Go,SL: Race condition fix
Go->>SL: tool_result arrives before tool_call
SL->>H: dispatch tool_result
H->>H: ensureTerminalToolCallState
H->>H: set status=success, markToolResultSeen
Go->>SL: tool_call arrives late
SL->>H: dispatch tool_call
H->>H: existing.status not pending, return early
Note over SL,DB: Async resume
SL->>DB: getAsyncToolCall per pending tool
alt terminal durable row found
SL->>DB: claimCompletedAsyncToolCall
SL->>Go: POST /api/tools/resume
Go->>SL: new SSE stream
SL->>DB: markAsyncToolDelivered
else retries exhausted
SL->>SL: throw explicit error
end
Reviews (1): Last reviewed commit: "ensure tool call terminal state" | Re-trigger Greptile |
apps/sim/lib/copilot/orchestrator/sse/handlers/tool-execution.ts
Outdated
Show resolved
Hide resolved
apps/sim/lib/copilot/orchestrator/sse/handlers/tool-execution.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Summary
Async continuation resume now only trusts durable terminal rows for Sim-executed tools, fails explicitly when a continuation cannot be resumed, and closes the parallel tool race where tool_result could arrive before local execution startup and cause incorrect dedupe or double-processing.
Type of Change
Testing
Tested manually
Checklist