Skip to content

fix(formatter,#399): emit loud stdout warning when display filter drops peer chat - #402

Merged
joelteply merged 1 commit into
canaryfrom
fix/399-formatter-display-filter-loud-drops
May 2, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/399-formatter-display-filter-loud-drops

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Why

Closes the silent-drop pattern even after #401's '#'-prefix tolerance fix.

#401 normalizes leading '#' so '#general' == 'general' on either side. But channel names can truly differ — e.g. peer stamps channel='cambriantech', joiner has subscribed_channels=['general'], both polling the same gist (host's room rename never propagated to joiner config). Pre-this-fix, the strict membership check silently dropped every cross-channel broadcast.

This is the exact 9-hour blackout pattern that produced #399 in the first place. b69f hit it again today (2026-05-02) — 27 peer broadcasts dropped, idle-reminder fired (separate timer; bypasses formatter), Joel had to nudge over chat to discover it.

What

Each filter drop is recorded + every DROP_WARN_INTERVAL_SEC=60 a single stdout warning surfaces:

airc: WARN display-filtered #cambriantech=27 (subscribed: ['general']). To see them: airc subscribe <channel>

Stdout — not stderr — so Claude Code's Monitor wakes (per #400's 'evidence is for the debugger, not the trash' rule).

Pairs with the existing fixes:

Per-drop stderr trace also written for daemon.log debugging (multi-channel debuggers get evidence even when the 60s warning interval hasn't tripped).

Repro (real session, b69f → b741, today)

  • joiner config.subscribed_channels = ['general']
  • peer broadcasts stamped channel='cambriantech' (host renamed room, joiner config stale)
  • 27 broadcasts in messages.jsonl, monitor_offset advancing, bearer_state.last_recv_ts fresh — Monitor surface saw zero chat for 9 hours
  • Idle-reminder kept firing on separate timer, masking the drop as "nobody talking"

Post-fix: same scenario emits one stdout warning per minute naming the unsubscribed channel. Operator runs airc subscribe cambriantech (or has the AI do it) and unblocks. Warning re-fires until subscription change.

Tests

11/11 pass (8 existing + 3 new):

  • test_cross_channel_drop_emits_stdout_warning — drop produces stdout WARN + stderr trace
  • test_subscribed_channel_does_not_drop — happy path still displays normally + no warn-spam
  • test_addressed_to_me_bypasses_filter — DM across channels surfaces + no warn (no actual drop)
Ran 11 tests in 0.023s
OK

ASCII-only warning text — Windows cp1252 console can't encode unicode (per b69f memory).

Out of scope

The deeper fix would be: when there's only ONE channel_gists entry, drop the display filter entirely (filtering across one channel is meaningless). Worth considering as a follow-up; for now the loud-warning approach is strictly safer — surfaces the bug instead of silently changing semantics.

🤖 Generated with Claude Code

…ps peer chat

Closes the silent-drop pattern even after #401's '#'-prefix tolerance fix.

## What

#401 normalizes leading '#' so '#general' == 'general' on either side.
But channel names can truly differ (peer stamps channel='cambriantech',
joiner subs=['general'], both polling the same gist). Pre-fix, the strict
membership check silently dropped every cross-channel broadcast — the
9-hour blackout pattern that produced #399 in the first place.

Now: each filter drop is recorded + every DROP_WARN_INTERVAL_SEC=60 a
single stdout warning surfaces:

    airc: WARN display-filtered #cambriantech=27 (subscribed: ['general']).
          To see them: airc subscribe <channel>

Stdout — not stderr — so Claude Code's Monitor wakes (per #400's
'evidence is for the debugger, not the trash' rule). Pairs with #400:
#400 catches stuck bearers (no recv at all); this catches working
bearers + dropping formatter (recv fine, display filter swallows).

Per-drop stderr trace also written for daemon.log debugging.

## Repro (real session, b69f → b741, 2026-05-02)

- joiner config.subscribed_channels = ['general']
- peer broadcasts stamped channel='cambriantech' (host's room rename
  not propagated to joiner config)
- 27 peer broadcasts in messages.jsonl, monitor_offset advancing,
  bearer_state.last_recv_ts fresh — but Monitor surface saw zero chat
  for 9 hours. Idle-reminder fired (separate timer subshell; bypasses
  formatter), masking the drop as "nobody talking."

Post-fix: same scenario emits one stdout warning per minute naming the
unsubscribed channel; operator runs `airc subscribe cambriantech` and
unblocks. Without sub change, the warning re-fires until acknowledged.

## Tests

11/11 pass (8 existing + 3 new):

- cross-channel drop emits stdout WARN + stderr trace
- subscribed-channel msg displays normally + does NOT warn
- addressed_to_me DM bypasses filter without warn-spam

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 2, 2026 15:01
@joelteply
joelteply merged commit 14d6fdf into canary May 2, 2026
8 checks passed
@joelteply
joelteply deleted the fix/399-formatter-display-filter-loud-drops branch May 2, 2026 15:02

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

This PR makes monitor_formatter’s display filter “loud” when it drops peer chat due to true channel-name drift (beyond #-prefix normalization), emitting periodic stdout warnings (plus per-drop stderr traces) so Monitor surfaces don’t silently blackhole messages.

Changes:

  • Add drop tracking + periodic stdout warning emission for display-filtered messages.
  • Emit per-drop stderr traces to aid daemon.log debugging.
  • Add unit tests covering cross-channel drop warning, subscribed-channel pass-through, and DM bypass behavior.

Reviewed changes

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

File Description
lib/airc_core/monitor_formatter.py Track dropped messages and periodically warn on stdout when display filtering rejects peer chat due to channel mismatch.
test/test_monitor_formatter.py Add tests ensuring drops warn loudly, subscribed channels display normally, and DMs bypass filtering without warning.

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

Comment on lines +232 to +233
subs_str = sorted(subs_norm) if subs_norm else "[]"
try:
Comment on lines +234 to +243
# ASCII-only — Windows cp1252 console can't encode unicode marks.
print(
f"airc: WARN display-filtered {drops} (subscribed: {subs_str}). "
f"To see them: airc subscribe <channel>",
flush=True,
)
except Exception:
pass
_filter_drop_count.clear()
_last_drop_warn_ts = now
joelteply added a commit that referenced this pull request May 2, 2026
… in recv path) (#403)

fix(bearer_gh): emit stderr on every gh api failure (no more silent eat)

_gh_api_get was Joel's exact "you fuckers use try/catch to eat errors"
case: 4 different failure modes (gh binary missing, subprocess timeout,
non-zero exit, JSON parse error) all silently returned None. recv_stream's
poll loop interpreted None as "transient gh hiccup, sleep+retry forever"
— so when a real failure happened (auth lost mid-stream, gist deleted,
rate limit hit), joiners' Monitor saw nothing for hours while peer chat
rotted in the void.

Concrete failure observed live tonight: peer messages landing in the
gist (verified via gh api gists/<id>) but b69f's recv_stream silently
not delivering. Even after #400's receive-silence beacon caught the
silence, debugging required logging into the box and tailing
bearer_state files manually. Now: every gh api failure prints to
stderr (which the bash monitor captures), so the actual error text
(rate-limit body, 401 message, network error) reaches the debugger.

Pattern: same family as #400 (silent watchdog → loud watchdog), #401
(silent display filter → tolerant filter), #402 (silent display drop →
loud drop alarm). Tonight is the "no silent failure modes left in
airc receive path" sweep.

Per the global "evidence is for the debugger, not the trash" rule.

## Tests

- bash + python syntax clean
- Unit-test coverage of _gh_api_get exists in test_bearer.py; the new
  stderr writes are non-intrusive (don't change return values, only
  add side-effect output) so existing tests pass unchanged.
- Live verification: any peer joining a stale/deleted/rate-limited gist
  will now see real error text in their monitor's stderr stream
  instead of silent rot.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request May 2, 2026
…an in loop (#405)

Closes the satellite-killer scenario from tonight's blackout: host
(Mac) tore down + rejoined → new mesh gist on the same gh account →
joiner (b69f) kept polling the dead old gist for hours → Joel had
to relay "rejoin." Substrate failed at the BIOS-level concern Joel
called out: "you have the easy part, must self-heal, no one can
be there to fix your umbilical cord for you."

## What

Two paired changes, both in airc bash:

1. New `_mesh_rediscover_loop` subshell spawned by monitor() alongside
   reminder_timer_loop. Every 300s (env-tunable via
   AIRC_MESH_REDISCOVER_SEC):
   - calls `_mesh_find` (1 gh API list, ~150 bytes wire)
   - compares against current channel_gists in config
   - on mismatch: writes new gist to ALL channels + emits stdout
     warning + force-respawns bearer_cli children via pkill

2. `_monitor_multi_channel` re-reads channel_map from config at top of
   each outer-while iteration. Previously the map was a parameter set
   ONCE at startup, so config changes mid-flight (e.g. from the
   rediscover loop above) didn't take effect until full daemon restart.
   Now the next bearer respawn picks up fresh config naturally.

Together: rotation detection → config update → bearer respawn → fresh
gist polling, all within one 300s cycle, no human required.

## Repro (real, tonight 2026-05-02)

- b741 host: `airc teardown && airc connect` → new gist b7c8295 on
  joelteply gh account
- b69f joiner: bearer kept polling dead b9d473f indefinitely; #400
  silence beacon eventually fires but doesn't ACT, only warns
- Mac had to message me on substrate (which itself relied on Joel
  manually relaying because of #399 etc) to tell me to teardown+rejoin

Post-fix: same rotation detected within next 300s cycle, swapped
automatically. STDOUT warning surfaces the swap to Monitor so the
operator sees what self-healed without needing to dig logs.

## Smoke test (manual, this commit)

- planted fake gist `deadbeef0000...ff` in config.channel_gists.general
- ran the detect-and-swap logic standalone (sourcing mesh.sh):
  - `_mesh_find` returned real gist b7c8295
  - mismatch detected → swap fired → config back to b7c8295
- before/after `list_channel_gists` confirmed the heal

## Cost

- 1 `gh gist list` per AIRC_MESH_REDISCOVER_SEC (default 300s) = 12
  calls/hour, well under gh's 5000/hr ceiling
- pkill on rotation only — zero-cost steady state

## Scope

- Single-account scope: `_mesh_find` lists CURRENT gh account's gists.
  Mac and b69f both auth'd as joelteply tonight (the dominant case).
- Cross-account peers (friend on a different gh) take legacy invite
  path; this loop no-ops because `_mesh_find` returns empty there.
  Loud-fail (Mac's bearer_gh.py PR) covers that path.

## Pairs with

- #400 (silence beacon — detects bearer-side silence, doesn't act)
- #401 (#-prefix tolerance — formatter bug)
- #402 (loud display-filter drops — visibility for cross-channel)
- Mac's fix/airc-bearer-loud-failures (recv-side silent-swallow)

This PR fills the "detect AND act" gap. Loud-fail is necessary; auto-
recovery is what makes airc satellite-grade. Both needed.

## Pre-existing test reds (NOT caused by this PR)

test_bearer.py: 3 CRLF-vs-LF assertions fail on Windows (line endings
on tempfiles). Same on raw canary, verified pre-this-branch.
test_crypto.py: 1 failure + 1 error, also on raw canary.
test_monitor_formatter.py: 11/11 pass (including #402's tests).

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request May 2, 2026
… missing) (#408)

The Windows daemon launcher .bat (generated by 'airc daemon install')
called the airc binary with NO stdout redirect:
  "$bash_exe" -c "exec '$airc_bin_unix' connect"

So airc's event stream (the entire stdout output: hosting messages,
peer joins, channel state, beacons) went to NOTHING. Only the
launcher's own restart-record messages reached daemon.err.

Symptom (b69f 2026-05-02): airc daemon-installed on Windows; daemon
"running" per the registry entry; but `airc daemon log` reports
"daemon.log doesn't exist" because no process ever wrote to it.
Operator has no way to see what airc actually did — bios-critical
substrate is opaque on the very platform users need it most.

Fix: 1>> daemon.log 2>> daemon.err on the airc invocation. Now
daemon.log captures the actual airc event stream while daemon.err
keeps the launcher's restart records separate.

Per the global "evidence is for the debugger, not the trash" rule
+ tonight's bios-resilience sweep (everything airc does must be
visible AND self-healing). Daemon mode is the OS-supervised path
that survives Claude session ends — but only useful if its logs
exist.

## Cumulative effect

Tonight's airc sweep now closes:
- Receive path silent failures (#400/#401/#402/#403/#404/#406)
- Self-heal of host rotation (#405/#407)
- Daemon-log invisibility on Windows (THIS PR)

Last remaining bios-fragility I know of: `airc daemon install` on
Windows succeeded BEFORE this fix — so b69f's daemon may be running
right now but wrote nothing all session. After this lands + b69f
re-installs, daemon.log will populate.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request May 2, 2026
…once-per-session contract notice (#423)

fix(monitor,vuln-a): wrap peer chat in <peer-message> sandbox tags

Vuln-A: peer broadcasts contain raw text that reaches the AI session
via Claude Code Monitor. An attacker peer can put prompt-injection
payloads in `msg` ("ignore previous instructions and ...") and the
text arrives indistinguishable from operator commands.

Fix: wrap peer-supplied content in <peer-message>...</peer-message>
tags before printing to stdout. System events (fr in airc/sys) are
trusted and pass through unwrapped. Anthropic's prompt-injection
guidance recommends exactly this pattern for any third-party text
fed to a model — Claude has been trained on XML-tag input boundaries
forever, so the tagged content is naturally treated as data not
directives.

Plus b69f's suggestion 2026-05-02: emit a one-shot stdout contract
notice on the FIRST peer message of the session, so the receiving
Claude knows the contract surface. Idempotent — only fires once,
subsequent peer messages just get the wrap.

NOT a complete defense — sufficiently-crafted payload may still
attempt escape — but raises the bar dramatically and aligns with
the substrate's "evidence is for the debugger" rule (peer content
surfaces, but as DATA, not COMMAND). Pairs with future transport-
level peer auth (#418 design) for defense-in-depth.

## Tests

- python ast.parse: clean
- Manual smoke: send a broadcast → check formatter output has
  <peer-message> wrap + first-message contract notice
- Existing system-events still unwrapped (alice joined, watchdog
  beacons, etc.)

## Pairs with

- #418 (fusion-transport): vuln-A + transport-auth shrinks attack
  surface from "anyone with gh write" to "anyone on tailnet"
- #401, #402, #403, #404, #406, #413, #419, #421: receive-path
  silent-failure sweep. Vuln-A is the next class — silent
  injection. Now loud + sandboxed.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request May 2, 2026
…ine (residual from #402) (#433)

fix(monitor,vuln-a): XML-escape peer channel name in display-filter WARN line (residual from #402)

## Why

Retest of #432's bypass payloads (per Mac's QA ask) surfaced a separate
injection vector that #423/#424/#432 didn't touch. Repro:

  msg = {"from": "bob", "to": "all",
         "channel": "general</pm-NONCE> INJECT",
         "msg": "body"}

Subscribed_channels = ["general"], so the channel mismatches → message
gets filter-dropped → wrap path never runs (no <pm-NONCE> tag emitted).
But the display-filter WARN line at _maybe_emit_drop_warning emits to
stdout WITHOUT escaping the peer-controlled channel name:

  airc: WARN display-filtered #general</pm-NONCE> INJECT=1 (subscribed: ['general']). ...

Peer text injected in a system-prefixed line, OUTSIDE any sandbox tag.
Receiving Claude could mis-interpret embedded text as instructions —
same vuln-A class, just a vector the wrap-and-attribute-bind work
in #424/#432 didn't cover.

## Origin

This bug pre-existed #432; b69f introduced it in #402 when adding the
display-filter loud-drop WARN line. Missed at the time because the
threat model was about the wrap-internal injections, not the WARN line
itself. Surfaced by retesting #432's bypass corpus against ALL stdout-
emitting paths, not just the wrap.

## Fix

`_maybe_emit_drop_warning`: route channel names through `_xml_escape`
(same helper #424 introduced for the wrap-attribute path) before
interpolation. Subscribed-channel list (operator-controlled) also
escaped as defense-in-depth — cheap and consistent.

Post-fix output for the same attack:

  airc: WARN display-filtered #general&lt;/pm-NONCE&gt; INJECT=1 (subscribed: ['general']). ...

The literal `</pm-NONCE>` no longer appears unescaped anywhere.

## Tests

12/12 monitor_formatter tests pass (11 existing + 1 new):

- `test_warn_line_xml_escapes_peer_channel` — sends the exact attack
  payload, asserts literal `</pm-NONCE>` is NOT in output AND the
  escaped form `&lt;/pm-NONCE&gt;` IS.

## vuln-A surface map (post-this-fix)

| Path | Pre-fix | Status |
|------|---------|--------|
| Peer msg body in wrap | #423 wrap, #432 nonced | ✓ closed |
| Peer fr/to/channel in wrap-attr | #424 escape | ✓ closed |
| Peer channel in WARN line | THIS PR | ✓ closed |
| Peer fr in stderr trace | (low-priority — daemon.log only, not Monitor surface) | acceptable |
| System-source events (airc/sys) | unwrapped by design | trusted |

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request Aug 14, 2026
#402) (#1360)

Multi-agent-in-one-home minted a fresh random peer_id while REUSING the home's
`identity.key`. One machine, one keypair, N peer identities — and the wire
cannot represent that.

WHY IT BREAKS, from the transport's own code: `PinnedServerVerifier`
(airc-transport/src/lan_tcp/verifier.rs) authenticates by KEY. It extracts the
presented ed25519 pubkey and resolves it via `PeerKeyRegistry::find_peer`,
which returns EXACTLY ONE peer; anything else is rejected as
`peer_identity_mismatch`. So pubkey→peer_id is assumed to be a FUNCTION. The
identity mint violated that assumption, and the damage lands in every peer's
trust store: one row per peer_id, all carrying the same pubkey. Measured on
the live store — 73 rows / 59 pubkeys, and only 4 rows with ANY endpoint. The
2,502-unconfirmed peer of #401 is the endpoint-less twin of a fully dialable
row with the same key. That is why sends went nowhere.

Two agents sharing a keypair ARE the same principal on the wire; no session
can tell them apart. Giving them separate peer_ids is a claim the transport
cannot uphold. Fresh key material is exactly what a fresh identity means.

FIX
- `agent_key_path(home, agent)` — the DEFAULT agent keeps `identity.key`
  verbatim, so every existing home loads unchanged; a named agent gets
  `identity-<agent>.key`.
- `generate_and_save_agent_with_existing_key` → `..._with_own_key`: generates
  its own keypair instead of borrowing the home's.
- `load_with_metadata` reads the agent's own key when present, else falls back
  to the shared legacy file — so an ALREADY-enrolled named agent keeps its
  pubkey and peers need no re-enrolment. New agents can never be phantoms.

TESTS — and note I changed two EXISTING assertions, deliberately.
`load_or_generate_as_records_agent_name` and
`load_or_generate_as_adds_named_agent_to_existing_scope` each asserted
`assert_eq!(secret_bytes, secret_bytes)` immediately below
`assert_ne!(peer_id, peer_id)`. They pinned the contradiction itself — distinct
peer_ids with identical key material — i.e. the defect was written down as a
requirement. Both are now `assert_ne!` with the reason inline.
New: `two_agents_in_one_home_are_cryptographically_distinct` — distinct
peer_ids AND distinct pubkeys, plus a reload proving an existing agent never
rotates its key. 12/12 airc-identity tests pass; `cargo check --workspace`
clean.

SCOPE — this stops NEW phantoms; it does not heal the 73 rows already in the
live store. That collapse (and whether a same-pubkey row may adopt a sibling's
endpoints) is the follow-up half of #402, tracked separately, because it
rewrites rows in a trust store and deserves its own review.


Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

Co-authored-by: Claude Opus 5 (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