Skip to content

feat(context): audit delivery receipts - #2792

Merged
Sinity merged 5 commits into
masterfrom
feature/fanout/hermes-recall-leg
Jul 12, 2026
Merged

Sinity merged 5 commits into
masterfrom
feature/fanout/hermes-recall-leg

Conversation

@Sinity

@Sinity Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

Expose existing immutable context-delivery receipts through a recipient-scoped API lookup and a read-role MCP audit tool.

Problem

The user-tier receipt writer already persists the exact context image, hash, evidence references, omissions, caveats, recipient, and delivery boundary. There was no supported API/MCP path to recover that evidence after delivery.

Solution

  • Add Polylogue.get_context_delivery(snapshot_ref, recipient_ref=...), which returns a receipt only when its persisted recipient matches.
  • Add read-role MCP get_context_delivery, returning the exact stored image and SHA-256 through a typed payload; mismatch and absence both return not-found.
  • Register the tool in MCP discovery and the single-object envelope contract in a separate test commit.
  • Reuse the durable receipt writer and image model unchanged. No scheduler, automatic recall, manifest format, or write endpoint is introduced.

Acceptance criteria

Bead Status Evidence
polylogue-fs1.11: persisted delivery manifest is auditable satisfied API/MCP resolve the stored image, digest, evidence refs, omissions, and caveats.
polylogue-fs1.11: recipient isolation partially satisfied The API verifies the recorded recipient and MCP makes mismatch indistinguishable from absence. Scheduler-level owner/session capability enforcement remains deferred.
polylogue-fs1.11: explicit/automatic recall, budgets, injection fencing, unavailable delivery outcomes deferred Owned by the open polylogue-37t.11 scheduler and later Hermes delivery integration.
polylogue-fs1.12 deferred Requires the remaining fs1.11 scheduler leg and forensic demo consumer.

Anti-vacuity

  • test_get_context_delivery_scopes_exact_receipt_to_recipient writes a real durable receipt, then exercises the facade against user.db. Removing the user-tier reader or recipient equality check makes it fail.
  • test_get_context_delivery_reads_recipient_scoped_facade_receipt invokes the real MCP tool and asserts the exact image/hash plus facade call. Removing the tool, facade call, or payload mapper makes it fail.
  • MCP registry tests pin discovery and the single-object contract for the registered read tool.

Verification

  • nix develop --command devtools test tests/unit/api/test_facade_contracts.py tests/unit/mcp/test_server_surfaces.py -k context_delivery — 3 passed, 337 deselected.
  • nix develop --command devtools test tests/unit/mcp/test_server_surfaces.py tests/unit/mcp/test_envelope_contracts.py -k 'server_surface_contract or RegistryWideClassification' — 7 passed, 103 deselected.
  • nix develop --command devtools verify --quick — passed all 15 checks.

The broad MCP discovery test run was interrupted by its supervisor after the envelope suite and produced no result summary; it is not claimed as passing.

Ref polylogue-fs1.11
Ref polylogue-fs1.12

Sinity and others added 2 commits July 12, 2026 23:12
Problem: exact context-delivery receipts were durable but unavailable to the
API and read-role MCP audit surfaces.

What changed: add a recipient-scoped API lookup and a read-only MCP tool that
returns the immutable context image, digest, evidence, omissions, and caveats.
The receipt remains stored by the existing user-tier writer; no new manifest or
scheduler is introduced.

Compatibility: adds one API method and one read-role MCP tool.

Ref polylogue-fs1.11.

Co-Authored-By: Claude <[email protected]>
Add the read-role MCP discovery pin, minimal invocation arguments, and
single-object envelope contract for recipient-scoped context-delivery receipts.

Ref polylogue-fs1.11.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1b032211-7867-4b68-8242-7d80a4627393

📥 Commits

Reviewing files that changed from the base of the PR and between 901825e and caa02bc.

📒 Files selected for processing (8)
  • polylogue/api/archive.py
  • polylogue/mcp/payloads.py
  • polylogue/mcp/server_context_tools.py
  • tests/infra/mcp.py
  • tests/unit/api/test_facade_contracts.py
  • tests/unit/mcp/test_envelope_contracts.py
  • tests/unit/mcp/test_server_surfaces.py
  • tests/unit/mcp/test_tool_discovery.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fanout/hermes-recall-leg

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

CI triage: this PR has the same external GitHub Actions failure signature as #2789. CI run 29209327787 completed its non-skipped jobs in 2–4 seconds with empty steps arrays, before any repository command could execute. The CodeRabbit response is rate-limit-only and has no code findings. Local gates remain green: receipt API/MCP tests (3 passed), MCP registry/surface contracts (7 passed), and devtools verify --quick (all 15 checks). No code change made for this infrastructure failure.

