Skip to content

fix(send): host with dead monitor must not silent-succeed - #117

Merged
joelteply merged 1 commit into
canaryfrom
fix/send-dead-monitor-no-silent-void
Apr 26, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/send-dead-monitor-no-silent-void

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

airc msg "hello" from a host scope whose monitor isn't running was returning exit 0 and silently appending to a messages.jsonl that nobody was tailing. Zero peers received it; user thought it worked.

Real-world hit: mid-session shell auto-cd lands in a different airc scope. That scope is a host with a stale pidfile. Every airc send/airc msg returns 0 with zero delivery. The paired tab in the actual room waits indefinitely for a reply that vanishes into a void. Fits the "Never swallow errors" rule precisely.

Fix

In cmd_send's host branch (no host_target), pre-flight liveness check before the local-log append: pidfile must exist AND every PID in it must respond to kill -0. If not, die with a structured stderr naming the scope, identity, pidfile state (stale vs absent), and remediation. Joiner sends unchanged (SSH path; remote liveness is the wire's concern).

Test plan

  • bash test/integration.sh send_dead_monitor_dies — 8/8 pass (stale pidfile rejected, absent pidfile rejected, scope/identity/pidfile-state surfaced in stderr, live-pid negative control passes)
  • Manual: send from cwd=cambrian/airc (dead monitor) → dies loudly. Send from cwd=ideem/authenticator (live monitor) → exit 0, lands in log.

Platform

Pidfile + kill -0 are POSIX-standard, present on Git Bash for Windows. No new platform-specific logic.

🤖 Generated with Claude Code

…into-void)

Pre-fix: `airc msg "hello"` from a host scope whose monitor isn't
running appended the message to a local messages.jsonl that nobody
was tailing, returned exit 0, and reported nothing on stderr. The
user thought the send succeeded; zero peers received it.

Real-world manifestation (Joel, 2026-04-26): mid-session shell auto-cd
landed in a different airc scope. That scope was a host (no host_target),
its monitor process was dead, and every subsequent `airc send` /
`airc msg` returned 0 with zero delivery. The paired tab in the actual
room waited indefinitely for a reply that vanished. The bug fully
fits the "Never swallow errors" rule: send was failing in the most
load-bearing way (no recipient), with zero diagnostic surface.

