Skip to content

fix(excision): forget only unshared blobs; keep sidecar locators unhashed - #5815

Merged
Sinity merged 5 commits into
masterfrom
fix/bgnxh-shared-blob-excision
Sep 29, 2026
Merged

Sinity merged 5 commits into
masterfrom
fix/bgnxh-shared-blob-excision

Conversation

@Sinity

@Sinity Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Summary

Excising a session now forgets that session only. A content-addressed blob that another session still references gets no excised_content marker and stays readable for that session; excising the last session that references it marks it. The sidecar blob_hash locator becomes publication metadata stored beside its event, outside the session object whose identity was bound.

Tracks polylogue-bgnxh (operator decision option (a)).

Problem

  • _preacquire_sidecar_blobs copied each published sidecar's blob_hash into the session's events after the parse worker had bound content_hash, and returned model_copy(...) with the old hash. The stored session's digest then disagreed with its own semantic content, and the prepared-carrier route could publish a different object from the one that was bound (audit F29).
  • Excision marked every blob hash the excised session's rows named. Blobs are content-addressed, so two sessions with the same tool output or the same attachment share one hash: excising A refused B's next revision that carried the same bytes.

Solution

  • _preacquire_sidecar_blobs returns locators keyed by tool_use_id and never rewrites the session. The writer adds them to the stored event row (_stored_event_payload), and pipeline/ids.py excludes the two declared locator keys (blob_hash, blob_refusal) from the event hash, with reasons. The stored row therefore hashes to the identity it was bound under, on the unprepared, writer-prepared and worker-prepared routes.
  • A sidecar whose bytes are already excised is not published again. Its locator records blob_refusal: content_excised, and the rest of the session still writes. A whole session is never refused over one sidecar.
  • inspect_session_blob_references (storage/blob_liveness.py) decides, after the excised session's source rows are deleted and inside the same transaction, whether any other session still references each hash: source owners from BLOB_OWNERS (the generation-local source_attachments census excluded) and index attachments linked to a session outside the excision. Each owner is queried once per chunk of hashes. A hash still referenced goes into the receipt's shared_blob_hashes and is not marked. An undecidable answer (an unknown blob_refs type, a missing owner table, or a replacement index that has not re-materialized and cannot prove absence) raises ExcisionBlobReferenceUnknownError, and the source transaction rolls back. The mutation actuator, its recovery replay and the lifecycle invalidation report that as a blocked or failed outcome.
  • The CLI line names kept shared blobs. docs/security.md and the durable-write census describe the rule.

Verification

  • agentctl job start polylogue pytest_focused -- tests/unit/security/ tests/unit/pipeline/test_sidecar_blob_locator.py tests/unit/pipeline/test_ingest_batch.py tests/unit/storage/test_blob_liveness.py tests/unit/operations/test_mutation_actuators.py: job 2621 at bc5b333: 408 passed, 1 xfailed, 1 failed. The failure is test_mutation_actuators::TestTagAddActuator::test_production_tag_and_metadata_writes_use_user_overlay_policy, which fails identically on master (job 2576)
  • agentctl job start polylogue verify_quick: job 2580 at 6cb4eaebd6 (before the rebase onto 98b9add): verify: PASSED exit=0
  • Earlier on this branch: tests/unit/pipeline/test_hash_vocabulary_totality.py tests/unit/pipeline/test_pipeline_ids.py tests/unit/pipeline/test_content_hash_determinism.py tests/unit/sources/test_claude_code_sidecar_evidence.py passed (job 2440).

Tests on production routes:

  • test_sidecar_blob_locator.py: a genuinely bound session through _write_session, parametrized over unprepared, writer-prepared and worker-prepared. It asserts that the committed event carries the locator, that the parsed event does not, and that the stored representation hashes to the bound identity. A second test covers the excised-sidecar refusal.
  • test_excision_shared_blobs.py: two Claude Code sessions ingested through LiveBatchProcessor share a sidecar blob. After A is excised, B's shared blob is unmarked, retained and readable. A new session C with the same bytes is admitted with its sidecar matched and its stored identity equal to the one re-derived from its retained bytes, and A's re-ingested export is not resurrected. The attachment class runs on _write_session and write_source_raw_session: B's reference lives only in index.attachments, and B's next revision is admitted while A's own attachment is refused.

Derived identity

