Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): idle agent sessions free their memory after 2 minutes #41174

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/41174/headmerged by juliusmarminge View on GitHub

Showing 4 changed files with 68 additions and 26 deletions (loading 3).

x
0 of 4 viewed, 4 left
68 additions and 26 deletionsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsModified
View file
@@ -402,7 +402,7 @@
const CLAUDE_STDERR_TAIL_LENGTH = 2_048;
// The process group is killed on exit, so its stderr closes promptly.
const CLAUDE_STDERR_DRAIN_TIMEOUT = Duration.seconds(1);
-// How often the CLI's process tree is recorded when no agent scope will stop what it leaves.
+// How often a working CLI's process tree is recorded when no agent scope will stop what it leaves.
const CLAUDE_DESCENDANT_POLL = "1 second";
// Claude Code's refusal of bypassPermissions as root, which it explains only on stderr.
const CLAUDE_ROOT_REFUSAL =
@@ -556,8 +556,9 @@
​
/**
- * Process table reads for every running CLI. A poll reads the table once for all of them, so the
- * `ps` cost does not grow with open sessions.
+ * Process table reads for every working CLI. A poll reads the table once for all of them, so the
+ * `ps` cost does not grow with open sessions. Jobs start only while a CLI works, so an idle CLI is
+ * left out of polls; its turn ends with one last read.
export function makeClaudeDescendantPoll(
readProcessTable: Effect.Effect<ReadonlyArray<ClaudeProcessRow>>,
@@ -570,27 +571,44 @@
reading.withPermits(1)(readProcessTable.pipe(Effect.map(apply)));
return {
// A table read before a CLI started may list an older process under its pid, so a poll records
- // only into the CLIs tracked when its read began.
- poll: reading
- .withPermits(1)(