Skip to content

feat(storage): backfill unfetched attachment acquisition from durable raw evidence - #3590

Merged
Sinity merged 2 commits into
masterfrom
feature/storage/attachment-reacquisition-backfill
Aug 2, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/storage/attachment-reacquisition-backfill

Conversation

@Sinity

@Sinity Sinity commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a read-only classifier plus an operator-gated actuator that backfills historically-unfetched attachments rows where the source payload still contains the bytes, and marks the genuinely unrecoverable ones distinctly instead of leaving them ambiguously 'unfetched' forever.

Problem

7,376 of 9,289 attachments (79%, polylogue-pfdf / polylogue-7r6u) sit at acquisition_status='unfetched'. PR #2469 and commit 60d93b6 ("acquire Claude extracted payloads") fixed real attachment-byte acquisition going forward, but the historical backlog was never backfilled: an attachment ingested before a parser fix landed still has no blob_hash, even though its owning session's raw payload is durable in source.db and today's parser may already extract it (ParsedAttachment.inline_bytes). Separately, 'unfetched' was the only acquisition_status a genuinely gone attachment could ever reach (e.g. ChatGPT Code Interpreter sandbox output — chatgpt.py's own comments document these as never carrying bytes at all) — indistinguishable from "not yet tried".

Solution

polylogue/storage/attachment_reacquisition.py follows the same read-only-classifier + operator-gated-actuator architecture already established by attachment_relink.py (ref-linkage backfill) and blob_integrity.py's raw-side actuators:

  • plan_attachment_reacquisition() classifies every unfetched attachment into:
    • reacquirable: re-parsing its still-durable raw_sessions payload with today's parser (via the real ingest_record entry point) reproduces its content-identity hash (write.py:_attachment_id, independent of session/message) with inline bytes.
    • unrecoverable: a static source_url='sandbox:...' signature — no reparse needed, matches chatgpt.py's own documented "nothing local to fetch" semantics for Code Interpreter output.
    • undetermined: left exactly as unfetched — most commonly Drive/OAuth attachments that would need a live authenticated fetch (the separate, larger polylogue-ck5v follow-on); this module performs zero network I/O and never guesses.
  • apply_attachment_reacquisition() acts on the safe verdicts only. Dry-run by default; --apply requires an immutable JSONL manifest of every row acted on plus a verified backup manifest for the index tier (the same gate durable-tier migrations use, validate_migration_backup_manifest). Reacquired bytes are published through the same content-addressed blob store/ArchiveBlobPublisher every other acquisition path uses. The schema's existing but previously-unused acquisition_status='unavailable' value is what marks unrecoverable attachments distinctly — no schema change needed.
  • Two devtools commands wire this into the control plane: devtools workspace attachment-reacquisition (report) and ...-apply (actuator), mirroring the raw-live-source-reconciliation report/apply pair.

Never attempted: acquisition for Drive-hosted/OAuth attachments needing a live network fetch — that is polylogue-ck5v's scope, not this bead's.

Verification

  • devtools test tests/unit/storage/test_attachment_reacquisition.py — 7 passed. Exercises real ingest_record parsing against a real source.db/blob store and real index.db mutation: proves a historically-unfetched attachment with recoverable extracted_content bytes is reacquired, a sandbox-output attachment is marked unavailable with zero reparse, a genuinely unmatched ("ghost") attachment stays undetermined/unfetched, and --apply refuses without a manifest path or a verified backup manifest.
  • devtools verify --quick clean (added a degrade-loudly log call and a hash-boundary-census registry entry for the new hashlib.sha256 call site).
  • Ran the new read-only report against the live production archive (/realm/db/polylogue, read-only, no mutation) as a real-world sanity check; full-corpus timing is dominated by real per-row parse cost on large session payloads (some multi-MB/GB Claude Code JSONL files), so a bounded --raw-row-limit is the intended operator dial for a first-pass classification before deciding on --apply scope.

Ref polylogue-pfdf, polylogue-7r6u

@coderabbitai

coderabbitai Bot commented Aug 2, 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: 20 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 Plus

Run ID: db2ba41a-7931-4c3a-b069-5ec323007cbb

📥 Commits

Reviewing files that changed from the base of the PR and between 6eaf337 and b73deb3.

📒 Files selected for processing (9)
  • .beads/issues.jsonl
  • devtools/attachment_reacquisition_apply.py
  • devtools/attachment_reacquisition_report.py
  • devtools/command_catalog.py
  • docs/devtools.md
  • docs/plans/hash-boundary-registry.yaml
  • docs/plans/topology-target.yaml
  • polylogue/storage/attachment_reacquisition.py
  • tests/unit/storage/test_attachment_reacquisition.py

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 and others added 2 commits August 2, 2026 23:13
… raw evidence

Problem: 7,376 of 9,289 attachments (79%, polylogue-pfdf/polylogue-7r6u)
sit at acquisition_status='unfetched'. PR #2469 and 60d93b6 fixed real
attachment-byte acquisition going forward (ParsedAttachment.inline_bytes
propagation), but the historical backlog was never backfilled: an
attachment ingested before a parser fix landed still has no blob_hash,
even though its owning session's raw payload is durable in source.db and
today's parser may already extract it. Separately, 'unfetched' was the
only acquisition_status a genuinely gone attachment (e.g. ChatGPT Code
Interpreter sandbox output, which chatgpt.py's own comments document as
never carrying bytes) could ever reach -- indistinguishable from "not yet
tried".

What changed: new polylogue/storage/attachment_reacquisition.py, following
the same read-only-classifier + operator-gated-actuator architecture as
attachment_relink.py (ref-linkage backfill) and blob_integrity.py's raw
actuators:
- plan_attachment_reacquisition() classifies every unfetched attachment
  into reacquirable (re-parsing its still-durable raw_sessions payload
  with today's parser, via the real ingest_record entry point, reproduces
  its content-identity hash with inline bytes), unrecoverable (a static
  source_url='sandbox:...' signature -- no reparse needed, matches
  chatgpt.py's own documented semantics), or undetermined (left unfetched,
  honestly not-yet -- most commonly Drive/OAuth attachments needing a live
  authenticated fetch this module never performs, see polylogue-ck5v).
- apply_attachment_reacquisition() acts on the safe verdicts only: dry-run
  by default; --apply requires an immutable JSONL manifest of every row
  acted on plus a verified backup manifest for the index tier (the same
  gate durable-tier migrations use). Reacquired bytes are published through
  the same content-addressed blob store and ArchiveBlobPublisher every
  other acquisition path uses; the schema's existing but previously-unused
  acquisition_status='unavailable' value is what marks unrecoverable
  attachments distinctly from 'unfetched', with no schema change needed.
- Two devtools commands wire this into the control plane:
  `devtools workspace attachment-reacquisition` (report) and
  `...-apply` (actuator), mirroring the raw-live-source-reconciliation
  report/apply pair.

Never touched: acquisition for Drive-hosted/OAuth attachments needing a
live network fetch (polylogue-ck5v is the separate, larger follow-on for
that); this module performs zero network I/O.

Verification: `devtools test tests/unit/storage/test_attachment_reacquisition.py`
(7 passed) exercises real ingest_record parsing against a real source.db/
blob store and real index.db mutation -- proves a historically-unfetched
attachment with recoverable extracted_content bytes is reacquired, a
sandbox-output attachment is marked unavailable without any reparse, a
genuinely unmatched ("ghost") attachment stays undetermined/unfetched, and
--apply refuses without a manifest path or a verified backup manifest.
`devtools verify --quick` clean (added a degrade-loudly log call and a
hash-boundary-census registry entry for the new hashlib.sha256 call site).
Ran the new read-only report against the live production archive
(/realm/db/polylogue, read-only) as a real-world sanity check.

Ref polylogue-pfdf, polylogue-7r6u

Co-Authored-By: Claude <[email protected]>
Ref polylogue-pfdf, polylogue-7r6u

Co-Authored-By: Claude <[email protected]>
@Sinity
Sinity force-pushed the feature/storage/attachment-reacquisition-backfill branch from a08c719 to b73deb3 Compare August 2, 2026 21:16
@Sinity
Sinity merged commit 5193ffa into master Aug 2, 2026
3 checks passed
@Sinity
Sinity deleted the feature/storage/attachment-reacquisition-backfill branch August 2, 2026 21:19
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