Skip to content

refactor(agents): canonicalize subagent execution state - #117267

Merged
steipete merged 1 commit into
mainfrom
codex/prod-wave-subagent-state-052208-2d45
Aug 1, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/prod-wave-subagent-state-052208-2d45

Conversation

@steipete

@steipete steipete commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Subagent terminal timing and outcomes were duplicated at the run-record root and under execution. Lifecycle paths could update one copy without the other, leaving status, cleanup, requester wake, and SQLite projections to disagree after pause, kill, restart, or recovery.

Why

  • Makes execution the sole owner of per-run startedAt, endedAt, and outcome.
  • Removes duplicate outcome comparison/update policy and orphan terminal fabrication.
  • Projects SQLite indexes and lightweight session rows from canonical execution state.
  • Updates completion findings to consume canonical execution outcomes, preserving fallback output after resumed NO_REPLY completions.
  • Adds an idempotent additive backfill for shipped pause/kill payloads; typed SQLite columns remain unchanged for downgrade readers.

User Impact

Subagent status and completion output remain consistent across yields, kills, restarts, recovery, session listings, cron follow-up, and requester-settle wakes. Existing shipped rows are repaired on schema ensure without a schema-version bump.

Evidence

Migration tests cover sessions_yield, provisional kill, newer nested-terminal precedence, missing start timing, malformed JSON, idempotence, typed-column preservation, and the v2026.7.2-beta.6 downgrade-reader projection.

Legacy Payload Provenance

Root-only SQLite payloads are not a shipped state and are intentionally outside this backfill. Nested execution normalization predates SQLite: commit d73f3ac85d5 made normalizeSubagentRunState create execution when absent and merge it when present (subagent-delivery-state.ts:34-77). Its JSON reader and writer both normalized records (subagent-registry.store.ts:152-185).

SQLite arrived later in 5374c7a8a20. Every SQLite write normalizes before serializing (subagent-registry.store.sqlite.ts:184-185), and the one-time JSON import first uses the normalizing JSON loader before that writer (subagent-registry.store.sqlite.ts:279-297). Therefore no production writer or importer can create a root-only SQLite row.

The shipped defect is narrower: for pause/kill rows with an existing nested execution: {status:"running"}, the old merge order let that nested status win over root terminal facts. Those are the exact observed canonical mismatches repaired and covered here. Adding support for a manually inserted root-only SQLite payload would preserve an unshipped hypothetical state, contrary to the repository's migration/compatibility doctrine; the typed-column downgrade contract remains covered by the actual v2026.7.2-beta.6 reader proof below.

Real Behavior Proof

Exact proof head: df703605205bd0b9632b88a33526823caca5ab27 after the single refresh onto current main.

A temporary proof test drove the production pause and kill owners (markSubagentRunPausedAfterYield and markSubagentRunTerminated), the real SQLite writer, a shared-database close/reopen, additive schema ensure twice, and the current SQLite loader. It was removed after the run. Observed projections:

Run Before restart After restart
paused-live pauseReason=sessions_yield; execution={status:terminal,startedAt:100,endedAt:200} identical
killed-live endedReason=subagent-killed; terminal execution.outcome.status=error; reconciliation killedAt equals execution end identical
legacy paused row root mirrors plus nested running state in seeded JSON canonical nested terminal execution after reopen; root mirrors removed
legacy killed row root mirrors/outcome plus nested running state in seeded JSON canonical nested terminal execution/outcome after reopen; root mirrors removed

The post-migration SQLite index columns retained the seeded timestamps (500/600 and 700/800) and outcome. A second close/reopen produced an identical map, proving idempotence.

Downgrade compatibility was then exercised with the actual shipped reader from tag v2026.7.2-beta.6 at 4d6bdbdbf33fe3ece3c53853fab9931882ff3f3c against that same upgraded database. It loaded all four rows with the same timing/outcome projections expected by the old runtime: paused 100/200, killed 300/<owner end> with error outcome, legacy paused 500/600, and legacy killed 700/800 with error outcome. This proves current readers consume canonical nested execution, while shipped downgrade readers continue to receive the preserved typed-column projections.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 1, 2026
@steipete
steipete marked this pull request as ready for review August 1, 2026 06:56
@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. P1 High-priority user-facing bug, regression, or broken workflow. 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 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

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

