Skip to content

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 initialRef dependency is now initialBinding.

What to do ​

  • You use the SDK's stores and runtimes: upgrade them together with core. No migration: the binding reuses the existing workspace_ref column.
  • @helix-agents/runtime-js 40.0.0 (major): JSAgentExecutor's construction-time store guard now requires updateWorkspaceBinding (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 DefaultWorkspaceRegistry yourself: pass initialBinding (the session's SessionState.workspaceBinding) instead of initialRef, and optionally endBinding (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 as workspaceRef);
    • { 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.workspaceBinding carries it into a run.
  • Only the op writes the column. Full-state writes (saveState, the step and suspension commits, the terminal commitState) keep the stored binding, whatever workspaceRef the 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 an ended tombstone it did not see (it logs and leaves the tombstone);
    • a child's or a companion consult's end writes ended / child_ended before its terminal commit;
    • destroyWorkspace, resetWorkspace and agent-server's expiredSessionCleanup write ended with destroyed, reset or expired. They are refused while a run is live.
  • The column holds only a binding. readStoredWorkspaceBinding is its one reader. A value that is not a binding reads as none, logged at error (state_corrupt_row, ids only). readStoredWorkspaceRef and workspaceRefColumn are removed; use readStoredWorkspaceBinding / workspaceBindingColumn and boundWorkspaceRef.

  • The registry reads the binding. An ended tombstone opens a fresh workspace. A bound one is resolved, then verified: Workspace.verify?() (new, optional) runs after every resolve, and on a run's first get() of a workspace an earlier run left open.

  • A lost workspace (a resolve that throws WorkspaceEvictedError, or a failed verify) follows WorkspaceConfig.onUnavailable:

    • 'fail' (default): the workspace is unavailable; workspace tools fail with WorkspaceUnavailableError until the app calls resetWorkspace(sessionId). Nothing is opened.
    • 'reset': the run destroys the lost workspace (best effort), ends the binding reset, opens a fresh one, and fires onWorkspaceReset.

    WorkspaceUnavailableReason gains wrong_host and content_reset (a verify failure). Update exhaustive switches.

  • Hooks: onWorkspaceReset is new (WorkspaceResetPayload). Langfuse records it as a workspace:reset span.

Custom state stores ​

Implement updateWorkspaceBinding(sessionId, change, opts?) as one atomic step that touches only the workspace_ref column (or your store's equivalent):

  1. A missing session throws state_session_not_found (core sessionNotFoundError).

  2. 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 RunSupersededError with nothing written. Core's assertRunIsCurrentLive / assertRunIsCurrentIdle implement both checks.

  3. Read the stored column with readStoredWorkspaceBinding, and decide with core applyWorkspaceBindingChange(stored, change). It validates change.next (a malformed binding throws a non-retryable validation_error, nothing written) and compares the stored binding with change.expect.

  4. When it answers write: true, write workspaceBindingColumn(next) to the column. Move no version, write no checkpoint, bump nothing else. Return its result: { written: true, binding }, or, on a mismatch, { written: false, actual } with nothing written.

  5. If your store bounds state size (maxStateBytes), measure the column you write and refuse an oversized one with StateSizeExceededError (operation state), nothing written.

  6. If your compare-and-set can lose a race (a read followed by a conditional write), retry it WORKSPACE_BINDING_ATTEMPTS times, then throw core workspaceBindingContendedError(sessionId) (a retryable state_concurrency_conflict).

  7. loadState fills both workspaceBinding and workspaceRef (the bound binding's ref) from the column.

  8. Every full-state write keeps the column: saveState, saveStateAndPromoteStaging, commitState and any other write of a whole SessionState must not write it, whatever workspaceRef / workspaceBinding the 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.

Released under the MIT License.