Skip to content

refactor(agents): centralize terminal lifecycle outcomes - #118254

Merged
steipete merged 4 commits into
mainfrom
refactor/terminal-outcome-owner
Aug 3, 2026
Merged

steipete merged 4 commits into
mainfrom
refactor/terminal-outcome-owner

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes terminal agent runs being classified differently depending on which core consumer observed the lifecycle event. In particular, a plain AbortError could 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 agent responses deliberately retain their shipped cancellation-as-timeout wire contract, while internal task/session projections use cancellation. ACP background tasks now use the existing structured TURN_TIMEOUT detail code instead of matching human-readable error text.

The ambiguous legacy aborted: true event without timeout attribution is treated as cancellation. Current producers emit explicit stopReason/timeoutPhase for 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 | timeout status values.

Evidence

  • Canonical outcome, activity-note, and ACP tests: 46 passed.
  • 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.
  • Codex autoreview (gpt-5.6-sol, high): clean, no accepted/actionable findings; TruffleHog clean.
  • Exact-head CI: green on run 30771177189 attempt 2. The sole first-attempt failure was an unrelated SQLite flip-proof transcript-persistence flake; newer main passed 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.

@steipete
steipete marked this pull request as ready for review August 2, 2026 22:20
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Aug 2, 2026
@steipete
steipete force-pushed the refactor/terminal-outcome-owner branch from db611f7 to 6d237dc Compare August 2, 2026 22:28
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 7:22 PM ET / 23:22 UTC.

ClawSweeper review

What this changes

This 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 agent wire contract.

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
Reviewed head: b3298a9def08a3720141434fc0b6e33c1136cf06

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is a coherent, well-covered owner-boundary refactor, but test and CI evidence alone do not satisfy the required real-behavior proof gate.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR provides focused tests and CI results, but no inspectable after-fix terminal output, runtime log, recording, or live artifact demonstrates the changed real behavior; add redacted proof before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR provides focused tests and CI results, but no inspectable after-fix terminal output, runtime log, recording, or live artifact demonstrates the changed real behavior; add redacted proof before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current main still needs the refactor: Current main retains the terminal-error carrier inside the outcome module and has no lifecycle-event builder/classifier; the PR introduces the canonical lifecycle-event path and migrates the consumer projections.
Canonical lifecycle classification: The branch treats a bare lifecycle abort as cancellation, requires structured timeout attribution, and passes the normalized outcome through the existing terminal-outcome rules.
Consumer contracts remain explicit: Task and session consumers map cancellation to cancelled and killed, while Gateway deliberately maps its cancellation classification to the existing timeout wire status.
Findings None None.
Security None None.

How this fits together

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

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR provides focused tests and CI results, but no inspectable after-fix terminal output, runtime log, recording, or live artifact demonstrates the changed real behavior; add redacted proof before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P2) - The branch changes persisted task/session classifications and preserves a distinct Gateway cancellation-as-timeout wire mapping; no inspectable after-fix runtime artifact demonstrates those projections together from a real run.
  • Complete next step (P2) - This protected, maintainer-labeled PR has no mechanical repair finding; the contributor must provide inspectable real behavior proof before normal maintainer merge review.
Agent review details

Security

None.

PR surface

Source +14, Tests +73. Total +87 across 27 files.

View PR surface stats
Area Files Added Removed Net
Source 19 278 264 +14
Tests 8 85 12 +73
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 27 363 276 +87

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/agents/session-activity-notes.test.ts, serialized state: src/agents/session-activity-notes.ts, serialized state: src/gateway/session-lifecycle-state.test.ts, serialized state: src/gateway/session-lifecycle-state.ts, unknown-data-model-change: src/gateway/session-lifecycle-state.ts, vector/embedding metadata: src/tui/embedded-backend.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Add projection proof before merge (recommended)
    Attach redacted after-fix terminal output or runtime logs that show a bare cancellation, an explicitly attributed timeout, and an ordinary failure receiving the intended Gateway, task, and session statuses.
  2. Pause for a narrower split
    If a refreshed merge result exposes unrelated lifecycle drift, separate the canonical classifier from consumer-specific projection changes so each compatibility contract can be reviewed independently.

Technical review

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

Labels

Label justifications:

  • P2: This is a normal-priority correction to agent terminal-state reporting across several consumers, without evidence of an emergency availability or security impact.
  • merge-risk: 🚨 compatibility: The patch intentionally changes shared classification while preserving Gateway’s historical cancellation-as-timeout response contract.
  • merge-risk: 🚨 session-state: Task and session projections persist different terminal statuses for cancellation, timeout, and failure after this change.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides focused tests and CI results, but no inspectable after-fix terminal output, runtime log, recording, or live artifact demonstrates the changed real behavior; add redacted proof before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame attributes the central terminal-outcome rules to Peter Steinberger, and this PR plus the related lifecycle work are authored as steipete. (role: feature owner and recent area contributor; confidence: high; commits: 8729d541a9f0, 0ac3fb89080e, 1a026c6f617f; files: src/agents/agent-run-terminal-outcome.ts, src/gateway/server-methods/agent-run-dispatch.ts, src/tasks/task-registry-lifecycle.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach redacted after-fix terminal output or runtime logs covering cancellation, timeout, and failure projections.

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-02T22:33:21.953Z sha 6d237dcf8174ca676ac452c5acba4e15a6289e18 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T22:44:00.209Z sha 5d1f680059961f0abffd51667f6eee03aaad1b52 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T23:00:28.527Z sha b3298a9 :: needs real behavior proof before merge. :: none

@steipete
steipete force-pushed the refactor/terminal-outcome-owner branch from 6d237dc to 5d1f680 Compare August 2, 2026 22:38
@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label Aug 2, 2026
@steipete
steipete force-pushed the refactor/terminal-outcome-owner branch from 5d1f680 to b3298a9 Compare August 2, 2026 22:55
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 2, 2026
@steipete
steipete merged commit 3a555d5 into main Aug 3, 2026
202 of 208 checks passed
@steipete
steipete deleted the refactor/terminal-outcome-owner branch August 3, 2026 02:17
@steipete

steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

agents Agent runtime and tooling commands Command implementations gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant