Skip to content

fix(store): key rejections on the value so a forgotten fact stays rejected (#35) - #194

Merged
abogartz merged 5 commits into
mainfrom
fix/rejection-tombstone-35
Oct 30, 2026
Merged

abogartz merged 5 commits into
mainfrom
fix/rejection-tombstone-35

Conversation

@abogartz

@abogartz abogartz commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Closes #35.

Review round (head 58ffced → e5b74ae). Two P2s from review are fixed; read this with them, because they change what the near-match section below means. (1) The reason a tombstone records is now scrubbed of recognized credentials at the write boundary, on the read path, and where the hint is built — prune() used to persist its raw reason and the hint echoed it. (2) The near-match no longer refuses a changed value: overlap scores a correction (0.800 for "30 days"→"90", 0.778 for "enable"→"disable") higher than an honest rewording, so no floor separates them. The tombstone now also records what the rejected statement asserted — num (hashed numbers) and pol (polarity signs) — and a value that has actually MOVED on a dimension vetoes the near-match instead — which means each side must assert something the other does not, so appended metadata ({30} vs {30, 2}) and a dropped value stay refused while 30→90 is released, and a negator that is itself a polarity word (never) composes with its predicate instead of also counting as its own sign. Round 3 of review fixed two regressions in the first version of that rule; see #194 (comment) NEAR_FLOOR=0.40 and the band below are unchanged; read the floor as "worth a second look at the values", not as a verdict on its own. Details, mutation results and the residuals that remain are in the reply: #194 (comment)

The gap

Nothing was keyed on a rejected value. The blocklist keys on ts; memory_forget/prune deletes the row outright. So re-ingesting the original source — the same transcript through auto-capture, the same export through memory_import — stored the rejected fact again with a fresh ts, as if it had never been turned down. Step 6 of the Atlas deletion-durability sequence, and the most-repeated gap in the field.

grep -rn "rejected.logfmt|previously_rejected" src/ was zero hits before this branch.

What ships

rejected.logfmt at the memory root, consulted at GATE-3 and enforced first in the GATE-4 block chain — a human decision outranks every heuristic below it. Both untrusted write paths (memory_import, auto-capture) already route through runWriteGate, so they inherit the check for free.

Two matching modes:

key why
exact sha1(content)[0:12] — the same ch the gates already emit on gate_start/write_promoted unambiguous, and searchable with identifiers telemetry already carries
near bottom-k sketch of the content's hashed token set closes the rewording hole: different bytes, same claim

Hashes only, never values (Atlas step-10 inversion: a deletion log that reproduces the deleted secret is a compliance problem). The sketch is one-way per token and carries no ordering, so the file cannot be read back as prose — strictly less revealing than deletions.logfmt, which stores forgotten prose verbatim by design.

Not snapshotted: snapshotFiles() walks memoryFiles(), which excludes RESERVED names — so memory_undo can neither resurrect nor erase a rejection.

Near-match is calibrated, not guessed

You said include near-match, and the reason to be careful is false positives: a wrong near-match silently eats a legitimate write. So I measured instead of picking a number.

rewordings of the SAME claim ......... 0.500 – 0.615
same topic, DIFFERENT claim .......... 0.059 – 0.235
unrelated ............................ 0.000

0.40 sits mid-gap with ~0.17 margin on both sides. It is also in family with the existing calibration — GATE-3 uses 0.9 for "reworded duplicate of a live row" and 0.3 for a decision/preference conflict, so this is the conflict-style band applied to a rejection. My first guess was 0.8; measurement showed a genuine rewording scores 0.47, i.e. the mechanism would never have fired. Worth saying out loud: the number came from the calibration, not from me.

NEAR_MIN_SHARED stops short content near-matching at all — small token sets score high against almost anything, so short content is refused only on an exact match.

Lifting is human-only

The viewer lists rejections and POST /api/unreject lifts one. There is deliberately no plugin tool for it: a session whose write was refused could otherwise clear its own refusal and re-submit the rejected value in the same turn, which would make the whole mechanism advisory. Same shape as the blocklist, which likewise has no unblock tool. The block hint carries the hash and says this explicitly.

block now tombstones the value; unblock withdraws it.

Red-first, and what I found by mutating it

The committed spec in negative-eval.test.ts said "un-skip this test — it must turn green without being edited." Un-skipped, unedited, green. scenarios-scripted.test.ts flipped to row absent, tally blocked — the exact outcome its own comment predicted.

Then I broke the mechanism three ways to check the suite actually bites:

mutant result
findRejection always undefined 12 die, incl. both acceptance specs
forget stops recording 5 die, incl. both acceptance specs
NEAR_FLOOR 0.4 → 0.05 0 die ← the gap

Mutant 3 surviving is the interesting one. My only over-blocking test used genuinely unrelated prose, which scores 0.0 against anything — so it stays green at any floor. "We do not over-block" was claimed and unpinned, and the guard actually doing the work was NEAR_MIN_SHARED, not the floor. Fixed in the second commit by pinning the calibrated 0.059–0.235 pairs ("same topic, different claim"); with the guard band collapsed it dies as it must, at shipped settings it passes.

A test bug surfaced the same way: the exact-match hint originally shipped without the escape-hatch text, so the common case was a reported dead end.

Two things worth your eye

  1. Scope is global, matching the file's location: repo A's rejection also declines repo B's byte-identical write. I read that as the honest meaning of "this value was rejected here", and it is liftable — but it is a real judgement call, not an oversight.
  2. memory_forget is a model-facing tool, so a model that prunes aggressively tombstones aggressively. Consequence is bounded (identical prose refused with an explicit hint, nothing destroyed) and it is what the ticket specified, but the honest mitigation is the viewer hatch rather than a design guarantee.

src/tokenize.ts holds the tokenizer moved verbatim out of gates.ts so the sketch and GATE-3 cannot drift on what a "token" is. Behavior there is byte-identical.

Gate

bun run gate: 739 pass / 11 skip / 0 fail unit, 11 pass / 0 fail terminal e2e, tsc clean, biome lint exit 0.

…ected (#35)

The blocklist keys on `ts` and prune deletes the row outright, so neither
survives re-ingestion: replay the source (a transcript through auto-capture,
an export through memory_import) and the rejected fact is stored again with a
fresh `ts`, as if it had never been turned down. Something has to be keyed on
the VALUE.

Adds rejected.logfmt at the memory root, consulted by GATE-3 and enforced first
in the GATE-4 chain -- a human decision outranks every heuristic below it. Two
matching modes:

  exact  sha1(content)[0:12], the same `ch` the gates already emit
  near   a bottom-k sketch of the content's hashed token set, which supports
         rewording detection WITHOUT storing the prose

The floor is calibrated, not guessed: rewordings of the same claim measured
0.500-0.615, same-topic/different-claim 0.059-0.235, unrelated 0.000, so 0.40
sits mid-gap. Short content can never near-match (a NEAR_MIN_SHARED token floor),
because small token sets score high against almost anything and a false positive
silently eats a legitimate write.

Hashes only, never values (atlas step-10 inversion: a deletion log that
reproduces what it deleted is a compliance problem). Not snapshotted, so undo
can neither resurrect nor erase a rejection.

Lifting is human-only by construction: the viewer lists rejections and exposes
/api/unreject, and there is deliberately no plugin tool for it -- a session whose
write was refused cannot clear its own refusal and re-submit. The block/unblock
pair now tombstones and withdraws accordingly.

Tokenizing moved to src/tokenize.ts so GATE-3 and the sketch cannot drift apart
on what a "token" is; behavior there is byte-identical.

Acceptance: the committed spec in negative-eval.test.ts that said "un-skip this
test -- it must turn green without being edited" is un-skipped and passes, and
the scenarios-scripted import case flipped to "row absent, tally blocked" as its
own comment predicted.

Suite: 738 pass / 11 skip / 0 fail. tsc clean; biome lint exit 0.
Found by mutating the mechanism and watching what survived, per #68's rule that
a test nothing dies on is fiction.

Three mutants run against the suite:

  1. findRejection always undefined ....... 12 tests die (both acceptance specs)
  2. forget stops recording the value .....  5 tests die (both acceptance specs)
  3. NEAR_FLOOR 0.4 -> 0.05 ...............  0 tests die   <-- the gap

Mutant 3 survived because the only over-blocking test used genuinely unrelated
prose, which scores 0.0 against the rejected value: it stays green at any floor,
so "we do not over-block" was claimed and unpinned. The guard that was actually
doing the work is NEAR_MIN_SHARED, not the floor.

Adds "a different claim in the same topic is NOT refused" over the calibrated
0.059-0.235 pairs -- same vocabulary, same subject, different claim. With the
guard band collapsed (floor 0.05 + min-shared 2) it dies as it must; at the
shipped settings it passes. Refusals are collected and asserted as an empty list
so a failure names the vetoed claim and the hint that vetoed it.

Also fixes the un-reject tool scan: invoking every registered tool included
memory_init, which spawns the external indexer and timed out the test under the
parallel workers. The scan now excludes it explicitly and asserts the tool-name
shape separately.
Investigating the Windows CI failure (run 41112466339) landed a real bug in the
feature, plus a hot-path cost that should not have shipped.

ATTRIBUTION. test-windows failed twice on this branch and nowhere else: main was
green repeatedly today, and the sibling scenario that also failed ("the viewer
deleting and editing while another session writes") failed identically on
fix/gate-evidence, which carries none of my changes -- that one is the known
Windows load family. The prune scenario, however, failed 2/2 here and not once on
main, and it exercises the function I changed: "a prune sweep while another
session is appending", 4704 of 5700 untargeted rows vanished.

Mechanism, per src/lock.ts: the store lock gives up after 5s and PROCEEDS
unlocked ("strictly no worse than the alternative" -- unless another writer is
mid read-modify-write, which is exactly the case here). prune() was making that
window far more expensive to wait behind.

THE BUG THIS FOUND. tombstone() did a full read of rejected.logfmt plus a lock
create/unlink pair PER VALUE. memory_forget deletes by scope+type and routinely
removes hundreds of rows, so one forget issued hundreds of lock cycles while
other sessions were writing. Batching to one read / one lock / one append cut a
320-row forget from 154ms to 26ms locally, and removes ~99% of the file ops from
the scenario's critical path.

Batching then exposed a second bug, which is the one that actually mattered:
formatLine returns NO terminator, so joining the batch with "" published every
record as a single line, of which only the first parsed. A bulk forget of 40
values therefore recorded ONE rejection and silently dropped 39 -- the core
promise of #35, broken in its most common shape. Nothing caught it because no
test in the suite had ever forgotten more than one value at a time. Pinned by
"a bulk forget records EVERY value, not just the first" (40 rows -> 40 tombstones
-> 40 gate refusals -> 40 lines on disk); re-introducing the join kills it.

Also caches the tombstone read. findRejection runs on EVERY gated write, so the
mechanism this branch adds also added a full read of every rejection ever
recorded to every write. Cached on fileIdentity rather than a TTL, because a
human lifting a rejection in the viewer process must be seen by the next write in
this one -- a TTL would keep refusing a value for its duration after they said
otherwise. Reset hook added to the #149 isolation preload, since it is a module
global outliving a test file.

Local: bun run gate all green -- 751 pass / 0 fail unit, 11/0 e2e, tsc clean.
Windows verdict on this commit is the experiment that decides attribution.
@abogartz

Copy link
Copy Markdown
Owner Author

Windows: what actually happened

Investigated rather than re-run until green. Two distinct problems were tangled together, and only one was mine — but that one was real and it was not a timing flake.

Not mine. the viewer deleting and editing while another session writes failed identically on fix/gate-evidence, which carries none of my changes, and auto-capture end-to-end has failed on fix/gate-reader. Windows flaked on ~15% of runs today across unrelated branches. This is the load family the repo is already working (the ci/parallel-tests branch, 854ca46 budgeting the import scenario, #190 instrumenting ACL phase timings).

Mine. a prune sweep while another session is appending failed 2/2 with 4704 of 5700 untargeted rows vanished, and never once on main. That is data loss, not a slow test:

run commit windows failing
41112466339 a1 per-row tombstones fail prune (4704 rows lost) + viewer
41112466339 a2 per-row tombstones fail prune only
41115615447 a1 58ffced batched pass —
41115615447 a2 58ffced batched fail auto-capture compaction ×2 (unrelated)
41115615447 a3 58ffced batched pass —

Mechanism, straight out of src/lock.ts: DEFAULT_TIMEOUT_MS = 5_000 and the default degraded mode proceeds unlocked — documented as "strictly no worse than the alternative," which is untrue behind another writer's whole-file read-modify-write. prune() was issuing a tombstones() read plus a lock create/unlink pair per deleted value. memory_forget deletes by scope+type, so one forget meant hundreds of lock cycles against a day file two child processes were hammering, and starved writers proceeded through prune's publish window.

Batched to one read / one lock / one append: 154 ms → 26 ms on a 320-row forget, and the prune scenario has failed 0/3 since.

The bug the flake was hiding

Batching surfaced a genuine correctness bug that had nothing to do with Windows: formatLine() returns no terminator (appendLog adds the one). My first batch joined with "", so 40 records landed as a single line and only the first parsed — a bulk forget of 40 values recorded one rejection and silently dropped 39. That is the entire promise of #35 broken in its most common shape, and my suite could not see it because every test before this wrote exactly one value per call.

Pinned by a bulk forget records EVERY value, not just the first: 40 rows → 40 tombstones → 40 gate refusals → 40 lines on disk. Re-introducing the "" join kills it (verified).

Also addressed: findRejection runs on every gated write, so the mechanism added a full tombstone read to every write. Cached on fileIdentity rather than a TTL — a human lifting a rejection in the viewer process must be seen by the next write in this one, and a TTL would keep refusing a value after they said otherwise. Measured rather than assumed for overall cost: same command, two runs each, main 35–37 s vs this branch 37 s while running 17 more tests.

Where that leaves the review

The remaining Windows red is ambient and I have deliberately not bumped any test timeout to force green — that would paper over the family rather than fix it, and #190 plus 854ca46 show it's already being worked properly. Current head is green on the latest attempt, and every test that failed for a reason belonging to this branch now passes.

bun run gate locally: 751 pass / 0 fail unit, 11/0 e2e, tsc clean, biome lint exit 0.

@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.

Review of 58ffced56fcc0de348889cfc316db09267bfc72c: two P2 findings to resolve before merge. The batch-forget regression test passes, and I see the latest CI is green. These are separate from the Windows timing failures described above.

[P2] Redact forget reasons at the new tombstone write boundary — src/tombstones.ts:220.

prune() passes its raw reason into tombstoneMany, which persists opts.reason directly. The existing deletion audit scrubs recognized credentials, but the new rejected.logfmt file does not; src/gates.ts:674 then copies that reason into the model-facing refusal hint. With a synthetic token ("ghp_" + "a".repeat(36), confirmed recognized by redactSecrets), forgetting a harmless fact leaves the deletion audit redacted but writes the token verbatim to the rejection file and returns it on replay. Please scrub metadata at the shared tombstone write boundary and ensure hints cannot return unsanitized reasons, with regression coverage for both destinations.

[P2] Near-match treats changed values and opposite instructions as the rejected fact — src/tombstones.ts:276.

The same-topic calibration misses high-overlap corrections. After storing and forgetting each first statement, these grounded replacements are both blocked as previously_rejected:

  • the production service retains audit records for 30 days before cleanup → the same statement with 90 days: score 0.8.
  • the service must enable anonymous access for production control endpoints → the same statement with disable: score 0.7777777777777778.

Both are different facts, and both promote on the base. They score above the intended rewordings, so increasing the scalar threshold alone cannot preserve the documented 0.500–0.615 rewordings while allowing these corrections. Please include numeric-value and polarity changes in calibration and distinguish them before an authoritative near-match refusal. This is about the stated different-claim contract, not an objection to adding near matching. The current escape hatch requires lifting the rejection of the old, wrong fact to accept its correction.

Validation: Windows x64, Bun 1.4.4. At the reviewed head, bun test test/tombstones.test.ts test/review-194.test.ts gives 17 existing tests passing / 3 added probes failing, reproduced twice. The same three behavioral controls pass against production base 525ed89 (only adapting the new tombstone imports/file absence for the base). This was focused validation, not another full gate run. No changes pushed to your branch and no duplicate issues opened.

Additional test file: test/review-194.test.ts
import { beforeEach, afterEach, test, expect } from "bun:test";
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { runWriteGate } from "../src/gates.ts";
import { prune, loadAll } from "../src/memory.ts";
import { resetSessionScopes, setRepoScope } from "../src/repokey.ts";
import { resetState } from "../src/state.ts";
import { resetTombstoneCache, rejectedFile } from "../src/tombstones.ts";
import { redactSecrets } from "../src/secrets.ts";

let root: string;
beforeEach(() => {
  root = mkdtempSync(join(tmpdir(), "osi-review194-"));
  process.env.OPENCODE_MEMORY_DIR = join(root, "memory");
  process.env.OPENCODE_COMMANDS_DIR = join(root, "commands");
  resetState(); resetSessionScopes(); setRepoScope(null); resetTombstoneCache();
});
afterEach(() => {
  resetState(); resetSessionScopes(); setRepoScope(null); resetTombstoneCache();
  delete process.env.OPENCODE_MEMORY_DIR; delete process.env.OPENCODE_COMMANDS_DIR;
  rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
});
const promote = (content: string) => runWriteGate({ type: "learning", scope: "review", content }, {
  liveRoot: root, evidenceCalls: [], hasGateCheck: true, hasEngagement: true,
});

test("forget reasons remain redacted in the new tombstone and replay hint", async () => {
  const token = "ghp_" + "a".repeat(36);
  expect(redactSecrets(token)).toBe("[redacted]");
  const content = "the production service records every completed deployment";
  expect((await promote(content)).action).toBe("promoted");
  await prune("review", "learning", `rotated ${token}`);
  const deletion = readFileSync(join(root, "memory", "deletions.logfmt"), "utf8");
  expect(deletion).not.toContain(token); // pre-existing boundary still scrubs it
  const rejected = readFileSync(rejectedFile(), "utf8");
  const replay = await promote(content);
  console.log(JSON.stringify({ probe: "reason", tombstoneLeaks: rejected.includes(token), hintLeaks: replay.hint?.includes(token), replayAction: replay.action }));
  expect(rejected).not.toContain(token);
  expect(replay.hint).not.toContain(token);
});

test.each([
  ["numeric value", "the production service retains audit records for 30 days before cleanup", "the production service retains audit records for 90 days before cleanup"],
  ["opposite action", "the service must enable anonymous access for production control endpoints", "the service must disable anonymous access for production control endpoints"],
])("a different fact survives rejection of the old fact: %s", async (kind, rejected, corrected) => {
  expect((await promote(rejected)).action).toBe("promoted");
  await prune("review", "learning", "wrong policy");
  const next = await promote(corrected);
  console.log(JSON.stringify({ probe: kind, action: next.action, reason: next.reason, hint: next.hint }));
  expect(next.action).toBe("promoted");
  expect((await loadAll()).map((m) => m.content)).toContain(corrected);
});

@abogartz

Copy link
Copy Markdown
Owner Author

Residual filed as #196 (severity high): the underlying mechanism this PR tripped — LOCK_WRITE proceeds unlocked past the 5 s budget, and the comment on that option claims it "never costs a user their write," which the 4704-row loss contradicts. Six whole-file publishers are exposed; snapshot restore is the only one that already fails closed. Nothing in this PR needs to change for that.

@abogartz

abogartz commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner Author

Both P2s addressed — 846ad03

Reproduced both before changing anything, on 58ffced. Your numbers are exact: 0.800 (shared 8) and 0.7778 (shared 7), and the honest rewordings in the suite measure 0.5385 / 0.5455 / 0.5000. That settles the mechanism for me: the corrections are not lower-scoring rewordings, they are higher-scoring different statements, so the floor cannot be the instrument — releasing the 0.8 correction needs a floor above 0.8, which releases nothing between 0.615 and 0.8 and blocks every rewording the near-match exists for.

Your three probes ran verbatim against the fix (3/3 green; they were the same 3 red at the reviewed head). I folded the cases into test/tombstones.test.ts rather than committing a second file.

1. Redaction at the tombstone write boundary

redactSecrets now sits at three points, in this order:

seam why it is there
tombstoneMany, before formatLine the boundary you named — one place, so no future caller has to remember. viewer/mutate.ts already scrubbed at its call site; it now scrubs twice, harmlessly
tombstones(), on the way out the single read path behind both the refusal hint and the viewer's Rejections panel, and the only thing that covers rows already on disk from the pre-fix head
gates.ts, where the hint is built the seam where the field becomes a model-facing sentence

Pinned: a ghp_… token in a prune reason is absent from rejected.logfmt and from the replay hint (via a real forget, not a hand-written fixture), and a hand-written dirty row is clean by the time it leaves tombstones(). Mutants: remove the write-boundary scrub → the first spec dies; remove the read scrub → the second dies. Remove the hint-side scrub → nothing dies, because the two layers behind it are pinned. That third layer is deliberately redundant and its comment says so instead of pretending to be tested; the guarantee lives on the read path, where it also covers the viewer.

2. A changed value is not the rejected fact

The tombstone now records what the rejected statement asserted on the two dimensions overlap cannot see:

  • num — hashes of the numeric tokens (30, 3.19, 9ae0998),
  • pol — the polarity signs, from a closed antonym table plus explicit negation.

differsIn vetoes the near-match when both sides assert a dimension and disagree. Still no prose in the file: num is a hash and pol is a label from a two-value vocabulary, which is also why recording it reveals nothing about the sentence.

Three judgement calls worth your eye:

  • A dimension counts only when both sides assert it. If a value merely disappearing counted, deleting "30 days" from a rejected sentence would be enough to resubmit it. So [] (tracked, asserted nothing) never vetoes.
  • A row written before the fields existed (undefined, distinct from []) asserts nothing, so it decides exactly as shipped. Pinned explicitly so the degradation is a decision rather than an accident; every row from here on carries both.
  • Signs carry no word identity. enable, allow, permit all reduce to pos, so a synonym rewording is still caught (0.600 against the enable rejection, refused), while enable ↔ disable cannot be. Cross-group synonymy was the reason for collapsing groups into signs: allow vs enable as separate groups would have created false vetoes.

Match selection falls through: the guard runs per candidate, so the strongest non-vetoed match wins even when a vetoed one scores higher. That case is real — "must not enable…" scores 0.889 against the rejection of ENABLE (a polarity flip, correctly not the rejected fact) and 0.700 against the rejection of DISABLE, which it does restate. The spec asserts which hash the hint names, not merely that it refused, so "strongest wins" dies.

Declined matches emit ev=rejection_vetoed … differs=numeric_value action=allow_different_fact, so "is the guard too eager?" becomes a query against the field instead of an argument.

Mutants (each applied alone, suite re-run, reverted)

mutant dies
differsIn always undefined (guard removed) 3 — both correction specs + the veto audit
veto whenever signatures differ, including where one side asserts nothing 2 — the rewording guarantee (all four restatements leak) + the pre-tracking degradation
selection ignores the veto (strongest match wins) 4
negation stops composing 2
write-boundary scrub removed 1
read-path scrub removed 1
hint-side scrub removed 0 — redundant by construction, see above

What is still true after this, stated rather than buried

  • The guard covers numbers and polarity, as scoped. A swapped non-numeric value stays caught by the sketch: "writes checkpoints to the prod bucket" → "staging" scores 0.778 with both signatures equal, so it is still refused and the human hatch is the answer. The table is closed-vocabulary on purpose; this is not an attempt to understand a claim.
  • A sign that is merely absent leaves the sketch to decide. "more/less" and "on/off" are excluded for that reason — they live in ordinary prose, and a false veto releases a value a human rejected, which is the expensive direction.
  • memory_forget remains a model-facing tool, so an aggressive prune still tombstones aggressively. Unchanged from the round-1 note.

Drive-by: dropped tombstone and type Rejection from gates.ts's import (biome noUnusedImports, pre-existing at your head, on a line I was already in).

bun run gate: 750 pass / 11 skip / 0 fail unit, 11 / 0 terminal e2e, tsc clean, biome exit 0 at the 409-warning baseline. No new files, locks, or I/O in the write path, so nothing here touches the #196 load family.

…iew)

Addresses both P2 findings from review of 58ffced.

1. Scrub the reason at the tombstone boundary. `prune()` passed its raw
   `reason` straight into `tombstoneMany`, which persisted it verbatim, and
   gates.ts then copied it into the model-facing refusal hint — so a
   credential in a forget reason landed in `rejected.logfmt` and came back on
   replay, while the deletion audit beside it was correctly redacted. Now
   scrubbed on the way in (one boundary, so no future caller can forget), on
   the way out of `tombstones()` (the single read path feeding both the hint
   and the viewer, which also covers rows already on disk), and again where
   the hint is built, since that is the only place the string reaches a model.

2. A near-match no longer refuses a changed value. Overlap cannot separate a
   rewording from a correction because a correction scores HIGHER: against a
   rejected "retains audit records for 30 days", the same statement with 90
   days scores 0.800 and "must disable" against "must enable" scores 0.778,
   while honest rewordings measure 0.500-0.615. So raising the floor was never
   the answer. The tombstone now records what the rejected statement ASSERTED
   on the two dimensions overlap cannot see — its numeric tokens (hashed) and
   its polarity signs (a two-value label, so nothing about the prose is
   recoverable) — and a disagreement on a dimension BOTH sides assert vetoes
   the near-match instead of refusing.

   A dimension counts only when both sides assert it: a value that went
   missing in a rewording is not evidence of a change, or dropping "30 days"
   from a rejected sentence would smuggle it back in. A row written before
   value tracking existed asserts nothing, so it decides as shipped.

   The guard runs per candidate, so the strongest non-vetoed match still wins
   when a vetoed one scores higher — the case that motivated this: "must not
   enable" scores 0.79 against a rejection of ENABLE (correctly not the same
   fact) and 0.70 against the rejection of DISABLE, which it does restate.

   A declined near-match is recorded as `rejection_vetoed` with the dimension
   that said "different fact", so whether the guard is too eager is a measured
   question rather than an assertion.

Drive-by: dropped the unused `tombstone`/`Rejection` imports from gates.ts.

Verification: the reviewer's three probes (reproduced verbatim, run locally)
pass; the two must-not-regress specs — the rewording guarantee and the
pre-tracking degradation — were green before this commit and stay green;
`bun run gate`: 750 pass / 11 skip / 0 fail unit, 11/0 e2e, tsc clean,
biome exit 0 at the 409-warning baseline.
@abogartz
abogartz force-pushed the fix/rejection-tombstone-35 branch from 03db0fd to 846ad03 Compare October 30, 2026 20:27

@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.

Re-review at 846ad036bb447d4de120519739844c02ac765b2e (current head): the original credential-reason leak and both original correction probes are resolved. I independently ran the three original probes plus the expanded committed tombstone suite: 30 pass / 0 fail, Windows x64, Bun 1.4.4. The read-path scrub also covers the legacy dirty-row case as intended. All four hosted checks are green.

Two P2 regressions remain in the new veto logic. Both violate its stated restatement guarantee: my additional tests pass at the previous head 58ffced (blocked) and fail at this head (promoted and stored).

[P2] Additional numeric metadata is treated as a changed existing value — src/tombstones.ts:220.

Forget the production service retains audit records for 30 days before cleanup, then submit that exact statement with (policy revision 2) appended. The retention claim still says 30 days, the sketch score is 0.75 with 9 shared tokens, but the new write is promoted. differsIn sees {30} versus {30,2} as disagreement even though the rejected numeric value remains intact. The same numeric token set with extra metadata is not evidence that the rejected value was corrected. Please distinguish a changed assertion from added/removed numeric metadata before granting the veto, and pin this counterexample alongside 30→90.

[P2] never contributes a standalone sign as well as negating the following verb — src/tokenize.ts:176–180.

Forget the service must enable anonymous access for production control endpoints, then submit the service must never disable anonymous access for production control endpoints. This restatement scores 0.70 with 7 shared tokens but is promoted. polaritySigns("not disable") returns ["pos"], while polaritySigns("never disable") returns ["neg","pos"]: never adds neg immediately, then negates disable to add pos. The unequal-set veto releases the restatement. Please compose a negator with its predicate without also retaining the standalone negator sign for that construction; pin the end-to-end refusal as well as the signature.

These are regressions introduced by the new guard. The explicitly documented non-numeric prod/staging limitation is a separate scope decision. No changes pushed to your branch. Keeping the review at changes requested for these two cases; the original findings should not be counted as still open.

Additional reproducer: test/review-194-veto.test.ts
import { beforeEach, afterEach, test, expect } from "bun:test";
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { runWriteGate } from "../src/gates.ts";
import { prune, loadAll } from "../src/memory.ts";
import { resetSessionScopes, setRepoScope } from "../src/repokey.ts";
import { resetState } from "../src/state.ts";
import { resetTombstoneCache, rejectedFile } from "../src/tombstones.ts";
import { redactSecrets } from "../src/secrets.ts";

let root: string;
beforeEach(() => {
  root = mkdtempSync(join(tmpdir(), "osi-review194-"));
  process.env.OPENCODE_MEMORY_DIR = join(root, "memory");
  process.env.OPENCODE_COMMANDS_DIR = join(root, "commands");
  resetState(); resetSessionScopes(); setRepoScope(null); resetTombstoneCache();
});
afterEach(() => {
  resetState(); resetSessionScopes(); setRepoScope(null); resetTombstoneCache();
  delete process.env.OPENCODE_MEMORY_DIR; delete process.env.OPENCODE_COMMANDS_DIR;
  rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
});
const promote = (content: string) => runWriteGate({ type: "learning", scope: "review", content }, {
  liveRoot: root, evidenceCalls: [], hasGateCheck: true, hasEngagement: true,
});

test.each([
  ["additional numeric metadata", "the production service retains audit records for 30 days before cleanup", "the production service retains audit records for 30 days before cleanup (policy revision 2)"],
  ["equivalent never-negation", "the service must enable anonymous access for production control endpoints", "the service must never disable anonymous access for production control endpoints"],
])("a restatement must stay rejected: %s", async (kind, rejected, repeated) => {
  expect((await promote(rejected)).action).toBe("promoted");
  await prune("review", "learning", "wrong policy");
  const replay = await promote(repeated);
  console.log(JSON.stringify({ kind, action: replay.action, reason: replay.reason }));
  expect(replay.reason).toBe("previously_rejected");
  expect((await loadAll()).map(row => row.content)).not.toContain(repeated);
});

…d 3)

Both findings are regressions in the veto added in the previous commit, and both
came from the same shortcut: treating "the signatures differ" as "the assertion
changed".

1. Added numeric metadata. "{30}" vs "{30, 2}" — the rejected claim still says
   30 days, with a revision number appended — vetoed the near-match and stored
   the restatement. A dimension has moved only when EACH side asserts something
   the other does not, so extension (a note, a revision, a count appended to the
   sentence) is refused, omission stays refused (that is the path where dropping
   "30 days" would release the claim), and 30→90 stays released — as does
   "30 days with 5 copies" → "90 days with 5 copies", which is the pair that
   rules out a "no numbers in common" rule satisfying the same cases by accident.

2. `never` counted twice. It is both a term in the antonym table and a word that
   negates what follows, so "must never disable" contributed `neg` for itself and
   `pos` for the flipped verb — both signs, no match, restatement stored. A
   dual-role negator now holds its own sign back and lets the flipped predicate be
   its contribution; standalone, with nothing in its span ("the job never runs"),
   its own ban is still all there is and still counts.

Pinned: both reproducers (run verbatim, 2/2 green), the signature-level pins for
the composition, and the shared-number correction pair.

Verification: `bun run gate` 752 pass / 11 skip / 0 fail unit, 11/0 e2e, tsc
clean, biome exit 0 at the 409-warning baseline. Mutants, each alone: round-2
set-inequality rule restored → the restatement spec dies; disjointness in place
of each-side-moves → the shared-number spec dies; a held negator never released
→ the standalone `never` pins die.
@abogartz

Copy link
Copy Markdown
Owner Author

Both regressions fixed — e5b74ae

Reproduced both as red specs against 846ad03 first: your scores are exact again (0.750 / shared 9 and 0.700 / shared 7), and polaritySigns("the service must never disable …") did come back ["neg","pos"].

They share one root cause, and it is mine: I wrote the veto as "the signatures differ" and then named it "the assertion changed". Those are not the same predicate. A rejected statement's assertion is replaced only when each side names something the other does not:

function moved(a: string[], b: string[]): boolean {
  const sa = new Set(a);
  const sb = new Set(b);
  return a.some((x) => !sb.has(x)) && b.some((y) => !sa.has(y));
}

1. src/tombstones.ts — extension and omission are not disagreement.

rejected nums incoming nums reading now
{30} {90} each names a number the other does not → moved veto, stored
{30} {30, 2} the rejected 30 is still asserted; 2 is appended metadata refused
{30, 90} {30} something was only dropped — the path where deleting "30 days" releases the claim refused
{30, 5} {90, 5} 5 is shared metadata, 30 → 90 moved veto, stored

That last row is why I did not implement it as "no numbers in common": a disjointness rule passes the 30→90 case by accident and silently refuses a correction that keeps any number in place. It is pinned (a value change vetoes even when both statements share another number, 0.833 / shared 10), so the rule can't quietly slide back.

2. src/tokenize.ts — a dual-role negator no longer counts twice.

never is both a table term (it asserts a prohibition) and a word that negates what follows, so "never disable" contributed neg for itself and pos for the flipped verb: two signs, no match, restatement stored. A negator that is also a table term now holds its own sign back; if something in its span consumes the negation, that flipped predicate is its entire contribution. If nothing does, the word's own ban is all there is and still counts:

polaritySigns("must never disable anonymous access") = ["pos"]   // restates "enable"
polaritySigns("must never enable anonymous access")  = ["neg"]   // still a reversal
polaritySigns("the job never runs")                  = ["neg"]   // standalone
polaritySigns("we never allow it and never log it")  = ["neg"]

Your reproducer ran verbatim: 2/2 pass, both previously_rejected, neither stored. Both cases are also committed — in the restatement list (so they are refused end-to-end and the hint must name the right rejection) and at the signature level.

Mutants at e5b74ae (each applied alone, suite re-run, reverted)

mutant dies
round-2 rule restored: veto on any signature difference 1 — the restatement spec
disjointness instead of each-side-moves 1 — the shared-number spec
a held negator is never released as its own sign 1 — the composition spec
guard removed (differsIn → undefined) 5
selection ignores the veto 5
negators disabled 3
write-boundary / read-path scrub removed 1 each
hint-side scrub removed 0 — the layer is redundant behind two pinned ones, as before

Where the line now sits, stated plainly

A correction that names both the old and the new value — "retained for 90 days, up from 30" — is a superset of the rejected numbers, so it reads as extension and stays refused. That is not an oversight of the fix, it is the cost of the rule the finding asks for: from a token set, "the value was corrected to 90 and the 30 mentioned for context" and "the rejected claim plus a revision number" are the same shape. I took the side that refuses, because the escape hatch is a human click while a wrong veto silently discards a write; ev=rejection_vetoed still counts the ones that are released. The prod/staging limitation you scoped out is unchanged.

bun run gate: 752 pass / 11 skip / 0 fail unit, 11 / 0 e2e, tsc clean, biome exit 0 at the 409-warning baseline.

@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.

Approved at e5b74ae07e6b986cd668a34075f416095c6413b7. This supersedes my two earlier CHANGES_REQUESTED reviews: all four reported findings are resolved at this head.

Independently verified on Windows x64 / Bun 1.4.4:

  • Re-ran both original reproducer files verbatim, alongside the committed tombstone suite: bun test test/tombstones.test.ts test/review-194.test.ts test/review-194-veto.test.ts — 34 pass / 0 fail.
  • The credential reason is scrubbed on disk and in the replay hint; the committed dirty-row test covers the read path for existing files.
  • The 30→90 and enable→disable corrections still promote.
  • The unchanged 30-day rule plus revision metadata and the enable→never-disable restatement are now refused and remain absent from the store. Those same two tests failed at 846ad03 during the prior review.
  • Inspected the delta: the bidirectional set-difference check rejects extension/omission as evidence of replacement, while the shared-number correction test keeps it from degenerating into a disjointness rule. The held-sign logic composes never with its predicate and retains its standalone sign when unconsumed.

All four hosted checks are green on this exact head. My local validation was the focused re-review above, not a repeat of the full gate.

The documented heuristic limits remain: a correction mentioning both old and new values can still be refused, non-numeric substitutions can still require the human escape hatch, and tombstones predating value signatures retain the earlier matching behavior. Those are explicit scope decisions, not unresolved instances of my four findings. This approval does not claim general semantic equivalence detection.

No further changes requested from this review. Merge timing remains yours; #196 is separately covered by #197.

@abogartz
abogartz merged commit 4d337e9 into main Oct 30, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.14.25 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

P0: Value-keyed rejection tombstone — rejected content must stay rejected across re-ingestion

2 participants