Skip to content

fix(chat): Yield paused work after request deadline - #1381

Merged
dcramer merged 4 commits into
mainfrom
fix/timeout-continue-fresh-request
Aug 10, 2026
Merged

dcramer merged 4 commits into
mainfrom
fix/timeout-continue-fresh-request

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Fix JUNIOR-7X without changing the turn progress rule.

A worker can resume paused work under the same lease while the host request has time left. When the host request deadline is spent, the worker now yields before another resume. The next queue wake gets a fresh request deadline.

The same-boundary no-progress check remains unchanged.

The durable queue integration test now runs the production agent runtime, resume logic, checkpoint, worker, lease, mailbox, and queue routing. It fakes only model generation at the executeAgentRun stream boundary and Slack I/O at the adapter boundary. The task-execution README records this rule.

Requested by David Cramer.

--

View Junior Session [Sentry]

A timeout pause can mark conversation execution paused under the current
lease while the host request deadline is already spent. Resuming that turn
in the same worker loop reused the dead deadline and failed later slices
with no-progress even after the boundary advanced once.

Always yield the lease when execution is paused after a run so the next
slice starts from a fresh queue wake and request deadline. Keep the
same-boundary no-progress fail-safe. Cover both paths in durable-queue
integration tests.

Refs JUNIOR-7X

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

vercel Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview Aug 10, 2026 5:47pm

Request Review

@sentry-junior sentry-junior Bot changed the title fix(chat): Leave host request after timeout pause fix(chat): Yield paused work after request deadline Aug 10, 2026
@dcramer
dcramer marked this pull request as ready for review August 10, 2026 17:47
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Aug 10, 2026
@dcramer
dcramer merged commit 9a2433a into main Aug 10, 2026
46 checks passed
@dcramer
dcramer deleted the fix/timeout-continue-fresh-request branch August 10, 2026 18:07
sentry-junior Bot added a commit that referenced this pull request Aug 10, 2026
BYK added a commit that referenced this pull request Nov 7, 2026
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 (#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.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3Aa59eb1d03b0a1ee74e1524f22301a86e -->

--

[View Session in
Sentry](https://sentry.sentry.io/explore/conversations/agent%3Aa59eb1d03b0a1ee74e1524f22301a86e/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>

This branch was successfully deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant