Repository navigation
refactor(agents): centralize terminal lifecycle outcomes - #118254
Conversation
db611f7 to
6d237dc
Compare
|
Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 7:22 PM ET / 23:22 UTC. ClawSweeper reviewWhat this changesThis PR centralizes terminal agent-run outcome classification so task records, session state, chat, audit events, ACP background tasks, and the TUI consistently distinguish success, timeout, cancellation, and failure while retaining the Gateway Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 3 items remain The PR remains necessary: current main still has the older split terminal-outcome handling, while this branch establishes one lifecycle-event classifier and explicit domain projections. The patch appears correct on source review, but it needs real after-fix behavior proof before merge; focused tests and green CI are supplemental only. Priority: P2 Review scores
Verification
How this fits togetherAgent runtimes emit terminal lifecycle events consumed by task persistence, session projections, Gateway responses, chat state, audit records, ACP background tasks, and the embedded TUI. This change normalizes the event once, then lets each consumer map the shared classification into its own persisted or user-visible status. flowchart LR
A[Agent runtime lifecycle event] --> B[Canonical terminal outcome]
B --> C[Shared classification]
C --> D[Task and session records]
C --> E[Gateway and chat status]
C --> F[Audit, ACP, and TUI state]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +14, Tests +73. Total +87 across 27 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land one canonical lifecycle-event classifier with explicit per-consumer mappings after a current-main merge refresh and redacted runtime proof shows bare cancellation, structured timeout, and ordinary failure reach their intended task, session, and Gateway projections. Do we have a high-confidence way to reproduce the issue? Yes, from source with high confidence: current main has separate lifecycle derivations, and the branch’s focused tests exercise the bare-abort, structured-timeout, and signal-only activity-note paths. This read-only review did not run a live failing reproduction. Is this the best way to solve the issue? Yes: classifying terminal lifecycle facts once at the shared producer boundary is a better fix than preserving several consumer-local timeout and cancellation heuristics; the explicit Gateway compatibility mapping avoids replacing its shipped wire vocabulary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 15560382a2ad. LabelsLabel 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
HistoryReview history (3 earlier review cycles)
|
6d237dc to
5d1f680
Compare
5d1f680 to
b3298a9
Compare
|
Merged via squash.
|
* origin/main: refactor(agents): centralize terminal lifecycle outcomes (#118254) fix(scripts): warm gateway concurrency probes (#118364) test(discord): consolidate activity HTTP fixtures (#118314) fix(qa): restore prerelease validation (#118255) improve(tests): focus overflow compaction owner coverage (#118351) test(telegram): deduplicate dispatch fixtures (#118319) test(xai): consolidate realtime voice fixtures (#118318) fix(telegram): prevent durable ingress lane spins (#118357)
…8254) * refactor(agents): centralize terminal lifecycle outcomes * fix(agents): preserve terminal projection contracts * refactor(agents): split terminal error boundary * test(gateway): align stale lifecycle projection
What Problem This Solves
Fixes terminal agent runs being classified differently depending on which core consumer observed the lifecycle event. In particular, a plain
AbortErrorcould be recorded as a timed-out task, signal-only aborted lifecycle events could appear completed in activity notes, and several task/session/chat/audit/TUI paths independently re-derived timeout and cancellation precedence.Why This Change Was Made
The canonical terminal-outcome owner now accepts lifecycle events directly, classifies reasons once as success/timeout/cancellation/failure, and lets each owning domain map that classification into its existing vocabulary. Gateway
agentresponses deliberately retain their shipped cancellation-as-timeoutwire contract, while internal task/session projections use cancellation. ACP background tasks now use the existing structuredTURN_TIMEOUTdetail code instead of matching human-readable error text.The ambiguous legacy
aborted: trueevent without timeout attribution is treated as cancellation. Current producers emit explicitstopReason/timeoutPhasefor real timeouts; this removes the older compensation that turned every bare abort into a timeout.AI-assisted change; I reviewed the complete implementation and behavior boundaries.
User Impact
Cancelled runs are no longer mislabeled as timed out in task tracking, and session activity no longer reports signal-only aborted runs as completed. Existing Gateway clients continue receiving the same final
ok | error | timeoutstatus values.Evidence
node scripts/run-vitest.mjs src/gateway/session-lifecycle-state.test.ts: 31 passed.node scripts/run-vitest.mjs src/tasks/task-registry.test.ts: 120 passed.node scripts/run-vitest.mjs src/gateway/server-methods/agent.test.ts -t "unsignaled AbortError": 1 passed, 266 skipped.node scripts/run-vitest.mjs src/audit/audit-events.test.ts src/gateway/server-chat.agent-events.test.ts src/tui/embedded-backend.test.ts -t "classifies terminal run metadata|projects lifecycle self-aborts|actionable terminal failure": 18 passed, 248 skipped.node scripts/run-vitest.mjs src/agents/agent-command.ingress-diagnostics.test.ts src/gateway/server-methods/agent-job.timeout-fallback.test.ts: 24 passed.git diff --check: passed.gpt-5.6-sol, high): clean, no accepted/actionable findings; TruffleHog clean.mainpassed the same check and the failed-job retry passed.node scripts/check-changed.mjs: delegation attempted, but the local Crabbox/Testbox provider doctor was unavailable; exact-head PR CI supplied the type/lint/build proof.The cron message-text timeout classifier is intentionally not changed here: active PR #117340 owns the overlapping cron producer/projection files, and its remaining watchdog path still needs structured classification wiring before that regex can be deleted safely.