From 4edd2014a405fb5298ea2f45b5683c8dc9b97b74 Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Tue, 10 Nov 2026 20:03:05 -0600 Subject: [PATCH] docs(id): design: Notion importer for the knowledge layer (#6436) --- doc/2026-11-10_design_id6436.md | 238 ++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 doc/2026-11-10_design_id6436.md diff --git a/doc/2026-11-10_design_id6436.md b/doc/2026-11-10_design_id6436.md new file mode 100644 index 0000000000..f545fa79cd --- /dev/null +++ b/doc/2026-11-10_design_id6436.md @@ -0,0 +1,238 @@ +# Design: importer design — Notion into the #2048 object model + +- Date: 2026-11-10 +- Status: **decision-ready proposal** — design only; no importer code is implemented here. +- Issue: [#6436](https://github.com/developing-today/code/issues/6436), parent programme [#5678](https://github.com/developing-today/code/issues/5678), programme epic [#2056](https://github.com/developing-today/code/issues/2056). +- Object model: [#2048](https://github.com/developing-today/code/issues/2048) as landed in `doc/2026-11-01_design_id2048.md`: stable logical notes (`note.create` = stable note ID), signed immutable revisions (`note.revise` naming parents and a content blob), structured typed references (target note ID, sigil/type, authored surface, optional pinned revision), tags as signed observed-remove claims, names/aliases as claims, tombstone removal, group `Read`/`Write` as the authority model. This design **consumes** those decisions; it does not re-decide them. +- Sibling importer designs: [#5848](https://github.com/developing-today/code/issues/5848) (Joplin) at `doc/2026-11-08_design_id5848.md` and [#5847](https://github.com/developing-today/code/issues/5847) (Logseq) at `doc/2026-11-08_design_id5847.md`. This design follows their shape deliberately — same manifest contract, same invariant set, same corpus discipline — so the importer family stays one design with per-source deltas. Where Notion forces a different answer, the difference is stated as a delta (§0). +- Read-authority constraint (ruled on #6436; do not re-litigate): ID knowledge defaults to public read; owners may grant read to any number of groups and/or users; resolution order is **object → user default → server config → public**. §7 states how this design complies and how imported Notion access metadata is handled. + +## Decision to make + +How does a Notion workspace — pages made of typed blocks, databases whose rows are pages with typed properties, relations and rollups between databases, comments, and files — enter the #2048 object model such that (a) the imported material uses the model's stable identity, typed references and claims rather than a file dump beside it, (b) a repeat import of the same workspace is safe and recognises what is already there, and (c) nothing about Notion's own sharing model silently becomes an ID read path? + +## Recommendation + +**Import is a mapping into the object model, recorded in a persisted import manifest, acquired hybrid (export for content fidelity, API for inventory and identity), and it is one-shot plus idempotent re-import — never a sync emulation.** The shape is the Joplin/Logseq record's; the Notion deltas are these: + +1. **Pages → logical notes; blocks are content, not notes.** Each Notion page becomes one logical note (`note.create`, initial revision blob = the page's block tree rendered to the model's content form after reference rewriting, §3). A **block is not a note**: blocks are structure *inside* a note's revision content, carried as an explicit block tree with stable block identities in the manifest — the Logseq rule (§2.1 of #5847), adopted unchanged. Notion pages nest (child pages), but a child page is a full page with its own URL and permissions, so a child page **is** its own note, linked to its parent by a typed reference — nesting of *pages* is graph structure, nesting of *blocks* is content (§2.1). +2. **Databases are the hard part, and they are claims, not a new object type.** A Notion database becomes: one note for the database itself (its description page content, if any), one note per row (a row *is* a page), the database's property schema recorded as provenance claims on the database note, and each row's property values recorded as claims on the row note (§2.2). Relations become typed references between row notes; rollups and formulas are **derived values** — imported as recorded provenance claims naming their formula/rollup definition, never as silently-authoritative values (§2.3). No database object type is added to the model. +3. **Stable identity comes from Notion's own IDs.** Every Notion page, database, and block has a UUID. The manifest maps Notion UUID ↔ note ID (and block UUID ↔ (note ID, block identity)), which is what makes re-import idempotent and duplicate detection decidable (§6). An import without a manifest is a failed import — same contract as #5848. +4. **Hybrid acquisition: export is the content source of record; the API is the inventory and identity source.** A workspace export carries content and files the API serves poorly (and file URLs from the API expire); the API carries complete identity, database schemas, relations, and comments that an export flattens or omits. Neither alone is sufficient; §1 states what each path covers and what each loses, and the fidelity report (§6.4) is computed against the API inventory even when content came from the export. +5. **Notion access metadata is reported, never applied.** Who a page was shared with, whether it was published to the web, and workspace membership are recorded as provenance claims and named in the fidelity report. The importer creates **no** grants and **no** alternate read path; every imported object resolves read authority by the ruled order (object → user default → server config → public) exactly like a native object (§7). Applying a source-visibility mapping is a separate, explicit user action outside the importer. +6. **Comments import as claims with provenance, where the API exposes them.** A comment becomes a comment claim on the note (author Notion user ID + display name as recorded provenance, timestamp, body blob), never a revision — comments are discussion *about* the object, not content *of* it. Where the acquisition path cannot supply comments, the loss is named per page in the fidelity report, not silently dropped (§2.4). + +## §0 Deltas against the sibling importer designs (#5848 Joplin, #5847 Logseq) + +| Concern | Joplin / Logseq | Notion (this design) | Why | +| --- | --- | --- | --- | +| Primary content unit | Note / page = the note; blocks are content inside it | Same | Notion pages are the reading and revision unit; blocks are content structure | +| Nesting | Folders / namespaces are claims, not containment | Child pages are separate notes + typed parent reference; block nesting is content | A Notion child page has its own identity, URL and sharing; a nested block does not | +| Identity | Joplin note ID / page name + block UUID | Notion UUID for pages, databases **and** blocks, from the API | Notion's API exposes stable UUIDs for all three; export alone does not reliably | +| Structured data | Joplin: none. Logseq: page/block properties as claims | **Databases**: schema as provenance claims, row values as claims, relations as typed references, rollups/formulas as derived-value provenance claims | Databases are Notion's centre of gravity; neither sibling has an equivalent | +| Source shapes | JEX / Markdown dir; graph directory / EDN | Workspace export (Markdown+CSV or HTML) **plus** API inventory — hybrid required | Export loses relations/comments/schema typing; API loses file permanence and some block fidelity | +| Access metadata | Not modelled by either source | Present (sharing, publish-to-web) and **must not** become ID authority — provenance + report only (§7) | #6436's ruled read-authority order forbids an importer-created read path | +| Lossy list | Plugin markup, E2EE; query blocks, whiteboards | Synced blocks (cross-page), linked-database views, rollups-as-live-values, Notion AI content, template buttons, wikis' verification badges | Notion features with no note-model counterpart | + +Everything else — manifest contract, idempotency, no-silent-drops accounting, no key handling, corpus discipline — is inherited from #5848 unchanged. + +## §1 Source shape (what Notion actually gives an importer) + +Two acquisition paths exist. The design uses both, for different jobs. + +### §1.1 Workspace export (content source of record) + +- **What it is:** a workspace admin triggers export (Markdown & CSV, or HTML, optionally including subpages and files); Notion produces a downloadable archive. Pages arrive as Markdown (databases as CSV plus per-row Markdown in the Markdown flavour), attachments as files beside them, internal links as Notion URLs or relative paths depending on flavour and version. +- **Prerequisites and constraints:** requires a workspace admin/owner to initiate; large workspaces export slowly and the download link expires; export content and options vary by plan edition (see Open Questions — which editions are in scope is Drew's, not this design's). Export is a point-in-time snapshot: no incremental export exists. +- **Coverage:** page content and files well; database *rows* as pages adequately; database *schema typing, relations and rollups* poorly (CSV flattens relations to titles/URLs, rollups and formulas to their last computed display value); comments not at all in the Markdown flavour; page sharing metadata not at all. +- **Fidelity risks the importer must handle:** duplicate page titles produce colliding filenames (identity must never come from filenames — §6); Markdown flavour loses block types with no Markdown form (toggles survive as text structure, columns/callouts/equations degrade); link forms vary, so link rewriting (§3) must accept both Notion URLs and relative export paths. + +### §1.2 Notion API (inventory, identity, schema, comments) + +- **What it is:** an integration (internal, per-workspace) with a bearer token calls the public API: search, page and database retrieval, block-children traversal, comments, users. The integration sees **only** pages/databases explicitly shared with it — inventory completeness is bounded by what was shared, and the import's inventory step must state the share set it could see. +- **Prerequisites and constraints:** a workspace admin creates the integration and shares each top-level page/database with it; the token is a credential — §6.5 governs its handling. The API is rate-limited (on the order of 3 requests/second per integration) and paginated; a large workspace inventory is a long, resumable crawl, not a single call. API responses are versioned by a `Notion-Version` header; the importer pins one version per import and records it in the manifest. +- **Coverage:** stable UUIDs for every page, database and block; full database schemas (property types, select options, relation targets, rollup/formula definitions); block trees with types the export flattens; comments (for integrations with comment capabilities, on pages/blocks shared with it); user directory for author provenance. +- **Coverage gaps:** file blocks carry **expiring** signed URLs — files must be fetched during the import run, never referenced (§4); some block types are API-invisible or read-only representations of richer editor state (synced blocks resolve to their source block's children only at the source); page *sharing* detail (who can read) is not exposed — the API cannot tell the importer who a page was shared with, which is one reason §7 maps access metadata from export/admin observation only where available and otherwise reports it as unknown. + +### §1.3 The hybrid rule + +Inventory and identity always come from the API crawl (UUIDs, schemas, relations, comments). Content comes from the export when an export of the same workspace is supplied, matched to inventory by UUID where the export flavour carries it and otherwise by the manifest's recorded title+path matching with every uncertain match named in the fidelity report; where no export is supplied, content comes from the API block crawl and the report names the export-only losses (chiefly file permanence risk already handled by §4, and any block types the API represents more lossily). An import that cannot reach the API at all (export-only) is a **degraded mode**: identity falls back to content-hash + path keys in the manifest, re-import idempotency weakens to hash equality, and the fidelity report must headline the degradation — the Logseq Markdown-only rule, restated for Notion. + +## §2 Entity mapping + +### §2.1 Pages and blocks + +| Notion item | #2048 mapping | Notes | +| --- | --- | --- | +| Page | Logical note (`note.create` + initial revision) | Body blob = block tree (§2.1, blocks) after §3/§4 rewriting. Page title → name/alias claim (names are claims, never identity, per #2048). Notion page UUID → manifest identity (§6). | +| Child page (page block inside a page) | Its own logical note + typed reference from the parent note | A child page has its own UUID, URL and sharing; it is graph structure, not content. The parent's revision records the reference at the block position where the child page sits. | +| Block (paragraph, headings, lists, to-do, toggle, quote, callout, code, divider, table block, embed, …) | Structure **inside** the note's revision content, with a stable block identity recorded in the manifest | Not a note (Recommendation 1). The block tree is stored with the revision so export can rebuild it. Block types with no model content form degrade per §2.5's table, and every degradation is counted in the fidelity report. | +| Block children (nested blocks) | Nested content under their parent block identity | Nesting is content structure; depth is preserved as-is. | +| Page icon / cover | Provenance claims on the note; cover file → blob (§4) | Icons that are emoji are a claim value; icons/covers that are files are blobs. | +| Page created/edited timestamps, created-by / last-edited-by | Provenance claims on the note | Recorded as source facts (Notion user ID + display name), never as ID authorship — the importer authors the ID events, and the manifest says so. | +| Archived / in-trash page | Excluded by default; included only by explicit import option, mapped to a note carrying a source-archived provenance claim | Importing trash silently would resurrect content its owner deleted in the source; the option exists because trash is also where accidental deletions live. The fidelity report names which mode ran. | + +### §2.2 Databases and properties + +| Notion item | #2048 mapping | Notes | +| --- | --- | --- | +| Database | One logical note (body = the database page's own content blocks, if any) + schema provenance claims | The schema (property names, types, select/multi-select options, relation targets, rollup and formula definitions) is recorded verbatim as provenance claims on the database note, so a reader can reconstruct what the database *was* even where values degrade. | +| Database row | Logical note + typed reference to the database note | A row is a page: it has a UUID, a body (its page content), and property values. Row body → revision content exactly like a page; property values → claims (next rows). | +| Linked database (a view of a database elsewhere) | A typed reference to the database note at the block position | A linked database is a *view*, not a copy: importing it as a second database would fork identity. Views/filters/sorts are presentation state and are **not** imported; the loss is named once per linked database in the fidelity report. | +| Property: title | The row note's name/alias claim source | Every database has exactly one title property; it plays the page-title role. | +| Property: rich text, number, checkbox, date, URL, email, phone, status, select, multi-select | Claims on the row note, typed by the schema | Select/status option *definitions* live in the schema claims; values are claim values. Multi-value properties are multi-value claims, not comma-joined strings. | +| Property: people | Claims whose values are recorded Notion user references (ID + display name provenance) | Notion users are **not** ID principals. A people value never creates an ID user, group, or grant (§7); it is a provenance fact about the source. | +| Property: files & media | Blob references as claim values (§4) | The files themselves are blobs; the claim names the blob. | +| Property: relation | **Typed references** between row notes, recorded in the manifest's reference metadata | The model's reference type for a relation is the relation's schema identity (database + property), so the two directions of a two-way relation resolve to the same reference pair and re-import does not duplicate them. | +| Property: rollup, formula | Derived-value provenance claims: computed display value **plus** the verbatim rollup/formula definition and its inputs | The imported value is a snapshot fact ("Notion computed X at import time from definition D"), never a live computation. If a later ID-side mechanism evaluates formulas, it consumes the recorded definition; the importer does not invent one. | +| Property: unique ID, created time, last edited time, created by, last edited by | Provenance claims on the row note | System properties are source facts, handled like page timestamps. | +| Property: button, verification, Notion AI fields | Not imported as values; named in the fidelity report per database | Actions and AI-generated content have no claim form in the model; the schema claim still records that the property existed. | + +### §2.3 Relations are references, and references are the graph + +Relations, page mentions, and inline links to pages are all the same underlying thing in Notion — a pointer to a page — and they map to the model's one mechanism, the typed reference, differing only in reference type and authored surface (schema relation vs. in-content mention vs. link). This uniformity is what keeps the imported graph navigable as a graph (backlinks are the reverse index of the same references, computed, not stored twice) and what §3's rewriting relies on. + +### §2.4 Comments + +| Notion item | #2048 mapping | Notes | +| --- | --- | --- | +| Discussion comment on a page or block | Comment claim on the note (block-anchored comments name the block identity) | Author = Notion user provenance (ID + display name); timestamp and body recorded; replies chain by manifest-recorded parent comment ID. | +| Resolved discussion | Comment claim + resolved provenance fact | Resolution state is a source fact, recorded, not an ID workflow state. | +| Comment attachments | Blobs (§4) named by the comment claim | Same fetch-at-import rule. | +| Comments the acquisition path cannot see | Absent, and counted in the fidelity report per page | Export path: all comments. API path without comment capability: all comments. Never silently partial within a page the importer claims to have covered. | + +### §2.5 Block degradation table (extract — the importer's full table is an implementation artifact, this design fixes its rules) + +Rules: every block type is exactly one of **clean** (a model content form exists), **degraded** (imported with a named, report-counted loss), or **unsupported** (content preserved as a verbatim source blob attached to the note, with a provenance claim, so nothing is *lost* even when it is not *modelled* — unsupported never means dropped). + +| Block type | Class | Form / loss | +| --- | --- | --- | +| Paragraph, headings, lists, to-do, quote, code, divider, bookmark (as link) | Clean | Direct content forms; to-do checked state preserved. | +| Toggle, callout, column list / columns, simple table block, equation (block + inline) | Clean-to-degraded | Structure preserved as content structure; presentation attributes (colour, icon, column widths) recorded as provenance or dropped-and-counted per attribute, named in the report. | +| Image, video, file, audio, PDF | Clean via §4 | Blob + reference at block position; captions preserved. | +| Embed / link preview (external) | Degraded | The URL and a link reference survive; the preview rendering does not. | +| Synced block | Degraded | Content is imported **at the source block's page**; at every other referencing page, a typed reference to (source note, block identity) stands in place of a copy — importing copies would fork one block into many identities. | +| Table of contents, breadcrumb, template button, Notion AI blocks | Unsupported | Verbatim source blob + provenance claim; auto-generated or action content is not modelled. | +| Child database block | Clean via §2.2 | It *is* a database (inline) or a linked-database reference. | +| Unknown / future block type | Unsupported by default | The verbatim-blob rule is the forward-compatibility guarantee: a Notion release can add block types without the importer dropping content. | + +## §3 Internal links + +- **Page links and mentions** (`notion.so//-`, `notion://` forms, export relative paths, and in-text mentions) rewrite to typed references to the target note, using the manifest's UUID → note ID map. A link whose target is outside the import set stays a verbatim external URL **and** is counted in the fidelity report as an externalised link — the importer never rewrites a link to a note it did not import. +- **Block links** (URLs with a `#` fragment) rewrite to a typed reference to the owning note **plus** a block selector in the manifest's reference metadata — the Logseq rule: the revision-pin slot names revisions only and is never used for blocks. +- **Database relations** rewrite per §2.2; a relation value naming a row outside the import set is recorded as a provenance claim with the source row's title/UUID and counted as an externalised relation. +- **Backlinks** are not imported as data: they are the reverse view of the imported references and must be derivable from them. The acceptance checks (§8) include a backlink spot-check precisely because a missed reference rewrite shows up there first. +- Link rewriting happens against the **completed** inventory (two-pass import: inventory and identity first, content second), so forward references to pages imported later in the run resolve. Single-pass rewriting is the known way importer families produce dangling links; it is prohibited by the implementation slicing below. + +## §4 Attachments / resources + +- Every file reachable from an imported page, row property, or comment is fetched **during the import run** and stored as a content blob; the note content/claims reference the blob. API file URLs are signed and expire — the importer must never store the URL as the resource. Export-supplied files are copied from the archive by path, matched to blocks by the manifest. +- A file that cannot be fetched (expired link mid-run, export archive missing the file, size or type refusal by local policy) does not abort the import: the block/claim records a missing-resource provenance fact, the fidelity report names the file, its source page, and the reason, and the import's accounting (§6.4) treats the page as *degraded*, never *clean*. +- Duplicate files (same bytes attached in several places — common with pasted images) are stored once by content hash and referenced from each position; the manifest maps each source file occurrence to the blob. +- File size and count totals are part of the inventory report before content import begins, so a user can see the cost of the import they are starting; imports have no silent size ceiling — a policy ceiling, if the implementation sets one, is a named fidelity-report line when hit, not a truncation. + +## §5 Round-trip export expectations + +Export from ID back to Notion is **not** an importer feature and Notion offers no bulk import API of comparable fidelity; the expectation this design sets is the Joplin one, restated: the manifest plus the recorded schema/provenance claims must be sufficient for a *future* exporter to rebuild a Notion-shaped workspace export (Markdown+CSV flavour) in which pages, databases-as-CSV-plus-row-pages, relations (as the CSV's relation columns), and attachments round-trip to the fidelity the export flavour itself supports. Multi-head notes follow the sibling rule: export uses the world's current merged head when one exists; for a note with unmerged concurrent heads, export takes the head descended from the last import (the Notion-lineage head) and the export report names the note and the unexported head(s). Nothing is merged or discarded in ID by exporting. If Drew prefers a different export rule, this paragraph is the decision to amend — on #5678/#2048, not in importer code. + +## §6 Invariants implementation must hold + +1. **Manifest first.** Every import produces a persisted manifest before it is considered to have happened: source workspace identity, acquisition paths used and API version pinned, Notion UUID ↔ note ID, block UUID ↔ (note ID, block identity), source file ↔ blob, relation/reference rewrites, per-page outcome (clean / degraded / failed / skipped) with reasons. An import without a manifest is a failed import. +2. **Idempotent re-import.** Re-running an import over an unchanged workspace changes nothing: identity resolves through the manifest, unchanged content hashes produce no new revisions, and the run reports itself a no-op. Concurrent heads stay visible until an explicit merge (#2048) — a re-import that finds locally-edited content does not overwrite it; it creates its revision alongside and the conflict is a named fidelity-report section, resolved by a person or an explicit merge, never by importer fiat. +3. **No destructive replacement.** The importer never deletes, tombstones, or rewrites an existing ID object to make the source "win". Source-side deletions between imports are *reported* (pages in the manifest, absent from the new inventory) and nothing more, unless a user runs an explicit, separate reconciliation action that this design does not create. +4. **No silent drops — the fidelity report is accounting, not prose.** §6.4. +5. **Credentials are inputs, not artifacts.** §6.5. +6. **Partial imports recover.** §6.3. + +### §6.1 Identity and duplicate detection + +Identity is the Notion UUID (API mode). Two pages with the same title are two notes; one page moved or renamed is the same note (UUID stable across moves/renames — that is the property the whole design leans on, and the corpus in §8 tests it). In degraded export-only mode, identity is (export path + title + content hash) and the report must say duplicate detection is best-effort: two same-title pages in the same folder are the known ambiguous case and are surfaced for a user decision at inventory time, not guessed. + +### §6.2 Repeat / incremental import + +Notion has no changes feed the importer can rely on, so "incremental" means: full inventory re-crawl, manifest diff, import only new/changed objects (changed = `last_edited_time` advanced **or** content hash differs — both are checked, because property-only edits move one and block edits can move the other first). The diff categories are exactly: new, changed, unchanged, missing-from-source (§6 invariant 3), and each is a fidelity-report count with a per-item listing available. + +### §6.3 Recovery from partial imports + +The import is staged — inventory → files → content → references → report — and the manifest records each object's stage completion as it lands. A crashed or interrupted run resumes from the manifest: completed objects are not re-created (identity check first), staged blobs are reused by hash, and a run that cannot resume (manifest corrupt, source workspace changed identity) fails loudly at inventory rather than importing a second copy of the world. Progress is observable throughout: the staged manifest *is* the progress record (counts per stage, per-object state), so any UI or log is a view of it, not a second source of truth. + +### §6.4 The fidelity report + +Every import ends with a user-visible fidelity report, persisted with the manifest, containing at minimum: objects by outcome (clean / degraded / failed / skipped) with counts and per-item reasons for every non-clean item; every degradation class from §2.5 with counts; externalised links and relations (§3); missing resources (§4); comments coverage (§2.4); access-metadata observations (§7); conflicts from re-import (§6 invariant 2); and the acquisition degradations of §1.3 when they apply. The report's invariant: **every source object in the inventory is accounted for exactly once** — an import whose report does not reconcile to the inventory has failed, whatever its logs say. + +### §6.5 Credentials and privacy boundaries + +The Notion integration token is supplied to the importer at run time from the user's secret store, is used only for the API crawl and file fetches of that run, and is never written to the manifest, the fidelity report, logs, or any ID object. The importer runs with exactly the integration's visibility (pages shared with the integration) and cannot exceed it; the inventory step records which top-level shares were visible so a user can tell an incomplete share set from an incomplete workspace. Source content is data, not instructions: page text that looks like a prompt or a command is imported as content and never acted on by the importer. + +## §7 Read-authority compliance (the ruled order) and imported access metadata + +The ruling on #6436: ID knowledge defaults to public read; owners may grant read to any number of groups and/or users; resolution order is **object → user default → server config → public**; the importer must not create an alternate read path that reveals content denied by the resolved policy. + +How this design complies, point by point: + +1. **Imported objects are ordinary objects.** A note created by import carries no importer-specific authority state. Its read resolution is the ruled order, evaluated by the same code path as a native note's. There is no "imported from Notion, therefore visible to the Notion audience" concept anywhere in the mapping. +2. **Notion sharing is provenance, not authority.** For each page, whatever the acquisition path can observe about source visibility (published to the web, shared with the workspace, shared with named users/groups) is recorded as provenance claims and summarised in the fidelity report. Recording is deliberately one-directional: the facts are preserved so a person can decide, and the importer applies none of them. +3. **No grants are created.** Import creates no group grants, no per-user grants, and no public-flag changes on any object — including for pages Notion had published to the web. If the user wants the imported set's visibility to mirror the source, that is an explicit post-import action by the user against the report's access section, performed through the ordinary grant mechanism. +4. **People values are not principals.** §2.2's people-property and §2.4's comment-author mappings record Notion user identities as provenance strings. They never resolve to, create, or grant anything to an ID user or group — a Notion workspace member who is also an ID user is linked only if a person performs that linking outside the importer. +5. **The fidelity report is itself an imported-set object** and resolves under the same order; because it names page titles and sharing facts, implementations must not widen its visibility beyond the import's target world defaults. + +Where this touches a parent decision: it does not amend one. #2048's group `Read`/`Write` authority model is the mechanism the ruled order resolves through; this section only states that the importer stays out of it. If Drew wants source-visibility *mirroring* as a feature, that is a #5678-level decision to record there, and the provenance claims in point 2 are the input it would consume. + +## §8 Test corpus plan + +A representative Notion workspace, built once as a fixture (export archive + recorded API responses, so the corpus runs offline and deterministically), containing at minimum: + +- **Pages/blocks:** a page nesting every clean and degraded block type from §2.5 at least twice, at depth ≥ 3; toggles with rich children; a synced block referenced from two other pages; child pages at depth ≥ 2; two pages with identical titles in different parents and in the same parent. +- **Databases:** a database exercising every property type in §2.2, including a two-way relation to a second database, a rollup over that relation, a formula combining properties, a linked-database view placed on a page, and rows whose bodies contain blocks, files and relations to rows outside the corpus set (the externalised-relation case). +- **Files:** the same image attached on two pages and as a row property; a file large enough to exercise staged fetch; one deliberately unfetchable file (expired URL) for the missing-resource path. +- **Comments:** a page with a discussion, replies, a resolved discussion, and a block-anchored comment; a page the fixture integration cannot see comments on (coverage accounting case). +- **Identity/repeat:** the corpus imported twice (second run must be a no-op); the corpus re-imported after a source-side rename and move (identity must follow the UUID); after a source-side property-only edit and a block-only edit (§6.2's two change signals); after a local ID-side edit to an imported note (conflict path, §6 invariant 2); after a source-side deletion (report-only path, §6 invariant 3). +- **Failure injection:** a run killed mid-content stage and resumed (§6.3); an export-only run over the same corpus (degraded mode, §1.3) with its weaker guarantees asserted as such. + +**Decidable acceptance checks** (each is a yes/no query over the manifest, report, and resulting graph — no eyeballing): + +1. For every inventory object: exactly one manifest outcome, and report counts reconcile to inventory totals (§6.4). +2. For every internal link/relation in the corpus source: either a typed reference exists between the expected notes, or the item is listed as externalised with the expected reason (§3). +3. Second import run: zero new notes, zero new revisions, report says no-op (§6 invariant 2). Rename/move re-import: note IDs unchanged, alias claims updated. +4. For every degradation in §2.5's table present in the corpus: the fidelity report's count for that class equals the corpus's known count. +5. Read-authority: for every imported object, a read-resolution probe returns the result predicted by the ruled order given the test world's grants — and for the page the fixture had published to the web, the probe confirms **no** grant was created by the import (§7 point 3). +6. Missing-resource run: the unfetchable file's page is marked degraded, the file is named in the report, and no stored content references the expired URL (§4). +7. Comments: every fixture comment the acquisition path could see exists as a claim on the expected note/block; every page it could not is listed in the comments-coverage section (§2.4). + +## Open questions — Drew-owned, preserved, not decided here + +From #6436 and its parent #5678. This design records which ones touch Notion acquisition/mapping; none is answered here. + +| Question | Affects this design? | +| --- | --- | +| Which product versions/editions to inventory (free vs. paid)? | **Yes — acquisition.** Edition gates export options, API behaviour for some content, and workspace size limits. §1 is written edition-neutral; the corpus (§8) and any hands-on evaluation need the edition set Drew names. The importer must record the source workspace's edition in the manifest when known, because fidelity expectations differ by it. | +| Hands-on vs. documentation-only evaluation budget? | **Yes — corpus and validation.** §8 assumes a fixture workspace can be created and exported. If the budget is documentation-only, the corpus becomes recorded/synthetic API fixtures and the export-flavour claims in §1.1 must be re-validated against Notion's current docs at implementation time; the design's mapping rules do not change. | +| What does "Open Knowledge" refer to? | **Not for the importer mechanics.** It may name a programme-level surface the imported content lands in (parent #5678). If it turns out to name a specific ID surface with its own read rules, §7's compliance statement must be re-checked against it before implementation; the mapping and manifest are unaffected. | +| Graph scope: all ID objects vs. knowledge-only in v1? | **Yes — slicing.** If v1 of the knowledge layer is knowledge-only, the database/claims mapping (§2.2) still holds (claims are the knowledge layer's own mechanism), but §9's slicing order changes: the page/block core ships first and database mapping can follow. The design deliberately does not bake in either answer — §2.2 is specified either way. | +| AI-over-notes model choice (local, hosted, or user choice) and its authority implications? | **No for import; yes for anything that reads the import.** The importer uses no AI and summarises nothing. The authority half of the question matters to whichever feature later runs over imported notes: imported provenance claims (§7) are the record such a feature must respect. Flagged here so the programme does not mistake this design for an answer. | + +## Viable options + +**Acquisition strategy** (the one real fork in this design): + +| Option | Shape | Pros | Cons | +| --- | --- | --- | --- | +| A. Export only | Parse the workspace export; no API | No credential, no integration setup; files are permanent | No reliable UUIDs (identity degrades, §1.3), relations/schema/comments effectively lost — fails #6436's mapping acceptance for databases | +| B. API only | Full crawl via integration | Complete identity, schema, relations, comments; incremental re-crawl possible | File URLs expire mid-run (handled, §4, but operationally fragile on huge workspaces); block fidelity for some editor constructs is the API's representation, not the export's; inventory bounded by integration sharing | +| **C. Hybrid (recommended)** | API for inventory/identity/schema/comments; export for content/files when supplied, API content otherwise | Each source covers the other's structural gap; fidelity report can cross-check the two inventories against each other, which neither single-source option can do | Two parsers to build and keep in step; matching export content to API identity is real work (§1.3) and the uncertain-match path must be honest | + +Options A and B are retained as the degraded modes of C (§1.3), not as separate implementations: an import with only one source available runs C's pipeline with the missing source's inputs marked absent. + +**Database representation** was the other candidate fork — a dedicated database object type in the model versus §2.2's claims-and-references mapping. The object-type option is rejected here because it re-opens #2048 (a programme decision) to serve one importer, and because relations-as-references already give the graph behaviour databases exist for in ID. If a future programme decision adds a database type, §2.2's schema claims are the migration input. + +## Implementation slicing (follow-on issues, not this design) + +In dependency order; each slice is independently landable and testable against §8's corpus subset: + +1. **Manifest + inventory:** manifest store and staged-state machine (§6.3), API inventory crawl with share-set accounting (§1.2), edition/version recording. +2. **Page/block core:** block tree → revision content for the clean classes of §2.5, identity mapping, two-pass link rewriting (§3), files (§4). +3. **Databases:** schema claims, row claims, relation references, rollup/formula provenance (§2.2). +4. **Comments + degradation completion:** comment claims (§2.4), the unsupported/degraded classes of §2.5, export-content matching for hybrid mode (§1.3). +5. **Fidelity report + re-import:** report generation with inventory reconciliation (§6.4), incremental diff and conflict surfacing (§6.2), corpus completion and the §8 acceptance harness. + +Each slice files as its own implementation issue referencing this design and #6436; the design issue closes when this document lands and the slices are filed.