Skip to content

A synced document's Markdown export drops its pictures' base64 and marks where they were - #312

Merged
zlareb1 merged 11 commits into
mainfrom
fix/gdrive-doc-inline-images
Nov 7, 2026
Merged

zlareb1 merged 11 commits into
mainfrom
fix/gdrive-doc-inline-images

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A gdrive source no longer stores, chunks and embeds the base64 bytes of the pictures pasted into a document: a line of pictures becomes an [image-only: …] marker, as on a page store's page, and documents synced before this release are converted again once.

Why

The store's Markdown export of a native document holds every pasted picture as a reference definition with an inline data URI ([image1]: <data:image/png;base64,…>), referenced from the text as ![][image1]. The sync wrote that export as it came, so the bytes of each screenshot and diagram became document text: windowed into chunks, embedded, indexed for BM25 and served as search hits and pack context.

Measured on a private set of 44 real native documents (design documents, meeting notes, status reports and runbooks, 64 pasted pictures in 16 of them; 42 synced through the gdrive source, 2 kept in a folder the source is not given): 81% of the documents' characters were base64, and 4,768 of the namespace's 6,692 chunks were base64 windows with no text in them.

The export conversion now drops definitions whose destination is a data URI and replaces each line (or run of lines) that only shows such pictures with the marker the page and slide conversions already use, > [image-only: N pictures, rationale not extracted], followed by any alt text. A list item, quote line or heading that only shows pictures keeps its marker in place (* [image-only: 1 picture, …]), and a run of pictures indented under a list item gets a marker with that indentation. A picture inside a line of text is dropped and its alt text kept, with a space before the text that follows (so exactly one space stays between the neighbouring words, none inside brackets or emphasis and none before punctuation; a line of only a picture wrapped in emphasis is a picture line). Fenced code, at any indent and after list-item or quote marks (so a fence nested in a list item too), is left as it is, and only the blank lines the removed lines leave behind are dropped, so a document without pictures comes out byte for byte as it went in. Reference definitions to real links are left as they are. On the same set: 7.27M characters become 1.38M, no base64 is left, no line of text is lost, 59 markers.

A document stored by an earlier build keeps its revision, so the sync would skip it forever. On a full listing (the only one that lists an unchanged file: LOOM_KNOWLEDGE_SOURCE_SYNC_FULL_INTERVAL_SECONDS, a day by default, or loom knowledge sync --full), the stored-revision read also says whether a document's stored text still holds a picture definition with a data URI; such a native document is fetched and converted again at its same revision. A document without pictures is never fetched again, rewritten or re-embedded, and a converted document no longer matches, so no version stamp is needed. A document whose stored text only shows such a definition (in a code sample, which the conversion leaves as it is) still matches: it is exported once at its revision, compared with the stored copy, neither written nor mined, and recorded in the source's sync state (pictures_checked, file id to revision) so later listings skip it until its file changes; a record is dropped once its file is listed at another revision, or is missing from a trusted full listing. The check reads each document's text, so only full listings ask for it: on the real set's 63 synced files (42 native documents, 14 decks, 7 PDF and .pptx files; 1.6 MiB of live text, plus older versions not yet merged away), the stored-revision read went from 0.94 MiB to 9.4 MiB read, at 0.14-0.21 s either way (system.query_log, two runs each). The check stays on every full listing (daily by default) rather than ending once a listing finds no match: a build without this change, during a rolling upgrade or after a rollback, can store a raw export again, and only this read would find it. It is one read of the source's stored text per full listing (daily by default, and repeated each pass while a full listing stays incomplete, as when the pass bound spreads the reconversion over passes), bounded by the revisions limit; a later release can drop the check once no supported build stores raw exports.

