Skip to content

fix(worktrees): workspace creation fails while a registered project is busy - #184304

Closed
wyf027 wants to merge 2 commits into
openclaw:mainfrom
wyf027:fix/worktree-source-wait-184272
Closed

wyf027 wants to merge 2 commits into
openclaw:mainfrom
wyf027:fix/worktree-source-wait-184272

Conversation

@wyf027

@wyf027 wyf027 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #184272

What Problem This Solves

Workspace creation fails after 30 seconds when its registered project is busy, even though the shared workspace contention budget still has time remaining.

User Impact

The same request can wait for its registered source within the existing workspace budget. Later source acquisition uses that remaining budget too, so waiting during checkout, provisioning, setup admission, or publication does not require replaying completed preparation.

Why This Change Was Made

Reuse the existing startWorktreeWait accounting owner instead of maintaining a separate 30-second source counter. Stop accounting as soon as source access is acquired, before protected work runs. Immediate reservation admission remains waitMs: 0; cancellation, source checks, and native acquisition errors retain their existing paths. This removes the separate source-wait state without introducing another timer, retry loop, or configuration option.

Related work checked: #184138 is merged and deliberately retained the shorter source deadline; #184121 concerns shared-fetch cancellation; #184253 is merged and concerns duplicate repository discovery. Their complete discussions and diffs were reviewed.

Evidence

  • Source-level before/after probe executed the actual extracted withWorktreeSource and startWorktreeWait functions. With a shared 100,000 ms budget, two simulated 31,000 ms acquisitions receive 100,000 then 69,000 ms and leave 38,000 ms; 900,000 ms spent inside the protected callback is not deducted. The base passes no acquisition budget and leaves the shared budget unchanged.
  • The same probe confirms failed acquisition deducts elapsed wait while preserving the original error, an empty acquisition option uses the shared remainder, and explicit zero-wait reservation remains immediate without consuming the waiting budget.
  • Changed-file formatting with the repository configuration and whitespace checks pass. Independent source review found and resolved the empty-option forwarding case.
  • No repository tests were added or changed, and no build was run. The probe isolates source functions with a simulated clock/source; it does not establish real Git/SQLite contention, Gateway behavior, cancellation at native boundaries, or the reported 31-second scenario. This PR remains draft pending that runtime proof and the existing focused suites.

Documentation verification: The managed-worktrees guide now describes the shared 30-minute contention budget and retained cancellation, matching the implementation. Changed Markdown formatting and whitespace checks passed; runtime-proof limitations above remain.

@clawsweeper

clawsweeper Bot commented Oct 26, 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 agents Agent runtime and tooling size: S labels Oct 26, 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. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed 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 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Registered-project source acquisition consumes the existing shared workspace contention budget instead of a separate 30-second limit.

Example: A registered project's checkout remains busy for 31 seconds while workspace creation still has contention budget available.

  • Before: Workspace creation fails with OPENCLAW_STATE_LEASE_HELD after about 30 seconds.
  • After: The same request can acquire the released source and continue within its remaining workspace budget.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and source-consistent, but simulated extracted-function evidence does not satisfy the external-PR behavior-proof gate.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A temporarily busy registered project makes an accepted workspace request fail prematurely and require another attempt.
Reason: The linked maintainer-authored issue explicitly requests this behavior, resolving the earlier deliberate retention of the shorter deadline.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open: it addresses a current-main failure documented by a maintainer, and the focused implementation preserves immediate reservation and source-authority checks.

Priority: P2
Reviewed head: d5eb079c51958614c0781ab399a267d7f7db0f0d

Before merge

  • Add real behavior proof - The PR supplies an extracted-function probe with a simulated clock/source, not the changed workspace owner running through a shipped entry point. The contributor should supply redacted Gateway sessions.create output showing a source held beyond 30 seconds, unrelated progress, successful continuation with original identity, and cancellation; later-phase contention should demonstrate that completed preparation is retained. Redact IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Update the documented registered-project waiting limit (P3) - Passing the shared remainder here removes the separate 30-second source deadline, but docs/concepts/managed-worktrees.md:156 still explicitly promises that deadline. A user diagnosing a busy project will now see substantially longer waiting than documented. Update that paragraph to describe the shared contention budget and retained cancellation behavior.

Findings

  • [P3] Update the documented registered-project waiting limit — src/agents/worktrees/service-preparation.ts:196-205

Tests

  • Missing end-to-end proof: No committed red-on-base/green-on-head regression or corrected production-flow contention run is supplied, including later-phase waiting without repeated preparation.
Agent review details

How this fits together

Gateway session creation supplies registered-project source access to the managed-worktree service, which reserves capacity, prepares a Git checkout, and publishes the workspace record.

flowchart TD
  A[Session creation] --> B[Managed worktree service]
  B --> C[Immediate reservation attempt]
  C --> D[Release allocation and wait]
  D --> E[Shared contention budget]
  E --> C
  C --> F[Checkout and setup]
  F --> G[Publish workspace]
Loading

Technical review

Best possible solution:

Retain the shared-budget implementation and align its regression coverage and documented waiting contract.

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

Current-main source establishes the shorter deadline, and the linked maintainer issue reports its failure through real registry, Git, SQLite, and workspace-service owners; this review executed no target code.

Is this the best way to solve the issue?

The patch uses the existing accounting owner, stops charging before protected work, preserves zero-wait reservation, and removes the competing source counter without unnecessary machinery.

Full review comments:

  • [P3] Update the documented registered-project waiting limit — src/agents/worktrees/service-preparation.ts:196-205
    Passing the shared remainder here removes the separate 30-second source deadline, but docs/concepts/managed-worktrees.md:156 still explicitly promises that deadline. A user diagnosing a busy project will now see substantially longer waiting than documented. Update that paragraph to describe the shared contention budget and retained cancellation behavior.
    Confidence: 0.99

Overall correctness: patch is correct
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Registered-source reservation deadline changes intended behavior with a stated reason (95a3ccd: Release global allocation while waiting for a busy project, preserving the existing source deadline to bound that earlier repair.)
  • Finite project-source scopes and cancellation keeps the original intent (cfec084: Use worker-backed source resolution while preserving cancellation, stale-source refusal, and final commit authority.)
  • Worker authority and cleanup custody keeps the original intent (e4f89eb: Keep worktree settlement under worker-owned predicates and live authority while preserving uncertain-outcome recovery.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

Acceptance criteria:

  • pnpm check:docs
  • git diff --check

What I checked:

PR surface

Source +9. Total +9 across 1 file. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 47 38 +9
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 47 38 +9

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #184272
Summary: This PR directly targets the canonical registered-source deadline issue; the neighboring merged repair addresses unrelated-repository progress.

Members:

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

Labels

Label changes:

  • add P2: Same-project contention causes avoidable workspace-creation failures and retries with limited blast radius.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: Same-project contention causes avoidable workspace-creation failures and retries with limited blast radius.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

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

  • Commit a focused production-owner regression that fails on the base and passes on the head.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 26, 2026, 2:56 AM ET / 06:56 UTC.

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 26, 2026
@shakkernerd

Copy link
Copy Markdown
Contributor

The source-wait budget change is being handled in #184672, including the Gateway preparation path and regression coverage for contention, continuation, and cancellation. We'll keep the implementation and validation together there. Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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.

bug: workspace preparation fails after 30 seconds of registered-source contention

2 participants