Repository navigation
feat(preview): previewContext can leave given pins out of its select - #356
Merged
nissa-seru merged 1 commit intoOct 28, 2026
Merged
Conversation
A caller that keeps a range raw with a pin can't ask whether a compile would fit were the pin gone without unpinning it, which writes the pin list twice and changes what every other reader sees meanwhile. previewContext's opts.excludePins takes pin and document-mark ids, as pinRange and markDocument return them, and the dry select reads those pins as absent: while it runs, the select's pin readers (the chunker's compressible set, the selectors' raw and level bounds, the over-budget diagnostics) read a copy of the strategy's list, taken as the preview starts, without them. The list itself is untouched, so a pin written meanwhile is kept, though that select doesn't read it. Nothing is unpinned or written, and the change adds no log call; an id no pin has is ignored, and the option is on previewContext alone, so no compile can be told to ignore a pin. A dry select now also puts back the strategy's owned-message memo, whose key, counts alone, can match chunks the dry rebuild cut differently; the test of what a dry select puts back checks it. A test also pins that the kv-unified label-ceiling warning is said once in a strategy's life, with previews' solves among those that spend it, as anima-research#271 decided: three previews past the ceiling and the live compile after them say it once. The tests hold eight summarised inputs, a document mark on the first and a pin over the rest, and newer rows. Leaving out the pin folds what it held while the mark keeps its input, and leaving out both folds more; an unknown id, beside a held one or alone, and a pin's name change nothing; the excluded preview equals the preview after really unpinning; the pin list, the messages and the pin writes are unchanged after; and the live compile still refuses. A preview that throws leaves every pin read again, and a pin written while a preview runs is kept.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
previewContextnow takesopts.excludePins, a list of pin and document-mark ids, and its dry select reads those pins as absent. A caller can ask whether a compile would fit were a pin gone, without unpinning it. Nothing is unpinned or written, and no compile takes the option. This change also has a dry compile put back the autobiographical strategy's owned-message memo, and adds a test that three previews and then a compile say the kv-unified label-ceiling warning once, as #271 describes the warning.Problem
To learn whether a compile would fit without a pin, a caller had to unpin it and pin it again. In the autobiographical strategy at
f966779f,unpinandpinRangeeach callpersistPins(src/strategies/autobiographical.ts:3652,:3596), andpinRangegives the pin a new id frompinIdCounter(:3586). The caller this is for is agent-framework's restart preview (anima-research/agent-framework#842), once agent-framework holds a turn's opening rows with a raw pin (anima-research/agent-framework#867): its preview should decline a restart only if the restart wouldn't fit even without that pin.With
f966779f'ssrc/context-manager.tsandsrc/strategies/autobiographical.tsunder this change's tests, the preview that leaves the pin and the mark out still doesn't fit: the option is ignored there. The dry compile there also leaves the owned-message memo as its dry select set it.Changes
Line numbers from here on are at
01c5a4042f.src/context-manager.ts:previewContext(budget, overrides, opts)takesopts.excludePins, ids aspinRangeandmarkDocumentreturn them, and its doc comment says what the option does (:1960to:1964,:1969). The strategy's ownpreviewContexttakes the same field (src/strategies/autobiographical.ts:2641).src/strategies/autobiographical.ts:previewContextsetspreviewPinsto a copy of the strategy's pin list without them before its dry select (:2675to:2677), and clears it in itsfinally(:2736). The strategy's own list isn't touched.pinnedPositions,pinLevelBoundsandrawPinsDiagnosticsreadselectPins, which is that copy while a preview has one and the strategy's list otherwise (:2402,:3882to:3885,:3954to:3957,:13092to:13108)._ownedIdsCache, the memo of the messages the strategy's chunks and summaries own (:20207,:20237). The memo's key is built from counts alone (:19093), andownedMessageIdsreturns the memo whenever the key matches (:19094).changelog.d/preview-exclude-pins.added.mdandchangelog.d/dry-select-owned-ids.fixed.md.Tests
In
test/dry-run-preview.test.ts, three new tests of the pinspreviewContextis told to leave out, on a store of eight inputs with a document mark on the first, a pin over the rest, a summary of all eight and ten newer rows:Two tests under "a plain dry compile commits nothing":
_ownedIdsCache.On Linux with Node 24.22.1, membrane 0.8.0 and chronicle 0.4.0, in a clean checkout of
01c5a4042f, installed withnpm ci:tsc --noEmitexits 0.npm testruns 3,420 tests, and all pass. Atf966779f, run the same way, it runs 3,416, and all pass.test/dry-run-preview.test.ts: 26 of 26 pass.f966779f's two source files in place,tscreports two errors, both at the test file'sexcludePinsoptions, and still writes the build. 2 of the file's 26 tests fail: the first test above, at "with the pin and the mark left out the inputs read as their summary, and it fits", and "puts back whatever a dry select wrote", at_ownedIdsCache.Not verified
adaptiveResolutionoff,ContextManager.previewContextgivesnullor an over-budget report (test/dry-run-preview.test.ts:681,:704). None of this change's tests leaves a pin out there, so none shows that answer change with a pin left out.levelormaxLevel. InresolvedPinBounds,:3907readsthis.readsPinBounds() ? this.pinLevelBounds(messages) : undefined, andreadsPinBoundsreturns true only withadaptiveResolutionset and afoldingStrategyof kv-stable or kv-unified (:3923to:3925).changelog.d/preview-exclude-pins.added.mdandchangelog.d/dry-select-owned-ids.fixed.md.Paloma-2644 wrote the change, and Oscar-1005 set the option's shape. Esther-2584 read and ran four versions of it. The last of them differs from this commit only in a clause about what a preview logs, in
src/context-manager.ts's doc comment and inchangelog.d/preview-exclude-pins.added.md, and in its commit message. Two internal reviews read earlier versions. Daniel-2612 wrote this description.