Upgrade: session-scoped workspaces
This page covers the session-scoped workspace releases, from @helix-agents/core 15.0.0 through the d5 release (core 25.0.0): the steps of the session-scoped workspaces design (spec). Each release has its own section: what to do, then what changed.
What to do, by release
- Phase 1 (core 15.0.0): delete a session's workspace from your own session deletion (
executor.destroyWorkspace(sessionId)), scheduleprovider.reap({ olderThan }), route a session to one replica for a host-bound provider, handleworkspace_unavailable, and add'unavailable'to exhaustiveswitches overWorkspaceEntryStateKind. - d1: the workspace binding: upgrade the stores and runtimes with core; a custom state store implements
updateWorkspaceBinding; a hand-builtDefaultWorkspaceRegistrytakesinitialBinding; removeadoptWorkspaceRefWrites/WorkspaceRefWrite; chooseWorkspaceConfig.onUnavailable. - d2: provider durability and destroy: pass the Cloudflare sandbox's required
scope, removedestroyOnClose, route each session to the host that opened its workspace (sethostIdwhere needed), schedule docker'sreap, adddurabilityanddestroyto a custom provider andlistContainersto a customDockerEngine, and read the per-session id and behaviour changes for the Cloudflare providers. - d3: workspace scope: remove
workspaceLifetime, handleend_pending, and setreusesSessionIdson a custom provider that names the same resource for every open of a session;scope: 'turn'andonWorkspaceDestroyare optional. - d4: Durable Object operations and companion ends: the CF Durable Object gains
destroyWorkspace/resetWorkspaceandworkspaceEndWaitMs; an agent resolver that switches exhaustively on the lookupreasonhandles'workspace_hook'. - d5: operations on every executor and agent-server: a custom
AgentExecutoraddsdestroyWorkspace/resetWorkspace; callers handle the returned outcome; agent-server's new routes go throughauthorize; code that namesdescribeWorkspace'sno-registryor switches overHostOperationis updated.
Phase 1 (core 15.0.0)
@helix-agents/core 15.0.0 (major), with minors of the workspace providers, @helix-agents/runtime-js, @helix-agents/agent-server and @helix-agents/tracing-langfuse: a run's end keeps the workspace; deleting it is your call.
@helix-agents/core 15.0.0 changes what happens to a session's workspace when a run ends. Before, every run's end deleted the workspace's files on local-bash, local-sandbox and docker, including every suspension (a client tool, an approval, waiting on sub-agents) and every completed turn. The session's next run then silently got an empty workspace. Now a run's end only releases the workspace, and its data stays until you delete it.
The release also bumps the workspace providers, @helix-agents/runtime-js, @helix-agents/agent-server and @helix-agents/tracing-langfuse (minors). Deploy them together, in one release.
What to do
- Delete workspaces when you delete sessions. Call
executor.destroyWorkspace(sessionId)from your own session deletion. Without it, local-bash / local-sandbox / docker files and in-memory workspaces stay until you reap them. - Reap abandoned workspaces on a schedule. For local-bash and local-sandbox, call
provider.reap({ olderThan })from a cron or alarm. PickolderThanlonger than your longest run plus how long a session's workspace should be kept when idle. - Route a session to one replica when a host-bound provider (local-bash, local-sandbox, docker) serves it. Another replica can't see that host's files, and a misrouted request now fails typed instead of silently starting empty.
- Handle
workspace_unavailable. When a stored workspace can't be reattached, workspace tools fail with it. Callexecutor.resetWorkspace(sessionId)to start the session over with a fresh workspace (see below). - Update exhaustive
switches overWorkspaceEntryStateKind/EntrySnapshot.stateto include'unavailable'.
What changed
A run's end releases; destroy is explicit
- local-bash and local-sandbox:
close()keeps the tmpdir. - docker:
close()stops and removes the container but keeps the host tmpdir.resolve()recreates a container over it. - New, optional provider methods:
WorkspaceProvider.destroy?(ref)deletes one workspace. It validates the ref exactly asresolve()does, and refuses (deleting nothing) a ref outside the provider's own storage.WorkspaceProvider.reap?({ olderThan })removes the provider's own abandoned workspaces, by last use. It never follows a link.- local-bash, local-sandbox, docker and in-memory implement
destroy; local-bash and local-sandbox implementreap. The Cloudflare providers have neither yet, and keep their behaviour. (A later release madedestroyrequired and gave the Cloudflare providers one: see d2.)
- runtime-js keeps one workspace registry per session. A run takes a hold on it and releases the hold at its end. An inheriting child (
inheritWorkspace: true) holds its parent's workspace until it ends, so a non-blocking companion still running after its parent's run keeps working on the same files. - Children end their own. A sub-agent or a companion consult with its own workspace keeps it across its own suspensions. When it ends (
completed,failedorinterrupted), the framework clears its stored ref and destroys the workspace, so a companion's next consult starts fresh. This is skipped for a provider withoutdestroy. (A later release madedestroyrequired, so no provider is skipped: see d2.)
destroyWorkspace / resetWorkspace
// From your own session deletion:
await executor.destroyWorkspace(sessionId);
// After a workspace_unavailable loss, or to start over:
await executor.resetWorkspace(sessionId);- What they do: both clear the session's stored workspace ref under the idle fence, then call the provider's
destroy(ref). The session's next run opens a fresh workspace. In this releaseresetWorkspaceis the same asdestroyWorkspace. - A session with no stored workspace is a no-op.
- Refused with
AgentAlreadyRunningError, changing nothing:- while the session has a live run;
- while a run or an inheriting child in this process still holds the workspace.
- A provider without
destroy(or one not registered on this executor) is refused withframework_not_supported. (A later release madedestroyrequired; only an unregistered provider is refused now: see d2.) - If the provider's own delete fails, the error is rethrown after the ref is cleared. Nothing reattaches the workspace, and the provider's
reapremoves the leftover. - Later releases: d4 adds these operations to the CF Durable Object, and d5 makes them return an outcome and bounds their wait on runtime-js.
A lost workspace is typed: workspace_unavailable
When: a stored ref whose
resolve()reports the workspace gone makes the registry entry'unavailable'. Every workspace tool then fails withWorkspaceUnavailableError:code: 'workspace_unavailable';reason: 'not_found' | 'process_restarted';- non-retryable.
Nothing is opened in its place. Before, the registry silently opened a fresh, empty workspace.
Typical causes:
- the files were removed (a reap, a host wipe);
- the request reached another replica (
not_found); - an in-memory workspace's process restarted (
process_restarted).
Signals:
onWorkspaceUnavailable(agent hook) andWorkspaceHooks.onUnavailablefire;- tracing-langfuse records an
ERRORspan.
Recovery:
executor.resetWorkspace(sessionId).onEvictionRetry/onWorkspaceEvictionRetry:'recovered'now always means the same workspace was reattached, never a fresh one;'exhausted'also fires when the retry finds the workspace gone (aWorkspaceUnavailableError), not only on a second eviction.
WorkspaceEntryStateKind gains 'unavailable' (the major)
The registry state union, also EntrySnapshot.state, has a new member. Code that switches over it exhaustively needs the new case:
// EntrySnapshot.state is WorkspaceEntryStateKind minus 'unknown' (peekState's no-entry sentinel).
switch (snapshot.state) {
case 'configured':
case 'opening':
case 'open':
case 'closing':
case 'closed':
case 'failed':
case 'evicted':
// …
break;
case 'unavailable':
// New: the workspace is gone; tools fail with workspace_unavailable until resetWorkspace.
break;
}In-memory provider: a provider-level map
- Reattaching:
InMemoryWorkspaceProvidernow keeps its workspaces in a provider-level map, so a session's workspace reattaches within the provider's process. Its ref is schema version 3 and carries the instance's nonce. - Restarts: after a restart, or on a new CF Durable Object instance, the ref is
workspace_unavailable(process_restarted). - The map grows until
destroy(ref), and the provider has noreap. A long-lived process callsdestroyWorkspace(sessionId)for the sessions it's done with. - Peer dependency: the provider now declares
zodas a peer dependency (core already requires it).
One replica per session for host-bound providers
local-bash, local-sandbox and docker store a workspace on one host. Serve a session's requests from the replica that holds its workspace (sticky routing by session id). A request that reaches another replica now fails with workspace_unavailable (not_found) instead of silently starting an empty workspace.
agent-server: expired sessions' workspaces are destroyed
- What it does: for an expired session (
expiresAtin the past) that is notcompletedorfailed,expiredSessionCleanupnow clears its stored ref under the idle fence, then destroys the workspace. The result's newworkspacesDestroyedcounts them. - What it skips:
- a session with a live run is not touched, and counts in
errors; - a provider without
destroyis skipped (a later release madedestroyrequired: see d2); - completed and failed sessions are not handled here: their workspaces need your
destroyWorkspaceor the provider'sreap.
- a session with a live run is not touched, and counts in
d1: the workspace binding
@helix-agents/core 21.0.0 and @helix-agents/runtime-js 40.0.0 (majors), with minors of the state stores: the session's workspace binding, one writer, and a typed loss.
This release makes the workspace binding the one persisted record of a session's workspace, and gives it a store op, updateWorkspaceBinding, that every writer of it goes through. A workspace that cannot be reattached is a typed, configurable loss. It is steps d1a and d1b of the session-scoped workspaces design (spec §2.1, §3.1, §3.3, §6).
It is a major release of @helix-agents/core and @helix-agents/runtime-js:
- every state store must implement the new method, and runtime-js's construction-time store guard requires it;
- R38's exports are removed, and the registry's
initialRefdependency is nowinitialBinding.
What to do
- You use the SDK's stores and runtimes: upgrade them together with core. No migration: the binding reuses the existing
workspace_refcolumn. @helix-agents/runtime-js40.0.0 (major):JSAgentExecutor's construction-time store guard now requiresupdateWorkspaceBinding(WORKSPACE_BINDING_STORE_METHODS). A store without it is refused when the executor is built, not at a run's first workspace write. The CF Durable Object runs this executor, so the same applies there.- You wrote a custom state store: implement
updateWorkspaceBinding, keep the column out of every full-state write (below), and run the contract suite. - You built a
DefaultWorkspaceRegistryyourself: passinitialBinding(the session'sSessionState.workspaceBinding) instead ofinitialRef, and optionallyendBinding(below). - You used
adoptWorkspaceRefWrites/WorkspaceRefWrite: remove them. Persisting a ref no longer moves the session's version, so nothing needs adopting. - Choose what a lost workspace does: set
WorkspaceConfig.onUnavailable(below). The default is unchanged: it fails typed.
What changed
SessionState.workspaceBinding(read-only) is the session's workspace record as stored:{ state: 'bound', ref, turnId?, openedAt? }: the workspace and its ref (the same asworkspaceRef);{ state: 'ended', reason, at, providerId }: a tombstone, the workspace ended on purpose (destroyed,reset,expired,child_ended, …);- absent: the session never opened a workspace.
AgentState.workspaceBindingcarries it into a run.
Only the op writes the column. Full-state writes (
saveState, the step and suspension commits, the terminalcommitState) keep the stored binding, whateverworkspaceRefthe state they write carries. So a tombstone is never resurrected by a full-state write.The framework's writers use the op:
- a workspace the registry opens is persisted with a compare-and-set over the binding the run last saw, fenced on the run (core
persistWorkspaceRef). It retries once over another open; it never writes over anendedtombstone it did not see (it logs and leaves the tombstone); - a child's or a companion consult's end writes
ended/child_endedbefore its terminal commit; destroyWorkspace,resetWorkspaceand agent-server'sexpiredSessionCleanupwriteendedwithdestroyed,resetorexpired. They are refused while a run is live.
- a workspace the registry opens is persisted with a compare-and-set over the binding the run last saw, fenced on the run (core
The column holds only a binding.
readStoredWorkspaceBindingis its one reader. A value that is not a binding reads as none, logged at error (state_corrupt_row, ids only).readStoredWorkspaceRefandworkspaceRefColumnare removed; usereadStoredWorkspaceBinding/workspaceBindingColumnandboundWorkspaceRef.The registry reads the binding. An
endedtombstone opens a fresh workspace. Aboundone is resolved, then verified:Workspace.verify?()(new, optional) runs after everyresolve, and on a run's firstget()of a workspace an earlier run left open.A lost workspace (a resolve that throws
WorkspaceEvictedError, or a failed verify) followsWorkspaceConfig.onUnavailable:'fail'(default): the workspace isunavailable; workspace tools fail withWorkspaceUnavailableErroruntil the app callsresetWorkspace(sessionId). Nothing is opened.'reset': the run destroys the lost workspace (best effort), ends the bindingreset, opens a fresh one, and firesonWorkspaceReset.
WorkspaceUnavailableReasongainswrong_hostandcontent_reset(a verify failure). Update exhaustiveswitches.Hooks:
onWorkspaceResetis new (WorkspaceResetPayload). Langfuse records it as aworkspace:resetspan.
Custom state stores
Implement updateWorkspaceBinding(sessionId, change, opts?) as one atomic step that touches only the workspace_ref column (or your store's equivalent):
A missing session throws
state_session_not_found(coresessionNotFoundError).Check the fences in the same atomic step, the same rules as
saveState's:opts.fenceRunId: the run is the session's current, live run;opts.fenceIdle.runId: that run is still the session's current run and has ended (null: the session has no run).
Either failing throws
RunSupersededErrorwith nothing written. Core'sassertRunIsCurrentLive/assertRunIsCurrentIdleimplement both checks.Read the stored column with
readStoredWorkspaceBinding, and decide with coreapplyWorkspaceBindingChange(stored, change). It validateschange.next(a malformed binding throws a non-retryablevalidation_error, nothing written) and compares the stored binding withchange.expect.When it answers
write: true, writeworkspaceBindingColumn(next)to the column. Move noversion, write no checkpoint, bump nothing else. Return itsresult:{ written: true, binding }, or, on a mismatch,{ written: false, actual }with nothing written.If your store bounds state size (
maxStateBytes), measure the column you write and refuse an oversized one withStateSizeExceededError(operationstate), nothing written.If your compare-and-set can lose a race (a read followed by a conditional write), retry it
WORKSPACE_BINDING_ATTEMPTStimes, then throw coreworkspaceBindingContendedError(sessionId)(a retryablestate_concurrency_conflict).loadStatefills bothworkspaceBindingandworkspaceRef(theboundbinding's ref) from the column.Every full-state write keeps the column:
saveState,saveStateAndPromoteStaging,commitStateand any other write of a wholeSessionStatemust not write it, whateverworkspaceRef/workspaceBindingthe state carries.
Run the contract. stateStoreContractTests from @helix-agents/core/testing includes the workspace-binding scenarios (workspaceBindingOperationTests, WSB-1..8). WSB-6 (the size cap) is in the size-limit suite. WSB-5 (a value that is not a binding reads as none) needs the runner hook rawHooks.writeWorkspaceColumnRaw(sessionId, raw) that writes your raw column; without it, WSB-5 is skipped. A store that passes them implements the method as the SDK's stores do.
d2: provider durability and destroy
@helix-agents/core 23.0.0, @helix-agents/runtime-cloudflare 29.0.0 and @helix-agents/workspace-docker 2.0.0 (majors), with minors of runtime-js and the other workspace providers: every provider says where its refs resolve and can delete what it opened.
This release makes every workspace provider say where its refs resolve and lets every provider delete what it opened. It is the workspace providers step (d2) of the session-scoped workspaces design (spec §3.2, §3.3, §7).
It is a major release of @helix-agents/core, @helix-agents/runtime-cloudflare and @helix-agents/workspace-docker, with minors of @helix-agents/runtime-js, @helix-agents/workspace-posix-core, @helix-agents/workspace-local-bash, @helix-agents/workspace-local-sandbox and @helix-agents/workspace-memory.
Who is affected:
- apps that use the Cloudflare sandbox's
destroyOnClose; - apps that use a per-session Cloudflare sandbox or filestore, or set an explicit sandbox
idor filestorenamespace(see Per-session ids); - apps whose sub-agents or companions declare their own Cloudflare filestore or sandbox workspace (see Behaviour changes);
- multi-host Node deployments of local-bash, local-sandbox or docker;
- anyone who wrote a custom
WorkspaceProvideror a customDockerEngine.
What to do
You use the SDK's providers and runtimes: upgrade them together with core, in one release.
You construct a
CloudflareSandboxWorkspaceProvider: pass the new requiredscopeoption, what owns the session store the provider serves. On the CF Durable Object, use the agent DO's own id; theworkspaceProvidersfactory receives(env, ctx):tsworkspaceProviders: (env, ctx) => new Map([ [ 'cloudflare-sandbox', new CloudflareSandboxWorkspaceProvider({ namespace: env.Sandbox, scope: ctx.id.toString(), }), ], ]);On another host, pass a value that uniquely names the store the sessions' state lives in, the same on every call. A missing or empty
scopeis a typedWorkspaceFailedErrorat construction.You set
destroyOnCloseon a Cloudflare sandbox: remove it. It no longer exists. A run's end is a release and never destroys the container. Delete a session's container when it is no longer needed. An executor that hosts the provider does it withdestroyWorkspace(sessionId)(the provider'sdestroy, which callssandbox.destroy()).On the CF Durable Object, until its own workspace operation ships (it shipped in d4): the DO exposed no
destroyWorkspaceto the app yet. A child's or consult's container is still destroyed at its end, but a root session's container is the app's to delete, in one line (a per-session container's sandbox id iscloudflareSandboxIdForSession(scope, sessionId), with the provider'sscope: the DO'sctx.id.toString()):tsimport { getSandbox } from '@cloudflare/sandbox'; import { cloudflareSandboxIdForSession } from '@helix-agents/runtime-cloudflare/sandbox'; await getSandbox(env.Sandbox, await cloudflareSandboxIdForSession(scope, sessionId)).destroy();The DO step of the design (d4) adds the DO's own workspace operation, which replaces this call (see d4). Until then a lost sandbox workspace is reset by default (the provider's
defaultOnUnavailableis'reset'), so a container whose disk was reset is replaced without an app call; see Behaviour changes.
You run local-bash, local-sandbox or docker on more than one host: route every request of a session to the host that opened its workspace (sticky routing). A ref from another host is now refused typed (
wrong_host). Set the provider'shostIdoption when several hosts (containers) share a hostname but not a filesystem. The defaulthostIdis the hostname, which changes when a container or pod is recreated: whentmpdirRootis on a persistent volume, sethostIdto a stable value, or the recreated host refuses its own workspaceswrong_host. Awrong_hostloss is never reset, whateveronUnavailablesays: the workspace still exists on the host that opened it.You use docker: schedule
provider.reap({ olderThan })on every host, as for local-bash and local-sandbox. PickolderThanlonger than your longest run plus the idle time a session's workspace should be kept.You wrote a custom
WorkspaceProvider: add the two required members,durabilityanddestroy(ref), to the contract below. See Building a provider.You wrote a custom
DockerEngine: implementlistContainers(label): every container (running or not) carrying the labelkey=value, with all its labels.Your sub-agents or companions keep files in their own Cloudflare workspace: read Behaviour changes. Those files are now deleted at the child's end.
You use a Cloudflare sandbox or filestore: read Per-session ids. A per-session workspace has a new id, and an explicit
id/namespacenow always needsshareAcrossSessions: true.
Per-session ids
Session and shared Cloudflare workspaces use separate ids, and per-session workspace ids are scoped to the owning Durable Object (or the configured scope).
- Per-session sandbox (no
id): the container's sandbox id iscloudflareSandboxIdForSession(scope, sessionId),helix-session-plus 24 hex characters of SHA-256 of the scope and the session id (lowercase, 38 characters). It is no longer the session id.cloudflareSandboxIdForSessionandSESSION_SANDBOX_ID_PREFIXare exported from@helix-agents/runtime-cloudflare/sandbox. - Per-session filestore (no
namespace): the namespace iscloudflareFileStoreNamespaceForSession(doId, sessionId),helix_session_plus 32 hex characters of SHA-256 of the Durable Object's id and the session id. It replaces "the session id when valid, elses_<hex>". Its R2 spill keys are scoped to the Durable Object too (<doId>/<namespace>/<path>).cloudflareFileStoreNamespaceForSessionandSESSION_FILESTORE_NAMESPACE_PREFIXare exported from@helix-agents/runtime-cloudflare/filestore. - An explicit
id/namespaceis always a shared workspace. It requiresshareAcrossSessions: true, also when it equals the session id, and it may not start withhelix-session-/helix_session_(case-insensitive). Either violation is a typedWorkspaceFailedErrorat open. If you setid: sessionId(ornamespace: sessionId) to get a per-session workspace, omitid/namespaceinstead. - Workspaces created before this release are not reattached. A per-session sandbox or filestore namespace created before this release was named by the session id (or
s_<hex>for a filestore session id that is not a valid namespace), so the new release opens a fresh one. There is no migration. Remove the old ones with platform tools:- sandbox:
await getSandbox(env.Sandbox, oldSessionId).destroy(); - filestore: drop the old namespace's
cf_workspace_<old namespace>tables from the Durable Object's storage, and delete its R2 spill objects (keys under<old namespace>/<old namespace>/).
- sandbox:
The provider contract
durability: WorkspaceDurability(required): one of'process': the ref resolves only in the process that opened it;'host': on the host that opened it, while its files exist; a multi-replica Node deployment needs sticky routing;'global': wherever the provider's bindings reach.
destroy(ref)(required; was optional) deletes the workspace's data and resources:- it works without a live handle;
- it is idempotent: a missing workspace is already destroyed;
- it never re-creates anything, and afterwards
resolve(ref)throwsWorkspaceEvictedError; - it validates the ref as
resolve()does, and refuses a ref it cannot validate withWorkspaceFailedError, deleting nothing; - a
'host'provider refuses a ref from another host withWorkspaceEvictedErrorreason: 'wrong_host', deleting nothing; - a provider with nothing to delete implements it as a no-op.
reap({ olderThan })stays optional.Workspace.verify()(optional): implement it whenresolvecan succeed against a reset resource. It throwsWorkspaceEvictedErrorreason: 'content_reset'when the live workspace is no longer the one its ref names.close()still releases and never deletes data.
@helix-agents/workspace-posix-core exports the shared host-binding helpers, resolveHostId(hostId?) and assertRefHost(refHost, hostId, providerId).
What changed
- core:
WorkspaceProvidergains the requireddurabilityanddestroy(above), and an optionaldefaultOnUnavailable?: 'fail' | 'reset': what a lost workspace does when itsWorkspaceConfig.onUnavailableis unset (else'fail'; an explicitonUnavailablealways wins).- A
wrong_hostloss is never reset: the workspace staysunavailable, typed, whateveronUnavailablesays. executor.destroyWorkspace(sessionId)andresetWorkspace(sessionId)are refused withframework_not_supportedonly when the session's provider is not registered on the executor. CoredestroySessionWorkspaceanswersunsupportedonly in that case.
- local-bash, local-sandbox, docker (
durability: 'host'):- each ref records the host that opened it: the provider's new
hostIdoption, elseos.hostname(); resolveordestroyof a ref from another host throwsWorkspaceEvictedErrorwithreason: 'wrong_host'and deletes nothing. The registry reports it asWorkspaceUnavailableError(workspace_unavailable) with reasonwrong_host, instead of a missing tmpdir (not_found).
- each ref records the host that opened it: the provider's new
- docker:
- new
reap({ olderThan }): it removes this provider's containers on this host whose tmpdir is gone or was last used at leastolderThanms ago, then its idle tmpdirs (the same rule as local-bash'sreap). It never touches another host's containers, anothertmpdirRoot's, one whose tmpdir is not one of the provider's own (helix-dk-…), or unlabelled ones; - containers carry the labels
helix.workspace.provider=docker,helix.workspace.tmpdirandhelix.workspace.host; - resolving and releasing a workspace mark its tmpdir used;
- release (
close()) still stops and removes the container and keeps the files; DockerEnginegainslistContainers(label).
- new
- workspace-memory:
durability: 'process'. - Cloudflare filestore (
durability: 'global'):- its ref carries the owning Durable Object's id, so
resolveordestroyin another DO is refusedwrong_hostand never opens empty tables; destroydeletes the namespace's files and their R2 spill objects; R2 spill keys are scoped to the Durable Object;- a marker table,
helix_workspace_filestore, records each namespace's current opening, so a destroyed or replaced opening resolvesnot_found(a session's namespace is reused by its next workspace). A destroy removes the namespace's rows and its marker in one step (a newer opening of the namespace always starts empty), then deletes the spilled R2 objects, keeping any object a newer opening references again. The table also records whether the namespace is shared: an open whose sharing disagrees with it is refused, typedWorkspaceFailedError, anddestroynever deletes a namespace marked shared.
- its ref carries the owning Durable Object's id, so
- Cloudflare sandbox (
durability: 'global'):destroyOnCloseis removed.close()is a release and never destroys the container;- the new required
scopeoption scopes per-session container ids to the owner of the session store (above); openwrites a marker file,<workspaceDir>/.helix/workspace-id, holding{ "id": <opening id>, "shared": <bool> }. An open whose sharing disagrees with the container's marker is refused, typedWorkspaceFailedError, before any configuration call (sleepAfter, env vars, bucket mounts);verify()reads it back (one file read per run). The registry calls it after everyresolve, and on a run's first get of a workspace still open from an earlier run. A container whose disk was reset (a sleep pastsleepAfter, a replacement) is reportedcontent_reset, instead of a silently empty workspace. What follows is the workspace'sonUnavailablesetting:'reset'(the sandbox's default, see below) destroys the old workspace and opens a fresh one;'fail'fails workspace tools withworkspace_unavailableuntil the app callsresetWorkspace(on the CF DO from d4);destroy(ref)callssandbox.destroy()on its own opening's per-session container: when the marker is its own, or missing (a reset disk). A container whose marker names another opening, or is shared, is left alone (logged at warn). A ref whose id does not match its sharing is refused, typed, and nothing is destroyed;- a snapshot restore or branch writes its own marker into the restored container; from a shared base the restored container is a per-session one, with an id of its own, so the session's destroy removes it;
- an app that needs files to survive a sleep uses the Cloudflare Sandbox SDK's
keepAliveor the snapshot tools.
- Cloudflare script runner (
durability: 'global'):destroyis a no-op (stateless isolates).
Behaviour changes
- A child's workspace is destroyed at its end on every provider. A child session's (an ephemeral sub-agent's) or a companion consult's own workspace is ended and destroyed at the child's terminal exit on every provider, the Cloudflare filestore and sandbox included, on the CF Durable Object too. The child's workspace contents are gone after its terminal exit. Before, the Cloudflare providers had no
destroy, so their child and companion workspaces were kept across consults. A root session's workspace is still kept until the app destroys it. An interrupted child counts as a terminal exit: a CF Durable Object child that is resumed afterwards starts with a fresh workspace. A new run of the session (the next consult, a resume, a retry) opens its workspace after the previous run's destroy has finished, waiting up toworkspaceEndWaitMs(default 30 s; a Stop ends the wait): within one runtime-js executor through its session workspaces, and on the CF Durable Object across all its drives (they share the session workspace registries, and a drive's settle waits for the session's pending ends, bounded, before the next entry; hibernation or eviction drops that wait, and a destroy an eviction cut is the provider'sreap()). PastworkspaceEndWaitMs, a provider whose per-session resource repeats (A2A R0(d) d3,reusesSessionIds: the Cloudflare filestore and sandbox) gets no workspace for that run (its workspace tools are refused typed,end_pending); any other provider opens a fresh one. Across runtime-js processes the order is not guaranteed. - A lost Cloudflare sandbox workspace is reset by default. The sandbox provider's
defaultOnUnavailableis'reset': a container whose disk was reset (content_reset) or that is gone is destroyed and replaced by a fresh, empty workspace, firingonWorkspaceResetand logging a warning. Until the DO's own workspace operation (d4) gives the app a reset call,'fail'would leave a root session's workspace unusable on the DO. SetonUnavailable: 'fail'explicitly to keep the old behaviour (for example to inspect a lost container). d4 revisits this default. - A shared workspace is never destroyed. A filestore with an explicit
namespaceandshareAcrossSessions: true, or a sandbox with an explicitidandshareAcrossSessions: true, is shared by every session that opens it.destroynever removes its data: it logs a warning (ids only) and returns. An app that wants that data gone removes it on purpose itself:- filestore: delete the files in that namespace, for example by opening it and removing its entries with
ws.fs.rm(which also removes their R2 spill objects), or by dropping its tables from the DO's storage; - sandbox: call
getSandbox(env.Sandbox, id).destroy()from@cloudflare/sandbox, with the sharedid.
- filestore: delete the files in that namespace, for example by opening it and removing its entries with
- A ref written before this release fails validation. local-bash, local-sandbox and docker refs now carry the host, and filestore and sandbox refs carry their new ids. A ref written before this release fails payload validation with a typed
WorkspaceFailedError. There is no legacy-ref handling.
d3: workspace scope
@helix-agents/core 24.0.0 (major) and @helix-agents/runtime-js 40.2.0 (minor): workspace scope, onWorkspaceDestroy, and workspaceLifetime removed.
A2A R0(d) d3, the runtime-js step of the session-scoped workspaces spec. @helix-agents/core is a major release (PersistentAgentConfig.workspaceLifetime is removed); @helix-agents/runtime-js is a minor.
What to do
- Remove
workspaceLifetimefrom everypersistentAgentsentry: the setting is removed, and a companion keeps a fresh workspace per consult. - Optional:
scope: 'turn'on a root agent'sworkspacefor a workspace per turn (destroyed when the turn ends). The default,'session', is today's behaviour. - Optional:
onWorkspaceDestroyin the agent's hooks, to learn when the framework destroyed a workspace (itsreason, the session it belonged to). UnderonUnavailable: 'reset'it fires beforeonWorkspaceReset. - Handle
end_pendingwherever you switch overWorkspaceUnavailableReasonexhaustively (a new member is a type error there). AnonWorkspaceUnavailablehandler that callsresetWorkspaceshould skipreason: 'end_pending': that refusal is the run's own, and a later run opens fresh once the end has finished. - A custom provider whose
opennames the same resource for every open of a session setsreusesSessionIds: true, so a session's open follows the end of its previous workspace (the Cloudflare filestore and sandbox set it).
What changed
WorkspaceConfig.scope?: 'session' | 'turn'(core). A root's'turn'workspace is kept across the turn's suspensions and continuations, and destroyed when the turn ends (a stop ends the turn wherever it lands); a workspace an earlier turn left bound is destroyed at a later run's entry; a crash between a turn's end and its destroy leaves the workspace to the provider'sreap(), which the app schedules (user ruling 2026-11-19). A sub-agent's or a companion's own workspace follows the child lifetime whatever it says; a child declaring'session'is logged once per agent type per executor.AgentHooks.onWorkspaceDestroy(core,WorkspaceDestroyPayload,WorkspaceDestroyReason), andWorkspaceHooks.onDestroyfor registry hook integrations. It fires for framework destroys only.A companion's terminate and respawn end its workspace on runtime-js: a companion terminated while its consult is paused has its workspace destroyed once the stop is recorded, and a respawn destroys the old session's workspace before the session is replaced (core
CompanionToolDispatchDeps.endChildWorkspace, which runtime-js supplies).A session's open follows its previous end (runtime-js). A destroy the run stops waiting for (past the executor's
workspaceEndWaitMs, default 30 s, or at a Stop) is still the session's pending end: the next run waits for it, and its success, when it comes, firesonWorkspaceDestroyonce. On a provider whose per-session resource repeats (coreWorkspaceProvider.reusesSessionIds, set by the Cloudflare filestore and sandbox), a run whose wait ends first opens no workspace: its workspace tools fail withWorkspaceUnavailableError(reason: 'end_pending') andonWorkspaceUnavailablefires, for that run only; a later run opens fresh once the end has finished. This includes a'turn'workspace an inheriting companion still holds after its turn: the session's later turns wait for that companion to end. Any other provider opens a fresh workspace past the bound and logs the end, as before. On the CF Durable Object the runs of every drive wait for it: the DO's drives share one set of session workspace registries, and a drive's settle waits for the session's pending ends (at mostworkspaceEndWaitMs, never more than half ofconcurrentEntryTimeoutMs) before it admits the next entry. Hibernation or eviction drops that in-memory wait: the next drive rebuilds the registry from the stored binding, and a destroy an eviction cut is left to the provider'sreap()(user ruling 2026-11-19).
Scope by runtime
- runtime-js: all of the above.
- CF Durable Object:
scope, the turn end and the earlier-turn check, andonWorkspaceDestroyfor them, through the runtime-js run loop it runs, across all its drives (above). Its workspace operations and a companion's end are in d4. - CF Workflows, Temporal and DBOS refuse workspace agents, unchanged.
There is no framework idle TTL or sweep, and no text for the model (user rulings 2026-11-13 and 2026-11-19): the app ends a root session's workspace (destroyWorkspace / resetWorkspace), schedules reap, and renders any context it wants the model to see.
d4: Durable Object operations and companion ends
@helix-agents/runtime-cloudflare 29.2.0, @helix-agents/runtime-js 40.3.0 and @helix-agents/core 24.1.0 (minors): the CF Durable Object's workspace operations and a companion's workspace end (A2A R0(d) d4).
- Operations.
DOFrontendExecutor.destroyWorkspace(sessionId)/resetWorkspace(sessionId)(POST /workspace/destroy//workspace/resetthroughhandle) end the session's workspace as runtime-js's executor does: refusedstate_already_runningwhile a run is live or holds it,framework_not_supportedfor a provider the DO does not register. A destroy still running pastworkspaceEndWaitMsresolves the call (logged at warn): the binding has ended, and the session's next run waits for the destroy. The methods returnvoid, as runtime-js's do. (d5 makes both return an outcome: see d5.) While the operation runs it holds the DO's producer claim, so another entry of the session is answered as against a running drive: one without a request key is refusedstate_already_running(409, nothing written), and a keyed one waits for the operation, up toconcurrentEntryTimeoutMs. A session's identity is fixed at creation: the operations refuse a request whose verdict names another identity (validation_error), as entries do. DurableObjectAgentConfig.workspaceEndWaitMs(default 30 000 ms): a run's wait for its session's previous end, and the bound of the operations' and a companion end's destroy. A drive's settle waits for the session's pending ends for at most this, and never more than half ofconcurrentEntryTimeoutMs.- Companions. A terminate or a respawn ends the companion's workspace in its own Durable Object. A destroy that finishes within the companion's
workspaceEndWaitMsfires the parent'sonWorkspaceDestroywith the companion'ssessionId, as on runtime-js. One still running past it fires the companion agent's ownonWorkspaceDestroywhen it succeeds (on runtime-js the parent's fires then), and a respawn ends a workspace still bound when the companion's session is wiped, firing the companion agent's own hook. A hook fired outside a run reads the session's state; itsupdateStateandemitdo nothing and itsaddContextis refused typed. The companion's own late hook fires while its Durable Object instance stays live (hibernation or eviction drops it, as it drops the pending end), and a Stop of the parent during a companion's workspace end can leave its hook unfired; the destroy itself still completes. - An agent resolver that switches exhaustively on the lookup context's
reasonhandles'workspace_hook'.
d5: operations on every executor and agent-server
@helix-agents/core 25.0.0 and @helix-agents/agent-server 11.0.0 (majors), with minors of runtime-js, runtime-cloudflare, runtime-temporal and runtime-dbos: workspace operations on every executor, and on agent-server (A2A R0(d) d5).
- Custom
AgentExecutorimplementations adddestroyWorkspace(sessionId)andresetWorkspace(sessionId), bothPromise<WorkspaceOperationOutcome>. An executor without workspaces rejects themframework_not_supportedbefore doing anything (coreworkspaceOperationNotSupported({ runtimeName, sessionId, fallbackRuntimes })builds the error); CF Workflows, Temporal and DBOS do this. - runtime-js:
JSAgentExecutor.destroyWorkspace/resetWorkspaceresolve todestroyed,noneorstill_running(they returnedvoid), and wait for the provider's destroy for at most the executor'sworkspaceEndWaitMs(they waited without a bound). Past it the binding has ended and the destroy keeps running as the session's pending end in this process: the session's next run here waits for it, a run in another process does not. - CF Durable Object:
DOFrontendExecutor.destroyWorkspace/resetWorkspaceresolve to the DO's outcome (they returnedvoid). The DO servesGET /workspacethroughhandle:{ binding, workspace }, a read with no identity check. - agent-server (major):
POST /workspace/destroyandPOST /workspace/reset({ sessionId }→{ outcome }):authorizegets'workspace.destroy'/'workspace.reset'; not admitted, with no identity check (session ownership is the app's check). Gate them inauthorize.GET /workspaceanswers{ binding, workspace }from the stored binding: a bound session between runs, or on another replica, is200(it was404 WORKSPACES_NOT_FOUND), an unknown session is404 NOT_FOUND, and the body'sworkspacekey keeps the live snapshot (nullwithout one).AgentServer.describeWorkspacereturns{ kind: 'ok', binding, snapshot },{ kind: 'not-found' }, or{ kind: 'no-runtime-support' }for an executor without workspaces (the route answers404 RUNTIME_NO_WORKSPACE_SUPPORT);no-registryis gone, so code that names it stops compiling.- A provider's destroy failure is answered after the binding ended: a typed error at its own status, anything else the generic
500 INTERNAL_ERROR.
HostOperationgains'workspace.destroy'and'workspace.reset': an exhaustiveswitchover it handles them.- Not built:
createAgentHost(the A2A host) has no workspace operations yet (A2A R1).
See also
- Workspaces (its
scopesection) and Workspaces: Session-scoped workspaces - Sub-agents: workspaces
- Building a provider:
destroyandreapfor a custom provider, and the durability and destroy contract. - Cloudflare Sandbox — Lifecycle and Cloudflare Filestore — Lifecycle.
- Docker — Reaping.
- Runbook §14:
wrong_hostandcontent_reset. - Upgrading & Migration: the workspace stack's compatibility matrix, rollback and blue/green deploys.
- The session-scoped workspaces design (phase 1 is the cut in its §13):
docs/superpowers/specs/2026-11-14-session-scoped-workspaces-design.md.