From fdf5e2c65f71f4e7d91c3660456f0ee490a79bcd Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 31 Oct 2026 05:00:25 +0800 Subject: [PATCH] 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. --- internal/cli/main.go | 4 ++++ internal/cli/signals.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/internal/cli/main.go b/internal/cli/main.go index e833befaf..752368fbd 100644 --- a/internal/cli/main.go +++ b/internal/cli/main.go @@ -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) diff --git a/internal/cli/signals.go b/internal/cli/signals.go index d27102608..2d8620319 100644 --- a/internal/cli/signals.go +++ b/internal/cli/signals.go @@ -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