Skip to content

impl(fleet-hosted): session registry — server-minted session ids, resolution-order parity with #9075 (#12584) - #12838

Merged
dezren39 merged 1 commit into
mainfrom
felix/12584-session-registry
Nov 23, 2026
Merged

dezren39 merged 1 commit into
mainfrom
felix/12584-session-registry

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Refs #12584 (component C of #9081; design doc/2026-11-22T14-28-45Z_design_fleet-tool-workers-edition §4.2). Builds on the #12583 skeleton (PR #12822, pkgs/fleet/hosted-worker). Left unmerged for Felix's review.

What landed

Session registry (src/sessions.ts, src/routes/sessions.ts) — the server-side replacement for #9075's env + worktree pwd-file:

  • Routes over the skeleton's authenticated pipeline: POST /v1/sessions (open), POST /v1/sessions/resume, POST /v1/sessions/resolve (the stamp path's question), POST /v1/sessions/close. All carry door id sessions for service-token scoping.
  • The service mints the id: ses_ + 32 lowercase hex from 16 crypto.getRandomValues bytes (128-bit entropy). The format is the native impl(fleet): session state — session id in env + worktree pwd-file #9075 format (session_state.rs valid_session_id: ses_ + ASCII alphanumerics), so an id means the same thing in both editions. A client-sent session_id/binding_id on open is ignored — the client never chooses its id and never asserts tenancy; the record is keyed by the caller's credential-resolved binding_id only.
  • Record: binding_id, lane, declared model, open/close times (service clock), lane-start issue set — read back verbatim by resolve (acceptance 3).
  • Refusals, all named: unknown id → 404 session_unknown; another tenancy's session → also session_unknown (deliberately indistinguishable, no cross-tenant existence oracle); closed id → 409 session_closed; malformed id → 400 invalid_session_id (format checked before the registry is consulted, as native checks before trusting a source); agent caller declaring a lane other than its credential's → 403 lane_beyond_credential (design §4.1 ceiling; an omitted lane inherits the credential's).
  • Storage seam: SessionRegistry interface + FixtureSessionRegistry (in-memory, the TenancyDirectory idiom). The production home is the impl(fleet): metadata database + fleet Metadata query surface #9074 metadata DB session table behind the same interface; src/worker.ts holds one fixture instance at module scope. No live Cloudflare/Turso anything.

CLI-side resolution (src/session-resolution.ts) — design §3.2's carriage, a step-for-step transcription of the native resolver (pkgs/fleet/crates/fleet/src/session_state.rs): explicit argument > env (FLEET_SESSION_ID, then OPENCODE_SESSION_ID — the native env level, per pkgs/fleet/README) > per-workspace stored state, with the native failure modes preserved (trim/nonempty at every level; malformed nonempty values fail closed rather than falling through; a stored id is used only when live — hosted liveness is the registry's word — and an ended/unverifiable stored id is a named stale_session_state error; supplied identities persist to the stored state for a later bare invocation, and the stored state is not read when a higher level supplies one).

Parity evidence

test/session-parity.test.ts runs one case table against the hosted resolver — 13 cases, each named for the session_state.rs test it transcribes (explicit_argument_wins_over_both_environments_and_pwd_file, fleet_env_precedes_opencode_env_and_pwd_file, opencode_env_precedes_pwd_file, marker_is_used_only_when_live_and_stale_marker_is_explicit ×2, whitespace_values_are_absent ×2, invalid_environment_and_marker_ids_fail_closed ×2, plus the malformed-env-before-stored, malformed-explicit, whitespace-explicit and empty cases) — plus the two native persistence tests (supplied_identity_is_persisted_for_a_later_bare_invocation, explicit_and_environment_values_do_not_read_an_invalid_marker) as full bind/recover flows. #9075's order is recorded in its acceptance, in the pm-board design note §14, and in component-C design §3.2; the native path is executable Rust, so the table is transcribed from its tests rather than run cross-language.

Suite evidence

  • npm test: 56/56 pass — the 28 baseline skeleton tests untouched and green, plus 13 registry/route tests and 15 parity tests (incl. the end-to-end acceptance flow: open via the router → bare recovery of the same id from stored state → close → bare resolution refuses stale).
  • npm run typecheck: clean.
  • npm run smoke: all checks pass, including the new sequence through the real router — open (201, minted ses_…) → resolve (200) → close (200) → resolve refused (409 session_closed).

Deliberate calls

  • The capabilities doors list is unchanged: the registry is a §4.2 service surface, not one of the five §3.1 front doors (auth/tenancy aren't doors either), and the baseline capabilities/health tests pin that list.
  • No Closes keyword: the acceptance's CLI surface is delivered as the resolution library the thin TS CLI consumes (this package ships no CLI binary, as with the skeleton); Felix's merge/done-check decides the close.
  • No new dependencies.

Get evidence
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…olution-order parity with #9075 (#12584)

The hosted session registry (component C design §4.2): the service
mints the session id (ses_ + 128 bits of crypto randomness as hex —
the native #9075 id format), records it against the caller's
credential-resolved binding_id with lane, declared model, open/close
times and the lane-start issue set, and resolves ids on the stamp
path. Open / resume / resolve / close routes over the skeleton's
auth plumbing; unknown ids refuse session_unknown (another
tenancy's session answers identically — no existence oracle),
closed ids session_closed, malformed ids invalid_session_id.

CLI-side resolution (design §3.2) transcribes the native resolver
(pkgs/fleet/crates/fleet/src/session_state.rs) step for step:
explicit argument > FLEET_SESSION_ID > OPENCODE_SESSION_ID >
per-workspace stored state, with its failure modes (malformed
nonempty values fail closed; an ended stored id is a named stale
error; supplied identities persist for a later bare invocation).
test/session-parity.test.ts runs the case table transcribed from
the native resolver's own tests against it.

Storage follows the skeleton's seam idiom: SessionRegistry is an
interface (its production home is the #9074 metadata DB session
table) with a fixture in-memory implementation. No new
dependencies; no deployment.
@dezren39
dezren39 requested a review from a team as a code owner November 23, 2026 03:34
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6d5436a9-2316-4f36-90a8-e370596964aa
Commits

Reviewing files that changed from the base of the PR and between a321f4a and 2f69ec2.

Files selected for processing: 11

  • pkgs/fleet/hosted-worker/README.md
  • pkgs/fleet/hosted-worker/package.json
  • pkgs/fleet/hosted-worker/smoke/smoke.mjs
  • pkgs/fleet/hosted-worker/src/auth.ts
  • pkgs/fleet/hosted-worker/src/router.ts
  • pkgs/fleet/hosted-worker/src/routes/sessions.ts
  • pkgs/fleet/hosted-worker/src/session-resolution.ts
  • pkgs/fleet/hosted-worker/src/sessions.ts
  • pkgs/fleet/hosted-worker/src/worker.ts
  • pkgs/fleet/hosted-worker/test/session-parity.test.ts
  • pkgs/fleet/hosted-worker/test/sessions.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dezren39
dezren39 merged commit 1d6d8f0 into main Nov 23, 2026
2 checks passed
@dezren39
dezren39 deleted the felix/12584-session-registry branch November 23, 2026 03:36
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.

1 participant