Skip to content

fix(agents): persist terminal cleanup revocation before reset - #146565

Merged
steipete merged 2 commits into
mainfrom
codex/swarm-durable-reset-cleanup
Sep 13, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/swarm-durable-reset-cleanup

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Split from #130741. Prerequisite: #146542.

What Problem This Solves

A completed collector can retain a cleanup retry after an earlier deletion failed. Resetting its session between retries could publish a successor that the old cleanup later deletes.

User Impact

Reset durably revokes completed runs' session cleanup before publishing the new session generation. Active and yielded continuations remain eligible, and collector results and task outcomes keep their normal retention.

Why This Change Was Made

The existing lifecycle owner persists its existing suppression flag from the reset owner's synchronous commit guard. Registry hydration and strict persistence failure block reset; a pending completion capture also asks the caller to retry. A later reset failure or Gateway stop cannot restore old cleanup authority, so the original session may remain with cleanup disabled after revocation was saved. This is the accepted fail-closed outcome. Retained kill claims cannot undo revocation.

The reset owner keeps canonical agent/session selection and existing post-wait authority checks. No new schema or persistent field is introduced.

Evidence

Sixteen concrete assertions failed before repair, with five controls passing; all 21 new cases pass afterward. The complete 314 tests across nine files pass, including reset/global aliases, real boundary and archive cases. The normal build, full canonical gate and independent P1 review pass. The reviewed eight-file source remains byte-identical through the patch-identical base refresh.

Write-failure and reopen tests use isolated real SQLite state; they are not an OS-kill crash experiment. The broader real-provider and 500 ms responsiveness work remains tracked in #130741.

@clawsweeper

clawsweeper Bot commented Sep 12, 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 app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 23:41
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 8:18 PM ET / September 13, 2026, 00:18 UTC (Revision 3).

ClawSweeper review

What this changes

The branch persists completed subagents’ cleanup revocation before session reset and replaces cached reconciliation reads with scoped reads and cleanup identity fences.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

This remains useful, protected maintainer work that current main does not implement. The previously reported read-failure isolation defect remains unresolved in the pinned head.

Priority: P2
Reviewed head: f1912fb6acc06924d25f19f38f2fe80b0f7afe31

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The owner-level repair and substantial boundary coverage are useful, but the repeated availability defect still blocks readiness.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied maintainer-author exemption applies. Source-reviewed reset/delete boundary tests cover revocation, successor preservation, write failure, and reopen; historical UI screenshots do not independently prove durability, and no new runtime execution is claimed.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied maintainer-author exemption applies. Source-reviewed reset/delete boundary tests cover revocation, successor preservation, write failure, and reopen; historical UI screenshots do not independently prove durability, and no new runtime execution is claimed.
Evidence reviewed 9 items Introduced failure remains: The pinned merge-base-to-head diff introduces eager cleanup identity capture. freezeSessionIdentity calls the throwing singleton reader before recovery begins; sweepOnce has only a finally block, and runTick catches the failure around the entire pass.
Concrete malformed-row trigger: The modified metadata test writes malformed session JSON and now expects the reconciliation read to throw. The singleton reader explicitly rejects invalid persisted rows; this is a supported source-level trigger, not a hypothetical transport error.
Other affected reconciliation callers: Restore activation reads each child without per-entry exception isolation. The sweeper's stale-run completion path and provisional-kill reconciliation also consume the newly strict reader without isolating read failures from sibling work.
Findings 1 actionable finding [P2] Isolate unreadable child rows before collecting cleanup identities
Security None None.

How this fits together

The subagent registry tracks delegated work, retained results, and delayed cleanup. Gateway session reset must retire old cleanup authority before publishing a replacement session generation.

flowchart TD
  A[Session reset request] --> B[Gateway reset owner]
  B --> C[Validate current session]
  C --> D[Persist cleanup revocation]
  D --> E[Publish reset generation]
  F[Delayed cleanup retry] --> G[Check suppression and session identity]
  D --> G
  G --> H[Delete original or preserve successor]
Loading

Before merge

  • Isolate unreadable child rows before collecting cleanup identities (P2) - The prior blocker remains: an expired candidate with malformed persisted session JSON makes freezeSessionIdentity() throw before the recovery loop starts. runTick() catches only the entire sweep, so each retry again prevents healthy siblings from recovering. The modified metadata test explicitly demonstrates the reader's new throwing contract. Catch and defer the affected entry without treating a failed read as an absent session, and apply that isolation to restore activation and the other newly strict reconciliation reads.
  • Resolve merge risk (P1) - Malformed retained session data can prevent unrelated runs from reaching recovery or cleanup on every sweep; the prevalence of such rows in existing installations is unknown.
  • Resolve merge risk (P1) - Reset now fails when registry hydration, revocation persistence, or completion settling prevents safe publication. As explicitly accepted in the linked discussion, a later reset failure can leave the original session with cleanup disabled.
  • Complete next step (P2) - Resolve the repeated per-entry read-failure isolation finding, including healthy-sibling regression coverage, and carry the prerequisite fix into this branch.

Findings

  • [P2] Isolate unreadable child rows before collecting cleanup identities — src/agents/subagents/registry/subagent-registry-sweeper.ts:279-283
Agent review details

Security

None.

PR surface

Source +45, Tests +833, Docs +7. Total +885 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 9 166 121 +45
Tests 5 884 51 +833
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 1057 172 +885

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Isolate strict-read failures (recommended)
    Defer and report the unreadable child without aborting sibling recovery, and carry the prerequisite repair into this branch.

Technical review

Best possible solution:

