Skip to content

fix(worktrees): allow concurrent empty-workspace dispatches - #179240

Merged
steipete merged 1 commit into
mainfrom
steipete/cs-spawnparent-1021
Oct 21, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/cs-spawnparent-1021

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Fixes #179229

What Problem This Solves

Fresh-workspace dispatch can fail with Spawn parent managed worktree changed when another session registers an unrelated empty workspace during its registry lookup.

User Impact

Independent empty-workspace sessions can prepare and dispatch concurrently. Changes to the selected session's own worktree still reject stale preparation with the existing error.

Why This Change Was Made

The registry guard captured a registry-wide revision before its asynchronous read, even when the session's worktree ID and owner were already known. Scope that read to the known row and owner selection, retaining the existing identity, removal, database-admission, and synchronous effect checks. Dispatch and managed-parent preparation both supply their known binding. Discovery reads retain their existing behavior.

The regression uses actual empty workspaces, session storage, and the dispatch preparation owner with a deterministic barrier. It also covers removal, repository changes, and replacement of the selected owner. The production change adds no state, queries, locks, or retries.

Evidence

  • Direct create-and-prepare probe through resolveWorkerPlacementSessionTarget: reproduced the exact error on base e2f330eb480b in 320.71 s; the same two-session overlap passes with the fix in 201.95 s. Both sessions use real isolated empty workspaces and SQLite session/registry state; no cloud provider is needed.
  • Six direct stale-source checks pass in 135.39 s: removal, repository change, and replacement each reject during the read and at the retained effect check, with the original error.
  • Added src/gateway/server-worker-placement-session-target.worktree.test.ts to the database-worker lane. The local OPENCLAW_VITEST_RUNTIME=node pnpm test src/gateway/server-worker-placement-session-target.worktree.test.ts --maxWorkers=1 run did not reach assertions on the heavily loaded host; the interrupted run took 627.14 s wall time (exit 130). Compiled-worker preparation alone took 264.918 s. This is an incomplete setup run, not a product verdict; PR CI must run the committed regression and broader consumer suites. A queued Testbox attempt was stopped; no remote test result is claimed.
  • pnpm run tsgo:core: passed, 113.36 s wall time.
  • Type-aware scoped lint via node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json <changed code/test files> reported only the inherited eslint(max-lines) failure in session-worktree-preparation.ts: 725 counted lines on the unchanged base, 729 with this change, limit 700. The base failure was independently reproduced with the same rule settings; no lint exception was added.
  • pnpm exec oxfmt --check <all six changed files> and git diff --check: passed.
  • Independent Codex review at P0–P2: scoped-clean, no accepted/actionable findings. The simplification pass retained the existing guard owner and shares the row/owner selection between read phases. Known bindings lose their registry-wide dependency; production delta is +20 lines, with 148 lines of focused regression/lane coverage.

Scope known session source reads to their worktree and owner selection before awaiting registry reads. Preserve selected-source invalidation and cover concurrent empty workspaces at dispatch preparation.
@clawsweeper

clawsweeper Bot commented Oct 21, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T07:56:06.416937Z b093bac PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 21, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 21, 2026
@steipete
steipete merged commit 4e6f52e into main Oct 21, 2026
128 of 140 checks passed
@steipete
steipete deleted the steipete/cs-spawnparent-1021 branch October 21, 2026 08:02
@steipete

Copy link
Copy Markdown
Contributor Author

Landing note for head b093bac7c156: no failure is caused by this PR.

  • check-test-types-core-2 fails on test/scripts/ci-changed-node-test-plan.test.ts (TS2345 CompactNodeTestShard vs ChangedNodeTestShard at lines 813 and 891), a CI tooling test this PR does not touch; it is inherited from main.
  • The five Security High (...) CodeQL shards, Scan changed paths (precise) and Select Critical Quality shards failed on API rate limit exceeded for installation (GitHub API quota for the CI app), not on findings.

All other required checks are green, the concurrent create-and-prepare reproduction fails on base and passes here, own-worktree changes still reject, and Codex autoreview is clean. Landing via the inherited-failure admin exception.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
…#179240)

Concurrent empty-workspace dispatches could fail with 'Spawn parent managed worktree changed; retry from its current session' (seen live when three cloud sessions dispatched together). Dispatch and spawn-parent preparation captured a registry-wide worktree revision for the async lookup, so an unrelated sibling registration invalidated the guard even though the session's own worktree was unchanged. When the worktree and owner are already known, the read guard is now scoped to that row and owner selection; discovery reads keep the registry-wide capture until they narrow, and real changes to the session's own worktree still reject.

Fixes openclaw#179229
steipete added a commit that referenced this pull request Nov 11, 2026
Keep local workspace resolution and retirement guarded by their already-known
worktree ID while awaiting the registry reader. Unrelated concurrent publication
must not revoke the selected row; identity and removal changes to that row still
reject the operation.

The native Btrfs morning replay exposed this existing main regression from
#166236. Reuse the selection contract introduced in #179240 instead of retrying
or serializing the callers. The deterministic regression fails on exact parent
3a6cc65 and passes with this repair, including selected-row revocation controls.

Allocate 46 regression-test lines for the real registry/session owner interleave.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Concurrent empty-workspace dispatches fail before worker provisioning

1 participant