Skip to content

[ty] Register file roots for first-party search paths#25522

Merged
MichaReiser merged 7 commits into
astral-sh:mainfrom
cheparity:main
Jun 3, 2026
Merged

[ty] Register file roots for first-party search paths#25522
MichaReiser merged 7 commits into
astral-sh:mainfrom
cheparity:main

Conversation

@cheparity

@cheparity cheparity commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes astral-sh/ty#3594.

try_register_static_roots previously skipped first-party search paths
(from ty.toml root) when registering file roots.
When queries like list_modules_in later called expect_root() on one
of these paths, ty panicked No root found for path '/path/in/the/ty/config'.

Test Plan

cargo test Result

FileRoot count increases by 1. I think it is reasonable, because it reflects the newly registered first-party search path root.

failures:

---- commands::debug_command stdout ----
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot Summary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Snapshot file: crates/ty_server/tests/e2e/snapshots/e2e__commands__debug_command.snap
Snapshot: debug_command
Source: crates/ty_server/tests/e2e/commands.rs:60
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
Expression: response
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
-old snapshot
+new results
────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────
  173   173 │ Memory report:
  174   174 │ =======SALSA STRUCTS=======
  175   175 │ `Program`                                          metadata=[X.XXMB]   fields=[X.XXMB]   count=1
  176   176 │ `Project`                                          metadata=[X.XXMB]   fields=[X.XXMB]   count=1
  177       │-`FileRoot`                                         metadata=[X.XXMB]   fields=[X.XXMB]   count=1
        177 │+`FileRoot`                                         metadata=[X.XXMB]   fields=[X.XXMB]   count=2
  178   178 │ `ModuleResolveModeIngredient`                      metadata=[X.XXMB]   fields=[X.XXMB]   count=1
  179   179 │ =======SALSA QUERIES=======
  180   180 │ `dynamic_resolution_paths -> alloc::vec::Vec<ty_module_resolver::path::SearchPath>`
  181   181 │     metadata=[X.XXMB]   fields=[X.XXMB]   count=1
────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────
To update snapshots run `cargo insta review`
Stopped on the first failure. Run `cargo insta test` to run all snapshots.


failures:
    commands::debug_command

test result: FAILED. 127 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out; finished in 22.90s

error: test failed, to rerun pass `-p ty_server --test e2e`

Screen Recording

Before:

Screen.Recording.2026-06-01.at.22.10.49.mov

After fix:

Screen.Recording.2026-06-01.at.20.23.32.mov

cheparity and others added 2 commits June 1, 2026 16:51
`try_register_static_roots` previously skipped first-party search paths
(from `ty.toml` `root`) when registering file roots.

```
  No root found for path '/my/proj/rdfdb'. Known roots: [...]
```

This applies the same logic already used for dynamic editable install
paths (in `dynamic_resolution_paths`): if a first-party path isn't
already covered by an existing root, register it as a `LibrarySearchPath`
file root. This resolves the panic without affecting paths already under
an existing root.

Fixes astral-sh/ty#3594
@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 1, 2026
@AlexWaygood AlexWaygood removed their request for review June 1, 2026 13:01
@MichaReiser MichaReiser assigned MichaReiser and unassigned carljm Jun 1, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 1, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 91.94%. The percentage of expected errors that received a diagnostic held steady at 87.09%. The number of fully passing files held steady at 92/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 1, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jun 1, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Full report with detailed diff (timing results)

@codspeed-hq

codspeed-hq Bot commented Jun 1, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 125 untouched benchmarks


Comparing cheparity:main (b729a3a) with main (b58b5cc)

Open in CodSpeed

@MichaReiser

Copy link
Copy Markdown
Member

I have to take a closer look but the performance regression suggests that we now misclassify first-party files as third-party files and assign them durability Medium instead of low

@cheparity

Copy link
Copy Markdown
Contributor Author

I have to take a closer look but the performance regression suggests that we now misclassify first-party files as third-party files and assign them durability Medium instead of low

Yeah thanks for review. It is my very first PR to an open-source project, thus may not be so comprehensive and perfect. I'd love to offer further assistance.

@carljm carljm removed their request for review June 1, 2026 18:48
… panic

Configuring a `root` in `ty.toml` creates a first-party search path, but
`try_register_static_roots` skipped first-party paths — leaving them
without a `FileRoot`.  This caused `expect_root` to panic with
"No root found for path" when those paths were later accessed.

Fix by attempting a lazy `try_add_root` in `expect_root` before panicking.
This avoids the 36% performance regression seen with the eager approach
(registering all first-party roots at init), which inadvertently changed
Salsa durability for subdirectories like `.venv`.

Fixes astral-sh#3594
@cheparity

cheparity commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

I just pushed a newer version [ty] Register file roots for first-party search paths.

I used to register root eagerly and caused performance degradation. Now the fix is a lazy fallback: if a root lookup fails, try registering one before panicking.

My performance test seems OK now.

image

@astral-sh-bot

astral-sh-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Comment thread crates/ruff_db/src/files.rs Outdated
return root;
}

// A configured first-party search path may not have been registered

@MichaReiser MichaReiser Jun 3, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While this fix the symptom, this is not the proper fix. The more likely fix is to narrow down why we fail to register the first party paths, then register them instead. I also identified another performance regression in how we handle file roots. I might take a stab at this later today

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes you are right. I debugged again and found it is tougher than I thought. I will write a more detailed root-cause-analysis in this PR later.

@cheparity

Copy link
Copy Markdown
Contributor Author

The two commits are all not so perfect and maybe we need more consideration.

The root cause is:

When we init a path that isn't in the project folder but written in ty.toml's root like:

[environment]
root = [
    "/Projects/test_ty", # project folder will be registered as FirstParty
    "/tmp/some_dep", # isn't FirstParty
]

Here's what happening:

ProjectDatabase::new:

  1. Program::from_settings -> try_register_static_roots will ignore /tmp/some_dep because it isn't FirstParty
  2. Project::from_metadata -> try_add_file_root will also ignore /tmp/some_dep as this method only registers project root path

So the key question is what kind should /tmp/some_dep belong to, Project or LibrarySearchPath.

@MichaReiser MichaReiser requested a review from ibraheemdev as a code owner June 3, 2026 10:11
@MichaReiser MichaReiser merged commit 9348403 into astral-sh:main Jun 3, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"No root found for path" panic

3 participants