Skip to content

core: apply governed Delete, Move, Persist here and Keep a permanent copy effects for media findings with Undo #2781

Closed

Description

@schlessera

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-large or inventory-unscannable refuse without mutation. One running scan per server; a newer preview from the same principal aborts the older; another principal gets preview-busy.
  • Delete: preview the file and known references; capture bytes before mutation under the existing bounded journal retention (rollback A), refuse capture-capacity if 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 partial outcome. A linked scratch original refuses Move.
  • Persist here: exact-file media.track by 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 kept disposition 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 refs fingerprint field, which core: build one media inventory with kept dispositions and count-only sync reporting for hygiene review #2780 records as unscanned until 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-copy after verification, compensating on refusal; the kept outcome status in hygieneOutcomeSchema and the server resultSchema (an old schema yields check_failed, never resolved); the review's kept counter; and recover() confirming only when entry state, fingerprint and copy-sha256 match (otherwise receipt-unknown).

Out of scope

Acceptance criteria

Verification

bun run test packages/core packages/ui-server
bun run typecheck
bun run lint

Odysseus 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

  1. added
    type: feat
    area: core
    area: ui-server
    priority: p2
    agent-ready
    blocked
    contract
    on Oct 24, 2026
  2. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    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.

    • Reference-inventory digest. Every media finding's fingerprint has a refs field, which core: build one media inventory with kept dispositions and count-only sync reporting for hygiene review #2780 records as the literal unscanned (REFS_UNSCANNED, packages/core/src/lib/media-inventory.ts) because the declared reference scan is this task's. When the scan lands, refs becomes its digest. That reopens every media disposition once, which is the safe direction. Document it in the changeset.
    • Server side of Keep a permanent copy (rev 6 §1, §6.4, §6.6). core: build one media inventory with kept dispositions and count-only sync reporting for hygiene review #2780 ships the core write path: brain hygiene keep-copy <id> --expect-fingerprint <fp> --copy <path> --copy-sha256 <sha256> --journal <id>. It records a kept entry only for a media finding whose copy already holds, and otherwise refuses with not-media, copy-missing, copy-untracked or copy-changed, writing nothing. Still to do here: step 6b dispatches it after verifying the copy, with compensation when it refuses; the kept outcome status in hygieneOutcomeSchema and the server resultSchema, where an old schema must yield check_failed and never resolved; incrementing the review's kept counter (already in review state, defaulting to 0); and recover() confirming a keep-copy only when entry state, fingerprint and copy-sha256 all match (otherwise receipt-unknown).
  3. self-assigned this
    on Nov 2, 2026
  4. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Claiming (token claim-2781-824f5f6f). Branch feat/2781-media-finding-effects from epic/1777-media-hygiene at 98a15b9 (#2780 delivered there via #3288), PR targets the epic branch per the maintainer's epic-branch ruling. Collisions: path overlap on packages/core/src/lib/hygiene.ts with #3293 and with the epic landing PR #3316 (its own base); the rest are closure-only.

  5. added this to the 0.45.0 milestone on Nov 2, 2026
  6. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Progress, slice 1: #3328 (base epic/1777-media-hygiene at 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: the refs fingerprint field is now none, a digest, or too-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; the rewrittenNotes/preview bounds and scan concurrency; the preview, command and receipt contract; brain config media edits; and the server side of Keep a permanent copy (step 6b, the kept outcome, the counter and recover()). The full list is under Anything left open in the PR.

  7. 15 remaining items

  8. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Claiming slice 3 (token claim-2781-s3-a701). Branch feat/2781-media-undo-review from epic/1777-media-hygiene at 14d6986; the PR targets the epic branch per the epic-branch ruling. Scope: the undo-media review command per the 2026-11-03 ruling, including removal of the kept entry when a copy is undone, then as much of the remaining list as forms one reviewable PR. Collisions (path): packages/ui-sdk/src/schemas.ts with #3342, #3386, #3404, #3407; packages/core/src/lib/hygiene.ts with #3293, #3462; packages/core/src/cli/commands/hygiene.ts with #3458. The rest are closure-only.

  9. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Progress, slice 3: #3472, against epic/1777-media-hygiene (base 14d6986, head daa7004), now ready for hosted proof.

    It delivers:

    • The undo-media review 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 the fixed or kept counter, and the restored finding returns on a successor card.
    • Removal of the kept entry when a copy is undone, through the new brain hygiene unkeep <id> --journal <id>, after the copy and config are restored. Compensation and recovery remove it the same way.
    • Tests for a source change mid-copy and for link-not-rename.
    • The byte check that a later ordinary sync commits the copy.

    Still open here, and no new ruling is needed:

    • Persist here's broader rule and the broader ignore adjustment, with their byte checks.
    • brain config media … --expect-sha with approval binding.
    • One scan per server with preview-busy, and the preview body-limit check.
    • The preview's media dimensions and refusals[]/requestId.

    I'm keeping the claim while #3472 is live.

  10. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Claiming slice 4 (token claim-2781-s4-c3f2). Branch feat/2781-media-config-preview from epic/1777-media-hygiene at 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), and brain config media <add|remove>-<track|ignore> <pattern> --expect-sha. preview-busy and the preview's media/refusals[]/requestId fields stay for the next slice. Collisions (path): packages/ui-sdk/src/{protocol,schemas}.ts with #3342, #3386, #3404, #3407, #3473, #3484; packages/core/src/cli/commands/hygiene.ts/brain.ts with #3458; packages/core/src/cli/commands/config.ts with #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.

  11. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    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-run and 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.
    • Persist here's broader rule (--pattern) and the broader ignore adjustment (--ignore-adjust, M1 A). Each is previewed with its matches and needs its approval back (stale-approval otherwise).
    • The review option Persist with a broader rule…. An approval is bound to the principal who previewed it.

    Still open here; no new ruling is needed:

    • One scan per server with preview-busy, and the preview body-limit check.
    • The preview's media dimensions and refusals[]/requestId.

    I'm keeping the claim while #3491 is live.

  12. schlessera commented on Nov 4, 2026

    @schlessera
    OwnerAuthor

    Acceptance audit, 2026-11-04, against the tree that landed on main in 401c66b0b (#3565, epic #1777 batch: #3491 and #3567). The slices are f9b8dde1d (#3328), 14d6986b5 (#3421), dd50bf087 (#3472), 81c8fd1cd (#3491) and 8a197a177 (#3567). The focused suites pass at that tree: media-references, media-effects, media-config and hygiene-media in core, plus hygiene-media-effects in ui-server.

    Ticked (delivered):

    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-busy for another principal (8a197a177). The server's preview response carries requestId, refusals[] and media dimensions. The review UI sending requestId and showing those dimensions belongs to #2782, not here.

    Still open:

    1. Bytes after apply and after Undo:
      • Undo of Keep a permanent copy does not re-read .brain/scratch-pins/pins.json.
      • The broader ignore adjustment (--ignore-adjust) has no after-Undo byte check.
      • Neither does the exact Persist here that removes a conflicting exact-path ignore; its test checks only the splice.
    2. Q1 limits:
      • scanTime is admitted at 1000 and refused at 20 (core/tests/media-references.test.ts), so the exact boundary and boundary plus one are untested.
      • All bounds are exercised with injected small limits. No test asserts the default values (50,000 / 256 MiB / 4 MiB / 20 s / 500 / 200 / 1 MiB). The test only compares against DEFAULT_MEDIA_REFERENCE_LIMITS itself.
      • At the boundary, the tests assert only status: complete, not a complete reference inventory.
      • No scan-limit refusal is driven through an effect apply to show nothing was mutated.
    3. Restart recovery: "no concurrent edit overwritten" is proven for Move only (MEDIA_RECOVERY_NO_OVERWRITE). No test edits the copy or brain.config before an interrupted copy's recovery.
    4. Scope item with no test: the server side of Keep a permanent copy says recover() confirms a kept copy only when entry state, fingerprint and copy-sha256 match, and otherwise reports receipt-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 yields check_failed, never resolved".

    #2781 stays open for these. Each is a test addition against existing behaviour. None needs a new ruling.

  13. schlessera commented on Nov 4, 2026

    @schlessera
    OwnerAuthor

    Slice 6, #3584, squash-merged into epic/1777-media-hygiene as b7d6982cb. Its ready proof passed every selected job (run 41900267079; base 70ce32e84, checkout tree 820c139cb, 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.

    • Exact Persist here and a conflicting exact-path ignore: this can't arise on the finding itself, because a pending media finding is never matched by 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.
    • Old schema: "an old schema yields check_failed" is proven through the fail-closed path for an unrecognised keep-copy status (MEDIA_MIXED_*). An old server build can't run in the suite.

    The issue closes when batch PR #3586 lands on main.

  14. added a commit that references this issue on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: corearea: ui-servercontractpriority: p2type: feat

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions