Skip to content

Assistant answers bind mirror admission and private accounting - #835

Merged
zlareb1 merged 5 commits into
mainfrom
fix/assistant-mirror-response-boundary
Nov 18, 2026
Merged

zlareb1 merged 5 commits into
mainfrom
fix/assistant-mirror-response-boundary

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Related: #825

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

Assistant answers flag mirrored source access before output and fix mirror admission for the answer's lifetime. Streaming SDKs reject incomplete answers.

Why

A delegated tool call's privacy state does not return to the outer model answer. The bridge classifies the authorized namespace's active mirrored registrations before checking spend, marks the complete answer, and fixes a separate signed answer_mirrors restriction on its token. An initially ordinary answer cannot acquire a mirror leg when a source becomes active later. The caller's session_protection promise retains its separate meaning; ordinary delegated children omit both claims.

Normal operation models do not carry the request's privacy mark. The transports attach it after serialization and preserve it through MCP structured and text results; a marked search summary follows a first JSON marker block.

Using the capability promise alone permits late activation. An answer registry would add shared state without replacing per-document authorization. The signed restriction keeps ordinary namespace reads and current ACL checks intact.

Final usage exists after incremental text. A marked response therefore owns its accounting lifetime beyond HTTP headers, joins producer cleanup despite repeated cancellation, and confirms its required private cost row before terminal completion. Partial text remains provisional. Whole responses and checked source frames keep their accounting-before-publication boundary.

Scope and risk

The change covers assistant admission, first-output flags, required stream accounting, shared HTTP/MCP success and error flags, generated output types, and SDK completion detection. The regressions exercise late activation, strict claims and descendant restrictions, first SSE/whole flags, failed private delivery, repeated cancellation, protocol unwrapping and incomplete EOF. The native signed-read fixture adds an anyone-readable mirror and ordinary-document control for CI. Its inactive-source branch compares complete responses, including download bytes and headers, with unmarked baselines captured before registration. Active-source baselines retain the flag even when ACL checks exclude every private row.

Durable SDK stream observation, automatic-capture qualification and fleet readiness remain separate work. Mirrored-source creation stays disabled.

Compatibility, rollout and rollback

  • Wire: assistant.ask adds optional mirrored: bool, default false. Marked chat responses begin with mirrored: true; marked SSE begins with data: {"mirrored":true}. Marked error payloads retain the flag after protocol unwrapping. SDKs require [DONE] before returning a completed answer, ignore subsequent text and retain transport-error handling.
  • Tokens: answer_mirrors is a strict server-issued Boolean. Missing admission is false. No caller field, header, mint endpoint or CLI flag sets it.
  • Operator steps: no schema migration or data backfill. Keep mirrored-source creation disabled until every serving build and consumer enforces the privacy protocol. An older verifier accepting the claim does not enforce it.
  • Rollback: reverting restores the earlier protocol behavior; no tables are added. The documented fleet drain, private-data removal and latch requirements still govern rollback after mirror enablement.

Tests

  • 42 selected Python assistant/admission/SDK and package-boundary checks pass; 22 tests in sdk/typescript/src/assistant.test.ts pass with one worker. The assistant reads registration presence through the knowledge app layer; the package contract and its allowlist remain unchanged.
  • The signed-claim follow-up passes 24 cases: python -m pytest -q -n 0 tests/unit/test_assistant_mirror_boundary.py tests/unit/test_session_protection_declaration.py::test_the_bridge_fixes_the_callers_declaration_in_the_answer.
  • The shared success-flag follow-up passes 16 selected cases: HTTP search/get serialization, ordinary controls, MCP direct/search unwrapping, canonical refusals, argument feedback, audit identity and assistant flags.
  • Changed-file Ruff, formatting, mypy and TypeScript formatting checks pass. The changed-file statement/length ratchet uses the existing thresholds and baselines. SDK and reference generators ran; generated diffs were read.
  • All 49 final-head CI checks are terminal: 47 pass and two publication jobs are skipped. The passing gates include all six unit shards, coverage floors, 251 benchmark cases, all native integration parts, the signed mirror-token matrix, both Postgres versions, mixed-version checks, SDKs, browser checks and quickstarts. No broad local suites ran.

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

  • AI-generated: Codex wrote the change; independent source review and exact-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, type, unit and integration gates pass on the final head.
  • Applicable SDK and reference files are regenerated from source; unrelated generated artifacts remain current.
  • No migration or merged migration changes.
  • No plugin behavior or manifest changes.
  • No frontend changes.
  • Architecture docs describe the protocol, stream completion boundary and rollout limits.
  • Added public text follows the repository copy rules.
  • Commits are signed off.

Fix mirror admission before model work so a later source activation cannot widen an ordinary answer. Mark private output first and retain required stream accounting through owned cancellation cleanup; SDKs require terminal completion.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Keep the registration-only admission lookup within the package contract while preserving the conservative privacy boundary.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Attach the server-owned mark after typed output serialization and keep it through structured and text protocol unwrapping.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Active registrations mark responses before ACL filtering. Compare inactive responses with the same content and no flag; keep active and stale-evidence expectations intact.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Capture ordinary responses before registration so inactive-source assertions retain complete JSON, download bytes and header comparisons without removing privacy metadata from expected values.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
@zlareb1
zlareb1 merged commit 9f02cc9 into main Nov 18, 2026
49 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