Skip to content

fix: cold-host split-brain via post-publish race-loser detection - #115

Merged
joelteply merged 1 commit into
canaryfrom
fix/cold-host-race-postpublish
Apr 26, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/cold-host-race-postpublish

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Two tabs running airc join --room X simultaneously both saw empty gh, both became host. Post-publish recheck + deterministic tiebreaker resolves it: loser deletes its gist + re-execs as joiner. Verified e2e on this Mac: simultaneous spawn → 1 gist final, multi-address pick joins via 127.0.0.1.

Two tabs running `airc join --room X` simultaneously both saw empty
gist list (gh propagation lag), both fell through to host mode, both
published — split-brain. Pre-publish recheck doesn't help because
neither tab's gist is globally visible at the moment of recheck.

Real fix: AFTER publishing, look for OTHER gists with the same room
name. Deterministic tiebreaker (lowest gist id alphabetically) picks
the winner. Loser stops its heartbeat, deletes its gist, clears
scope state, and re-execs as joiner targeting the winner's gist
(which goes through the existing multi-address pick → 127.0.0.1
for same-machine).

Verified: spawn two `airc join` processes simultaneously against a
shared room name → one wins host, the other yields cleanly + joins
via localhost. Exactly one gist on the gh account at the end.

Removed the previous pre-publish recheck I added in the prior commit
— it was redundant and didn't address the real race window. Comment
left at the discovery site pointing at the post-publish fix.

This is the same class of race PR #107 patched on the takeover paths
(stale gist takeover); now also patched on the cold-host path
(no gist exists yet → both create).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 26, 2026 16:12
@joelteply
joelteply merged commit 8e928b5 into canary Apr 26, 2026
@joelteply
joelteply deleted the fix/cold-host-race-postpublish branch April 26, 2026 16:12

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 addresses a “cold start” split-brain in room mode where two concurrent airc join --room X instances can both observe an empty gist list and both become host. It adds a post-publish recheck that detects a concurrent host and forces a deterministic winner, with the loser deleting its gist and re-execing as a joiner.

Changes:

  • Update room discovery commentary to clarify why pre-publish rechecks don’t prevent the race.
  • Add post-publish “race-loser detection” after creating the room gist, with jitter + gist-list scan + deterministic tiebreaker.
  • On race loss: stop heartbeat, delete the losing gist, clear local host state, and re-exec into joiner mode targeting the winning gist.

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

Comment thread airc
local _race_jit; _race_jit=$(awk -v r="$RANDOM" 'BEGIN{printf "%.3f", 0.5 + (r%1000)/1000}')
sleep "$_race_jit"
local _peer_rooms; _peer_rooms=$(gh gist list --limit 50 2>/dev/null \
| awk -F'\t' -v re="airc room: ${room_name}\$" '$2 ~ re {print $1}' \
Comment thread airc
Comment on lines +2703 to +2705
local _peer_rooms; _peer_rooms=$(gh gist list --limit 50 2>/dev/null \
| awk -F'\t' -v re="airc room: ${room_name}\$" '$2 ~ re {print $1}' \
| sort)
Comment thread airc
Comment on lines +2705 to +2709
| sort)
local _peer_count; _peer_count=$(printf '%s\n' "$_peer_rooms" | grep -c . || true)
if [ "$_peer_count" -gt 1 ]; then
local _winner_id; _winner_id=$(printf '%s\n' "$_peer_rooms" | head -1)
if [ "$_winner_id" != "$_gist_id" ]; then
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