diff --git a/pre_commit/languages/python.py b/pre_commit/languages/python.py
index 6f7c900..7a68580 100644
--- a/pre_commit/languages/python.py
+++ b/pre_commit/languages/python.py
@@ -191,7 +191,8 @@ def healthy(prefix: Prefix, language_version: str) -> bool:
 
     return (
         'version_info' in cfg and
-        _version_info(py_exe) == cfg['version_info'] and (
+        # always use uncached lookup here in case we replaced an unhealthy env
+        _version_info.__wrapped__(py_exe) == cfg['version_info'] and (
             'base-executable' not in cfg or
             _version_info(cfg['base-executable']) == cfg['version_info']
         )

Flask style test failing health check in CI
Flask's style test in GitHub actions runs `tox -e style`, which runs `pre-commit run --all-files --show-diff-on-failure`, which is failing with "An unexpected error has occurred: AssertionError: BUG: expected environment for python to be healthy() immediately after install, please open an issue describing your environment".

Note, this does not reproduce locally.

AFAIK, this first appeared in pallets/flask#3739.

We're trying to debug this over in pallets/flask#3740 where I've temporarily added a `cat .../pre-commit.log` command. Output here: https://github.com/pallets/flask/pull/3740/checks?check_run_id=1018335736#step:9:14

Neither the error message nor the log actually say what specifically about the environment is unhealthy.
 
Any ideas?

Thanks!
diff --git a/tests/languages/python_test.py b/tests/languages/python_test.py
index c419ad6..29c5a9b 100644
--- a/tests/languages/python_test.py
+++ b/tests/languages/python_test.py
@@ -8,6 +8,7 @@ import pre_commit.constants as C
 from pre_commit.envcontext import envcontext
 from pre_commit.languages import python
 from pre_commit.prefix import Prefix
+from pre_commit.util import make_executable
 
 
 def test_read_pyvenv_cfg(tmpdir):
@@ -141,3 +142,26 @@ def test_unhealthy_old_virtualenv(python_dir):
     os.remove(prefix.path('py_env-default/pyvenv.cfg'))
 
     assert python.healthy(prefix, C.DEFAULT) is False
+
+
+def test_unhealthy_then_replaced(python_dir):
+    prefix, tmpdir = python_dir
+
+    python.install_environment(prefix, C.DEFAULT, ())
+
+    # simulate an exe which returns an old version
+    exe_name = 'python.exe' if sys.platform == 'win32' else 'python'
+    py_exe = prefix.path(python.bin_dir('py_env-default'), exe_name)
+    os.rename(py_exe, f'{py_exe}.tmp')
+
+    with open(py_exe, 'w') as f:
+        f.write('#!/usr/bin/env bash\necho 1.2.3\n')
+    make_executable(py_exe)
+
+    # should be unhealthy due to version mismatch
+    assert python.healthy(prefix, C.DEFAULT) is False
+
+    # now put the exe back and it should be healthy again
+    os.replace(f'{py_exe}.tmp', py_exe)
+
+    assert python.healthy(prefix, C.DEFAULT) is True

pip install -e .[dev]
parse_log_pytest
requirements.txt
3.9
requirements-dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
cfgv==3.4.0
covdefaults==2.3.0
coverage==7.8.0
distlib==0.3.9
exceptiongroup==1.2.2
filelock==3.18.0
identify==2.6.9
iniconfig==2.1.0
nodeenv==1.9.1
packaging==24.2
platformdirs==4.3.7
pluggy==1.5.0
-e git+https://github.com/pre-commit/pre-commit.git@2e0ee5f5b216cba29e41f2b2fe1106e1d1e2e52c#egg=pre_commit
pytest==8.3.5
pytest-env==1.1.5
PyYAML==6.0.2
toml==0.10.2
tomli==2.2.1
virtualenv==20.29.3

name: pre-commit
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - cfgv==3.4.0
      - covdefaults==2.3.0
      - coverage==7.8.0
      - distlib==0.3.9
      - exceptiongroup==1.2.2
      - filelock==3.18.0
      - identify==2.6.9
      - iniconfig==2.1.0
      - nodeenv==1.9.1
      - packaging==24.2
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - pytest==8.3.5
      - pytest-env==1.1.5
      - pyyaml==6.0.2
      - toml==0.10.2
      - tomli==2.2.1
      - virtualenv==20.29.3
prefix: /opt/conda/envs/pre-commit

tests/languages/python_test.py::test_unhealthy_then_replaced
tests/languages/python_test.py::test_read_pyvenv_cfg tests/languages/python_test.py::test_norm_version_expanduser tests/languages/python_test.py::test_norm_version_of_default_is_sys_executable tests/languages/python_test.py::test_sys_executable_matches[python3.6] tests/languages/python_test.py::test_sys_executable_matches[python3] tests/languages/python_test.py::test_sys_executable_matches[python] tests/languages/python_test.py::test_sys_executable_matches_does_not_match[notpython] tests/languages/python_test.py::test_sys_executable_matches_does_not_match[python3.x] tests/languages/python_test.py::test_find_by_sys_executable[/usr/bin/python3-/usr/bin/python3.7-python3] tests/languages/python_test.py::test_find_by_sys_executable[/usr/bin/python-/usr/bin/python3.7-python3.7] tests/languages/python_test.py::test_find_by_sys_executable[/usr/bin/python-/usr/bin/python-None] tests/languages/python_test.py::test_find_by_sys_executable[/usr/bin/python3.6m-/usr/bin/python3.6m-python3.6m] tests/languages/python_test.py::test_find_by_sys_executable[v/bin/python-v/bin/pypy-pypy] tests/languages/python_test.py::test_healthy_default_creator tests/languages/python_test.py::test_healthy_venv_creator tests/languages/python_test.py::test_unhealthy_python_goes_missing tests/languages/python_test.py::test_unhealthy_with_version_change tests/languages/python_test.py::test_unhealthy_system_version_changes tests/languages/python_test.py::test_unhealthy_old_virtualenv
pre_commit/languages/python.py
pre_commit/languages/python.py