Repository navigation
fix(agents): settle aborted runs through after-turn so agent_end fires - #116087
Conversation
509a885 to
f117fc3
Compare
|
Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 5:24 PM ET / 21:24 UTC. ClawSweeper reviewWhat this changesThe PR treats expected abort errors during embedded-run teardown as aborted terminal outcomes, allowing after-turn processing, agent-end hooks, and interrupted-turn experience review to run. Merge readinessKeep this PR open for normal maintainer review. The supplied diff narrowly restores the established settle → after-turn lifecycle for user-aborted embedded runs, and its stated live gateway proof plus focused regressions support the change; the Priority: P1 Review scores
Verification
How this fits togetherAn embedded agent run streams model work, waits for completion-required asynchronous tasks, and then executes after-turn processing that flushes state and emits an agent-end event. Plugins and the experience-review feature consume that event to distinguish normal completion, errors, timeouts, and user interruptions. flowchart LR
A[User stops an agent turn] --> B[Embedded run stream]
B --> C[Async-task settlement]
C --> D[After-turn processing]
D --> E[Agent-end event]
E --> F[Plugin hooks]
E --> G[Experience review]
D --> H[Terminal outcome]
Decision needed
Why: The code change deliberately expands delivery of an existing terminal event to aborted runs; the repository marks this PR for maintainer handling, and the final integration decision depends on current-main behavior beyond the supplied branch diff. Before merge
Agent review detailsSecurityNone. PR surfaceSource +24, Tests +135. Total +159 across 5 files. View PR surface stats
Review metricsNone. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Land the focused lifecycle repair after confirming it rebases cleanly onto current main and the remaining required checks validate the exact head; retain abort precedence so plugins and experience review receive a consistent aborted agent-end event without a synthetic error. Do we have a high-confidence way to reproduce the issue? Yes, at source level: an abort thrown from prompt release or completion-required task settlement bypasses after-turn in the reported pre-change path, and the branch adds focused regression coverage for both routes. The PR also supplies a described real gateway before/after run, but I did not independently execute it in this read-only review. Is this the best way to solve the issue? Yes, provisionally: continuing expected teardown aborts into the existing settle and after-turn owner is narrower than adding a parallel hook or self-learning-only workaround. The final check is that current-main integration still keeps terminal delivery single-shot. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d98e984ec2ae. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
What Problem This Solves
User-aborted agent runs unwound with a raw
AbortErrorout of the embedded run's lane task, skippingcompleteEmbeddedAttemptAfterTurnentirely. No agent-end side effects ever fired for aborted turns: the interrupted-turn experience review (#115887) was unreachable on the primary abort path, deterministic correction autocapture never ran (its own doc says failed-turn corrections are the most worth keeping), and pluginagent_endhooks were starved. Live-verified on a scratch gateway:lane task error: lane=main ... error="AbortError: This operation was aborted"/"Error: attempt aborted before prompt submission", with zero scheduling activity.Why This Change Was Made
Three escape hatches let aborts bypass the settle → after-turn pipeline that already handles aborted lifecycles everywhere else (
finalizeAttemptContextEngineTurntakesaborted, bootstrap persistence checks it, the agent-end event computessuccess = !aborted && !promptError):attempt-stream-finalize.ts—releaseForPrompt()throws "attempt aborted before prompt submission" when abort blocks the next round's submission; an aborted attempt never submits another prompt, so this is expected teardown noise, now tolerated when the lifecycle is aborted.attempt-stream-settle.ts— the completion-required async-task wait rethrewAbortErrorunless the lifecycle wastimedOut; user aborts now settle the same way timeout-aborts always have. An aborted run's unfinished async tasks no longer stamp a "Timed out waiting for async task completion" prompt error (that would reclassify the abort as an errored completion).attempt-after-turn.ts— teardown races can leave anAbortErrorinpromptError; abort outranks failure in terminal-outcome precedence, so the agent-end event no longer attacheserrorwhen the lifecycle is aborted. The scheduler's abort-vs-error split then classifies correctly.The abort-race test that pinned the old unwind ("preserves a run-budget timeout when abort blocks prompt submission") now asserts the run resolves with its run-budget timeout attribution preserved on the terminal — convergent with the normal timeout contract, which always settled through this path.
User Impact
Interrupting a deep agent turn now feeds self-learning and plugin hooks instead of silently dropping the turn. No config or API changes.
Evidence
gpt-5.6-luna, native runtime): before — SIGINT mid-turn produced a lane-taskAbortErrorrejection and no scheduling; after — a 22-iteration aborted turn logsexperience review scheduled: session=agent:main:abort-live-3 iterations=22 aborted=true, the review runs cleanly (isolated incognito session, correct self-exclusion), zero lane task errors. A completed short turn logs thebelow-depth-barskip, proving the event path fires for every turn.node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt-phase-lifecycle.test.ts src/agents/embedded-agent-runner/run/attempt-abort.test.ts src/agents/embedded-agent-runner/run/attempt.abort-race.test.ts src/agents/embedded-agent-runner/run/attempt-session-settle.test.ts— 16 passed, incl. two new regressions: aborted async-task wait settles without reclassification, and a teardown-racedAbortErroryields an abort-classified agent-end event (success:false, noerror).node scripts/check-changed.mjsgreen (local fallback; Blacksmith backend unreachable).