Skip to content

fix(attachments): Partition the acquired bucket instead of certifying unchecked claims - #5378

Merged
Sinity merged 1 commit into
masterfrom
fix/attachment-coverage-honesty
Sep 22, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/attachment-coverage-honesty

Conversation

@Sinity

@Sinity Sinity commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

Two coverage reads over source_attachments disagreed. corpus-attachment-fidelity already partitioned the acquired bucket correctly; scan_attachment_coverage and the attachment-coverage gate collapsed it into a boolean and certified rows they had not checked. This partitions the second read the same way and stops one write route from re-asserting acquisition on trust.

Problem (evidence)

Measured at 158d1363e on a synthetic index.db with three acquisition_status='acquired' rows — one with bytes in the store, one naming a hash the store does not hold, one with blob_hash NULL:

  • scan_attachment_coverage returned {acquired_count: 3, acquired_reachable_count: 3, acquired_missing_blob_count: 1} — no term at all for the NULL-hash row, because of if blob_hash is None: continue.
  • On a lone hashless acquired row the attachment-coverage gate printed OutcomeStatus.OK with the summary all 1 acquired attachment(s) have bytes and a live attachment reference — a false sentence about an archive where it had checked nothing.
  • _surviving_blob_ref gated the re-bind on blob_store.exists() ("a file sits at that path") and then wrote acquisition_status='acquired'. A published blob corrupted in place produced {recorded_hash: 664656fb…, actual_hash_of_file: 4ca8451f…, byte_count_claimed: 32, actual_size: 31, downloads_attempted: []} — acquisition re-asserted with no provider request and no signal.

The bead's other cited defect (DriveNotFoundError recorded as acquired) does not reproduce at head; it terminates unavailable and has since #4873/#4908. That citation is stale.

Solution

  • AttachmentCoverageReport partitions acquired into acquired_with_bytes_count (corroborated), acquired_missing_blob_count (contradicted) and acquired_unverifiable_count (nothing to check), published side by side in to_dict(). Following fix: Separate unmeasured from measured zero across four red surfaces #5367's raw_materialization_unmeasured_reason, an unmeasured claim gets its own term rather than folding into the nearest boolean.
  • ok is false for either non-corroborated term, so an unmeasured claim blocks exactly as a false one does — without the report ever asserting bytes are absent.
  • The survivor probe uses blob_store.verify(), not exists(). A contradicted survivor is not evidence: it falls through to the provider, and emits operations.attachment_convergence.survivor_contradicted at WARNING/outcome=degraded so a decayed published blob is not silently erased by a re-download.

Verification

devtools verify --quick                    exit 0   25 gates ok (schema-closure, atlas, layering, test-collection)
devtools render all --check                exit 0   8 "sync OK", 0 "out of sync" (grep -c on captured log)
devtools test <8 attachment selections>    exit 0   198 passed in 75.25s

Receipt .cache/verify/runs/20260922T003420Z-focused-test-183221-b5c5388c/run.json.

Inherited-red baseline at 158d1363e in this worktree: 177 passed, exit 0 — no inherited reds in the touched scope.

Anti-vacuity conditions were executed, not asserted. Restoring if blob_hash is None: continue → 3 failed, including assert <OutcomeStatus.OK> is <OutcomeStatus.ERROR> with summary all 1 acquired attachme…. Reverting debt_count to missing + unreachable → 1 failed, whose evidence dict reads 'unverifiable_count': 1 beside that same summary — the exact claim/measurement split. Reverting verify() to exists() → assert [] == ['drive-file-1'], the corrupted survivor re-binding with no provider request.

Schema identity

Does not move. derived_schema_identity at 158d1363e equals that at this head for both derived tiers (index d5e285b3…, ops 86866235…). All six changed files report out; storage/blob_liveness.py is the one IN-closure file in the area and was deliberately not touched. No DDL, no vocabulary member — acquisition_status keeps its existing three-value durable CHECK. Safe to land at any point relative to the build boundary.

Residuals

  • Criterion 5 of polylogue-o0uw5 is not discharged by this branch. Which route removed the 1242 blobs is still unnamed; the evidence is gc_generations in source.db and the daemon event log, neither read here. The bead's own design marks it not dispatchable to a code worker.
  • Live census (read-only, reflink copy, deleted after): 1933 acquired rows, 1446 distinct acquired hashes, 204 with bytes, 1242 contradicted — the bead's 1240/1446 still reproduces. 0 acquired rows with NULL blob_hash, so the unverifiable term guards a latent shape the live archive does not currently contain.
  • Oversize attachments and explicit 404s both terminate unavailable, but for an oversize file the provider still has the bytes — the same overstated claim in the opposite direction. Out of scope; wants its own bead.
  • demo/constructs.py:104 claims stored bytes but its SQL never consults the store.
  • daemon/webui_data.py collapses six attachment states into missing-blob.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy

Summary by CodeRabbit

  • Bug Fixes

    • Attachment coverage now flags acquired attachments without verifiable blob identity as blocking issues.
    • Coverage reports distinguish attachments with bytes, missing blobs, and unverifiable blobs, including counts and sample details.
    • Corrupted retained blobs are rejected and re-fetched when possible, preventing invalid attachments from being rebound as acquired.
    • When recovery fails, affected attachments are correctly marked unavailable without retaining invalid blob data.
  • Tests

    • Added coverage for unverifiable attachments, corrupted blobs, and recovery failures.

`acquisition_status = 'acquired'` is a positive claim about durable state,
not a measurement of it. Two routes still took it, or wrote it, on trust:

