Skip to content

Expose container instanceId in JS API#6528

Open
ghostwriternr wants to merge 2 commits intocloudflare:mainfrom
ghostwriternr:feat/container-instance-id
Open

Expose container instanceId in JS API#6528
ghostwriternr wants to merge 2 commits intocloudflare:mainfrom
ghostwriternr:feat/container-instance-id

Conversation

@ghostwriternr
Copy link
Copy Markdown
Member

Add a readonly instanceId property to ctx.container that exposes the container's placement_id — an opaque string that uniquely identifies the current container instance. It changes whenever a new container is provisioned (after sleep, crash, or eviction) and is undefined when no container is running.

This lets developers detect container replacement without resorting to writing marker files into the container filesystem.

instanceId follows the same lifecycle as running: it is populated from the status() RPC at construction, updated via a background task when start() resolves, and cleared when monitor() or destroy() fires. A lifecycle epoch counter guards against stale start responses writing back after the container has already been torn down.

Part of a cross-repo change — the container engine must populate the new capnp field before this surfaces useful values.

Containers are ephemeral — they can be replaced after sleep,
crash, or eviction. Users currently have no way to detect this
and resort to writing marker files into the container filesystem.

The Coordinator already assigns a unique placement_id to each
container instance. This exposes it as ctx.container.instanceId,
a readonly string property that changes whenever a new container
is provisioned and is undefined when no container is running.
@ghostwriternr ghostwriternr requested review from a team as code owners April 8, 2026 16:14
Verify instanceId is undefined when not running, a non-empty string
when the container is healthy, undefined after destroy, and changes
after a restart cycle.
@ghostwriternr ghostwriternr force-pushed the feat/container-instance-id branch from cfe50c6 to 410795d Compare April 8, 2026 16:24
@gabivlj
Copy link
Copy Markdown
Contributor

gabivlj commented Apr 8, 2026

I believe we'd want an RFC and develop a further discussion on how we want to approach this

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