Skip to content

refactor(acpx): complete lease ownership and remove legacy reaper heuristics - #121016

Merged
steipete merged 2 commits into
mainfrom
steipete/acp-lease-coverage
Aug 9, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/acp-lease-coverage

Conversation

@steipete

@steipete steipete commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Related: #120937

What Problem This Solves

ACPX startup cleanup could not safely resolve generated-wrapper launches whose lease was persisted before spawn but whose PID was never recorded. Generated availability and doctor probes also entered upstream launch code without first persisting an OpenClaw ownership lease. That left cleanup dependent on aggregate command-marker scanning and made a specific pending lease vulnerable to being retired from evidence that did not identify that lease.

Why This Change Was Made

Generated-wrapper probes now use the same lease-first launch scope as sessions: OpenClaw persists an open rootPid: 0 lease before entering upstream code, then promotes it when the session-store callback records a PID. Startup recovery matches a pending lease only when the live process command contains the exact wrapper path, lease id, and Gateway instance id; ambiguous, unavailable, foreign-instance, and Windows evidence fails closed. Aggregate marker cleanup is kept separate from individual lease state transitions, and lease-aware wrapper roots are excluded from that fallback.

This is an intentional partial completion of the work order. The PR title reflects the requested end state, but deleting the legacy marker heuristics is blocked by the order's escape hatch:

  • Generated wrapper probes: confirmed gap, fixed with pre-spawn lease persistence and exact post-probe inspection.
  • rootPid: 0 crash windows: confirmed gap, fixed for generated wrappers. An uncertain launch leaves an open lease; recovery signals only one exact same-instance wrapper match.
  • Direct agent spawns: confirmed gap, not fixed. Published acpx owns command resolution and process creation without pre-spawn identity injection or a post-spawn PID callback.
  • Reparented descendants: confirmed gap, not fixed. Detached adapter descendants do not retain the lease arguments and the wrapper does not report a stable process-group identity.
  • Windows containment: not proven and intentionally fails closed because equivalent live process enumeration and tree termination are unavailable here.

The @zed-industries/codex-acp-* and /acpx/dist/ marker matching therefore remains narrowly enabled for unleased direct-agent processes and reparented descendants after an uncertain spawn. It cannot retire any specific lease. Removing it now would reduce orphan coverage and violate the safety invariant.

The version 1 lease shape is unchanged from the latest shipped tag checked for this work, v2026.7.2-beta.7; no plugin doctor migration is required. Legacy session records without a lease id retain their existing fail-closed cleanup path.

User Impact

Operators get safer ACPX restart cleanup for generated wrapper probes and pending launches: OpenClaw can recover an exact same-Gateway orphan without risking another Gateway instance's process. There is no new configuration or user-visible command change. Direct-agent, reparented-descendant, and Windows cleanup remain conservative until upstream ownership hooks and stable tree identity exist.

Evidence

  • node scripts/run-vitest.mjs extensions/acpx — 19 files, 256 tests passed on final head.
  • node scripts/check-changed.mjs — passed before the final base refresh on Blacksmith Testbox tbx_01kzjwahypjvw1g4gsh1jf7v7g; run 31305084480.
  • node scripts/check-docs-mdx.mjs docs/refactor/acp.md — passed.
  • node scripts/check-docs-i18n-glossary.mjs — passed.
  • node scripts/docs-link-audit.mjs — 6,411 internal links checked, 0 broken.
  • git diff --check origin/main...HEAD — passed on final head.
  • Final structured autoreview before commit: clean, exit 0, confidence 0.98.
  • Exact-head CI rerun 31305893627 failed check-plugin-sdk-api-baseline. The same generate-plugin-sdk-api-baseline.ts --check command fails with the identical manifest mismatch on a clean archive of current origin/main (7d4066639ef008c122c8243ce08d834227a494f3), so the work order's one unrelated-failure rerun was exhausted and no out-of-scope Plugin SDK/generated-baseline change was added here.
  • LOC: production +190/-34 (net +156); tests +431/-14 (net +417); docs +118/-240 (net -122). The production growth establishes the missing ownership boundary and exact live-evidence recovery while retaining the upstream-blocked safety fallback.

