Skip to content

fix(parser,prereq): jq is required — fallback parser corrupts gist envelopes without it (continuum's diagnosis) - #162

Merged
joelteply merged 1 commit into
canaryfrom
fix/jq-fallback-parser-and-prereq
Apr 27, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/jq-fallback-parser-and-prereq

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Bug (continuum-b69f Win→Mac e2e 2026-04-27)

Windows airc connect "succeeded" but:

  • displayed peer name was `'"invite":"authenticator-fd63'` (JSON syntax leaked)
  • `room_name` file never written to disk
  • subsequent `airc msg` stored with `from:"unknown"` and never landed on mac host

Root cause

`cmd_connect`'s gist resolver has two paths. The JSON-envelope parse path is gated on `command -v jq`. Windows Git Bash ships without jq by default. Falls through to grep-based fallback that captures the JSON `"invite":"...` key prefix into the parsed invite, AND never sets `resolved_room_name`. Hence both the corrupt peer name AND the missing room_name file.

Three-layer fix

1. jq is now a required prereq. install.sh, install.ps1, airc doctor — all updated. winget id `jqlang.jq`; brew/apt/dnf/pacman/apk all use bare `jq`.

2. Legacy fallback strips JSON-key prefix. `sed -E 's/^[^a-zA-Z]+//'` before @-split. Defense in depth for any minimal environment that escapes layer 1.

3. Legacy fallback extracts room name. Walks raw_content for `"name": "..."` regex and captures the value when jq is absent. Same envelope shape; works without any JSON parser.

Test posture

Doctor live on this Mac shows new `[ok] jq`. Mac regression all green (part_persists 8/8, list 4/4, general_sidecar_default 12/12, platform_adapters 11/11).

…rrupts gist envelopes without it

Bug found by continuum-b69f Win→Mac e2e 2026-04-27 (forensics in
cross-Mac/Windows coord gist):

continuum's airc connect from Windows Git Bash succeeded with
"Connected to '\"invite\":\"authenticator-fd63'" — JSON envelope syntax
leaked into the displayed peer name. Worse:
- room_name file never written to disk
- subsequent airc msg stored locally with from:"unknown"
- broadcast never landed in mac host's messages.jsonl

Two bugs from one root cause: **jq missing on Windows Git Bash.**

## Root cause

cmd_connect's gist resolver has two paths:
1. JSON envelope parse via jq — sets `resolved` (invite string) AND
   `resolved_room_name` from `.name` field.
2. Legacy raw-string fallback — bare grep for the first `@.*@` line.

When jq is absent on PATH (the default state on Git Bash), path 1
short-circuits silently. Path 2 grabs the whole quoted JSON line
including the `"invite":"` key prefix. The downstream @-split
(which extracts name@user@host:port) then captures the JSON-key
fragment as the peer name.

Worse: `resolved_room_name` is ONLY set inside path 1's room-case
branch. Path 2 leaves it empty. Hence the `if [ -n "$resolved_room_name" ]; then echo ... > room_name`
write at line 2495 never fires. Joiner connects "successfully" but
doesn't know what room they're in. Subsequent msg sends queue/ship
without room context; host filters them out.

## Fix (three layers)

### Layer 1: jq is now a required prereq (install.sh + install.ps1 + airc doctor)

- install.sh: added `jq` to the prereq install loop. pkgname_for
  maps `jq` → `jqlang.jq` on winget, bare `jq` on
  brew/apt/dnf/pacman/apk.
- install.ps1: new `Install-IfMissing -Name 'jq' -WingetId 'jqlang.jq'`
  line.
- airc doctor: new probe `_doctor_probe "jq" "Gist envelope parser
  (rooms, addresses)"` flags missing jq with the same install hint
  shape as other prereqs.

### Layer 2: legacy fallback now strips JSON-key prefix

The grep-based fallback can still be reached on minimal environments
that genuinely don't have jq (busybox+nothing, weird CI). Pre-fix it
captured `"invite":"authenticator-fd63@...` verbatim. Post-fix:
`sed -E 's/^[^a-zA-Z]+//'` strips leading non-letter characters before
the @-split runs. JSON quotes, key syntax, leading whitespace all
stripped uniformly.

### Layer 3: legacy fallback now extracts room name

When jq is missing, the fallback also walks the raw_content for
`"name": "..."` and captures the value into `resolved_room_name`.
Same JSON envelope shape as the jq path; sed-only so it works
without any JSON parser. Empty for legacy gists (no envelope) —
matches pre-existing behavior on those.

## Why three layers

Layer 1 (jq required) is the canonical fix — every install going
forward has jq, the JSON path always works. Layers 2+3 are defense
in depth: any environment that escapes layer 1 (older airc installs,
manual installs, distros where jq install fails) won't silently
corrupt — fallback now produces a correct peer name AND the right
room_name file.

## Test posture

Mac doctor with PR live: all probes [ok] including new jq.

```
[ok] git
[ok] gh
[ok] gh authenticated
[ok] openssl
[ok] ssh
[ok] ssh-keygen
[ok] python3
[ok] jq
[ok] sshd (Remote Login enabled)
[ok] tailscale (optional) -- daemon up
```

Mac regression:
- part_persists: 8/8
- list: 4/4
- general_sidecar_default: 12/12
- platform_adapters: 11/11

## Out of scope

continuum-b69f's UTF-8 → Latin-1 double-decode on `→` is a separate
encoding bug in the bash → python3 → jq pipeline. File for
follow-up; this PR is JSON-key-leak + jq-as-prereq.
Copilot AI review requested due to automatic review settings April 27, 2026 20:23
@joelteply
joelteply merged commit 4a81484 into canary Apr 27, 2026
1 check passed
@joelteply
joelteply deleted the fix/jq-fallback-parser-and-prereq branch April 27, 2026 20:24
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.

1 participant