wangwu25685333 on X (10-29, v0.1.1840, Linux, i5-7500 4c/4t): a fresh
Hermes session of 31.5K tokens spent 98.8s in the local model (AstrLink
Guard) and 2.3s upstream, and every new session (cron opens one each
time) read the same ~30K of system prompt again.
The cache by content was already there (#3682: sha256 of each text or
piece -> spans, in memory and in found-<rev>.bin, no text), and tool
definitions are no longer read (a5315c70d). What made a fresh session
miss it is how a long text is cut: a piece ended after the last line's
end in its second half, so its end was a distance from the piece's
start. A line of the prompt edited (Hermes puts its date, memory and a
workspace snapshot in the prompt) moved every later piece's ends by as
many bytes, and every piece after the edit was new to the cache.
Now a piece ends after the line's end (else space) in that second half
whose 48 bytes before it hash least (FNV-1a): the text's own choice. Once
one end meets an end of before, the rest are the same pieces, known by
hash. The rune-start fallback (no line's end or space in 2 KB) is
unchanged.
Measured, pieces new to the cache after one edit (4 inserts x 2
deletes at every ~1 KB) of three texts, guardChunk pieces (cut only):
39 KB of AGENTS.md/LESSONS.md/code-standards: mean 3.92 -> 1.65,
worst 13 of 13 -> 5 of 18
68 KB of LESSONS.md/agent-wiring.md: 2.80 -> 1.63, worst 14 -> 6
58 KB of prose(): 4.96 -> 1.64, worst 20 of 20 -> 4 of 28
The cost: pieces are 3/4 as long on average, so a cold read reads
142% of the text where it read 130% (overlaps). Tried and dropped:
a narrower window (3/4 of the piece: 2.49 mean, worst 9) and the last
line's end whose hash is 0 mod K (K 4..32: worst 9 to 15 at the
small K, no better than this at 32).
The real model (AstrLink Guard, int8, pure Go) on the Linux box with
GOMAXPROCS=4 taskset -c 0-3 (wsl magpie-desktop), a 110 KB Hermes-like
system prompt (about 28K tokens; AGENTS.md, code-standards, LESSONS.md
and two subsystem pages, a memory section, a date line):
cold: 59.9s -> 62.4s
a line added at 10/25/50/75%: 3.06/4.77/1.79/2.49s ->
1.35/2.93/1.65/2.48s (mean 3.03 -> 2.10)
memory line + date changed: 2.83s -> 2.72s
the same prompt again: 0s both (the cache by hash)
On mote (CoreML) the cold read is 1.3s both ways.
Test: TestEditedTextReadsItsPiecesAgainOnly reads a 40 KB prompt-like
text, then the same with a line inserted at 14 places x 4 inserts, and
fails when more than 3 pieces' bytes are read again or a span is lost.
Broken by hand: with find.go of origin/main it fails ("Conversation
started: ..." at 536: 53573 bytes read again, want at most 12288).
Run (mote): go test ./internal/pii/... ./internal/masking ok; gofmt -l
clean.
At ca221e115 with the three pii commits of this push: gofmt -l clean;
go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
./... and go build ok (mote); go test ./internal/pii/...
./internal/masking ok on mote, on Windows (win-run) and with -race on
Linux (wsl-run). Not run before the push: go test ./... (both mote and
the Linux box were running other sessions' full suites, one a machine).
Not tried: the reporter's own Hermes prompt (it is on their machine);
the measure is on this repo's docs and on prose(); a CJK text with no
line's end or space for 2 KB still cuts by distance.