ClawSweeper review

What this changes

This PR makes nested execution the sole owner of subagent run timing and outcomes, updates lifecycle/session consumers, and backfills affected SQLite payloads.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

Keep this PR open for maintainer review. Current main still carries the competing root and nested execution terminal fields, so the central cleanup remains necessary; the PR also supplies exact-head persistence and downgrade-reader proof. However, its protected maintainer label, broad session-state migration, overlap with another open lifecycle PR, and unavailable local copy of the submitted commit mean this should not receive an automated merge or close verdict.

Priority: P1
Reviewed head: df703605205bd0b9632b88a33526823caca5ab27
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The runtime proof is strong, but independent exact-head and three-way-merge inspection is blocked and the patch remains a broad persisted session-state refactor.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR body provides exact-head after-fix SQLite close/reopen, idempotence, pause/kill, and shipped downgrade-reader observations, and the supplied check rollup records successful real-behavior-proof runs.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR body provides exact-head after-fix SQLite close/reopen, idempotence, pause/kill, and shipped downgrade-reader observations, and the supplied check rollup records successful real-behavior-proof runs.
Evidence reviewed 6 items Current main still has duplicated terminal state: At current-main commit f216d3cc868eccb820a94b0b691f3e2137e9b647, SubagentRunRecord defines root startedAt, endedAt, and outcome alongside nested execution; the reported split-brain state remains a real current-main design problem.
Current lifecycle owner writes both representations: Current-main interrupted-recovery completion writes root terminal fields and then writes corresponding nested execution fields, confirming the duplicated-owner invariant that this PR targets.
SQLite upgrade boundary is compatibility-sensitive: Current main normalizes payloads before SQLite writes while separately projecting root timing and outcome columns, so changing the serialized owner requires the PR's claimed additive backfill and downgrade-reader preservation to remain exact.
Findings None None.
Security None None.

How this fits together

Subagent lifecycle handlers record run progress and terminal outcomes, which are then persisted to SQLite and projected into recovery, delivery, cron follow-up, and session-status surfaces. The PR changes the canonical state source used across those downstream consumers.

flowchart LR
  A[Subagent lifecycle events] --> B[Run execution state]
  B --> C[Registry and lifecycle handlers]
  C --> D[SQLite run records]
  C --> E[Recovery and cleanup]
  C --> F[Delivery and requester wake]
  C --> G[Session and cron projections]
Loading

Decision needed

Question Recommendation
Should this broad canonical-state and SQLite-backfill refactor land now as the lifecycle foundation, or be sequenced with the overlapping recovery/delivery work in #117283? Review the exact merge and land this foundation: Review the current three-way merge, retain the stated typed-column downgrade contract, and land this canonical-owner refactor before reconciling later recovery work.

Why: Both PRs modify the same recovery, delivery, and persisted subagent-state neighborhood; choosing their integration order and accepting the stored-state migration risk requires maintainer intent.

Before merge

  • Resolve merge risk (P1) - The migration rewrites persisted subagent payloads during schema ensure while retaining typed SQLite projections for older readers; the exact merged tree needs an upgrade and downgrade review before landing.
  • Resolve merge risk (P1) - The local checkout cannot resolve GitHub to fetch the submitted head, so the complete 106-file exact-head diff and its clean merge against current main were not independently inspected.
Agent review details

Security

None.

Review metrics

None.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-state-db-legacy-backfills.test.ts, serialized state: src/gateway/session-utils-core.ts, serialized state: src/gateway/session-utils.single-row-cache.test.ts, serialized state: src/state/openclaw-state-db-legacy-backfills.test.ts, serialized state: src/state/openclaw-state-db-legacy-backfills.ts, unknown-data-model-change: src/gateway/session-utils-row.ts, and 2 more. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge-risk options

Maintainer options:

  1. Review the exact three-way merge first (recommended)
    Confirm the current-main merge preserves the one-owner invariant and rerun the SQLite reopen and downgrade-reader proof on the merged head before landing.
  2. Pause for lifecycle sequencing
    Hold this refactor while maintainers decide whether its state-model migration should be integrated with the overlapping recovery and delivery work.

