Skip to content

TypeScript streams and sessions retain contributor protection - #849

Merged
zlareb1 merged 2 commits into
mainfrom
feat/typescript-session-protection
Nov 18, 2026
Merged

zlareb1 merged 2 commits into
mainfrom
feat/typescript-session-protection

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Related: #840

Changelog category (leave one):

  • Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

TypeScript streams and Session buffers retain protection for every contributing conversation. Automatic transcript and extraction work stop after protection while explicit actions remain available.

Why

A streaming caller can read through a reader, a body method or a clone. Each route must wait for durable protection before receiving a marked frame. Guarding the native response body gives those routes the same boundary without buffering the complete answer.

Scope and risk

Bound successful SSE responses use a native guarded Response. It retains status, headers and response metadata through ordinary clones. Complete frames preserve their original bytes; marked frames wait for every retained handle's durable acknowledgement. Framing supports CR, LF, split CRLF, multiline data, comments, an initial BOM and split UTF-8. An unfinished frame is limited to 4 MiB. Invalid frames, partial EOF, unsupported media types and compression refuse and protect the retained handles.

Cancellation and read failures protect the contributors and join bounded owned cleanup before returning failure. Original source read errors retain their identity. Unbound raw responses retain their original identity and behavior. Native clone queues follow platform tee behavior; the frame limit does not bound caller-created clone queues. BYOB readers remain unsupported and refuse.

The typed assistant parses the same newline forms and multiline data, preserves constant protection failures, and accepts an optional SessionCapture alongside its question for automatic invocations. It requires the completion marker before returning an answer and continues draining after that marker so later protection metadata is observed.

Session snapshots its constructor capture and retains every bound handle it later uses. Automatic recall, transcript and extraction requests carry those contributors through credential waits and dispatch. A first marked recall can return; optional history is omitted after protection. Pending and carry-over text are discarded on protection instead of retried. A synchronous buffer read clears known local taint; asynchronous owner boundaries also check durable state. A clean failed extraction preserves old-before-new retry order only after another bounded state check. Zero carry-over sends no prior batch.

Explicit offload, fetch and note use observation-only controls. They remain available after protection and mark all retained families on marked or malformed replies, including after client rebinding. The same observation-only control is available on ordinary calls and raw streams.

Framework callbacks, durable storage backends, restored host lineage and fleet qualification remain separate work. This change sends no capability declaration and does not enable mirrored-source creation.

Compatibility, rollout and rollback

  • Wire: no operation, body, header or server default changes. The assistant and Session accept optional capture controls; call options add observation-only observe. All are SDK controls outside wire arguments. The existing configured transport timeout is readable and bounds Session state checks.
  • Storage: no schema or durable-format change. Applications retain the existing application-owned authority and shared same-process handle contract.
  • Operator steps: none. Use a default reader or standard body method for a protected stream; compressed streams and BYOB readers remain unqualified.
  • Rollback: no migration. Retain existing durable protection records; rolling back cannot qualify an older consumer to declare support.

Tests

  • vitest run --pool=forks --maxWorkers=1 --no-file-parallelism src/protected-stream.test.ts src/protected-stream-lifetime.test.ts src/protected-stream-protocol.test.ts src/assistant-protection.test.ts src/assistant.test.ts: 59 pass in the focused local check. These cover durable-before-first-byte across readers/body methods/clones, framing and bounds, metadata, cancellation, abort, source failures, pending storage, contributor forwarding and existing assistant completion/timeout behavior.
  • vitest run --pool=forks --maxWorkers=1 --no-file-parallelism src/session-capture-protection.test.ts src/session.test.ts: 22 pass, including contributor retention, buffer cleanup, explicit actions, optional-history authentication, pending stores, primary backend errors, concurrent clean retries and ordinary Session behavior.
  • A further observation-only raw-stream check passes with an already protected retained contributor and a clean bound contributor. It remains explicit and protects both before returning marked bytes.
  • Causal checks reproduce unsupported bound streaming, loose MIME matching, early failure before cancellation cleanup, lost source TypeError, multiline assistant parsing, changed protection exceptions, missing contributor forwarding, automatic Session leaks and zero-carryover resends before their source fixes.
  • Changed-file Biome, scoped strict TypeScript, SDK documentation formatting and prose checks pass. The sender inventory retains all literal Session producers, adds context.pack and audits its generic forwarding site; unrelated classifications and source pins remain intact.
  • The gateway bearer-token fixture uses its own clock binding, leaving the model-call policy clock unchanged. Its existing rotation and 401 cases run at two clock epochs, with explicit customer attribution on the 401 case. The attributed large-epoch case reproduces the shared-clock failure before the fix; all 16 module cases pass after it, with every original bearer and retry assertion retained.
  • Full SDK/package, unit, integration and applicable platform suites run in CI and must pass on the final head before merge. No broad local suite ran. Injected stores do not qualify a concrete backend or native platform authority.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated: Codex wrote the change; fresh independent whole-diff review and final-head CI are required before merge.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Full final-head CI passes.
  • Fresh whole-diff review has no findings or nits.
  • SDK documentation describes the implemented boundaries and unsupported readers.
  • No generated operation, migration, plugin or frontend changes.
  • Public text follows repository copy rules.
  • Commits are signed off.

Observe the native response body before releasing marked frames and keep every contributing handle across buffered automatic work. Explicit actions retain observation without becoming automatic capture.

Signed-off-by: zlareb1 <[email protected]>
A shared monotonic patch could expire a freshly loaded model-call policy before the bearer test reached its first request. Exercise the same attributed token rotation at two clock epochs without changing the policy clock.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 8cba514 into main Nov 18, 2026
42 checks passed
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