Skip to content

fix(agent-invocations): Resume child runs that lose their worker - #2886

Merged
BYK merged 1 commit into
mainfrom
fix/agent-invocation-lost-worker-resume
Nov 7, 2026
Merged

BYK merged 1 commit into
mainfrom
fix/agent-invocation-lost-worker-resume

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

A child agent run can fail with Agent invocation lost its worker before it could pause, and the parent then has to start the task over.

Cause. On 2026-11-07, a worker took a second child invocation 703s into its request (trace cd517dd5433d4a39be16732422c2f5c0). The soft yield was not due yet. The child Turn deadline is turnTimeoutMs from the Turn start, and nothing caps it at the host request deadline. So the run kept going until Vercel killed the function at maxDuration (800s). The last span is 799s after the first one. The lease expired, and on the next wake projectTerminalTurn found the Turn still running and failed it. Root Slack Turns and automations resume once from their last save in this case (#2298). Child invocations did not.

The deploy at about 16:00 UTC was not the trigger. The killed request ran on the old release until 16:08:51. Sentry shows about 26 child traces in 14 days that were cut off at 795–800s with no queue.process span. They happen throughout the day, not at deploy times.

Fix.

  • Cap the child Turn deadline at the worker's host request deadline (getTurnRequestDeadline()), as Slack Turns do (fix(chat): Yield paused work after request deadline #1381). The Turn then times out and parks before the host kills the request.
  • When the worker dies anyway, the main worker path resumes the Turn once from its last save with pauseLostWorkerTurn, the same helper the root path uses. A second loss before the resumed run saves still fails the invocation and reports the failure to the parent. Stop and supersede paths do not change.
  • Move the lost-worker helpers from paused-turn.ts to checkpoint.ts so both paths can use them.
  • killWorker in the shared harness can now save the run's input before it kills the worker. That gives the integration tests a real running Turn.

Remaining risk. A resumed run can repeat tool work done after the last save. Root Turns have the same limit. Web, event, and dispatch Turns also run without a deadline cap. This PR does not change them.

via @BYK.

--

View Session in Sentry

A child agent run that outlived its host request was killed at Vercel
maxDuration. The next wake found its Turn still running and failed it with
"Agent invocation lost its worker before it could pause".

Cap the child Turn deadline at the worker's host request deadline, as Slack
Turns do, so the Turn pauses before the host ends the request. When a worker
dies anyway, resume the Turn once from its last save, as root Turns do. A
second loss before the resumed run saves still fails the invocation.

Move the lost-worker resume helpers next to the Turn checkpoint writes so
both paths share them.

Co-Authored-By: BYK <[email protected]>
@vercel

vercel Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 7, 2026 4:44pm UTC

Request Review

@BYK
BYK marked this pull request as ready for review November 7, 2026 16:46
@github-actions github-actions Bot added the risk: high PR risk score: high label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

12 screenshot changes — 12 changed · 0 added · 0 removed

Review screenshots in Frameshift

Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Conversation Attachment · Mobile
Conversation Attachment · Mobile
Changed
Conversation Attachment Modal · Desktop
Conversation Attachment Modal · Desktop
Changed
Conversation Attachment Zoom · Desktop
Conversation Attachment Zoom · Desktop
Changed
Conversation Captured Memories Popover · Desktop
Conversation Captured Memories Popover · Desktop
Changed
Conversation Captured Memories Popover · Mobile
Conversation Captured Memories Popover · Mobile
Changed
Show 6 more changed screenshots
Conversation Details Watched Linked Work · Desktop
Conversation Details Watched Linked Work · Desktop
Changed
Conversation Details Watched Linked Work · Mobile
Conversation Details Watched Linked Work · Mobile
Changed
Conversation Long Transcript Touch · Mobile
Conversation Long Transcript Touch · Mobile
Changed
Conversation Recalled Memories Popover · Desktop
Conversation Recalled Memories Popover · Desktop
Changed
Conversation Recalled Memories Popover · Mobile
Conversation Recalled Memories Popover · Mobile
Changed
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

@BYK
BYK merged commit 5187ebf into main Nov 7, 2026
46 checks passed
@BYK
BYK deleted the fix/agent-invocation-lost-worker-resume branch November 7, 2026 17:07

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 700e5c62 Deployed Nov 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant