Skip to content

Session objects on the explicit recovery protocol - #57

Open
slinkydeveloper wants to merge 8 commits into
mainfrom
session-objects-protocol
Open

slinkydeveloper wants to merge 8 commits into
mainfrom
session-objects-protocol

Conversation

@slinkydeveloper

@slinkydeveloper slinkydeveloper commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Session objects run on the new explicit recovery protocol (version 1), with the shared core's new VM.

  • Session objects on the explicit recovery protocol: discovery manifest v6 (protocolFamily), the addon binding the shared core's explicit recovery VM, heartbeats, ctx.span, ctx.request.attempt, and invalid input as a TerminalError.
  • E2E tests on the real runtime (testcontainers) in place of the fake runtime.
  • The tests run on ghcr.io/restatedev/restate:session-objects-protocol, the image built from the runtime's session-objects-protocol branch. CI runs the vitest e2e tests on that image, and runs the e2e scripts on its restate-server binary.
  • The shared core is pinned to sdk-shared-core's main commit bfa0347 (Session objects protocol sdk-shared-core#125, merged), until it is released.

🤖 Generated with Claude Code

slinkydeveloper and others added 7 commits December 4, 2026 15:43
Session objects now run on the explicit recovery protocol v1, served by
the package itself beside the published SDK: /discover returns manifest
v6 with the family on every session-object handler, and /invoke for
session objects goes to the new VM. Journaled services are unchanged.

- The addon binds the shared core's new VM; only the driver's tick takes
  notifications, the cancel signal arrives on its reserved handle.
- A commit is one atomic group with its sends; the outbox is gone.
- Spans per transaction, calls named and nested under the current span.
- SIGTERM ends live attempts with an unasked shutdown and refuses new
  ones with 503 while draining.
- Wire tests run on the shared core's fake runtime.

The shared core is a local path dependency until it is released.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A malformed invocation id or key passed to cancel, attach, signals,
calls or sends now throws InvalidInput, a TerminalError with code 400,
instead of a retryable error or a protocol violation that retried the
attempt forever. Fire-and-forget actions no longer swallow it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A handler's context runs a span itself (ctx.span), and its request carries
the attempt's number (SessionRequest, attempt from 1), instead of the free
span and a cast of the request. Invocation state, signals and flush stay
free functions in @restatedev/sessions/internal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The interval was a hard-coded 20 seconds, so a handler or object that set an
inactivity timeout under a minute was shut down while it worked in
ctx.working. The interval is now a third of the handler's inactivity timeout,
else its object's, else Restate's default minute.
RESTATE_SESSIONS_HEARTBEAT (milliseconds) still overrides it, for a timeout
set where the SDK cannot see it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* packages/e2e/test runs session objects against a Restate image
  (RESTATE_IMAGE, default localhost/restatedev/restate:session-objects)
  through testcontainers: the protocol, the saga, transactions under
  cancel, discovery, 415 and request signing. Skipped without Docker or
  the image; the unit tests stay Docker-free.
* The addon's binding of the shared core's fake runtime (FakeRuntime,
  feature fake_runtime), the tests built on it, and e2e/identity.ts
  (now in endpoint.test.ts) are removed.
* The example's idle handler: restarted at every inactivity timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A handler's db.transaction was wrapped in a span named `transaction`, so
every transaction sent a span start and a span end beside its commit. It
opens none now: its commit is recorded inside the span the handler's code
is in, if any, and at the top level otherwise. Where a transaction should
show as a span, wrap it: ctx.span('save', () => ctx.db.transaction(...)).
* The e2e tests in packages/e2e/test run on
  ghcr.io/restatedev/restate:session-objects-protocol by default, pulled if
  missing: the runtime's "Build Docker image" workflow builds it from its
  session-objects-protocol branch. RESTATE_IMAGE still overrides it.
* CI runs them, and runs the e2e scripts on that image's restate-server
  (RESTATE_SERVER) in place of the 1.8.0 release, which has no explicit
  recovery protocol.
* The READMEs name the image.
* The shared core is the git commit of sdk-shared-core#125 (8.7.4 with the
  explicit recovery VM), not a local path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The protocol migration itself holds up. The workflows were not updated with it, though: the typescript CI job still calls a script this PR deletes, and the nightly jobs still run session objects on servers that can no longer serve them.

Approach: sound. A transaction's sends now ride the commit's atomic group instead of a persisted outbox. That removes the crash-recovery bookkeeping (idempotency keys, re-sends, a second commit) rather than patching around it.

Reviewed changes