pipeline/ids.py, archive_tiers/write.py, archive_tiers/source_write.py, storage/blob_liveness.py and ingest_batch/_models.py are in the derived-identity closure (devtools schema closure). This must land before the fresh rebuild starts.

Self-review

  • Sibling sites. Every excision entry point that can raise the new refusal maps it to a typed outcome: SessionExcisionActuator.apply, its crash-recovery replay, and apply_primary_invalidation_if_confirmed. The locator is written in one place, _write_session_events, and it rejects undeclared keys, so no key reaches a stored row without the hash partition excluding it.
  • Interruption. Marking runs inside the same source transaction as the row deletes. A refusal rolls back both, and a retry re-reads the references. The retry check treats hashes in both removed_blob_hashes and shared_blob_hashes as already handled.
  • Scale. Reference checks are chunked per owner (500 hashes per IN), never one query per hash per owner.
  • Fail-open. A query that errors propagates and rolls back. A blocked answer refuses and never guesses in either direction. A replacement index only blocks a hash that no source owner claims.
  • Compatibility. The old in-session locator write is removed, with no dual path.

Residuals

  • Excision still does not reach a session's own tool-result sidecar raws (polylogue-8j9rh). test_excising_a_forgets_the_tool_output_only_it_had is a strict xfail that flips when that lands.
  • An excised sidecar's text, which the parser copied into its tool_result block, is still written to blocks.text and FTS when a new session meets excised bytes. This is the existing master behaviour. This PR only stops the blob from being republished.
  • polylogue-8cra7 records a spurious-sidecar-debt observation on a grown Claude Code transcript, found while writing these tests. It is not yet isolated from excision.

🤖 Generated with Claude Code

https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg

Sinity and others added 5 commits September 29, 2026 10:24
Excision marks a blob hash excised only when no session outside it still
references the blob. The sidecar blob locator is publication metadata:
the writer stores it beside the event, outside the bound session object,
and the hash partition excludes it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
…ion routes

Refuse to mark a hash only the index could vouch for while the index is a
replacement that has not re-materialized, name kept shared blobs on the
CLI line, and give the revision and fact-evidence excision tests the
archive format marker the apply now requires.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
Query each blob owner once per chunk of the excised session's hashes, so
an owner without a blob_hash index is scanned once rather than once per
hash, and cover the attachment class with an index-only reference.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
Excision does not reach a session's tool-result sidecar raws
(polylogue-8j9rh); the live-route test now guards B's shared sidecar and
a strict xfail flips when the reach lands. Blob reference queries
propagate SQLite errors instead of degrading to a blocked answer.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
The mutation actuator, its crash-recovery replay and the lifecycle
invalidation report ExcisionBlobReferenceUnknownError as a blocked or
failed outcome instead of an exception. The shared-sidecar test proves
a new session with the shared bytes is admitted after the excision, and
the lifecycle test runs on an initialized archive root.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Sinity
Sinity enabled auto-merge (squash) September 29, 2026 09:14
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-09-29T09:23:43.292476Z bc5b333 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Sinity
Sinity merged commit 41f81ca into master Sep 29, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the fix/bgnxh-shared-blob-excision branch September 29, 2026 09:24
Sinity added a commit that referenced this pull request Sep 29, 2026
…5696)

## Summary
No publication route can put excised bytes back on disk. The reservation
reads the excision ledger in its own write transaction; an excised hash
gets no reservation, and its staged file is discarded (polylogue-u6jyu).

## Problem
Excision is enforced where rows are written (raw sessions, blob refs,
attachment convergence), but a publisher could still reserve and expose
excised bytes first. The parse-time Antigravity `.pb` snapshot
(`_antigravity_raw_snapshot`) published the blob before any check, so
excised content reappeared on disk with a GC-immune reservation until
the reservation was abandoned.

## Solution
- `BlobPublicationReservationStore.reserve_many` reads `excised_content`
for the batch inside its `BEGIN IMMEDIATE`, reserves only non-excised
receipts, and returns the refused hashes.
- `ArchiveBlobPublisher.flush` discards staged files for refused hashes,
drops their receipt ids, and publishes the rest. Every publisher caller
inherits the refusal. The row-level refusals downstream stay as they
are.

