GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): re-provision workspace when destroy and recreate race connect by kitlangton · Pull Request #66684 · anomalyco/opencode

Conversation

@kitlangton

@kitlangton kitlangton commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Workspace operations no longer crash when a workspace is destroyed and recreated right as a call connects.
Previously, an operation that saw a warm connection before acquiring the per-workspace lock skipped provisioning; if a destroy and recreate replaced the row before the lock was granted, opening the connection died with an unhandled defect instead of provisioning the new binding. Missing workspaces still return NotFound.

❌ Before

  1. connect checks connections.has(workspaceID) outside the per-workspace lock and skips provision because a warm connection is present.
  2. While waiting for the lock, destroy removes the old connection and row, and create inserts a fresh unbound row with the same ID.
  3. ❌ open runs under the lock, finds the unbound row, and dies with workspace <id> has no binding after provision.

✅ After

  1. connect checks and opens under the per-workspace lock first; open returns undefined when the row has no binding yet.
  2. If open returns undefined, connect releases the lock, calls provision(workspaceID), and loops back under the lock to open the provisioned binding.
  3. A permanently destroyed workspace still fails with NotFound, and keepWarm: 0 release serialization stays intact.
- if (!connections.has(id)) await provision(id)
- withLock(id, () => open(id)) // dies if row.binding is null
+ while (true) {
+   const conn = await withLock(id, () => openOrUndefined(id))
+   if (conn) return conn
+   await provision(id) // outside the lock
+ }

📊 Proof: new tests fail without the change (workspace ... has no binding after provision) and pass with it:

Case Before After
Warm connection destroyed + recreated before lock ❌ Dies with has no binding after provision ✅ Re-provisions and succeeds
Warm connection permanently destroyed before lock ✅ NotFound ✅ NotFound
keepWarm: 0 overlapping release + next connect ✅ Serialized ✅ Serialized, 0 leaked scopes

👀 Read: packages/core/src/workspace.ts (open and connect, ~15 lines) — verify the lock is always released before calling provision. The rest is routine.

🔍 Found while model-checking workspace concurrency · no user reports

Checks run
  • packages/core: bun test test/workspace.test.ts --rerun-each 20 (560 pass, 0 fail)
  • packages/core: bun run typecheck, bun run typecheck:tsc (pass)
  • packages/server: bun run typecheck (pass)
  • root: bun run lint (pass)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kitlangton
fix(core): re-provision workspace when destroy and recreate race connect
f6d6d61
@github-actions github-actions Bot added the contributor label Nov 26, 2026
opencodejr[bot]
opencodejr Bot reviewed Nov 26, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks right. I confirmed the race on the base: the new destroy+recreate test dies there with has no binding after provision. With this change the whole workspace test file passes, including 10 reruns of each test. typecheck:tsc passes. provision is only called after the lock is released, and a deleted row still ends the loop with NotFound from load, so it can't spin forever.

Public API: unchanged (internal to Workspace.connect/open).

No concerns.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kitlangton
kitlangton merged commit 42542ea into dev Nov 26, 2026
11 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@kitlangton
kitlangton deleted the workspace-connect-race branch November 26, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@kitlangton
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.