Technical review

Best possible solution:

Keep execution as the single lifecycle owner, but land only after a maintainer reviews the exact clean merge and confirms the additive backfill preserves both current projections and the documented shipped-reader downgrade contract.

Do we have a high-confidence way to reproduce the issue?

Yes — source-reproducible on current main: the record type and interrupted-recovery lifecycle path retain root terminal fields alongside nested execution fields, allowing the two representations to diverge. This read-only review did not run a failing harness.

Is this the best way to solve the issue?

Unclear — making execution the sole owner matches the current duplicate-owner defect and repository guidance, but the exact submitted tree and merge result could not be fetched for independent validation of every persisted-state path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against f216d3cc868e.

Labels

Label justifications:

  • P1: Subagent terminal state drives recovery, requester wake-up, delivery, and operator-visible session status across active workflows.
  • merge-risk: 🚨 compatibility: The PR rewrites persisted SQLite payload JSON during schema ensure while preserving an older reader projection.
  • merge-risk: 🚨 session-state: The change relocates canonical start, end, and outcome state used by lifecycle and session consumers.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR body provides exact-head after-fix SQLite close/reopen, idempotence, pause/kill, and shipped downgrade-reader observations, and the supplied check rollup records successful real-behavior-proof runs.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact-head after-fix SQLite close/reopen, idempotence, pause/kill, and shipped downgrade-reader observations, and the supplied check rollup records successful real-behavior-proof runs.

Evidence

What I checked:

  • Current main still has duplicated terminal state: At current-main commit f216d3cc868eccb820a94b0b691f3e2137e9b647, SubagentRunRecord defines root startedAt, endedAt, and outcome alongside nested execution; the reported split-brain state remains a real current-main design problem. (src/agents/subagent-registry.types.ts:203, f216d3cc868e)
  • Current lifecycle owner writes both representations: Current-main interrupted-recovery completion writes root terminal fields and then writes corresponding nested execution fields, confirming the duplicated-owner invariant that this PR targets. (src/agents/subagent-registry-lifecycle-completion.ts:142, f216d3cc868e)
  • SQLite upgrade boundary is compatibility-sensitive: Current main normalizes payloads before SQLite writes while separately projecting root timing and outcome columns, so changing the serialized owner requires the PR's claimed additive backfill and downgrade-reader preservation to remain exact. (src/agents/subagent-registry.store.sqlite.ts:126, f216d3cc868e)
  • Submitted real behavior proof: The supplied PR body ties pause, kill, restart, idempotent schema ensure, SQLite reopen, and v2026.7.2-beta.6 downgrade-reader observations to the exact submitted head; the supplied check rollup also records successful real-behavior-proof checks. (df703605205b)
  • Feature-history routing: The behavior appears closely connected to the recent subagent status/restart work in commit 7fba71eb7aeb73f6a3b146389e251625efb4fd07, which is an ancestor of current main. (src/agents/subagent-registry.types.ts:172, 7fba71eb7aeb)
  • Exact-head inspection infrastructure gap: The checkout can inspect current main but does not contain the submitted PR object. Its promisor fetch for df703605205bd0b9632b88a33526823caca5ab27 fails because GitHub DNS is unavailable, so this review cannot independently inspect the complete exact-head tree or three-way merge result.

Likely related people:

  • steipete: Authored the recent current-main subagent restart/status work that owns the duplicate terminal-state model and is also the author of this proposed consolidation. (role: recent lifecycle contributor; confidence: high; commits: 7fba71eb7aeb, bf2da1ce1af7; files: src/agents/subagent-registry.types.ts, src/agents/subagent-registry-lifecycle-completion.ts, src/agents/subagent-registry.store.sqlite.ts)
  • Vincent Koc: Recent history shows agent-boundary refactoring work, and the linked open recovery/delivery PR covers an overlapping lifecycle neighborhood. (role: adjacent lifecycle contributor; confidence: medium; commits: e35c7a3c95b2; files: src/agents/subagent-registry.types.ts, src/agents/subagent-registry.store.sqlite.ts)
  • Josh Lehman: The SQLite state-store conversion is part of the persistence contract this migration relies on. (role: state-storage refactor contributor; confidence: medium; commits: 0a8e3604ba24; files: src/agents/subagent-registry.store.sqlite.ts, src/state/openclaw-state-db-schema-additive.ts)

