Skip to content

fix: channel_gist convergence — oldest gist wins on duplicates - #321

Merged
joelteply merged 1 commit into
canaryfrom
fix-channel-gist-convergence-oldest
Apr 29, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix-channel-gist-convergence-oldest

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Real production bug Joel pinpointed: 'I can manually message them' — peers were on DIFFERENT #general gists (multiple dups on the gh account). Sends looked successful, peers heard nothing. find_existing returned whichever appeared first in gh's list-response (recency-ordered, non-deterministic). Now returns OLDEST by created_at, same rule _mesh_find uses. Test coverage: 5 cases. Critical for substrate convergence.

Symptom: 'I can manually message them' / 'they ain't gonna notice
they are all broken' (Joel 2026-04-29). Confirmed: my account had
TWO #general gists (9740e0e1... and d469970...). My broadcasts went
to one; peers were polling the other. Sends looked successful, peers
heard nothing.

Root cause: channel_gist.find_existing returned whichever matching
gist appeared first in gh's list-response. gh list-response is
recency-ordered, so the 'first match' could differ across peers and
across calls. Two peers polling at slightly different times could
pick DIFFERENT duplicates of the same channel → substrate split.

Fix: convergence rule. When N gists describe the same channel,
return the OLDEST by created_at. Deterministic across every peer
regardless of when they polled. Same rule mesh.sh:_mesh_find already
uses for the legacy 'airc mesh' singleton; bringing channel_gist
into line.

#290 contract preserved: canonical single-channel gists still take
priority over legacy multi-channel mesh gists. The oldest tiebreak
applies WITHIN each pass.

TDD: test_channel_gist.py (5 cases) — two-dup, three-dup, canonical-
beats-older-legacy, none-match, all-legacy-still-oldest.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@joelteply
joelteply merged commit a33aaf8 into canary Apr 29, 2026
@joelteply
joelteply deleted the fix-channel-gist-convergence-oldest branch April 29, 2026 16:00
joelteply added a commit that referenced this pull request Apr 29, 2026
canary → main: channel_gist convergence (#321) — oldest gist wins
joelteply added a commit that referenced this pull request Apr 29, 2026
…ial) (#323)

Two new TDD scenarios in test/integration_smoke.sh against real gh:

  scenario_status_agrees_with_send: catches the diagnostic-disagreement
  bug Joel hit live today — 'airc msg' lands in the gist but 'airc
  status' reports monitor: not running. If sends work, status MUST
  say running. (Helps catch the airc.pid incompleteness — pidfile
  only tracks parent, not the bearer_cli + formatter children.)

  scenario_stale_config_auto_resyncs: pre-seeds channel_gists with a
  bogus gist id (simulates a peer who paired with a non-canonical
  dup pre-#321), bounces, asserts the bogus is replaced with the
  canonical gist on next connect. CURRENTLY FAILING — host bootstrap
  path creates a 3rd duplicate instead of consulting find_existing.

Partial fix in cmd_connect.sh: added find-first logic before the
host bootstrap's gh gist create — adopts existing canonical if
found. The fix is structurally right but the test still fails
because (a) the discovery path on --as-host bypasses my find-first
gate and (b) the host bootstrap subscribe/set_channel_gist sequence
needs to be unified with ensure_channel_subscribed_with_gist's
helper to get auto-resync coverage.

Filing scenario_stale_config_auto_resyncs as a known-failing
regression guard. Shipping the test as red so the next iteration
makes it green. The convergence-on-clean-state path (#321) works
in production today — Joel's 4 peers all converged on
d469970250fce78d9413eb9639dcb052 — but stale-config recovery for
existing peers requires either manual channel_gists clear OR a
follow-up to thread the helper through the host-bootstrap path.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request Apr 29, 2026
fix: resolve retry + host bootstrap find-first (auto-resync infrastructure)

Two complementary changes for substrate convergence:

1. channel_gist.resolve() retries find_existing 3× with backoff
   (1.5s, 3s) to bridge gh's gist-listing eventual-consistency window.
   A peer reconnecting moments after another peer hosted previously
   missed the canonical because gh's listing hadn't propagated yet,
   resulting in a 3rd duplicate gist. Retry with backoff catches
   the propagation. AIRC_RESOLVE_NO_RETRY=1 opts out for callers
   that don't want to wait.

2. cmd_connect host bootstrap calls channel_gist.resolve before
   creating a new gist (#321 follow-up). Previously the host path
   bypassed find_existing and unconditionally created a new gist;
   if a canonical already existed on the gh account from a prior
   session, the host created a duplicate. Now adopts existing
   canonical when found.

Test scenario stale_config_auto_resyncs (introduced PR #323)
documents the regression class — pre-seeded bogus channel_gists
must be replaced on bounce. Currently red because of an orthogonal
bug (orphan subshells survive teardown and re-write airc.pid,
blocking the next spawn via #292 stomp guard) that needs its own
fix. The auto-resync mechanism is correct; the test harness needs
better orphan cleanup.

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.

1 participant