[file-search] Session can complete before the first query is processed

Open
#33,729 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
rust
Domain
cli

Research direction

Start in the file-search/src/lib.rs test module with the provided regression test, then inspect matcher_worker and the create_session → update_query → wait_for_complete path. Run just test -p codex-file-search initial_query_survives_preemption_after_session_creation; done means a preempted session does not complete before its first query and the test reports "file-0039".

Written by the indexing model from the issue text.

Description

bug CLI
What issue are you seeing?

FileSearchSession can call SessionReporter::on_complete() after the directory walk finishes but before the matcher has processed its first QueryUpdated signal.

This matters to the synchronous run() path: it creates the session, starts the walker and matcher workers, then sends the query and waits for completion. The walker and caller send through different clones of the channel sender. For a fast or empty walk, WalkComplete can be received first, causing run() to return the reporter's default empty snapshot before its requested query has run.

What steps can reproduce the bug?

On main commit 315195492c80fdade38e917c18f9584efd599304, add the following regression test inside the existing file-search/src/lib.rs test module:

#[test]
fn initial_query_survives_preemption_after_session_creation() {
    let dir = create_temp_tree(/*file_count*/ 40);
    let reporter = Arc::new(RunReporter::default());
    let session = create_session(
        vec![dir.path().to_path_buf()],
        FileSearchOptions::default(),
        reporter.clone(),
        /*cancel_flag*/ None,
    )
    .expect("session");

    // Model the caller being descheduled after create_session returns but
    // before run() can send its initial query.
    thread::sleep(Duration::from_millis(100));
    session.update_query("file-0039");

    let snapshot = reporter.wait_for_complete();
    assert_eq!(snapshot.query, "file-0039");
}

The short pause models a valid operating-system preemption at the exact boundary used by run(); the test otherwise follows the real create_session → update_query → wait_for_complete path and does not inject private work signals.

Run:

just test -p codex-file-search initial_query_survives_preemption_after_session_creation

The test fails on both the initial run and nextest retry:

left: ""
right: "file-0039"
What is the expected behavior?

Completing the directory walk should not complete a session that has not received a query. Once a query is received, the existing contract should remain unchanged: the reporter is eventually completed for that update.

Additional information

Root-cause hypothesis: matcher_worker gates completion on !status.running && walk_complete, but it does not track whether a query has ever been received. A minimal fix is to record receipt of the first QueryUpdated and require that state before reporting normal completion.

The session-based implementation originated in merged PR #9939. I searched existing issues and pull requests using the relevant file-search symbols and completion-order terms; I found related session completion discussions in that PR, but no report covering WalkComplete arriving before the first QueryUpdated signal.

I have a focused regression test and local one-commit fix ready. I would be happy to submit it if a Codex maintainer invites a PR.

Dominant language
Rust
Stars
125k
Forks
19.5k
Avg merge
1m
Merged PRs (30d)
1k

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openai/codex

All issues in openai/codex

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.