Skip to content

fix: let unrelated workspaces proceed while a project is busy - #184138

Merged
shakkernerd merged 2 commits into
mainfrom
workspace-release-allocation
Oct 26, 2026
Merged

shakkernerd merged 2 commits into
mainfrom
workspace-release-allocation

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

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.list while 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.create completed, appeared in worktrees.list and sessions.list, and returned the expected random README contents through sessions.files.get before 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:

Fixture Baseline median / p95 Candidate median / p95
Registered-source contention 32.63 s / 32.66 s, expected failure 3.61 s / 3.78 s, pass
Uncontended registered source, first creation 1.486 s / 1.506 s 1.462 s / 1.467 s
Uncontended registered source, subsequent creation 0.552 s / 0.559 s 0.546 s / 0.547 s

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.

@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 docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 26, 2026
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 maintainer review before merge.

What this changes

This 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.

  • Before: project-unrelated waits behind project-second's project-access lease wait.
  • After: project-unrelated completes while project-second waits, and project-second resumes when its source becomes available.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-level repair with reported shipped-entry-point before/after proof, meaningful regression coverage, passing exact-head gates, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The maintainer's detailed Gateway-process report exercises contention through sessions.create and verifies unrelated workspace contents through sessions.files.get before releasing the busy source, satisfying the previous rank-up request; separate real-model proof verifies workspace consumption.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Creating a workspace from a busy project delays workspace creation in unrelated repositories.
Reason: The maintainer-authored repair restores independent progress while retaining existing capacity, authority, cleanup, and waiting contracts.

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
Reviewed head: 0d8273603cdbe98d29fde57af224e61e5d39f2d9

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway 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]
Loading

Technical review

Best 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

  • Project checkout lifecycle keeps the original intent (f26c195: Shared-worker registration retained checkout custody to protect registration and uncertain outcomes; the PR adds immediate acquisition without removing that custody.)
  • Allocation reservation and pending-slot observation keeps the original intent (c6168a9: Short persisted reservations enable parallel materialization; later commit fbb590b required pending-before-live observation for owner reuse, which the extracted reservation block preserves.)
  • Gateway registered-project source adapters keeps the original intent (cfec084: Finite worker-backed source scopes preserve cancellation, stale-source refusal, and final session authority; forwarding acquisition options leaves those checks intact.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +94, Tests +172, Docs +2, Other +1. Total +269 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 149 55 +94
Tests 2 172 0 +172
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 10 324 55 +269

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Busy registered projects can delay otherwise independent workspace creation, with bounded waits and limited workflow impact.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-26T03:34:27.452Z sha 0d82736 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-26T04:58:16.433Z sha 0d82736 :: needs maintainer review before merge. :: none

Reviewed October 26, 2026, 1:27 AM ET / 05:27 UTC (Revision 3).

@shakkernerd

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. 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
@shakkernerd

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. labels Oct 26, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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
@shakkernerd
shakkernerd merged commit 95a3ccd into main Oct 26, 2026
212 of 213 checks passed
@shakkernerd
shakkernerd deleted the workspace-release-allocation branch October 26, 2026 05:31
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Fixed: unrelated repositories can create workspaces while another request waits for a busy registered project.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…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.
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. scripts Repository scripts size: M 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.

1 participant