Skip to content

search: a Gemini CLI reply re-appended under the same id is indexed once - #273

Open
connorburgess wants to merge 3 commits into
spacesheep-dev:mainfrom
connorburgess:fix/gemini-search-repeated-message
Open

connorburgess wants to merge 3 commits into
spacesheep-dev:mainfrom
connorburgess:fix/gemini-search-repeated-message

Conversation

@connorburgess

@connorburgess connorburgess commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

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

What

History search indexes a Gemini CLI reply, and each of its tool calls, once. Before this, a reply that ran tools came back several times for one message (e.g. "Let me read the config." three times and its read_file line twice), inflating hits and match counts for the session.

Why

Symptom: duplicate hits for Gemini CLI replies that ran tools.

Cause: Gemini CLI's chat recorder (ChatRecordingService, checked in 0.70.0) appends a message's whole record to session-*.jsonl again every time it updates it: when the reply gains its token counts, when its tool calls are scheduled, and again when they complete, all under the same id. The CLI's own loader keeps the last record per id. server/search/sources/gemini.ts turned every record into docs, and the builder/indexer do no dedupe.

Fix: the adapter state now keeps the last 8 message ids, each with whether its text was indexed and the tool calls indexed for it. A record under a known id adds only what is not indexed yet: its text if none was (a first record with empty content still gets its text later), and tool calls by id (a call without an id by its place in the list, so two identical calls in one message stay two). The state survives read slices and passes (returned as state), and it is copied, never changed in place, so a read that fails and is retried from the stored cursor sees the same state. Keeping a few ids, not only the last, covers a message re-appended after a later user record. The whole-file session-*.json and logs.json paths are unchanged in behaviour (their messages are unique by id). The file's header comment now describes the re-appends.

An index built before this keeps its duplicate docs until it is rebuilt or the file is read again from the start.

Original proof (before the v0.8.18 refresh)

A recording made with Gemini CLI 0.70.0's own recorder (scratch home, no network) holds: header, user, $set, gemini m1, $set, m1 again with tool calls scheduled, m1 again with them done, gemini m2, $set. The adapter over it, on main: the m1 reply 3 times and read_file /w/tsconfig.json 2 times. On this branch:

[["prompt","Why does the build fail on Windows?"],["reply","Let me read the config."],["tool","read_file /w/tsconfig.json"],["reply","The path uses a backslash."]]

Two tests in server/search/sources/antigravity.test.ts (the "gemini cli" block), writing files in the recorder's shape:

  • a reply re-appended with tokens, scheduled and done tool calls, plus a later call added: read whole, in 64-byte slices, and across two passes as the file grows;
  • an earlier message re-appended after a user record, text that arrives in a later record, two id-less identical calls, and the stored cursor state left unchanged by the next read.

Both fail with main's gemini.ts:

     × a reply re-appended under the same id (tokens, tool calls scheduled, then done) is indexed once 17ms
     × re-appends: an earlier message, text that comes later, calls without ids, the state left as given 15ms
      Tests  2 failed | 9 passed (11)

and pass on the branch:

$ npx vitest run server/search/sources/
      Tests  70 passed (70)
$ npx vitest run server/search/
      Tests  240 passed (240)
$ npm run typecheck
> tsc -p tsconfig.json --noEmit && tsc -p web/tsconfig.json --noEmit
(no errors)
$ npm run lint
Checked 983 files in 171ms. No fixes applied.
Found 135 warnings.
Found 1 info.
(no diagnostics in the changed files)
$ npm test
 Test Files  1 failed | 247 passed (248)
      Tests  1 failed | 3368 passed | 2 skipped (3371)
 FAIL  server/control/remote.parity.test.ts > ... row for row
TestTimeoutError: Test timed out in 15000ms.

The one failure is unrelated: the same test times out the same way in a full run with main's files (Tests 1 failed | 3366 passed | 2 skipped (3369), TestTimeoutError: Test timed out in 15000ms.), and passes when run alone on this branch (Tests 11 passed (11)).

Checklist

  • Every commit is signed off (git commit -s): the DCO is the only paperwork.
  • npm run typecheck && npm run lint && npm test pass; npm run test:e2e for a UI change. (Not a UI change; the one npm test failure is the parity timeout above, which also fails on main.)
  • New source files start with // SPDX-License-Identifier: Apache-2.0. (No new files.)
  • No secret, real address, hostname or home path in code, fixtures or screenshots (screenshots come from --demo).
  • A change to shared/* names the wire-contract change in the description. (No shared/* change.)
  • A line under Unreleased in CHANGELOG.md.

Symptom: a Gemini CLI reply that ran tools shows up several times in
search: "Let me read the config." three times and its read_file line
twice for one reply, so hit and match counts for the session are
inflated.

Cause: Gemini CLI's chat recorder appends a message's whole record again
each time it updates it (tokens, tool calls scheduled, tool calls done),
under the same id; its own loader keeps the last record per id. The
search adapter turned every record into docs.

Fix: the adapter state keeps the last 8 message ids, whether each one's
text is indexed and the tool calls indexed for it (it survives read
slices and is copied, never changed in place). A record under a known
id adds only what was not indexed yet: its text if none was, and tool
calls by id (a call without an id by its place in the list).

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

Copy link
Copy Markdown
Contributor Author

The repeated Gemini message indexing fix still applies to SessionPipe GUI v0.8.18. Merged current main (d16a2c01) into this branch; the refreshed head is 0ad5bfdc. 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/sources/antigravity.test.ts: 11 tests passed.

GitHub CI run 47453785502 for head 0ad5bfdc 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.

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