Coalesce superseded file-search query signals

perfloop/codex · UNBOUNDED QUEUE

https://perfloop.ai/t/oss/case_c7zssat97s

Verdict

VERIFIED · settled 2026-08-26

Hypothesis

A static source-trace check showed the modeled TUI cadence is every changed nonempty `@` token: `on_user_query` forwards each change to `update_query`. The assigned method clones the text into `WorkSignal::QueryUpdated` and sends it to a channel created with `unbounded()`. One `matcher_worker` receives that shared channel serially; each query signal reparses the pattern, schedules a tick, and can build a match snapshot. This gives a plausible producer-over-consumer case when a large workspace makes matching or snapshot construction take longer than the user's repeated edit cadence, with no rejection, blocking, or replacement path. The consumer trace also matters: the reporter forwards snapshots without comparing `snapshot.query` to `latest_query`, while the popup ultimately returns early for a query that differs from `pending_query`; thus stale queued queries can spend matcher and event work before their result is discarded. The removed delta is the channel entries and downstream reparse/tick/snapshot/event work for superseded query values, while retaining the final value. No queue-depth or latency profile was obtained: an attempted targeted cargo test did not start because toolchain/dependency synchronization timed out, so it is not evidence for the cost claim. A case session should replay sustained changed-token edits against a large workspace at a fixed typing cadence while walking and matching, timestamp enqueue/dequeue, and record queue depth, p99 queue age, query-to-current-result latency, matcher CPU, and snapshots/events whose query is already stale. The hypothesis is confirmed if depth and p99 age climb while the matcher is busy and latest-value coalescing lowers stale-work counts and current-query tail latency without changing final results.

Change to test: Replace the per-edit `QueryUpdated(String)` enqueue with a nonblocking latest-query slot plus a single wake signal, so the matcher takes the newest pending query rather than replaying superseded ones. Keep shutdown, walk-complete, and matcher notifications reliably deliverable, and preserve the `SessionReporter` completion contract for callers even when matching work is coalesced.

Where it lives

perfloop/codex · codex-rs/tui/src/file_search.rs

Evidence

TUI file search on 32768 files, four 32-prefix bursts at 1ms cadence while walking, to the current-query result · 10 sample pairs

metric baseline candidate paired median change confidence range required result
tui_file_search_query_burst_to_current_result_ns 328900000 150300000 −54.6% (−179700000) −184600000 to −173800000 < −16445000 PASSED

Checks: 8 of 8 passed. Verification: no defect found.

Timeline