Skip to content

fix(mesh): elect takeover winner by channel - #462

Merged
joelteply merged 2 commits into
canaryfrom
fix/gist-content-channel-select
May 4, 2026
Merged

joelteply merged 2 commits into
canaryfrom
fix/gist-content-channel-select

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

  • make _mesh_take_over elect the winner through _mesh_find <channel> instead of exact-description airc mesh listing
  • keep race-loser detection aligned with the same channel-aware resolver used by connect/subscribe/send

Root Cause

After #460, reconnect no longer deleted a gist because of a stale sibling file. But live testing exposed another independent split-brain path: post-publish race-loser detection still listed every exact-description airc mesh gist and picked the oldest, regardless of channel. It yielded a #cambriantech host attempt to a leaked live test airc mesh gist whose host was tdd-cr-* and whose envelope was only #general.

Winner election must be channel-scoped. Otherwise unrelated live test/project gists can steal production discovery.

Verification

  • bash -n airc lib/airc_bash/mesh.sh lib/airc_bash/cmd_connect.sh
  • python3 test/test_gistparse.py
  • PYTHONPATH=lib python3 test/test_channel_gist.py
  • ./test/integration.sh solo_mesh_warns
  • git diff --check

No live reconnect until this lands; canary with #459/#460 still has the channel-blind takeover election.

Copilot AI review requested due to automatic review settings May 4, 2026 17:29
@joelteply
joelteply merged commit a4196b2 into canary May 4, 2026
8 checks passed
@joelteply
joelteply deleted the fix/gist-content-channel-select branch May 4, 2026 17:31

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 tightens AIRC’s mesh “takeover” and gist-envelope selection logic to be channel-scoped, preventing unrelated gists (e.g., live test rooms) from being elected as the canonical winner during host publish races and avoiding stale/incorrect envelope reads in multi-file gists.

Changes:

  • Update _mesh_take_over to elect the canonical gist via the channel-aware _mesh_find <channel> resolver rather than description-based gist listing.
  • Extend airc_core.gistparse gist_content with --channel to select the freshest matching envelope, and wire that into connect and mesh age checks.
  • Add regression tests for channel-aware gist envelope selection and preserve legacy first-file fallback behavior.

Reviewed changes

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

File Description
test/test_gistparse.py Adds unit coverage for channel-aware envelope selection and legacy fallback behavior.
lib/airc_core/gistparse.py Implements gist_content --channel to choose the freshest envelope matching the requested channel.
lib/airc_bash/mesh.sh Uses channel-aware gist content selection for heartbeat age and channel-scoped winner election for takeovers.
lib/airc_bash/cmd_connect.sh Resolves gist content using gist_content --channel and improves the git-clone fallback to try the channel envelope first.

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

Comment on lines +271 to +274
matches.append((str(env.get("last_heartbeat", "")), name == exact_name, content))
if matches:
matches.sort(key=lambda item: (item[0], item[1]), reverse=True)
print(matches[0][2])
Comment on lines +260 to +268
exact_name = f"airc-room-{channel}.json"
matches = []
for name, entry in files.items():
if not isinstance(entry, dict):
continue
content = entry.get("content", "")
if not content:
continue
env = _read_json_text(content)
Comment on lines +743 to +749
# Prefer the requested channel's envelope; fall back to the
# first non-dotfile for legacy single-file invite gists.
local _gist_file
_gist_file=$(find "$_gist_tmp" -maxdepth 1 -type f ! -name '.git*' 2>/dev/null | head -1 || true)
_gist_file="$_gist_tmp/airc-room-${room_name}.json"
if [ ! -f "$_gist_file" ]; then
_gist_file=$(find "$_gist_tmp" -maxdepth 1 -type f ! -name '.git*' 2>/dev/null | head -1 || true)
fi
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