Skip to content

fix: keep subagent cleanup and session maintenance responsive - #158251

Merged
steipete merged 89 commits into
mainfrom
codex/subagent-registration-worker-20260925
Oct 2, 2026
Merged

steipete merged 89 commits into
mainfrom
codex/subagent-registration-worker-20260925

Conversation

@steipete

@steipete steipete commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Failed subagent registration can leave its caller waiting indefinitely for repeated cancellation attempts. Session maintenance can hold the archive queue while waiting for a database writer, and a failed shared worker can prevent lease cleanup and Gateway shutdown.

User Impact

An uncertain hosted registration reports its error after the first cancellation attempt while its Gateway tracks the remaining cleanup and retains the child's admission capacity. Maintenance prepares metadata through the existing database executor, leaving the archive queue available. Cleanup preserves current ownership, authored data, retention, and joined shutdown. There is no configuration or schema migration. Deployed performance gains remain unverified.

Implementation

The change uses main's immutable, ordered registry mutation owner from #163195 and removes the superseded registration writer and persistence-mode paths. Registration retains committed facts while rechecking caller authority and the original Gateway instance before activation. Completion rechecks registered authority at the final outbound handoff; a retired store's policy query returns false without authorizing delivery. Custody callbacks cannot publish cache notifications into a replacement database generation.

Uncertain registration retains the session and reports its run identifiers. Further cancellation attempts belong to the captured Gateway's existing execution tracker. Database retirement cannot release a live child's admission slot or restore expired abort authority: the exact controller's removal or Gateway shutdown settles that ownership. Provisional rollback, collector ordering, and local embedded cleanup remain joined.

Maintenance prepares outside archive and writer queues, refreshes protection, and rechecks selected rows before commit. The shared-store owner retires failed actors before releasing their original leases; genuine cleanup failures retain custody. Immutable row preparation belongs to the existing memory owner, with all callers migrated and no compatibility re-export. The spawn lifecycle emitter now owns both success and failure hooks.

Validation

Candidate 3fda29d9f1aa5ce44eac52e969c09181b68fc66a, tree a96ec746aad9b28f37570407da2d789fc05f7615.

The current-main integration preserves fs-safe 0.23 admission and fixes ordinary registration lookup to include its resolved child agent. The existing concurrent raw-owner regression fails before that fix and passes afterward. Five owning type graphs, 85 registry cases, and 146 state cases passed. The remaining group passed 134 cases; two unchanged error-path cases exceeded the 512-byte key limit because of the temporary directory prefix, then passed with a short private state root on identical source. The final claim-binding cleanup and recovery selection passed 45 cases (wrapper times 47.11s, 32.47s, and 60.98s). Three managed integration reviews found no unresolved actionable issues. All 33 selected static checks passed, including core types and all 27 test-type graphs. Exact-head CI failed only on three inherited main fixture/import-inventory jobs; the same failures were reproduced independently on main. Upstream commits 779c5aae5e882da47460e0a49d820b2bd3ee4254 and ba811fafc1844c0098fc6b3e7032ae57db6b4b51 repair those causes. The failed CI result and skipped coverage are retained for native inherited-failure admission.

