Skip to content

fix: preserve managed checkouts with shared project references - #126004

Merged
steipete merged 3 commits into
mainfrom
steipete/practical-noyce-7366c1
Aug 19, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/practical-noyce-7366c1

Conversation

@steipete

@steipete steipete commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes #125976

What Problem This Solves

Fixes an issue where removing one managed project could delete its physical checkout while another selectable project registration still referenced the same canonical repository root. The surviving project then pointed at a directory that no longer existed.

Why This Change Was Made

Project registration and managed-checkout deletion now share a lifecycle lease keyed by the canonical repository root. Every return of an existing canonical project is serialized under that checkout lifecycle and re-read before it can be returned, while the clone lease remains the outer operation boundary. Registration deduplicates canonical roots transactionally, and deletion removes one registry reference and re-reads sibling rows immediately before physically deleting only the final managed checkout.

For legacy mixed registered/cloned rows, the removal transaction transfers managed ownership and the clone origin to the surviving registered sibling. That keeps the checkout selectable while it is referenced and preserves a later path to final managed-checkout cleanup. Existing workspace, worktree, and session protections remain in place. No SQLite schema version changes are required.

The Gateway chat test helper now drains canonical root work first, then retains the successful terminal assertion through a nonblocking agent.wait(..., 0). This prevents the known compact-shard cleanup cascade without weakening the acceptance-path outcome check.

User Impact

Operators can safely remove duplicate or overlapping managed project entries without invalidating the remaining project. Concurrent add/remove operations cannot return a selectable project whose checkout has just been deleted, and legacy mixed-source registrations do not strand a managed checkout after the final usable reference is removed.

Evidence

  • node scripts/run-vitest.mjs src/projects/project-registry.test.ts src/gateway/server-methods/projects.test.ts — 24 registry tests and 12 Gateway project RPC tests passed after the final rebase.
  • OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat.test.ts — 55/55 passed serially after the final rebase.
  • node scripts/run-vitest.mjs src/gateway/server-methods/chat-send-dispatch-errors.test.ts src/process/gateway-work-admission.test.ts — the cleanup-owner suites passed 5/5 and 18/18 on the reviewed working tree.
  • Fresh Blacksmith Testbox reproduction against the actual synthetic merge baseline: 161 passed / 2 failed before the cleanup synchronization.
  • The repaired exact 24-file compact shard passed 399/399 on Blacksmith Testbox for the retained project/Gateway candidate.
  • node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo and node scripts/run-tsgo-core-test-shards.mjs passed after the final rebase.
  • Targeted Oxfmt and Oxlint passed for the reviewed changed files.
  • pnpm check:import-cycles — zero runtime value cycles.
  • node scripts/check-native-state-schema-version.mjs — schema remains v9.
  • git diff --check passed.
  • Fresh branch autoreview against origin/main reported no accepted/actionable findings (overall correctness 0.97).
  • Production LOC: +233/-78 (net +155); tests: +203/-5 (net +198). The production growth establishes the canonical checkout lifecycle ownership boundary, including serialized existing-project returns and transferable legacy managed ownership; the test growth protects the project lifecycle races and successful Gateway terminal outcomes.

AI-assisted: implementation and review were performed with coding agents under maintainer supervision.

@clawsweeper

clawsweeper Bot commented Aug 18, 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 gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 18, 2026
@steipete
steipete marked this pull request as ready for review August 18, 2026 20:55
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 9:28 PM ET / August 19, 2026, 01:28 UTC.

ClawSweeper review

What this changes

The PR serializes managed-project registration and deletion by canonical checkout path, preserves shared managed checkouts, and makes Gateway chat cleanup retain its terminal-success assertion.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking correctness findings at the current head. The earlier lifecycle and terminal-assertion concerns are addressed; this maintainer-labeled PR should remain open for exact-head CI and normal owner review.

Priority: P2
Reviewed head: 78d878b5a17cc0f7944cedc8df40df37a2b2b504

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a coherent owner-boundary repair with focused race coverage; pending exact-head CI is the remaining merge gate.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless provides focused Testbox and suite evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless provides focused Testbox and suite evidence.
Evidence reviewed 7 items Lifecycle owner boundary: Registration takes a checkout-root lease, re-resolves the checkout after acquiring it, and deduplicates canonical roots inside the write transaction.
Existing-return race repaired: The clone path now retries existing canonical-project lookup under the same checkout lifecycle lease before returning a row.
Final-reference deletion: Removal atomically deletes one cloned row, retains a sibling checkout reference when present, and transfers managed ownership to a legacy registered sibling before physical deletion is considered.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/projects/project-registry.test.ts src/gateway/server-methods/projects.test.ts

Result: PASS (completed)

