Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): reap recorded Linux Claude survivors before recovery #22834

Mergedjuliusmarmingemerged 6 commits intomain fromrefs/pull/22834/headmerged by juliusmarminge View on GitHub

Showing 6 changed files with 106 additions and 22 deletions (loading 3).

x
0 of 6 viewed, 6 left
26 additions and 2 deletionsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsModified
View file
@@ -82,6 +82,7 @@
mcpAppToolResourceUri,
} from "@t3tools/shared/mcpApp";
import { AgentScope } from "@t3tools/shared/AgentScope";
+import * as ProviderProcesses from "../../process/providerProcesses.ts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import { applyClaudePromptEffortPrefix } from "@t3tools/shared/model";
import { compareSemverVersions } from "@t3tools/shared/semver";
@@ -372,7 +373,10 @@
const CLAUDE_ROOT_REFUSAL =
"--dangerously-skip-permissions cannot be used with root/sudo privileges for security reasons";
​
+// fd 4 gates the launch until the server has recorded the process it is about to become.
const CLAUDE_GROUP_WATCH_SCRIPT = [
+ "read -r _ <&4 || exit 1",
+ "exec 4<&-",
"{ trap '' TERM; read -r _ <&3; kill -TERM 0; sleep 5; kill -KILL 0; } </dev/null >/dev/null 2>&1 &",
'exec "$@" 3<&-',
].join("\n");
@@ -380,13 +384,15 @@
/**
* Kill the CLI's group on exit to stop MCP grandchildren; `onExit` stops its agent scope for
* setsid daemons. The CLI keeps working after its pipes close, so a watcher stops the group on
- * EOF from a pipe only this server holds, including when the server crashes.
+ * EOF from a pipe only this server holds, including when the server crashes. `register` records
+ * the CLI before it may run, so a restarted server can reap it if the watcher did not.
export function spawnClaudeProcessGroup(