Skip to content

search: a running reply past 20,000 characters is indexed once - #279

Open
connorburgess wants to merge 5 commits into
spacesheep-dev:mainfrom
connorburgess:fix/search-progress-tail-cap
Open

connorburgess wants to merge 5 commits into
spacesheep-dev:mainfrom
connorburgess:fix/search-progress-tail-cap

Conversation

@connorburgess

@connorburgess connorburgess commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Updated against v0.8.19 / main e8bfe999 on 2026-12-05. Current validation and refresh details.

What

When a turn's reply runs past 20,000 characters, search now indexes each running piece once. Before, every later turn.progress was indexed whole again, and so was the final turn.transcript. A 34,889-character reply came to 6 reply documents and 98,997 indexed characters. A word near the start was in 3 of those documents and a word in the middle was in 5.

Why

sessionpipe caps reply text in packages/core/src/privacy/filter.ts (capText), in two ways:

  • turn.progress keeps the end (capTail): … followed by the last 19,999 characters.
  • turn.transcript keeps the start (cap): the first 20,000 characters followed by ….

A running turn sends a progress event at most every 20 s, and each one carries the whole reply so far. In server/search/sources/events.ts, the continuation check compares a fingerprint of the text's first 64 characters with the last text's (fp(asst, pg.a) === pg.h). Once the reply is capped, its start moves with every progress, so the check fails and the whole capped text is indexed again. The head-capped transcript starts differently from the last progress, so it is indexed whole too. This breaks the contract in events.test.ts: "progress pieces and the final transcript never repeat a word".

Fix

All of the change is in server/search/sources/events.ts.

  • What the cursor keeps. Each turn's cursor now also keeps fingerprints of the end of the last reply text seen: e for its last 64 characters, f for its last 1,024, and l, a list with one fingerprint for each of its last 1,024, 2,048, 3,072, … characters (19 numbers at most). These are hashes, never words, like h.
  • Joining a capped progress. A capped progress (one that starts with …, is at least 20,000 characters, and does not continue from its start) is searched for that end. The join is made only if the end appears exactly once, every whole 1,024 characters the progress keeps before it match l, and the progress does not keep more before it than the last text held. Then only the text after it is indexed. pg.a, which says how much of the reply's start is indexed, then grows by that amount. When the head-capped transcript comes, its first 20,000 characters are already covered, so it adds nothing.
  • When the end can't be placed. This covers the end being missing, appearing twice, what is kept before it not matching the last text, a previous text shorter than 1,024 characters, and a turn whose first progress is already capped. The capped progress is then indexed whole, as before, and the cursor records a gap (g), so pg.a stops growing from then on.
  • Only capped progress is searched. Transcripts and uncapped progress keep the start check alone. A rewritten reply that happens to contain the last end is still indexed whole.
  • Older cursors. Cursors saved before this change hold { n, u, a, h } only. Without e, the first new text simply records it, and joining starts from the next one.

Not changed here:

  • Child sessions (parent_id set) are indexed as before: every text is indexed whole, because the cursor tracks the parent's turn only. The repeat after the cap happens there too, and needs a cursor per child.
  • A turn whose first progress is already capped (for example after a tier raise mid-turn). Its transcript is still indexed whole, so the part where the two overlap is indexed twice, as before. Nothing is lost.
  • A repeated ending after a jump no longer skips text. An earlier version of this branch joined at any single copy of the last 1,024 characters. When a progress jumped more than about 20,000 characters past the last one and the reply then printed those 1,024 characters again, the join was made at the copy and the kept text before it was not indexed. The join now needs everything kept before it to match the last text, in whole blocks of 1,024 characters, so that progress is indexed whole. What is left unchecked is fewer than 1,024 characters at the very start of the kept text, and only when the reply repeats the last text word for word from there up to the copy.

The source and test files remain independent of #277, which changes server/search/sources/text.ts.

An entry is now included under Unreleased in CHANGELOG.md. Other open PRs also add release notes; those entries may need combining as the PRs land.

Proof

New tests in server/search/sources/events.test.ts, under "a reply past sessionpipe's 20,000-character cap". Each one builds the events with the same two caps as core.

  • Progress with a kept end, then the head-capped transcript. A 6,000-word reply over 34,000 characters arrives as progress at about 12k, 19k, 24k, 30k and 36k characters, then as the head-capped transcript. Every word is indexed exactly once, in 5 reply documents.
  • A cursor saved by an older release. Only { n, u, a, h } is passed back. Progress at 19k and 24k and the transcript then index no word twice, and the cursor holds numbers only.
  • A capped progress that does not continue the last text is indexed whole.
  • A capped progress after a gap. The previous end's 80-character separator line recurs in the middle of the progress. It is not joined there, and every word it holds is indexed.
  • A capped progress after a jump, with the last text's ending repeated in it. Two tests, one after an uncapped progress and one after a capped one. The repeated 1,024 characters are not joined at, and a marker word before them is indexed. Both fail on the earlier version of this branch (26ca736d).
  • A new turn whose first progress is already capped. Its transcript is still indexed, so the reply's first word is found.

With server/search/sources/events.ts from origin/main (6165bed), the same test file:

       × progress with a kept end and the head-capped transcript never repeat a word 7ms
       × continues from a cursor saved before the end fingerprint existed 3ms
      Tests  2 failed | 14 passed (16)

The other five new tests pass on origin/main too, because it indexes those texts whole. They guard against the join losing words. A first version of this branch matched only the last 64 characters and took the first match. It failed the gap test, and the 1,024-character check is why it now passes.

On this branch:

$ npx vitest run server/search
 Test Files  24 passed (24)
      Tests  245 passed (245)

