Skip to content

fix(rename): chain-repair skips when host is ambiguous (closes #180) - #256

Merged
joelteply merged 1 commit into
canaryfrom
fix/chain-repair-phantom-when-host-ambiguous
Apr 28, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/chain-repair-phantom-when-host-ambiguous

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Same-machine peers share host field; chain-repair returning first-match corrupted an unrelated peer's record. Now returns None unless exactly one record matches the host.

continuum-b741 hit this on canary dee3b6c: round-trip rename leaves a
phantom peer record at sibling-host on same gh user.

## Root cause

\`_find_peer_by_host\` returned the FIRST match. Same-machine peers
share the \`host\` field (e.g. multiple Claudes on Joel's box all have
[email protected]). When chain-repair ran with that host and the
listdir returned bob first, alice's rename event renamed bob's file
to alice, corrupting bob's identity record.

## Fix

\`_find_peer_by_host\` collects ALL matches; returns the name only
when there's EXACTLY ONE. Zero or two-plus matches → return None →
chain-repair silently skips. No phantom. Cost: chain-repair is
slightly less aggressive in healing genuinely-broken chains across
multi-peer-on-one-host setups, but the alternative (corrupting an
unrelated peer's identity) is worse.

Verification: tabs 19/0; module syntax-checks.
Copilot AI review requested due to automatic review settings April 28, 2026 23:12
@joelteply
joelteply merged commit 8864e1a into canary Apr 28, 2026
@joelteply
joelteply deleted the fix/chain-repair-phantom-when-host-ambiguous branch April 28, 2026 23: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 adjusts rename “chain-repair” behavior in monitor_formatter to avoid corrupting unrelated peer records when multiple peer JSONs share the same host value (issue #180).

Changes:

  • Update _find_peer_by_host() to return a match only when exactly one peer record matches the given host.
  • Add explanatory docstring/comments describing the ambiguous-host failure mode and the skip behavior.

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

Comment on lines 157 to +161
d = json.load(open(os.path.join(peers_dir, entry)))
except Exception:
continue
if d.get("host") == host:
return d.get("name") or entry[:-5]
matches.append(d.get("name") or entry[:-5])

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside this directory scan you now potentially open many peer JSON files; using json.load(open(...)) leaves file descriptors to be GC-closed and can exhaust FDs on large peer dirs. Use a context manager (with open(...) as f: json.load(f)) so each file is closed promptly, especially now that you no longer return early on first match.

Copilot uses AI. Check for mistakes.
Comment on lines 160 to +164
if d.get("host") == host:
return d.get("name") or entry[:-5]
matches.append(d.get("name") or entry[:-5])
if len(matches) == 1:
return matches[0]
# 0 matches → no record to chain-repair against (probably the rename

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This collects all matches even though the only outcomes are 0, 1, or 2+ matches. Consider short-circuiting once you find a second match (return None immediately) to avoid unnecessary file I/O when the host is ambiguous.

Copilot uses AI. Check for mistakes.
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