Problem: the newly exposed delivery-receipt facade returned Any and the\nMCP boundary lacked a regression test for absent or recipient-mismatched\nreceipts.\n\nWhat changed: expose the durable receipt envelope in the facade contract,\ncompute the fixture digest from the rendered context image, and assert the\nMCP tool returns a uniform not_found response when no authorized receipt is\navailable.\n\nRef polylogue-fs1.11
@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial self-review iteration 1

Findings fixed:

  • The async facade exposed the durable receipt as Any; it now returns the concrete ArchiveContextDeliveryEnvelope | None.
  • The MCP tool had no direct regression for the absence/recipient-mismatch result. It now proves the route returns the same structured not_found response and does not disclose receipt content.
  • The success fixture now derives its digest from the actual context image rather than using a hand-written hash.

What survived scrutiny:

  • This remains a read-only audit seam over an existing user-tier receipt; it does not create context packs, schedule recall, or add a 37t.11 scheduler.
  • Recipient equality is deliberately an opacity fence at this layer. Binding an authenticated caller identity/capability is scheduler/auth substrate work and remains deferred to polylogue-37t.11; the PR body already marks that AC partial rather than claiming full isolation.
  • polylogue-fs1.12 remains deferred.

Verification:

  • nix develop --command devtools test tests/unit/api/test_facade_contracts.py tests/unit/mcp/test_server_surfaces.py -k 'context_delivery' — 4 passed.
  • nix develop --command devtools verify --quick — green locally; the push hook reran the same quick baseline successfully before updating 851517415.

Ref polylogue-fs1.11
Ref polylogue-fs1.12

Problem: the receipt facade named its envelope only under TYPE_CHECKING,\nso runtime consumers using typing.get_type_hints received NameError.\n\nWhat changed: import the public receipt envelope at module scope and pin that\nget_type_hints resolves the exact optional envelope return contract.\n\nRef polylogue-fs1.11
@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial self-review iteration 2

Finding fixed:

  • The concrete receipt return annotation was not runtime-resolvable: typing.get_type_hints(Polylogue.get_context_delivery) raised NameError because ArchiveContextDeliveryEnvelope existed only under TYPE_CHECKING. The envelope is now available at module scope and a facade contract test pins the resolved ArchiveContextDeliveryEnvelope | None return type.

What survived scrutiny:

  • The direct user-tier reader remains read-only (mode=ro) and returns no receipt when the snapshot is absent, malformed, or recorded for another recipient.
  • The MCP route is registered only with the read-context tools and returns a typed single-record payload; it neither imports scheduler machinery nor writes a manifest.
  • Authenticated caller/capability binding is not present in this repository surface. It remains deliberately deferred to polylogue-37t.11, so the PR’s isolation claim stays partial rather than overstated.

Verification:

  • nix develop --command devtools test tests/unit/api/test_facade_contracts.py tests/unit/mcp/test_server_surfaces.py -k 'context_delivery' — 5 passed.
  • nix develop --command devtools verify --quick — local quick checks green through format, lint, mypy, and render; the verified pre-push baseline then accepted 0273183c7.

Ref polylogue-fs1.11
Ref polylogue-fs1.12

Problem: runtime introspection of the delivery payload mapper could not\nresolve its envelope annotation because it was imported only for static\ntype checking.\n\nWhat changed: expose the envelope at module scope and pin resolved mapper\ninput and output type hints.\n\nRef polylogue-fs1.11
@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial self-review iteration 3

Finding fixed:

  • MCPContextDeliveryPayload.from_envelope had the same runtime annotation defect as the facade: its envelope parameter was imported only under TYPE_CHECKING. The mapper now resolves both its envelope input and typed payload output through typing.get_type_hints.

What survived scrutiny:

  • The exact receipt payload faithfully preserves the stored rendered context image, its SHA-256, references, omissions, caveats, delivery actor, and delivery timestamp.
  • The recipient-mismatch path remains opaque (not_found) and has a route-level test; the real SQLite facade test covers the underlying recipient equality check.
  • No fs1.3 explain-import path, scheduler, automatic recall, write operation, daemon, or fs1.12 demo was added.

Verification:

  • nix develop --command devtools test tests/unit/mcp/test_server_surfaces.py tests/unit/api/test_facade_contracts.py -k 'context_delivery' — 6 passed.
  • Pre-push quick baseline completed before the remote branch advanced to caa02bc31.

Ref polylogue-fs1.11
Ref polylogue-fs1.12

@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial self-review iteration 4 — zero new findings

I refreshed from origin, reviewed the full origin/master...HEAD diff (clean under git diff --check), reread the current AC and notes for polylogue-fs1.3, polylogue-fs1.11, and polylogue-fs1.12, and checked the PR body, top-level comments, inline review API, and status rollup. There are no substantive review findings. CodeRabbit remains rate-limited; every GitHub Actions job has the known empty-step 2–4 second init/billing failure pattern.

Final acceptance matrix:

