Skip to content

fix(init): re-tag rows stored before the injection screen (#375) - #378

Merged
abogartz merged 3 commits into
374-init-stamp-filefrom
375-retag-quarantined
Nov 12, 2026
Merged

abogartz merged 3 commits into
374-init-stamp-filefrom
375-retag-quarantined

Conversation

@abogartz

@abogartz abogartz commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Stacked on #374

This branch is based on 374-init-stamp-file because both change src/init/run.ts. GitHub will retarget this PR to main when #374 merges; until then the diff shown here is only #375's work.

What

/repo-init repairs stores that were poisoned before #372 screened its writes (#375).

The screen covers writes made after #372. A store that already holds an untagged injection-shaped row keeps it, and re-running init could not fix it: GATE-3's exact-duplicate check compares type and content, so the quarantined candidate collapsed into the older untagged row, and force: true skips the stamp check, not the dedup. The user could not see the row and could not clear it.

src/init/retag.ts scans every row the caller can read (this repository plus global) and re-tags each hit through the only shape GATE-3 accepts as a metadata edit: a normal gated write that names the row it replaces (supersedesTs), followed by the supersession. Nothing is deleted; every replacement emits its own write_promoted line.

Three choices the ticket left open:

  • It lives in memory_init (the ticket's Option 1) — "init repairs the repo's memory" is the shape users already have, and no operator has to find a script.
  • It runs before the stamp check. A stamped repository is the common poisoned case; returning early would leave the row live forever.
  • Fields are carried, not reset. The twin keeps original, ref/claim/klass, issue, kw, status and repo, so closing the injection boundary does not quietly destroy capture provenance or move a row's visibility.

Measured

RED — main at f8f42fd, hermetic store, non-git fixture:

after init(force=false): active=true tags= null | init skipped: false
after init(force=true):  active=true tags= null | init skipped: false
RED CONFIRMED: the poisoned row is still live and untagged

GREEN — this branch, same script:

Injection screen: re-tagged=1, blocked=0, partial=0
old row active: false | twin active: true | twin tags: ["quarantine","quarantine:instruction_override"]
skipped run: Injection screen: re-tagged=1, blocked=0, partial=0
second poisoned row retired: true
third init reports a repair? false

Acceptance from the ticket:

  • quarantinePatterns runs over every active row the caller can read — content, scope and original, the three fields quarantineCandidate screens (Make user-stated facts survive: verbatim quote, guaranteed guided row, cache refresh, timing fix #364 made original model-facing too).
  • Re-tagging goes through the normal write path, so the change is audited: one write_promoted per replacement, and the original retired, not deleted.
  • The count is reported: re-tagged=N on the reply, and retagged= on the init_complete / init_skip evidence lines.

bun run gate green: typecheck, lint, 1199 unit pass / 19 skip / 0 fail, terminal smoke + BDD 30 pass / 0 fail.

Limits, stated rather than discovered later

  • Reach is visibility. A session repairs its own repository plus global rows, not another repository's. That is the same boundary every other flow in this plugin enforces.
  • A hit the gate refuses stays live. GATE-1 can block a replacement whose prose names code that no longer resolves. The reply says blocked=N rather than reporting a clean repair.
  • One run re-tags at most 100 rows and reports remaining=N, so an injection-shaped directory name plus a thousand quoting rows cannot turn one /repo-init into a thousand full-file publishes.
  • GATE-2 collateral is named. If a replacement caused drift supersessions elsewhere, the count is reported; the caller-owned durable ledger is what makes that visible (fix(update): metadata fidelity and truthful partial results (#154 #155) #158's mechanism).
  • A partial is a partial. If the replacement lands and the retirement does not, it counts as partial=N in the memory_update shape, never as a clean re-tag.

Closes #375

#372 screens what /repo-init writes. It never repaired what was already there:
GATE-3's exact-duplicate check compares type and content, so a quarantined
candidate collapsed into the older untagged row, and force skips the stamp
check, not the dedup. A store poisoned before #372 therefore kept a live,
injectable row that no user could see.

Init now scans every row the caller can read and re-tags each hit the way the
gate allows: a normal write that names the row it replaces (supersedesTs), which
GATE-3 reads as a metadata edit rather than a duplicate, followed by the
supersession. Nothing is deleted and every replacement emits its own
write_promoted line.

The repair runs before the stamp check, because a stamped repository is the
common poisoned case. It carries every field the row had (original, ref/claim/
klass, issue, kw, status, repo) so closing one boundary does not open another,
caps one run at 100 writes and reports the remainder, and reports blocked,
partial and GATE-2 collateral retirements instead of a clean summary.

Measured: RED on main at f8f42fd — the poisoned row stays active and untagged
after both init and init --force. GREEN on this branch — re-tagged=1, old row
retired, twin tagged quarantine + quarantine:instruction_override, and the same
repair lands on a run that skips its stamp.

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — A transient retirement failure leaves the unsafe original active, and the next repair cannot recover it (src/init/retag.ts:121–148).

Independently reproduced on ab1b3ac with Bun 1.4.4 / Windows and a synthetic store: seed one untagged instruction-override row in an older day file, hold that file's normal store lock, and run the repair. The gate durably appends the quarantined twin to today's file; markSuperseded then times out and throws instead of returning the promised partial result. Both rows remain active. After releasing the lock, retrying returns retagged=0, blocked=1, partial=0: GATE-3 collapses into the already-written twin, so the original remains unquarantined. The ordinary uncontended repair tests pass.

Please preserve/report the durable partial outcome and make a retry finish retiring the original when its matching quarantined successor already exists. A regression covering contention followed by an unlocked retry would pin both halves. This tests the repair/store path only; no live model or production store was used.

…jects

Review finding on #378 (WhollyMindless), both cases reproduced. The repair
path shipped without tests, which is how both survived the PR.

(a) COLLAPSED is not "nothing happened". An interrupted repair leaves a
    quarantined twin durable and the original unretired; every retry then
    collapsed into the twin, was counted `blocked`, and left the poisoned
    row injectable forever (retagged=0, blocked=1, stable). The collapse
    survivor IS the twin: the re-tagged candidate differs from the original
    only by tags, and GATE-3's supersedesTs carve-out means the original
    can never match as its own duplicate — an exact-content match is the
    prior replacement. On collapse the repair now retires the original
    under `collapsedWith`.

(b) markSuperseded can REJECT (lock contention), not only return false.
    The throw escaped retagQuarantinedRows, so memory_init reported nothing
    about the twin that WAS written — the #155 lesson, missing on the
    repair path. The call is wrapped; the failure lands in `partial` with
    its reason in a new `failures` ledger surfaced as `retag_failures`, and
    the retry (a) completes the job.

- src/init/retag.ts: collapse completes; reject reports
- src/init/run.ts: retag_failures in the tool output
- test/retag-repair.test.ts: clean repair, twin-completes (a),
  reject-then-retry (b), clean row untouched — (a) and (b) fail on the
  pre-fix code, verified by checkout

Co-authored-by: OpenCode <[email protected]>
@abogartz

Copy link
Copy Markdown
Owner Author

@WhollyMindless both cases confirmed and fixed in 61cc019. You were right that the repair path shipped without tests — test/retag-repair.test.ts now exists, and both regressions fail on the pre-fix code (verified by checkout, not by argument).

(a) COLLAPSED now completes the repair. Your reading of the mechanism is correct: the retry's gate write collapses into the durable quarantined twin, and the old code counted that as blocked — retagged=0, blocked=1, stable across retries, original injectable forever. The fix treats the collapse survivor as the twin and retires the original under collapsedWith. The identification is safe, not assumed: the re-tagged candidate differs from the original only by tags, and GATE-3's supersedesTs carve-out means the original can never match as its own duplicate — so an exact-content match is the prior replacement. Pinned: twin durable + original live → one run → retagged=1, original superseded_by the twin, one active row.

(b) A rejecting markSuperseded now reports, not escapes. The throw leaving the whole repair is exactly what you described — the twin WAS written and memory_init said nothing (the #155 lesson, missing on this path). The call is wrapped; the failure lands in partial with its reason in a new failures ledger, surfaced as retag_failures in the tool output. Pinned end-to-end: simulated lock refusal → partial=1, failure named, both rows live after the run; the retry then takes path (a) and the store ends with exactly one active quarantined row.

bun run gate green: 1222 unit, 30 e2e, typecheck, lint.

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently verified the interrupted-repair finding resolved on 61cc01971301445da1ca595e41da756ae5d97c6e.

Replayed the original real old-day-file lock-contention probe: the first call now returns partial=1 with the busy-lock reason in failures; the durable quarantined twin and active original are both visible. After releasing the lock, the retry returns retagged=1, blocked=0, retires the original under the existing twin, and leaves one active quarantined row. No exception escapes the repair.

43 focused retag/init/boundaries/lifecycle tests, the separate real-lock/retry probe (8 assertions), and typecheck pass on Windows/Bun 1.4.4. Approval addresses the maintainer's repair change at this head; no live-user store or model behavior was tested.

@abogartz
abogartz merged commit cfb0e0b into 374-init-stamp-file Nov 12, 2026
4 checks passed
abogartz-opencode-self-improvement Bot pushed a commit that referenced this pull request Nov 12, 2026
## [0.23.1](v0.23.0...v0.23.1) (2026-11-12)

### Bug Fixes

* **init:** finish the re-tag when the gate collapses or retirement rejects ([61cc019](61cc019)), closes [#378](#378) [#155](#155)
* **init:** keep the init stamp out of the memory store ([#374](#374)) ([27e74e8](27e74e8))
* **init:** make the legacy init-stamp row inert, and make its migration report the truth ([805bc6c](805bc6c)), closes [pre-#374](https://github.com/pre-/issues/374)
* **init:** re-tag rows stored before the injection screen ([#375](#375)) ([ab1b3ac](ab1b3ac)), closes [#372](#372) [#372](#372)
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.23.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@abogartz
abogartz deleted the 375-retag-quarantined branch November 19, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants