Skip to content

test(qa): cover session and Workboard managed-worktree lifecycles; fix symlinked state-dir lock blindness - #120362

Merged
steipete merged 9 commits into
mainfrom
claude/intelligent-clarke-8391bf
Aug 8, 2026
Merged

steipete merged 9 commits into
mainfrom
claude/intelligent-clarke-8391bf

Conversation

@steipete

@steipete steipete commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

ClawSweeper's review of #120335 noted that the new agent-runtime.managed-worktrees-lifecycle coverage proves the manual-owner lifecycle only: session-owned and Workboard-owned worktree cleanup lifecycles (run-end lossless removal, session-delete worktreePreserved reporting, gc owner protection) had no product-boundary proof.

While building that proof, the Workboard e2e surfaced a real product bug: on a symlinked state directory (macOS /tmp -> /private/tmp), the managed-worktree service cannot recognize its own git lock, and Workboard run-end cleanup dies with fatal: cannot remove a locked working tree, lock reason: openclaw pid=....

Why This Change Was Made

Product fix (root cause, producer-side). git worktree list reports canonicalized paths, but record.path was minted from the raw resolveStateDir() (src/agents/worktrees/service.ts:636), so lockState() in git-lock.ts (and the sibling path.resolve comparisons at service.ts:146/269/304) compared a non-canonical stored path against git's canonical output and missed the service's own lock. The repo already canonicalizes repoRoot (resolveRepositoryFromRealPath) and uses canonicalPathKey in the orphan path; this fix extends the same invariant to the state-dir side: a worktreesRoot() helper mkdirs and realpaths the worktrees root once, used at the three minting/boundary sites (create, removeEmptyParents boundary, orphan reconciliation). Producer-side canonicalization restores the invariant for every downstream comparison; the comparison sites stay untouched. Linux CI never saw this because /tmp is not a symlink there.

QA coverage. Two new coverage IDs in the Agent Turn Execution taxonomy category, two scenarios, and two child-gateway product-proof e2e tests (QA live-lane harness, mock provider, real RPC boundary):

  • agent-runtime.managed-worktrees-session-lifecycle: sessions.create with worktree: true/worktreeName/worktreeBaseRef returns and persists the managed checkout; a real turn runs from it; worktrees.gc preserves the live session-owned worktree; clean and dirty sessions.delete snapshot and remove with a pinned restorable ref; worktrees.restore rebuilds dirty untracked state without the synthetic snapshot commit entering branch history; a foreign git worktree lock makes deletion report worktreePreserved with the checkout retained.
  • agent-runtime.managed-worktrees-workboard-lifecycle: workboard.cards.dispatch materializes the card workspace as wb-<card-id> on openclaw/wb-<card-id>, writes the resolved path/branch back to the card, the subagent run completes, and run-end cleanup removes the clean checkout losslessly.

Intentionally not claimed: 7-day idle expiry (proving it at a product boundary would mean backdating SQLite rows; it stays unit-covered in service.test.ts/owner-protection.test.ts) and Workboard dirty-retention (agent.wait can resolve before the async subagent_ended cleanup hook, and there is no product-boundary marker for "cleanup attempted" — a retention assertion would be false proof). Follow-up worth considering: record the run-end cleanup outcome as an observable fact on the card/registry so retention becomes provable.

User Impact

Operators whose OpenClaw state directory traverses a symlink no longer hit failed Workboard run-end cleanup (and the same blind spot in lock recognition during remove/release). Session and Workboard worktree lifecycles are now covered by the QA scenario pack at the real gateway boundary.

Evidence

  • Regression test replays the exact failing sequence through an explicit symlinked state dir (proves on Linux too): create -> canonical record.path -> acquire -> removeIfLossless succeeds.
  • Worktree module suite: 34 files, 297 passed, 3 skipped.
  • Session lifecycle e2e: green twice (45.4s, 35.7s). Workboard lifecycle e2e: green twice (21.3s, 21.4s) — failed with the locked-worktree error before the fix.
  • Scenario catalog: 58 passed. pnpm maturity:check: passed (no generated-doc changes required).
  • Autoreview (Codex gpt-5.6-sol, high): clean, no actionable findings.

CI Fix Notes

  • check-lint tripped max-lines on service.test.ts after the new regression test; the canonical-path tests (the new symlink regression plus the existing linked-checkout anchoring test) moved into focused src/agents/worktrees/service.canonical-paths.test.ts, following the service.orphans.test.ts sibling convention.

  • security-fast failed on an unrelated freshly published advisory (HIGH nanoid <3.3.17, GHSA-2v37-7h3g-55p8, transitive via postcss). Fixed in this landing PR per the red-gate rule with a lockfile-only bump to nanoid 3.3.17; pnpm-audit-prod exits clean.

  • ClawSweeper P1 (persisted rows): the state-migration owner (state-migrations.doctor.ts) now canonicalizes legacy raw-root path spellings for live and removed rows (read-only detection, stale-safe id+old-path rewrites, idempotent), with an end-to-end regression proving the migrated row survives the previously failing lock sequence.

  • ClawSweeper P2 (read-only detection): detection no longer mkdirs the worktrees root; missing roots resolve read-only via the state dir realpath, with an empty-state regression asserting diagnostics create nothing.

  • Red-main check-lint (2nd): #120285 landed runs.test.ts at 1001 lint-counted lines, failing every PR's core oxlint shard; smallest correct fix in this landing PR moves the steering/admission cluster into focused runs.steering.test.ts (merge-ref result 748 lines, suppressions forbidden).

Exact-head real-behavior proof

PR #120362 exact-head real-behavior proof

  • Exact head: 435ba64f0fed5c718a75b45a1dc5141a6af5ba7f
  • Captured (UTC): Sat Aug 8 01:53:13 UTC 2026
  • Node: v26.7.0
  • Checkout paths in captured output: sanitized to <checkout>

QA-enabled dist build

$ OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build
[build-all] phase timings: total 2m 49.6s; slowest tsdown-unified 2m 18.8s; write-cli-startup-metadata (reused) 10.3s; tsdown-packages 9.36s; ui:build 3.48s; tsdown-ai 3.06s; plugins:assets:build 1.31s; check-cli-bootstrap-imports 1.01s; runtime-postbuild 883ms; plugins:assets:copy 433ms; check-plugin-sdk-exports 370ms; write-plugin-sdk-entry-dts 359ms; write-build-info 101ms; copy-hook-metadata 87ms; runtime-postbuild-stamp 50ms; build-stamp 49ms
exit: 0

Session lifecycle product proof — PASS

$ node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/managed-worktrees-session-lifecycle-product-proof.e2e.test.ts 2>&1 | tee /tmp/wt-session-proof.txt
[test] starting test/vitest/vitest.e2e.config.ts

 RUN  v4.1.10 <checkout>

[vitest] still running with no output for 30000ms (test/vitest/vitest.e2e.config.ts).

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  18:50:58
   Duration  48.45s (transform 11.23s, setup 598ms, import 13.47s, tests 34.26s, environment 0ms)

[test] passed 1 Vitest shard in 48.79s

Workboard lifecycle product proof — PASS

$ node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/managed-worktrees-workboard-lifecycle-product-proof.e2e.test.ts 2>&1 | tee /tmp/wt-workboard-proof.txt
[test] starting test/vitest/vitest.e2e.config.ts

 RUN  v4.1.10 <checkout>


 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  18:51:54
   Duration  25.15s (transform 2.55s, setup 236ms, import 5.00s, tests 19.82s, environment 0ms)

[test] passed 1 Vitest shard in 25.45s

Worktree-path state migration proof — PASS

$ node scripts/run-vitest.mjs src/infra/state-migrations.worktree-paths.test.ts 2>&1 | tee /tmp/wt-migration-proof.txt
[test] starting test/vitest/vitest.infra.config.ts

 RUN  v4.1.10 <checkout>

[vitest] still running with no output for 30000ms (test/vitest/vitest.infra.config.ts).

 Test Files  1 passed (1)
      Tests  2 passed (2)
   Start at  18:52:24
   Duration  39.54s (transform 1.01s, setup 294ms, import 1.45s, tests 37.71s, environment 0ms)

[test] passed 1 Vitest shard in 41.01s

@steipete
steipete marked this pull request as ready for review August 7, 2026 21:55
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling extensions: qa-lab size: L maintainer Maintainer-authored PR labels Aug 7, 2026
@steipete
steipete requested a review from a team as a code owner August 7, 2026 22:12
@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph guard cleared

This PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh /allow-dependencies-change comment after the guard blocks that new head SHA.

  • Current SHA: 435ba64f0fed5c718a75b45a1dc5141a6af5ba7f

@steipete
steipete force-pushed the claude/intelligent-clarke-8391bf branch from 4a9f340 to 43255a4 Compare August 7, 2026 22:41
@github-actions github-actions Bot removed the dependencies-changed PR changes dependency-related files label Aug 7, 2026
@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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 7, 2026
@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 7, 2026, 9:44 PM ET / August 8, 2026, 01:44 UTC.

ClawSweeper review

What this changes

This PR canonicalizes managed-worktree paths, migrates legacy persisted paths, and adds session and Workboard lifecycle QA coverage.

Regression provenance

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

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 4 items remain

The patch appears correct and resolves the prior migration/read-only findings, but it needs attached exact-head real-behavior evidence before merge; the protected maintainer label also requires human handling.

Priority: P1
Reviewed head: 435ba64f0fed5c718a75b45a1dc5141a6af5ba7f
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation and focused coverage are strong, but the missing inspectable after-fix runtime artifact remains a merge gate.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The described child-gateway tests exercise real Git and gateway boundaries with a mock provider, but the PR body supplies only prose pass summaries rather than an inspectable exact-head runtime transcript, log, or verdict artifact. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The described child-gateway tests exercise real Git and gateway boundaries with a mock provider, but the PR body supplies only prose pass summaries rather than an inspectable exact-head runtime transcript, log, or verdict artifact. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Producer-side repair: The service realpaths the managed-worktree root before minting records, aligning stored paths with Git's canonical worktree paths used by lock detection.
Lock comparison contract: Git lock state compares the stored worktree path against paths emitted by git worktree list, so canonicalizing at record creation repairs the mismatch at its owner boundary.
Upgrade-safe persistence migration: Doctor detects legacy paths without opening or creating a new database, then applies id-and-old-path guarded rewrites in the migration owner.
Findings None None.
Security None None.

How this fits together

Managed worktrees are Git checkouts created for agent sessions and Workboard cards. The service records their paths in the state database, then Git locks and owner cleanup determine whether they can be removed or restored.

flowchart LR
  A[Session or Workboard request] --> B[Managed worktree service]
  B --> C[Canonical worktrees root]
  C --> D[Git worktree and lock state]
  B --> E[State database record]
  E --> F[Doctor path migration]
  D --> G[Cleanup or restore outcome]
Loading

Decision needed

Question Recommendation
Is the attached QA evidence sufficient for merging this persisted-path migration, or should the contributor provide the exact-head harness transcript/verdict artifact? Request the harness artifact: Require a redacted exact-head child-gateway transcript, logs, or verdict JSON that demonstrates the repaired lifecycle.

Why: The source and tests are strong, but the public PR body has no inspectable after-fix runtime artifact beyond prose summaries.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The described child-gateway tests exercise real Git and gateway boundaries with a mock provider, but the PR body supplies only prose pass summaries rather than an inspectable exact-head runtime transcript, log, or verdict artifact. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The PR body reports only prose summaries of mock-provider child-gateway runs; attach a redacted exact-head harness transcript, artifact, or verdict JSON showing the after-fix lifecycle before merge.
  • Resolve merge risk (P1) - Persisted managed-worktree identity is rewritten during Doctor migration, so maintainers should retain the focused upgrade proof when landing.
Agent review details

Security

None.

PR surface

Source +145, Tests +727, Other +59. Total +931 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 6 180 35 +145
Tests 7 1042 315 +727
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 59 0 +59
Total 16 1281 350 +931

Review metrics

Metric Value Why it matters
Production versus test LOC production +163/-34; tests and QA +1118/-316 The production growth is justified by canonical persisted identity and its migration owner; the much larger test delta supplies lifecycle coverage.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor.e2e-harness.ts, migration/backfill/repair: src/infra/state-migrations.worktree-paths.test.ts, serialized state: src/agents/worktrees/service.test-support.ts, serialized state: src/agents/worktrees/service.test.ts, serialized state: src/infra/state-migrations.doctor.ts, serialized state: src/infra/state-migrations.types.ts, and 8 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #120362
Summary: This PR addresses a distinct symlinked-path identity defect while extending prior managed-worktree coverage to session and Workboard owners.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Attach exact-head behavior proof (recommended)
    Provide a redacted child-gateway transcript, logs, or verdict artifact showing the after-fix session and Workboard lifecycle paths.
  2. Pause for manual evidence acceptance
    Maintain the existing proof summaries only if a maintainer explicitly accepts them for this persisted-state migration.