All 7 commits, against main:

  • Explicit recovery VM binding. native/src/vm.rs drops journal routing. Only the tick takes notifications now. It also adds the cancel handle, aborted groups, VM_REFUSED/INVALID_INPUT error texts, state scopes, signals, flush, atomic groups and spans.
  • Commit as one atomic group. VmStore::commit builds begin_commit plus the transaction's sends (withCommit stash) in one critical section. A commit that writes nothing sends in a group of its own (commit_alone). The outbox record and its re-send logic are gone from session.ts.
  • Discovery and routing. endpoint.ts serves manifest v6 itself, with protocolFamily: EXPLICIT_RECOVERY and explicitRecoveryProtocol. It refuses request/response mode, verifies signatures on /discover too, answers 415 to other protocols, and drains on SIGTERM (goAway, 503).
  • Driver lifecycle. The response closes only once the runtime has closed its side (whenClosable, 30 s fallback). Spans use AsyncLocalStorage, and a transaction's commit nests in the enclosing span. Invalid input becomes a catchable TerminalError. The heartbeat is a third of the handler's (or object's) inactivityTimeout.
  • New surface. Public ctx.span and ctx.request.attempt; provisional invocationState, readSignal, sendSignal and flush in internal.
  • Tests. The wire-level unit suites are replaced by vitest e2e tests on testcontainers in packages/e2e/test/, which run against the session-objects-protocol image.

I also checked the commit path against the pinned shared core (ec1a03e). It calls KvStore::commit exactly once per flush, and that call writes the head. Checkpoint, fold and GC go through put or sync. The TS layer serializes calls on a connection, so nothing can take the with_commit stash before the transaction's own commit does.

P1 checks.yml still runs the deleted identity script

This PR deletes packages/e2e/identity.ts and its identity script in packages/e2e/package.json, but .github/workflows/checks.yml:74 still runs pnpm --filter e2e identity. The typescript job will fail at that step ("Missing script"), and explicit-recovery and leak after it will never run. The new test/endpoint.test.ts already covers what the script checked.

Technical details
# CI step for a deleted script

## Affected sites
- .github/workflows/checks.yml:73-74 — the comment and the `pnpm --filter e2e identity` step

## Required outcome
- The `typescript` job no longer invokes `identity`. The signature checks are covered by `packages/e2e/test/endpoint.test.ts`, which runs in the `test:e2e` step.

P1 The e2e scripts and nightly jobs still target servers that cannot serve session objects

The README now says session objects need the explicit recovery runtime with RESTATE_EXPERIMENTAL_ENABLE_EXPLICIT_RECOVERY_PROTOCOL=true, and that 1.8 "serves only the journaled services and objects beside them". The scripts and workflows outside the new vitest suite were not updated to match:

  • The scripts (crash.ts, concurrency.ts, explicit-recovery.ts, and the rest) spawn RESTATE_SERVER with ...process.env and never set the experimental flag. checks.yml exports only RESTATE_SERVER, not the flag. Only test/global-setup.ts sets it.
  • When RESTATE_SERVER is unset, the scripts still fall back to the pinned @restatedev/restate-server 1.8.0, both locally and in nightly.yml's soak and platforms jobs. restate-latest installs @restatedev/restate-server@latest. All three exercise session objects.

So unless the branch binary enables the protocol by default, the session-object scripts fail in PR CI. And the nightly jobs that run session objects fail regardless.

Technical details
# Servers and flags for the e2e scripts

## Affected sites
- .github/workflows/checks.yml:48-54 — exports RESTATE_SERVER only; no RESTATE_EXPERIMENTAL_ENABLE_EXPLICIT_RECOVERY_PROTOCOL
- packages/e2e/{crash,concurrency,explicit-recovery,restate-tools,steering,agentlib,bench}.ts — spawn(SERVER, …, { env: { ...process.env, … } }) without the flag
- packages/e2e/restate-server.ts — default is still the 1.8.0 release
- .github/workflows/nightly.yml — `soak` (crash on 1.8.0), `restate-latest` (latest release), `platforms` (concurrency/explicit-recovery/versions on 1.8.0)
- README.md:240 — still says the scripts default to the 1.8.0 release

## Required outcome
- Every script that serves a session object runs against a server with the explicit recovery protocol enabled, in PR CI and in nightly.
- The nightly jobs either use the session-objects-protocol image or binary, or skip the session-object scripts until a release has the protocol.

## Open questions for the human
- Does the `session-objects-protocol` binary enable the protocol without the flag? If it does, PR CI may pass, and only the nightly and local-default paths need the change.

Non-blocking

  • Outbox records left by the previous version are never sent. An attempt that crashed between its commit and emptying outbox left committed sends in that record. Before this PR, the next open made them. Now nothing reads the record (session.ts), so those sends are silently dropped after an upgrade. It needs a crash at exactly that point, but a one-time drain, or at least a release note, would close it.
  • heartbeatMs lost its unit coverage, and the new test points at a deleted file. test/heartbeat.test.ts:3 says the third-of-timeout rule is tested "in driver.test.ts", which this PR deletes. With the wire-level suites gone, the driver's heartbeat, cancellation and close logic is covered only by the container e2e tests, which skip silently without Docker or the image.

Pullfrog  | Fix it ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

…ry VM

sdk-shared-core#125 is merged: bfa0347 on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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