Earlier source-bound proof:

  • The prior corrections pass 60 focused behavior cases, 481 test-project ownership checks, three owning type graphs, and 13 selected static checks. Independent scoped reviews have no unresolved actionable findings. The behavior cases cover retired-store completion policy, actual current/revoked outbound delivery, all 13 preparation-authority cases, all 26 session-group cases, and all 18 cases from the affected SDK selection. Fixtures use the actual Gateway dispatcher, join accepted handlers, share the correct state owner, and route worker-backed maintenance through the existing host-broker project. Assertions and deadlines are unchanged.
    Actual node scripts/run-vitest.mjs run … --maxWorkers=1 wrapper times: retired completion 88.00s, outbound controls 65.37s, preparation authority 106.05s, session groups 96.51s, SDK selection 111.14s, and project ownership 135.20s. These retain the existing real Gateway/worker and public SDK boundaries; current CI timing is pending.
  • Source-bound earlier proof covers 315 selected cases across 20 files, including real Gateway rollback, uncertain cleanup, admission capacity, controller reassignment, shutdown takeover, nested sessions, and SDK registration failure. Subsequent integration checks cover 53 hook/thread-binding/spawn cases and the changed publication, usage-cache, maintenance, and incognito paths. Evidence is reused only for unchanged inputs.
  • Negative controls demonstrate the original acceptance after caller retirement, publication into a replaced database, and actual outbound delivery after revocation. A controlled worktree-deletion sequence also reaches the unchanged filesystem assertion after the real 10-second response deadline while the Gateway handler remains pending; the fixture repair joins that handler, and the original eight-case prefix passes.
  • The full-DTS build/package passed in 641.33s. The published 2026.9.7 → installed candidate → orderly shutdown cell passed in 421.24s on Linux/Node 24.19.0. Installed and serving build identities matched the source-bound candidate, the durable update finished successfully, authenticated readiness returned 200, service stop returned 0/null with its process tree terminated, and the final Gateway exited 0/null. All 58 collected artifacts and runner cleanup were verified. This uses a synthetic supervisor; it does not establish production systemd behavior, installed failed-worker fault injection, new live-session continuity, or deployed performance recovery.

The CI parent-fork teardown admission failure remains unexplained. A bounded replay of its original 30-file selector passed all 335 cases with temporary refusal probes, which were removed afterward. That replay used Node 24.21 on macOS; CI used Node 24.19 on Linux, and its exact inter-fork ordering was unavailable. This is not a causal repair or an inherited-failure classification.

Retained limitations

The original cause of an earlier first managed-worktree acceptance failure and an earlier Linux/Node 24.19 audio-only TTS dedupe/teardown failure remains unresolved. The natural worktree-deletion failure lacked its RPC receipt, so the later controlled reproduction does not establish that original trigger. An SDK negative-control attempt lost required coordinates to redaction and remains unqualified. Interrupted resource-monitor attempts remain interrupted; their source and cleanup were reconciled before subsequent work.

Earlier worker-retirement/Gateway-shutdown proof includes 108 Linux cases and native Windows replacement behavior. CI 36956812499 passed at prior head 44ce2fd0a466eb8be193feb67f5c29b6df1ff9fc, including all five native Windows jobs. It is not current-head CI. Earlier local runtime preparation skipped package declaration generation; the final installed-cell candidate includes the completed full declaration build.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: XL labels Sep 25, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 2, 2026, 10:55 AM ET / 14:55 UTC (Revision 80).

ClawSweeper review

What this changes

This PR moves failed subagent cancellation into Gateway-owned cleanup, separates session-maintenance preparation from archive queues, and repairs failed-worker lease cleanup.

Merge readiness

⛔ Blocked before merge - 2 items remain

The PR remains useful and has no supported blocking correctness finding. The new source-bound update and orderly-shutdown evidence resolves the previous review’s proof request; ordinary CI and landing gates remain authoritative.

Priority: P1
Reviewed head: 3fda29d9f1aa5ce44eac52e969c09181b68fc66a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The owner-focused repairs have meaningful boundary and installed-update evidence, with limitations preserved and no supported blocking defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Recorded Gateway/SQLite boundary scenarios cover failed registration, retained admission, reassignment, retirement, and shutdown; current/revoked completion scenarios cover final adapter handoff. The exact-head full-build published-driver update cell observes installed identity, readiness, process-tree termination, and clean Gateway exit, resolving the prior request. Synthetic execution/adapters and supervision limit live-provider and production-systemd claims. No stored-data contract changes were found.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded Gateway/SQLite boundary scenarios cover failed registration, retained admission, reassignment, retirement, and shutdown; current/revoked completion scenarios cover final adapter handoff. The exact-head full-build published-driver update cell observes installed identity, readiness, process-tree termination, and clean Gateway exit, resolving the prior request. Synthetic execution/adapters and supervision limit live-provider and production-systemd claims. No stored-data contract changes were found.
Evidence reviewed 10 items Pinned scope and clean checkout: Reviewed the introduced delta from the pinned base to the exact original PR head. The complete local inventory contains 95 paths, resolving the prompt’s truncated inventory. The checkout remained clean.
Distinct work remains on the branch: The fetched main retains the base cleanup implementation, which lacks the new accepted-run termination handoff. The relevant main comparison also does not contain this branch’s maintenance-worker or failed shared-worker cleanup changes. The stale test merge was not used to infer removal of main behavior.
Accepted-child cleanup ownership: After the first failed cancellation, cleanup transfers to the captured Gateway execution tracker while retaining admission. Dispatch checks the exact Gateway, session identity, controller, and operational run instance; database retirement stops further cancellation without immediately freeing a still-running child’s slot.
Findings None None.
Security None None.

How this fits together

Subagent spawning registers child runs and delivers their results through the Gateway. SQLite maintenance and worker retirement manage the sessions and database leases underneath those runs.

flowchart TD
  A[Child spawn] --> B[Registry acknowledgement]
  B --> C[Current ownership checks]
  C --> D[Completion delivery]
  B --> E[Gateway cleanup]
  F[Session maintenance] --> G[Database executor]
  G --> H[Committed session updates]
  E --> G
Loading

Before merge

  • Review config compatibility - Confirm compatibility and upgrade impact for the changed config or default surface before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

PR surface statistics unavailable: the file list is incomplete.

Review metrics

Metric Value Why it matters
Production versus test growth production net +1,018 lines; tests/support net +2,208 lines Growth is concentrated in retained cleanup custody, maintenance execution/publication, and boundary regressions, with those responsibilities explained in the PR.

Stored data model

Persistent data-model change detected: unknown-truncated-pull-files. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep cancellation, maintenance preparation, and retirement with their existing lifecycle owners while preserving exact-child authority, committed data, and joined shutdown.

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

Yes—the failed-registration retry and SQLite contention paths are concrete in source and have recorded production-boundary fault scenarios; this read-only review did not execute them.

Is this the best way to solve the issue?

Yes—the branch extends existing execution, registry, and transaction owners rather than introducing competing storage or cleanup policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 918153ea3355.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. Recorded Gateway/SQLite boundary scenarios cover failed registration, retained admission, reassignment, retirement, and shutdown; current/revoked completion scenarios cover final adapter handoff. The exact-head full-build published-driver update cell observes installed identity, readiness, process-tree termination, and clean Gateway exit, resolving the prior request. Synthetic execution/adapters and supervision limit live-provider and production-systemd claims. No stored-data contract changes were found.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P1: The reported failures can stall child-spawn error handling, session maintenance, and Gateway shutdown.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded Gateway/SQLite boundary scenarios cover failed registration, retained admission, reassignment, retirement, and shutdown; current/revoked completion scenarios cover final adapter handoff. The exact-head full-build published-driver update cell observes installed identity, readiness, process-tree termination, and clean Gateway exit, resolving the prior request. Synthetic execution/adapters and supervision limit live-provider and production-systemd claims. No stored-data contract changes were found.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded Gateway/SQLite boundary scenarios cover failed registration, retained admission, reassignment, retirement, and shutdown; current/revoked completion scenarios cover final adapter handoff. The exact-head full-build published-driver update cell observes installed identity, readiness, process-tree termination, and clean Gateway exit, resolving the prior request. Synthetic execution/adapters and supervision limit live-provider and production-systemd claims. No stored-data contract changes were found.

Evidence

What I checked:

  • Pinned scope and clean checkout: Reviewed the introduced delta from the pinned base to the exact original PR head. The complete local inventory contains 95 paths, resolving the prompt’s truncated inventory. The checkout remained clean. (3fda29d9f1aa)
  • Distinct work remains on the branch: The fetched main retains the base cleanup implementation, which lacks the new accepted-run termination handoff. The relevant main comparison also does not contain this branch’s maintenance-worker or failed shared-worker cleanup changes. The stale test merge was not used to infer removal of main behavior. (src/agents/subagents/spawn/subagent-spawn-cleanup.ts:125, 918153ea3355)
  • Accepted-child cleanup ownership: After the first failed cancellation, cleanup transfers to the captured Gateway execution tracker while retaining admission. Dispatch checks the exact Gateway, session identity, controller, and operational run instance; database retirement stops further cancellation without immediately freeing a still-running child’s slot. (src/agents/subagents/spawn/subagent-spawn-cleanup.ts:125, 3fda29d9f1aa)
  • Allowed and reassigned cleanup scenarios: The production-boundary fixture invokes the real Gateway recovery dispatcher after an injected first-abort failure. Its recorded passing scenarios cover retry, operator revocation, controller reassignment, database retirement, and shutdown; assertions preserve successor controllers, retained sessions, and admission capacity. Embedded execution is synthetic, so this is scoped boundary evidence rather than live-provider proof. (src/agents/subagents/spawn/subagent-spawn.rollback.test-support.ts:323, 3fda29d9f1aa)
  • Final completion authority: Completion now supplies the existing synchronous final-adapter authority guard. The current/revoked fixture exercises real registry persistence and completion routing, observing one adapter invocation for current authority and zero after revocation. The final channel adapter is a test adapter; no live Discord transport claim is made. (src/agents/subagents/announce/subagent-announce-completion-delivery.ts:452, 3fda29d9f1aa)
  • Maintenance and storage compatibility: Metadata preparation uses the existing agent executor before writer admission, refreshes protection before writing, and rechecks selected rows in the existing transaction kernel. Retained preparations are runtime maps; the diff introduces no schema, serialized-format, configuration, retention-policy, or public SDK contract change. (src/state/openclaw-agent-execution-maintenance.ts:22, 3fda29d9f1aa)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shakker: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (79 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-02T02:32:22.471Z sha 45c7f95 :: needs real behavior proof before merge. :: [P2] Bound accepted-run abort cleanup before returning spawn failure
  • reviewed 2026-10-02T02:49:11.216Z sha 44ce2fd :: needs real behavior proof before merge. :: [P2] Bound accepted-run abort cleanup before returning spawn failure
  • reviewed 2026-10-02T03:05:07.997Z sha 44ce2fd :: needs real behavior proof before merge. :: [P2] Bound accepted-run abort cleanup before returning spawn failure
  • reviewed 2026-10-02T05:49:35.103Z sha 4b610eb :: blocked before merge. :: none
  • reviewed 2026-10-02T06:48:51.678Z sha 111f62b :: blocked before merge. :: none
  • reviewed 2026-10-02T09:52:43.082Z sha 7ea5c9a :: blocked before merge. :: none
  • reviewed 2026-10-02T11:43:41.462Z sha ac85d9c :: blocked before merge. :: none
  • reviewed 2026-10-02T13:46:48.520Z sha 3fda29d :: blocked before merge. :: none

@steipete
steipete marked this pull request as ready for review September 25, 2026 18:38
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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. labels Sep 25, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 26, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 2, 2026
@steipete steipete changed the title fix: keep subagent registration responsive during database contention fix: keep subagent cleanup and session maintenance responsive Oct 2, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Oct 2, 2026
Return the existing false completion policy for retired stores before checking
live delivery authority. Eligible delivery still requires current authority at
the outbound boundary.

Route preparation-fixture cleanup through the captured Gateway owner and join
accepted handlers before tearing down parent state. Align session-group fixture
helpers with the catalog's state directory and classify published inbound
maintenance under the existing host broker test project.

Verified 60 focused behavior cases, 481 project-ownership checks, three owning
type graphs, 13 static checks, and two scoped independent reviews. The prior
parent-fork teardown failure did not reproduce in one bounded diagnostic replay;
its cause remains unresolved. All temporary diagnostics were removed.
@clawsweeper clawsweeper Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Oct 2, 2026
Preserve agent-qualified child-session ownership during watched registration,
and keep generation-bound claim validation in the native execution owner.

Resolve current-main integration with the fs-safe 0.23 admission contract.
Runtime regressions and managed reviews passed; final static checks will run
after this merge commit binds their baseline to the integrated main parent.
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Oct 2, 2026
@steipete
steipete merged commit 7555e3f into main Oct 2, 2026
183 of 191 checks passed
@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: memory-core Extension: memory-core gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts 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