Skip to content

[ty] Fix Salsa panic propagation#24141

Merged
MichaReiser merged 2 commits intomainfrom
micha/fix-salsa-panic-handling
Mar 24, 2026
Merged

[ty] Fix Salsa panic propagation#24141
MichaReiser merged 2 commits intomainfrom
micha/fix-salsa-panic-handling

Conversation

@MichaReiser
Copy link
Copy Markdown
Member

@MichaReiser MichaReiser commented Mar 23, 2026

Summary

This PR fixes probably the most likely case why users saw astral-sh/ty#1565 in their IDE.

I added handling to convert panics to diagnostics in #17631 to check_file_impl. However, this was before check_file_impl became a Salsa query. We have to be a bit more careful, now that check_file_impl is a Salsa query.

  1. We have to add an untracked read whenever we suppress a panic because Salsa only carries over dependencies of queries that run to completion and not of queries that panic (the assumption is that all queries unwind). Adding an untracked_read ensures that the check_file_impl reruns after every change. This is more often than necessary, but it is the best we can do here without knowing the exact dependencies that were collected up to when check_file_impl's dependency panicked.
  2. Suppressing all Salsa panics in check_files_impl is unlikely to be what we want because it means the function still runs to completion even when the query was cancelled. Instead, we want to propagate a cancellation so that its db handle gets released as quickly as possible to unblock any pending mutation. However, we do need some special handling for Salsa's propagating panic to avoid regressing [red-knot] Fix CLI hang when a dependent query panics #17631. For a query A running on thread a that depends on query B running on thread b. If B panics, Salsa throws the original panic on thread b but throws a Cancelled::PropagatingPanic panic on thread a. Thread b's panic is the more useful one because it contains the actual panic information. We already convert b's panic to a Diagnostic, but we silently ignore any Cancelled::PropagatingPanic. This PR also creates a propagating panic to a diagnostic. While these panics don't contain any useful information, they at least indicate to a user that A was only partially checked. They should have a second diagnostic for B that contains the full panic information (unless B is a query that didn't run as part of project.check, e.g. hover).

Test plan

I used @AlexWaygood's panda-stubs reproducer and I was no longer able to reproduce the Salsa panic.

I plan on doing some CLI --watch testing tomorrow morning but this should block code review.

@MichaReiser MichaReiser added the bug Something isn't working label Mar 23, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 23, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 85.29%. The percentage of expected errors that received a diagnostic held steady at 78.70%. The number of fully passing files held steady at 64/133.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 23, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 23, 2026

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 23, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser marked this pull request as ready for review March 23, 2026 17:59
@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Mar 23, 2026
Ok(result) => Ok(result),
Err(error) => {
match error.payload.downcast_ref::<salsa::Cancelled>() {
Some(salsa::Cancelled::PropagatedPanic) | None => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible for PropagatedPanic to happen just because another thread was cancelled normally, while our thread was blocked on it? I.e. could this change mean that a normal file-written revision bump during parallel check ends up causing a panicked diagnostic in a thread which was blocked on another thread when the change occurred?

I'm not totally sure but looking at where Salsa throws PropagatedPanic it seems like this might be a problem?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice catch! I'll add a db.unwind_if_cancelled check above to ensure we don't take this path if there's a pending write.

@MichaReiser MichaReiser merged commit d8a0f0a into main Mar 24, 2026
49 checks passed
@MichaReiser MichaReiser deleted the micha/fix-salsa-panic-handling branch March 24, 2026 09:17
carljm added a commit that referenced this pull request Mar 25, 2026
* main:
  [ty] Avoid eager TypedDict diagnostics in `TypedDict | dict` unions (#24151)
  `F507`: Fix false negative for non-tuple RHS in `%`-formatting (#24142)
  [ty] Update `SpecializationBuilder` hook to get both lower/upper bounds (#23848)
  Fix `%foo?` parsing in IPython assignment expressions (#24152)
  `E501`/`W505`/formatter: Exclude nested pragma comments from line width calculation  (#24071)
  [ty] Fix Salsa panic propagation (#24141)
  [ty] Support `type:ignore[ty:code]` suppressions (#24096)
  [ty] Support narrowing for extended walrus targets (#24129)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants