Skip to content

fix(runtime): require cleanup evidence before releasing owned work - #139657

Merged
steipete merged 4 commits into
mainfrom
steipete/split-135868-s3-cleanup-consumers
Sep 6, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/split-135868-s3-cleanup-consumers

Conversation

@steipete

@steipete steipete commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Related: #135868
Foundation: #139517 (merged)

What Problem This Solves

Cleanup could be reported as finished after a command returned, a transport exited, or a session left its registry, even though the previous owner had not confirmed resource closure. A later CLI invocation could replace that work, and a bounded agent invocation could release its state too early. Native Codex terminal entries could also disappear before descendant cleanup finished.

This is Stage 3, part 2 of the #135868 split: cleanup evidence and its agent consumers (concern C), including the coupled Gateway close and sidecar lifetime propagation from concern F.

Why This Change Was Made

MCP and LSP use the shared stdio process owner. CLI sessions retain cleanup by execution identity, including after natural retirement or a previous timeout. Codex reports physical transport exit separately from descendant cleanup, and native execution observations remain uncertain when the pinned upstream contract supplies no OS cleanup proof.

One cleanup scope carries failures through nested agent cleanup without replacing the original result or cancellation. Retained host writes recheck their source authority. Gateway lifetime cleanup preserves failures instead of authorizing the next lifecycle. Existing best-effort plugin disposal remains compatible; explicit cleanup joins provide the stronger evidence needed by owned work.

The change removes the old late supervisor join, duplicate cleanup timers and error observers, one-use adapters, and an unnecessary asynchronous finalizer callback. Tests share typed fixtures and exercise real process/output boundaries alongside the relevant refusal and failure cases.

User Impact

Completed output and cancellation outcomes remain available. Cleanup uncertainty retains bounded agent state and locks, prevents replacement of an unclosed CLI session, and prevents unsafe lifecycle completion. This does not enable automatic recovery; activation remains in the later #135868 stage.

Evidence

The selected suites cover CLI, MCP/LSP, embedded runs, Codex, process ownership, agent authority, worker/node-host, Gateway teardown, and memory promotion. Three fixture failures found in the broad run were repaired and their complete relevant suites passed: Gateway shutdown now expects both retained failure phases; CLI replacement awaits its owner; WebSocket fake time starts after a client frame. Final focused correction proof passed 189 tests, with a separate 34-test node-host supplement.

Real macOS tests exercise anchored process groups and scope extinction. A real stdio child receives protocol EOF and drains complete output plus 8,192 Unicode diagnostic lines before successful cleanup. Seven consumer regressions failed on pre-fix production for the intended reasons and passed after repair. The import-cycle check reports zero runtime cycles. Final committed-branch independent review is clean through P2.

Full Linux changed check/build after the embedded-runner reconciliation passed in the configured Blacksmith Testbox (exit 0); its lease completed and stopped. The complete embedded-runner rerun passed 4,442 tests. The subsequent MCP-only reconciliation passed 28 focused tests, including real-child output, with its complete selected core/coreTests gate passing. Final branch review is clean through P2. Exact-head hosted CI is required before landing. Local extension declaration preparation hits parent-checkout dependency resolution; the isolated gate supplies the full check/build proof.

Judged consumer delta: production +1,581/−821 (net +760), tests +2,937/−978 (net +1,959), docs +10/−1, tooling zero. Including #139517, Stage 3 is +1,155 production and +2,593 test lines, compared with the audited source path set's +1,187 production and +2,689 tests. Remaining production growth carries native cleanup evidence, retained failed-owner state, and final-effect authority checks; the campaign still needs offsets elsewhere to reach its cumulative production limit.

Codex's pinned rust-v0.153.4 contract was checked in thread_processor.rs:2362–2423, unified_exec/process_manager.rs:1697–1728, unified_exec/process.rs:240–252, and utils/pty/src/process.rs:219–269. Their termination/list acknowledgments do not certify kernel process extinction. The paired-node exec-server caller also reads the explicit physical-exit field from the new close result.

Windows process utility paths use fixtures; native Windows utility execution was not separately demonstrated. Codex protocol tests use a synthetic app-server and source inspection of rust-v0.153.4. POSIX group ownership does not certify deliberately escaped descendants.

Review follow-through

The conflicts with #139597 and #139616 are reconciled: retain shared attempt setup/resources and a single settlement set, plus MCP shutdown fencing during data-directory preparation and protection against signaling retired owners. The directly affected cleanup suites pass all 53 cases; the final reconciled-head checks and CI are recorded before landing.

ClawSweeper's configuration/data-model flags do not identify a schema or serialized-format change. The file and memory paths add checks of the original invocation's current authority before committing effects. Existing configuration fields, stored provenance fields, and migration versions are unchanged. Retaining state after uncertain cleanup is the intended safety contract; completed command output alone does not authorize releasing it.

The optional MCP joinCleanup hook preserves existing best-effort dispose. A runtime without the hook remains usable but cannot certify shared cleanup. agent-bundle-mcp-tools.materialize.test.ts covers that case without closing shared peers. agent-exec.state-lock.test.ts covers both fresh temporary state and retained state after uncertainty, plus normal lock release. These are boundary tests, not installed-upgrade proof.

The optional rank-up move for a full fresh/existing installation matrix is deferred to the installed recovery matrix in Stage 5. Native Windows execution is also explicitly outside this lane's fixture-only proof. On that platform, as elsewhere, uncertain cleanup may block later owned work even after a command completes; this conservative outcome is intentional and remains documented.

CI caught two test-integration omissions: a Gateway fixture imported a concrete plugin test facade into core, and the new Codex suite lacked full-suite shard registration. The repair exercises the existing trusted-diagnostic service contract through the real service manager with a synthetic service, keeps the same dependency-retention assertions, and registers the Codex suite in its existing attempt shard. All 108 affected tests passed, including unchanged boundary/coverage checks; the selected changed gate and independent review passed. No guard or baseline was relaxed.

The next CI run caught unrelated suppression-inventory line drift from main in fetch-guard.socks.test.ts. Main repaired it in #139747; this branch rebased onto that merge with an unchanged patch, and both inventory tests passed. No inventory edit was added to this PR.

@clawsweeper

clawsweeper Bot commented Sep 6, 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 commands Command implementations agents Agent runtime and tooling extensions: codex size: XL labels Sep 6, 2026
@steipete
steipete marked this pull request as ready for review September 6, 2026 03:01
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Sep 6, 2026
@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 6, 2026, 1:02 AM ET / 05:02 UTC.

ClawSweeper review

What this changes

The PR carries cleanup uncertainty through agent, CLI, tool-server, and Gateway lifecycles, retains owned state when closure is unconfirmed, and rechecks authority before retained actions.

Merge readiness

⛔ Blocked before merge - 3 items remain

The cleanup-consumer work remains necessary beyond the merged process foundation. No concrete blocking defect was found in the inspected paths; the maintainer’s explicit acceptance of conservative cleanup refusal resolves the prior intent concern.

Priority: P2
Reviewed head: 5b16717a71e0ed2d5b507e8154f54ee4bd45fa09

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent owner-level repair with meaningful boundary coverage and explicit operational tradeoffs; no actionable blocking finding was established.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor proof gate is exempt for this maintainer-authored PR. Reported macOS process runs exercise cleanup ownership; inspected real-file revocation tests support the authority checks, with Windows and installed-upgrade limits explicitly retained.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor proof gate is exempt for this maintainer-authored PR. Reported macOS process runs exercise cleanup ownership; inspected real-file revocation tests support the authority checks, with Windows and installed-upgrade limits explicitly retained.
Evidence reviewed 12 items Pinned introduction scope: Inspected the complete introduced file list from the pinned merge base to HEAD, recovering paths omitted from the supplied patches. Base-only Mattermost changes were excluded.
Current main still lacks cleanup propagation: Current main's cleanup helper logs failure or timeout and returns without the new cleanup scope or retained uncertainty result. The supplied merged foundation explicitly leaves agent and transport consumers to this dependent PR.
Merged foundation provenance: The raw commit record for #139517 describes the process foundation and explicitly defers the remaining consumers. It does not establish that this PR is implemented.
Findings None None.
Security None None.

How this fits together

Agent runs launch commands and tool servers whose resources can outlive their returned output. Cleanup owners report whether those resources closed, controlling state release and whether subsequent work may proceed.

flowchart TD
  A[Agent or CLI invocation] --> B[Commands and tool servers]
  B --> C[Returned output]
  B --> D[Resource cleanup owners]
  D --> E{Closure confirmed?}
  E -->|Yes| F[Release owned state]
  E -->|No| G[Retain state and refuse replacement]
Loading

Before merge

  • Resolve merge risk (P1) - Previously successful one-shot commands can report cleanup failure and retain state or locks; failed CLI or Gateway cleanup can prevent subsequent owned work. The PR body explicitly accepts this behavior.
  • Resolve merge risk (P1) - Native Windows execution and the installed fresh/existing-state matrix remain deferred; the inspected boundary tests do not establish those deployment outcomes.
  • Review config compatibility - Confirm compatibility and upgrade impact for the changed config or default surface 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
Cleanup API compatibility 1 optional cleanup hook; existing dispose retained Older MCP runtimes remain usable while inability to certify cleanup is represented explicitly.

Stored data model

Persistent data-model change detected: serialized state: src/agents/memory-write-provenance.ts, unknown-data-model-change: src/agents/sessions/tools/edit.ts, unknown-data-model-change: src/agents/sessions/tools/write.ts, unknown-truncated-pull-files, vector/embedding metadata: src/agents/memory-write-provenance.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge-risk options