Preserve durable revocation and successor identity fences while deferring unreadable children individually, so healthy siblings continue and failed reads never authorize cleanup.

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

Yes, from source: an expired cleanup candidate with malformed persisted session JSON throws during identity capture before healthy recovery candidates run. No execution reproduction was performed in this read-only review.

Is this the best way to solve the issue?

The durable owner-level revocation is appropriate and its fail-closed tradeoff is documented; the branch is not ready while strict reconciliation read failures can escape across unrelated runs.

Full review comments:

  • [P2] Isolate unreadable child rows before collecting cleanup identities — src/agents/subagents/registry/subagent-registry-sweeper.ts:279-283
    The prior blocker remains: an expired candidate with malformed persisted session JSON makes freezeSessionIdentity() throw before the recovery loop starts. runTick() catches only the entire sweep, so each retry again prevents healthy siblings from recovering. The modified metadata test explicitly demonstrates the reader's new throwing contract. Catch and defer the affected entry without treating a failed read as an absent session, and apply that isolation to restore activation and the other newly strict reconciliation reads.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 292e1618d9ce.

Labels

Label justifications:

  • P2: This addresses a bounded reset/cleanup race, with a concrete remaining reconciliation defect.
  • merge-risk: 🚨 availability: The introduced eager singleton reads allow one malformed session row to abort recovery for unrelated subagents.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The supplied maintainer-author exemption applies. Source-reviewed reset/delete boundary tests cover revocation, successor preservation, write failure, and reopen; historical UI screenshots do not independently prove durability, and no new runtime execution is claimed.

Evidence

What I checked:

Likely related people:

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

Rank-up moves

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

  • Add per-entry read-failure isolation and regression coverage proving that an unreadable cleanup candidate cannot block healthy recovery or restore activation.

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 (2 earlier review cycles)
  • reviewed 2026-09-12T23:40:53.311Z sha 24e956f2dab39ffdcda0c0e54d578bd374bafffa :: blocked before merge. :: [P2] Isolate unreadable child rows before collecting cleanup identities
  • reviewed 2026-09-12T23:47:51.825Z sha 24e956f2dab39ffdcda0c0e54d578bd374bafffa :: blocked before merge. :: [P2] Isolate unreadable child rows before collecting cleanup identities

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 12, 2026
@steipete
steipete force-pushed the codex/swarm-durable-reset-cleanup branch from 24e956f to f1912fb Compare September 13, 2026 00:12
@openclaw-barnacle openclaw-barnacle Bot removed app: web-ui App: web-ui scripts Repository scripts labels Sep 13, 2026
@steipete
steipete merged commit 869851c into main Sep 13, 2026
185 checks passed
@steipete
steipete deleted the codex/swarm-durable-reset-cleanup branch September 13, 2026 01:42
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
…aw#146565)

* fix(agents): reconcile subagents through scoped session owner

* fix(agents): persist terminal cleanup revocation before reset
etzelm added a commit to etzelm/openclaw that referenced this pull request Sep 13, 2026
…nts_wait forever

- Reject sessions_yield from a Swarm collector turn before any claim source
  runs, so no durable yield intent is recorded against a child row, and return
  a diagnostic telling the model to finish the turn so its collected result is
  recorded for whoever waits on the run. This admission layer only sees turns
  whose tool factory is given collector context.
- Settle a yielded terminal for a run with collect === true as an ordinary ok
  terminal on both the lifecycle-event path and the agent.wait observer path.
  A collector is read by an explicit wait and never receives a requester
  continuation, so a parked collector row has no wake source at all and its
  waiter blocks until the operator gives up.
- Keep a result the collector already captured through structured_output; a
  collector that captured nothing keeps the existing "structured_output was not
  called" diagnostic instead of having a valid result overwritten.
- Settle as ok rather than a cancellation: a yielded terminal can also look
  aborted, and any other settlement would reintroduce the false cancellation
  notice from openclaw#92448.
- Leave every non-collector yielded terminal on the shipped
  markSubagentRunPausedAfterYield path. The documented sub-agent
  self-yield-for-external-work contract preserved in openclaw#125850 is unchanged;
  openclaw#141474 carries clawsweeper:needs-product-decision for that arm.
- Write no pauseReason on the settle path, so downstream
  pauseReason === "sessions_yield" guards, openclaw#146248 retention, and the paused-run
  adoption added by openclaw#146667 are untouched: they select paused rows, which a
  settled collector never becomes.
- Document the collector rule in the sessions_yield and Swarm docs, qualified to
  demonstrated behavior rather than universal tool hiding: the tool is withheld
  where collector context reaches the tool factory, such as the embedded runner;
  a CLI-backed collector turn through the Gateway tool resolver can still be
  offered it and receive a successful yielded result; and in every case the
  terminal settle is what resolves the waiter.
- Repoint the yielded-continuation reset case added by openclaw#146565 at an ordinary
  announcing sub-agent fixture, with every assertion unchanged, because a
  yielded collector is now settled at its terminal and is no longer a
  continuation to preserve. Add a sibling case pinning that contract: a yielded
  collector completes with no pauseReason and a frozen collectorCompletion, and
  sessions.reset then revokes its cleanup as a completed run.
- Await the durable cleanup mark of the settled collector in that reset case,
  not the residual-roots deadline. Its cleanup: "delete" work is dispatched
  detached and takes 0.5 s to 3.9 s locally depending on whether the SQLite
  reclamation worker starts cold, so the one-second vi.waitFor inside
  settleSubagentRegistryPersistenceWork could observe a live registry root under
  CI load. The guard and every assertion are unchanged.

Related: openclaw#141474
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 gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant