feat(ctx_read): serve explicit re-reads as deltas when delta_explicit is enabled - #463
Merged
yvgude merged 1 commit intoJun 20, 2026
Conversation
|
All contributors have signed the CLA. ✅ |
parker-brown-family
marked this pull request as ready for review
June 19, 2026 15:31
parker-brown-family
force-pushed
the
feat/ctx-read-delta-explicit
branch
2 times, most recently
from
June 19, 2026 20:02
11c7e06 to
29e5409
Compare
Contributor
Author
|
recheck |
… is enabled When an agent re-requests `full` or `lines:N-M` for a file it already read this session and the file changed on disk, return `mode=diff` instead of re-emitting content the model already holds; when unchanged, a `lines:` re-read of a fully-delivered file collapses to the full-mode `[unchanged]` stub. This enforces, on explicit re-reads, the RE-READ discipline lean-ctx already recommends. Opt-in and default OFF: config field `delta_explicit` plus the `LCTX_DELTA_EXPLICIT=1/0` env override (env wins in both directions, mirroring `no_degrade_effective`). First reads are unaffected and `fresh=true` always bypasses. - Staleness uses the verified mtime+md5 `is_cache_entry_stale_verified`, not mtime alone, so a same-second write on a coarse-granularity filesystem cannot be mistaken for "unchanged" and yield a misleading empty diff. - The diff base is the full cached source (via `handle_diff`), never a compressed map/signatures view. - The `[delta-explicit]` advisory and the diff carry no timestamps/counters, so identical inputs stay byte-stable (yvgude#498). The decision is factored into the pure, testable `ctx_read::resolve_explicit_delta_mode`; the MCP dispatcher calls it under a cache read-lock before the `lines:`->fresh guard so a changed-file `lines:` re-read can still be diverted to a diff. Tests: config round-trip + env-override (both directions); ctx_read behavior matrix (changed->diff, unchanged `lines:`->stub, OFF preserves current behavior, fresh bypasses, first read unaffected, auto-mode never diverted, diff base is full source, decision byte-stable). Schema + feature-catalog get a concise opt-in note.
parker-brown-family
force-pushed
the
feat/ctx-read-delta-explicit
branch
from
June 19, 2026 20:12
29e5409 to
3521329
Compare
yvgude
approved these changes
Jun 20, 2026
yvgude
left a comment
Owner
There was a problem hiding this comment.
Reviewed line-by-line: the core is a pure resolve_explicit_delta_mode(cache, path, mode, …) with no wall-clock/counter/randomness, opt-in (default off = zero behavior change), and #498-determinism-aware — it uses the verified staleness check so a same-second write can't be misread as unchanged, and ships a byte-stability test plus a guard that the diff base is the full cached source (not a compressed view). Thorough test matrix (changed→diff, unchanged-lines→stub, fresh bypass, first-read, off-preserves). CI green. LGTM.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Hi, and thanks for lean-ctx 👋
Daily user here. This adds an opt-in I wanted for myself: delta-aware explicit
re-reads in
ctx_read.For context — a lot of my sessions are tight iterative loops over a handful of
files: read, edit, re-read to confirm, edit again. When I (or the agent)
explicitly re-read a file already seen this session, getting the whole thing
back is mostly tokens I'm already holding — the change is the only new
information.
The pain
lean-ctx already collapses auto re-reads to deltas. But an explicit
fullor
lines:N-Mre-read of a session-cached file re-emits content the model stillholds, even when only a few lines moved.
What this adds
delta_explicit(config field +LCTX_DELTA_EXPLICITenv, default off): whenenabled, an explicit re-read of a session-cached file returns
mode=diffif itchanged on disk, or collapses to the existing full-mode stub if unchanged. First
reads are untouched;
fresh=truealways bypasses.Tradeoff / Tension
Opt-in by design — some workflows want an explicit
fullto always mean full.Default off keeps it purely additive: those who want the token savings on explicit
re-reads turn it on. Workflow-specific, like a lot of token-economy choices.
Notes
is_cache_entry_stale_verified),so a same-second write can't produce a misleading empty diff.
Tests
Config round-trip + env override, and
ctx_readbehavior: unchanged → stub,changed + enabled → diff, disabled → full (today's behavior),
fresh=truebypasses, first read untouched.
CI / back-compat
cargo fmtandclippy -D warningsclean on the changed files;ctx_readandconfiglib tests green. One additive config field; default off.