Maintainer options:

  1. Retain the accepted conservative contract (recommended)
    Proceed under the documented refusal behavior and preserve the explicit Stage 5 disposition for installed and Windows validation.

Technical review

Best possible solution:

Keep cleanup certification with resource owners, preserve completed output and existing plugin disposal, and carry the documented platform and installation validation into the recovery rollout.

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

Yes, from source: current main logs cleanup failure or timeout without carrying uncertainty to the outer owner. The PR includes targeted regressions, but this read-only review did not execute them.

Is this the best way to solve the issue?

Yes for the reviewed boundary: carrying cleanup evidence from existing owners avoids equating returned output with resource closure, while preserving best-effort plugin disposal.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 883d4d65bad1.

Labels

Label justifications:

  • P2: This is a substantive lifecycle reliability repair without evidence of an urgent user-facing regression requiring escalation.
  • merge-risk: 🚨 compatibility: Stronger cleanup certification can change successful command outcomes and adds an optional plugin cleanup contract.
  • merge-risk: 🚨 availability: Unconfirmed cleanup intentionally prevents replacement or lifecycle completion, potentially blocking subsequent work.
  • 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: The ordinary contributor proof gate is exempt for this maintainer-authored PR. Reported macOS process runs exercise cleanup ownership; inspected real-file revocation tests support the authority checks, with Windows and installed-upgrade limits explicitly retained.

Evidence

What I checked:

  • Pinned introduction scope: Inspected the complete introduced file list from the pinned merge base to HEAD, recovering paths omitted from the supplied patches. Base-only Mattermost changes were excluded. (5b16717a71e0)
  • Current main still lacks cleanup propagation: Current main's cleanup helper logs failure or timeout and returns without the new cleanup scope or retained uncertainty result. The supplied merged foundation explicitly leaves agent and transport consumers to this dependent PR. (src/agents/run-cleanup-timeout.ts:88, 883d4d65bad1)
  • Merged foundation provenance: The raw commit record for fix(process): require cleanup evidence before releasing owned work #139517 describes the process foundation and explicitly defers the remaining consumers. It does not establish that this PR is implemented. (220578ba3408)
  • Maintainer disposition and review continuity: The captured PR body accepts retained state and replacement refusal, preserves optional MCP cleanup compatibility, and explicitly defers installed-upgrade and native Windows validation. The previous completed review reports no findings or published rank-up moves. Its earlier SHA was unavailable locally, so patch equivalence across the rebase was not independently established. (5b16717a71e0)
  • Affirmative Codex dependency boundary: The client distinguishes physical transport exit from cleanup certification and marks observed native execution uncertain; the PR explicitly bases this on the pinned Codex terminal contract. (extensions/codex/src/app-server/client.ts:752, 5b16717a71e0)
  • Pinned upstream termination semantics: Personally inspected rust-v0.153.4: local terminate_confirmed requests termination and signals logical exit without awaiting kernel extinction. The backing cache's origin was verified as https://github.com/openai/codex.git. (codex-rs/core/src/unified_exec/process.rs:240, 3d2ee51ca2d5)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Sebastien Tardif: 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 (3 earlier review cycles)
  • reviewed 2026-09-06T03:09:36.130Z sha f57f2b4 :: blocked before merge. :: none
  • reviewed 2026-09-06T04:02:31.688Z sha cb3bd2bd5bbed4ab30ba10a8ee9ebcdf99b5e868 :: blocked before merge. :: none
  • reviewed 2026-09-06T04:48:43.326Z sha f7bc2cebc6bf2051a366a34b71fad0c68dda65fb :: blocked before merge. :: none

@steipete
steipete force-pushed the steipete/split-135868-s3-cleanup-consumers branch from f57f2b4 to cb3bd2b Compare September 6, 2026 03:56
@steipete
steipete force-pushed the steipete/split-135868-s3-cleanup-consumers branch from cb3bd2b to f7bc2ce Compare September 6, 2026 04:40
Keep command results and cancellation separate from cleanup uncertainty.
MCP, LSP, Codex, CLI and Gateway owners retain cleanup evidence before
releasing resources or replacing a prior execution. Keep bounded agent
state when closure cannot be confirmed and fence retained host writes.

Stage 3 consumer extraction from #135868, following the process foundation
in #139517. Remove duplicate cleanup timers, one-use adapters, and the
unused asynchronous finalizer callback while preserving plugin disposal
compatibility.
@steipete
steipete force-pushed the steipete/split-135868-s3-cleanup-consumers branch from f7bc2ce to 5b16717 Compare September 6, 2026 04:54
@steipete
steipete merged commit bcef3b3 into main Sep 6, 2026
181 checks passed
@steipete
steipete deleted the steipete/split-135868-s3-cleanup-consumers branch September 6, 2026 05:20
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 docs Improvements or additions to documentation extensions: codex gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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