Skip to content

fix(heartbeat): port bearer_gh.py edit-then-add fallback + classify gh stderr (#348) - #350

Merged
joelteply merged 1 commit into
canaryfrom
fix/heartbeat-gh-classifier-348
Apr 30, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/heartbeat-gh-classifier-348

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Fixes #348. bash heartbeat (cmd_connect.sh:1595) had two issues that bearer_gh.py already solved for the message-send path back in #285:

1. gh gist edit GIST FILE doesn't handle "file not yet in gist"

After a take-over / fresh-host race, the canonical airc-room-<channel>.json may not yet be in the gist. Plain gh gist edit GIST FILE then fails with unsure what file to edit; either specify --filename or run interactively (or per #285 silently no-ops). bearer_gh.py handles this by checking gist contents first and using -a (add) when the file isn't there. Ported the same defense to bash via a check-edit-then-fallback-to-add pattern.

2. Raw gh stderr leaked into the airc event log

On eviction, the [HOST EVICTED] marker appended the raw gh stderr verbatim. Carl saw gh's vocabulary (unsure what file to edit, 401 Unauthorized, API rate limit exceeded) in their airc event stream — opaque, off-vocabulary, no clear next action. Now classified into airc-readable buckets per the #348 comment thread:

gh stderr matches airc event reads as
rate limit / abuse detection / secondary rate-limit (gh secondary; back off 5-15 min before retry)
unsure what file / file does not exist multi-file gist disambiguation (#348 — airc bug, please report)
401 / Unauthorized / token / keyring / auth gh auth failure (run 'gh auth login -h github.com')
network / connection refused / timeout / DNS network error
(empty) unknown (no stderr captured)
anything else raw stderr (fallback)

What it doesn't change

  • Eviction threshold (still 3 consecutive failures, configurable via AIRC_HB_MAX_FAIL)
  • Self-heal mechanism (still SIGTERM parent → daemon respawns → fresh discovery)
  • Local-state cleanup (host_gist_id, room_gist_id still removed before eviction)

Test plan

  • Syntax check passes (bash -n cmd_connect.sh)
  • Live take-over scenario: take over a stale host whose gist exists with messages.jsonl only (no airc-room-<channel>.json yet) → first heartbeat should hit the disambig stderr → fallback -a should succeed → no eviction
  • Live eviction scenario: revoke gh token mid-host → 3 consecutive failures → eviction emits [HOST EVICTED] ... cause: gh auth failure (run 'gh auth login -h github.com') instead of raw 401 Unauthorized text
  • Doctor scenario heartbeat_persists_through_multifile_gist (suggested in Host eviction triggered by 'gh: unsure what file to edit; either specify --filename or run interactively' #348) — separate follow-up PR; not in scope here

Out of scope

The same classifier shape would help in cmd_send.sh's auth_failure branch (still surfaces "your GitHub token is dead" without the rate-limit-vs-auth distinction). Separate follow-up — needs a look at the Python bearer's auth_failure determination first.

Ready for review when CI clears.

🤖 Generated with Claude Code

…h stderr (#348)

bash heartbeat (cmd_connect.sh:1595) had two issues bearer_gh.py already
solved for the message-send path back in #285:

1. `gh gist edit GIST FILE` (no flag) requires the basename to already
   exist in the gist. After a take-over / fresh-host race, the canonical
   `airc-room-<channel>.json` may not yet be in the gist. Plain edit
   then fails with 'unsure what file to edit; either specify --filename
   or run interactively' (or, per #285, silently no-ops). bearer_gh.py
   handles this by checking gist contents first and using `-a` (add)
   when the file isn't there. Port the same defense to bash.

2. When eviction fires after N consecutive heartbeat failures, the
   raw gh stderr is appended to the airc event log verbatim. Carl
   sees gh's vocabulary ('unsure what file to edit', '401 Unauthorized',
   'API rate limit exceeded') in their airc event stream — opaque,
   off-vocabulary, no clear next action. Classify into airc-readable
   buckets (rate-limit / multi-file-disambig / auth / network) before
   emitting.

Bash heartbeat now:
- First attempt: `gh gist edit GIST FILE` (replace, happy path)
- On failure with disambig stderr: retry as `gh gist edit GIST -a FILE` (add)
- If both fail: count toward eviction
- On eviction: classify the captured stderr → emit one airc event with
  human-readable cause (and a #348 self-link for the multi-file case so
  Carl knows it's a known bug, not their misconfiguration)

Doesn't touch the eviction threshold, the local-state cleanup, or the
SIGTERM-parent self-heal — those were already correct. Just the
gh-call shape and the user-facing event text.

Per other-mac's #348 review: classifier covers the four buckets we
discussed (rate-limit, multi-file-disambig, auth, network) plus a
raw-fallback for unmodeled errors and an empty-stderr branch for
defense-in-depth.

Test: syntax check passes; behavioral verification will land via the
next mesh take-over scenario or a doctor scenario added in a follow-up.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@joelteply
joelteply merged commit 8c9b341 into canary Apr 30, 2026
6 checks passed
@joelteply
joelteply deleted the fix/heartbeat-gh-classifier-348 branch April 30, 2026 00:55
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