@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: acpx size: L maintainer Maintainer-authored PR labels Aug 9, 2026
@steipete
steipete marked this pull request as ready for review August 9, 2026 09:16
@steipete
steipete force-pushed the steipete/acp-lease-coverage branch from 8e8f630 to a0d7719 Compare August 9, 2026 09:26
@steipete steipete self-assigned this Aug 9, 2026
@steipete
steipete force-pushed the steipete/acp-lease-coverage branch from a0d7719 to 1722626 Compare August 9, 2026 09:44
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 9, 2026, 5:50 AM ET / 09:50 UTC.

ClawSweeper review

What this changes

The PR records ACPX generated-wrapper probe leases before launch and recovers pending processes only when wrapper, lease, and Gateway identities exactly match.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: this PR’s retained probe leases can exhaust the capped lease store and evict an older live session lease, losing process-cleanup ownership. The exact-match recovery design is otherwise well placed, but the bounded-state regression needs repair before merge.

Priority: P2
Reviewed head: 1722626154872ee3997be5296b69e80309d968bd

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The ownership design is promising, but the bounded-state regression is a concrete merge blocker.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; the body reports focused automated validation, but no independent live process trace was reviewed.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; the body reports focused automated validation, but no independent live process trace was reviewed.
Evidence reviewed 5 items Unbounded retained probe leases: Each probe creates a new lease, and completed or absent-wrapper probe leases are deliberately retained open rather than finalized or coalesced.
Capacity eviction can discard ownership: The ACPX lease namespace is capped at 4,096 entries; the plugin state store uses oldest-entry eviction, with repository coverage for that behavior.
Current tests do not exercise repeated probe retention: The new tests cover one retained probe and exact recovery cases, but not enough probes to preserve an older real-process lease at store capacity.
Findings 1 actionable finding [P2] Bound retained probe uncertainty
Security None None.

How this fits together

ACPX launches ACP sessions and generated wrapper processes from OpenClaw. Its lease store carries ownership into startup recovery so cleanup can terminate only processes belonging to the current Gateway.

flowchart LR
  A[Probe or ACP session] --> B[Persist process lease]
  B --> C[Launch generated wrapper]
  C --> D[Record process identity]
  D --> E[Startup recovery]
  E --> F[Validate exact ownership]
  F --> G[Terminate owned process]
  B --> H[Bounded lease store]
Loading

Before merge

  • Bound retained probe uncertainty (P2) - Every completed or absent-wrapper probe now retains a fresh open lease. The lease store caps entries at 4,096 and evicts the oldest, so repeated availability or doctor probes can evict an older live session lease and lose its cleanup identity. Coalesce or bound probe uncertainty and add capacity coverage that preserves real leases.
  • Resolve merge risk (P1) - Repeated availability or doctor probes can retain 4,096 unique pending leases and silently evict an older real-process lease, preventing safe later cleanup.
  • Resolve merge risk (P1) - Published ACPX and Codex runtime sources could not be inspected, so the claimed upstream launch-hook limitation remains unverified.
  • Complete next step (P2) - A protected maintainer PR has a concrete bounded-state blocker that needs owner-directed repair and exact-head validation.

Findings

  • [P2] Bound retained probe uncertainty — extensions/acpx/src/runtime.ts:1267-1307
Agent review details

Security

None.

PR surface

Source +156, Tests +417, Docs -122. Total +451 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 187 31 +156
Tests 3 431 14 +417
Docs 1 133 255 -122
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 751 300 +451

Review metrics

Metric Value Why it matters
Production and test delta production +187/-31 (net +156); tests +431/-14 (net +417) The production growth establishes a new ownership boundary, so bounded persistent-state behavior needs explicit regression coverage.

Stored data model

Persistent data-model change detected: migration/backfill/repair: extensions/acpx/src/runtime.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Bound retained probe uncertainty (recommended)
    Coalesce or bound retained probe evidence and prove that capacity pressure cannot evict an open real-process lease.
  2. Pause the cleanup expansion
    Leave this PR unmerged until the retained-probe state can preserve session ownership under repeated diagnostics.

Technical review

Best possible solution:

Represent unresolved probe ownership as bounded uncertainty per wrapper and Gateway, preserving real session leases, and add a capacity regression test before merge.

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

Yes from source: complete or fail more than 4,096 probe launches while retaining their pending leases, then observe oldest-entry eviction remove an earlier live lease.

Is this the best way to solve the issue?

No: producer-side lease persistence and exact recovery are appropriate, but durable per-probe UUID leases violate the bounded-store invariant; bounded aggregation is safer.

Full review comments:

  • [P2] Bound retained probe uncertainty — extensions/acpx/src/runtime.ts:1267-1307
    Every completed or absent-wrapper probe now retains a fresh open lease. The lease store caps entries at 4,096 and evicts the oldest, so repeated availability or doctor probes can evict an older live session lease and lose its cleanup identity. Coalesce or bound probe uncertainty and add capacity coverage that preserves real leases.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: The patch can lose ACPX cleanup ownership after enough routine probes, but the reported impact is bounded to this plugin lifecycle.
  • add merge-risk: 🚨 other: The new retained probe records can evict a live ownership lease from the capped state store, a merge risk outside the specific label taxonomy.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; the body reports focused automated validation, but no independent live process trace was reviewed.

Label justifications:

  • P2: The patch can lose ACPX cleanup ownership after enough routine probes, but the reported impact is bounded to this plugin lifecycle.
  • merge-risk: 🚨 other: The new retained probe records can evict a live ownership lease from the capped state store, a merge risk outside the specific label taxonomy.
  • 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: This maintainer-authored PR is outside the external-contributor proof gate; the body reports focused automated validation, but no independent live process trace was reviewed.

Evidence

What I checked:

  • Unbounded retained probe leases: Each probe creates a new lease, and completed or absent-wrapper probe leases are deliberately retained open rather than finalized or coalesced. (extensions/acpx/src/runtime.ts:1035, 172262615487)
  • Capacity eviction can discard ownership: The ACPX lease namespace is capped at 4,096 entries; the plugin state store uses oldest-entry eviction, with repository coverage for that behavior. (extensions/acpx/src/process-lease.ts:113, 135278c8968f)
  • Current tests do not exercise repeated probe retention: The new tests cover one retained probe and exact recovery cases, but not enough probes to preserve an older real-process lease at store capacity. (extensions/acpx/src/runtime.test.ts:314, 172262615487)
  • Related work provenance: The merged related ACPX cleanup change intentionally retained marker reaping; it is an ancestor of this branch, so this PR owns the subsequent generated-probe lease gap rather than duplicating that work. (extensions/acpx/src/service.ts:259, cc4cc83e3622)
  • Dependency-contract limitation: The pinned published ACPX/Codex sources and sibling ../codex source were unavailable because DNS failed, so the asserted upstream callback limitation was not independently verified. (extensions/acpx/package.json:1, 172262615487)

Likely related people:

  • steipete: Authored the current branch and the recent merged ACPX cleanup work that forms its direct predecessor. (role: recent ACPX runtime contributor; confidence: high; commits: 172262615487, cc4cc83e3622; files: extensions/acpx/src/runtime.ts, extensions/acpx/src/service.ts, extensions/acpx/src/process-reaper.ts)
  • shakkerdroid: History attributes lease identity, retention, serialized transitions, and retryable lease preservation to this area. (role: historical lease-lifecycle contributor; confidence: high; commits: f41b39147f, a22a3ac8ff, 4b0d01b1b0; files: extensions/acpx/src/process-lease.ts, extensions/acpx/src/runtime.ts)
  • VincentKoc: Feature history shows substantial authorship across ACPX runtime and lease files. (role: adjacent ACPX runtime contributor; confidence: medium; files: extensions/acpx/src/runtime.ts, extensions/acpx/src/process-lease.ts)

Rank-up moves

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

  • Bound or coalesce retained probe leases and add a capacity regression test.
  • Independently inspect the pinned ACPX and Codex contracts when source access is restored.
  • Rerun exact-head CI after the repair.

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.

@steipete
steipete merged commit a9d3980 into main Aug 9, 2026
117 checks passed
@steipete
steipete deleted the steipete/acp-lease-coverage branch August 9, 2026 10:15
@steipete

steipete commented Aug 9, 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

docs Improvements or additions to documentation extensions: acpx maintainer Maintainer-authored PR merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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