## Verification
Head 0ccc5de (master 64a9bd0 merged).
- `agentctl job start --workspace <wt> polylogue verify_quick` (job
2885, on 30a2c8d, the last source change): `succeeded`.
- `agentctl job start --workspace <wt> polylogue pytest_focused --
tests/unit/storage/test_blob_publication_excision.py
tests/unit/daemon/test_antigravity_conversation_acquisition.py
tests/unit/daemon/test_attachment_convergence_excision.py
tests/unit/daemon/test_operation_protocol.py
tests/unit/pipeline/test_ingest_batch.py
tests/unit/pipeline/test_sidecar_blob_locator.py
tests/unit/pipeline/test_blob_publication_crash_matrix.py
tests/unit/pipeline/test_acquisition_excision_policy.py
tests/unit/security/test_excision.py
tests/unit/security/test_excision_shared_blobs.py
tests/unit/security/test_excision_carrier_reach.py
tests/unit/security/test_excision_revision_reach.py
tests/unit/sources/test_live_batch_support.py
tests/unit/storage/test_revision_replay.py
tests/unit/storage/test_revision_application.py
tests/unit/storage/test_ingest_governance.py
tests/unit/sources/test_location_binding.py
tests/integration/test_daemon_ingest_idempotency.py
tests/integration/test_daemon_ingest_redrive.py
tests/unit/operations/test_ingest_acceptance.py
tests/unit/operations/test_ingest_await_result_contract.py
tests/unit/operations/test_daemon_ingest_convergence.py
tests/unit/operations/test_declared_operation_handlers.py
tests/unit/daemon/test_daemon_operation_route.py
tests/unit/cli/test_import.py` (job 2919, head 0ccc5de): `passed 611,
xfailed 1, failed 3, flaky 1`.
- All three failures are inherited. They fail the same way on a clean
detached master 64a9bd0 (job 2802, `--on-default-branch`: `3
failed`):
`test_revision_replay.py::test_chain_replay_supersedes_equal_frontier_quarantined_membership_head`,
`test_ingest_governance.py::test_membership_that_becomes_eligible_after_preparation_defers_publication`
and
`test_antigravity_conversation_acquisition.py::test_common_live_batch_retries_a_failed_vendor_conversion`
(polylogue-rb7tx).
- The flaky test is
`test_operation_protocol.py::test_cli_import_daemon_ingest_and_from_empty_build_write_identical_material`.
Under xdist load its client await timed out (`QueryTimeoutError`); it
passed when rerun alone, and it passed in job 2888 on the same source.
This PR's changes affect only the refusal and failure paths, and that
test does not take either.
- The renamed
`test_reimporting_an_excised_file_is_a_typed_permanent_refusal` passes
(job 2919).
- Derived-identity closure (`devtools schema closure <file>`): IN are
`pipeline/services/ingest_batch/_models.py`, `sources/decoder_zip.py`,
`sources/live/batch.py`, `sources/source_parsing.py`,
`storage/blob_publication.py`, `storage/sqlite/archive_tiers/archive.py`
and `storage/sqlite/archive_tiers/revision_governance.py`. So merging
this PR moves the index/ops schema identity. It has to land before a
rebuild starts, not during one. Out:
`operations/attachment_convergence.py`, `operations/daemon_ingest.py`,
`pipeline/services/ingest_batch/_core.py`,
`pipeline/services/ingest_batch/_summary.py`, `security/excision.py`,
`storage/ingest_governance.py`.

