Repository navigation
fix(init): keep the init stamp out of the memory store (#374) - #376
Conversation
A `context` row tagged `init-stamp` decided whether a repository had been set up, and nothing reserved the tag: any session could write one with memory_remember naming the current short HEAD, and every later memory_init then answered "Already initialized" for that commit and wrote no command rows, with no line saying why. The stamp is a file under the memory root now, named for the repository identity key and read or written only by src/init/, so no tool reaches it and memory_recall, export and the viewer stop showing state that was never meant for them. The one-time migration honours a pre-#374 row only when an `init_complete` evidence line names its ts — the pairing a row cannot supply about itself — copies it to the file, and leaves the row alone. A row no init audited is ignored, so the forgery that motivated the change stays ignored. A stamp file that cannot be written is reported on the reply instead of swallowed: the honest consequence is one more run of an idempotent command.
#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.
…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]>
fix(init): re-tag rows stored before the injection screen (#375)
Adversarial review — REQUEST_CHANGESReviewed head The core fix is correct and the forgery vector is genuinely closed: RED reproduced at Scope note: this head is P1 — Legacy
|
| Mutation | Result |
|---|---|
M1 initAudited guard removed |
kills "a hand-written init-stamp row cannot suppress init" |
| M2 unparseable stamp accepted | kills "a stamp file that cannot be parsed is no stamp at all" |
| M3 stamp file ignored | kills 5 (the idempotency set) |
M4 stampError swallowed |
22 pass — claim 6 untested |
| M5 migration write failure treated as no-stamp | 22 pass — P2 above untested |
| M6 retag collapse reverted | kills 2 |
M7 markSuperseded throw escapes |
kills retag-repair finding (b) |
| M8 retag moved after the stamp check | kills 4, including "the repair runs even when init skips" |
No new test passes vacuously. M4 and M5 are coverage gaps, not vacuous tests.
…on report the truth Adversarial review of #376. Four defects in the pre-#374 stamp migration, each reproduced before the change and re-run after it. (1) P1 — the honoured row was not inert. `isInjectable` had no tag filter and `selectRelevant` none either, so a legacy `init-stamp` row still entered the rendered injection block and `memory_recall`, against the PR's claim that such rows "are inert: nothing reads them any more". Two changes close it. The migration now retires the row it copies, with the `markSuperseded` call retag.ts already uses. And `isInjectable` withholds the `init-stamp` tag from every model-facing read, because migration cannot reach a row whose `init_complete` audit line is gone and that row would otherwise ride the prompt forever. Store reads that are not model-facing — the viewer, memory_forget, memory_undo, export — still see it: this is about a row riding the prompt, not about hiding store contents. A retirement that is refused or throws never undoes the migration; its reason is returned in `StampRead.retireError` and reported as `stampRetireError`, in the shape retag.ts uses for a retirement that did not land. (2) P2 — a migration whose stamp file could not be written reported success. `readStamp` discarded `writeStampFile`'s return, so with the stamp directory at 0500 init answered `{"skipped":true,"migrated":true,"stampError":null}` with no file on disk, and every later init re-migrated and re-claimed success. The write error is threaded into `StampRead.stampError` and surfaced on the skip path as `stamp NOT recorded (...) — the migration will be retried`, alongside the run-path report that already existed. (3) P2 — the audit pairing did not bind the row's head. It checked only `fields.stamp === ts` and took the head from the row's own prose, so a row naming one head and colliding by millisecond with an init that stamped another suppressed init for a head no init ever stamped at. The head now comes from the evidence line the plugin wrote; the `stamp === ts` pairing is unchanged. (4) P2 — claim 6 had no coverage: `grep -rn "stampError|NOT recorded" test/` returned nothing, so swallowing `stampError` on the run path left the suite green. Both the run path and the migration path are pinned now. Nits from the same review: (5) `parseStamp` never checked the file's `key` against its filename, though the comment above it said a component the plugin did not mint is not authority. It now returns no stamp when the two disagree; `scope` and `path` stay descriptive, and the comment says so. (6) The pairing read only the row's own evidence day. `appendMemory` stamps the row at the millisecond it mints while `record()` writes to whatever day the line lands on, so an init crossing UTC midnight lost its migration. The audit reads the row's day and the one after it. Files: - src/core/tags.ts: INIT_STAMP_TAG, the one place the tag is named - src/store/model/predicates.ts: isInjectable withholds the tag - src/init/stamp.ts: retire after copy; head from the evidence line; audit the next day too; validate key against the file name; report both faults - src/init/run.ts: stampError and stampRetireError on both summaries and both evidence lines - src/init/format.ts: the reply says which half failed - test/init.test.ts: eight new tests Mutation evidence — each new test is RED with only its own fix reverted, GREEN with it restored: - isInjectable back to `isActive && !isQuarantined` -> "cannot ride the injection block or recall" - drop the retireLegacyStampRow call -> "the migration retires the audited row" - swallow the retirement throw -> "a retirement that does not land is reported" - drop stampRetireError from the skip summary -> same test - discard writeStampFile's return -> "a migration whose file write fails" - drop stampError from the run-path summary -> "a stamp write failure on the run path" - take the head from the row prose -> "a row naming a head the audit line does not name" - drop the `fileKey !== key` check -> "a stamp file naming a different key" - audit only the row's own day -> "an audit line that lands after midnight" Co-authored-by: OpenCode <[email protected]>
Nit from the #376 review: test/retag-repair.test.ts shipped seven lint diagnostics — six noNonNullAssertion and one useTemplate — which is why the branch sat at 548 warnings against main's 545. Each `rows.find(...)!` becomes `rows.find(...)` plus an optional-chain expectation. The strength is unchanged: a missing row now fails the expect instead of throwing a TypeError, and the two `toBeUndefined()` checks keep the length assertion immediately above them as their existence guard. No behaviour change; the four tests pass as before. Co-authored-by: OpenCode <[email protected]>
…acy stamp row Nit from the #376 review. The paragraph on the #375 repair said "each replacement carries its own write_promoted audit line" as an unconditional guarantee, but retag.ts counts replacements whose audit line fell as `unaudited` and format.ts reports them as "N without an audit line". The sentence now states the emission and the reporting of a fallen line, which is what the code does. The /repo-init step also gains the migration contract this branch implements: a store left by an older release is honoured only when an init_complete audit line names the row, at the head that line names; the row is then retired, and it is withheld from recall and injection either way. Co-authored-by: OpenCode <[email protected]>
# Conflicts: # src/core/tags.ts
#376 review findings: fixed and pushed (
|
| Mutation | Test it killed |
|---|---|
isInjectable back to isActive(m) && !isQuarantined(m) |
a legacy stamp row cannot ride the injection block or recall |
drop the retireLegacyStampRow call from readStamp |
the migration retires the audited row and still writes the file |
swallow the throw in retireLegacyStampRow |
a retirement that does not land is reported, and the migration survives |
drop stampRetireError from the skip summary |
a retirement that does not land is reported, and the migration survives |
discard writeStampFile's return on the migration path |
a migration whose file write fails is reported, not claimed |
drop stampError from the run-path summary |
a stamp write failure on the run path is reported (#374 claim 6) |
| take the head from the row's prose instead of the evidence line | a row naming a head the audit line does not name does not suppress init |
drop if (fileKey !== key) return null |
a stamp file naming a different key is no stamp at all |
auditDays returns only the row's own day |
an audit line that lands after midnight still migrates the row |
Eight new tests in test/init.test.ts. The unit suite went 1203 → 1278 passing
with the merge of main; the eight are the delta on this branch.
Gate
On the pushed head e696f84:
bun run typecheck— exit 0.biome lint— 545 warnings, which is exactlyorigin/main(ce36c65) at
545: this branch adds none. Measured before the merge it was 542 against this
branch's own 548 baseline, so the six warnings the PR had introduced are gone
and nothing replaced them.bun test ./test/— 1278 pass / 19 skip / 0 fail, 13441 assertions, 115
files.bun test ./e2e/ --timeout 240000— 30 pass / 0 fail, 255 assertions, 8
files.bun run gate— all green; the pre-push hook ran it and the push is the
result.
Merged origin/main into the branch
The PR was MERGEABLE at cfb0e0b and my own edit broke that: INIT_STAMP_TAG
lands in src/core/tags.ts at the same place main's CODE_CHECKED_TAG (#393)
does. Resolved as a union — both constants, main's first — which is the only
conflict in the merge. e696f84 is that merge; the gate above is measured on it.
Deliberately not fixed
memory_exportand the status counts still see a legacy row.export.ts
filters onisActive, andsummarizeStorecounts active rows and emits no row
content. Both are store-level surfaces, and the review's boundary was explicitly
"do not change whatmemory_forget/memory_undo/the viewer can see".- F5.1 validates
keyonly.scopeandpathin the stamp file are still
unchecked; they are written by the plugin, read by nothing that locates state,
and the comment now states that instead of overclaiming. - The
markSupersededreturned-falsebranch is untested. In this
environment a blocked store root makesmarkSupersededthrow (lock
acquisition), so the test exercises the throw path; thefalsebranch is a
defensive report for an out-of-band retirement racing the migration and is
reached only in a race the harness cannot pin without a process-wide module
mock, whichtest/retag-repair.test.tsalready shows leaks across files. - F5.3 reads two day files rather than deriving the day from the evidence
lookup. The review allowed either. Two days is the smaller change, cannot
widen the pairing window beyond the one millisecond of real risk, and is pinned
deterministically.
There was a problem hiding this comment.
Approving.
The round-2 findings are addressed at e696f84: the legacy init-stamp row is retired after migration and the tag is no longer injectable, a failed migration write is reported instead of swallowed, and the audit pairing takes the head from the evidence line rather than from the row it is checking. Each fix carries a test that is red without it.
Full gate green at this head and CI green on all four jobs. Not merged — the merge is left to a human.
|
🎉 This PR is included in version 0.23.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What
Moves the
/repo-initstamp out of the memory store and into a file under the memory root.The stamp used to be a
contextrow in the repository's scope taggedinit-stampwhose content named the current short HEAD. Nothing reserved that tag, so any session could write one withmemory_rememberand every latermemory_initanswered "Already initialized" for that commit and wrote no command rows — silently.src/init/stamp.tsnow owns it:<memory-root>/init-stamps/<repo-key>.json, holding{key, scope, path, head, ts}, read and written only bysrc/init/. The name is the repository identity key (origin hash, or path hash with no origin), so a re-clone keeps its stamp and two checkouts that merely share a directory basename never share one.memory_recall,memory_exportand the viewer no longer show internal state.Migration
Honouring "any row that looks like a stamp" is the forgery this ticket removes, so the one-time migration honours a pre-#374 row only when an
init_completeevidence line names its ts. Evidence is written only by the plugin's ownrecord()— no tool gives a session a write path to it — so the pairing is provenance a row cannot supply about itself. The row is copied to the file and left alone. A row no init audited is ignored and init re-runs: idempotent and cheap.A stamp file that cannot be written is reported on the tool reply (
stamp NOT recorded (…) — init will run again) instead of swallowed.Measured
Both runs on
mainatf8f42fdand the branch head, macOS, Bun 1.4.3, hermeticOPENCODE_MEMORY_DIR.RED — on
origin/main, a hand-written row naming the current HEAD:GREEN — same script on this branch:
Acceptance, line by line:
test("a hand-written init-stamp row cannot suppress init").test("idempotent: …").test("a store row an init audited is honoured once and migrated to the file").bun run gategreen: typecheck, lint, 1193 unit pass / 19 skip / 0 fail, terminal smoke + BDD 30 pass / 0 fail.Notes for the reviewer
memory_initand then reads its own evidence line could pair a stamp. That path performs an init rather than skipping one, so it buys nothing an attacker wants. The boundary this closes is the tool-facing one.test("a stamp file that cannot be parsed is no stamp at all").init_completestill carriesstamp=<ts>, now the file's ts, so the audit shape is unchanged.Closes #374