Repository navigation
refactor(agents): route terminal-reason groups through the canonical classifier - #124122
Conversation
…classifier Root AGENTS.md: terminal state normalizes via agent-run-terminal-outcome.ts; projections must not rederive timeout/cancel precedence. Three consumers re-enumerated the reason groups by hand, so any future reason value would silently misclassify: - subagent-announce-output.ts applySubagentWaitOutcome: byte-equivalent four-way partition replaced with a switch on classifyAgentRunTerminalOutcome (status "timeout" iff reason is a timeout classification, per buildAgentRunTerminalOutcome). - subagent-registry-run-wait.ts waitAborted: aborted|cancelled|superseded is exactly classification === "cancellation" (waitBlocked stays finer-grained intentionally). - embedded-agent-runner terminal-outcome.ts: isEmbeddedRunTerminalTimeout / Abort become one-liners over the classifier. Rider: dropped the provably unreachable chatLink && !finished guard in finalizeLifecycleEvent — peek and shift run in one synchronous frame, so the shifted head is exactly the peeked entry (comment records the invariant). Net -1 production LOC; 2005 tests across agents/subagents/embedded/gateway suites green.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 5:08 AM ET / 09:08 UTC. ClawSweeper reviewWhat this changesThis PR routes embedded-run, subagent-announcement, and subagent-wait terminal handling through the shared classifier and removes an unreachable Gateway lifecycle guard. Merge readinessKeep open for normal maintainer handling. The PR removes duplicate terminal-reason policy while preserving the canonical four-way mapping, and the Gateway guard removal is safe under the synchronous registry contract; current main still contains the duplicated projections. Priority: P3 Review scores
Verification
How this fits togetherThe agents subsystem normalizes raw wait, timeout, cancellation, and lifecycle signals into one terminal outcome. Subagent completion flows and Gateway chat projection consume that outcome to update parent results, retries, and session status. flowchart LR
A[Agent wait and lifecycle signals] --> B[Terminal outcome normalizer]
B --> C[Canonical reason classifier]
C --> D[Subagent announcement result]
C --> E[Subagent completion recovery]
B --> F[Gateway chat projection]
F --> G[Chat and session status]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -1. Total -1 across 4 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Land the focused refactor after ordinary maintainer sign-off and exact-head CI, keeping all terminal-reason grouping at the canonical classifier. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a behavior-preserving refactor, and source plus existing exhaustive tests establish equivalence rather than a user-facing failure reproduction. Is this the best way to solve the issue? Yes. Routing projections through the exhaustive canonical classifier is the narrowest maintainable way to remove duplicate precedence policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 160e368a8902. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…classifier (openclaw#124122) Root AGENTS.md: terminal state normalizes via agent-run-terminal-outcome.ts; projections must not rederive timeout/cancel precedence. Three consumers re-enumerated the reason groups by hand, so any future reason value would silently misclassify: - subagent-announce-output.ts applySubagentWaitOutcome: byte-equivalent four-way partition replaced with a switch on classifyAgentRunTerminalOutcome (status "timeout" iff reason is a timeout classification, per buildAgentRunTerminalOutcome). - subagent-registry-run-wait.ts waitAborted: aborted|cancelled|superseded is exactly classification === "cancellation" (waitBlocked stays finer-grained intentionally). - embedded-agent-runner terminal-outcome.ts: isEmbeddedRunTerminalTimeout / Abort become one-liners over the classifier. Rider: dropped the provably unreachable chatLink && !finished guard in finalizeLifecycleEvent — peek and shift run in one synchronous frame, so the shifted head is exactly the peeked entry (comment records the invariant). Net -1 production LOC; 2005 tests across agents/subagents/embedded/gateway suites green.
What Problem This Solves
Root
AGENTS.mdnames the invariant: agent-run terminal state normalizes viasrc/agents/agent-run-terminal-outcome.ts— projections must not rederive timeout/cancel precedence. Three consumers re-enumerated the terminal reason groups by hand, so any futureAgentRunTerminalReasonvalue would silently misclassify in those projections while the canonical classifier handled it correctly:subagent-announce-output.tsapplySubagentWaitOutcome— a hand-written four-way partition (timeout / aborted|cancelled|superseded / blocked|abandoned|failed / completed), byte-equivalent to the canonical classification.subagent-registry-run-wait.tswaitAborted—aborted|cancelled|supersededis exactlyclassification === "cancellation"(waitBlockedstays finer-grained intentionally).embedded-agent-runner/run/terminal-outcome.ts—isEmbeddedRunTerminalTimeout/Abortre-enumerated the same groups.Why This Change Was Made
All three now route through
classifyAgentRunTerminalOutcome, the exported four-way classification already used by session-lifecycle, chat-state, TUI, and gateway-wire projections. One recorded fact instead of four copies of the partition.Rider (same lifecycle neighborhood): dropped the provably unreachable
chatLink && !finishedguard infinalizeLifecycleEvent—registry.peekandregistry.shiftrun in one synchronous frame with no await between them, so the shifted head is exactly the peeked entry; a comment records the invariant.User Impact
None visible today — behavior is byte-equivalent for every current reason value. The fix removes the silent-misclassification trap for future reason values.
Evidence
buildAgentRunTerminalOutcome(status"timeout"iff reason ∈ {hard_timeout, timed_out}) and theAGENT_RUN_TERMINAL_CLASSIFICATIONtable.node scripts/run-vitest.mjs run src/agents/subagents— 1089/1089 across 38 files;src/agents/agent-run-terminal-outcome.test.ts+src/agents/embedded-agent-runner— 903/903;src/gateway/server-chat.agent-events.test.ts— in the 13-test run, green.pnpm tsgo,pnpm check:test-types, oxfmt/oxlint clean; autoreview clean (0.98).Production LOC +32/−33 (net −1); no test changes needed — existing suites pin the partition.