Repository navigation
fix(part): IRC /part semantics — leave one room, keep sidecar - #125
Merged
Merged
Conversation
Pre-fix: 'airc part' from a primary scope (e.g. #useideem) called cmd_teardown which (post-#122) cleaned BOTH the primary scope AND the #general sidecar — so leaving #useideem also dropped the lobby unintentionally. IRC convention: /part leaves ONE channel; the lobby should persist. Caught while testing the multi-room model after #122 landed. Two related issues fixed: 1. cmd_teardown's pgrep-children walker would catch the sidecar bash (forked from primary) and kill it via the descendant tree even though the sidecar's PID isn't in primary's airc.pid (after #122 we stopped appending it). Added AIRC_TEARDOWN_PART_ONLY=1 guard: when set, cmd_teardown's exclusion list reads sidecar's airc.pid + descendants and removes them from the kill set. 2. cmd_part now sets local AIRC_TEARDOWN_PART_ONLY=1 before calling cmd_teardown. This also short-circuits the explicit sidecar-block in cmd_teardown (gist + pidfile cleanup for the .general scope), so part is fully scope-local. Also: removed the redundant 'echo $sidecar_pid >> primary/airc.pid' from spawn_general_sidecar_if_wanted. The sidecar already has its own scope's airc.pid, and cmd_teardown's explicit sidecar-block walks that pidfile directly. Appending was unnecessary AND was exactly what made cmd_part nuke the sidecar via the primary's pidfile walk in pre-#122 testing. Test: scenario_part_keeps_sidecar — 6 assertions: - primary + sidecar both running pre-part - airc part removes primary's airc.pid - sidecar's main bash PID still alive after primary's part (the load-bearing assertion — was the regression) - sidecar scope dir + pidfile preserved - sidecar room_name preserved - subsequent 'airc teardown' (no flag) DOES reap the sidecar (verifies full-kill semantic still works for the explicit case) Test bugfix included: read first PID from sidecar's airc.pid via awk '{print \$1; exit}' instead of head -1. host-mode airc.pid is '\$\$ PAIR_PID hb_pid' on one line, so head -1 returned the whole line and kill -0 failed on the multi-PID string. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adjusts airc part to follow IRC semantics by leaving only the current room’s scope running, while preserving the #general sidecar subscription introduced in #122.
Changes:
- Add
AIRC_TEARDOWN_PART_ONLY=1path socmd_teardownskips sidecar cleanup and excludes sidecar PIDs from the primary kill set when invoked viacmd_part. - Stop appending the sidecar PID into the primary scope’s
airc.pid(sidecar teardown is handled via the sidecar scope pidfile). - Add an integration scenario
part_keeps_sidecarvalidating sidecar survival afterpartand reaping on subsequentteardown.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
airc |
Implements part-only teardown semantics and removes sidecar PID coupling to the primary pidfile. |
test/integration.sh |
Adds a regression scenario ensuring /part does not kill the #general sidecar and that a later full teardown still cleans it up. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
852
to
+863
| ( env -u AIRC_PORT "${_env_args[@]}" "$0" connect --room general ) & | ||
| local _sidecar_pid=$! | ||
|
|
||
| # Append to primary's pidfile so cmd_teardown kills the sidecar | ||
| # process tree along with the primary's. (Sidecar's own scope has | ||
| # its own pidfile for sidecar's descendants — that gets cleaned by | ||
| # the next sidecar's auto-stale-pidfile recovery on reconnect.) | ||
| echo "$_sidecar_pid" >> "$_primary_scope/airc.pid" | ||
| # Sidecar's own scope writes its own airc.pid for its bash + descendants. | ||
| # cmd_teardown walks $AIRC_WRITE_DIR.general/airc.pid explicitly to kill | ||
| # the sidecar tree, so we DON'T append the sidecar bash PID to the | ||
| # primary's airc.pid. Earlier (PR #122) we did — but that broke | ||
| # cmd_part, which walks the same primary pidfile and ends up killing | ||
| # the sidecar too even though IRC semantics say `/part` should leave | ||
| # only the current channel and keep others (e.g. #general) alive. | ||
| # Pidfiles per scope; cmd_teardown is the only path that walks both. | ||
| : |
Comment on lines
4378
to
+4386
| # kill there. Without this, killing the primary leaves an orphan | ||
| # #general gist on the gh account AND an orphan sidecar process that | ||
| # the primary's pidfile descendant-walk wouldn't catch (sidecar's | ||
| # bash isn't a child of cmd_teardown — it was forked detached). | ||
| # | ||
| # Guard: AIRC_TEARDOWN_PART_ONLY=1 (set by cmd_part) skips the sidecar | ||
| # block. IRC `/part` should leave only the current channel; the | ||
| # sidecar (#general lobby) should keep running. cmd_teardown without | ||
| # this flag is the "kill everything in this scope tree" semantic. |
Comment on lines
+2576
to
+2580
| sleep 1 | ||
|
|
||
| ! kill -0 "$_sc_pid" 2>/dev/null \ | ||
| && pass "subsequent airc teardown DOES reap the sidecar (full kill semantic preserved)" \ | ||
| || fail "sidecar survived even airc teardown — over-skip bug" |
3 of 6 tasks
joelteply
added a commit
that referenced
this pull request
Apr 26, 2026
refactor(platform): extract proc/port/file/platform adapters; route all callsites through them Joel, 2026-04-26: 'we mess each other up if we dont abstract.' / 'fixing one [platform] can degrade the other.' Multiple AIs working on the same codebase across Mac/Linux/WSL/Windows-Git-Bash repeatedly retouched the same inline pgrep/lsof/stat patterns; each tweak risked diverging from the others. The fix is to consolidate all platform-specific shell calls behind named adapters so business logic stays platform-agnostic and porting work happens in one place per capability. ## New adapters (top of file, just before relay_ssh) - `proc_children <pid>` — direct children of PID, one per line. pgrep -P primary; ps -axo pid,ppid + awk fallback for envs without pgrep (Git Bash for Windows ships only msys coreutils). - `proc_parent <pid>` — PPID. ps -p X -o ppid= cross-platform. - `proc_cmdline <pid>` — full argv. ps -p X -o command=. - `proc_airc_pids_matching <regex>` — airc-related PIDs owned by current user, used by `airc teardown --all`. pgrep -u + -f primary; ps + awk fallback. - `port_listeners <port>` — PIDs listening on a TCP port. lsof primary (mac/most linux); ss fallback (modern linux); netstat -ano fallback (Windows native + minimal containers). Empty output = nobody listening. - `file_size <path>` — bytes. stat -f%z (BSD) → stat -c%s (GNU) → wc -c fallback (POSIX-portable). - `detect_platform` — emits macos/linux/wsl/windows-bash/unknown. WSL detection unified via /proc/version content match. Reserved for the rare case where a top-level decision genuinely depends on platform (e.g. Tailscale.app launching) — most callers should use the proc_/ port_/file_ adapters which handle differences internally. ## Callsites converted - 8 inline `pgrep -P <pid>` sites → `proc_children` - 2 inline `pgrep -u $(id -u) -f <pattern>` sites → `proc_airc_pids_matching` - 4 inline `lsof -tiTCP:<port> -sTCP:LISTEN` sites → `port_listeners` - 3 inline `ps -p <pid> -o ppid= | tr -d ' '` and `ps -p <pid> -o command=` sites → `proc_parent` / `proc_cmdline` - 1 inline `stat -f%z X || stat -c%s X || echo 0` site → `file_size` Inline `case "$(uname -s)"` blocks for tailscale-down guidance and machine_id lookup were NOT converted to `detect_platform`. Those blocks do platform-specific WORK (different commands per platform), not platform-specific abstraction of one shape — converting them would be larger surface-area for marginal cleanup. detect_platform stays available for future per-platform decisions. ## Tests - scenario_platform_adapters — 8 assertions exercising each adapter with a synthetic process tree + listener. proc_children sees a spawned sleep; proc_parent returns the harness PID; proc_cmdline contains 'sleep'; port_listeners finds a python listener on a random high port; file_size returns 11 for 'hello world' and 0 for missing files; detect_platform returns a valid value matching uname. - scenario_general_sidecar_default fixed — was reading primary's airc.pid for sidecar PID, stale since #125 separated sidecar pidfiles. Now reads ${home}.general/airc.pid via awk '{print $1; exit}' to extract first PID from the multi-PID host-mode line. ## Mac/Linux regression sweep Full suite (mode=all) ran post-refactor: - 194 assertions pass - 1 flake (rename propagation in scenario_tabs — passed on retry, pre- existing intermittent timing issue, not caused by this refactor) No new platform dependencies introduced. The adapters add fallback paths that activate on platforms the inline calls didn't support (e.g. Git Bash without pgrep), so this is strictly more portable than what was on canary before, while behavior on Mac/Linux is unchanged. ## Why now Joel asked to take this on while he prepares to rebuild the Windows side. With adapters in place, each Windows fallback bug becomes a one-helper edit with a contained blast radius. Without adapters, every Windows fix risks breaking the Mac/Linux paths it touches. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.
Summary
Follow-up to #122. Pre-fix: `airc part` from primary scope nuked the #general sidecar too (because cmd_teardown's pgrep-children walker reached the sidecar via the parent-child relationship). IRC convention is /part leaves ONE channel; the lobby should persist.
Fix
Test plan
Test bugfix included
read first PID from `airc.pid` via `awk '{print $1; exit}'` instead of `head -1` — host-mode pidfile has multiple space-separated PIDs on one line.
🤖 Generated with Claude Code