## Decision: an all-excised re-import is a typed permanent refusal
(reverses #5805's outcome)
#5805's test expected a re-import of an excised file to settle
`completed`. On master that works only because the ingest input route
publishes and reserves the excised bytes again, and admission then skips
the record. With this PR the flush refuses those bytes, so the request
accepts nothing. The operator chose option (d) of polylogue-u6jyu: keep
the typed permanent refusal. The request settles `failed` with error
code `ContentExcisedError`, `retryable: false` and no accepted
reference; nothing is written, and nothing new keeps the bytes from blob
GC. The rejected options were (a) an empty accepted generation, which
would relax durable audit receipt and manifest models; (b) a no-op
`IngestResult` without acceptance, which would change the wire type and
its consumers; and (c) reserving excised bytes on this route, which
would reopen the hole. The test is renamed
`test_reimporting_an_excised_file_is_a_typed_permanent_refusal`. It
asserts the refusal, and it asserts that the re-import adds no source
item and no reservation for the file's hash.

Making the refusal reliable needed one fix (30a2c8d). A request that
failed before acceptance still fenced and settled an attempt it never
created. Settling takes a settled audit read, which fails while the
caller polls the same request, so the refusal was sometimes reported as
`AuditContinuityPendingError` (job 2862). Fencing and settling now run
only after the acceptance write began or a resent request found its
record (`acceptance_attempted`). The same guard covers the stopped and
transient-refusal branches, which had the same pre-acceptance race.

## Residuals
The rest of the security family (qut1/l6v61, dahse, n3xdn, 8k10u, mdlft,
dzk48) is not in this PR; each bead records its state. An excised
sidecar's text, which parse copies into its `tool_result` block, is
still written on a fresh ingest, as on master (polylogue-bgnxh).

## Self-review
I reviewed the complete diff against master 64a9bd0 at head
0ccc5de. The invariant is that no route puts excised bytes back on
disk or back into the index.


**The publication boundary**
- `reserve_many` reads the excision ledger inside its own `BEGIN
IMMEDIATE` and refuses excised hashes. `flush` discards their staged
files.
- `require_published` rechecks the ledger after flush (`excised_now`).
Every refusal is typed (`ContentExcisedError`) or recorded as not
acquired.

**Excision is serialized with every retained write**
- `apply_session_excision`, retained replay,
`apply_raw_membership_classification` and
`write_parsed_for_retained_raw` all run under the store-level
`_retained_replay_exclusion`.
- A batch holds the publisher slot across its transaction, and excision
targets are resolved under that exclusion.

**Each route turns an excised input into a terminal skip, not a retry**
- A ZIP member's bytes that match an excised hash are skipped at decode.
- On the daemon publish path the member is recorded as `REFUSED` with
diagnostic `content_excised`, and never reaches raw admission.
- An Antigravity `.pb` snapshot refused as excised is reported in the
batch's `excised_paths`, not `failed`.
- Excised sidecars keep master's behavior. This PR tried two designs:
redacting the `tool_result` text at write time, which rewrote hashed
content after its identity was bound, and refusing the session, which
dropped the whole session for one sidecar. Both are removed, and the
decision is recorded in polylogue-bgnxh. Since the third merge, master's
sidecar locators (#5815) carry the refusal: a sidecar the pre-check sees
as excised gets `blob_refusal: content_excised`, and
`_settle_sidecar_blobs` gives the same locator to one the flush refuses,
and counts only what the flush published.
- Excised replay attachments are skipped.
- Excised raws settle as skipped, and the reason is durable.


**Merge with master 64a9bd0.** `_core.py` was the only conflict. I
took master's version (#5815's sidecar locators,
`SIDECAR_BLOB_EVENT_TYPES`, the `source_conn` pre-check,
`sidecar_blobs_refused_excised`) and re-applied this PR's non-sidecar
hunks: the `refuse_excised_attachment_blobs` downgrade, the
`ContentExcisedError` session skip with its durable `content_excised`
diagnostic, and the publisher slot held across the batch transaction.
This PR's predecessor sidecar helpers (`_replaced_sidecar_texts`,
`_with_sidecar_blob_hashes`, event-payload `blob_hash` rewriting) are
gone, and nothing references them (`git grep` count 0). Flush sites
master added since the last merge (the hook-evidence, work-event and
raw-artifact writes) go through raw admission after the flush, and
admission raises `ContentExcisedError` at the source-write boundary. The
flush refusal therefore adds no untyped outcome there.

**Sidecar settle fix (85661ff).** Found by
`test_write_session_counts_no_refused_sidecar_blob`: with a publisher
but no `source_conn`, master's locator named a blob the flush then
discarded, and counted it as written. The fix counts after the flush and
gives the typed refusal locator to a sidecar the flush refused.

**Pre-acceptance settle guard (30a2c8d).** Every exit branch of
`execute_ingest_operation` (stopped, transient, generic) checks the
guard. `acceptance_attempted` is set before the acceptance write, so the
path where acceptance committed but the handler raised still fences and
settles. A resent request also sets it. `IngestRedrive` does not go
through this function.

**Checklist (review guide and worker contract).** Consumers updated: all
publisher callers inherit the refusal, and `publication_refused` has
four callers. No compatibility path is added. No cap or timeout:
`_excised_hashes` pages its `IN` list by 500 and reads every row. Tests
assert typed outcomes and counts, not prose. No fixture holds private
data.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[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