Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): open Claude sessions on macOS share one process-table poll #37585

Mergedjuliusmarmingemerged 2 commits intomain fromrefs/pull/37585/headmerged by juliusmarminge View on GitHub

Showing 2 changed files with 147 additions and 50 deletions.

x
0 of 2 viewed, 2 left
83 additions and 37 deletionsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsModified
View file
@@ -534,40 +534,75 @@
return found;
​
-/** What a CLI started, by pid and start time, recorded from each process table read while it runs. */
-export function makeClaudeDescendantTracker(
- cliPid: number,
+const processIdentity = (row: ClaudeProcessRow) => `${row.pid} ${row.started}`;
+​
+/** What one CLI started, by pid and start time, recorded from each process table read while it runs. */
+function makeClaudeDescendantTracker(cliPid: number) {
+ const tracked = new Map<string, ClaudeProcessRow>();
+ // After exit the CLI's pid may belong to an unrelated process, so only tracked jobs are roots.
+ const record = (rows: ReadonlyArray<ClaudeProcessRow>, cliRunning: boolean) => {
+ const running = new Set(rows.map(processIdentity));
+ // `ps -A` lists itself, so no rows is a failed read.
+ if (rows.length === 0) return running;
+ const roots = cliRunning ? [cliPid] : [];
+ for (const [key, row] of tracked) {
+ if (running.has(key)) roots.push(row.pid);
+ else tracked.delete(key);
+ }
+ for (const row of claudeDescendants(rows, roots)) tracked.set(processIdentity(row), row);
+ return running;
+ };
+ return { tracked: tracked as ReadonlyMap<string, ClaudeProcessRow>, record };
+}
+​
+/**
+ * Process table reads for every running CLI. A poll reads the table once for all of them, so the