Skip to content

Fix rules files not loading and config file rescan clearing tokens#53659

Open
AJenbo wants to merge 1 commit intozed-industries:mainfrom
AJenbo:fix-rescan
Open

Fix rules files not loading and config file rescan clearing tokens#53659
AJenbo wants to merge 1 commit intozed-industries:mainfrom
AJenbo:fix-rescan

Conversation

@AJenbo
Copy link
Copy Markdown

@AJenbo AJenbo commented Apr 10, 2026

Fixes #52453
Fixes #53246

Both issues were introduced by #51208 ("Handle Linux FS Rescan Events"), which added PathEventKind::Rescan handling.

Rules files not loading (#52453)

load_worktree_info_for_system_prompt called load_worktree_rules_file synchronously, which uses entry_for_path() on the current worktree snapshot. If the background scanner hasn't finished its initial scan, the entry doesn't exist yet and the lookup returns None — the code concludes no rules file exists. This was always a latent race condition, but became more visible after Rescan events were introduced, since they can trigger additional WorktreeUpdatedEntries churn that interacts with the refresh mechanism.

The fix awaits scan_complete() on local worktrees before performing the rules file lookup, ensuring the full directory tree is indexed first.

Config file rescan clearing OAuth tokens (#53246)

The Rescan handlers in watch_config_dir used fs.load(file_path).await.unwrap_or_default(), which turns any file-read error into an empty string. This empty string flows to consumers like CopilotChat, where extract_oauth_token("") returns None, causing the OAuth token to be unconditionally overwritten with None — triggering re-authentication.

The fix changes both Rescan handlers to skip files that fail to load (using if let Ok(contents) = ...), matching the pattern already used by the Created/Changed handler.

Release Notes:

  • Fixed rules files (AGENTS.md, CLAUDE.md, .rules, etc.) sometimes not being applied in agent threads.
  • Fixed GitHub Copilot re-prompting for authentication after filesystem rescan events.

Wait for worktree scan to complete before looking up rules files
(AGENTS.md, CLAUDE.md, .rules, etc.) so that entry_for_path does not
return None for files that exist on disk but haven't been indexed yet.

In watch_config_dir, skip files that fail to load during Rescan events
instead of sending empty content. The previous unwrap_or_default()
turned read errors into empty strings, which consumers like CopilotChat
interpreted as 'file has no content', clearing OAuth tokens and
triggering repeated re-authentication prompts.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Apr 10, 2026
@AJenbo AJenbo changed the title Fix rules files not loading and config file rescan clearing tokenswwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww Fix rules files not loading and config file rescan clearing tokens Apr 10, 2026
@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Apr 10, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator bot requested review from a team, benbrandt and osyvokon and removed request for a team April 10, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Github Co-pilot OAuth issue, prompting me re-login every 2 mins CLAUDE.md and AGENTS.md not being applied as rule in thread

2 participants