GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(core,server): add Workspace keepWarm/attach/alarm lifecycle for workerd by kitlangton · Pull Request #66183 · anomalyco/opencode Conversation
|
| 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.
There was an error while loading. Please reload this page.
There was a problem 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.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:
ServerWorkerd.create now always disables the poller, so hosts that don't wire alarm() lose idle suspension completely.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| existingProvider: existing.provider, | ||
| }) | ||
| } | ||
| yield* dropConnection(workspaceID) |
There was a problem 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.
There was an error while loading. Please reload this page.
| 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)], |
There was a problem 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.
There was an error while loading. Please reload this page.
b11a8f1 to
da14773
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Both earlier points are fixed.
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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.