Repository navigation
fix(inject): hold the frontier block and contextual pulls to injectBudget - #66
Conversation
…dget Only the relevance block honoured injectBudget. The open-threads block and each contextual pull carried up to three full-length rows, about 12 KB of system prompt or tool output regardless of the budget. Combined with import, a JSONL file with a pasted export header and repo:"global" open rows put that 12 KB into the system prompt of every repo on the machine. - The frontier block and the contextual pull are each capped with capToBudget at the configured budget (whole rows, existing order). frontier_injected evidence counts only the rows actually shown. - memory_import downgrades a header-backed open row that claims repo:"global" to settled. Repo-scoped open rows from a real export keep their status (abogartz#32 round trip unchanged). - The standing digest, relevance block and compaction anchor are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
abogartz
left a comment
There was a problem hiding this comment.
Request changes. The budget hole is real and I measured it. But as implemented the cap silently degrades the open-threads feature on realistic data — including this maintainer's live store — and that trade needs to be made deliberately, not as a side effect of reusing capToBudget.
The bug, confirmed on 0.8.1 (main @ 4643ec4)
- 3 open rows at the 4,000-char content cap → 12,450 chars injected into the system prompt on every request with
injectBudgetat its 1200 default. contextualPullon agrepwhose term matched those rows appended 12,142 chars to a single tool result.- On your branch: 277 chars and 0 chars respectively. The
repo:"global"import downgrade also works: an import row claiming global open status is tallieddowngraded: 1and landssettled global. - 291 pass / 4 skip / 0 fail; 3 of your tests fail against main's source;
tscclean.
Blocker: the cap silently kills the frontier when rows are long
capToBudget keeps whole lines and drops a line that doesn't fit; if only headers survive it returns "". Content is allowed up to 4,000 chars, and open threads are encouraged to be rich. Measured against the live store on this machine (132 rows, budget 1200):
| case | result |
|---|---|
| today's three newest open threads (1,098 + 602 + 593 rendered) | block is 2,377 chars → after the cap 1,180 chars, 1 of 3 rows |
| newest thread grows by 150 chars (→1,398) | the newest thread is dropped and an older one is injected in its place |
| all three threads ≈1,200+ chars each | capToBudget returns "" → no frontier block at all, no frontier_injected evidence row, and (because of if (!frontier) return) the convergence-tracking line disappears too |
So the failure lands worst exactly when planning notes are most detailed: the frontier is the feature that stops a session re-deriving yesterday's state, and under this PR it either shrinks to one row, prefers a stale row over the newest one, or vanishes without a trace. memory_status's frontier counters would show shown: 0 with no reason attached.
What I'd like to see
- A knob that can express the frontier on its own.
injectBudgetcurrently means "the relevance block"; reusing it means raising the frontier also raises per-request relevance injection and every pull. Either a separate option (e.g.frontierBudget, default something like3 × budget) or an explicit multiplier, documented as such. - Never silently drop the newest open thread. It is the whole point of the block. If it doesn't fit, say so in the block (
+ 2 open threads omitted: over budget) so both the user reading the panel and thefrontier_injectedevidence reflect what happened. - Decouple the drop from the rest of
systemDigest.if (!frontier) returncurrently takes the convergence summary and the evidence row down with it; those should stay (or the evidence should recordshown: 0, omitted: N, reason: over_budget). - README consequences, not just the option table. "The open-threads block and each contextual pull get the same cap" reads as a free win; please state that a thread longer than the budget is not injected.
Second issue: the import downgrade closes the loudest case only
Verified on your branch: a row with repo:"global" is downgraded ✅ — but a row claiming another repo's key is still promoted as open:
{"type":"context","scope":"evil3","content":"…","status":"open","repo":"5981a5640bc3"} → promoted: 1, downgraded: 0
landed: evil3 open 5981a5640bc3
repokey.ts:64 derives that key as sha1(normalizeRemote(origin)).slice(0,12) with no salt, so anyone who knows a repo's public remote can compute it. Your stated goal — "one file can't add an open thread to every repo" — holds; the class behind it ("one file can add an open frontier thread to a specific public repo, which is where that maintainer works") does not. I have filed a follow-up. Since you are already in importMemories, the cheap closure here is to ignore repo/repoPath on import unless they match the current scope (rows without a stamp already get re-stamped to the importing session's repo, so that path is safe today — I checked).
Nits
const keptLines = new Set(frontier.split("\n")); const shown = open.filter((_, i) => keptLines.has(rendered[i]))— two rows that render identically both count as shown. Practically unreachable (the dup gate blocks identical content), but it's a correctness-by-accident shape; returning the kept indices from the capper would be exact.- Integration: this PR cannot be merged after #65 without a real rebase, and it is not only the
srchunk —test/frontier.test.ts:178passesbudgetpositionally, so a naive merge failstsc(TS2345: number is not assignable to Memory[]). Working resolution:systemDigest(_input, output, rows?: Memory[], budget = injectBudget()), call sitesystemDigest({…}, { system: parts }, mems, budget), testsystemDigest({…}, { system }, undefined, budget). I merged all six of your PRs with that change: 308 pass / 4 skip / 0 fail, tsc clean. Better still, move both to an options object so the two can't collide silently.
Review follow-up for abogartz#66: - New frontierBudget option (env OPENCODE_MEMORY_FRONTIER_BUDGET), default 3x injectBudget; contextual pulls stay on injectBudget. - The frontier fills newest-first and stops at the first row that doesn't fit, so an older thread never replaces a newer one. Omissions are shown in the block ("+ N open threads omitted: over budget") and recorded in frontier_injected (shown, omitted, reason=over_budget). The convergence line and evidence survive an over-budget frontier. - The capper returns the kept rows, so shown is exact. - systemDigest(input, output, { frontierBudget }) options object. - Import keeps repo/repoPath only when they match the importing repo (explicit global kept; with no current scope stamps are kept and stamped open rows are downgraded). Closes abogartz#73. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/index.ts # src/inject.ts
|
Thanks for measuring it against a real store. Pushed and merged with main (0.8.4), following your list:
Import, per your #73 suggestion (this says "Closes #73"): a foreign
Your three live-store cases are tests now. I merged this together with #62, #67, #76 and #77 on 0.8.4: 324 unit tests and the e2e suite pass on Linux. |
abogartz
left a comment
There was a problem hiding this comment.
Approving. Every blocking item from my request-changes review is fixed, and I verified the fix behaviourally, not just by reading — all five PRs in this batch merged onto 0.8.4 together (as you claimed; the merge really is clean), then I ran my own probe suite against the combined source.
Verified live on my probes, not your tests:
- The knob exists and defaults sane:
frontierBudget()= 3 ×injectBudget()= 3600;OPENCODE_MEMORY_FRONTIER_BUDGET=777overrides it. - The gutting I complained about is gone: a realistic store shape (one ~1 100-char + two ~600-char open rows, 2 384 chars rendered) now shows all three rows, no omission marker under the default — the old
capToBudget(injectBudget)behaviour showed one row or nothing. - Tight budget behaves to spec: at 1 200 the newest row is kept, the two older ones are dropped, and the block says
+ 2 open threads omitted: over budget. At budget 20 the header and the marker are still emitted — the block never vanishes. - Evidence is exact:
frontier_injectedcarriesshown=3 omitted=0(default),shown=1 omitted=2 reason=over_budget(tight),shown=0 omitted=3(tiny). - #73: the foreign-stamp removal is the right shape — a foreign key is treated as no stamp so
appendMemoryre-stamps the importer; your5981a5640bc3test is my repro. The two judgement calls you flagged are both correct, and I'm ruling on them: keeping an explicitglobalon a settled row is right (a settled row gets no grounding exemption and re-scoping a cross-machine convention would be the worse silent failure), and with no current scope, keeping the unverifiable stamp while withdrawing the open exemption is right — widening to global would be strictly worse than the bug we are fixing.
Combined-batch gates: 324 pass / 4 skip / 0 fail, tsc --noEmit clean, biome exit 0.
One note for the record: the repoScopeFor(getCurrent().sid) call means import-time scoping follows the session that invokes the tool — same identity mechanism the write path already trusts, so no new attack surface, but worth remembering when reading an import tally.
|
🎉 This PR is included in version 0.8.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Only the relevance block honours
injectBudget. The open-threads block and the contextual pull don't, and an import file can use that to reach other repos' system prompts. I found this while reviewing 0.8.0, and it's unchanged in 0.8.1. Updated after your review: the frontier gets its own budget, never drops a thread silently, and import no longer honours a foreign repo stamp (#73).The problem:
"repo":"global"(every repo) or with a specific repo's key (memory_import: an unsalted repo key lets a file plant an OPEN frontier row in another repo #73: the key is an unsalted hash of the public remote). Open rows are exempt from grounding and ride the frontier block.Reproduced on 0.8.0 with the default budget of 1200:
frontierBudgetinjectBudgetChange:
frontierBudgetoption, with env fallbackOPENCODE_MEMORY_FRONTIER_BUDGET. It defaults to 3 ×injectBudget(3600 by default) and caps the open-threads block.contextualPullstays capped byinjectBudget, and the relevance block is unchanged.+ 3 open threads omitted: over budgetstill appear, so the block never vanishes. That holds even for a budget too small for those two lines; that one exception is commented in the code.frontier_injectedevidence are still emitted. The evidence recordsshown,omittedandreason=over_budget. With no open rows at all, behaviour is unchanged.shownis exact even when two rows render identically.systemDigest(input, output, { rows, frontierBudget }). This converts the positionalrowsargument fix(inject): refresh the frozen memory block when its rows change #65 added, so the two can no longer collide positionally.repo/repoPathare kept only when they match the importing session's repo. A foreign stamp is dropped, soappendMemorystamps the importing repo.repo:"global"are still downgraded to settled.repo:"global"on a settled row is kept. It isn't a foreign repo, and dropping it would silently re-scope global exports.frontierBudgetisn't injected and is reported as omitted, and how to raise the budget. The import policy is updated.Tests
test/frontier.test.ts:frontierBudgetdefault and env override.test/inject.test.ts: the appended pull block stays withininjectBudgetat whole rows.test/portable.test.ts:test/repo-scope.test.ts: export, then import in another repo, replaces the foreign stamp with the importer's.With the source change reverted, the new tests fail.
Checks (Linux, Bun 1.4.4, on 0.8.4):
bun test ./test/313 pass, 4 skip, 0 fail.bun run test:e2eagainst opencode 2.0.26: 9 pass.tsc --noEmitis clean, andbiome lintexits 0 with warnings unchanged frommain. Nothing here is platform-specific.Merge order: main (0.8.4) is merged in, with #64 and #65 resolved. It applies cleanly alongside #62, #67 and #76 and #77; I merged all of them together on 0.8.4 to check.
🤖 Generated with Claude Code