fix: address Codex review on PR #3601

This commit is contained in:
netcatty-bot committed 2026-10-11 02:04:00 +00:00
1 parent 347d141eae
commit 3fd0577b86
4 files changed
+38 -13

No files matched your search

@@ -702,8 +702,9 @@ test("filterSessionHistory caps the query and matches on its capped prefix", ()
const session = createSession("a", "nginx restart", [{ content: "reload nginx" }]);
// A pasted multi-megabyte query must not be re-normalized per session: it is
// capped (MAX_SEARCH_QUERY_LENGTH) and normalized once per scan, so matching
// falls back to the capped prefix (which still spans tokens here).
// capped via truncateQueryForMatch (MAX_SEARCH_QUERY_LENGTH) at this scan's
// input and normalized once per scan, so matching falls back to the capped
// prefix (which still spans tokens here).
const longQuery = `${"nginx ".repeat(200_000)}zzz-impossible-tail`;
assert.deepEqual(filterSessionHistory([session], longQuery), [session]);
// The uncapped-looking but normal query still matches exactly.
+7 -5
View File
@@ -5,7 +5,7 @@ import {
type SessionHistorySearchTarget,
type SessionSearchIndex,
} from '../../domain/sessionHistorySearch';
import { prepareSearchQuery } from '../../lib/searchMatcher';
import { prepareSearchQuery, truncateQueryForMatch } from '../../lib/searchMatcher';
/**
* Memory bounds for the per-session search index cache. `filterSessionHistory`
@@ -290,10 +290,12 @@ function filterSessionHistoryStore<T extends SessionHistorySearchTarget>(
// Bound and prepare the query once per scan: a pasted-in multi-megabyte
// query would otherwise be re-normalized (NFKC), tokenized and compacted
// inside `matchesSessionSearchIndex` for every session, freezing the
// renderer. `prepareSearchQuery` caps the input (`MAX_SEARCH_QUERY_LENGTH`)
// and computes the normalized forms a single time so the per-session work
// below only does `includes` scans over the cached haystacks.
const preparedQuery = prepareSearchQuery(trimmed);
// renderer. The cap (`truncateQueryForMatch`, `MAX_SEARCH_QUERY_LENGTH`) is
// applied here at this scan's input — not inside the shared `prepareSearchQuery`
// — so the meaning of over-limit queries stays local to session history and
// the normalized forms are computed a single time, letting the per-session
// work below only do `includes` scans over the cached haystacks.
const preparedQuery = prepareSearchQuery(truncateQueryForMatch(trimmed));
// A new scan starts with no visited sessions: the touched set records only
// this scan's visits so `canCacheSessionSearchIndex` can never mistake a
// previous scan's keys for keys the current scan still needs.