Skip to content

fix(whois): walk sibling sidecar scopes (closes #134) - #135

Merged
joelteply merged 1 commit into
canaryfrom
fix/whois-cross-scope
Apr 27, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/whois-cross-scope

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Bug

vhsm-d1f4 (paired in #useideem primary + #general sidecar) saw a JOIN event for continuum-b741 in #general. Then:

$ airc whois continuum-b741
whois: no record for 'continuum-b741' (try airc peers to list paired peers)

Issue #134.

Root cause

cmd_whois only consulted the primary scope's lookups. A peer who's only in a sidecar scope returned "no record" — even though airc peers (post-#124) already aggregates across scopes.

Fix

Walk sibling sidecar scopes using the same prefix-detection pattern cmd_peers uses. Per-scope lookup logic factored into _whois_in_scope (host name, local peer file, cross-peer-via-host SSH). Primary scope tried first, siblings second; first hit wins.

Cross-peer SSH uses the scope's ssh_key (not the primary's), so a sidecar joiner can authenticate to its sidecar host even when the primary scope is paired with a different host on different keys.

Test

scenario_whois_cross_scope (6 assertions):

  • sidecar local peer found from primary scope (the vhsm bug)
  • sidecar HOST resolved from primary scope
  • primary host still resolves (no regression)
  • unknown peer still 404s after walking all scopes
  • symmetric: sidecar→primary lookup works

Adjacent tests still green: whois (5/5), identity (19/19), kick (12/12).

Compatibility

No wire-format change. Single-scope users get the identical fast path (primary scope hit ends the walk). Empty sibling list = no-op.

Pre-fix: cmd_whois only consulted the primary scope's host /
local-peer-file / cross-peer-via-host SSH lookups. A peer in the
#general sidecar but not the primary project room returned "no
record" — even after airc peers (post-#124) already showed them
across rooms. JOIN events in the sidecar emitted names the IRC-style
mental model said should be reachable, but whois 404'd.

Post-fix: cmd_whois walks sibling scopes (.airc + .airc.<room>) using
the same prefix-detection pattern cmd_peers uses. Each scope tries
its own host / local-peer-file / cross-peer-via-host lookups; first
hit wins. Per-scope logic factored into _whois_in_scope so primary
and siblings share one code path.

The cross-peer-via-host SSH path uses the SCOPE's identity/ssh_key
(not the primary scope's), so a sidecar joiner can authenticate
to its sidecar host even when the primary scope is paired with a
different host on different keys.

Test (scenario_whois_cross_scope) covers:
  - sidecar local peer found from primary scope (the vhsm bug)
  - sidecar HOST resolved from primary scope
  - primary host still resolves (no regression)
  - unknown peer still 404s after exhausting all scopes
  - symmetric: sidecar→primary lookup also works

No wire-format change; backward compatible with single-scope users.
Copilot AI review requested due to automatic review settings April 27, 2026 15:02
@joelteply
joelteply merged commit 2f2e684 into canary Apr 27, 2026
3 checks passed
@joelteply
joelteply deleted the fix/whois-cross-scope branch April 27, 2026 15:03

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

Fixes airc whois in multi-scope setups by searching across sibling sidecar scopes (matching the cross-scope behavior already added to airc peers), closing issue #134.

Changes:

  • Refactors cmd_whois to delegate per-scope resolution to _whois_in_scope and then walk sibling scopes if not found in the current scope.
  • Ensures cross-peer SSH lookups use the scope-specific SSH identity (per-scope identity/ssh_key).
  • Adds an integration test scenario covering cross-scope whois resolution.

Reviewed changes

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

File Description
airc Updates cmd_whois to search across sibling scopes and factors lookup logic into _whois_in_scope.
test/integration.sh Adds scenario_whois_cross_scope and wires it into the test runner.

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

Comment thread airc
Comment on lines +3246 to +3249
# Strip a trailing .<word> to recover the primary prefix. Mirrors the
# detection in cmd_peers (#124) so .airc / .airc.general both resolve
# to .airc as the prefix; in tests we see state / state.general → state.
prefix=$(printf '%s' "$self_base" | sed -E 's/\.[a-z0-9-]+$//')

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

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

The prefix derivation sed -E 's/\.[a-z0-9-]+$//' will turn the primary scope basename .airc into an empty string (because it strips the entire .airc). That makes the sibling glob expand to $parent/ and $parent/.*, causing whois to scan essentially the whole parent directory and potentially return incorrect matches. Please mirror cmd_peers’ anchored prefix detection (airc:4203-4205), so .airc stays .airc while .airc.general becomes .airc.

Suggested change
# Strip a trailing .<word> to recover the primary prefix. Mirrors the
# detection in cmd_peers (#124) so .airc / .airc.general both resolve
# to .airc as the prefix; in tests we see state / state.general → state.
prefix=$(printf '%s' "$self_base" | sed -E 's/\.[a-z0-9-]+$//')
# Strip only a sidecar suffix to recover the primary prefix. Mirrors
# the anchored detection in cmd_peers (#124): .airc stays .airc,
# .airc.general becomes .airc, and state.general becomes state.
prefix="$self_base"
if [[ "$self_base" =~ ^(.+)\.[a-z0-9-]+$ ]]; then
prefix="${BASH_REMATCH[1]}"
fi

Copilot uses AI. Check for mistakes.
Comment thread airc
for sibling in "$parent/$prefix" "$parent/$prefix".*; do
[ -d "$sibling" ] || continue
[ "$sibling" = "$AIRC_WRITE_DIR" ] && continue
[ -f "$sibling/config.json" ] || continue

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

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

Sibling-scope discovery for whois currently accepts any $parent/$prefix.* directory that has config.json. cmd_peers additionally requires room_name + peers/ to avoid unrelated/stale dirs like .airc.bak polluting cross-scope behavior (airc:4207-4210). Consider applying the same gating here so whois doesn’t consult old/backup scopes and return stale identities.

Suggested change
[ -f "$sibling/config.json" ] || continue
[ -f "$sibling/config.json" ] || continue
[ -f "$sibling/room_name" ] || continue
[ -d "$sibling/peers" ] || continue

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