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 into
main fromrefs/pull/35711/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -1286,4 +1286,20 @@12861286 for (const row of claudeDescendants(rows, roots)) tracked.set(identity(row), row);12871287 return running;12881288 });1289- const stop = refresh(false).pipe(1289+ const refreshRunning = refresh(true).pipe(Effect.asVoid);1290+ let exited = false;1291+ let polling: Fiber.Fiber<unknown> | undefined;1292+ // Jobs start only while the CLI works, so polling runs from launch or a prompt until a result.1293+ const poll = () => {1294+ if (exited || polling !== undefined) return;1295+ polling = runFork(1296+ refreshRunning.pipe(Effect.repeat(Schedule.spaced(CLAUDE_DESCENDANT_POLL))),1297+ );1298+ };1299+ const pause = Effect.suspend(() => {1300+ const fiber = polling;1301+ polling = undefined;1302+ return fiber === undefined ? Effect.void : Fiber.interrupt(fiber);1303+ });1304+ const settle = pause.pipe(1305+ Effect.andThen(Effect.suspend(() => (exited ? Effect.void : refreshRunning))),@@ -1289,0 +1291,21 @@1291+ let polling: Fiber.Fiber<unknown> | undefined;1292+ // Jobs start only while the CLI works, so polling runs from launch or a prompt until a result.1293+ const poll = () => {1294+ if (exited || polling !== undefined) return;1295+ polling = runFork(1296+ refreshRunning.pipe(Effect.repeat(Schedule.spaced(CLAUDE_DESCENDANT_POLL))),1297+ );1298+ };1299+ const pause = Effect.suspend(() => {1300+ const fiber = polling;1301+ polling = undefined;1302+ return fiber === undefined ? Effect.void : Fiber.interrupt(fiber);1303+ });1304+ const settle = pause.pipe(1305+ Effect.andThen(Effect.suspend(() => (exited ? Effect.void : refreshRunning))),1306+ );1307+ const stop = Effect.suspend(() => {1308+ exited = true;1309+ return pause;1310+ }).pipe(1311+ Effect.andThen(refresh(false)),@@ -503,4 +512,10 @@503512 readonly providerSessionId: ProviderSessionId;504513 readonly threadId: ThreadId;505514 }) => `${input.providerSessionId}\u0000${input.threadId}`;506- const idleTimeoutMs = Math.max(1, options.idleTimeoutMs ?? DEFAULT_IDLE_TIMEOUT_MS);515+ const idleTimeoutFor = (runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime) =>516+ Math.max(517+ 1,518+ options.idleTimeoutMs ??519+ (UNVERIFIED_RESUME_DRIVERS.has(runtime.driver)520+ ? UNVERIFIED_RESUME_IDLE_TIMEOUT_MS521+ : DEFAULT_IDLE_TIMEOUT_MS),@@ -1459,7 +1475,7 @@1459147514601476 yield* cancelIdleFiber(entry.idleFiber);14611477 const generation = entry.idleGeneration + 1;1462- const idleFiber = yield* Effect.sleep(Duration.millis(idleTimeoutMs)).pipe(1478+ const idleFiber = yield* Effect.sleep(Duration.millis(idleTimeoutFor(entry.runtime))).pipe(14631479 Effect.andThen(releaseIfStillIdle({ providerSessionId, generation })),14641480 Effect.forkIn(layerScope),14651481 );
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — Idle sessions will release memory after 2 minutes instead of 30 for most drivers, while Claude process polling pauses between turns. The shorter default requires human acceptance of the resource-saving versus session-continuity tradeoff.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).