Skip to content

Report the files a session read - #31

Merged
knutwannheden merged 3 commits into
mainfrom
investigate-reporting-files-ty-read
Dec 2, 2026
Merged

knutwannheden merged 3 commits into
mainfrom
investigate-reporting-files-ty-read

Conversation

@knutwannheden

Copy link
Copy Markdown
Contributor

A build that runs ty-types once per target has to declare the target's whole transitive closure as inputs: every dependency's sources and each wheel's site-packages. An edit anywhere in it re-runs the analysis, even in a module the target never imports. Bazel ignores inputs an action reports as unused (unused_inputs_list), but only if the tool can say what it read.

ty is lazy, so what it reads is far smaller than the static import closure a build would otherwise have to assume. Measured on two single-file targets against a closure that follows every import, including conditional and function-local ones:

Target imports site-packages files ty read Static closure
requests, pydantic 51 418
pandas 146 8,605

A recording System, queried per session

→ {"jsonrpc":"2.0","method":"getReadFiles","id":3}
← {"jsonrpc":"2.0","result":{"readFiles":["/…/proj/main.py","/…/proj/ty.toml","/…/libs/used.py"]},"id":3}

Salsa exposes neither a query's input dependencies nor an event for reading one, but ty reaches files through its System. The database runs on a RecordingSystem that records each content read, from before configuration discovery so ty.toml, pyproject.toml and pyvenv.cfg are included. A read that finds no file is left out: ty tries configuration files in every ancestor by reading them.

The set is cumulative since initialize and answered by its own method rather than on each getTypes. A file cached by an earlier request is not read again, so a per-request delta would under-report. A file whose inference panics still counts, and a client asks once per session instead of threading the list through every response.

Not changed here

  • Indexing the project reads every file under the project root for PEP 723 metadata, so those are all listed. CheckMode::OpenFiles would avoid that, but it changes should_check_file for existing clients.
  • The ignore files that decide what gets indexed, and what uv reads when TY_UV is set, bypass System. The README names both as exceptions to the guarantee.

read_files_name_what_inference_read_and_not_the_rest_of_a_search_root puts a dependency in a search root outside the project. It asserts the imported module and ty.toml are listed, while an unimported sibling and the missing pyproject.toml are not. It was mutation-checked: the test fails if recording is dropped, and fails if directory listings count as reads.

A new `getReadFiles` method returns every file whose content the session
has read since `initialize`: the configuration found, every file under the
project root (read when ty indexes the project for PEP 723 metadata), and
each source, stub, `py.typed` and `.pth` file reached through the search
roots. A build system that declares a target's whole import closure as
inputs can use it to learn which of them the answer did not depend on.

The database runs on a `RecordingSystem` that delegates to `OsSystem` and
records each content read, starting before configuration discovery. ty
does not necessarily read a cached file again, so the set is cumulative
per session rather than per request. A read that finds no file is not
recorded, since ty tries configuration files by reading them.
…-files-ty-read

# Conflicts:
#	CLAUDE.md
#	src/main.rs
#	src/protocol.rs
#	tests/integration/main.rs
Indexing reads only the Python files the src settings and ignore files
admit, and a notebook only when a request names it. The test now asks
for a notebook and expects it listed, covering read_to_notebook.
@knutwannheden
knutwannheden merged commit 9aab250 into main Dec 2, 2026
7 checks passed
@knutwannheden
knutwannheden deleted the investigate-reporting-files-ty-read branch December 2, 2026 20:11
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant