Repository navigation
fix: cold-host split-brain via post-publish race-loser detection - #115
Merged
Merged
Conversation
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]>
There was a problem hiding this comment.
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.
| 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 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 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 |
This was referenced Apr 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two tabs running
airc join --room Xsimultaneously 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.