Repository navigation
fix(gate): allow explicit Git history pointers to retired paths - #459
Conversation
|
Author follow-up after #464: I ran |
abogartz
left a comment
There was a problem hiding this comment.
Reviewed 7270eba (including 0dbbe54). Every claim below was run against the PR head in a throwaway worktree, not read off the diff.
The carve-out is syntax, so it launders a hallucinated path.
src/gate/resolver.ts:173: 🔴 high: nothing checks that a pointer's path ever existed, so the documented form exempts an invented one. `"Retired: \`git log -- poc-999/never-a.ts\`."` → refs `[]`, action `promoted`; the same path unwrapped → `ref_path_missing`. Three invented pointers in one row → promoted. Verify the path in history before exempting it, or require at least one live checkable ref in any row that carries a pointer.
scripts/ref-fixer.ts:323: 🔴 high: the auditor reads the same span helper, so an invented pointer passes the write gate and is dropped from `reported` as well — it never reaches "dead paths left for a human". This script already indexes whole history at line 266; keep the row in the report unless history confirms the path.
src/gate/gate.ts:910: 🟡 medium: the refusal hint still says "drop the path or fix it" and never names the new form, and `src/core/guidance.ts` says nothing about path refs. The model at the moment of refusal is steered to do exactly what #447 objects to. Put the convention in the hint.
test/gate/path-refs.test.ts:154: 🟡 medium: the new cases pin escaped and nested spans (both verified blocked), but the row whose entire content is an invented pointer is asserted `promoted`, and no test anywhere asserts a fabricated pointer is caught. Add that case with the history check.
docs/internals/write-gates.md:17: 🟡 medium: the doc says "a single backticked command" and never states that the gate does not check the path ever existed. Verified: unlimited occurrences are exempt — three pointers in one row give refs `[]`. State both limits where people read them.
src/gate/resolver.ts:170: 🟡 low: the accepted spelling is narrow and the block gives no reason. Verified still `ref_path_missing`: `` `git show -- x.ts` ``, `` `git log --follow -- x.ts` ``, `` `git log -- x.ts ` `` with a trailing space, two spaces after `--`, `Git log`, and any multi-path command. Three of those are pinned as intended at `test/gate/path-refs.test.ts:166`; the rest are surprises an author resolves by deleting the pointer. Accept `git show` and intervening flags, or name the exact accepted form in the hint.
src/inject/attribution.ts:88: 🟡 low: `deriveMemoryRefs` still calls `extractPathRefs`, so a retired pointer counts as a live cited path in Tier B, and `pathHit` matches on basename — a pointer to `poc-409/casebank/gate-e2e.ts` scores "re-read" against any opened `*/gate-e2e.*`. Use the span helper so attribution agrees with the gate.
package.json:80: 🟡 low: a third runtime dependency (`@lezer/markdown`, plus `@lezer/common` and `@lezer/highlight`) for one span check, while #464 is open to shed dependencies so a loose copy under `~/.config/opencode/plugins` loads without `node_modules`. It does not newly break that case — zod already does — and the parse is lazy and cheap, but a twenty-line backtick-boundary scan would do the same job. Record the choice in an ADR or a line in `docs/reference/install.md`.
scripts/ref-fixer.ts:381: 🟡 low: nothing migrates the 18 rows #447 measured. They stay dead and keep appearing in every report until a human reword them by hand. Print the exact `git log -- <path>` spelling in the "dead paths left for a human" block.
Verified, in favour of the change
test/gate/path-refs.test.tsandtest/gate/ref-fixer.test.ts: 46 pass.bun run typecheckclean.- No existing test was edited or weakened; both files are additions only.
- The
0dbbe54correction works as claimed. Escaped opening backtick and a command nested in a double-backtick example both stay live and block. - Parsing really is conditional. Measured
checkablePathRefsat the 10 KB cap: 52.9 ms per call with a candidate on this PR, 52.9 ms onmain. The cost is the pre-existing regex scan, not the parser. Worth its own issue, not this one. - The live-citation rule holds: a pointer plus a current mention of a ghost path still blocks, and the pointer's own path stays checkable when mentioned plainly.
- The stale e2e note is stale in your favour: the two viewer EBUSY failures you reproduced on
bd419e3are what #458 fixed, and the head now contains it.
Verdict: block. One required change: verify a history pointer against git history before exempting it. gate1 is already async and the plugin already spawns git for identity and availability (src/identity/repokey.ts:55, src/capture/available.ts:316), so a git log --format=%H -1 -- <path> limited to pointer-bearing rows fits the existing pattern. Until that lands, a pointer should not be able to carry a row to promoted on its own.
— identified as an AI Assistant
abogartz
left a comment
There was a problem hiding this comment.
Re-reviewed at 88dad8a. The blocker is closed. Everything below was run against this commit in a throwaway worktree with full history.
The laundering hole is gone. Same probe as last round, against a real checkout:
fabricated pointer → ref_path_missing blocked
three fabricated pointers in one row → ref_path_missing blocked
verified retired path → promoted
path renamed away (old spelling) → promoted
verified pointer + one invented pointer → ref_path_missing blocked
verified pointer + live ghost citation → ref_path_missing blocked
`../../etc/passwd.ts` → ref_path_missing blocked
liveRoot that is not a git checkout → ref_path_missing blocked
escaped backtick / nested code example → ref_path_missing blocked
Partial laundering is closed too, which is the case I would have expected to slip: one real path in the row does not buy a free pass for the invented one next to it.
Each earlier finding, checked
src/gate/resolver.ts:203—missingHistoryPathswalks HEAD's file names with--literal-pathspecs,--no-renames,--diff-filter=AD, and any pointer it cannot confirm becomes a missing path.catchreturns all paths, so a missing git, an unborn HEAD or a timeout refuses rather than exempts. That is the right direction to fail.scripts/ref-fixer.ts:325— the auditor no longer loses the pointer:deadis seeded frommissingHistory, so an unverified pointer lands in "dead paths left for a human" and instillMissing, and the block now prints the exactgit log -- <path>reword.src/gate/gate.ts:910— the hint names the accepted form and states that each pointer must exist in this checkout's history. The model at the moment of refusal is no longer told to delete the path.src/inject/attribution.ts:88— fixed by narrowingextractPathRefsto live matches, so a pointer no longer earns Tier B path credit. Both consumers checked: attribution, and one length-guard test. Pinned bytest/inject/attribution.test.ts:52.docs/internals/write-gates.md:17— now says the gate verifies against HEAD's history, that unavailable history refuses, that the exact spelling matters, and that the repair report lists unverified pointers.test/gate/path-refs.test.ts— the fabricated case is asserted blocked, and there is a case for history being unavailable while an untracked file of the same name exists.
Numbers
bun test test/gate/ test/inject/attribution.test.ts 114 pass, 4 skip, 0 fail. Full unit suite 1614 pass, 0 fail. e2e 37 pass, 0 fail — the three failures you saw on bd419e3 are gone now that #458 is in the base. bun run typecheck clean, bun scripts/comment-lint.ts clean.
Three nits, none blocking
scripts/ref-fixer.ts:325: 🟡 low: one git walk per pointer-bearing row. Measured 40 ms per walk on this checkout, so a dry run over dozens of pointer rows spends seconds it does not need to. Collect every row's pointers, walk once, then map back.
src/gate/resolver.ts:203: 🟡 low: the walk is bounded by a 5 s timeout that fails closed, so a slow or very large checkout turns a legitimate pointer into `ref_path_missing` with no way to tell it from an invented one from the evidence line alone. Emit a distinct flag (say `history_unavailable`) when the walk fails, so `memory_evidence` separates "git could not answer" from "the path never existed".
src/gate/resolver.ts:170: 🟡 low: the accepted spelling is still exact — `git show -- x.ts`, `git log --follow -- x.ts`, a trailing space inside the backticks, two spaces after `--`, and `Git log` all stay live and block. Naming the form in the hint makes this defensible; accepting `git show` and intervening flags is cheap if the reports show people hitting it.
Verdict: ship. The carve-out now costs an author a specific spelling and costs a model nothing.
— identified as an AI Assistant
There was a problem hiding this comment.
Approving 88dad8a. Verdict from the re-review, restated here as the review state.
The blocker is closed and I re-ran the probe rather than reading the fix. Against a real checkout: an invented pointer blocks, three invented pointers in one row block, a verified retired path promotes, a renamed-away path promotes, and a verified pointer next to an invented one blocks — partial laundering is closed, which is the case I expected to slip. Unavailable history refuses rather than exempts, and .git that is not a repository blocks.
Every other finding from the first pass is addressed: the auditor no longer loses unverified pointers and prints the exact reword, the refusal hint names the accepted spelling instead of telling the model to drop the path, attribution agrees with the gate, and write-gates.md states verification, HEAD scope and the fail-closed rule.
Numbers at this head: 114 gate and attribution tests, full unit suite 1614 pass / 0 fail, e2e 37 pass / 0 fail, typecheck and comment-lint clean.
The three nits I left are low and non-blocking: one git walk per pointer-bearing row in ref-fixer (~40 ms each here, batchable), the 5 s timeout failing closed with no distinct flag so memory_evidence cannot separate "git could not answer" from "never existed", and the accepted spelling staying exact. None of them change what a fabricated pointer costs.
— identified as an AI Assistant
|
🎉 This PR is included in version 0.33.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #447.
A memory can now point to a retired file using the convention from the pre-release ritual, for example
git log -- bench/runners/append-cost-198.tswritten as inline code. The write gate excludes that path occurrence from current-tree validation and from the count of references used to ground a write. A separate live citation of the same path still has to resolve. The reference repair script uses the same spans, so it preserves the historical spelling when it renames a live citation.The write gate verifies every marked path against committed file names reachable from HEAD in the checkout. A missing path or unavailable history refuses a settled write. The repair report lists unverified pointers for human review. A later read of a matching basename no longer earns memory-use credit from the history pointer alone. Unquoted prose, multi-path commands, and line-number citations retain their existing checks.
The gate uses the pinned
@lezer/markdownparser to identify the exact source span of an inline command. This gives the gate and ref-fixer the same offsets even when backticks are escaped or nested inside a larger example. Parsing runs only when the text contains a candidate history pointer. The documented marker uses one backtick on each side. Paths inside double- or triple-backtick examples and fenced code blocks still receive the ordinary existence check.Verification at
88dad8a. On native Windows, an invented history pointer passed on the preceding head and was refused after this change. The actual retiredbench/runners/append-cost-198.tsverified against this repository. All 60 focused gate, repair, and attribution tests passed. The full unit suite passed 1,598 tests with 37 skipped. Typecheck, lint, formatting and comment policy passed. I ran the full Windows end-to-end suite on both7270ebaand88dad8a. Each had 34 passes and the same three failures: capture produced zero rows during teardown, and two viewer tests hitEBUSYremoving temporary stores.Verification at
0dbbe54. Two write-gate regressions failed before this correction and now pass. The focused path and repair suite passed all 46 tests. The Windows unit suite passed 1,588 tests with 37 skipped. Typecheck, lint, formatting and comment policy also passed.Earlier verification. All three new regressions failed before the change. All 44 path-reference and repair tests passed afterward. I also checked the actual retired runner from the issue: the history pointer produced zero live refs and no missing path, while a second mention of the runner as current code reported it missing.
On Windows, the local comment policy, typecheck, lint/format and unit suite passed (1,586 passed, 37 skipped). The end-to-end run had 34 passes and three failures. I reproduced all three on the unmodified base, bd419e3: the capture-on-teardown case produced zero rows, and two viewer cases reported EBUSY while removing temporary stores.