Skip to content

fix(desktop): probe py -3.12 launcher as fallback in _known_good_python() - #5864

Merged
vivekchand merged 4 commits into
mainfrom
bot-fix/issue-5859-known-good-python-py-launcher-fallback
Sep 11, 2026
Merged

fix(desktop): probe py -3.12 launcher as fallback in _known_good_python()#5864
vivekchand merged 4 commits into
mainfrom
bot-fix/issue-5859-known-good-python-py-launcher-fallback

Conversation

@vivekchand

Copy link
Copy Markdown
Owner

Summary

Fixes the recurring no_distribution Windows field failure (issue #5859) where _known_good_python() only checked one hardcoded per-user LOCALAPPDATA path for Python 3.12, returning None immediately for system-wide installs — leaving bootstrap_python_version stuck at "3.11" across multiple consecutive days of telemetry.

Root cause: _known_good_python() probed exactly one path (%LOCALAPPDATA%\Programs\Python\Python312\python.exe). When Python 3.12 was installed system-wide (or via a corporate IT policy, or the user's own python.org installer in all-users mode), the path didn't exist, the function returned None, and _retry_on_known_good_python() aborted without a retry interpreter.

Fix: After the per-user path check, fall through to py -3.12. The py launcher with an explicit minor version pin finds Python 3.12 wherever it lives — per-user, system-wide, or another path — without risking the "newest interpreter" trap that bare py poses (bare py would return Python 3.14, the very interpreter whose wheels are missing).

Changes

  • desktop/app.py: Extended _known_good_python() with a shutil.which("py") + py -3.12 fallback (per-user path is tried first; fallback runs only when that path is absent or fails the probe).
  • tests/test_desktop_bootstrap_resilience.py: Added two new tests:
    • test_known_good_python_falls_back_to_py_launcher_for_system_install — asserts that a system-wide Python 3.12 (not at the LOCALAPPDATA path) is found via py -3.12.
    • test_known_good_python_skips_py_launcher_when_absent — asserts that when py is not on PATH, no subprocess is spawned and None is returned cleanly.

Test plan

  • pytest tests/test_desktop_bootstrap_resilience.py — 65 passed (includes 2 new tests)
  • AST parse of both modified files passes
  • Manual Windows smoke: machine with Python 3.12 in system-wide location (not %LOCALAPPDATA%) — bootstrap should succeed and report bootstrap_python = 3.12

Closes #5859


No-PRD: field-failure hotfix — directly traceable to auto-filed telemetry issue with a single, narrow code path change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QngcJH4PkF4SgSdHs1UoV8


Generated by Claude Code

…on() (#5859)

When Python 3.12 is installed system-wide (not at the per-user
LOCALAPPDATA path that _winget_install_python writes), the existing
code returned None immediately — causing the interpreter retry to abort
and bootstrap_python_version to stay at "3.11", which is exactly what
repeated field-failure telemetry showed. The py launcher with an
explicit version pin (`py -3.12`) finds Python 3.12 wherever it lives
without risking the "newest interpreter" trap that bare `py` poses.

Closes #5859

Co-Authored-By: ClawMetry Autofix Bot <bot-autofix@clawmetry.dev>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QngcJH4PkF4SgSdHs1UoV8

Copy link
Copy Markdown
Owner Author

E2E Gate failure — not this PR's code.

The gate timed out after 3600 s because queue-priority.yml cancelled the queued CI run at ~16:29 UTC when a commit landed on main; the gate kept polling for status reports that never arrived. This is a CI infrastructure artefact, not a test failure from the diff.

Every check that actually ran before the cancellation passed:

  • ✅ Syntax & Lint
  • ✅ OSS golden path
  • ✅ Cross-repo handoff (C4)
  • ✅ No third-party asset loads
  • ✅ PR cites the product record
  • ✅ CodeQL

The cancelled checks (MOAT Keystone, pip install matrix, API Tests, E2E Browser, MOAT Verifier, Entitlement API, Store invariants, Wheel install) need a fresh run against this commit. Re-running now.


Generated by Claude Code

@vivekchand
vivekchand marked this pull request as ready for review September 11, 2026 18:46
@8090-software-factory

Copy link
Copy Markdown

⚠️ Drift Bot (ClawMetry): 1 potential drift finding(s)

1. Blueprint: Desktop Application Distribution

File: desktop/app.py:830

The blueprint specifies that _known_good_python() addresses the interpreter "by path, never by re-probing" using the py launcher. The PR now adds a fallback to use py -3.12 when the per-user path is absent or fails, which contradicts the blueprint's design principle to avoid any py launcher usage.
true

…ood_python()

Blueprint 'Desktop Application Distribution' requires _known_good_python()
to work "by path, never by re-probing" and to avoid any py launcher usage.
The previous fallback (py -3.12) violated this constraint as flagged by
Drift Bot.

Replace the py-launcher fallback with a Windows Registry lookup:
python.org's installer writes the exact install path under
SOFTWARE\Python\PythonCore\<minor>\InstallPath in both HKCU (per-user)
and HKLM (system-wide), giving a direct filesystem path with no launcher
or re-probing involved.

Tests updated to mock winreg (injected into sys.modules) rather than
shutil.which/py, and renamed to match the new mechanism:
  - test_known_good_python_falls_back_to_registry_for_system_install
  - test_known_good_python_returns_none_when_no_candidates

Closes #5859

Co-Authored-By: ClawMetry Autofix Bot <bot-autofix@clawmetry.dev>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QngcJH4PkF4SgSdHs1UoV8
@8090-software-factory

Copy link
Copy Markdown

✅ Drift Bot (ClawMetry): no drift detected

Drift Bot analyzed the changed files against this project's blueprints and requirements and found no drift.

Two test functions in test_desktop_bootstrap_resilience.py were renamed
(py-launcher variants → registry variants) in the previous commit.
The ratchet script detected the improvement (unlisted: 930 vs 931) and
requires the baseline to be updated.

Run: python3 scripts/check_ci_test_coverage.py --update-baseline

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QngcJH4PkF4SgSdHs1UoV8
@8090-software-factory

Copy link
Copy Markdown

✅ Drift Bot (ClawMetry): no drift detected

Drift Bot analyzed the changed files against this project's blueprints and requirements and found no drift.

Copy link
Copy Markdown
Owner Author

This branch has a merge conflict with main that cannot be auto-resolved (update_pull_request_branch returns "merge conflict between base and head").

The PR touches desktop/app.py and tests/test_desktop_bootstrap_resilience.py. Recent merges to main (notably #5588 — the routes/entitlement.py package split — and #5828) may have created the conflict. To unblock:

  1. git fetch origin main
  2. git checkout bot-fix/issue-5859-known-good-python-py-launcher-fallback
  3. git merge origin/main
  4. Resolve any conflicts, then git push

Once pushed, CI will re-run automatically.


Generated by Claude Code

Take main's updated baseline (total=1143, listed=213, unlisted_max=930);
the branch modifies an existing test file, not adding new test files, so
main's ratchet values are correct after the merge.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012WV68rruvmF4vapEVEzoZY
@8090-software-factory

Copy link
Copy Markdown

✅ Drift Bot (ClawMetry): no drift detected

Drift Bot analyzed the changed files against this project's blueprints and requirements and found no drift.

@vivekchand
vivekchand merged commit 0333692 into main Sep 11, 2026
45 of 68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[field-failure] no_distribution on Windows (py 3.11)

2 participants