Skip to content

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

Merged
probably-neb merged 1 commit intozed-industries:mainfrom
AJenbo:fix-rescan
Apr 21, 2026
Merged

Fix rules files not loading and config file rescan clearing tokens#53659
probably-neb merged 1 commit intozed-industries:mainfrom
AJenbo:fix-rescan

Conversation

@AJenbo
Copy link
Copy Markdown
Contributor

@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.

@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
@zelenenka zelenenka assigned probably-neb and unassigned benbrandt Apr 13, 2026
@zelenenka zelenenka requested review from probably-neb and removed request for benbrandt and osyvokon April 13, 2026 11:38
@probably-neb
Copy link
Copy Markdown
Collaborator

looks good! seems like it just needs a cargo fmt pass :)

@AJenbo
Copy link
Copy Markdown
Contributor Author

AJenbo commented Apr 15, 2026

@probably-neb done

Also some one has verified that it fixes the issue: #53246 (comment)

@cvanelteren
Copy link
Copy Markdown
Contributor

cvanelteren commented Apr 16, 2026

Codex is behaving weirdly (not sure if related) but the zed agent works well. The codex agent was not able to call tools or do progress but again not sure if related to this -- don't use codex much within zed.

@AJenbo
Copy link
Copy Markdown
Contributor Author

AJenbo commented Apr 16, 2026

The failing CI appears to be unrelated and happens in main as well.

@AJenbo
Copy link
Copy Markdown
Contributor Author

AJenbo commented Apr 20, 2026

@probably-neb anything else needed here?

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.
@probably-neb
Copy link
Copy Markdown
Collaborator

I don't think so! I rebased the branch to hopefully get the fix in for that CI issue. Will merge once green. Thanks!

@probably-neb probably-neb enabled auto-merge (squash) April 21, 2026 08:18
@probably-neb probably-neb merged commit 4a630f0 into zed-industries:main Apr 21, 2026
31 checks passed
@AJenbo AJenbo deleted the fix-rescan branch April 21, 2026 08:32
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

5 participants