Bead / criterion Status Evidence or remaining owner
polylogue-fs1.3 coverage/fidelity declaration satisfied outside this PR Delivered by #2789 per coordinator scope update; this receipt-audit PR intentionally does not touch explain-import or Hermes parsing.
polylogue-fs1.11: persisted delivery receipt can be audited satisfied for the granted minimal leg Read-only facade and read-role MCP return the existing immutable image, SHA-256, refs, omissions, caveats, boundary, actor, and timestamp.
polylogue-fs1.11: recipient isolation partially satisfied Stored recipient equality plus uniform not_found opacity are implemented and tested. Authenticated caller/owner/session capability enforcement is deferred to polylogue-37t.11.
polylogue-fs1.11: explicit recall, automatic recall, budgets, injection fencing, unavailable outcome, Hermes proof deferred to polylogue-37t.11 No scheduler, delivery actuation, or Hermes runtime flow exists in this PR.
polylogue-fs1.12 evidence-and-continuity demo deferred to polylogue-fs1.12 after polylogue-37t.11 The demo needs the missing scheduler/delivery flow and its packaged consumer proof.

Anti-vacuity evidence:

  • The facade test writes a real user-tier receipt and fails if the durable reader or recipient check is removed.
  • MCP tests invoke the registered tool, preserve the exact image/digest, enforce opaque absence, and fail if the tool/facade/payload route changes.
  • Runtime type-hint tests fail if either new concrete envelope annotation is hidden under TYPE_CHECKING again.

Final focused verification: nix develop --command devtools test tests/unit/mcp/test_server_surfaces.py tests/unit/api/test_facade_contracts.py -k 'context_delivery' — 6 passed.

Ref polylogue-fs1.11
Ref polylogue-fs1.12

@Sinity
Sinity merged commit 73959d4 into master Jul 12, 2026
3 of 14 checks passed
@Sinity
Sinity deleted the feature/fanout/hermes-recall-leg branch July 12, 2026 23:08
Sinity added a commit that referenced this pull request Jul 12, 2026
…789,2792,2797

d3xj, w8et, w379 (cost-honesty, PR #2776), fs1.3 (hermes-wedge, PR #2789), and
f2qv.5 (usage-convergence, PR #2797) fully satisfied — closed. cuxz
(temporal-provenance, PR #2786), th0 (test-harness, PR #2777), and fs1.11/
fs1.12 (hermes-wedge cluster, PR #2792) partially satisfied — noted with
disposition, left open per closure-discipline (no closing on partial ACs).

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Jul 14, 2026
… receipts

Problem: fs1.11 shipped a minimal read-only Hermes recall leg (#2792:
get_context_delivery API/MCP lookup over the existing context_deliveries
ledger) but deferred auth/scheduler to polylogue-37t.11 (open, out of this
cluster). The 2026-07-10 Nous follow-up refinement separately asked to
"persist the context token budget and rendered-token estimate alongside
the exact rendered-byte hash" and "correlate each delivery with the Hermes
snapshot revision and the durable context-delivered event from fs1.7/fs1.2"
-- fs1.7's spool (this branch, prior commits) is what that correlation
needed and did not exist before now.

Finding: token budget and rendered-token estimate were already persisted
(context.compiler.context_snapshot_record_from_image writes
metadata["max_tokens"]/metadata["token_estimate"]) -- no new write needed
there, only exposure. The event-correlation half was genuinely missing.

Solution: context/hermes_delivery_correlation.py is a read-side join, not a
new write path or schema (consistent with fs1.11's own design directive to
extend the existing ledger rather than create another manifest): a Hermes
producer that injects a compiled context pack emits a context_injected
lifecycle event (fs1.7's spool) whose payload carries the snapshot_ref it
received; this module resolves that id against the existing
context_deliveries receipt across the two durable tiers (source.db spool +
user.db ledger). An event with no resolvable receipt renders an explicit
available=False row with a caveat -- archive outage or a not-yet-committed
write is visible, never silently skipped (fs1.11 AC).

Wired onto the public facade as Polylogue.correlate_hermes_context_deliveries
(added to BESPOKE_METHODS + a dedicated contract test, per the existing
"every public async method is categorized" completeness gate). No new MCP
tool: extending the MCP tool surface has ripple costs (EXPECTED_TOOL_NAMES,
tool contracts, generated docs, and role-allowlist config that lives in the
sinnix repo, not here) disproportionate to this pass; the API method is
fully queryable/testable without it, and adding the MCP tool is a small,
clean, separately-reviewable follow-up.

Verification: devtools test tests/unit/context/test_hermes_delivery_correlation.py
tests/unit/api/test_facade_contracts.py -k "hermes or context_delivery" --
9 passed, including the exact-bytes-hash/token-budget/rendered-estimate
correlation happy path, a missing-receipt caveat, and a malformed
(no snapshot_ref) event caveat.

Ref polylogue-fs1.11.

Co-Authored-By: Claude <[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