Skip to content

fix(drive): one attachment owner and a revision-keyed document cache - #5649

Merged
Sinity merged 7 commits into
masterfrom
claude/bugsweep-1
Sep 27, 2026
Merged

Sinity merged 7 commits into
masterfrom
claude/bugsweep-1

Conversation

@Sinity

@Sinity Sinity commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Summary

Drive-hosted attachment bytes had two owners. This leaves the daemon attachment-convergence stage as the only one, and makes it stream downloads, with no size cap.

Problem

  • iter_drive_raw_data fetched every Drive-hosted attachment into memory during raw acquisition. Anything over 50 MiB was skipped. The rest was base64-embedded into the session JSON, and the whole document was re-serialized. The retained raw was therefore no longer the provider's bytes.
  • A later successful fetch minted a new raw revision. Only the JSON-structural classifier could relate that revision to its predecessor.
  • The daemon's attachment_bytes convergence stage already fetches the same references from the canonical attachment rows for every route (ZIP-restored payloads included). It also buffered each download in memory and marked files over 50 MiB permanently unavailable.

Solution

  • Delete sources/drive/attachment_fetch.py and the acquisition-time injector in sources/drive/__init__.py. Also delete the parser hooks that decoded or stripped the injected key (drive_support_attachments.py, providers/gemini_message.py). Drive raws are now the provider's bytes verbatim, and Drive attachments are parsed as unfetched references.
  • converge_drive_attachments now takes download_into(file_id, handle). Each download streams into a private staging spool (new BlobStore.spool_file). The blob is prepared from the spool, and a refused download discards its staged file. The 50 MiB cap is removed.
  • DriveSourceClient.download_into streams through the gateway, restarting the handle on retry.
  • structural_diff stays, because AI Studio itself re-serializes a document when a conversation grows. Its docs and the Drive catch-up equivalence test now use that real growth shape instead of the injector.

Verification

  • ruff check / ruff format on changed files: clean. mypy on the changed modules and tests: no issues.
  • New anti-vacuity test test_attachment_download_streams_to_disk_and_has_no_size_cap: buffering in memory makes fileno() raise, and reinstating a cap marks the row unavailable.
  • Focused devtools test is queued behind the host pytest pool. The result will be added to this PR.

Residuals

  • schema closure: sources/drive/__init__.py, sources/drive/source_client.py and storage/blob_store.py are IN, so this must land before a fresh rebuild.
  • Drive attachments on a fresh archive are acquired by the convergence stage after ingest, which needs a configured Drive client in the daemon.

🤖 Generated with Claude Code

https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 27, 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-27T21:48:19.236990Z aba885d New commits
ℹ️ 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.

@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: e67c608a8b

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

@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: d486c6b3de

ℹ️ 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/sources/drive/__init__.py Resolved

@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: dbbec44589

ℹ️ 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/sources/drive/__init__.py Resolved
@Sinity Sinity changed the title fix(drive): fetch attachment bytes only through the convergence stage fix(drive): one attachment owner and a revision-keyed document cache Sep 27, 2026
@Sinity

Sinity commented Sep 27, 2026

Copy link
Copy Markdown
Owner Author

Verification at dbdbd80, one focused selection of 13 files (Drive ops, cache skip, catch-up, parsers, structural diff, Gemini, attachment convergence and excision, stage admission, blob store, schema closure):

  • 3 failed. The same 3 fail on origin/master 048ade4 (master baseline receipt 20260927T191141Z-focused-test-1799024-a2bc45f3):
    • test_gc_records_a_new_generation_when_it_runs
    • test_gemini_cli_schema_fields_survive_dispatch_with_human_authored_override
    • test_drive_phased_matches_ordinary_*: the asserted lineage assertion. _bind_drive_revision_lineage raises no such table: source_item_raw_members on both master and this branch.
  • Everything else passed (receipt 20260927T191444Z-focused-test-1823711-1864f221).
  • Commit dbdbd8038 also keys the Drive cache by provider revision. Before this, a document that grew on Drive was served from the stale cache and never re-acquired; the removed injector had masked that.

@Sinity
Sinity enabled auto-merge (squash) September 27, 2026 20:05
@Sinity

Sinity commented Sep 27, 2026

Copy link
Copy Markdown
Owner Author

Focused tests at 4b9d67d (attachment convergence, excision, stage writer admission, blob store) passed; receipt 20260927T194744Z-focused-test-2237188-18176681, clean tree at that head.

Sinity and others added 7 commits September 27, 2026 23:43
Drive-hosted attachment bytes had two owners. Raw acquisition fetched them
into memory, dropped anything over 50 MiB, and re-serialized the whole
session document with the bytes embedded as base64, so the retained raw was
no longer the provider's bytes and a later successful fetch minted a new
revision that only a JSON-structural classifier could relate to its
predecessor. The daemon attachment convergence stage already fetches the same
references from the canonical attachment rows for every route.

Delete the acquisition-time injector and its parser hooks, leaving the
convergence stage as the one owner. Stream each download into a private
staging spool (BlobStore.spool_file) and prepare the blob from it, so an
attachment of any size costs bounded memory; the 50 MiB cap that marked
larger files permanently unavailable is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4
A Drive cache written by the removed acquisition-time injector is valid
JSON but not the provider's document; serving it would carry the base64
sidecar into the archive. Re-download it instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4
It entered the derived closure only through the deleted acquisition-time
attachment fetcher.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4
The cursor fast path proved a cache readable with ijson and skipped the
download, so a rewritten cache with an unchanged provider mtime survived.
Refuse the rewrite marker there too.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4
The Drive cache was keyed by file name only. Whenever it existed and
decoded, iter_drive_raw_data served it instead of downloading, so a document
that grew on Drive was never re-acquired: its modifiedTime changed, the
cursor fast path missed, and the stale cache still won. The removed
attachment injector masked this by rewriting the bytes on every read.

Record the provider revision beside each cache file and treat a cache as
valid only for that revision. That also retires caches written before
revisions were recorded, including ones the injector rewrote, so the
marker check added earlier in this branch is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4
Attachment convergence spooled each download to an anonymous file and then
copied it into a staging file, so an attachment larger than half the free
space failed with ENOSPC on every retry. BlobStore.prepare_from_writer lets
the producer write straight into the staging file that becomes the prepared
blob and hashes it in place, which also stays correct when a retrying
download restarts the file.

Also document that Drive-hosted Gemini attachments are fetched by the
convergence stage after ingest, not during it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4
#5651 added a no-size-cap test that buffers 51 MiB through the removed
bytes-returning download; test_attachment_download_streams_to_disk_and_has_no_size_cap
already proves the same property through the streaming contract.

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

Sinity commented Sep 27, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto master after #5651, which removed the size cap but kept the in-memory download. The conflict in attachment_convergence.py resolves to the streaming version. #5651's 51 MiB buffered size test is folded into test_attachment_download_streams_to_disk_and_has_no_size_cap. Focused selection at aba885d: 77 passed (convergence, excision, stage admission, Drive ops, cache skip, blob store, schema closure); receipt 20260927T214416Z-focused-test-3592177-1fa4b968.

@Sinity
Sinity merged commit d2e7214 into master Sep 27, 2026
3 checks passed
@Sinity
Sinity deleted the claude/bugsweep-1 branch September 27, 2026 21:53
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