Skip to content

refactor(agents): route terminal-reason groups through the canonical classifier - #124122

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-terminal-classification
Aug 15, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-terminal-classification

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Root AGENTS.md names the invariant: agent-run terminal state normalizes via src/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 future AgentRunTerminalReason value would silently misclassify in those projections while the canonical classifier handled it correctly:

  • subagent-announce-output.ts applySubagentWaitOutcome — a hand-written four-way partition (timeout / aborted|cancelled|superseded / blocked|abandoned|failed / completed), byte-equivalent to the canonical classification.
  • subagent-registry-run-wait.ts waitAborted — aborted|cancelled|superseded is exactly classification === "cancellation" (waitBlocked stays finer-grained intentionally).
  • embedded-agent-runner/run/terminal-outcome.ts — isEmbeddedRunTerminalTimeout/Abort re-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 && !finished guard in finalizeLifecycleEvent — registry.peek and registry.shift run 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

  • Behavior equivalence verified against buildAgentRunTerminalOutcome (status "timeout" iff reason ∈ {hard_timeout, timed_out}) and the AGENT_RUN_TERMINAL_CLASSIFICATION table.
  • 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.

…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.
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 15, 2026 09:02
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 15, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 5:08 AM ET / 09:08 UTC.

ClawSweeper review

What this changes

This PR routes embedded-run, subagent-announcement, and subagent-wait terminal handling through the shared classifier and removes an unreachable Gateway lifecycle guard.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep 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
Reviewed head: 96a72186848d9fe20d1123179470939e5d4fadaa

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative refactor with source-backed equivalence and existing coverage; no correctness finding was identified.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal refactor changes no directly user-visible flow; its PR body reports focused test coverage, but the external-contributor proof gate does not apply.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal refactor changes no directly user-visible flow; its PR body reports focused test coverage, but the external-contributor proof gate does not apply.
Evidence reviewed 6 items Canonical owner and exhaustive mapping: Current main owns the nine terminal reasons in one exhaustive Record and exposes the four-way classifier; the type contract requires classifier coverage when the reason union changes.
Current main still has the duplicated policy: The PR base contains the three local reason partitions; the PR head replaces them with canonical classification while retaining the distinct blocked case in the wait manager.
Existing behavior coverage: The classifier test covers every current reason, while focused announcement and embedded-run tests cover failure, timeout, cancellation, and success projections.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

  • Complete next step (P2) - This maintainer-authored, maintainer-labeled PR needs ordinary human sign-off rather than automated cleanup or repair.
Agent review details

Security

None.

PR surface

Source -1. Total -1 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 4 32 33 -1
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 32 33 -1

Review metrics

Metric Value Why it matters
Production versus test delta production +32/-33 (net -1); tests +0/-0 The refactor reduces duplicated production policy while existing focused suites cover the terminal partitions.

Technical review

Best 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.

Labels

Label changes:

  • add P3: This is a small behavior-preserving maintainability refactor with no reported user-facing regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal refactor changes no directly user-visible flow; its PR body reports focused test coverage, but the external-contributor proof gate does not apply.

Label justifications:

  • P3: This is a small behavior-preserving maintainability refactor with no reported user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal refactor changes no directly user-visible flow; its PR body reports focused test coverage, but the external-contributor proof gate does not apply.

Evidence

What I checked:

Likely related people:

  • steipete: Current classifier lines blame to Peter Steinberger, and the available feature history includes the terminal-lifecycle centralization and embedded-outcome refactors. (role: terminal-outcome centralization author and recent area contributor; confidence: high; commits: 3a555d5956ec, 61f036f74864, 637cd6fb0c78; files: src/agents/agent-run-terminal-outcome.ts, src/agents/embedded-agent-runner/run/terminal-outcome.ts, src/agents/subagents/announce/subagent-announce-output.ts)
  • Vincent Koc: Authored the available embedded deadline timeout repair in the same terminal-outcome neighborhood. (role: adjacent embedded-timeout contributor; confidence: medium; commits: 4f4fc7a7ca46; files: src/agents/embedded-agent-runner/run/terminal-outcome.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 4a6f99c into main Aug 15, 2026
253 checks passed
@steipete
steipete deleted the codex/autoqa-terminal-classification branch August 15, 2026 09:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant