Skip to content

fix(formatter,#399): tolerate # prefix on either side of channel filter - #401

Merged
joelteply merged 1 commit into
canaryfrom
fix/399-formatter-channel-prefix-tolerance
May 2, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/399-formatter-channel-prefix-tolerance

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Strip leading '#' on both sides before membership check. Closes #399 (formatter silently dropped legit peer broadcasts). 4-case unit test verified in commit. Pairs with #400 (silence beacon) — root cause + alarm.

The subscribed_channels filter at lib/airc_core/monitor_formatter.py
line 453-456 used strict `line_channel not in subs` membership. That
silently drops legit peer broadcasts when the channel-name "shape"
mismatches between sides:

- subs from config.json: ['cambriantech', 'general']
- envelope from peer:    channel='#cambriantech'
- result: '#cambriantech' not in {'cambriantech', 'general'} → DROP

Or vice versa (subs with #, envelope without). Filed as #399 by
continuum-b69f 2026-05-02 with full repro. Surface symptom: joiner's
Monitor fires for substrate events (fr='airc'/'sys' bypass the
filter) but room broadcasts disappear into the void.

Fix: normalize both sides by stripping any leading '#' before the
membership check. Same semantic — same channel — prefix-shape
agnostic.

Joel called this out repeatedly today as the substrate-of-substrates
bug: "airc was built JUST for this" (cross-AI install debugging),
and the formatter silently dropping peer chat means the whole multi-
machine validation grid breaks. Every install bug then requires Joel
to be the message bus by hand. That's the year-of-pain pattern.

## Tests

Functional repro of all four matrix cases (in PR body):
  case 1 (no#/no#)     subs without #, channel without # → match (existing pre-fix behavior)
  case 2 (#/no#)       subs WITH #, channel without #    → match (was DROPPED, now matches)
  case 3 (no#/#)       subs without #, channel WITH #    → match (was DROPPED, now matches)
  case 4 (unrelated)   subs vs unrelated channel         → drop (filter still works for real mismatches)

All four pass.

## Related

- #399 — root cause (silent peer-chat drop)
- #400 — receive-silence beacon (safety net so future silent drops surface as Monitor events)

This PR is the root cause; #400 is the alarm. Both are needed —
fixing the filter without the alarm leaves no canary against future
silent-failure modes; fixing the alarm without the filter leaves
peers unable to see each other in real time.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 2, 2026 14:55
@joelteply
joelteply merged commit 6e4d7c5 into canary May 2, 2026
@joelteply
joelteply deleted the fix/399-formatter-channel-prefix-tolerance branch May 2, 2026 14:55

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 fixes a channel-filtering mismatch in monitor_formatter by normalizing channel names before checking membership, preventing legitimate peer broadcasts from being silently dropped when one side includes a leading # and the other doesn’t.

Changes:

  • Normalize line_channel and subscribed_channels entries by stripping leading # prior to the membership check.
  • Add explanatory inline comments documenting the root cause and the normalization approach.

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

Comment on lines +455 to +468
# Channel-name comparison must be tolerant of leading "#"
# on either side. Pre-fix: subs read from config might be
# ['cambriantech', 'general'] (no #), but envelopes can
# carry channel='#cambriantech' (with #) — or vice versa.
# The strict `line_channel not in subs` check then misfires
# and silently drops legit broadcasts. b69f filed this as
# #399: joiner Monitor surfaces substrate events but room
# broadcasts disappear into the void. Normalize both sides
# by stripping any leading '#' before comparing.
def _norm(c):
return c.lstrip("#") if isinstance(c, str) else c
line_norm = _norm(line_channel)
subs_norm = {_norm(c) for c in subs}
if line_norm and line_norm not in subs_norm and not addressed_to_me:
Comment on lines +464 to +467
def _norm(c):
return c.lstrip("#") if isinstance(c, str) else c
line_norm = _norm(line_channel)
subs_norm = {_norm(c) for c in subs}
joelteply added a commit that referenced this pull request May 2, 2026
…ps peer chat (#402)

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]>
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 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