feat: add supersedeReads strategy to prune stale read outputs#451
Open
sudorest wants to merge 1 commit intoOpencode-DCP:masterfrom
Open
feat: add supersedeReads strategy to prune stale read outputs#451sudorest wants to merge 1 commit intoOpencode-DCP:masterfrom
sudorest wants to merge 1 commit intoOpencode-DCP:masterfrom
Conversation
When a file is read and then subsequently written/edited successfully, the original read output becomes stale. This new strategy automatically prunes those outdated read outputs, saving context tokens. - New strategy: supersedeReads (enabled by default) - Only prunes reads followed by successful writes/edits (errored writes are ignored) - Respects protectedFilePatterns, manual mode, and automaticStrategies - Full config support with JSON schema, validation, and merge logic - 14 comprehensive tests covering all edge cases - Wired into compress tool alongside existing strategies
985bd3e to
dc58183
Compare
Collaborator
|
Why should editing a file prune the read from context? that means you can't edit it again without first reading it again. You're right pruning the read when it has been overwritten by a write tool makes sense though. Also supersede writes is on its way out, that strategy doesn't work for other reasons. I like the idea! Will review if you address the first issue. |
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.
Summary
Adds a new automatic pruning strategy —
supersedeReads— that prunes stalereadtool outputs when the same file has been subsequently written or edited successfully. This is the natural complement to the existingsupersedeWritesstrategy.Problem
In a typical coding session, the model frequently reads a file, then edits or writes to it. After a successful write/edit, the original read output is stale — the file contents have changed. These outdated read outputs waste context tokens and can cause the model to reference old file contents, leading to confusion and hallucinations.
Read outputs are often large (entire file contents), so pruning them yields significant token savings.
Solution
The new
supersedeReadsstrategy:readtool calls and all successfulwrite/edittool calls by file pathsupersedeWrites)protectedFilePatterns,manualMode,automaticStrategies, turn protectionChanges
lib/strategies/supersede-reads.tslib/strategies/index.tslib/config.tsSupersedeReadsinterface, config keys, validation, defaults, merge logiclib/tools/compress.tsdcp.schema.jsonsupersedeReadsto JSON schema for IDE autocompletetests/supersede-reads.test.tstests/compress.test.tssupersedeReadsto test config fixtureConfiguration
{ "strategies": { "supersedeReads": { "enabled": true // default } } }Testing
npm run typecheck— passesnpm test— 30/30 tests pass (14 new + 16 existing)npm run format:check— passesTest coverage
enabled: falseautomaticStrategies: false