Skip to content

fix(prereqs): strict python3 probe — Windows Store alias defeats command -v - #153

Merged
joelteply merged 1 commit into
canaryfrom
fix/python-detection-windows-store-stub
Apr 27, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/python-detection-windows-store-stub

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Bug (continuum-b69f via substrate-bypass gist, 2026-04-27)

Windows Git Bash: `airc connect` failed with the misleading "Can't reach $host:7547. Is the host running 'airc connect'?" message even though the Mac side WAS hosting and reachable. Real diagnosis: every `python3 -c "..."` inside airc was silently exiting 49 against a Microsoft Store python3.exe shim.

Root cause

`%LOCALAPPDATA%\Microsoft\WindowsApps\python3.exe` is on Windows's default PATH, satisfies `command -v python3`, but is a Store-installer redirect ("Python was not found; run without arguments to install..." → exit 49). airc's top-level python detection gated on `command -v` alone, so the python→python3 shim never fired.

Fix (4 sites)

  1. airc top-level: `python3 --version >/dev/null 2>&1` instead of `command -v python3`. Store stub fails the strict probe; fallback `python` activates the shim.
  2. die "Can't reach": print `$response` (captured handshake stderr) before dying. Future debuggers see the actual error in 2 seconds. Per the global "never swallow errors" rule — continuum-b69f flagged this as a parallel finding.
  3. _doctor_probe: same strict probe. New [BROKEN] state distinguishes "on PATH but stub" from [MISSING] "absent". Hint text differs accordingly.
  4. install.sh prereq scan: same strict probe. Pre-fix install printed "All required prereqs present" against a stub-only Windows; airc then silent-fail-cascaded on first run.

Test posture

Manual stub simulation (Mac, Store stub fixture):

  • Stub python3, no real python → ERROR with Windows-specific hint ✓
  • Stub python3 + real python wrapper → fallback shim activates, `airc version` prints normally ✓

Mac integration regression:

  • identity 19/19, whois 5/5, quit 9/9, away 5/5, list 4/4, part_persists 8/8 (in progress when this body was written)

Cross-machine substrate test: this PR landing on canary unblocks continuum-b69f's Windows tab — they have a clean repro path queued.

Why no automated test

Simulating a Store stub in CI requires creating a binary that's on PATH but exits non-zero on `--version`. Doable; not yet wired into integration.sh. The manual fixture validated the four code paths; cross-port test infra (#152's territory) is the right shape for this class of probe-test.

…and -v

Bug found by continuum-b69f via cross-Mac/Windows substrate-bypass
gist on 2026-04-27. Symptoms on Windows Git Bash: airc connect failed
with "Can't reach 100.91.51.87:7547. Is the host running 'airc connect'?"
even though Test-NetConnection succeeded on the port and a manual
python socket connect to the same address completed the handshake.

## Root cause

Modern Windows ships %LOCALAPPDATA%\Microsoft\WindowsApps\python3.exe —
a Store-installer shim. The file exists, satisfies `command -v python3`,
but invocation exits 49 with stderr "Python was not found; run without
arguments to install from the Microsoft Store..." It is NOT a real
interpreter.

airc top-level (lines 17-31 pre-fix) gated python3 detection on
`command -v` alone. The Store stub fooled the gate, so the python ->
python3 shim NEVER installed. Every later `python3 -c "..."` inside
the script — including the pair handshake at line 2495 — silently
hit the Store stub, exited 49, and bash captured _pair_ok=0. The
script then printed the misleading "Can't reach" message and discarded
the captured stderr (the SECOND bug — see below).

## Fix

1. **airc top-level**: probe with `python3 --version >/dev/null 2>&1`,
   not bare `command -v`. Store stub fails fast → fallback to real
   `python` (also strict-probed) → if neither works, ERROR with a
   Windows-specific hint pointing at App execution aliases.

2. **die "Can't reach"**: print the captured handshake `$response`
   (stderr+stdout from 2>&1) before the die. Per the global "never
   swallow errors" rule — evidence is for the debugger, not the
   trash. Pre-fix, the actual Store-stub error was invisible to
   anyone trying to diagnose.

3. **_doctor_probe**: same strict --version probe. Distinguishes
   [BROKEN] (on PATH but stub) from [MISSING] (absent) so the fix
   hint matches the actual condition. Pre-fix `airc doctor` reported
   "[ok] python3" against the stub.

4. **install.sh prereq scan**: same strict probe in the installer's
   missing-prereq loop. Pre-fix, install.sh printed "All required
   prereqs present" against a stub-only Windows install, then airc
   immediately silent-fail-cascaded on first run.

## Why airc didn't catch this earlier

Windows + Microsoft Store python3 alias is the default since ~Windows
10 1903. The stub is invisible to existence-only probes. Anyone who
installs Python from python.org but doesn't disable the App execution
aliases (the default state) hits this. Joel hit it after rebooting
his Windows install today; continuum-b69f isolated it within ~5 min
on the substrate-bypass gist.

## Test posture

Manual: simulated Store stub locally with `exit 49` script on PATH:
- Stub-only:       ERROR with Windows-specific hint ✓
- Stub + real py:  fallback shim activates, airc runs ✓
Mac integration: identity 19/19, whois 5/5, quit 9/9, away 5/5,
                 list 4/4, part_persists running.

## Out of scope

The deeper bash↔PowerShell drift problem (#152) remains. This PR
fixes ONE symptom of that drift surfacing in production. Per Joel
2026-04-27: "make it work first then find patterns" — shipping the
work-now fix; architectural unification is its own conversation.
Copilot AI review requested due to automatic review settings April 27, 2026 18:19
@joelteply
joelteply merged commit 74cebe2 into canary Apr 27, 2026
2 checks passed
@joelteply
joelteply deleted the fix/python-detection-windows-store-stub branch April 27, 2026 18:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens Python prerequisite detection to avoid being fooled by the Windows Microsoft Store python3.exe PATH alias, and improves diagnostics for failed airc connect handshakes so the underlying error is visible instead of a generic “Can’t reach …” message.

Changes:

  • Switches Python detection from command -v python3 to a strict runtime probe (python3 --version) with a python fallback.
  • Prints captured pair-handshake stderr/stdout before failing the “Can’t reach …” error to aid debugging.
  • Extends strict probing into airc doctor and install.sh prereq checks, adding a new [BROKEN] status in doctor.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
install.sh Updates prereq detection to include a strict “can execute” check (currently applied to all prereqs in the loop).
airc Adds strict python detection + richer connect failure output; updates doctor prereq probing with strict execution checks and [BROKEN] state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread install.sh
Comment on lines 180 to +188
for cmd in git gh openssl ssh-keygen python3; do
if ! command -v "$cmd" >/dev/null 2>&1; then
# Strict probe: presence on PATH AND a successful --version invocation.
# The bare `command -v` form is fooled by Windows's Microsoft Store
# python3.exe alias (continuum-b69f, 2026-04-27) — the file exists,
# satisfies command -v, but exits 49 with a Store-redirect message
# when actually run. Pre-fix: install printed "All required prereqs
# present" and airc later silent-fail-cascaded at every python3 -c
# invocation. Strict probe catches this at install time.
if ! command -v "$cmd" >/dev/null 2>&1 || ! "$cmd" --version >/dev/null 2>&1; then
Comment thread airc
Comment on lines +5405 to 5414
# Strict probe: command must exist on PATH AND respond to --version with
# exit 0. The bare `command -v` form is fooled by Windows's Microsoft
# Store python3.exe alias (continuum-b69f, 2026-04-27) — the file
# exists, satisfies command -v, but exits 49 with a Store-redirect
# message on stderr when actually invoked. Same story for Windows
# python.exe alias. Strict-probe version catches this fail-fast at
# doctor time instead of letting every later python3 -c "..."
# call die silently in cmd_connect.
if command -v "$cmd" >/dev/null 2>&1 && "$cmd" --version >/dev/null 2>&1; then
printf " [ok] %s\n" "$cmd"
Comment thread airc
Comment on lines +5419 to +5426
if command -v "$cmd" >/dev/null 2>&1; then
# Present but non-functional — almost certainly a stub.
printf " [BROKEN] %s -- %s\n" "$cmd" "$purpose"
printf " '%s' is on PATH but '%s --version' fails. " "$cmd" "$cmd"
printf "Likely a Microsoft Store alias on Windows.\n"
printf " Disable: Settings -> Apps -> Advanced app settings -> App execution aliases\n"
printf " Or PATH-prepend a real install ahead of WindowsApps/.\n"
fix=$(_doctor_install_cmd_for "$mgr" "$cmd")
joelteply added a commit that referenced this pull request Apr 27, 2026
…ral gists (#154)

fix(sidecar): inherit --no-gist flag from primary so test fixtures stop leaking #general gists

Bug found by continuum-b69f via cross-Mac/Windows substrate-bypass
gist 2026-04-27. After the python3 detection fix landed on Windows
(PR #153), continuum's airc connect resolved a #general gist that
pointed at port 7556 — a Mac-side TEST FIXTURE corpse. Pre-fix:
spawn_general_sidecar_if_wanted at airc:1159 spawned the sidecar
with `--room general` only, ignoring the parent cmd_connect's
`--no-gist` flag. Test scenarios (scenario_part_persists,
scenario_general_sidecar_default, scenario_part_keeps_sidecar)
spawn the primary with --no-gist --no-discovery to stay isolated,
but the sidecar then went and PUBLISHED a real `airc room: general`
gist on the live joelteply gh namespace. cleanup_all's `kill -9`
bypasses the on-exit gist-delete trap, so the gist orphans forever.

Real users discovering #general via auto-scope hit the orphan first
(usually most-recent), try TCP to a port whose process exited 30
minutes ago, get RST, end up confused.

## Fix

If `use_gist=0` (set by --no-gist on the primary), pass --no-gist
to the sidecar spawn too. The flag inherits via the new
`_sidecar_args` array. AIRC_NO_DISCOVERY=1 already inherits via
subshell environment; only the flag needed explicit forwarding.

## Why integration tests didn't catch this

The leakage happens on the live gh account. Integration tests run
as Joel on his own gh account, so the leaked gists pollute his
own substrate — invisible to test assertions, very visible to
real users on the same gh account. Cross-account QA caught it
(continuum-b69f's Windows tab discovered the orphan that Mac
tests had created an hour earlier).

## Aftermath

Already manually deleted 6 orphan gists post-cleanup (alpha #general
+ 5x cakr-test-*). With this fix, future test runs stop creating
new ones. The trap-bypassed-by-kill-9 issue is a separate bug
(test fixtures should kill politely).

## Test posture

- part_keeps_sidecar: 6/6
- part_persists: 8/8
- general_sidecar_default: 12/12
joelteply added a commit that referenced this pull request Apr 27, 2026
…thon (PR #153 follow-up) (#156)

feat(doctor,install): probe sshd readiness so hosting works on Windows + scope ssh-stub probe to python only

Joel's directive 2026-04-27: "Both need to host so just part of doctor
and/or install" — Windows users need sshd to host airc rooms, but
Windows ships OpenSSH client only (server is opt-in capability since
Win10 1809). Pre-fix: install printed "All required prereqs present"
against a Windows install with no sshd; airc doctor probed for ssh
client only. First cross-machine pair silently failed at the
ssh-tail step.

## Changes

### `airc doctor` — new `_doctor_probe_sshd` per-platform

- **macOS**: launchctl + `systemsetup -getremotelogin` for the Remote
  Login state. Fix hint: System Settings -> Sharing -> Remote Login.
- **Linux/WSL**: `systemctl is-active` on `ssh` (Debian/Ubuntu unit
  name) and `sshd` (RHEL/Fedora). Fix hints for both pkgmgrs.
- **Windows-bash**: `powershell.exe -Command "(Get-Service sshd
  -ErrorAction SilentlyContinue).Status"` distinguishes:
    Running → ok
    Stopped/StopPending/StartPending/Paused → BROKEN with start hint
    empty → MISSING with Add-WindowsCapability hint
- **Other**: info-level skip; doesn't penalize.

### `install.sh` — same probe at install time

Same per-platform branches; warn-only (no auto-install since
elevation needed on Windows). User runs the printed PowerShell
commands once, re-runs installer, sshd is up.

### `_doctor_probe` — scope strict-probe to python only (BUG REGRESSED FROM PR #153)

The PR #153 strict-probe applied `--version` to ALL binaries. macOS BSD
ssh-keygen exits 1 on `--version` ("illegal option"), so doctor false-
positived [BROKEN] on every Mac. The new sshd probe surfaced this
regression on its first run (clean Mac doctor output revealed the
stale [BROKEN] ssh-keygen line).

Fix: only python and python3 have shadow-aliases on Windows
(Microsoft Store stubs). Other binaries are uniquely shipped by the
user's package manager — bare `command -v` is correct + portable.

## Why this matters

"Both need to host" — the airc design assumes every peer is a
first-class host candidate. Pre-fix Windows users discovered they
COULDN'T host until they hit it the hard way (peers can't connect,
no diagnostic). Post-fix, install + doctor surface it immediately
with the exact admin-PowerShell commands.

## Test posture (Mac regression)

- part_persists: 8/8
- list: 4/4
- general_sidecar_default: 12/12
- platform_adapters: 11/11
- airc doctor live: 7/7 prereqs ok, 1 sshd MISSING (this Mac has
  Remote Login off — correctly flagged with the macOS-specific fix).

## Out of scope

`airc.ps1` should also gain an equivalent probe + install.ps1 should
auto-install + start sshd when run elevated. Queued for Windows
iteration step 3.
joelteply added a commit that referenced this pull request Apr 27, 2026
…root cause) (#164)

fix(python): AIRC_PYTHON env var replaces broken export -f shim (THE root cause continuum found)

continuum-b69f's traced send 2026-04-27 found THE bug behind every
silent-broadcast-failure on Windows Git Bash. Long-form analysis in
the cross-Mac/Windows coord gist; tldr below.

## Bug

PR #153 added a bash function shim:

```bash
if ! python3 --version >/dev/null 2>&1; then
  if command -v python >/dev/null 2>&1; then
    python3() { command python "$@"; }
    export -f python3 2>/dev/null || true
  fi
fi
```

`export -f python3` is supposed to propagate the function into
subshells. On Git Bash MINGW, `export -f` succeeds silently but the
function does NOT reliably inherit into `$(...)` command-substitution
subshells. Result: every callsite that captures `$(python3 -c "...")`
output (45+ in airc) bypassed the shim, hit the Microsoft Store
stub, exited ~49 with empty stdout. The `|| echo ""` fallbacks on
those sites then silently set config values to empty strings.

Cascade:
- `get_name` → `from:"unknown"` in stored messages
- `get_config_val host_target ""` → empty → cmd_send takes HOST path
  (no `[ -n "$host_target" ]`), mirrors locally only, NEVER SSH-pushes
- `get_config_val host_airc_home ""` → empty → would-be wrong path
  anyway (but moot since SSH was skipped)

Net: continuum's Windows airc msg returned exit 0, mirrored locally,
broadcast NEVER reached the mac host's messages.jsonl. cmd_send's
"queue or die" failure paths never fired because cmd_send thought
it WAS the host. Every Win→Mac broadcast invisible-failed.

## Fix (continuum's prescription)

Replace the function-shim with a bash variable. Bash variables
propagate to subshells unconditionally — no function-export quirks.

```bash
if python3 --version >/dev/null 2>&1; then
  AIRC_PYTHON=python3
elif command -v python >/dev/null 2>&1 && python --version >/dev/null 2>&1; then
  AIRC_PYTHON=python
else
  echo "ERROR: airc requires a working python3..." >&2
  exit 1
fi
export AIRC_PYTHON
```

Then sed across airc: every `python3 -c "..."` callsite (45 of them)
becomes `"$AIRC_PYTHON" -c "..."`. The two `command -v python3`
guards (which became unreliable under the Store-stub case) become
`[ -n "${AIRC_PYTHON:-}" ]` — set if and only if a working python
resolved at startup.

## Why this matters beyond Win→Mac

The same `export -f` leak silently corrupted every config read on
Windows Git Bash. Every `airc nick` rendered nicks blank; every
`airc whois` walked an empty peer file path; every `cmd_send` was
mirroring-locally-only. Three full days of "Windows works" reports
were actually "Windows mostly works for read-only commands; sends
silent-fail." This fix unblocks the whole Windows code path.

## Test posture (Mac regression — function-shim never fired here)

- identity: 19/19
- whois: 5/5
- part_persists: 8/8
- list: 4/4
- general_sidecar_default: 12/12
- platform_adapters: 11/11

## Out of scope

continuum's secondary observations:
1. `relay_ssh` should fail loudly when host_target is empty rather
   than silent no-op. Defense in depth — this PR fixes the upstream
   cause; failing-loudly downstream is an additional safety net.
2. `|| echo ""` patterns on get_config_val / get_name silently mask
   ANY exec failure (not just Store-stub). Worth reviewing each
   callsite; out of scope for this PR which fixes the immediate
   blocker.

Both filed as separate issues for follow-up.
joelteply added a commit that referenced this pull request Apr 27, 2026
…nd-to-end (#177)

fix(msys): export MSYS2_ARG_CONV_EXCL at airc startup — last layer of cross-machine fix (continuum's catch + verify)

continuum-b69f's diagnosis 2026-04-27: even with PR #174 + #176's
argparse `--flags`, MSYS Git Bash on Windows translates argv VALUES
that look like Unix-rooted paths when bash invokes a Windows-native
binary. So `--host-airc-home /Users/joelteply/.airc` arrived at
python.exe as `--host-airc-home C:/Program Files/Git/Users/joelteply/.airc`,
the joiner cached the corrupted path, the SSH command later sent
it to a real Unix host that had no such file. Silent broadcast
failure.

## Fix

```bash
export MSYS2_ARG_CONV_EXCL="${MSYS2_ARG_CONV_EXCL:-/Users/;/home/;/root/}"
```

Set once at airc startup, exported, every airc_core invocation
inherits the same translation policy. Targeted prefix list covers
macOS / Linux / root home prefixes without breaking `/tmp/` or `/c/`
paths (which DO need translation for `--config "$CONFIG"` where
$CONFIG is on the local Windows filesystem). Honors a user override
via the `${...:-...}` default-fallback.

## End-to-end verification

continuum-b69f shipped a test broadcast from Windows after their
local patch:

> WORKING TEST: Windows-Mac airc msg via continuum-msyspatch with
> targeted MSYS exclude. should land!

Verified live in MY host's messages.jsonl on Mac:

```
{"from":"continuum-msyspatch","to":"all","ts":"2026-04-27T23:30:13Z",
 "msg":"WORKING TEST: Windows-Mac airc msg via continuum-msyspatch
 with targeted MSYS exclude. should land!","sig":"..."}
```

**Cross-machine Mac↔Windows airc end-to-end working.** This was the
last bug in the chain that started at PR #153 (Microsoft Store
python3 stub).

## Test posture (Mac, where the env var is a no-op)

- tabs 19/19, identity 19/19, whois 5/5, part_persists 8/8,
  list 4/4, general_sidecar_default 12/12, kick 12/12, events 5/5,
  platform_adapters 11/11, whois_cross_scope 6/6

## Today's full chain of cross-machine fixes

#153 → #154 → #155 → #156 → #157 → #158 → #159 → #160 → #162 →
#164 → #165 → #166 → ... → #176 → this. 27+ PRs to ship a working
cross-machine airc on Windows. Every step revealed a new layer.
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.

2 participants