Skip to content

Fix runtime env cache not detecting changes in requirements.txt files referenced via -r#63403

Open
Lucas61000 wants to merge 16 commits into
ray-project:masterfrom
Lucas61000:issue-61759
Open

Fix runtime env cache not detecting changes in requirements.txt files referenced via -r#63403
Lucas61000 wants to merge 16 commits into
ray-project:masterfrom
Lucas61000:issue-61759

Conversation

@Lucas61000
Copy link
Copy Markdown

Description

When using -r to reference a requirements.txt file in the runtime environment pip config, Ray doesn't detect changes to the file. This causes the cached environment to be reused even when the file content has changed.

Modified _get_pip_hash in ray/_private/runtime_env/pip.py to:

  1. Detect -r references in the packages list
  2. Read and parse the requirements.txt file content
  3. Include the file content in the hash calculation (ignoring comments and empty lines)

This ensures that when the requirements.txt file changes, a new hash is generated and a new runtime environment is created.

Related issues

Closes #61759

Additional information

A re-open new PR from #61760

Lucas61000 and others added 9 commits May 17, 2026 08:58
… referenced via -r

Signed-off-by: Lucas <54979663+lucas61000@users.noreply.github.com>
Signed-off-by: Lucas <54979663+lucas61000@users.noreply.github.com>
Signed-off-by: Lucas <54979663+lucas61000@users.noreply.github.com>
Signed-off-by: Lucas <54979663+lucas61000@users.noreply.github.com>
Signed-off-by: Lucas <54979663+lucas61000@users.noreply.github.com>
- Restructure file_path logic with explicit None init and if file_path is not None block
- Remove delayed imports in tests, move to top-level imports

Signed-off-by: Lucas <54979663+lucas61000@users.noreply.github.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: Lucas <54979663+lucas61000@users.noreply.github.com>
- Restructure file_path logic with explicit None init and if file_path is not None block
- Remove delayed imports in tests, move to top-level imports

Signed-off-by: Lucas <54979663+lucas61000@users.noreply.github.com>
Remove try/except block that was silently catching and logging all
exceptions. If a requirements file cannot be read, the exception
should propagate up since the hash cannot be calculated and the
environment cannot be installed.

Also fix ruff linter errors (W293, Q000) in related test file.

Signed-off-by: Lucas <54979663+lucas61000@users.noreply.github.com>
@Lucas61000 Lucas61000 requested a review from a team as a code owner May 17, 2026 02:06
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements recursive expansion of pip requirements files within the _get_pip_hash function to ensure that changes in nested requirement files correctly trigger hash updates. It includes a new _parse_requirements_file helper and comprehensive unit tests for circular references and relative paths. Feedback indicates that the current implementation is fragile: it lacks proper error handling for missing files (leading to potential FileNotFoundError crashes), does not account for URL-based requirements, and fails to handle empty requirement strings. Additionally, it is recommended to use explicit utf-8 encoding and support inline comments in the requirements parser to improve robustness and cache consistency.

Comment thread python/ray/_private/runtime_env/pip.py
Comment thread python/ray/_private/runtime_env/pip.py
Comment thread python/ray/tests/unit/test_runtime_env_validation.py
Comment thread python/ray/_private/runtime_env/pip.py
@Lucas61000
Copy link
Copy Markdown
Author

Hi @edoakes, I've opened this new PR. Sorry again for the noise caused by the previous one. Could you please take a look when you have a chance? Thanks!

Lucas61000 and others added 3 commits May 17, 2026 14:06
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Lucas <54979663+Lucas61000@users.noreply.github.com>
Signed-off-by: Lucas <54979663+lucas61000@users.noreply.github.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 54a911d. Configure here.

Comment thread python/ray/_private/runtime_env/pip.py
@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels May 17, 2026
@edoakes edoakes added the go add ONLY when ready to merge, run all tests label May 17, 2026
@edoakes edoakes enabled auto-merge (squash) May 18, 2026 21:07
@edoakes
Copy link
Copy Markdown
Collaborator

edoakes commented May 18, 2026

Premerge CI triggered, if it passes the PR will merge: https://buildkite.com/ray-project/premerge/builds/66623

…ders in _get_pip_hash

Paths containing unresolved environment variable placeholders
(e.g. ) are expanded by the
runtime env agent only after the driver-side hash is computed. Such
paths are not real files on the driver and attempting to open them
causes FileNotFoundError -> HTTP 500 during ray.init().

Skip file expansion for these placeholders and keep the original spec
string in the hash input. Real file paths that genuinely don't exist
will still propagate FileNotFoundError as required by the earlier
review resolution.

Signed-off-by: Lucas <54979663+lucas61000@users.noreply.github.com>
auto-merge was automatically disabled May 19, 2026 06:05

Head branch was pushed to by a user without write access

@Lucas61000
Copy link
Copy Markdown
Author

@edoakes Thanks a lot for the review and approval! I've addressed the issues that could be fixed from the premerge CI feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime environment cache not updated when requirements.txt file changes

2 participants