Repository navigation
Conversation
…ion (stablyai#7797) Live foreground detection walked the process tree downward from the pane's shell pid, but tmux double-forks its server and reparents it to pid 1, so the agent (claude/codex/...) is a child of the tmux SERVER, outside the walked subtree. The walk reached only the tmux client and reported tmux. The relay/SSH path had the same downward-only walk. Hop the fork: map the tmux client to its active pane pid via tmux list-clients, else fall back to the reparented tmux server pid from the ps table, then re-run recognition from there. Best-effort, POSIX-only. Wired into both the daemon (agent-foreground-process) and relay (pty-shell-utils) paths via a new shared helper; the relay path also stops trusting tmux as a foreground name so the pane is inspected. Adds regression tests covering the precise client-to-pane hop and the reparented-server fallback for both paths. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
📝 WalkthroughWalkthroughAdds shared tmux-aware foreground-agent resolution for double-forked and reparented process trees. Main and relay process detection now recognize tmux clients, query active pane PIDs, fall back to reparented tmux servers, and avoid trusting tmux commands directly. New regression tests simulate tmux availability, unavailable tmux, client-to-pane mapping, server reparenting, and direct server-root detection. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/shared/tmux-foreground-resolution.ts (1)
19-43: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate tree-walk/scoring logic vs
agent-foreground-process.ts.
collectDescendants/candidateScorehere re-implement the same generic descendant-walk and+/depth scoring already defined insrc/main/providers/agent-foreground-process.ts(lines 22-50, generic over{pid, ppid}). Consider having this shared resolver import/reuse that generic version instead of maintaining a second copy that can silently drift (e.g., if the scoring heuristic is tuned in one file but not the other).src/main/providers/tmux-agent-detection.test.ts (1)
64-68: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRestore
process.platformafter stubbing it. Both suites redefineprocess.platforminbeforeEachbut never restore the original value, so if Vitest reuses a worker process for other test files in the same run, thedarwinoverride can leak into unrelated suites that rely on the real platform.
src/main/providers/tmux-agent-detection.test.ts#L64-L68: capture the originalprocess.platformbefore overriding and restore it inafterEach.src/relay/tmux-agent-detection.test.ts#L55-L59: same fix for the relay suite.♻️ Proposed fix (apply to both files)
+ const originalPlatform = process.platform beforeEach(() => { execFileMock.mockReset() resetProcessTableSnapshotForTests() Object.defineProperty(process, 'platform', { value: 'darwin' }) }) + afterEach(() => { + Object.defineProperty(process, 'platform', { value: originalPlatform }) + })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4a525c78-5df2-426a-acd6-2c52dca16822
📒 Files selected for processing (5)
src/main/providers/agent-foreground-process.tssrc/main/providers/tmux-agent-detection.test.tssrc/relay/pty-shell-utils.tssrc/relay/tmux-agent-detection.test.tssrc/shared/tmux-foreground-resolution.ts
What
Agents (
claude,codex, …) started inside a user's tmux session are nevershown as running — the pane reads as
tmux. Fixes #7797 (both the daemon and therelay/SSH detection paths).
Root cause
Live foreground detection walks the process tree downward from the pane's
shell pid (
collectDescendants). tmux double-forks its server and reparents itto pid 1, so every pane process — including the agent — is a child of the tmux
server, not of the pane shell. The downward walk from the shell pid reaches only
the tmux client and falls back to reporting
tmux. The relay twin(
src/relay/pty-shell-utils.ts) has the same downward-only walk, so remotesessions are affected identically.
Fix
When the downward walk finds a tmux client but no agent, hop the fork and
re-run recognition from the client's pane:
tmux list-clients -F '#{client_pid} #{pane_pid}', then re-walk from there.PATH, no server),walk from the reparented tmux server pid(s) visible in the ps table.
Best-effort and POSIX-only; every failure mode returns
nullso callers keeptheir existing fallback. Logic lives in a new
src/shared/tmux-foreground-resolution.tsand is wired into both detection paths.The relay path additionally stops treating
tmuxas a trusted foreground name sothe pane is actually inspected.
Tests
New regression tests model the exact tmux topology (shell → tmux client; tmux
server reparented to pid 1 →
claude) and cover both the precise client→pane hopand the reparented-server fallback, for both the daemon
(
src/main/providers/tmux-agent-detection.test.ts) and relay(
src/relay/tmux-agent-detection.test.ts) paths.vitest run(touched suites): 5/5 passtsc --noEmit -p config/tsconfig.node.json: cleanoxlint/oxfmt: cleanSupersedes the repro artifact from
nwparker/bug-repro-pass2.🤖 Generated with Claude Code
ELI5
Agents started inside your own tmux session never showed as running—the pane just looked like tmux. Detection now finds agents reparented under the tmux server so they appear correctly in the sidebar.