docs feat/google-import: whole-branch code review Reviewer: Claude Fable 5.1 (claude-fable-5-1), 2026-11-01. Branch: feat/google-import at 9adc935, read as one diff against origin/main 7d218bd (merge base 7d218bd; five commits, 35 files, +4227/-171). Discussion oficina/docs #102 is the record. Read and tested in a review-only worktree (docs-review-google-import); the implementer's checkout was not touched.
VERDICT ON THE CODE: APPROVED at the corrected tip b805ac4. No blockers. Five non-blocking notes below. The review of 9adc935 found no blocker; b805ac4 adds the en-US spellings and lower reader limits (Addendum 2), and everything I could run is green there (Addendum 3).
MERGE GATE: hub CI at b805ac4 PASSED (checked independently by the parent session after this review's test runs). CI at 9adc935 had failed only the catalog guard, which b805ac4 fixes, and my own run of that test at b805ac4 passes. With CI green the branch meets all three of AGENTS.md's conditions: done, approved here, CI green. Code approval is not shipping approval: Google Cloud configuration, the deployed canary and live consent/export remain Paul's gate, and production DOCSGOOGLE* stays unset.
GATES, AS KNOWN TO ME Browser: DOCSIMPORTPLAYWRIGHT=... go test -tags browser -run TestGoogleImportBrowserCreatesAnEditableDocument in the review worktree: ok, 35 s, Chromium and WebKit, through rastrillo's production middleware; the bearer never reaches Docs, the external relationship target is never fetched, no CSP violation, the editor shows nested text with strong on the right run and no <a>, an edit saves and survives reload, the report reopens, the scriptless upload works, and the database and WAL hold neither content nor report codes in the clear. Go: a bare go test ./... in my worktree failed internal/shipped (Homebrew Go has no libexec/LICENSE; Homebrew rustc, not the pinned 1.98.0) and internal/export (node fixture without fixtures/nodemodules in a fresh worktree). Both are my environment, not the branch: the gate installs fixtures and sources ~/.cargo/env first. A re-run of internal/docs and internal/export after npm ci with the pinned toolchain is recorded in the addendum at the end. Reported by the parent, not run by me: the full .amadan/ci.d/10-gate locally (bundle freshness passed; clippy/wasm were running); hub CI at 9adc935 red on the catalog guard only. Still pending, by Paul's choice: Google Cloud configuration, a deployed canary and live consent/export. Production DOCSGOOGLE_* stays unset. Code approval is not shipping approval.
CHECKED AGAINST THE APPROVED SPEC (B1, B2, B3, R1, R2, R3, R4, R5) B1 Builder (core/src/build.rs, abi.rs, internal/core/core.go). A closed little-endian instruction list: paragraph or heading 1..6, runs of text with marks drawn from fragment.rs's MARKS table minus code and the retired sizes; one font and one size per run, no mark twice, text non-empty and free of control characters. Decoded and checked in full before the document is touched; written in one transaction into an empty root only; heading level stored as a number through the element's map, as y-prosemirror writes it; adjacent same-mark runs merged; empty blocks have no child. Inserts at index 0 in reverse so ten thousand blocks fit the call budget. Refuses a client id past 2^53-1 (lib0's varuint limit) on both sides. ABI bumped to 5, wasm rebuilt and committed. Go's Build runs in a throwaway instance with a 5x call allowance and returns the snapshot; EncodeBuild checks only field widths and leaves vocabulary to the builder. Rust tests cover every malformed shape with a snapshot-unchanged assertion, limits, NotEmpty, the unsafe id, and replay equality; Go tests cover the reader's maxima fitting the ordinary call limit on replay. Replay-equality (import.go convertImport): the update is applied to a second handle under a different id, rendered to JSON, parsed back and compared block by block with sorted marks and merged runs; a mismatch refuses. The interop test then hands twelve real convertImport outputs to Yjs and y-prosemirror under the editor's own schema and asserts the Yjs doc is not changed while reading (no schema clean-up), every client id is a safe integer, and root.check() passes. The gate exports DOCSREQUIREWASM=1 so that test cannot skip in CI. B1 Atomic CreateImported (import.go): row, first update at seq 1 sealed under the update kind, and report sealed under its own kind byte 4, in one transaction with requireMember inside it as CreateDraft has; creation token idempotence returns the existing document and writes nothing (tested: one row after a retried POST); sqid collision retried; ApplyUpdate's COALESCE(MAX(seq),0)+1 continues from 1. Content sealing inactive refuses GET, POST and the store call (tested, nothing written). Reports join readContentSealing, convertContent and requireSealedContent so docs-seal and the mixed-encoding boot check see them. Sealed-at-rest test reads the database and WAL for the marker text and report codes, and proves a report ciphertext does not open as an update. B2 Reader (internal/docx/read.go). Token walk over body, tbl/tr/tc (nested tables included), sdt/sdtContent at block and inline level, hyperlink, ins/moveTo kept and reported, del/moveFrom omitted and reported, smartTag, customXml, fldSimple, dir, bdo; AlternateContent, altChunk, drawing, pict, object, oMath reported as objects; footnote, endnote and comment references, headers and footers reported. Toggles honour w:val (0/false/off/none). Cascade: run rPr over character style over paragraph style chain (ten deep, loop-safe) over docDefaults, with explicit off stopping inheritance; what a style carries that Docs cannot hold is reported for the paragraphs it reaches. Headings by style id or name (Heading N, Title -> h1 reported, Subtitle -> paragraph reported) and take the level's look, keeping only face and run-stated marks. Tabs to spaces, br/cr to new blocks, page/column breaks likewise, each reported. Bounds: 1000 entries, 32 MiB per part and 64 MiB total counted on decompressed bytes, depth 256 counted in next(), DTD refused, duplicate part refused, 10,000 blocks, 40,000 runs, 2 MiB text. No relationship is read: hostile targets in rels never appear in output (tested). Report is closed metadata: codes, counts, first twenty paragraph numbers; no text and no face name (tested). Fuzz holds every output run builder-acceptable. The old reader's eleven losses are listed in the test that now catches them. B3 Route (import.go, app.go). GET/POST /import in the signed-in group under requireMemberRequest (guest 403 tested, cross-site POST 403 tested); MaxBytesReader at 10 MiB plus 64 KiB; MultipartReader part by part, at most eight parts, file into memory up to the bound, no disk; .docx extension and PK signature before the archive opens; two conversions at a time, a third told busy. Refusals are catalog keys with no file name, title or content on the page or in the log (tested with a marker and a secret filename). Title from the base name with separators of either kind stripped, control characters removed, 1024 bytes, else untitled. R1 CSP. Import page and its refused re-render carry exactly one policy equal to googleimport.Policy(ContentSecurityPolicy) with Google on, the app's own with Google off (and no "google" anywhere in the page), no COOP, no-store; the list keeps the app policy either way; served through rastrillo.Handler (tested). Script vendored from memory at a hashed path under /static/estilo/, linked only on a configured page. R2 Google constraints are the shared chooser's; Docs sets Kind docs and passes its form and input ids. Partial or malformed configuration refuses New (tested). R3 Docs copy English in its catalog; chooser labels via googleimport.Text(rastrillo.LocaleFrom(r)). R4 POST /import takes the same member check and transaction-side requireMember as POST /documents. R5 Report shown once on arrival (server-opened <dialog>, closed by a method=dialog form, no script), reopenable from the bar for anyone who can read the document, 404 for a stranger and for a document never imported (tested); the page states the supported subset first and that the list may be incomplete. go.mod pins estilo at merged main 7a19588.
NON-BLOCKING NOTES N1 internal/core/testdata/docscore.wasm, snapshots.go newestSnapshot, store.go replay and ApplyUpdate. The ABI bump to 5 means every stored snapshot (abiversion 4) is ignored, not deleted, from the first boot of this build. Reading never writes a snapshot (replay's comment, D3), so every open of an existing document replays its whole update log until that document's next ApplyUpdate, which writes an ABI 5 snapshot only if at least snapshotCadence (256) updates sit past the last usable one; a document with a shorter log never needed a snapshot and is unaffected. Long logs survive the full replay through reseedForReplay. So the cost is per read of a long document until its next write, not once on first open. Existing policy working as designed, not a defect; belongs in #102 and the deploy note in that form. (Corrected from an earlier wording that said the snapshot is rewritten on first open; the implementer's note in #102 is the accurate one.) N2 internal/docx/read.go run(): a hyperlink written as a complex field (fldChar begin, instrText HYPERLINK, separate, result runs, end) keeps its result text but is not reported under linktextkept. Google exports w:hyperlink, so this is a Word-origin gap only. N3 internal/docx/read.go root(): a document in the ISO Strict namespace (purl.oclc.org/ooxml/...) refuses as "not a Word document". Word's default is Transitional and Google exports Transitional; refusing beats misreading. Mention Strict in the notword copy if anyone ever hits it. N4 internal/docs/import.go importPost: the whole file is read into memory before the conversion slot is taken, so the slot bounds conversion memory (64 MiB decompressed, twice) but not upload buffers (10 MiB per in-flight request). Fine at this scale. N5 internal/docs/render.go catalog: colours, centred, colour are the three en-US guard failures. Fix is spelling only; no behaviour.
NOTED, NOT A FINDING All fixtures are synthesized OOXML in Google's shapes; read_test.go says so at the top. A real Google Docs export with a link, a table, a list, a suggestion and a bold-off run should join the corpus when Paul can supply one he is content to commit.
ADDENDUM 1: re-run at 9adc935 of internal/docs and internal/export with fixtures installed (npm ci) and the pinned toolchain on PATH internal/export: ok. internal/docs: one failure, TestTheCatalogIsWrittenInUSEnglish, on exactly the three strings hub CI named (colour, colours, centred). Nothing else failed. So my first run's other failures were my environment, and the branch's only red at 9adc935 was the spelling guard.
ADDENDUM 2: the corrected tip b805ac4, read as the full diff from 9adc935 Four files, +16/-18. Besides the three spellings it changes behaviour: internal/docx/read.go lowers the reader's limits from 10,000 blocks, 40,000 runs and 2 MiB of text to 5,000 blocks, 10,000 runs and 512 KiB of text; readtest.go's three refusal cases and internal/core/buildtest.go's budget case follow (5,000 blocks of two runs, about 508 KiB), and the toolarge copy now states the new limit. Assessment: acceptable and consistent. The builder's own limits (50,000 blocks, 500,000 runs, 8 MiB) still sit above the reader's, so the reader is the binding bound; the budget test still proves the reader's maximum builds within Build's allowance and replays within the ordinary call limit, which is the property every later open depends on; the user-facing limit and the refusal agree. 512 KiB of text is roughly a 150-page document, ample for the first slice, and the refusal is loud. The commit title says "replay headroom", which I read as the 10,000-block case sitting too close to the one-second call limit on a slower runner; #102 should say what was measured so the number has a reason attached. Not a condition. My own runs at b805ac4 are recorded in Addendum 3.
ADDENDUM 3: my runs at b805ac4 in the review worktree With fixtures installed, ~/.cargo/env sourced and DOCSREQUIREWASM=1: go test -count=1 ./internal/docs ok 111 s go test -count=1 ./internal/docx ok go test -count=1 ./internal/core ok 21 s go test -count=1 ./internal/export ok The catalog guard that was red at 9adc935 passes. The interop test (TestImportedUpdatesOpenInTheEditorUnchanged) ran rather than skipped, since DOCSREQUIREWASM=1 forbids the skip and the package passed. Browser: TestGoogleImportBrowserCreatesAnEditableDocument PASS (3.9 s, Chromium and WebKit, confirmed with -v that it ran). Not run by me: cargo test, clippy, the wasm freshness check and the rest of 10-gate; those are the parent's local gate and hub CI.
FINAL VERDICT ON THE CORRECTED TIP APPROVED on the code at b805ac4. Hub CI PASSED at that commit; my package and browser checks there are green (Addendum 3); no job of mine is still running. Merge may proceed under the usual squash-merge rule. Google Cloud configuration and the live canary remain a separate gate that this approval does not cover. Record in #102: the reviewed commits (9adc935, then b805ac4), this reviewer, the five notes, and the measured reason for the lower reader limits.