Technical review

Best possible solution:

Keep producer-side canonicalization and the Doctor-only legacy migration, then attach redacted exact-head behavior evidence for the session and Workboard flows before merging.

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

Yes at source level: the focused regression constructs a symlinked state directory, creates a worktree, acquires its lock, and verifies lossless removal. The review did not execute the test under the read-only constraint.

Is this the best way to solve the issue?

Yes. Canonicalizing the path at the record producer repairs every downstream Git comparison, while Doctor owns migration of pre-existing persisted spellings.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5a79d19ba179.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The described child-gateway tests exercise real Git and gateway boundaries with a mock provider, but the PR body supplies only prose pass summaries rather than an inspectable exact-head runtime transcript, log, or verdict artifact. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P1: A symlinked state directory can leave a Workboard-managed checkout locked and prevent expected cleanup.
  • merge-risk: 🚨 compatibility: Doctor rewrites persisted managed-worktree path identity for existing state databases during upgrade.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The described child-gateway tests exercise real Git and gateway boundaries with a mock provider, but the PR body supplies only prose pass summaries rather than an inspectable exact-head runtime transcript, log, or verdict artifact. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the focused canonical-path repair and the preceding merged managed-worktree lifecycle work. (role: introduced the current repair and related managed-worktree QA coverage; confidence: high; commits: d4aa74e93156, 45b1dbf9622c; files: src/agents/worktrees/service.ts, qa/scenarios/runtime/managed-worktrees-session-lifecycle.yaml)
  • joshavant: History on the Workboard workspace cleanup boundary connects this contributor to the affected owner lifecycle. (role: recent Workboard lifecycle contributor; confidence: medium; commits: 941f4a3; files: extensions/workboard/src/dispatcher-workspace.ts, extensions/workboard/src/dispatcher.ts)

Rank-up moves

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

  • Attach a redacted exact-head child-gateway transcript, logs, or verdict JSON for the two lifecycle scenarios.

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-08-07T22:46:52.505Z sha 43255a4 :: needs changes before merge. :: [P1] Migrate existing managed-worktree paths
  • reviewed 2026-08-07T23:40:42.547Z sha c5923f2 :: needs changes before merge. :: [P2] Keep legacy-state detection read-only

@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label Aug 7, 2026
@steipete

steipete commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — the P1 (persisted-path migration for pre-upgrade rows) is applied on head c5923f2: the state-migration owner now canonicalizes legacy raw-root path spellings (live and removed rows, idempotent, read-only detection), with an end-to-end regression proving the migrated row survives the previously failing lock sequence. CI is green on this exact head.

@clawsweeper

clawsweeper Bot commented Aug 7, 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 repository_dispatch).
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

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — P2 applied on head 435ba64: legacy-state detection is now side-effect-free (no mkdir; read-only realpath fallback for missing roots; empty-state regression). Also includes the red-main check-lint repair (runs.test.ts split, #120285 overflow). CI green on this exact head.

@clawsweeper

clawsweeper Bot commented Aug 8, 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 repository_dispatch).
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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 8, 2026
@steipete
steipete merged commit 6a6cd78 into main Aug 8, 2026
140 checks passed
@steipete
steipete deleted the claude/intelligent-clarke-8391bf branch August 8, 2026 01:57
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 8, 2026
…x symlinked state-dir lock blindness (openclaw#120362)

* fix(agents): canonicalize managed worktree paths

* test(qa): cover managed worktree owner lifecycles

* test(agents): split worktree canonical-path regression into focused file

* fix(doctor): canonicalize persisted managed-worktree paths for symlinked state dirs

* fix(doctor): keep worktree path migration detection read-only

* test(doctor): bound managed-worktree migration product proof

* fix(doctor): keep worktree path detection from creating state dirs

* test(doctor): allow state migration detection under CI load

* test(agents): split embedded-runner steering runs into focused file

Unblocks the check-lint gate broken by openclaw#120285's max-lines overflow.
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 extensions: qa-lab maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant