Repository navigation
fix(drive): one attachment owner and a revision-keyed document cache - #5649
Conversation
|
You have reached your Codex usage limits for security reviews. Please try again later. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
|
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):
|
|
Focused tests at 4b9d67d (attachment convergence, excision, stage writer admission, blob store) passed; receipt |
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
4b9d67d to
aba885d
Compare
|
Rebased onto master after #5651, which removed the size cap but kept the in-memory download. The conflict in |
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_datafetched 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.attachment_bytesconvergence 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 permanentlyunavailable.Solution
sources/drive/attachment_fetch.pyand the acquisition-time injector insources/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_attachmentsnow takesdownload_into(file_id, handle). Each download streams into a private staging spool (newBlobStore.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_intostreams through the gateway, restarting the handle on retry.structural_diffstays, 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 formaton changed files: clean.mypyon the changed modules and tests: no issues.test_attachment_download_streams_to_disk_and_has_no_size_cap: buffering in memory makesfileno()raise, and reinstating a cap marks the rowunavailable.devtools testis 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.pyandstorage/blob_store.pyare IN, so this must land before a fresh rebuild.🤖 Generated with Claude Code
https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4