- `scan_attachment_coverage` skipped an `acquired` row with a NULL
  `blob_hash` outright, so an acquisition claim with nothing to check it
  against counted as covered and left `ok` true. The `attachment-coverage`
  gate then reported "all 1 acquired attachment(s) have bytes and a live
  attachment reference" for an archive where it had checked nothing, while
  `corpus-attachment-fidelity` blocked on the same row.
- `_surviving_blob_ref` gated the re-bind on `exists` -- "a file sits at
  that path" -- and then wrote `acquired`. A published object whose content
  no longer hashes to the recorded identity re-asserted acquisition of
  content the archive no longer held, with no provider request.

The coverage report now partitions the `acquired` bucket into corroborated,
contradicted and unverifiable terms rather than collapsing any of them into
a boolean, and the re-bind re-hashes the object it binds: a contradicted
survivor is reported and falls through to the provider, which either
republishes real bytes or terminates the row `unavailable`.

Measured at head before the change (synthetic, three acquired rows -- one
with bytes, one with a hash the store lacks, one with no hash):
`acquired_count=3, acquired_reachable_count=3, acquired_missing_blob_count=1`
with the hashless row invisible; and a corrupted survivor re-bound to
`acquired` with `byte_count=32` for a 31-byte object hashing to a different
digest.

Refs polylogue-o0uw5

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
@Sinity
Sinity enabled auto-merge (squash) September 22, 2026 00:38
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 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
📝 Code Review ✅ Completed 2026-09-22T00:48:25.988400Z f9284d2 PR opened
🔒 Security Review ✅ Completed 2026-09-22T00:45:28.401102Z f9284d2 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.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 7715b0d6-3076-4ad9-a393-c69e5b03dcfc

📥 Commits

Reviewing files that changed from the base of the PR and between 158d136 and f9284d2.

📒 Files selected for processing (6)
  • polylogue/maintenance/archive_verification.py
  • polylogue/operations/attachment_convergence.py
  • polylogue/storage/blob_integrity.py
  • tests/unit/daemon/test_attachment_convergence.py
  • tests/unit/maintenance/test_archive_verification.py
  • tests/unit/storage/test_blob_integrity.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Recent review details
🔇 Additional comments (6)
polylogue/storage/blob_integrity.py (1)

2436-2455: LGTM!

Also applies to: 2460-2464, 2483-2483, 2487-2493, 2501-2501, 2508-2509, 2563-2565, 2569-2575, 2579-2579, 2590-2594

polylogue/maintenance/archive_verification.py (1)

2201-2207: LGTM!

Also applies to: 2221-2223, 2226-2226, 2233-2234, 2243-2248

tests/unit/storage/test_blob_integrity.py (1)

522-614: LGTM!

Also applies to: 616-648

tests/unit/maintenance/test_archive_verification.py (1)

1748-1795: LGTM!

polylogue/operations/attachment_convergence.py (1)

156-156: LGTM!

Also applies to: 175-184, 200-213, 263-266, 288-288

tests/unit/daemon/test_attachment_convergence.py (1)

14-14: LGTM!

Also applies to: 353-421


📝 Walkthrough

Walkthrough

Changes

Attachment coverage now counts hashless acquired attachments as unverifiable debt. Convergence verifies retained blob contents before rebinding and retries provider acquisition when verification fails.

Attachment evidence verification

Layer / File(s) Summary
Coverage debt reporting
polylogue/storage/blob_integrity.py, polylogue/maintenance/archive_verification.py, tests/unit/storage/test_blob_integrity.py, tests/unit/maintenance/test_archive_verification.py
Coverage reports verified, missing, and unverifiable acquired attachments. Hashless acquired rows make the report non-OK and appear in blocking evidence.
Retained blob verification
polylogue/operations/attachment_convergence.py, tests/unit/daemon/test_attachment_convergence.py
Convergence re-hashes retained blobs. Corrupted blobs emit a warning and trigger provider retrieval instead of rebinding stale content.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Sequence Diagram(s)

sequenceDiagram
  participant converge_drive_attachments
  participant _surviving_blob_ref
  participant BlobStore
  participant Provider
  converge_drive_attachments->>_surviving_blob_ref: probe retained attachment
  _surviving_blob_ref->>BlobStore: verify recorded blob hash
  BlobStore-->>_surviving_blob_ref: valid or contradicted content
  _surviving_blob_ref->>Provider: fetch when verification fails
  Provider-->>converge_drive_attachments: available or missing file
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 72.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: partitioning acquired attachment claims instead of certifying unchecked claims.
Description check ✅ Passed The description is detailed and covers the summary, problem, solution, verification, schema impact, and residual risks. It does not use the required Changelog heading, but the missing section is non-c…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

A rabbit checks each stored byte,
Hashless claims now mark the night.
Corrupted blobs raise a sound,
Fresh provider paths are found.
Coverage counts what proof can show.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f9284d2126

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/storage/blob_integrity.py Resolved
@Sinity
Sinity merged commit 5fe621a into master Sep 22, 2026
3 checks passed
@Sinity
Sinity deleted the fix/attachment-coverage-honesty branch September 22, 2026 00:48
@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at ef10e59):

Resolving the fixed, stale and refuted threads; tracked threads stay open.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 64a9bd0):

  • P1 polylogue/operations/attachment_convergence.py:200: Fixed on master (checked at 64a9bd0): Before staging, a download whose canonical destination exists but fails verification is refused as contradicted. The row stays unfetched and retryable instead of being marked acquired (polylogue/operations/attachment_convergence.py:416-443).

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at f88b4a6):

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 72.F059 / P1: fixed-already at the checked revision: polylogue/storage/blob_integrity.py:890 verifies the blob digest before counting acquired bytes. An existing file with the wrong hash instead increments corrupt_count at :894, so path existence alone no longer certifies attachment coverage.

Only the rows listed above are dispositioned. Held findings remain open.

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