Skip to content

Conversation

@yuvrajangadsingh
Copy link
Contributor

Summary

Fixes #9041

  • Adds update_search_dir() method to FileSearchManager to allow updating the search directory after initialization
  • Calls this method when the session CWD changes: new session, resume, or fork

Problem

The FileSearchManager was created once with the initial search_dir and never updated. When a user:

  1. Starts Codex in a non-git directory (e.g., /tmp/random)
  2. Resumes or forks a session from a different workspace
  3. The @filename lookup still searched the original directory

This caused no matches to be returned even when files existed in the current workspace.

Solution

Update FileSearchManager.search_dir whenever the session working directory changes:

  • AppEvent::NewSession: Use current config CWD
  • SessionSelection::Resume: Use resumed session CWD
  • SessionSelection::Fork: Use forked session CWD

Test plan

  • Start Codex in /tmp/test-dir (non-git)
  • Resume a session from a project with actual files
  • Verify @filename returns matches from the resumed session directory

@etraut-openai
Copy link
Collaborator

@codex review

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f1c1328972

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@etraut-openai
Copy link
Collaborator

@yuvrajangadsingh, thanks for the contribution. Please take a look at the code review comment from Codex.

@etraut-openai etraut-openai added the needs-response Additional information is requested label Jan 15, 2026
@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/file-search-cwd-update branch from f1c1328 to d39591e Compare January 16, 2026 06:18
@yuvrajangadsingh
Copy link
Contributor Author

Thanks for the review! I've addressed the feedback:

  • update_search_dir now cancels any in-flight search via the cancellation token
  • Clears active_search, latest_query, and is_search_scheduled to prevent stale results

This ensures old searches from the previous workspace can't pollute the new session.

@etraut-openai etraut-openai removed the needs-response Additional information is requested label Jan 16, 2026
@yuvrajangadsingh
Copy link
Contributor Author

@codex review

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d39591ee7f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/file-search-cwd-update branch from d39591e to d9583a7 Compare January 16, 2026 09:01
@yuvrajangadsingh
Copy link
Contributor Author

Addressed the second review comment as well:

Fix: Moved search_dir into SearchState (inside the mutex) so the debounce thread reads the current value when it fires, not a stale captured value.

Before: search_dir was captured at thread spawn time → race condition
After: search_dir read from mutex after debounce → always current

@codex review

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9583a7a34

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/file-search-cwd-update branch from d9583a7 to 7d9c72c Compare January 16, 2026 10:26
@yuvrajangadsingh
Copy link
Contributor Author

Addressed the third round of feedback:

Fix: Skip search if latest_query is empty when debounce fires.

This handles the case where update_search_dir() cleared the state while the debounce thread was sleeping - prevents expensive match-all traversal.

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/file-search-cwd-update branch from fa5e774 to 9718a48 Compare January 16, 2026 11:28
@etraut-openai etraut-openai added the needs-response Additional information is requested label Jan 16, 2026
@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/file-search-cwd-update branch from d1300b0 to 5a5df25 Compare January 16, 2026 22:06
@yuvrajangadsingh
Copy link
Contributor Author

Mirrored the changes to tui2 as requested. Both tui and tui2 now have:

  • update_search_dir method in file_search.rs
  • search_dir stored inside SearchState (mutex-protected) to prevent race conditions
  • Empty query check to avoid expensive match-all traversal
  • update_search_dir calls in NewSession, Resume, and ForkCurrentSession handlers in app.rs

All tests pass for both packages.

@yuvrajangadsingh
Copy link
Contributor Author

@etraut-openai Changes mirrored to tui2 as requested. Ready for another look!

@codex review

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5c56fb2f4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@yuvrajangadsingh
Copy link
Contributor Author

Addressed the P3 feedback: added a generation counter to invalidate stale debounce threads after session changes.

How it works:

  • generation field added to SearchState
  • Incremented in update_search_dir() on session change
  • Debounce threads capture generation at spawn time
  • Before proceeding with search, check if generation matches - if not, abort silently

This prevents duplicate searches when user types a new query before the old debounce fires.

@etraut-openai @codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/file-search-cwd-update branch 2 times, most recently from c5b2960 to 5c29b91 Compare January 20, 2026 11:03
@yuvrajangadsingh
Copy link
Contributor Author

Rebased on latest main to resolve conflicts.

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@yuvrajangadsingh
Copy link
Contributor Author

@etraut-openai All changes addressed - generation counter added to prevent duplicate debounce searches, mirrored to tui2. Conflicts resolved, CI passing, Codex review clean. Ready for final review.

@etraut-openai etraut-openai removed the needs-response Additional information is requested label Jan 20, 2026
@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/file-search-cwd-update branch from 5c29b91 to 387d9eb Compare January 21, 2026 09:53
@yuvrajangadsingh
Copy link
Contributor Author

Rebased again on latest main to resolve new conflicts.

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. 🎉

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/file-search-cwd-update branch from b582b70 to 511983c Compare January 22, 2026 15:10
@yuvrajangadsingh
Copy link
Contributor Author

Rebased on latest main - tui2 was removed upstream, changes now only apply to tui.

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/file-search-cwd-update branch from 19327e7 to c08722b Compare January 30, 2026 17:38
@yuvrajangadsingh
Copy link
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Add `update_search_dir` method to FileSearchManager that updates the
search directory and drops the current session so it will be recreated
with the new directory on the next query.

Replace the FileSearchManager recreation in the Resume case with a call
to this new method for more efficient CWD updates.
@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/file-search-cwd-update branch from 352790e to d8f6284 Compare January 30, 2026 21:07
Copy link
Collaborator

@etraut-openai etraut-openai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking pretty good. One small change request.

@etraut-openai etraut-openai added the needs-response Additional information is requested label Jan 30, 2026
@yuvrajangadsingh
Copy link
Contributor Author

@etraut-openai Fixed the docstring - now only mentions resume. Ready for another look.

@etraut-openai etraut-openai removed the needs-response Additional information is requested label Jan 30, 2026
@etraut-openai etraut-openai merged commit 13e85b1 into openai:main Jan 30, 2026
43 of 53 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2026
@yuvrajangadsingh yuvrajangadsingh deleted the fix/file-search-cwd-update branch January 31, 2026 03:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@filename lookup broken: “no matches” in trusted roots

2 participants