Skip to content

Add an opaque-archive store contract for remote session state - #444

Open
Kevin Kitts (kittskevin) wants to merge 2 commits into
waldemort/m1-pr1-compute-abstractionfrom
waldemort/m1-pr2-opaque-archive-store
Open

Kevin Kitts (kittskevin) wants to merge 2 commits into
waldemort/m1-pr1-compute-abstractionfrom
waldemort/m1-pr2-opaque-archive-store

Conversation

@kittskevin

@kittskevin Kevin Kitts (kittskevin) commented Dec 2, 2026 •

Copy link
Copy Markdown

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 02bb72b98eff6fb260923dc808ab92115587c1ed

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ snapshot-opaque-archive.test.js covers both FilesystemSessionStore and SessionBlobStore across conditional store-wins CAS, expectedEtag pinning, SHA-256 verification, the 16 MiB cap, create-only turn records, and mixed-fleet representation guards.
↓ Hosted PR checks on this branch run once the pull request is opened, and live Azure Blob Storage fault-injection is not run in PR CI.

Summary

Adds the opaque-archive store contract to VersionedSnapshotStore (FilesystemSessionStore and SessionBlobStore) so a worker can persist and read a remote sandbox's compressed state archive as opaque bytes without ever unpacking, listing, or interpreting remote files on the worker filesystem.

The archive chain lives under its own object names (<session>.sandbox.bin and <session>.e<N>.sandbox.bin) and carries an explicit opaque marker (psopaque = "1"). A worker running an older release never reads those names, and the local .tar.gz commit and hydrate paths refuse any object with the opaque marker (ARCHIVE_REPRESENTATION_CONFLICT).

Nothing calls these store methods yet; #445 wires statePolicy: "store-owned" to them.

Design record: docs/proposals/remote-compute-targets.md §8.2 in #443.

Stack

  1. Add a provider-neutral remote compute abstraction #443: compute abstraction (base main)
  2. This PR: opaque-archive store contract (base waldemort/m1-pr1-compute-abstraction)
  3. Run store-owned turns on remote compute targets #445: store-owned turns (base waldemort/m1-pr2-opaque-archive-store)

What changes

  • Store contract (snapshot-protocol.ts): adds probeSnapshotArchive, commitSnapshotArchive, readSnapshotArchive, and readTrustedTurnCommit to VersionedSnapshotStore, plus OpaqueArchiveError, object-name parsers, input validation, REMOTE_SNAPSHOT_ARCHIVE_MAX_BYTES (16 MiB), and REMOTE_TURN_COMMIT_MAX_BYTES (64 KiB).
  • Store-wins CAS (session-store.ts, blob-store.ts): commits version baseVersion + 1 only when the head is still at baseVersion and matches expectedEtag (ETag in blob store, content hash in filesystem store). A repeat commit with the same turnKey at baseVersion + 1 resolves idempotently; anything else raises SnapshotConflictError.
  • Integrity and size bounds: every input check runs before storage access; archives are capped at 16 MiB (ARCHIVE_TOO_LARGE), hashed with SHA-256 on write, and re-verified on read (ARCHIVE_CORRUPT). Codecs (gzip or brotli) are declared, never sniffed.
  • Trusted turn records: { turnKey, result } is written create-only before the head object, keyed by a hash of turnKey. The head stamps the record's suffix and SHA-256 (psrec, psrecsha), and readTrustedTurnCommit trusts a record only when stamped by the current head. Large results are bounded by fitTurnCommit (64 KiB cap, dropping events or marking truncated). Superseded records are cleaned up after the head advances.
  • Mixed-fleet guard and deletion: assertLocalArchiveHead refuses local tar hydrate/commit when opaque is set; delete and deleteAllEpochs also remove the opaque chain and its turn records using fail-closed name parsing.

Compatibility

  • Existing sessions: local .tar.gz snapshot commit, hydrate, and deletion behavior is unchanged.
  • No CMS migration and no orchestration version change.

Tests

Adds packages/sdk/test/local/snapshot-opaque-archive.test.js and packages/sdk/test/helpers/fake-container-client.js, testing both FilesystemSessionStore and SessionBlobStore:

  • Sequential version chain, expectedEtag pinning, idempotent turnKey retry, and SnapshotConflictError on stale base or recreated head.
  • 16 MiB cap enforcement on write and read, SHA-256 corruption refusal, and codec validation.
  • Create-only turn-commit records, orphan replacement after a crash between record and head, superseded-record cleanup, and fitTurnCommit truncation over 64 KiB.
  • Mixed-fleet refusal (ARCHIVE_REPRESENTATION_CONFLICT) and epoch deletion cleanup.

Not in this PR

Turn execution for statePolicy: "store-owned" (#445).

Trelawney (repo-manager-v2) and others added 2 commits December 2, 2026 06:57
The stores keep a compute host's compressed archive as opaque bytes under its own object names
(S.sandbox.bin, S.e<N>.sandbox.bin) so a worker without this contract never sees or unpacks it,
and the local tar commit and hydrate refuse an object carrying the opaque marker. Same conditional
store-wins CAS (version chain, idempotent turn key, expectedEtag pinning the exact head), 16 MiB cap,
SHA-256 over the bytes. The turn record is written first, create-only and scoped by the turn key, and
the head stamps its digest; superseded records are cleaned up and deleted with the chain. Large results
are stored as a bounded compact record.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…and deletes, opaque purge

- Turn records are content-addressed (<prefix>.turn-commit.<turn32>.<sha256(record)>.json), create-only
  and never replaced; readers read exactly the name the head stamps. Superseded records are removed by
  exact name; a blob commit that loses (conflict, alreadyCommitted with another record, retries
  exhausted) removes its own record unless the latest head stamps it.
- Filesystem: probe, trusted-record read and the opaque part of delete/deleteAllEpochs run under the CAS
  lock; delete unlinks metas first. A damaged meta (bad JSON, foreign binFile, bad digest or codec) is
  ARCHIVE_CORRUPT; the opaque marker is kept on a versionless tar head.
- Opaque session ids are [A-Za-z0-9_-]{1,128}, epochs undefined or non-negative safe integers, turn keys
  printable ASCII, and base > 0 requires expectedEtag; all refused before any storage access. The name
  parser accepts only canonical names and each store deletes only its own kinds.
- Blob: single-epoch delete removes the head, then sweeps records best-effort; the first-commit-across-
  delete window is documented and left to the purge; readSnapshotArchive destroys the stream on every
  throw; an unknown codec is ARCHIVE_CORRUPT.
- resourcemgr purge and stats recognise opaque heads and turn records via parseOpaqueObjectName.
- The validated turn result is a detached copy; fitTurnCommit never throws; the snapshot contract types
  are exported; the opaque suite is baselineOnly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@waldemort-auto
waldemort-auto Bot force-pushed the waldemort/m1-pr1-compute-abstraction branch from 903ae7b to 5be6099 Compare December 2, 2026 07:21
@waldemort-auto
waldemort-auto Bot force-pushed the waldemort/m1-pr2-opaque-archive-store branch from 02bb72b to 7851de6 Compare December 2, 2026 07:21

This branch has not been deployed

No deployments
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