Rank-up moves

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

  • Review the exact clean merge against current main and rerun the stated SQLite upgrade/downgrade proof if the merge result changes.

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 (7 earlier review cycles)
  • reviewed 2026-08-01T07:03:51.993Z sha f92943589584e6c3e287ca83e986b96206f5de75 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-01T07:33:01.808Z sha 4bf6538da01eb2de1c2eb228751a7e5f408749c2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-01T07:54:23.608Z sha 4bf6538da01eb2de1c2eb228751a7e5f408749c2 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T08:01:32.566Z sha 6c2260e8e6a2038230023fb6808b9a6f90c73585 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T08:08:27.454Z sha 6c2260e8e6a2038230023fb6808b9a6f90c73585 :: found issues before merge. :: [P1] Preserve root-only legacy terminal records
  • reviewed 2026-08-01T08:27:06.406Z sha 6c2260e8e6a2038230023fb6808b9a6f90c73585 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T08:59:14.943Z sha df70360 :: needs real behavior proof before merge. :: none

@steipete
steipete force-pushed the codex/prod-wave-subagent-state-052208-2d45 branch from f929435 to 4bf6538 Compare August 1, 2026 07:27
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 1, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 1, 2026
@steipete
steipete force-pushed the codex/prod-wave-subagent-state-052208-2d45 branch from 4bf6538 to 6c2260e Compare August 1, 2026 07:56
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 1, 2026
@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Aug 1, 2026
@steipete
steipete force-pushed the codex/prod-wave-subagent-state-052208-2d45 branch from 6c2260e to df70360 Compare August 1, 2026 08:54
@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. 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. labels Aug 1, 2026
@steipete
steipete merged commit fde5420 into main Aug 1, 2026
141 of 157 checks passed
@steipete
steipete deleted the codex/prod-wave-subagent-state-052208-2d45 branch August 1, 2026 09:21
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to Alix-007/openclaw that referenced this pull request Aug 1, 2026
* origin/main:
  fix(test/ui): prevent shared history pollution (openclaw#117348)
  fix(openrouter): apply image request transport policy (openclaw#117336)
  perf(gateway): skip clean transcript workers (openclaw#117342)
  test(testing): assert relay smoke readiness
  fix(testing): activate relay live smoke transport
  feat(channels): record account lifecycle facts and retire inferred health vocabularies (openclaw#117300)
  fix(canvas): remove unsupported snapshot delay hint (openclaw#117326)
  refactor(agents): fold cache TTL pruning into prompt projection (openclaw#117313)
  fix(canvas): honor paired-node invocation deadlines (openclaw#117316)
  fix(system-agent): make exit-and-run-a-terminal guidance surface-correct (openclaw#114633)
  fix(ai): assistant text blocks are run together on replay (openclaw#115743)
  refactor(agents): canonicalize subagent execution state (openclaw#117267)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* origin/main:
  fix(test/ui): prevent shared history pollution (openclaw#117348)
  fix(openrouter): apply image request transport policy (openclaw#117336)
  perf(gateway): skip clean transcript workers (openclaw#117342)
  test(testing): assert relay smoke readiness
  fix(testing): activate relay live smoke transport
  feat(channels): record account lifecycle facts and retire inferred health vocabularies (openclaw#117300)
  fix(canvas): remove unsupported snapshot delay hint (openclaw#117326)
  refactor(agents): fold cache TTL pruning into prompt projection (openclaw#117313)
  fix(canvas): honor paired-node invocation deadlines (openclaw#117316)
  fix(system-agent): make exit-and-run-a-terminal guidance surface-correct (openclaw#114633)
  fix(ai): assistant text blocks are run together on replay (openclaw#115743)
  refactor(agents): canonicalize subagent execution state (openclaw#117267)
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 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. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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