fix(rivetkit): lazy-load agent-os-core to avoid node:sqlite crash on Bun#4550
fix(rivetkit): lazy-load agent-os-core to avoid node:sqlite crash on Bun#4550brittianwarner wants to merge 2 commits intomainfrom
Conversation
|
This PR was not deployed automatically as @brittianwarner does not have access to the Railway project. In order to get automatic PR deploys, please add @brittianwarner to your workspace on Railway. |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
PR Review: fix(rivetkit) lazy-load agent-os-core Overall: Well-targeted, minimal fix. Consistent with the sqlite-pool.ts pattern. A few items to address before merge. Positive:
Issues: BUG (low-impact): Race condition in loadAgentOsCore during concurrent calls When two concurrent callers hit loadAgentOsCore() before the first import() resolves, both pass the null guard and create separate import(specifier) calls. The second assignment wins agentOsCorePromise, but both .catch handlers race to write agentOsCorePromise = null on failure. The dropped import() call can produce an unhandled promise rejection. Fix: Assign agentOsCorePromise to the full promise chain (including .catch) synchronously in one step before any await point, matching the sqlite-pool.ts approach. This closes the concurrent-caller race window. MINOR: No test coverage for the Bun import-safety guarantee Summary:
The core approach is correct. Main change before merging: fix assignment order so agentOsCorePromise is set synchronously before any await point. |
|
@NathanFlurry This is addition to #1428 |
Wrap loadAgentOsCore rejection with a descriptive error message and cause chain. Extract CreateMemFs type alias to clean up the verbose inline typeof import parameter on buildVmOptions.

Summary
@rivet-dev/agent-os-coreat runtime instead of importing eagerly at module levelrequire("node:sqlite")side-effect from crashing on runtimes that lack it (e.g. Bun)Array.join()specifier trick to prevent Turbopack from tracing into the module graph at compile time (same technique assqlite-pool.ts)Changes
agent-os/actor/index.ts: ConvertAgentOsandcreateInMemoryFileSystemfrom static imports to lazy dynamic imports vialoadAgentOsCore()buildVmOptions()now receivescreateMemFsas a parameter instead of importing it at the top level