Skip to content

SDK clients retain durable protection for mirrored session content - #840

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

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

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Related: #835

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):

SDK clients can bind application-owned session protection before receiving mirrored responses. Protected automatic work is suppressed while explicit actions remain available.

Why

A privacy flag must protect its contributing conversations before a caller receives content. Changing credentials, creating another client or flushing an older buffer must retain the original authority. The clients therefore observe responses before conversion and retry, and bind automatic work to every contributing protection handle.

Python supplies a content-free, durable POSIX capsule that applications explicitly create for an independent conversation and reopen on restore. The shared Node primitive reads the same format. Neither restore nor an unknown record creates clean state. TypeScript accepts an application-owned durable store through a portable handle; it does not import a filesystem backend or use a mutable global invocation stack.

A transient request flag cannot protect later callbacks, and a token or server address cannot identify the whole conversation. Durable monotonic state and retained producer handles provide that boundary without storing conversation content.

Scope and risk

Python transport observation covers JSON responses and bounded SSE frames before output, including errors and credential replay. Opening automatic and observation handles are retained across callbacks, authentication, body reads and client rebinding. Interrupted or malformed bound streams protect their captured handles before refusal. Its Session buffers and deferred memory batches retain their producer handles and run context; protected text is discarded instead of requeued. Explicit offload, fetch and note actions retain response observation.

TypeScript covers JSON transport observation and explicit immutable SessionCapture invocation control. Every same-process client and concurrent callback for a family must reuse the same handle. A synchronous latch suppresses sibling automatic requests while durable acknowledgement is pending; returning private content still requires every durable mark and readback. The final send checks retain marks recognized during credential or sibling-store waits. Unqualified bound raw streams refuse and cancel; ordinary unbound streams retain their existing behavior.

The Node capsule primitive and its generated Codex copy are available for shared state. Existing plugin hook wiring, capture and host binding behavior are unchanged. Framework callbacks, TypeScript Session buffers and streaming observation, concrete TypeScript storage backends, native Windows authority and host lifecycle qualification remain separate work. This PR sends no session-protection capability declaration and does not enable mirrored-source creation.

Compatibility, rollout and rollback

  • Wire: no operation, server field, header or default changes. Python constructors add optional session_protection; TypeScript transport options add sessionProtection, with automatic invocation control in call options rather than wire arguments. Bound malformed responses use a constant protection exception and withhold their body. Empty bound JSON responses require a bodyless 204 or 304 status.
  • Storage: applications provision and retain the same durable authority across clients, credentials, servers and restarts. Missing, damaged or inaccessible state suppresses automatic work. POSIX capsules have no expiry, reset or repair path. Native Windows requires a separate authority adapter and refuses here.
  • Operator steps: none. Both plugin manifests use the unused version 1.2.32; generated copies are synchronized. Capability declaration and mirror enablement remain subject to the documented consumer and fleet gates.
  • Rollback: no migration or server data change. Retain existing capsule records. Reverting this foundation cannot authorize an older client to declare support for protected sessions.

Tests

  • python -m pytest -q -n 0 tests/unit/test_sdk_stream_protection.py tests/unit/test_sdk_session_protection.py::test_empty_bound_json_requires_a_bodyless_status tests/unit/test_sdk_session_protection.py::test_node_and_python_share_the_same_capsule_format tests/unit/test_sdk_surface_contract.py::test_public_api_matches_the_snapshot: 31 pass on the composed publication source, including the merged assistant completion behavior.
  • vitest run --pool=forks --maxWorkers=1 --no-file-parallelism src/session-protection.test.ts: 14 pass, covering durable-before-return, pending storage, final-send races, abort, malformed bodies, retry and ordinary controls.
  • node --test --test-concurrency=1 integrations/claude-code-plugin/tests/session-protection.test.mjs integrations/claude-code-plugin/tests/recall-key-home.test.mjs: 20 pass on POSIX, retaining private permissions, child processes, restore, aliases, missing or damaged state and isolated test homes. Native Windows runs its fail-closed authority and unchanged-state contract in CI; the platform jobs remain required.
  • The corrected transport and inventory pass 31 selected authority, interrupted JSON, bodyless-response, literal producer and stream compatibility checks. Tests cover authentication, pre-dispatch callbacks and body-read rebinding; both network and cancellation failures retain protection. The sender collector recognizes capture wrappers and preserves their classified literal producers. Only two audited generic delivery entries and the moved history reference entry change.
  • A root-only ESM/CJS build and both exact runtime export checks pass. The full package, declaration and adapter checks remain in CI.
  • Earlier directly related checks cover Python Session carry-over, optional history suppression and deferred coalescer ownership; the retained regression modules run in CI. The stream observer also passed its 23 cases with HTTPX 0.27.0 in an isolated compatibility environment.
  • Changed-file Ruff, formatting, eight-source mypy, TypeScript formatting and scoped type checks pass. Plugin generation and its check pass. The SDK API snapshot retains current methods and adds only three constructor parameters.
  • Final-head CI passes all unit shards, coverage and benchmarks, native and Postgres integration, SDK packages and plugin platforms. The two documentation publication jobs are skipped on pull requests. No broad local suite ran. Injected store tests do not qualify a concrete TypeScript backend, and no native Windows qualification is claimed.

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 CI formatting, lint, types, unit, integration and applicable package gates pass on the final head.
  • The public SDK snapshot is checked; Codex library copies are regenerated and byte-identical.
  • No migration or merged migration changes.
  • Both plugin manifests are bumped to a version unused by other open PRs.
  • No frontend changes.
  • SDK documentation describes the storage contract, implemented boundaries and remaining rollout requirements.
  • Added public text follows repository copy rules.
  • Commits are signed off.

Observe responses before return and replay, retain every automatic producer authority across buffering, and require durable marks before releasing private content. Keep unqualified stream consumers closed and capability declaration disabled.

Signed-off-by: zlareb1 <[email protected]>
Protect interrupted JSON before retry or cancellation escapes, retain the initial automatic and observer families through rebinding, and preserve literal sender provenance across capture wrappers. Exercise native Windows refusal and the exact public SDK exports without weakening platform or classification gates.

Signed-off-by: zlareb1 <[email protected]>
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