npm run typecheck exits 0. npm run lint exits 0 with Checked 983 files … Found 135 warnings. and no errors, the same count as on origin/main.

Checklist

  • Every commit is signed off (git commit -s).
  • npm run typecheck && npm run lint pass; npx vitest run server/search passes (the whole npm test was not run).
  • No new source files.
  • No secret, real address, hostname or home path in code or fixtures.
  • No change to shared/*.
  • A line under Unreleased in CHANGELOG.md.

sessionpipe sends a running turn's reply in turn.progress with its end
kept ("…" and the last 19,999 characters) once it passes 20,000
characters. The continuation check hashes the text's start, which moves
with every progress, so each later progress was indexed whole again and
so was the head-capped turn.transcript: a 34,889-character reply came to
98,997 indexed characters.

The cursor now also keeps two fingerprints of the end of the last reply
text seen (its last 64 and last 1,024 characters). A kept-end progress
whose start does not continue is searched for that end, and when it holds
it exactly once only what follows is indexed; how much of the reply's
start is indexed grows with it, so the head-capped transcript adds
nothing already indexed. A kept end that cannot be joined is indexed
whole, as before, and stops the start from growing.

Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
@connorburgess

connorburgess commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor Author

The capped progress reply indexing fix still applies to SessionPipe GUI v0.8.18. Merged current main (d16a2c01) into this branch; the refreshed head is 26ca736d. The affected files have not changed upstream, and the original change is preserved.

Added the previously deferred Unreleased changelog entry.

Validation on this head, macOS / Node 22.23.2:

  • npm run typecheck, npm run lint, and npm run build passed. Lint has the same 135 warnings and one informational diagnostic as current main, with no errors.
  • npx vitest run --maxWorkers=2 server/search: 243 tests passed.

GitHub CI run 47453787549 for head 26ca736d passed: typecheck · lint · unit · build, all three desktop e2e shards, e2e (phone · duo), e2e (control channel), and the aggregate typecheck · lint · unit · build · e2e gate.

Also checked the combined source/test changes from all 19 refreshed PRs on the same main: no source conflicts; typecheck, lint and build passed; all 252 unit-test files passed (3,439 tests, two skipped). This was a local integration check, separate from the individual PR run above. Release-note entries may still need combining as PRs land.

Merge blocker: confirmed loss of searchable text. The description already notes that an exact repeated 1,024-character ending after a large progress gap can be mistaken for an overlap. I reproduced this on the refreshed head: a marker present in the received progress is not indexed. The same regression probe passes with current main's events.ts. The existing passing suite does not cover this case.

Reproduction using the existing events adapter test helpers:

const p1 = Array.from({ length: 1800 }, (_, i) => `prior${i}`).join(" ");
const gap = Array.from({ length: 6000 }, (_, i) => `later${i}`).join(" ");
const full = `${p1} ${gap} mustfindmarker ${p1.slice(-1024)} finalword`;

Send p1 as the first progress, "…" + full.slice(-19999) as the next progress, then full.slice(0, 20000) + "…" as the transcript, all for the same turn. Assert that at least one indexed document contains mustfindmarker: it fails on this PR and passes on main. findEnd joins at the repeated suffix and skips the previously unseen text before it.

Keeping the PR as draft until overlap detection can retain that text, or the optimization is narrowed to cases where continuity can be established. The refresh preserves the original implementation; it does not fix this blocker.

@connorburgess
connorburgess marked this pull request as draft December 5, 2026 00:26
…is found

A progress more than 20,000 characters past the last one no longer holds
that text's end. When the reply then repeated its last 1,024 characters
once, the join was made at the copy and the text kept before it was not
indexed.

The cursor now also keeps fingerprints of the last text's final 1,024,
2,048, ... characters. A join is made only when every whole 1,024
characters the progress keeps before it match, and never when it keeps
more before the join than the last text held. Otherwise the progress is
indexed whole, as before.

Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
@connorburgess

Copy link
Copy Markdown
Contributor Author

Follow-up to my earlier comment, which held this PR as a draft because a repeated 1,024-character ending after a jump of more than 20,000 characters made findEnd join at the copy and skip the text kept before it.

That case is fixed in aaa302b9. The cursor now also keeps l, one fingerprint for each of the last text's final 1,024, 2,048, 3,072, … characters (19 numbers at most, still no words). A capped progress is joined only when every whole 1,024 characters it keeps before the join match those fingerprints, and never when it keeps more before the join than the last text held. Otherwise it is indexed whole, as on main.

  • The reproduction from the earlier comment (mustfindmarker after an uncapped first progress) now passes, and is in events.test.ts together with a second case where the first progress is itself capped. Both new tests fail on the previous head 26ca736d and pass here.
  • The existing "never repeat a word" tests still pass, so the fix does not bring the repeats back.
  • What remains unchecked is fewer than 1,024 characters at the very start of a capped progress, and only when the reply repeats the last text word for word from there up to the copy. The description is updated to say this in place of the old "one narrow case" note.

Also merged current main (e8bfe999, v0.8.19); the head is now 05ef76af. The one conflict was in CHANGELOG.md, where this PR's Unreleased entry stays above the new 0.8.19 section.

CI run 47497358863 for head 05ef76af passed every job: typecheck · lint · unit · build, e2e (desktop 1/3), e2e (desktop 2/3), e2e (desktop 3/3), e2e (phone · duo), e2e (control channel) and the aggregate typecheck · lint · unit · build · e2e gate.

Locally on 05ef76af (macOS, Node 22.23.2): npm run typecheck, npm run lint (135 warnings, no errors, as on main) and npm run build passed; npx vitest run server/search: 245 tests passed.

With the blocker resolved, this is marked ready for review.

@connorburgess
connorburgess marked this pull request as ready for review December 5, 2026 08:22

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant