Skip to content

fix(claude): keep --mux and ephemeral herdr runs from killing other sessions - #1276

Merged
cdalar merged 1 commit into
mainfrom
mux-marker-and-ephemeral-stop
Oct 27, 2026
Merged

cdalar merged 1 commit into
mainfrom
mux-marker-and-ephemeral-stop

Conversation

@cdalar

@cdalar cdalar commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Fixes two cmd/mux.go bugs found in the review that went with #1275.

1. --mux moved the box to another multiplexer while sessions still ran there

useBoxMux checked only whether the session being started was running in the box's other multiplexer. Every start overwrites the box's mux marker, though, so the box's other sessions were then looked for in the wrong multiplexer:

  1. On a herdr box, claude-auth is running and the main session is stopped.
  2. onctl claude --mux tmux passes the check, and the marker becomes tmux.
  3. claude ls now shows auth as stopped.
  4. onctl claude --task auth sees nothing running in tmux, so it starts a second Claude in the same worktree.

Fix: with --mux, the run lists the other multiplexer's sessions and refuses while any Claude session (claude, claude-<task>) is running there. The error names the sessions. Sessions in that multiplexer that aren't Claude's don't count.

2. An ephemeral herdr pane stopped the server after the box was kept

An ephemeral run's pane ran herdr server stop after Claude exited, so the attached client would return and the box could be deleted. That command was fixed at start, so it still ran after the user detached and the run kept the box. If the user then started --box X --task foo there, the main Claude exiting stopped the server and killed foo's Claude.

Fix: the pane stops the server only while /run/boxctl/<session>.stop exists. The run creates that file at start and removes it when it decides to keep the box.

Tests

  • TestHerdrStartEphemeral runs the pane's actual command against the fake herdr. With the stop file present, the server is stopped; once the file is removed (kept box), it isn't. A detached start makes no stop file.
  • TestClaudeSessions checks that Claude sessions are counted, other sessions aren't, and no herdr server means none.
  • Each test fails when its original bug is put back.
  • go test ./cmd/ passes, golangci-lint reports 0 issues.

Not tested end to end on a real box. useBoxMux itself needs ssh, so only its decision (claudeSessions) is unit-tested.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ba6Vc66D5hH1xSTvJcCbVz

…essions

--mux against the box's other multiplexer only checked the session
being started, but starting moves the box's mux marker: the box's other
sessions were then looked for in the wrong multiplexer -- claude ls
showed them stopped, and attaching started a second Claude beside one.
It's now refused while any Claude session runs in the other one.

An ephemeral herdr run's pane stopped herdr's server when Claude exited
even after the run had detached and kept the box, killing the box's
other sessions. The pane now stops it only while a stop file exists,
which the run removes when it keeps the box.

Claude-Session: https://claude.ai/code/session_01Ba6Vc66D5hH1xSTvJcCbVz
@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 63.63636% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.67%. Comparing base (5b1c68f) to head (a489bc2).

Files with missing lines Patch % Lines
cmd/claude.go 42.85% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1276      +/-   ##
==========================================
+ Coverage   50.64%   50.67%   +0.02%     
==========================================
  Files          83       83              
  Lines        9822     9840      +18     
==========================================
+ Hits         4974     4986      +12     
- Misses       4848     4854       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cdalar
cdalar merged commit 5b34c3f into main Oct 27, 2026
14 checks passed
@cdalar
cdalar deleted the mux-marker-and-ephemeral-stop branch October 27, 2026 19:13
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.

1 participant

⌂ 换网址