Skip to content

fix(Cloudflare/Container): await monitor() Promise instead of discarding it - #74

Merged
sam-goodwin merged 1 commit into
alchemy-run:mainfrom
yovanoc:fix/container-monitor-promise
Apr 20, 2026
Merged

sam-goodwin merged 1 commit into
alchemy-run:mainfrom
yovanoc:fix/container-monitor-promise

Conversation

@yovanoc

@yovanoc yovanoc commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Summary

state.container.monitor() returns Promise<void> that resolves when the container process exits. Wrapping it in Effect.sync() creates a synchronous effect that discards the return value, so the Promise is never awaited.

The monitor fiber completes instantly (logging "monitor exited" at the same ms as "started") and never detects container process death. This causes container.running to stay stale (true) when the process dies, ensureRunning skips restart, and port.fetch hangs on a dead process.

Fix

Use Effect.promise() to properly await the monitor Promise:

// Before (broken):
monitor: () => Effect.sync(() => state.container?.monitor()),

// After (fixed):
monitor: () =>
  Effect.promise(() => state.container?.monitor() ?? Promise.resolve()),

Note: start() remains Effect.sync() since Container.start() returns void per @cloudflare/workers-types (synchronous).

Testing

Deployed to Cloudflare Workers with a DeviceContainer (Bun runtime). After the fix:

  • Monitor fiber stays alive (logs "monitor started" persists, no instant "monitor exited")
  • Dead container processes are properly detected
  • port.fetch() no longer hangs indefinitely on dead processes

…ing it

state.container.monitor() returns Promise<void> that resolves when the container process exits.\nWrapping it in Effect.sync() creates a synchronous effect that discards the\nreturn value, so the Promise is never awaited. The monitor fiber completes\ninstantly (logging 'monitor exited' at the same ms as 'started') and never\ndetects container process death.\n\nThis causes container.running to stay stale (true) when the process dies,\nensureRunning skips restart, and port.fetch hangs on a dead process.\n\nFix: Use Effect.promise() to properly await the monitor Promise.\n\nNote: start() remains Effect.sync() since Container.start() returns void\nper @cloudflare/workers-types (synchronous).

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <[email protected]>
@sam-goodwin
sam-goodwin merged commit d75e6dd into alchemy-run:main Apr 20, 2026
1 check failed
sam-goodwin added a commit that referenced this pull request Jul 28, 2026
Review feedback from #963 (john-royal): replace the hand-rolled
ephemeral-workerd gateways with the runtime's platform proxy
(cloudflare-tools#88, extracted from #74).

- D1: withLocalD1Query opens a proxy hosting a raw `d1` service binding
  and POSTs the full D1 HTTP protocol through the proxy's fetch
  passthrough — multi-statement migrations/imports keep working, minus
  the bespoke gateway worker.
- KV/R2: the REST-API emulation gateways are gone entirely. For `dev:`
  ids the *Local layers now build the same native-binding clients the
  *Binding variants use (makeReadKVClient / makeRead / …) over
  per-operation proxied bindings; real ids keep the HTTP clients. A
  shared dispatchByMode builds the per-call dispatching client from the
  lazily-resolved id. R2 rich objects (R2ObjectBody bodies, metadata,
  writeHttpMetadata) ride the proxy's new "r2-object" encoding.
- LocalGateway.ts shrinks to the shared runtime layer, gatewayName, and
  dispatchByMode; the REST-emulation scaffolding (withLocalGateway,
  rebaseHttpClient) is deleted.

Co-authored-by: Cursor <[email protected]>
sam-goodwin added a commit that referenced this pull request Aug 4, 2026
DavidJFelix pushed a commit to DavidJFelix/alchemy-effect that referenced this pull request Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants