Skip to content

Commit e8d3bb7

Browse files
maria-rcksvoltcrash
authored andcommitted
fix(server): recheck pinned idle sessions without recursion
1 parent 1805efe commit e8d3bb7

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

‎apps/server/src/orchestration-v2/ProviderSessionManager.ts‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,11 +1355,11 @@ export const layerWithOptions = (
13551355
),
13561356
);
13571357

1358-
const releaseIfStillIdle = Effect.fn("ProviderSessionManager.releaseIfStillIdle")(
1358+
const releaseOrDeferIdle = Effect.fn("ProviderSessionManager.releaseIfStillIdle")(
13591359
function* (input: {
13601360
readonly providerSessionId: ProviderSessionId;
13611361
readonly generation: number;
1362-
}): Effect.fn.Return<void> {
1362+
}): Effect.fn.Return<boolean> {
13631363
const current = yield* Ref.get(sessions);
13641364
const key = sessionKey(input.providerSessionId);
13651365
const entry = current.get(key);
@@ -1368,7 +1368,7 @@ export const layerWithOptions = (
13681368
entry.busyTurns.size > 0 ||
13691369
entry.idleGeneration !== input.generation
13701370
) {
1371-
return;
1371+
return false;
13721372
}
13731373
// Capture runtime identity before yielding; replacements can reuse the session id.
13741374
const probedRuntime = entry.runtime;
@@ -1409,15 +1409,14 @@ export const layerWithOptions = (
14091409
return [true, updated] as const;
14101410
});
14111411
if (!shouldContinuePin) {
1412-
return;
1412+
return false;
14131413
}
14141414
yield* Effect.logInfo("orchestration-v2.driver-session.idle-release-deferred", {
14151415
providerSessionId: input.providerSessionId,
14161416
pinnedForMs: now - pinnedSinceMs,
14171417
});
1418-
// Recheck on this fiber; scheduleIdleReleaseInternal would interrupt it and self-deadlock.
14191418
yield* Effect.sleep(Duration.millis(idleTimeoutMs));
1420-
return yield* releaseIfStillIdle(input);
1419+
return true;
14211420
}
14221421
yield* Effect.logWarning("orchestration-v2.driver-session.idle-release-pin-expired", {
14231422
providerSessionId: input.providerSessionId,
@@ -1450,9 +1449,21 @@ export const layerWithOptions = (
14501449
}),
14511450
),
14521451
);
1452+
return false;
14531453
},
14541454
);
14551455

1456+
// Recheck on this fiber; scheduleIdleReleaseInternal would interrupt it and self-deadlock.
1457+
// Repeat instead of recursing so indefinitely pinned work keeps constant memory.
1458+
const releaseIfStillIdle = (input: {
1459+
readonly providerSessionId: ProviderSessionId;
1460+
readonly generation: number;
1461+
}) =>
1462+
releaseOrDeferIdle(input).pipe(
1463+
Effect.repeat({ while: (deferred) => deferred }),
1464+
Effect.asVoid,
1465+
);
1466+
14561467
const withActivityError = <A, E, R>(
14571468
providerSessionId: ProviderSessionId,
14581469
effect: Effect.Effect<A, E, R>,

0 commit comments

Comments
 (0)