Scope and risk

  • Only native documents (docs) of a gdrive source. Decks, PDF/PPTX extraction, page stores, trackers and recordings are unchanged; knowledge.add and knowledge.ingest store what their caller sent.
  • The refetch after an upgrade is one export and one write per stored native document that still holds pictures' bytes, spread over passes by LOOM_KNOWLEDGE_SOURCE_SYNC_DOCUMENTS_PER_PASS; its chunks are embedded again (far fewer, with the base64 gone). On the real set, 16 of 44 documents matched, the same 16 that had pictures.
  • Mining keys a document by its revision, which the refetch keeps, unless the document carries a text_sha256, in which case by revision and hash (the page-store sync's mechanism). Every native-document write now stores the hash of its title and text, so a copy written again at the same revision with other text (a reconversion, or its redo after a write cut between its document row and its chunks) changes its mined key in the same row and is mined once more, including one given up on earlier as too large for a pass; a write that fails leaves the old copy and its old, already mined key. A document not rewritten keeps its revision-only key, and a rewrite at a new revision has a new key either way, so nothing already mined is mined again. Whether a reconversion changed anything is judged against the SHA-256 of the stored text that the full listing's read returns, so no second read of the document is needed.
  • The stored check only flags reference definitions, the form the store's export writes; an inline ![](data:…) in stored text is converted when its file next changes. A flagged copy whose address moved at the same revision takes the ordinary path: written at the new address, the old one retired.
  • A file given up on at its listed revision is not refetched and not counted unconverted: its stored copy is still served, and the waits decide when it is tried again. The skip-by-revision step takes an explicit refetch for this, rather than a blanked stored revision.

Compatibility, rollout and rollback

  • Wire: none.
  • Rolling upgrade (docs/architecture/rolling-upgrades.md, rule 32): a build without this change skips a document at the revision it stored, so the two builds do not rewrite each other. A document N-1 writes moves the stamp past it, so N converts it again at the next full listing or when the file changes again. Both builds key mining by revision and text_sha256 when a document carries one, so a reconverted document is mined once whichever build mines it.
  • Operator steps: none; loom knowledge sync --full converts the stored documents at once instead of at the next full listing.
  • Rollback: documents written by this build keep their marker text; an older build leaves them until their file changes.

Tests

  • tests/unit/test_knowledge_source_sync.py: the conversion on a synthetic export (pictures alone on a line, a run of them, a list item, a quote line and a heading of only a picture, a run indented under a list item, one inside a list item's text, one between two words, one with a caption beside it, a fenced code block holding image syntax and blank lines, a fence nested in a list item, one opened on a list item's own line, one in a quote, a ~~~ fence, a line whose backtick info string opens no fence, inline data images alone and inside text, a definition with a quoted or parenthesised title, CRLF line endings left as they are, a line of prose that only starts like a definition (kept), emphasis around a picture with and without alt text, a reference to a real link, a document without pictures unchanged); a document stored with its pictures' bytes is converted again at its same revision, mined again and skipped on the next full listing; one stored without them is not fetched again; one whose code sample shows a definition is fetched once at its revision and neither written nor mined (and is written with the comparison removed); flagged-but-unchanged copies listed before a new file do not hold a full listing at the pass bound (and do with the record removed), and the record is dropped when its file is listed at another revision or missing from a full listing, and kept when an incremental turn does not list it; a failed reconverting write mines nothing until the new text is written, then mines it once; a turn cut after the reconverting write, or a write cut before its chunks, still mines the new text; a document given up on is not refetched and not counted unconverted at its address, and is counted unconverted when its address moved; a deck and an uploaded PDF are not fetched again.
  • tests/unit/test_knowledge_source_revisions_sql.py (clickhouse-local, the real loom.documents): a full listing's read flags a definition, and returns the stored text's SHA-256 for a flagged copy only, with a data URI with or without angle brackets and indented, and not a link definition or one inside a line of text; without the flag it reads none (and fails with the pattern's multi-line mode removed).
  • The same file runs the stored check and the conversion's definition pattern on the same lines (with and without angle brackets, indented, with a title, a definition ending in a carriage return (flagged, kept, then found unchanged), a link definition, a definition inside a line): the check flags every line the conversion drops, and also the prose line and the carriage-return line, which the stored-copy comparison then finds unchanged.
  • The same pattern, run against a private ClickHouse: it matches a definition with a data URI, with or without angle brackets and indentation, and not a link definition; on the real exports it flags the 16 documents with pictures and none of the 28 without.
  • The sync of the real set above, run through Loom's own sync worker with the store's transport replaced by the exported files: counts above. Reproduce on any folder of documents with pasted pictures by comparing length(content) and countSubstrings(content, 'base64,') in loom.documents before and after one sync.
  • make format lint typecheck, tests/analyzer, the doc-link and public-copy tests, and the unit suite.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. The conversion was checked line by line against 44 real exports: every line of text that is not a picture is kept.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the fix/gdrive-doc-inline-images branch from ce61f58 to e1183ce Compare November 7, 2026 08:28
zlareb1 and others added 11 commits November 7, 2026 11:53
…rks where they were

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…d not fetched again; no space after an opening bracket

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…nt hash is named for what it hashes

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…a picture keeps its shape; stale records of unchanged copies go

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…only at the stored address; patterns at module level

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…hesised title tested; the code-sample test counts its exports

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…cut write is mined again; readable record pruning

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…nd a reconversion is only tried at the stored address

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…matches the same way

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ed hash is read with prior narrowed

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…icture-check record's pruning is tested on each listing

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/gdrive-doc-inline-images branch from 86c68e7 to 5929c89 Compare November 7, 2026 12:02
@zlareb1
zlareb1 merged commit b50ebc1 into main Nov 7, 2026
@zlareb1
zlareb1 deleted the fix/gdrive-doc-inline-images branch November 7, 2026 12:02
@zlareb1 zlareb1 mentioned this pull request Nov 12, 2026
3 tasks done
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