Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/35711/headopened View on GitHub

Showing 4 changed files with 124 additions and 13 deletions (loading 2).

x
0 of 4 viewed, 4 left
48 additions and 13 deletionsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsModified
View file
@@ -366,7 +366,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 the 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 =
@@ -1286,14 +1286,36 @@
for (const row of claudeDescendants(rows, roots)) tracked.set(identity(row), row);
return running;
- const stop = refresh(false).pipe(
+ const refreshRunning = refresh(true).pipe(Effect.asVoid);
+ let exited = false;
+ let polling: Fiber.Fiber<unknown> | undefined;
+ // Jobs start only while the CLI works, so polling runs from launch or a prompt until a result.
+ const poll = () => {
+ if (exited || polling !== undefined) return;
+ polling = runFork(
+ refreshRunning.pipe(Effect.repeat(Schedule.spaced(CLAUDE_DESCENDANT_POLL))),
+ );
+ };
+ const pause = Effect.suspend(() => {
+ const fiber = polling;
+ polling = undefined;
+ return fiber === undefined ? Effect.void : Fiber.interrupt(fiber);
+ });