Upgrade: the session's workspace binding (core major)
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.