runner@runnervmzvulz:/tmp/clawsweeper-live-proof-126004-qEdbnv/target$ node scripts/run-vitest.mjs src/projects/project-registry.test.ts src/gateway/server-meth
ods/projects.test.ts
[test] starting test/vitest/vitest.unit.config.ts
node scripts/run-vitest.mjs src/projects/project-registry.test.ts src/gateway/server-methods/projects.test.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126004-qEdbnv/target

 ✓  unit  src/projects/project-registry.test.ts (24 tests) 9484ms
     ✓ lazily ensures the additive table exactly once per database  4141ms
     ✓ registers, orders, resolves real paths, deduplicates roots, and removes rows  1539ms
     ✓ clones a local bare fixture through the internal full-history clone boundary  2658ms
     ✓ serializes an existing cloned-project return with checkout deletion  356ms
     ✓ serializes registration with the final managed-checkout deletion boundary  473ms

 Test Files  1 passed (1)
      Tests  24 passed (24)
   Start at  01:29:27
   Duration  11.46s (transform 1.50s, setup 889ms, import 793ms, tests 9.48s, environment 0ms)

[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126004-qEdbnv/target





























Assertions:

  • PASS expect_output: Test Files

How this fits together

Managed project records in the shared state database feed Gateway project operations and point to local checkouts. Registration, deletion, sessions, worktrees, and agent work must agree on whether a checkout remains usable.

flowchart LR
  A[Project add or remove request] --> B[Project registry]
  B --> C[Checkout lifecycle lease]
  C --> D[Shared state database]
  C --> E[Managed checkout]
  E --> F[Gateway project operations]
  F --> G[Sessions and worktrees]
Loading

Before merge

  • Resolve merge risk (P1) - The change modifies persisted project-row ownership semantics; the exact-head project and Gateway suites must finish green before merge, particularly for legacy mixed registered/cloned rows.
  • Complete next step (P2) - No mechanical repair remains; this maintainer-labeled PR needs normal exact-head CI completion and owner review.
Agent review details

Security

None.

PR surface

Source +155, Tests +198. Total +353 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 233 78 +155
Tests 3 203 5 +198
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 436 83 +353

Review metrics

Metric Value Why it matters
Production versus test delta production +155 net, tests +198 net The added production code establishes one checkout lifecycle owner across registration, existing-project returns, and deletion; the test growth covers the resulting races and legacy ownership transfer.

Merge-risk options

Maintainer options:

  1. Merge after exact-head lifecycle validation (recommended)
    Accept the compatibility-sensitive lifecycle change once the pending exact-head checks confirm shared and legacy project rows retain a usable checkout through removal.

Technical review

Best possible solution:

Land the canonical checkout-lifecycle repair once exact-head CI confirms the focused registry and Gateway paths, retaining the single lease boundary rather than restoring uncoordinated early returns or deletion steps.

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

Yes, from source: concurrent existing-project return or registration can overlap final managed-checkout deletion; the PR adds deferred-order regressions for both paths.

Is this the best way to solve the issue?

Yes: the checkout-root lease at the registry/clone owner is preferable to a Gateway-only guard because every existing return, registration, and final deletion passes through it.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless provides focused Testbox and suite evidence.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This fixes a managed-project lifecycle race that can leave a selectable project pointing at a deleted checkout.
  • merge-risk: 🚨 compatibility: The PR changes persisted project registry ownership and managed-checkout deletion behavior for existing installations.
  • 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: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless provides focused Testbox and suite evidence.

Evidence

What I checked:

  • Lifecycle owner boundary: Registration takes a checkout-root lease, re-resolves the checkout after acquiring it, and deduplicates canonical roots inside the write transaction. (src/projects/project-registry.ts:247, 78d878b5a17c)
  • Existing-return race repaired: The clone path now retries existing canonical-project lookup under the same checkout lifecycle lease before returning a row. (src/projects/project-clone.ts:63, 78d878b5a17c)
  • Final-reference deletion: Removal atomically deletes one cloned row, retains a sibling checkout reference when present, and transfers managed ownership to a legacy registered sibling before physical deletion is considered. (src/projects/project-registry.ts:310, 78d878b5a17c)
  • Gateway caller and reference protection: The Gateway removal handler delegates checkout lifecycle ownership to the project layer and checks workspace, worktree, and active-session references before removal. (src/gateway/server-methods/projects.ts:391, 78d878b5a17c)
  • Regression coverage: Focused tests cover add-versus-delete serialization, registration versus final deletion, legacy mixed-source survivor transfer, configured workspace protection, and retained Gateway terminal assertions. (src/projects/project-registry.test.ts:207, 78d878b5a17c)
  • Current-main comparison: The base implementation returned an existing canonical row before entering the clone lease and physically deleted a managed checkout before removing its registry row; the PR moves both operations behind the checkout lifecycle boundary. (src/projects/project-clone.ts:63, 61eb7b932b91)

Likely related people:

  • steipete: Peter Steinberger authored the current lifecycle completion commit and the available history shows repeated work on the shared state-lease owner used by this repair. (role: state-lifecycle contributor; confidence: high; commits: 78d878b5a17c, 39b39ca6eec6; files: src/projects/project-registry.ts, src/projects/project-clone.ts, src/state/openclaw-state-lease.ts)

Rank-up moves

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

  • Wait for the pending exact-head checks to complete green.

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-08-18T21:05:03.396Z sha ed6fcb071a67acf0f698725d6541910b03e1d90d :: needs changes before merge. :: [P2] Serialize existing-project returns with checkout deletion | [P2] Clean up the final mixed-source managed checkout
  • reviewed 2026-08-18T23:47:13.012Z sha f3158e1fcbfef5e0a033819f9da65d8f3343fcc8 :: found issues before merge. :: [P2] Serialize existing-project returns with checkout deletion | [P2] Clean up the final mixed-source managed checkout | [P2] Retain successful-completion assertions in chat tests
  • reviewed 2026-08-19T00:40:44.651Z sha 0b34093 :: found issues before merge. :: [P2] Serialize existing-project returns with checkout deletion | [P2] Clean up the final mixed-source managed checkout | [P2] Retain terminal-success assertions in chat cleanup

@steipete
steipete force-pushed the steipete/practical-noyce-7366c1 branch 2 times, most recently from f3158e1 to 6930b6f Compare August 19, 2026 00:25
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Aug 19, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@steipete
steipete force-pushed the steipete/practical-noyce-7366c1 branch from 6930b6f to 0b34093 Compare August 19, 2026 00:35
@openclaw-barnacle openclaw-barnacle Bot removed the agents Agent runtime and tooling label Aug 19, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 19, 2026
@steipete
steipete force-pushed the steipete/practical-noyce-7366c1 branch from 0b34093 to 78d878b Compare August 19, 2026 01:23
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready evidence for prepared exact head 78d878b5a17cc0f7944cedc8df40df37a2b2b504:

  • Exact-head CI run 32204781437 completed green with zero non-green checks, and GitHub reports the PR mergeable. scripts/pr prepare-run completed with hosted exact/recent-parent gates and preserved the same PR head.
  • node scripts/run-vitest.mjs src/projects/project-registry.test.ts src/gateway/server-methods/projects.test.ts — registry 24/24 and project RPC 12/12 passed.
  • OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat.test.ts — chat 55/55 passed.
  • node scripts/run-vitest.mjs src/gateway/server-methods/chat-send-dispatch-errors.test.ts src/process/gateway-work-admission.test.ts — dispatch-error 5/5 and work-admission 18/18 passed.
  • node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo and node scripts/run-tsgo-core-test-shards.mjs passed. Targeted Oxfmt/Oxlint passed, pnpm check:import-cycles reported 0 cycles, node scripts/check-native-state-schema-version.mjs confirmed schema v9, and git diff --check passed.
  • Blacksmith Testbox reproduced the compact shard at 161 passed / 2 failed pre-fix; the repaired exact 24-file shard passed 399/399.
  • Final Codex autoreview was clean with overall correctness 0.97.
  • Exact-head ClawSweeper review workflow openclaw/clawsweeper#32204815388 completed successfully. The local artifact reported no findings, security cleared, overall/patch B, and no required maintainer decision. Its sole rank-up move was green exact-head checks, now satisfied. The publisher remains delayed, which policy says does not block landing.

The final judged surface is six files: production +233/-78 (net +155), tests +202/-4 (net +198). The production growth is the canonical cross-process checkout lifecycle owner, authoritative registration/deletion coordination, and legacy ownership transfer.

There are no protocol, config, dependency, schema-version, docs, or changelog changes. No external live channel proof is needed: this is deterministic internal SQLite, filesystem-checkout, and Gateway lifecycle behavior with no external API or channel boundary.

@steipete
steipete merged commit 16419cb into main Aug 19, 2026
230 checks passed
@steipete
steipete deleted the steipete/practical-noyce-7366c1 branch August 19, 2026 01:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@clawsweeper clawsweeper Bot added 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 19, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
…law#126004)

* fix: preserve shared managed project checkouts

* test(gateway): drain root work without agent wait

* fix(projects): complete canonical checkout lifecycle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR 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: L 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.

[CI] gateway-server-chat: 2 tests failing across unrelated PRs on compact-small-10 (send/history timeout + drain-overlap assertion)

1 participant