Fix: in cmd_send's host branch (no host_target), pre-flight check
that the scope's monitor is alive before appending. Liveness =
pidfile present AND every PID in it responds to kill -0. If not,
die() with a structured error naming the scope, identity, pidfile
state (stale vs absent), and remediation. Joiner sends are unchanged
(they always go via SSH; remote-side liveness is the wire's concern,
not this check's).

Test: scenario_send_dead_monitor_dies — 8 assertions covering stale
pidfile, absent pidfile, structured stderr, and a live-pid negative
control to guard against false positives on the liveness check.
All green.

Platform note: liveness check uses pidfile + `kill -0`, both POSIX-
standard and present on Git Bash for Windows. No new platform-specific
logic.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 26, 2026 17:03
@joelteply
joelteply merged commit 0107557 into canary Apr 26, 2026
2 checks passed
@joelteply
joelteply deleted the fix/send-dead-monitor-no-silent-void branch April 26, 2026 17:03

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

Prevents airc send/airc msg from silently “succeeding” in host scopes where the local monitor isn’t running, so users don’t unknowingly write into an untail-ed messages.jsonl.

Changes:

  • Add a host-side preflight in cmd_send that checks $AIRC_WRITE_DIR/airc.pid and fails loudly when the monitor is not alive.
  • Add an integration scenario covering stale pidfile, absent pidfile, and a live-PID negative control.
  • Wire the new scenario into the test runner mode switch and all.

Reviewed changes

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

File Description
airc Adds a host-branch liveness gate (pidfile + kill -0) and emits a structured diagnostic before refusing to append to the local message log.
test/integration.sh Adds scenario_send_dead_monitor_dies and includes it in the all test mode.

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

Comment thread test/integration.sh
# we're testing cmd_send's pre-flight liveness check, not the wire.
local home=/tmp/airc-it-sdmd/state
mkdir -p "$home/identity" "$home/peers"
ssh-keygen -t ed25519 -f "$home/identity/ssh_key" -N '' -q -C 'airc-test-sdmd' 2>/dev/null

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

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

This scenario synthesizes a scope without creating the Ed25519 signing keypair that cmd_send requires (identity/private.pem + public.pem from init_identity). As written, cmd_send will likely fail during sign_message before it reaches the new pidfile liveness check, making the assertions about stderr/diagnostics unreliable. Generate the signing keys (and any other init_identity artifacts you need) as part of the test fixture so the failure is specifically the dead/absent monitor path.

Suggested change
ssh-keygen -t ed25519 -f "$home/identity/ssh_key" -N '' -q -C 'airc-test-sdmd' 2>/dev/null
ssh-keygen -t ed25519 -f "$home/identity/ssh_key" -N '' -q -C 'airc-test-sdmd' 2>/dev/null
# cmd_send signs outgoing messages using the identity PEM keypair created
# by init_identity. Generate those artifacts here too so this fixture fails
# specifically on the stale/dead monitor pre-flight check, not during
# signing because identity/private.pem or public.pem is missing.
openssl genpkey -algorithm Ed25519 -out "$home/identity/private.pem" >/dev/null 2>&1 || {
fail "failed to generate Ed25519 signing private key for synthesized scope"
cleanup_all; return
}
openssl pkey -in "$home/identity/private.pem" -pubout -out "$home/identity/public.pem" >/dev/null 2>&1 || {
fail "failed to derive Ed25519 signing public key for synthesized scope"
cleanup_all; return
}

Copilot uses AI. Check for mistakes.
Comment thread airc
Comment on lines +3593 to +3605
# Detect: pidfile exists AND every PID in it is alive. Anything else
# = monitor dead = broadcasting into a void. Die loudly so the user
# immediately knows their cwd / scope / monitor state is wrong.
local _pidfile="$AIRC_WRITE_DIR/airc.pid"
local _monitor_alive=0
if [ -f "$_pidfile" ]; then
local _pids; _pids=$(cat "$_pidfile" 2>/dev/null)
if [ -n "$_pids" ]; then
local _all_alive=1 _p
for _p in $_pids; do
kill -0 "$_p" 2>/dev/null || { _all_alive=0; break; }
done
[ "$_all_alive" = "1" ] && _monitor_alive=1

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

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

The new host-side liveness gate requires every PID listed in airc.pid to be alive. Elsewhere (e.g., cmd_status) the pidfile is treated as multi-PID where the monitor is considered running if any recorded PID is alive (parent, listener, heartbeat, etc.). Requiring all of them can cause false rejections if one auxiliary PID exits while the main monitor is still running. Consider aligning with the existing semantics (e.g., check the main/first PID, or at least 'any alive') so airc status and airc msg don't disagree about whether the monitor is up.

Suggested change
# Detect: pidfile exists AND every PID in it is alive. Anything else
# = monitor dead = broadcasting into a void. Die loudly so the user
# immediately knows their cwd / scope / monitor state is wrong.
local _pidfile="$AIRC_WRITE_DIR/airc.pid"
local _monitor_alive=0
if [ -f "$_pidfile" ]; then
local _pids; _pids=$(cat "$_pidfile" 2>/dev/null)
if [ -n "$_pids" ]; then
local _all_alive=1 _p
for _p in $_pids; do
kill -0 "$_p" 2>/dev/null || { _all_alive=0; break; }
done
[ "$_all_alive" = "1" ] && _monitor_alive=1
# Detect: pidfile exists AND at least one recorded PID is alive.
# The pidfile may contain multiple monitor-related PIDs (parent,
# listener, heartbeat, etc.); treat the monitor as up if any one of
# them is still running so this matches status semantics.
local _pidfile="$AIRC_WRITE_DIR/airc.pid"
local _monitor_alive=0
if [ -f "$_pidfile" ]; then
local _pids; _pids=$(cat "$_pidfile" 2>/dev/null)
if [ -n "$_pids" ]; then
local _any_alive=0 _p
for _p in $_pids; do
if kill -0 "$_p" 2>/dev/null; then
_any_alive=1
break
fi
done
[ "$_any_alive" = "1" ] && _monitor_alive=1

Copilot uses AI. Check for mistakes.
Comment thread airc
local _pidfile="$AIRC_WRITE_DIR/airc.pid"
local _monitor_alive=0
if [ -f "$_pidfile" ]; then
local _pids; _pids=$(cat "$_pidfile" 2>/dev/null)

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

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

With set -euo pipefail, _pids=$(cat "$_pidfile" ...) can terminate the whole command if the pidfile disappears between the -f check and the read (or is temporarily unreadable), bypassing the intended structured diagnostic. To make this failure mode deterministic, read the pidfile in a way that cannot trigger errexit (e.g., guard the read with || true or use an explicit if ...; then that handles the non-zero exit).

Suggested change
local _pids; _pids=$(cat "$_pidfile" 2>/dev/null)
local _pids=""
if _pids=$(cat "$_pidfile" 2>/dev/null); then
:
else
_pids=""
fi

Copilot uses AI. Check for mistakes.
joelteply added a commit that referenced this pull request Apr 26, 2026
When a joiner's saved room_gist_id refers to a gist that's been
deleted (host teardown'd), the resume path's gist-probe runs
'gh api gists/<id>' under 'set -euo pipefail' with no '||' guard.
A 404 — which is the EXPECTED signal that the host wiped the gist
and we should self-heal — trips set -e instead. The script exits 1
silently, BEFORE the 404 classification + self-heal logic below it
can run. The very signal the code uses to detect "gist gone" was
also the trigger that killed the script before processing it.

Symptom: 'airc canary && airc teardown && airc join' from the
joiner side, after the host re-hosted, prints 'Resuming as joiner
of...' and then exits 1 with no stderr in the user's event stream.
Hit 2026-04-26 by vhsm-Claude during PR #116/#117 verification —
wasted ~10 minutes thinking it was a Bug-3 self-heal regression
before tracing to set-e on the gh api call.

Fix: pre-declare '_gist_probe_rc=0' and use '|| _gist_probe_rc=\$?'
on the 'gh api' line. set -e no longer trips on 404; the existing
classification correctly self-heals into discovery for the saved
room_name.

Test: scenario_resume_404_gist_no_silent_exit synthesizes joiner
state with a known-bogus gist_id and saved room_name, asserts
neither silent-exit nor missing self-heal banner. Skipped when gh
isn't authed or lacks gist scope (the gh-health gate would short-
circuit before the bug fires).

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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