cli: claude-tui-helper ends on a signal its own way, not of magpie's handler

magpie's process-wide handler (endProbesOnSignal) re-raises SIGTERM. In
claude-tui-helper it killed the helper (exit -15) before the shim's own
handler could stop its Claude Code and remove what it wrote, so a run the
gateway aborted left them behind. The helper's command now lets go of
those signals (leaveSignals) before claudetui.Run.

Run: go test ./internal/claudetui ./internal/cli on mote (macOS) and in
WSL magpie-desktop (-tags nogui), ok; go vet ./..., GOOS=linux go vet
-tags nogui ./..., GOOS=windows go vet ./..., go build on mote, ok.
Broken by hand: without leaveSignals, SIGTERM to a real helper in the
sandbox gateway exited -15 and left its temp folder; with it, exit 1 and
the folder removed (termimg.py).
Not tried: SIGHUP from a closed terminal.
This commit is contained in:
yetone
2026-10-31 05:00:39 +08:00
parent cac606be1a
commit fdf5e2c65f
2 changed files with 12 additions and 0 deletions
+4
View File
@@ -324,6 +324,10 @@ func run(args []string) error {
case "claude-mcp-helper": // internal: stdio MCP subprocess spawned by Claude Code
return claudebridge.RunMCP(args[1:])
case claudetui.Command: // internal: Claude Code's interactive mode for the bridge
// it ends its Claude Code and removes its files on SIGINT,
// SIGTERM and SIGHUP itself: magpie dying of the signal first
// left them behind
leaveSignals()
return claudetui.Run(args[1:])
case "statusline":
return statuslineCmd(args)
+8
View File
@@ -89,6 +89,14 @@ func ownSignals() {
}
}
// leaveSignals hands every signal endProbesOnSignal asked for back, for a
// command that starts no probe and ends on each its own way.
func leaveSignals() {
if onSignal != nil {
signal.Stop(onSignal)
}
}
// interrupts counts the commands ending themselves on Ctrl+C.
var interrupts atomic.Int32