Repository navigation
fix: let unrelated workspaces proceed while a project is busy - #184138
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR releases global workspace allocation before waiting for a busy registered project, then retries reservation. Example: Create project-second from a busy registered repository while creating project-unrelated from another repository.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes current-main allocation contention without weakening reservation checks, and review found no actionable defects. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway session creation passes selected project authority into the managed-worktree service, which reserves capacity, creates a Git checkout, and publishes its registry record. flowchart TD
A[Gateway session creation] --> B[Managed worktree service]
B --> C[Global allocation]
C --> D[Project access attempt]
D --> E[Reserve and create checkout]
D --> F[Release allocation and wait]
F --> B
E --> G[Publish workspace]
Technical reviewBest possible solution: Retain immediate project-access admission and the existing retry owner so busy sources cannot monopolize global allocation. Do we have a high-confidence way to reproduce the issue? Current-main source shows project acquisition waiting inside global allocation, and the supplied baseline replay reports the corresponding unrelated-request failure; this read-only review ran no target code. Is this the best way to solve the issue? The patch addresses the lock-holding cause through existing lifecycle and retry owners, preserves acquisition ordering, and retains distinct contention, cancellation, deadline, and callback-error coverage. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f1664980f94c. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +94, Tests +172, Docs +2, Other +1. Total +269 across 10 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 26, 2026, 1:27 AM ET / 05:27 UTC (Revision 3). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Fixed: unrelated repositories can create workspaces while another request waits for a busy registered project. |
…aw#184138) Release global workspace allocation before waiting for registered-project checkout access. Retry the normal reservation path with the existing wait budget and current source, owner, name, and capacity checks.
What Problem This Solves
Creating a workspace from a busy registered project can delay workspace creation in unrelated repositories. The waiting request acquires global allocation before requesting project access, then retains allocation throughout the project's 30-second lease wait. Other repositories cannot reserve their own workspaces even when their sources are available.
User Impact
Workspace creation in another repository can proceed while the busy project's request waits. If project access returns within the existing wait budget, the original request continues and rechecks its source, owner, name, and capacity before creating the checkout. Cancellation still stops the waiting request without leaving a pending slot or branch.
This change retains the existing project-access wait limit, hard capacity limit, source/base selection, and cleanup policy. It does not extend preparation waiting or introduce a new status, configuration option, or migration.
Why This Change Was Made
Reservation now attempts project access immediately. The project lease owner identifies contention only when acquisition fails before its protected callback begins. The existing creation retry loop unwinds allocation and source custody, waits outside allocation, releases project access, and retries the ordinary reservation path. This preserves the allocation-then-project ordering used by rollback.
The original 30-second source-wait budget is shared across these reservation retries. Callback failures and uncertain native outcomes are not treated as acquisition contention. Ordinary uncontended creation keeps its existing source acquisitions and Git/setup operations. The two registered-project Gateway adapters forward the internal acquisition option.
Evidence
A regression using real registered projects, the real Git mutation queue, and SQLite fails on the baseline after 31.3 seconds with
OPENCLAW_STATE_LEASE_HELD: the unrelated creation cannot finish before the waiting request fails. With the fix, the unrelated workspace completes while the first creator remains blocked and the second still waits; releasing the predecessor lets both complete. Repeating the second request reuses its completed checkout.Additional controls cover Stop, exhaustion of the existing source wait, and a protected callback throwing a lease error without being classified for retry. Changed formatting/lint and all selected production/test type graphs passed. The related test run passed 104 files and 1,386 tests; two platform-specific files and 11 tests were skipped on Linux. After moving the existing reservation block into its preparation owner, the affected type graphs, line-cap check, and 70 focused tests passed. The complete pending-slot file took 23.08 seconds; the new contention case took 1.61 seconds on that run. These are synthetic scenario timings, not a throughput benchmark.
The admitted Gateway handler scenario also passed: an unrelated child session persisted and appeared in
sessions.listwhile another child waited for its registered source, then the waiting child completed with its original parent, base, and worktree identity. This fixture uses real lifecycle admission, Git, and SQLite with mocked model dispatch. The extracted-wrapper import closure passed all 19 cases after adding the required project-checkout source to its inventory.A real Gateway process also passed the contention scenario through its WebSocket protocol. After the waiting request passed source preflight, native allocation and project lifecycle leases held its registered source busy. An unrelated
sessions.createcompleted, appeared inworktrees.listandsessions.list, and returned the expected random README contents throughsessions.files.getbefore the busy source was released. The waiting request then completed with its original base and owner. The identical scenario on the fetched unfixed target failed because the unrelated creation reached its 12-second request deadline while the source remained held. This fixture uses a configured sandbox-required agent to select the registered-source adapter, with no sandbox or model turn started; the holder is a real project lifecycle lease, while the earlier service regression covers an actual Git queue predecessor. No product hooks or mocked Gateway handlers are used.A separate live fixture started a real Gateway process and used its protocol to create a managed workspace, run a real model turn, and verify that the model read a random README marker absent from the prompt. The tool result and final reply matched the marker, and the persisted session retained the expected owner, base, workspace path, and runtime. This task-only variant used the existing QA live fixture; it proves workspace consumption through a real process and model. The concurrent contention scenario above remains a separate handler-level proof with mocked model dispatch.
Five alternating baseline/candidate comparisons on the same runner reproduced the expected contention failure on every baseline and passed on every candidate. A separate registered-project comparison measured selection plus creation through the real source callback, after one excluded warmup pair:
Every registered-source sample performed three source acquisitions and four project resolutions on both revisions. Git starts were also unchanged: 22 for first creation and 21 for subsequent creation. The measurements use fresh processes with warm build/dependency caches and nearest-rank p95 over five measured pairs. These are bounded fixture measurements, not production latency or throughput claims.
The three additional caller E2E files passed all 11 tests: session clone identity, worker destination authority, and remote managed skills. Hosted CI passed on this head, and independent review completed with no findings. The existing project-access wait limit remains unchanged.