Repository navigation
fix(agent-invocations): Tell the parent when a child's work stops after its tries run out - #2627
Merged
Merged
Conversation
…er its tries run out Co-Authored-By: David Cramer <[email protected]>
…rsation work harness Co-Authored-By: David Cramer <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…opped-work cleanup
Contributor
|
6 screenshot changes — 6 changed · 0 added · 0 removed Review screenshots in Frameshift |
dcramer
reviewed
Nov 3, 2026
dcramer
left a comment
Member
There was a problem hiding this comment.
im a little worried we have over engineered this and we're including yet again a bunch more jargon, another branch of execution, etc
Run the cleanup before the heartbeat stops the work, so the existing expired-lease retry covers a failed cleanup. This removes the failed-status branch, which never ran because stopped work leaves the active index. End every unfinished invocation of the child with one message, and reuse one status-filtered invocation query instead of adding a second one.
Run beforeWorkStops inside clearExpiredConversationLease, after it confirms the lease expired. A late worker check-in now waits for the lock and then finds no lease, so it cannot keep running after its invocations end. This also removes the retry-count check that the heartbeat copied.
This comment has been minimized.
This comment has been minimized.
dcramer
approved these changes
Nov 3, 2026
…stopped-work Co-Authored-By: David Cramer <[email protected]>
…rt again A pending invocation whose input has not reached the child's mailbox is appended after the stop, and that append starts new work for the child. Failing it told the parent the task failed instead of running it. Co-Authored-By: David Cramer <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f11dcbc. Configure here.
…mailbox The enqueue writes the child's mailbox before it marks the invocation appended. A stop between those writes dropped input that the mailbox already recorded, so the later append was a duplicate and the invocation stayed open. The cleanup now reads the recorded message ids under the stop's lock and ends every invocation whose input reached the mailbox.
This was referenced Nov 12, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

A child worker that is killed (function timeout, OOM, deploy) never runs its own failure path. Only the heartbeat sees the expired lease. After
CONVERSATION_WORK_MAX_RETRIESexpired leases,recoverConversationWorkmarks the child's workfailedand only logsconversation.work.retry.exhausted. The agent invocation staysrunningorpaused, so the parent never gets a result. The open invocation also makes later results from that childreplaceduntil new work reaches the child (#2558).Fix
recoverConversationWorktakes anonWorkStoppedcallback. It calls it when the tries run out, and again on each later heartbeat while the work staysfailed. The conversation leaves the recovery scan only after the callback succeeds.task-executionstays unaware of agent invocations.runHeartbeatpassesendAgentInvocationsOfStoppedWork. It ends each running or paused invocation of that child the same wayendOtherActiveAgentInvocationdoes: a running Turn fails with "lost its worker", and a paused Turn is abandoned with a failed result. Stopped work drops its mailbox, so apendinginvocation whose input was already appended also fails ("This task did not start"). Apendinginvocation whose append has not run yet is left alone, because that append starts the work again. All results usereportNow, so none isreplaced.Injected faults
Until now, tests of a dead worker wrote by hand the state a dead worker leaves (store calls,
startConversationWorkwith no release, hand-built checkpoints). That tests the heartbeat against a guessed state, not against what the worker leaves.createConversationWorkHarness().killWorker(message)runs the production worker and kills it when the agent runner starts. The run never returns, and the worker keeps its lease. With fakesetInterval, the dead worker never checks in.runHeartbeatAfterLeasesExpire(queue)moves the clock past the lease TTL and runs the productionrunHeartbeat. A test that calls onlyrecoverConversationWorkmisses this bug, because the result is sent in a later heartbeat phase.policies/testing.mdgets an "Injected faults" section: inject at the production edge, use a named harness fault, mark it withInjected fault:, and write failure state by hand only when no harness fault can cause it.agent-invocation-worker-crash.test.tskills every try of a child and runs the heartbeat after each one. On the last try the parent sends the child a follow-up task. The test checks that the parent gets a failed result for both. It fails onmainand passes with the fix.Not moved yet
The "worker dies mid-run" cases in
durable-queue.test.tsand the lost-resume case inagent-dispatch-work.test.tskill the worker after a tool result is saved.killWorkercannot reach that point yet, so those tests still write their state by hand. They can move onto the harness when it gets a kill point after a save. Thepausedcase of #2558's leftover-invocation test needs the same kill point.--
View Session [Sentry]