Repository navigation
SDK clients retain durable protection for mirrored session content - #840
Merged
Merged
Conversation
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]>
This was referenced Nov 18, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #835
Changelog category (leave one):
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
session_protection; TypeScript transport options addsessionProtection, 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.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.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