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 — feat(core,server): add Workspace keepWarm/attach/alarm lifecycle for workerd by kitlangton · Pull Request #66183 · anomalyco/opencode

Conversation

@kitlangton

@kitlangton kitlangton commented Nov 24, 2026 •
edited by opencodejr Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Adds zero-idle-billing Durable Object workspace lifecycle support (keepWarm: 0, pollInterval: null, KV-persisted earliest-deadline alarm scheduling, and suspendIdle()), Workspace.attach for already-provisioned sandboxes/VMs, and ServerWorkerd's handler.alarm().

Before: Workspace always held connections open until idleThreshold (20 min) and ran a 1-minute background polling fiber, which keeps a Cloudflare Durable Object pinned awake and billed while idle; creating a workspace always called driver.create(), with no way to register an already-running VM/sandbox binding.

After:

// 1. Attach an already-provisioned VM/sandbox without calling driver.create()
const id = yield* workspace.attach({ provider: "exe-dev", binding: { host, peerKey } })

// 2. Durable Object profile: close connection right after op, disarm 60s poller, drive idle suspend via alarm()
const handler = yield* ServerWorkerd.create({ storage, config })
// inside DurableObject:
fetch(req: Request) { return this.oc(req) }
alarm()             { return this.oc.alarm() }
  • Zero DB migrations: pending idle-suspend deadlines persist in KV.Service under workspace.idle:<id>, surviving DO eviction/restarts and coalescing across multiple workspaces onto Cloudflare's single storage.setAlarm slot (earliest deadline wins).
  • Safe against long ops & transient failures: active operations past idleThreshold push their deadline forward instead of tight-looping; failed suspendForIdle calls back off by idleThreshold without corrupting last_used_at; startup re-arms any persisted deadlines.
  • Zero SDK regression: alarmWorkspaceReplacement is applied in ServerWorkerd.create (which exposes handler.alarm()) and exported for the follow-up SDK PR when OpenCodeWorkerd exposes alarm().
Metric Value
Base dev (follows #66024 & #66030)
DB migrations 0 (reuses KVTable)
Public SDK changes 0 (OpenCodeWorkerd untouched until follow-up PR)
Verification bun check + tsc -b (core, server, sdk), probe:workerd, lint, lint:effect-simplifications, 58 core + 5 server + sdk embedded tests pass

Read: packages/core/src/workspace.ts, packages/server/src/workerd.ts, packages/server/src/fetch.ts, and packages/core/src/database/sqlite.workerd.ts.


Added by the opencode bot (AI-generated).

Public API: adds Workspace.attach/suspendIdle and keepWarm/onIdleScheduled/pollInterval:null options; ServerWorkerd.create handler gains alarm(); DurableObjectStorage now requires setAlarm (compatible with real DO storage)

Sorry, something went wrong.

Uh oh!

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

All reactions
@github-actions github-actions Bot added the contributor label Nov 24, 2026
opencodejr[bot]
opencodejr Bot reviewed Nov 24, 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.

The change looks sound. I ran the core workspace tests (26 pass) and the server workerd tests (5 pass), and tsc -b is clean for core, server and sdk. The new tests use TestClock throughout, so the timing is deterministic.

Public API: HTTP API, OpenAPI, config, CLI and plugin API are unchanged. Additions and changes to the TypeScript package APIs:

  • Workspace.Interface: adds attach and suspendIdle.
  • Workspace.Options: adds keepWarm and onIdleScheduled. pollInterval now also accepts null.
  • DurableObjectStorage (core sqlite.workerd): now requires setAlarm. Real Cloudflare storage already has it. Hand-written fakes passed as storage to ServerWorkerd or the SDK's OpenCodeWorkerd won't type-check until they add it.
  • ServerWorkerd.create: now returns a Handler, which is the same fetch function plus alarm(). Existing callers still compile.
  • New exports: ServerWorkerd.alarmWorkspaceReplacement, ServerWorkerd.Handler and ServerFetch.makeWithContext.

All of this is backwards compatible, except for custom storage fakes, which need setAlarm.

Concerns: two, both inline:

  • Re-attaching an ID closes the scope of a connection that may still have operations running.
  • ServerWorkerd.create now always disables the poller, so hosts that don't wire alarm() lose idle suspension completely.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread packages/core/src/workspace.ts Outdated
existingProvider: existing.provider,
})
}
yield* dropConnection(workspaceID)

@opencodejr opencodejr Bot Nov 24, 2026

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.

connect holds the lock only while it acquires and releases a connection, not while the operation runs. That means a re-attach can get here while connection.active > 0 and close the environment scope under an in-flight spawn or file operation. Could re-attach either refuse, or wait for the current operations to finish, when the cached connection is active? The alternative is to leave the old connection in place until its last release, as the expected check in dropConnection already allows.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread packages/server/src/workerd.ts Outdated
return ServerFetch.make(serverOptions(options), { overrides: replacements(options) })
return Effect.gen(function* () {
const server = yield* ServerFetch.makeWithContext(serverOptions(options), {
overrides: [...replacements(options), alarmWorkspaceReplacement(options.storage)],

@opencodejr opencodejr Bot Nov 24, 2026

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.

This always applies pollInterval: null + keepWarm: 0 in ServerWorkerd.create. A host that keeps using create() as a plain fetch handler, without forwarding alarm(), now gets no idle suspension at all. Before this change, the poller suspended idle workspaces while the isolate was awake. The new Handler type doesn't make alarm() mandatory, so that's easy to miss. Should alarm mode be opt-in here, like it is for replacements()? Otherwise, the doc comment on create should say that alarm() must be wired.

Sorry, something went wrong.

Uh oh!

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

All reactions
@kitlangton
feat(core,server): add Workspace keepWarm/attach/alarm lifecycle for …
da14773
…workerd
@kitlangton
kitlangton force-pushed the workerd-workspace-lifecycle branch from b11a8f1 to da14773 Compare November 24, 2026 21:21
opencodejr[bot]
opencodejr Bot reviewed Nov 24, 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.

Both earlier points are fixed.

  • Re-attach during an active op: the old connection now stays open until its last release closes it, and new operations go to the new binding. The new test covers this.
  • ServerWorkerd.create and polling: the doc comment on create now says callers must forward the Durable Object's alarm() to handler.alarm().

I found nothing new that needs changing. I re-ran the core workspace tests (27/27) and the server workerd tests (5/5), and tsc -b is clean for core, server and sdk. The public API impact is the same as in my earlier review.

Sorry, something went wrong.

Uh oh!

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

All reactions
@kitlangton
kitlangton merged commit fb56d1c into dev Nov 24, 2026
10 checks passed

Uh oh!

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

@kitlangton
kitlangton deleted the workerd-workspace-lifecycle branch November 24, 2026 21:59
@amrkmn amrkmn mentioned this pull request Nov 26, 2026
opencode 2.4.2 amrkmn/homebrew-tap#1260
Closed
1 task
This was referenced Nov 26, 2026
feat: opencode release v2.4.2 sprisa/opencode-server#97
Merged
Tool release: OpenCode 2 v2.4.2 (was v2.3.2) agent-sh/agnix#1894
Closed
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.