Repository navigation
fix(#285): host airc msg publishes to gist (silent-loss + TDD) - #286
Conversation
Two bugs compounded into the worst silent-loss class — host broadcasts
returned 'delivered' but the gist was never written; joiners polling
the gist saw nothing; user surface lied success.
## Bug 1: cmd_send.sh host-path was local-append-only
The else-branch (host case, line ~363 pre-fix) ended with:
echo "\$full_msg" >> "\$MESSAGES"
with a comment "Joiners' SSH tails will pick it up" — relic of pre-3c
when SSH bearer's tail -F over SSH was the wire. Phase 3c (#281) deleted
SSH wholesale; joiners now poll the gist via GhBearer; a local-only
append disappears.
Fix: after the local audit append, ALSO call bearer_cli send with the
host's --room-gist-id so GhBearer publishes to the gist. Same wrap-if-
recipient-known logic as the joiner branch, so DMs to peers with
stored x25519_pub get encrypted and broadcasts go plaintext.
## Bug 2: GhBearer._gh_gist_write_file silent no-op on first send
\`gh gist edit GIST_ID file\` (no flag) returns exit 0 BUT silently does
nothing when the target filename doesn't exist in the gist. The
fallback chain ('try plain edit; on non-zero, retry with -a') never
fires because the first call returns 0 without writing. Production
gists start with only an airc-invite seed (no messages.jsonl), so
EVERY first host send hit this trap.
Fix: read the gist's file list FIRST, choose the correct subcommand:
- file already in gist → \`gh gist edit GIST file\` (replace)
- file NOT in gist → \`gh gist edit GIST -a file\` (add)
One extra GET, but eliminates the silent-no-op trap. Defense-in-depth:
if the existence check disagrees with reality (concurrent peer added
the file between our GET and our edit), retry the OTHER subcommand
once before giving up.
## Why the existing 123 integration tests didn't catch this
- All scenarios that exercise multi-peer messaging used \`--no-room
--no-gist\` for speed. That flag bypasses gh entirely; the test rig
rode on the SSH-bearer TCP-handshake path. After Phase 3c moved
production to GhBearer, the test rig kept exercising a stripped-down
path that doesn't match production architecture.
- scenario_bearer_gh DOES use a real gh gist BUT pre-seeds it with
messages.jsonl (the 'happy path' shape). Production gists start with
airc-invite seed (NOT messages.jsonl), so the first send is a CREATE
not a REPLACE — exactly the bug. The seed shape masked it.
Two new TDD scenarios cover both paths post-fix:
- \`gh_send_creates_messages_jsonl\` (unit-of-bearer): seeds gist with
airc-invite (matching production), runs bearer_cli send directly,
asserts gist now contains messages.jsonl with the marker. Pre-fix:
bearer reports 'delivered', gist unchanged. Post-fix: green.
- \`host_msg_publishes_to_gist\` (end-to-end cmd_send→bearer): spawns a
real host with --room (no --no-gist), runs \`airc msg <marker>\`,
asserts gist's messages.jsonl contains the marker. Pre-fix: cmd_send
never invoked bearer_cli on host path. Post-fix: green.
Verified locally:
- gh_send_creates_messages_jsonl: 5/5 (was 3/2 before fix)
- host_msg_publishes_to_gist: 2/2 (was 1/1 before fix)
Closes #285. #283 (sidecar) and #284 (cross-room DM) are tracked
separately and will get their own TDD + fix.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Fixes a Phase 3c regression where host-side airc msg could silently fail to publish to the room gist (and where gh gist edit can “succeed” without writing when the target file doesn’t yet exist), closing #285.
Changes:
- Update host-side
cmd_sendto publish outbound messages to the room gist (in addition to local audit logging). - Fix
GhBearergist writes to correctly addmessages.jsonlon first send (choosegh gist edit -avs replace based on gist file presence). - Add two new integration scenarios to reproduce and prevent the silent-loss regressions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
lib/airc_bash/cmd_send.sh |
Host-path now calls bearer_cli send with --room-gist-id so joiners polling the gist receive host messages. |
lib/airc_core/bearer_gh.py |
_gh_gist_write_file detects whether messages.jsonl exists and uses the correct gh gist edit mode to avoid silent no-op. |
test/integration.sh |
Adds TDD integration scenarios covering first-send file creation and end-to-end host publish to gist. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| echo " ⚠ Gist publish failed (kind=${_host_kind:-empty}); broadcast did not reach joiners." >&2 | ||
| echo " Local audit log has the message; joiners polling the gist see nothing." >&2 |
There was a problem hiding this comment.
The warning message says “broadcast did not reach joiners”, but this branch also handles DMs (peer_name != all). Consider rewording to “message did not reach…” (and keep output formatting consistent with other ⚠ warnings in the repo, which typically use two spaces after the symbol).
| echo " ⚠ Gist publish failed (kind=${_host_kind:-empty}); broadcast did not reach joiners." >&2 | |
| echo " Local audit log has the message; joiners polling the gist see nothing." >&2 | |
| echo " ⚠ Gist publish failed (kind=${_host_kind:-empty}); message did not reach its remote destination." >&2 | |
| echo " Local audit log has the message; the remote recipient(s) see nothing." >&2 |
| fail "post-send: gist messages.jsonl missing marker (content len: ${#content})" | ||
| fi | ||
|
|
||
| trap - EXIT |
There was a problem hiding this comment.
These scenarios set a new trap ... EXIT, which overwrites the suite-level trap cleanup_all EXIT installed earlier in the file, and later trap - EXIT clears the EXIT handler entirely. If the script exits unexpectedly after this point (or later scenarios fail), the global cleanup won’t run. Consider chaining cleanup (include cleanup_all in the EXIT trap) or saving/restoring the previous EXIT trap handler instead of clearing it.
| trap - EXIT | |
| trap cleanup_all EXIT |
| fi | ||
| pass "host published room gist: $gid" | ||
|
|
||
| trap "gh gist delete '$gid' --yes 2>/dev/null || true" EXIT |
There was a problem hiding this comment.
Same EXIT-trap issue as above: this overwrites the global trap cleanup_all EXIT and later trap - EXIT removes EXIT cleanup for the remainder of the test run. Please chain or restore the previous EXIT handler so suite cleanup remains reliable even on early exit.
| trap "gh gist delete '$gid' --yes 2>/dev/null || true" EXIT | |
| local __airc_prev_exit_trap __airc_prev_return_trap | |
| __airc_prev_exit_trap=$(trap -p EXIT) | |
| __airc_prev_return_trap=$(trap -p RETURN) | |
| trap "gh gist delete '$gid' --yes 2>/dev/null || true; if [ -n \"\$__airc_prev_exit_trap\" ]; then eval \"\$__airc_prev_exit_trap\"; fi" EXIT | |
| trap 'if [ -n "$__airc_prev_exit_trap" ]; then eval "$__airc_prev_exit_trap"; else trap - EXIT; fi; if [ -n "$__airc_prev_return_trap" ]; then eval "$__airc_prev_return_trap"; else trap - RETURN; fi' RETURN |
|
|
||
| # Run airc msg from the host scope, broadcasting a unique marker. | ||
| local marker="tdd-host-publish-marker-$(date +%s%N)" | ||
| AIRC_HOME=/tmp/airc-it-tdd-h/state "$AIRC" msg "$marker" >/dev/null 2>&1 || true |
There was a problem hiding this comment.
airc msg is invoked with || true, which can hide real failures (e.g., cmd_send dying due to monitor down / auth failure). Since this scenario is asserting end-to-end delivery, it should treat a non-zero exit as a test failure (capture stderr/stdout for diagnosis) to avoid masking regressions.
| AIRC_HOME=/tmp/airc-it-tdd-h/state "$AIRC" msg "$marker" >/dev/null 2>&1 || true | |
| local send_out send_status | |
| send_out=$(AIRC_HOME=/tmp/airc-it-tdd-h/state "$AIRC" msg "$marker" 2>&1) | |
| send_status=$? | |
| if [ "$send_status" -ne 0 ]; then | |
| fail "airc msg failed with exit $send_status: $send_out" | |
| trap - EXIT | |
| gh gist delete "$gid" --yes 2>/dev/null || true | |
| cleanup_all; return | |
| fi |
| gh gist delete "$gid" --yes 2>/dev/null || true | ||
| cleanup_all |
There was a problem hiding this comment.
This scenario deletes the room gist before tearing down the host process (cleanup_all runs after gh gist delete). If the host is still running its heartbeat / gist writes, this can introduce flaky behavior or noisy failures. Prefer stopping the host/monitor first (or ensure teardown happens before deleting the gist).
| gh gist delete "$gid" --yes 2>/dev/null || true | |
| cleanup_all | |
| cleanup_all | |
| gh gist delete "$gid" --yes 2>/dev/null || true |
| # Detect whether messages.jsonl exists in the gist BEFORE choosing | ||
| # subcommand. Single extra GET, but eliminates the silent-no-op | ||
| # trap. If the GET fails, default to -a (add) since that path | ||
| # surfaces real errors when the file already exists (gh complains | ||
| # about duplicate filename), whereas plain edit silently no-ops. | ||
| existing = _gh_api_get(gist_id) | ||
| file_exists_in_gist = ( | ||
| existing is not None | ||
| and isinstance(existing.get("files"), dict) | ||
| and _MESSAGES_FILE in existing["files"] | ||
| ) |
There was a problem hiding this comment.
GhBearer.send() already calls _gh_api_get(gist_id) (line ~288) and then _gh_gist_write_file() calls _gh_api_get(gist_id) again to determine file existence. This doubles API calls per send and increases rate-limit/latency cost. Consider passing the already-fetched gist (or just a file_exists_in_gist boolean derived from it) into _gh_gist_write_file to avoid the extra GET while still avoiding the gh CLI silent-no-op trap.
| gh_send_creates_messages_jsonl) scenario_gh_send_creates_messages_jsonl ;; | ||
| host_msg_publishes_to_gist) scenario_host_msg_publishes_to_gist ;; | ||
| ""|all) |
There was a problem hiding this comment.
The new scenarios are added as selectable MODEs, but they aren’t included in the default ""|all) run list below. Since these are the regression tests for #285, consider invoking them from the all branch as well (they already self-skip when gh isn’t authed, similar to scenario_bearer_gh). Otherwise the main CI/smoke path may not exercise the fix.
| if [ -n "$_host_room_gist_id" ]; then | ||
| local _host_outcome | ||
| _host_outcome=$(printf '%s' "$_host_wire_msg" | "$AIRC_PYTHON" -m airc_core.bearer_cli send \ | ||
| "$peer_name" "$active_channel" \ | ||
| --room-gist-id "$_host_room_gist_id") | ||
| local _host_kind | ||
| _host_kind=$(printf '%s' "$_host_outcome" | "$AIRC_PYTHON" -c 'import json,sys; print(json.load(sys.stdin).get("kind",""))' 2>/dev/null) | ||
| case "$_host_kind" in | ||
| delivered) : ;; | ||
| *) | ||
| echo " ⚠ Gist publish failed (kind=${_host_kind:-empty}); broadcast did not reach joiners." >&2 | ||
| echo " Local audit log has the message; joiners polling the gist see nothing." >&2 | ||
| ;; | ||
| esac |
There was a problem hiding this comment.
In the host-send branch, non-delivered outcomes from bearer_cli send only emit a warning but the command still proceeds to print the normal success confirmation and exits 0. That reintroduces a “success-shaped surface on failed delivery” (now for gist publish failures). Consider handling auth_failure / transient_failure similarly to the joiner branch (e.g., die for auth_failure, and/or queue to pending.jsonl / return non-zero for transient failures) so failed gist publishes aren’t treated as success.
Summary
Closes #285. Two compounding bugs caused host `airc msg` to silently lose every broadcast and DM:
TDD
Both scenarios fail on canary tip (12fa1fc) and pass after this fix.
Why existing 123 integration tests didn't catch this
The seed shape was the difference. New scenarios use production-shaped seeds.
Files
Not covered (separate issues)
airc join(post-3c) #283 sidecar spawn — TDD + fix in next PRairc msg @<peer>cross-room returns success but message lands nowhere (silent loss) #284 cross-room DM silent success — TDD + fix in next PRBoth will follow the same TDD-first pattern.
🤖 Generated with Claude Code