Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

### Fixed

- Session commands no longer re-parse the runtime's Python sources on every runtime-identity
check (Refs #862). The import closure of each source is cached by its exact bytes, so a
changed file is still parsed again and the frozen-runtime refusal is unchanged. Each check
took about one second, and service commands run it about twice.
- Six Apps defects from the 2026-11-23 repository review (Refs #595, group 2):
- CUDA inspection and qualification share one whole-token device-model match, so
`--device-model L4` no longer accepts an `L40S`.
Expand Down
9 changes: 8 additions & 1 deletion src/inferrsi/harness/manager/_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import ast
import functools
import hashlib
import json
from importlib.resources import files
Expand Down Expand Up @@ -71,6 +72,12 @@ def _imports(tree, package, path):
yield resolve_name(argument.value, package)


@functools.cache
def _module_imports(source: bytes, package: str, relative: str) -> tuple[str, ...]:
# The result depends only on these arguments, so unchanged sources are parsed once.
return tuple(_imports(ast.parse(source, relative), package, relative))


def source_files(root):
"""Derive the internal import closure, including package initializers and lazy imports."""
pending = list(_ROOTS)
Expand All @@ -94,7 +101,7 @@ def source_files(root):
pending.append(name.rpartition(".")[0])
relative = path.relative_to(root).as_posix()
sources.add(relative)
pending.extend(_imports(ast.parse(path.read_bytes(), relative), package, relative))
pending.extend(_module_imports(path.read_bytes(), package, relative))
return sorted(sources)


Expand Down
19 changes: 19 additions & 0 deletions tests/apps/test_optimization_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,25 @@ def test_runtime_identity_covers_migrated_process_domain_and_not_removed_executo
assert identity["apps/workflows/campaign.py"] == sha256(root / "apps/workflows/campaign.py")


def test_runtime_identity_parses_only_changed_sources(tmp_path, monkeypatch):
# Every session command checks the identity, so unchanged sources must not be parsed again.
installed = Path(str(_runtime.files("inferrsi")))
for name in session_runtime_identity():
target = tmp_path / name
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(installed / name, target)
monkeypatch.setattr(_runtime, "files", lambda _: tmp_path)
first = session_runtime_identity()
parsed = _runtime._module_imports.cache_info().misses
assert session_runtime_identity() == first
assert _runtime._module_imports.cache_info().misses == parsed
path = tmp_path / "harness/records/evidence.py"
path.write_bytes(path.read_bytes() + b"\n# Changed after the first identity.\n")
changed = session_runtime_identity()
assert changed["harness/records/evidence.py"] != first["harness/records/evidence.py"]
assert _runtime._module_imports.cache_info().misses == parsed + 1


def test_runtime_identity_rejects_computed_dynamic_imports(tmp_path, monkeypatch):
identity = session_runtime_identity()
installed = Path(str(_runtime.files("inferrsi")))
Expand Down
Loading