Repository navigation
Description
Context
Part of the epic #1777 (resolve pending media through hygiene review). Read the epic for every maintainer ruling.
The inventory child of #1777 supplies findings with identity, fingerprints and dispositions. This task implements what each review action does to files, references and configuration, through the existing governed effect, journal, receipt and Undo machinery of hygiene review (docs/decisions/hygiene-review.md). The existing revert path reports partial outcomes rather than providing an all-file transaction (createTurnReverts, packages/ui-server/src/brain/turn-revert.ts:20; its execute, :90); media effects follow the same expected-version compensation model.
Design: rev 4 §3 (references and bounds), §5 (Keep a permanent copy, with §5.7 replaced by rev 5), §6 (Persist, Move, Delete) and §7 (config).
Scope
- References (B): the declared inventory of local Markdown link, image, reference-definition and file-link forms, documented frontmatter/HTML forms, and host-owned pointers (staged shares and scratch pins at their real owners, rev 4 §3-§4). No arbitrary string matching; code samples and unrelated bytes preserved; unsupported references refuse the move.
- Bounds (Q1 A): configurable 50,000 notes, 256 MiB scanned note bytes, 4 MiB per note, 20 s scan, 500 references per finding, 200 rewritten notes per move, 1 MiB preview; validated, snapshotted, enforced incrementally;
inventory-too-largeorinventory-unscannablerefuse without mutation. One running scan per server; a newer preview from the same principal aborts the older; another principal getspreview-busy. - Delete: preview the file and known references; capture bytes before mutation under the existing bounded journal retention (rollback A), refuse
capture-capacityif capture cannot fit; truthful Undo availability. - Move: contained destination outside scratch, collision and stale checks, supported reference and pointer updates in one governed effect with per-file expected-version compensation and an honest
partialoutcome. A linked scratch original refuses Move. - Persist here: exact-file
media.trackby default; an optional broader rule with current and future match preview (B); a conflicting exact-path ignore removed in the same approval, broader ignore adjustments previewed and approved, unexpressible ones refused (ignore-conflict B, M1 A). Config edits through the governed maintenance boundary without evaluating brain-controlled TypeScript (rev 4 §7); approval binds principal, config sha, diff and match-inventory digest. - Keep a permanent copy (Q2 B): for an eligible conversation-linked scratch original, a contained final copy with verified integrity and deliberate persistence; original bytes, path, pins and history untouched; duplicate bytes accounted; interrupted copies never reported complete; the original receives the
keptdisposition from the inventory child. - Undo: for every effect, under complete retained rollback data and stale guards, never overwriting later edits.
- Reference digest in the media fingerprint: the declared reference scan fills each media finding's
refsfingerprint field, which core: build one media inventory with kept dispositions and count-only sync reporting for hygiene review #2780 records asunscanneduntil then; the change reopens media dispositions once. - Keep a permanent copy, server side (rev 6 §1, §6.4, §6.6): step 6b dispatches core: build one media inventory with kept dispositions and count-only sync reporting for hygiene review #2780's
brain hygiene keep-copyafter verification, compensating on refusal; thekeptoutcome status inhygieneOutcomeSchemaand the serverresultSchema(an old schema yieldscheck_failed, neverresolved); the review'skeptcounter; andrecover()confirming only when entry state, fingerprint andcopy-sha256match (otherwisereceipt-unknown).
Out of scope
- Inventory, dispositions and counts (Epic: resolve pending media through hygiene review #1777's inventory child); the review UI (Epic: resolve pending media through hygiene review #1777's review child).
- Rewriting retained transcripts or history, mutating
brain.dbas authority, automatic commits, blanket write grants.
Acceptance criteria
- Each effect's actual file, reference, pointer and config bytes are inspected after apply and after Undo, for Delete, Move, Persist here (exact and broader) and Keep a permanent copy. (
14d6986b5, CONTRACT: feat: governed Delete, Move, Persist here and Keep a permanent copy for media findings, with journal capture, compensation and Undo (#2781) #3421;81c8fd1cd, CONTRACT: feat: brain config media and Persist here by a broader rule, with matches previewed and approval bound (#2781) #3491; Undo pins, ignore adjustment and exact-ignore removalb7d6982cb, test(hygiene): prove media Undo bytes, Q1 boundaries and copy recovery (#2781 slice 6) #3584) - Every Q1 limit refuses at boundary plus one without mutation, and admits at the boundary with a complete reference inventory. (
f9b8dde1d, CONTRACT: feat(core): fingerprint media by a bounded scan of declared note references (#2781) #3328; scan-time boundary, literal defaults, boundary inventory and refused applyb7d6982cb, test(hygiene): prove media Undo bytes, Q1 boundaries and copy recovery (#2781 slice 6) #3584) - Capture-capacity refusal happens before any write; eviction of rollback data disables Undo honestly; stale source, destination, reference or config premises refuse. (
14d6986b5, CONTRACT: feat: governed Delete, Move, Persist here and Keep a permanent copy for media findings, with journal capture, compensation and Undo (#2781) #3421; config premise81c8fd1cd, CONTRACT: feat: brain config media and Persist here by a broader rule, with matches previewed and approval bound (#2781) #3491) - Move of a linked scratch original is refused; Keep a permanent copy preserves the original's bytes, path and pins, and a later ordinary sync persists the copy. (
14d6986b5, CONTRACT: feat: governed Delete, Move, Persist here and Keep a permanent copy for media findings, with journal capture, compensation and Undo (#2781) #3421; syncdd50bf087, CONTRACT: feat: undo a confirmed media effect from hygiene review, removing a kept copy's entry with it (#2781) #3472) - Interrupted Move and copy recover to a truthful
partialor complete state after restart, with no concurrent edit overwritten. (8a197a177, CONTRACT: feat: one media preview scan per server, bounded by the response limit, with requestId, refusals and media dimensions (#2781) #3567; copy and config no-overwriteb7d6982cb, test(hygiene): prove media Undo bytes, Q1 boundaries and copy recovery (#2781 slice 6) #3584) - Guard mutations (capture-before-mutation, expected-version check, approval binding, reference containment) each fail their intended assertion and are restored, recorded in the PR. (receipts in CONTRACT: feat: governed Delete, Move, Persist here and Keep a permanent copy for media findings, with journal capture, compensation and Undo (#2781) #3421, CONTRACT: feat: brain config media and Persist here by a broader rule, with matches previewed and approval bound (#2781) #3491 and CONTRACT: feat: one media preview scan per server, bounded by the response limit, with requestId, refusals and media dimensions (#2781) #3567)
Verification
bun run test packages/core packages/ui-server
bun run typecheck
bun run lintOdysseus fixture brains, real Git and filesystem, offline.
Contract impact
Additive action, preview, refusal and receipt shapes and the brain config media edit path, per rev 5 §9: CONTRACT: commits, same-commit contract updates, minor changesets. No breaking change.
2026-11-02: folded in the two #2780 handoff items (reference digest in the media fingerprint, server side of Keep a permanent copy) from rev 4 §1 and rev 6 §1/§6; no new ruling.
Activity
schlessera commentedon Nov 2, 2026
2026-11-02 handoff from #2780 (inventory child, branch
feat/2780-media-inventory-hygiene): two pieces of the existing design land here, with the effects. Neither is a new ruling; both come from rev 4 §1 and rev 6 §1/§6.refsfield, which core: build one media inventory with kept dispositions and count-only sync reporting for hygiene review #2780 records as the literalunscanned(REFS_UNSCANNED,packages/core/src/lib/media-inventory.ts) because the declared reference scan is this task's. When the scan lands,refsbecomes its digest. That reopens every media disposition once, which is the safe direction. Document it in the changeset.brain hygiene keep-copy <id> --expect-fingerprint <fp> --copy <path> --copy-sha256 <sha256> --journal <id>. It records akeptentry only for a media finding whose copy already holds, and otherwise refuses withnot-media,copy-missing,copy-untrackedorcopy-changed, writing nothing. Still to do here: step 6b dispatches it after verifying the copy, with compensation when it refuses; thekeptoutcome status inhygieneOutcomeSchemaand the serverresultSchema, where an old schema must yieldcheck_failedand neverresolved; incrementing the review'skeptcounter (already in review state, defaulting to 0); andrecover()confirming a keep-copy only when entry state, fingerprint andcopy-sha256all match (otherwisereceipt-unknown).CONTRACT: feat(core): record a kept media original with brain hygiene…
CONTRACT: feat(core): count media awaiting review from one inventory …
schlessera commentedon Nov 2, 2026
Claiming (token
claim-2781-824f5f6f). Branchfeat/2781-media-finding-effectsfromepic/1777-media-hygieneat 98a15b9 (#2780 delivered there via #3288), PR targets the epic branch per the maintainer's epic-branch ruling. Collisions: path overlap onpackages/core/src/lib/hygiene.tswith #3293 and with the epic landing PR #3316 (its own base); the rest are closure-only.schlessera commentedon Nov 2, 2026
Progress, slice 1: #3328 (base
epic/1777-media-hygieneat 98a15b9, head 408dfe4) delivers the declared reference inventory with the five Q1 scan bounds (BRAIN_MEDIA_REFERENCE_LIMITS). It also delivers the first inherited #2780 item: therefsfingerprint field is nownone, a digest, ortoo-large/unscannable. This issue stays open for the rest: the Delete, Move, Persist here and Keep a permanent copy effects with capture, compensation and Undo; therewrittenNotes/previewbounds and scan concurrency; the preview, command and receipt contract;brain config mediaedits; and the server side of Keep a permanent copy (step 6b, thekeptoutcome, the counter andrecover()). The full list is under Anything left open in the PR.15 remaining items
schlessera commentedon Nov 3, 2026
Claiming slice 3 (token
claim-2781-s3-a701). Branchfeat/2781-media-undo-reviewfromepic/1777-media-hygieneat 14d6986; the PR targets the epic branch per the epic-branch ruling. Scope: theundo-mediareview command per the 2026-11-03 ruling, including removal of thekeptentry when a copy is undone, then as much of the remaining list as forms one reviewable PR. Collisions (path):packages/ui-sdk/src/schemas.tswith #3342, #3386, #3404, #3407;packages/core/src/lib/hygiene.tswith #3293, #3462;packages/core/src/cli/commands/hygiene.tswith #3458. The rest are closure-only.schlessera commentedon Nov 3, 2026
Progress, slice 3: #3472, against
epic/1777-media-hygiene(base 14d6986, head daa7004), now ready for hosted proof.It delivers:
undo-mediareview command, per the 2026-11-03 ruling. It has the CLI Undo's preflights, gives a refusal as a 200 result, and records the Undo's receipt on the resolved card. The undone effect leaves thefixedorkeptcounter, and the restored finding returns on a successor card.keptentry when a copy is undone, through the newbrain hygiene unkeep <id> --journal <id>, after the copy and config are restored. Compensation and recovery remove it the same way.Still open here, and no new ruling is needed:
brain config media … --expect-shawith approval binding.preview-busy, and thepreviewbody-limit check.mediadimensions andrefusals[]/requestId.I'm keeping the claim while #3472 is live.
CONTRACT: feat: undo a confirmed media effect from hygiene review, re…
schlessera commentedon Nov 3, 2026
Claiming slice 4 (token
claim-2781-s4-c3f2). Branchfeat/2781-media-config-previewfromepic/1777-media-hygieneat dd50bf0; the PR targets the epic branch per the epic-branch ruling. Scope: Persist here's broader rule and the broader ignore adjustment (with their match preview, approval binding and byte checks), andbrain config media <add|remove>-<track|ignore> <pattern> --expect-sha.preview-busyand the preview'smedia/refusals[]/requestIdfields stay for the next slice. Collisions (path):packages/ui-sdk/src/{protocol,schemas}.tswith #3342, #3386, #3404, #3407, #3473, #3484;packages/core/src/cli/commands/hygiene.ts/brain.tswith #3458;packages/core/src/cli/commands/config.tswith #3404; the contract docs with #3384, #3393, #3456, #3465, #3471; and the epic landing PR #3482 (this slice's base). The rest are closure-only.schlessera commentedon Nov 3, 2026
Progress, slice 4: #3491, against
epic/1777-media-hygiene(base d8f607e, head 826b4e7), now ready for hosted proof.It delivers:
brain config media <add|remove>-<track|ignore> <pattern>, previewed with--dry-runand applied with--expect-sha(and optionally--expect-approval). The preview shows the pattern's current matches, and the approval digest binds the config SHA-256, the diff and those matches.--pattern) and the broader ignore adjustment (--ignore-adjust, M1 A). Each is previewed with its matches and needs its approval back (stale-approvalotherwise).Still open here; no new ruling is needed:
preview-busy, and thepreviewbody-limit check.mediadimensions andrefusals[]/requestId.I'm keeping the claim while #3491 is live.
CONTRACT: feat: brain config media and Persist here by a broader rule…
CONTRACT: feat: one media preview scan per server, bounded by the res…
Merge pull request #3565 from schlessera/epic/1777-media-hygiene
schlessera commentedon Nov 4, 2026
Acceptance audit, 2026-11-04, against the tree that landed on main in
401c66b0b(#3565, epic #1777 batch: #3491 and #3567). The slices aref9b8dde1d(#3328),14d6986b5(#3421),dd50bf087(#3472),81c8fd1cd(#3491) and8a197a177(#3567). The focused suites pass at that tree:media-references,media-effects,media-configandhygiene-mediain core, plushygiene-media-effectsin ui-server.Ticked (delivered):
ui-server/tests/hygiene-media-effects.test.ts(capacity refused before any write;MEDIA_UNDO_EVICTED) andcore/tests/media-effects.test.ts(stale source,KEEP_NO_OVERWRITE,MOVE_NOTE_PREMISE), all14d6986b5.core/tests/media-config.test.tscoversCONFIG_STALE_SHA(81c8fd1cd).MOVE_LINKED_SCRATCH,KEEP_ORIGINAL_BYTESandKEEP_PINS_BYTES(14d6986b5), plusMEDIA_KEEP_SYNC_COPY(dd50bf087).BROADER_MUST_MATCH) and CONTRACT: feat: one media preview scan per server, bounded by the response limit, with requestId, refusals and media dimensions (#2781) #3567 (MEDIA_RECOVERY_PARTIAL).Also delivered, with no checkbox of its own: one running preview scan per server, a newer same-principal preview aborting the older one, and
preview-busyfor another principal (8a197a177). The server's preview response carriesrequestId,refusals[]andmediadimensions. The review UI sendingrequestIdand showing those dimensions belongs to #2782, not here.Still open:
.brain/scratch-pins/pins.json.--ignore-adjust) has no after-Undo byte check.scanTimeis admitted at 1000 and refused at 20 (core/tests/media-references.test.ts), so the exact boundary and boundary plus one are untested.DEFAULT_MEDIA_REFERENCE_LIMITSitself.status: complete, not a complete reference inventory.MEDIA_RECOVERY_NO_OVERWRITE). No test edits the copy orbrain.configbefore an interrupted copy's recovery.recover()confirms a kept copy only when entry state, fingerprint andcopy-sha256match, and otherwise reportsreceipt-unknown. That check exists (packages/ui-server/src/inbox/hygiene-review.ts:390-394) but no test drives a mismatch. Nor does any test cover "an old schema yieldscheck_failed, neverresolved".#2781 stays open for these. Each is a test addition against existing behaviour. None needs a new ruling.
test(hygiene): prove media Undo bytes, Q1 boundaries and copy recovery (
schlessera commentedon Nov 4, 2026
Slice 6, #3584, squash-merged into
epic/1777-media-hygieneasb7d6982cb. Its ready proof passed every selected job (run 41900267079; base70ce32e84, checkout tree820c139cb, which equals the squash tree). It covers every open item in the 2026-11-04 audit, and I've ticked the three remaining boxes with their commits.media.ignore(packages/core/src/lib/media-inventory.ts:9). It is byte-checked after apply and after Undo at a copy's destination instead.check_failed" is proven through the fail-closed path for an unrecognisedkeep-copystatus (MEDIA_MIXED_*). An old server build can't run in the suite.The issue closes when batch PR #3586 lands on main.
Merge pull request #3586 from schlessera/epic/1777-media-hygiene