Skip to content

fix(gist): git-clone fallback + |\| true guards under rate-limit (this limit will kill people) - #155

Merged
joelteply merged 1 commit into
canaryfrom
fix/gist-view-fallback-via-git
Apr 27, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/gist-view-fallback-via-git

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Bug

Joel mid-Windows-bringup 2026-04-27: continuum-b69f's airc on Windows hit "Resolving gist..." and hung. Mac side reproduced same hang shortly after — gh sub-bucket exhausted from the day's session activity. Joel: "this limit will kill people."

Two bugs in one

Bug A — set -e + pipefail aborts script on rate-limit

```bash

pre-fix

raw_content=$(gh api "gists/$gist_id" 2>/dev/null
| jq -r '.files | to_entries[0].value.content // empty' 2>/dev/null)
```

With `set -euo pipefail` at airc:9, `gh api` returning 403 propagates non-zero up the pipeline → `$(...)` capture → set -e aborts the WHOLE script. None of the existing fallbacks ever ran. Foreground exit code: 5. Background: silent death after "Resolving gist...".

Fix: wrap each path with `|| true` so a non-zero exit becomes empty `$raw_content`; `[ -z ]` gates flow through to the next fallback. Pre-fix, the `|| true` was missing — the chain LOOKED fault-tolerant but wasn't.

Bug B — all existing fallbacks share the throttled REST bucket

Paths A (`gh api + jq`) / B (`gh gist view --raw`) / C (`curl + jq`) ALL hit `gists.github.com` REST. When that's throttled, all three return empty. No fallback that uses different transport.

Fix: new fallback path — `git clone --depth 1 https://gist.github.com/$gist_id.git\`. Git transport is on a separate quota; keeps working under REST throttle. Adds ~1s on the slow path; unblocks discovery completely.

Verified live

While `gh api` returned 403 in <0.3s:

```

  • raw_content=
  • command -v gh
  • raw_content=
  • '[' -z '' ']'
  • raw_content='{
    "airc": 1,
    ```

Git-clone path populated raw_content with valid JSON envelope. Resolution succeeded under live rate-limit.

New fallback order

  1. `gh api + jq` (REST, fast — primary)
  2. `gh gist view --raw` (REST, fallback)
  3. `git clone` gist remote (NEW — bypasses REST sub-bucket)
  4. `curl + jq` (REST, anonymous last resort)

If you have git, you survive rate-limit.

Test posture

scenario result
part_persists 8/8
list 4/4
general_sidecar_default 12/12

Out of scope (separate)

`airc.ps1` has the same REST-only chain. Same fix applies; queued for Windows iteration step 2.

… kill resolution

Bug found by continuum-b69f mid-cross-machine bring-up 2026-04-27:
gh's gist sub-bucket throttled at ~60 reads/hr; a busy session
exhausts it; every subsequent `gh api gists/<id>` AND `gh gist view`
returns HTTP 403; airc's gist-resolution chain failed silently;
discovery hung at "Resolving gist...". Joel: "this limit will kill
people."

## Two bugs in one

### 1. set -e + pipefail aborts script on rate-limit
The existing chain:
```bash
raw_content=$(gh api "gists/$gist_id" 2>/dev/null \
              | jq -r '.files | to_entries[0].value.content // empty' 2>/dev/null)
```
With `set -euo pipefail` at airc:9, when `gh api` returns 403:
- pipefail propagates the non-zero from gh up the pipeline
- the `$(...)` capture inherits the non-zero
- set -e aborts the script before reaching the next fallback

Net: rate-limit hit = entire script dies with exit 5, no diagnostic,
no fallback attempted. Fix: each path wrapped with `|| true` so a
non-zero exit becomes empty `$raw_content` and the `[ -z ]` gate
flows through to the next fallback.

### 2. All existing fallbacks use the same throttled REST bucket
Even with the abort fixed, paths A (gh api+jq) / B (gh view --raw) /
C (curl + jq) all hit gist sub-bucket which is the EXACT thing
that's exhausted. New fallback: git clone the gist's git remote.
Git transport is on a separate quota — keeps working when REST is
throttled. Adds ~1s on the slow path, unblocks discovery completely.

## New chain (insertion-ordered fallthrough)

1. gh api + jq          (REST, fast — primary path)
2. gh gist view --raw   (REST, fallback)
3. **git clone gist remote** (NEW — bypasses REST sub-bucket)
4. curl + jq            (REST, anonymous last resort)

If you have git, you survive rate-limit. The git-clone path was
verified live: while gh api returned 403 in <0.3s, git clone of the
same gist returned the JSON envelope cleanly in ~0.3s.

## Test posture (Mac, regression check)

- part_persists: 8/8
- list: 4/4
- general_sidecar_default: 12/12

The actual rate-limit-recovery path was verified by `bash -x` trace
under live throttle: `+ raw_content='{` shows git-clone populating
raw_content after both gh paths returned empty.

## Out of scope (filed sep)

airc.ps1 has the same gist-resolution chain pattern (REST-only).
Same fix applies — Windows iteration step 2 in the canary backlog.
Copilot AI review requested due to automatic review settings April 27, 2026 19:05
@joelteply
joelteply merged commit 3606845 into canary Apr 27, 2026
1 of 2 checks passed
@joelteply
joelteply deleted the fix/gist-view-fallback-via-git branch April 27, 2026 19:06

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

Note

Copilot was unable to run its full agentic suite in this review.

Improves gist resolution reliability in cmd_connect() under GitHub REST rate limiting by preventing set -euo pipefail from aborting the script and by adding a non-REST fallback via git clone.

Changes:

  • Wrap REST-based gist fetch pipelines with || true so failed commands don’t terminate the script before fallbacks run.
  • Add a new git clone-based fallback path to bypass the GitHub REST gist sub-bucket rate limit.
  • Extend inline documentation describing the failure mode and the fallback chain behavior.

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

Comment thread airc
# slow path but unblocks discovery completely.
if [ -z "$raw_content" ] && command -v git >/dev/null 2>&1; then
local _gist_tmp; _gist_tmp=$(mktemp -d -t airc-gist-resolve.XXXXXX 2>/dev/null || echo "")
if [ -n "$_gist_tmp" ] && git clone --depth 1 --quiet "https://gist.github.com/$gist_id.git" "$_gist_tmp" 2>/dev/null; then

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

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

git clone over HTTPS can block waiting for interactive credential input (e.g., no credential helper configured, private gist, expired auth), which would reintroduce a “hang” during “Resolving gist…”. To keep this fallback non-interactive, run git with prompts disabled (e.g., GIT_TERMINAL_PROMPT=0 and/or an askpass override) so auth failures fail fast and fall through cleanly.

Suggested change
if [ -n "$_gist_tmp" ] && git clone --depth 1 --quiet "https://gist.github.com/$gist_id.git" "$_gist_tmp" 2>/dev/null; then
if [ -n "$_gist_tmp" ] && GIT_TERMINAL_PROMPT=0 git clone --depth 1 --quiet "https://gist.github.com/$gist_id.git" "$_gist_tmp" 2>/dev/null; then

Copilot uses AI. Check for mistakes.
Comment thread airc
Comment on lines +2259 to +2265
# Gists typically contain ONE file (airc envelopes always do).
# Take the first non-dotfile, non-.git entry. If a future gist
# shape ships multiple files we'll add an explicit airc-envelope
# filename convention; for now the single-file assumption is
# sound across every gist airc has ever published.
local _gist_file
_gist_file=$(find "$_gist_tmp" -maxdepth 1 -type f ! -name '.git*' 2>/dev/null | head -1 || true)

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

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

The comment says “first non-dotfile, non-.git entry”, but the find predicate only excludes names matching .git* (it does not exclude all dotfiles). Either adjust the predicate to exclude dotfiles generally, or update the comment to match the actual selection logic.

Copilot uses AI. Check for mistakes.
joelteply added a commit that referenced this pull request Apr 27, 2026
…_* config write (continuum's retest) (#165)

fix(airc): two PR #164 followups — sed missed line 1372 + harden host_* config write

continuum-b69f's PR #164 retest 2026-04-27 found two remaining bugs:

## Bug A: sed missed `python3 -u -c '` at line 1372

PR #164's sed pattern was `python3 -c` — didn't match the `-u` flag
sandwiched between python3 and -c at line 1372 (monitor_formatter
unbuffered launch). On Windows Git Bash with the Microsoft Store
stub, this site silent-failed too: monitor_formatter crashed at
launch, the inbound stream went dark, joiner couldn't see anything
the host wrote. One-line fix: `python3 -u -c '` →
`"$AIRC_PYTHON" -u -c '`.

## Bug B: host_* config write silently no-op'd if ANY bash subst broke

continuum's joiner config showed `name`, `host`, `host_target`,
`created` but NOT `host_airc_home`, `host_name`, `host_port`,
`host_ssh_pub`, `host_identity` — all five fields written together
by the heredoc at line 2768.

Pre-fix:
```bash
HOST_IDENTITY="$host_identity_json" "$AIRC_PYTHON" -c "
import json, os
c = json.load(open('$CONFIG'))
c['host_airc_home'] = '$host_airc_home'
c['host_name']      = '$peer_name'
c['host_port']      = ${peer_port:-7547}
c['host_ssh_pub']   = '''$host_ssh_pub'''
...
" 2>/dev/null || true
```

Five bash substitutions into python source. If ANY substitution
breaks python parsing (newline in host_ssh_pub, special char in
host_airc_home, empty/non-numeric peer_port, etc.) the whole heredoc
crashes at parse time. `2>/dev/null || true` swallows the SyntaxError
and zero fields land. Five silently-empty config fields downstream:
- host_airc_home empty → cmd_send computes wrong remote path
- host_name empty → "Connected to ''" banner
- host_port wrong → SSH targets wrong port (or 7547 fallback)
- host_ssh_pub empty → host's SSH key not in authorized_keys
- host_identity empty → airc whois <host> shows (unset)

Post-fix: pass everything as env vars; python reads from os.environ.
Bash never touches the python source. Also emit stderr to a warn line
(not /dev/null) so the future debugger can see it. Also catch
ValueError on int(host_port) so a non-numeric value falls back to
7547 instead of dying.

## Pattern lesson

bash → python heredoc with bash variable substitution into the
python SOURCE is fragile. Any unusual byte in the variable can
break python parsing. Same shape as the resolver heredoc that
broke pre-PR #155 with set -e + pipefail.

Repeat-offender pattern. Consider a sweep: every `"$AIRC_PYTHON" -c
"..."` heredoc that contains `$bash_var` substitutions — convert to
env-var pass + os.environ. Out of scope for this PR (would touch
~30 sites); file as a separate canary follow-up.

## Test posture

Mac regression (5 scenarios, all green):
- identity 19/19
- whois 5/5
- part_persists 8/8
- list 4/4
- general_sidecar_default 12/12

End-to-end Win→Mac broadcast verification still pending continuum's
retest after pulling this fix.
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