oficina / mapa Public

Notion import design, revision 4: answer Fable's diff check

Re-pin to images revision 4: the two import methods pass attach (the
rename revision does not); section 13 aligned with 14.1; both image
allowances named, commit as it goes, kept pages' pending images removed;
lease checked before AddImage/CopyImage; SafeURL and taskBox rows
widened; block-only image print; bookkeeping callers listed; workspace
id marked unverified.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev fc142a87800301c8e8c0def8e6a0b3e26e5c76ad parent 68eec68
1 file changed, +41 −22
  • docs/superpowers/specs/2026-11-17-notion-import.md +41 −22

CI passed — run details

CI log
=== editor ===
cd editor && npm ci --no-audit --no-fund --loglevel=error

added 16 packages in 317ms
cd editor && node build-bundles.mjs
wrote internal/mapa/static/editor.c25f62142895a785.js (318737 bytes, 99.5KB gzipped; L12 budget 120KB)
cd editor && node --test
✔ L1: mounting then serialising gives cleanBody(body), byte for byte (43.086846ms)
ℹ 760 bodies
✔ L1: mounting a stored body adds nothing, and saving it writes nothing new (64.371231ms)
✔ L2: one edited block changes only that block's bytes; undo gives the body back (131.804472ms)
ℹ 748 single-block edits
✔ L2: inserting or deleting a block changes bytes only at the new seams, by Join (142.753749ms)
ℹ 755 inserts, 715 deletes
✔ L3: seeded edits keep the document and its Markdown saying the same thing (3471.105724ms)
ℹ 18240 edits over 760 bodies
✔ L3: Link to a page makes exactly one chip, and changes nothing else (1386.009633ms)
ℹ 4124 links over 760 bodies; refused: {"A page link can’t hold another link or a line break. Select plain words.":610,"A page link can’t show [ or ]]. Select words without them.":370,"Select some words to link them to a page.":163,"Linked here, the Markdown around these words would read differently: a ! before them makes an embed, and a stray ` or * pairs up. Select other words.":17}
✔ linear: trailing spaces (25.39804ms)
✔ linear: trailing whitespace (15.242597ms)
✔ linear: unclosed web links (17.00512ms)
✔ linear: web links with no address (22.447067ms)
✔ linear: unclosed wiki links (19.083211ms)
✔ linear: unclosed embeds (25.975339ms)
✔ linear: closes only (5.250559ms)
✔ the selected words become the chip's shown text (9.047414ms)
✔ words that are the title make a plain [[Title]] (2.42462ms)
✔ spaces at the selection's edges stay outside the chip (1.047507ms)
✔ a date makes a date link, in a heading, an item and a quote (5.22362ms)
✔ bold words lose their bold: a chip carries no marks in Mapa's Markdown (0.934847ms)
✔ only the linked block's bytes change, and undo gives the body back (1.704144ms)
✔ a selection across blocks, over a chip or a break, or of brackets is refused (0.904109ms)
✔ a target the words cannot be linked to as typed is refused (0.192159ms)
✔ ⌘L: over a selection it opens Page link; with none it types [[; in code it does nothing (1.629865ms)
✔ web-linked words are refused: the address would be lost (review M4) (0.769608ms)
✔ words whose Markdown would read otherwise are refused (review M3) (1.366713ms)
✔ ⌘A then ⌘L says why, instead of doing nothing (review low 1) (0.324897ms)
✔ linkCheck says why it refuses (review low 2) (0.514772ms)
✔ golden file has bodies (0.671685ms)
✔ markup.mjs parses every body into Go's blocks, byte offsets and all (15.171143ms)
✔ markup.mjs strips and spans every block as Go does (28.089188ms)
✔ the schema's toDOM draws every body as Go renders it (49.831147ms)
✔ emphasis draws the four pinned outputs (15.636582ms)
✔ a body ends in the editor's empty paragraph (0.283659ms)
✔ a POST that never answers is aborted after the timeout (21.16435ms)
✔ a keepalive POST carries no signal, and an answer clears the timer (1.099284ms)
✔ autosave sends only what differs, and the tab owns the draft it wrote (11.960755ms)
✔ an offered draft never commits by itself; Save commits it (1.162882ms)
✔ reload, then close: sessionStorage says the draft is this tab's own (0.684168ms)
✔ closing carries text not yet sent, and the cap leaves it out (25.143113ms)
✔ clean rebase: applied, the caret survives, the base moves by the rebase POST (3.107245ms)
✔ the block under the caret is the teammate's too, and undo brings back yours (5.761353ms)
✔ typing mid-flight: the merge is not applied and the base does not move (1.05985ms)
✔ a merge the editor cannot represent stops after three tries (2.990658ms)
✔ a conflict is shown, locks the editor's own commits, and Resolve settles it (1.212406ms)
✔ leaving: a conflict stays with the choice; a failed flush offers Leave anyway; a stored draft leaves (1.507977ms)
✔ a stale tab shows the newer draft, offered, and never overwrites it (0.935598ms)
✔ the first scratch commit: empty creates nothing, then one page, then drafts on it (0.79779ms)
✔ noBase and gone lead to the existing choices (0.783354ms)
✔ a commit that merged is applied when nothing was typed since (1.105505ms)
✔ back from the cache: nothing unsaved reloads, unsaved text autosaves at once (5.870568ms)
✔ an own draft committed meanwhile goes on as a new draft (1.044041ms)
✔ a reload keeps a stored draft; unsent text still commits (0.421677ms)
✔ a page deleted mid-edit: what is typed is still stored as the draft, and nothing commits (H1) (0.850789ms)
✔ an offered draft committed in another tab: typing goes on as a new draft (H1) (2.243851ms)
✔ a commit reply without a revision is not a commit; an emptied day starts afresh (H2) (1.104253ms)
✔ Resolve stores what was typed first, and takes no typing until its answer is applied (M1) (3.755205ms)
✔ closing with a choice open, or commits held, still writes the text, never commits (M2) (0.988578ms)
✔ closing inside the settling window sends the loaded version with settling=1 (M3) (0.264113ms)
✔ a clean merge not applied because of typing still ends the choice on show (M4) (0.71172ms)
✔ settling finds the draft committed with a teammate's text: a close still writes (M-A) (0.387464ms)
✔ settling finds another tab's newer draft: the tab shows it before any typing (0.581627ms)
✔ a page deleted before the first autosave: the text is offered as a scratch page, and a close makes one (M-B) (0.522426ms)
✔ an autosave that never answered but landed: its 409 keeps the typing since (L3) (0.505415ms)
✔ marks: em outside strong, bold reopened around italics, edges outside (5.324528ms)
✔ marks close before code, links and atoms, and reopen after (0.422329ms)
✔ untouched blocks and atoms re-emit their source; edited atoms are written from attributes (5.377076ms)
✔ empty blocks are written as nothing (1.89981ms)
✔ an unclosed fence that is no longer last gets its closing fence (1.406408ms)
✔ the structure check puts Join's seam where a kept one would merge two blocks (1.729371ms)
✔ prepareSave adopts the parse when no seam or rewrite can save the document (3.188336ms)
✔ reparse: typed emphasis becomes a mark, "- " after a break becomes an item (1.888889ms)
✔ a trailing hard break stays on screen and is written as nothing (0.579502ms)
✔ the reparse waits while an IME is composing (0.733059ms)
✔ copied blocks paste with their bytes and seams; a cut and paste gives the body back (3.330433ms)
✔ a forged x-mapa slice is refused, and text from outside is read as Markdown (0.930449ms)
✔ rebuild changes origins only, outside undo history (1.717679ms)
✔ applyBody takes a teammate's block, keeps the caret, and ends untouched (1.380519ms)
✔ a block whose context changed is written again: a task toggled, a bullet, a quote (1.861337ms)
✔ a duplicate ^id typed above its holder never takes the id from it (1.690688ms)
✔ a copy-dragged block is reparsed, and says what its Markdown says (0.968149ms)
✔ a history command that throws is refused, never thrown (2.622791ms)
✔ one rename at a time, from either field (2.001811ms)
✔ an empty or unchanged title sends nothing (0.145752ms)
✔ a refusal keeps what was typed, and the title (0.228787ms)
✔ the pending state holds for the busy rule (8.326935ms)
✔ a failed POST says so and keeps the title (0.474537ms)
✔ Update links posts the confirm page's POST (0.274363ms)
✔ clean is CleanTitle's whitespace rule (0.142697ms)
✔ the saver's base follows a rename made over it, and only that (0.314087ms)
✔ closing sends the rename as one keepalive POST (2.773221ms)
✔ a drag whose anchor the document no longer reaches selects to its end (6.167704ms)
ℹ tests 90
ℹ suites 0
ℹ pass 90
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 5415.954649
=== vet ===
go vet ./...
go vet -tags browser ./internal/mapatest/
=== fmt ===
=== code ===
go tool rastrillo budget code
The base has no .rastrillo/code.txt: skipping the check that records only go down.
budget code: within the limits.
=== test ===
CGO_ENABLED=0 go test ./...
?   	amadan.net/oficina/mapa/cmd/mapa	[no test files]
ok  	amadan.net/oficina/mapa/internal/mapa	(cached)
?   	amadan.net/oficina/mapa/internal/mapa/icons	[no test files]
ok  	amadan.net/oficina/mapa/internal/mapa/markup	(cached)
ok  	amadan.net/oficina/mapa/internal/mapa/seal	(cached)
ok  	amadan.net/oficina/mapa/internal/mapatest	9.699s
?   	amadan.net/oficina/mapa/scripts/mutate	[no test files]
?   	amadan.net/oficina/mapa/scripts/preview	[no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
=== credits-check ===
python3 scripts/credits.py --check
credits: checked
diff --git a/docs/superpowers/specs/2026-11-17-notion-import.md b/docs/superpowers/specs/2026-11-17-notion-import.md
index c525b74..7fedbe2 100644
--- a/docs/superpowers/specs/2026-11-17-notion-import.md
+++ b/docs/superpowers/specs/2026-11-17-notion-import.md
@@ -1,13 +1,13 @@
# Notion import: pages into Mapa, databases into Fichas later
-**Status:** revision 3, 2026-11-17, for review. Fable reviewed revision 1 (`bb9b30d`, CHANGES REQUIRED: 3 high, 12 medium, 12 low) and revision 2 (`fda6c12`, CHANGES REQUIRED: no high, 4 medium, 11 low). §24 records what each changed. **Paul approved the import on 2026-11-17**, with his 2026-11-14 defaults (§1) and one overrule: images come in as real Mapa images. Everything marked **Proposed** in this spec is the author's recommendation and has not been ruled. Nothing is built.
+**Status:** revision 4, 2026-11-17, for review. Fable reviewed revision 1 (`bb9b30d`, CHANGES REQUIRED: 3 high, 12 medium, 12 low) and revision 2 (`fda6c12`, CHANGES REQUIRED: no high, 4 medium, 11 low), then diff-checked revision 3 (`68eec68`, CHANGES REQUIRED: 2 medium, 8 low). §24 records what each changed. **Paul approved the import on 2026-11-17**, with his 2026-11-14 defaults (§1) and one overrule: images come in as real Mapa images. Everything marked **Proposed** in this spec is the author's recommendation and has not been ruled. Nothing is built.
**Branch:** `design/notion-import` (Mapa).
**Base specs, which still bind:**
- Mapa `2026-11-12-mapa-design.md` (approved): §3 model and the shared namespace, §4 the seal boundary, §5 history, §6 index, gate 8.
- Mapa `2026-11-14-mapa-level-up.md` (approved): §6.3 the editor's subset, §6.4 fidelity.
-- Mapa images, `2026-11-17-mapa-images.md` on `design/images`, revision 2 (`c27a292`, for review). §12 uses its §7 hook. Revisions 1 and 2 of this spec stated assumptions in its place, before it existed.
+- Mapa images, `2026-11-17-mapa-images.md` on `design/images`, revision 4 (`3af0d79`, for review). §12 uses its §3.2 attach rule and its §7 hook. Revisions 1 and 2 of this spec stated assumptions in its place, before it existed.
- memoria `2026-09-05-notion-ingest-design.md`: its connector is the code this import lifts (§3) and retires (§16).
- Fichas `2026-09-19-fichas-design.md` and the type-designer draft on `design/type-designer`: only for §17's sketch.
- Suite doctrine revision 11 (`91affa1`, as Mapa consumes it): S1–S3, for §16.
@@ -207,7 +207,7 @@ A run is started by an importer's `POST`, mounted inside the session and CSRF gr
- **Stop** is a button while a run is active. In one write it sets the run `stopped` **and rotates its lease**, then cancels the context. So Stop takes effect at once even if the goroutine ignores its context: the goroutine's next write is refused. `stopped` offers Resume like `interrupted`.
- **Disconnect, Finish and Forget are refused while a run is active.** Their pages say "Stop the run first", and Stop always works, so a stuck run never blocks them.
- **Disconnect, or replacing the token, ends any resumable run.** The run becomes `failed` with `disconnected`, its staged trees are cleared, and the next run is a Start. A Resume never runs on a token other than the one its survey used.
-- **One workspace per map.** The connection keeps the workspace id `GET /v1/users/me` returns, sealed. A token for a different workspace is refused while a map exists: "This import came from another Notion workspace. Forget the import first."
+- **One workspace per map.** The connection keeps the workspace's identity, sealed: the workspace id from `GET /v1/users/me` if a bot token's response carries one (**unverified**: §19 step 5 checks the recording), otherwise its workspace name. A token for a different workspace is refused while a map exists: "This import came from another Notion workspace. Forget the import first."
- **Resume, Start over and Start.** After `interrupted` or `stopped`, the page offers **Resume**, which continues the same run with its staged trees, and **Start over**, which clears them and begins a new survey (for staged trees that are old, or a workspace that has changed since). Start is offered after `done` or `failed`; a failed run's staged trees are cleared when the next run starts. Staged trees of a run nobody resumes are deleted with the token under §6's 90-day idle retention.
- **Resuming a survey** walks the pages already surveyed *in this run* from their staged trees, with no requests, and asks Notion only for the rest. This is cheaper than memoria's resume, which repeated the whole traversal.
- **Resuming a write** continues from the rows still `staged`. Each page's write is one transaction that also writes its map row (§14.1), so a page and its record in the map land together or not at all. A crash between two pages can never make a second copy on Resume.
@@ -409,15 +409,15 @@ Mapa has **no escapes** (level-up D11). The editor accepts that because a person
| a block start at the beginning of any line of a block: a fence (```` ``` ````, `~~~` after any spaces), a heading (`# `), a list item (`- `, `* `, `+ `, `1. `, `1) `), a quote (`>`), a rule (`---`, `***`, `___`) | every line, the first and every hard-break continuation | U+200B before the line's first non-space character. The line looks the same and stays inside its block |
| `[[` or `![[` | the written line, **across run boundaries** (`[[Acme` in a bold run then `]]` in the next is caught) | U+200B between the two `[` |
| a literal `!` or `[` immediately before a generated link (`[[…]]`, a date link, `[text](url)`, and the images spec's `![alt](/i/…)` once built) | the seam between them | U+200B between the literal character and the generated `[` |
-| a literal `[label](http…)` or `![alt](/i/…)`, which would become a web link or, once the images spec is built, an image | the written line | U+200B between `]` and `(` |
-| a to-do's box: a bullet whose literal text starts `[ ] `, `[x] ` or `[X] ` | a bullet list item's text | U+200B before the `[`. (A real to-do is generated as one, and its box is part of "meant") |
+| a literal `[label](address)` for any address `markup.SafeURL` accepts (`http`, `https`, `mailto`), or `![alt](/i/…)`, which would become a web link or, once the images spec is built, an image | the written line | U+200B between `]` and `(` |
+| a to-do's box: any list item, bulleted or numbered, whose literal text starts `[ ]`, `[x]` or `[X]` then a space or a tab (`render.go`'s `taskBox`) | every list item's text | U+200B before the `[`. (A real to-do is generated as one, and its box is part of "meant") |
| a trailing ` ^word` (a block marker) | the block's last line | U+200B before the `^` |
-
-**The images spec revisits this table** once its image span exists in `markup`: the rows naming `![alt](/i/…)` are written against its §2.1 and get fixtures in that build.
| a backtick | any literal text | U+02CB MODIFIER LETTER GRAVE ACCENT (ˋ), which looks like one. A code-annotated run is the only source of real code spans |
| a bare `http(s)://` | — | left alone: Mapa links it, and Notion usually had |
| `*` | — | left alone. A literal `*a*` becomes emphasis, as in the editor (D11). A marked run holding `*` loses its mark (§11.1) |
+**The images spec revisits this table** once its image span exists in `markup`: the rows naming `![alt](/i/…)` are written against its §2.1 and get fixtures in that build.
+
**Headings with line breaks.** A Mapa heading is one line. The mapper joins a heading's lines with a space.
**The fallback.** A block whose written form still fails the check, which means the mapper has a bug, is not dropped and does not fail the page. It is written as a placeholder line, `> From Notion: this block couldn't be copied exactly. Its text follows.`, then a fence holding the block's plain text. The fence is ```` ``` ````, or `~~~` if a line of the text starts with ```` ``` ````; a line starting with the chosen fence gets U+200B first, so the fence always closes. The report counts these, and I1 fails on any fixture that produces one. **A page fails with `render_failed` only if the fallback itself fails the check.**
@@ -426,13 +426,13 @@ Mapa has **no escapes** (level-up D11). The editor accepts that because a person
**P9: Notion-hosted images become real Mapa images.**
-**This section follows the images spec**, `2026-11-17-mapa-images.md` on `design/images`, at revision 2 (`c27a292`, for review, not yet approved). Its §7 is the hook this import uses. Revisions 1 and 2 of this spec stated assumptions (A1–A11) before that spec existed. Each is now answered from it, and where it differs, this spec follows it. If the images spec changes before approval, this section changes with it.
+**This section follows the images spec**, `2026-11-17-mapa-images.md` on `design/images`, at revision 4 (`3af0d79`, for review, not yet approved). Its §7 is the hook this import uses. Revisions 1 and 2 of this spec stated assumptions (A1–A11) before that spec existed. Each is now answered from it, and where it differs, this spec follows it. If the images spec changes before approval, this section changes with it.
**What the images spec gives** (its section in brackets):
- **`Store.AddImage(ctx, actor, data)`** reads, checks and strips one image, seals it, stores it in CARLOS's bucket as ciphertext, and records it as a **pending** image owned by `actor`, logging `uploaded` (object kind `image`) by that person (§7, §3.2). It is its own write, before and outside the page's transaction. It waits for the blob semaphore rather than failing (§1.4).
- **`Store.CopyImage(ctx, actor, publicID)`** makes a new pending image from one the actor may read, with a new object (§3.2, §7).
- **`Image.Markdown(alt)`** gives `![alt](/i/<public id>)`, with alt cleaned: no `[`, `]` or line break, at most 1,000 bytes (§2.1). That form is in Mapa's subset once the images spec is built, parsed by `markup` and by the editor's port, with its own fidelity gates (§2.3).
-- **A commit attaches** each pending image that the new body introduces and the committer owns (§3.2). Every write that goes through `tx.commit` does this, so `ImportCreate` and `ImportUpdate` attach the run's images without any import code of their own.
+- **A commit attaches, when asked to.** Attaching is an explicit argument to `tx.commit`, passed only by a closed list of verbs that carry the person's own text (§3.2); every other caller attaches nothing. Then it attaches each pending image the new body introduces, that the committer owns, inside its seven-day window. **`ImportCreate`, and `ImportUpdate`'s `edited` revision, pass attach; its `renamed` revision passes nothing**, since it holds the previous body. The images spec's §3.2 list and its §7 (which says the importer commits "through the ordinary verbs") must name these two methods; that is an amendment to the images spec, raised with it. I14 goes red when the argument is dropped.
- **One image, one place.** An image belongs to one page; on any other page it renders as "Image not available" (§3.1). A file that appears on two pages is added once and copied for the second (§7).
- **Checks:** at most 10 MiB, 50 megapixels, and 10,000 px a side; the type is sniffed from the bytes (§3.4, §5). Refusals are typed: `ErrImageType`, `ErrImageTooLarge`, `ErrImageDimensions`, `ErrImageQuota`, `ErrNoImageStore` (§7).
- **Quota:** images on team pages count against the team's allowance, `MAPA_IMAGE_QUOTA_TEAM`, 10 GiB by default, checked at `AddImage` and `CopyImage`, never at commit (§3.4).
@@ -442,9 +442,11 @@ Mapa has **no escapes** (level-up D11). The editor accepts that because a person
**What the import does:**
- **When:** during Write, **before** the page's transaction, for each image block that is new to this page or whose `last_edited_time` changed since its last import. Notion's file URLs are signed and expire after about an hour, and Survey may finish long after it read the block. So Write fetches the block again (`GET /v1/blocks/{id}`) for a fresh URL, downloads it through the file transport (§5), and hands the bytes to `AddImage` as the run's person. No network call and no `AddImage` happens inside a page transaction.
- **Then** `ImportCreate` or `ImportUpdate` writes the body holding `image.Markdown(caption)` (the Notion caption as plain text; empty when there is none) and its commit attaches the image.
-- **Reuse.** `notion_images` maps (Notion block, Mapa page) to the Mapa image's public id, sealed. An unchanged block on the same page reuses it, after the run checks, in its own read, that the image row still exists and is attached to that page; one the sweep or a member's "Remove from Mapa" took away is fetched again. **A block that moves to another page**, or a synced block that shows one Notion file on several pages, gets `CopyImage` from the existing Mapa image where the runner may read it, and a fresh download otherwise.
-- **A failure is not the page's failure.** A refused or failed image becomes the images spec's text line, `(Image not imported: <caption or "an image">, <reason>)`, in its place, and the page is written. The report counts images by reason. **A permanent refusal** (type, size, dimensions, host not allowed) is recorded on its `notion_images` row with the block's edit time and is not downloaded again until the block changes. **A transient one** (network, 429, 5xx, an expired URL) is tried again on the next run.
-- **Quota.** Notion's block objects carry no file size, so the run cannot total the images before it starts. Instead, the Start page shows the team's remaining image allowance. On the first `ErrImageQuota` the run stops downloading for the rest of that run: every later image becomes the text line, with "the team's image allowance is full", and the report says so at the top. Raising the allowance and running again fills them in, because those pages render differently and are still untouched (§13.2). `ErrNoImageStore` does the same from the first image: "images aren't set up on this Mapa yet".
+- **Commit as it goes** (images §7). Images are downloaded and added only for the page about to be written, and that page is committed before the next page's images are added. So pending images never pile up against the runner's own allowance. **If the page's write returns *kept* or fails, the run deletes that page's pending images at once**, through the images spec's removal (one transaction, `removed`, the runner as actor, §3.2 item 3's shape), so nothing holds quota for seven days.
+- **The lease is checked just before each `AddImage` and `CopyImage`.** Those are their own writes, outside the page transaction. The one gap left: a lease that moves between the check and the call lets one pending image be added by a run that no longer holds it. It is never attached, and the sweep removes it after seven days. That is the named exception to §8.3's "changes nothing".
+- **Reuse.** `notion_images` maps (Notion block, Mapa page) to the Mapa image's public id, sealed. An unchanged block on the same page reuses it, after the run checks, in its own read, that the image row still exists and is attached to that page; one the sweep or a member's "Remove from Mapa" took away is fetched again. **A block that moves to another page**, or a synced block that shows one Notion file on several pages, is found by its block alone (`block_print`, §15), and gets `CopyImage` from the existing Mapa image where the runner may read it, and a fresh download otherwise.
+- **A failure is not the page's failure.** A refused or failed image becomes the images spec's text line, `(Image not imported: <file name>, <reason>)`, the file name taken from the last segment of Notion's file URL path, decoded (or the caption when the path has none),, in its place, and the page is written. The report counts images by reason. **A permanent refusal** (type, size, dimensions, host not allowed) is recorded on its `notion_images` row with the block's edit time and is not downloaded again until the block changes. **A transient one** (network, 429, 5xx, an expired URL) is tried again on the next run.
+- **Quota.** Notion's block objects carry no file size, so the run cannot total the images before it starts. Instead, the Start page shows **both** allowances the images spec checks: the team's (`MAPA_IMAGE_QUOTA_TEAM`) and the runner's own (`MAPA_IMAGE_QUOTA_PERSON`, which counts their pending and private images). `ErrImageQuota` can come from either. On the first one, the run reads both figures to say which, and stops downloading for the rest of that run: every later image becomes the text line, and the report says at the top which allowance is full. Raising that allowance, or freeing the runner's own, and running again fills them in, because those pages render differently and are still untouched (§13.2). `ErrNoImageStore` does the same from the first image: "images aren't set up on this Mapa yet".
- **External images** stay links (D13). The images spec leaves fetching them to this spec (its §7), and this spec does not propose it. **Q2** asks Paul.
- **Literal image syntax.** Notion text that happens to read `![…](/i/…)` would become an image reference once the images spec is built. §11.4 neutralises it.
@@ -461,20 +463,20 @@ For each mapped page on a re-run:
| Mapa page | Notion page | What happens |
|---|---|---|
| revision is still the one the import wrote | rendered body and title equal what Mapa holds | nothing. No revision, no event |
-| revision is still the one the import wrote | changed | **updated** by `ImportUpdate` (§14.1): body and title in one revision, as the person running this run |
+| revision is still the one the import wrote | changed | **updated** by `ImportUpdate` (§14.1), in one transaction, as the person running this run: a `renamed` revision if the title changed, then an `edited` revision if the body did |
| any later revision | anything | **kept**. Mapa's version stays whole. Listed in the report |
| deleted in Mapa | anything | **not re-created.** Deleting it was a decision in the app of record. Listed |
| restored as a new page | anything | the map still names the old, deleted page, so it is "deleted in Mapa". The restored page is an ordinary Mapa page |
- **"Changed" is decided by the rendered output**, not by Notion's edit time. Survey reads every block anyway (§8.1), so rendering again costs no requests. That makes a title change in a mentioned page, a page newly shared, a move, or a mapper fix all reach the pages they affect, which an edit-time comparison would miss (memoria §1.1: an ancestor's rename never moved a child's edit time).
- **Any later revision means edited**, a rename and "Update links" included. A rename leaves the body alone, but the person chose the page's Mapa name, and an import that renamed it back would undo a choice.
-- **The check and the write are one transaction.** `ImportUpdate` reads the page's revision and `gone` inside its own `Store.write` and, if either has moved since the decision, writes nothing and records the page as kept. It never merges. Mapa's ordinary commit would merge Notion's change into a teammate's save that landed in between (`commit.go`, `merged`), which this table rejects.
-- **A teammate's open draft does not stop an update.** Their draft's base is the import's revision, and their next commit merges against the update by base §5's block merge, as it would against a teammate's save. The import never touches drafts.
+- **The check and the write are one transaction.** `ImportUpdate` reads the page's revision and `gone` inside its own `Store.write` and, if either has moved since the decision, returns *kept* and rolls back; a lease-checked bookkeeping write then records it (§14.1). It never merges. Mapa's ordinary commit would merge Notion's change into a teammate's save that landed in between (`commit.go`, `merged`), which this table rejects.
+- **A teammate's open draft does not stop an update.** Their draft's base is the import's revision, and their next commit merges against the update by base §5's block merge, as it would against a teammate's save. The import moves no draft except as a rename does: `carryDrafts` moves drafts on the old revision onto the `renamed` revision, which holds the same body (§14.1).
- **Rejected: merging Notion's change into Mapa's edit.** Mapa has the three-way merge. But P6 says Mapa's version is kept where edited, and a merge that happens unseen in a run is a write nobody chose (base §5: "Nothing is committed that nobody chose").
### 13.3 Renames
-A Notion rename on an untouched page is part of `ImportUpdate`'s one revision, using the same namespace code the rename verb uses: the old title becomes an alias, so every link typed with it still resolves (base §3.4). The new title goes through §9.2's fitting and collision rules. Pages that link to it are re-rendered, and their links use the new title where those pages are untouched.
+A Notion rename on an untouched page is `ImportUpdate`'s `renamed` revision, using the same namespace code the rename verb uses: the old title becomes an alias, so every link typed with it still resolves (base §3.4). The new title goes through §9.2's fitting and collision rules. Pages that link to it are re-rendered, and their links use the new title where those pages are untouched.
### 13.4 Absence
@@ -505,10 +507,10 @@ The import writes pages only through two methods in package `mapa`, each **one `
### 14.2 What history records
-- **Every import write is a Mapa write** in one transaction with its event (gate 8). The verbs are Mapa's existing ones: `created`, `edited`, `renamed`. The actor is the person who pressed Start or Resume (P7). **Mapa is never an actor** (base §2).
+- **Every import write is a Mapa write** in one transaction with its event (gate 8). The verbs are Mapa's existing ones: `created`, `edited`, `renamed`, and the images spec's `uploaded` and `removed` (object kind `image`) for the run's images. The actor is the person who pressed Start or Resume (P7). **Mapa is never an actor** (base §2).
- **No new verb.** An `imported` verb would add nothing the sealed record does not say. It would also not hide much: see §15 on what the plaintext already shows.
- **Bookkeeping is a third named exemption from gate 8**, beside drafts and retention (base §5): run rows, heartbeats, progress, staging, clearing staged trees, and ledger state that changes no page. A page write is never bookkeeping. **The person's own acts on the connection do log events**, under a new object kind, `import`, naming the person: `connected`, `token_replaced`, `disconnected`, `finished`, `forgotten`, `started`, `stopped`. `resumed` and `started_over` too. These are routes a person posts to, so gate 8's route test (`gate8_test.go`) covers them like every other. S1 and the index ignore object kind `import`. §21 records the exemption and the object kind as amendments to base §3.1 and §5.
-- **Bookkeeping touches only `notion_*` tables, and only from the run.** It goes through one function whose transaction may name no other model; its writes are lease-checked (§8.3), so a run still going after Start's request has returned writes only while it holds its lease. **I19 fences the exemption:** a Survey-only run changes no row outside `notion_*`, and the bookkeeping function, mutated to touch `pages`, `revisions`, `aliases`, `title_prints` or `images`, goes red.
+- **Bookkeeping touches only `notion_*` tables.** It goes through one function whose transaction may name no other model. Its callers are the run, whose writes are lease-checked (§8.3), so a run still going after Start's request has returned writes only while it holds its lease; boot's `interrupted` transition; Stop, Disconnect, token replacement, Finish and Forget, which log their own `import` events beside it; and retention's 90-day idle delete, already exempt by name. **I19 fences the exemption:** a Survey-only run changes no row outside `notion_*`, and the bookkeeping function, mutated to touch `pages`, `revisions`, `aliases`, `title_prints` or `images`, goes red.
- **The sealed record gains two optional fields** (base §3.1's `Record`, JSON, additive):
- `origin`: `{source: "notion", created, edited}`, Notion's own created and last-edited times for the page. Set by the import, and carried forward by every later commit, so a page always knows where it came from, even after its imported revision ages out of the 90-day window. Every verb already opens the record, changes it and seals it again (`CommitFrom`, `Retitle`, `Revert`, `Restore`, relink, markers), so carrying `origin` needs nothing. A page restored from a deleted imported page keeps `origin`: its text did come from Notion. The map does not follow it (§13.2).
- `imported`: `true` on a revision the import wrote. **`tx.commit` clears it on every write unless the caller is `ImportCreate` or `ImportUpdate`.** The verbs carry the whole record forward by default, so without that one line a teammate's edit would read "imported from Notion". Gate I18 runs every verb on an imported page and checks it is cleared and `origin` kept.
@@ -529,7 +531,7 @@ The import writes pages only through two methods in package `mapa`, each **one `
| `notion_connections` (one row) | `id`, `created_by` (member id), `created_at`, `verified_at` | token, workspace name | that a Notion connection exists, who made it, when it was last checked |
| `notion_runs` | `id`, `actor`, `state`, `lease` (random, redrawn on start, resume and Stop), `started_at`, `heartbeat_at`, `progress_at`, `finished_at`, the counters, `error_code` | — | when imports ran, who ran them, how many pages each created, kept, failed. The lease is random and says nothing |
| `notion_pages` (the map) | `id`, `notion_print` (unique), `state`, `error_code`, `surveyed_run`, `seen_run` | the coordinate record (Notion id, last Notion title, Mapa page id, last written revision, unresolved mention ids, placeholder ids); the staged tree | how many Notion pages exist and their states |
-| `notion_images` | `id`, `block_print` (unique: an HMAC of the Notion block id and the Mapa page id together), `state` (`imported`, `refused`, `failed`) | the image record (block id, block edit time, Mapa page id, public id, refusal reason) | how many images were imported, refused and failed. The images spec's own `images` table holds the rest (§12) |
+| `notion_images` | `id`, `place_print` (unique: an HMAC of the Notion block id and the Mapa page id together), `block_print` (an HMAC of the block id alone, not unique, to find a block that moved or is shown on several pages), `state` (`imported`, `refused`, `failed`) | the image record (block id, block edit time, Mapa page id, public id, refusal reason) | how many images were imported, refused and failed, and, through equal `block_print`s, how many Notion images appear on more than one page. The images spec's own `images` table holds the rest (§12) |
- **What the file still shows, said plainly.** The coordinate is sealed, so no column joins a ledger row to a Mapa page. **But the plaintext event log does.** A run's `created` events, by the run's actor, inside the run's window in `notion_runs`, mark which team pages it made, and sequential `pages.id` and `notion_pages.id` in survey order line them up row for row. So the file shows **which team pages came from a Notion import, and roughly their order in Notion**. It does not show their titles, bodies or Notion ids. This goes in the leak list. `notion_pages` carries no `updated_at`, which would be a second join.
- **Prints are HMACs under the instance key**, equality only, as every print in Mapa (base §4).
@@ -631,13 +633,13 @@ The import writes pages only through two methods in package `mapa`, each **one `
- **I11, the token is never rendered**: no 8-character run of it in any response (memoria N14).
- **I12, resuming.** A run left `surveying` becomes `interrupted` at boot and Resume runs. Stop ends a run `stopped` at once, **even when the goroutine ignores its context**, and that goroutine's next write of any kind, bookkeeping included, is refused. A reclaimed goroutine writes nothing after the lease moves. Disconnect, Finish and Forget are refused during a run and work after Stop. Disconnect and a replaced token end a resumable run; a token for another workspace is refused while a map exists; Start over clears staged trees. A run with a live ticker and no progress for ten minutes is reclaimable. A resumed survey makes no request for a page already surveyed in that run. A resumed write writes no page twice.
- **I13, who sees Import.** With `MAPA_IMPORTERS` unset every import route 404s for everyone. With it set, a member not named gets 404 on every route, `GET` and `POST`. Nothing outside Import changes for them.
-- **I14, images.** A Notion-hosted image becomes a Mapa image through `AddImage` and is attached by the page's commit; an external one stays a link; an unchanged image block on the same page is not downloaded again, and one the sweep removed is; a block on a second page is copied; a refusal leaves the text line and a written page, and a permanent one is not downloaded again; the first `ErrImageQuota` stops downloads for the run. *Built with the images spec (§12).*
+- **I14, images.** A Notion-hosted image becomes a Mapa image through `AddImage` and is attached by the page's commit; an external one stays a link; an unchanged image block on the same page is not downloaded again, and one the sweep removed is; a block on a second page is copied; a refusal leaves the text line and a written page, and a permanent one is not downloaded again; the first `ErrImageQuota` stops downloads for the run and names which allowance; a *kept* page's pending images are removed at once; and dropping the attach argument from `ImportCreate` or `ImportUpdate` turns I14 red. *Built with the images spec (§12).*
- **I15, scriptless.** `make browser` connects, starts, watches the meta refresh, resumes and finishes with JavaScript off, then on.
- **I16, the import never asks to write.** Using a client from `notiontest` built, through the module's shared internal package, without M4's method pin (no build tag in production code), a whole run against the fake records every request: only `GET`s and `POST /v1/search`. With the pin in place the fake would never see a write, so this is the version that can go red for the callers.
- **I17, crash safety** (§14.1). Killed between every pair of statements in `ImportCreate`, `ImportUpdate` and the run loop, then resumed: no second page, no false *kept*, the map agrees with the pages. And a reclaimed run's goroutine writes no page after the lease moves (§8.3). Nothing but the run calls the two methods.
- **I18, provenance.** Every verb on an imported page (commit, rename, revert, restore, relink, mark) clears `imported` and keeps `origin`.
- **I19, the bookkeeping exemption is fenced** (§14.2). A Survey-only run changes no row outside `notion_*`. *Mutation: let the bookkeeping function touch `pages`, `revisions`, `aliases`, `title_prints` or `images`, one at a time.*
-- **I1's literal-text fixtures** include each seam row of §11.4: a literal `!` before a mention, a literal `[` before a generated link with a later `]]`, a literal `[label](https://…)`, and a bullet whose text starts `[ ] `.
+- **I1's literal-text fixtures** include each seam row of §11.4: a literal `!` before a mention, a literal `[` before a generated link with a later `]]`, a literal `[label](https://…)` and `[label](mailto:…)`, and a bulleted and a numbered item whose text starts `[ ]` then a tab.
**And the run is looked at in a browser**, at 0%, mid-survey, mid-write, interrupted and finished, before the build is called done. A template test proves markup exists, not that a run reads sensibly at 40% (memoria §13).
@@ -650,7 +652,7 @@ Against Paul's workspace. **Read-only on Notion's side**, owned by Paul, and a s
2. He shares a small set of top-level pages with it, a few hundred pages at most for the first run, not the workspace root.
3. `cmd/notion-record` records that set, from Paul's machine, into a directory outside every repository. Scrub it, commit the scrubbed fixtures to the module, delete the raw recording. Compare its block types with §10.1: any type not in the table is added to the table before the run.
4. Check the image file URLs in the recording against the file transport's (host, path prefix) pairs. Fix the allowlist from what Notion actually sends, not from the documentation's one example.
-5. Check that user mentions carry names (§11.2), and what a synced block's copy returns for its children (§10.1).
+5. Check that user mentions carry names (§11.2), what a synced block's copy returns for its children (§10.1), and whether `GET /v1/users/me` carries a workspace id (§8.3).
**The run, on the `test` team first** (`test.mapa.oficina.works`, disposable)
6. Connect, run, and watch the status page through to the end.
@@ -773,3 +775,20 @@ No high findings. Fable said a revision fixing N1–N4 as described needs only a
| **N14** Title-only update left drafts behind | `carryDrafts` on the rename revision | §14.1 |
| **N15** Build step 3 omitted I17, I18 | Listed, with I19 | §22 |
| *(not a finding)* The images spec landed (`c27a292`) | §12 rewritten against its §7 hook; A1–A11 replaced by what it says; `notion_images` keyed by block and page; quota and `ErrNoImageStore` handling | §12, §15, I14 |
+
+### Diff check: Fable (`claude-fable-5-2`) on revision 3 (`68eec68`): CHANGES REQUIRED, answered in revision 4
+
+N1–N15 confirmed answered, checked against `verbs.go`, `store.go` and `spans.go`. The new findings came mostly from the images spec moving to revisions 3 and 4 while this one pinned revision 2.
+
+| Finding | Change | Where |
+|---|---|---|
+| **D1 (M)** Attaching is now an explicit `tx.commit` argument for a closed list of verbs; imported images would stay pending | Re-pinned to images revision 4 (`3af0d79`); `ImportCreate` and `ImportUpdate`'s `edited` revision pass attach, the `renamed` one does not; the images spec's §3.2 and §7 must name the two methods (raised as an amendment to it); I14 goes red without the argument | §12, I14 |
+| **D2 (M)** §13.2 and §13.3 still described one revision, no drafts touched, and writing nothing inside the transaction | Aligned with §14.1 | §13.2, §13.3 |
+| **D3 (L)** `ErrImageQuota` also fires on the runner's own allowance; pending images of kept or failed pages hold quota | Both allowances shown and named; commit as it goes; a kept or failed page's pending images removed at once | §12 |
+| **D4 (L)** Refusal line wording | The images spec's: file name, from the URL path | §12 |
+| **D5 (L)** `AddImage` and `CopyImage` are run writes outside the lease | Lease checked just before each; the one-image gap named; `uploaded` and `removed` in §14.2 | §12, §14.2 |
+| **D6 (L)** A paragraph split the §11.4 table | Moved below it | §11.4 |
+| **D7 (L)** Rows narrower than `SafeURL` and `taskBox` | Any address `SafeURL` accepts; any list item, space or tab; fixtures | §11.4, I1 |
+| **D8 (L)** A moved block could not be found by a (block, page) print | `block_print` by block alone, beside `place_print`; leak line | §15, §12 |
+| **D9 (L)** Bookkeeping is not only from the run | Its callers listed | §14.2 |
+| **D10 (L)** Workspace id from `/v1/users/me` unverified | Marked, with a fallback to the name; §19 step 5 checks | §8.3, §19 |