Skip to content

Commit ba3f59c

Browse files
fix(server): fresh-session schedules start while an old session has background work
A scheduled fresh-context dispatch on an idle thread was refused when the session it would release still reported background work. Nobody can wait or press Stop for a schedule, so every later fire failed until the work ended. Scheduled fresh dispatches now leave the busy session running and start a new one, as queued fresh starts already do. Fixes #32100 AI-assisted; verified with the tests and tools listed above.
1 parent 3834a65 commit ba3f59c

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7298,7 +7298,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
72987298
isProviderSwitch &&
72997299
activeProviderThread.nativeThreadRef !== null &&
73007300
providerSwitchPlan?.transition.type === "restart_and_resume";
7301-
const sessionsToDetach = uniqueSessions([
7301+
const releasableSessions = uniqueSessions([
73027302
...projection.providerSessions.filter(
73037303
(session) =>
73047304
providerSwitchPlan?.releaseProviderSessionIds.includes(session.id) &&
@@ -7307,8 +7307,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
73077307
),
73087308
...(freshContext ? sessionsReleasedByFreshContext(projection, activeProviderThread) : []),
73097309
]);
7310-
for (const detaching of sessionsToDetach) {
7310+
const sessionsToDetach: Array<OrchestrationV2ProviderSession> = [];
7311+
for (const detaching of releasableSessions) {
73117312
if (yield* sessionHasBackgroundWork(detaching, projection.providerThreads)) {
7313+
// A schedule has nobody to wait or press Stop; like a queued fresh start, leave it running.
7314+
if (freshContext && command.scheduledTaskId !== undefined) continue;
73127315
return yield* new OrchestratorDispatchError({
73137316
commandId: command.commandId,
73147317
commandType: command.type,
@@ -7317,6 +7320,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
73177320
: "The previous provider is still running background agents or commands, and switching would end them. Wait for them to finish, or press Stop, then send the message again.",
73187321
});
73197322
}
7323+
sessionsToDetach.push(detaching);
73207324
}
73217325

73227326
if (

0 commit comments

Comments
 (0)