fix(server): a run no longer stays working after its idle session is released #14507
Closedsaphid(GitHub profile, opens in a new tab)wants to merge 5 commits into
t3code/codex-turn-mapping fromrefs/pull/14507/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:L
- @@ -526,3 +528,11 @@526528 ).pipe(Effect.map((targets): AutoBootstrapWelcomeTargets => targets)),527529 });528530 yield* Effect.logInfo("V2 orchestration recovery completed", recovery);531+ // An idle-released session's process is gone, so a run it still owned532+ // (for example one pinned open by background work that never reported533+ // back) can never finish. Settle it instead of leaving it working.534+ yield* providerSessions.idleReleases.pipe(535+ Stream.runForEach(({ providerSessionId, threadIds }) =>536+ Effect.gen(function* () {537+ // A replacement may have reused the id; its runs are live.538+ if (Option.isSome(yield* providerSessions.get(providerSessionId))) return;apps/server/src/orchestration-v2/ProviderRuntimeRecoveryService.ts line 838Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -755,3 +803,11 @@755803 } satisfies ProviderRuntimeReconciliationSummary;756804 });757805806+ const reconcileReleasedSession = (input: {807+ readonly threadId: ThreadId;808+ readonly providerSessionId: ProviderSessionId;809+ }) =>810+ Effect.gen(function* () {811+ const projection = yield* projections.getRuntimeRecoveryProjection(input.threadId);812+ if (!isStrandedBySession(projection, input.providerSessionId)) return;813+ yield* reconcileProjection(projection, "session-released", false);
- apps/server/src/orchestration-v2/ProviderRuntimeRecoveryService.ts lines 816 to 816OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -755,3 +803,14 @@755803 } satisfies ProviderRuntimeReconciliationSummary;756804 });757805806+ const reconcileReleasedSession = (input: {807+ readonly threadId: ThreadId;808+ readonly providerSessionId: ProviderSessionId;809+ }) =>810+ Effect.gen(function* () {811+ const projection = yield* projections.getRuntimeRecoveryProjection(input.threadId);812+ if (!isStrandedBySession(projection, input.providerSessionId)) return;813+ yield* reconcileProjection(projection, "session-released", false);814+ }).pipe(815+ Effect.mapError(816+ (cause) =>
- @@ -527,2 +529,21 @@527529 });528530 yield* Effect.logInfo("V2 orchestration recovery completed", recovery);531+ // An idle-released session's process is gone, so a run it still owned532+ // (for example one pinned open by background work that never reported533+ // back) can never finish. Settle it instead of leaving it working.534+ yield* providerSessions.idleReleases.pipe(535+ Stream.runForEach(({ providerSessionId, threadIds }) =>536+ Effect.gen(function* () {537+ // A replacement may have reused the id; its runs are live.538+ if (Option.isSome(yield* providerSessions.get(providerSessionId))) return;539+ yield* Effect.forEach(540+ threadIds,541+ (threadId) =>542+ providerRuntimeRecovery.reconcileReleasedSession({ threadId, providerSessionId }),543+ { discard: true },544+ );545+ }).pipe(546+ Effect.catchCause((cause) =>547+ Effect.logWarning("V2 orchestration idle-release reconciliation failed", {548+ providerSessionId,549+ cause: Cause.pretty(cause),
- apps/server/src/serverRuntimeStartup.ts line 537OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -526,3 +528,10 @@526528 ).pipe(Effect.map((targets): AutoBootstrapWelcomeTargets => targets)),527529 });528530 yield* Effect.logInfo("V2 orchestration recovery completed", recovery);531+ // An idle-released session's process is gone, so a run it still owned532+ // (for example one pinned open by background work that never reported533+ // back) can never finish. Settle it instead of leaving it working.534+ yield* providerSessions.idleReleases.pipe(535+ Stream.runForEach(({ providerSessionId, threadIds }) =>536+ Effect.gen(function* () {537+ yield* Effect.forEach(@@ -526,3 +528,7 @@526528 ).pipe(Effect.map((targets): AutoBootstrapWelcomeTargets => targets)),527529 });528530 yield* Effect.logInfo("V2 orchestration recovery completed", recovery);531+ // An idle-released session's process is gone, so a run it still owned532+ // (for example one pinned open by background work that never reported533+ // back) can never finish. Settle it instead of leaving it working.534+ yield* providerSessions.idleReleases.pipe(
- @@ -528,0 +531,21 @@531+ // An idle-released session's process is gone, so a run it still owned532+ // (for example one pinned open by background work that never reported533+ // back) can never finish. Settle it instead of leaving it working.534+ yield* providerSessions.idleReleases.pipe(535+ Stream.runForEach(({ providerSessionId, threadIds }) =>536+ Effect.forEach(537+ threadIds,538+ (threadId) =>539+ providerRuntimeRecovery540+ .reconcileReleasedSession({541+ threadId,542+ providerSessionId,543+ isSessionLive: providerSessions.get(providerSessionId).pipe(544+ Effect.map(Option.isSome),545+ // When unsure, treat it as live and leave the thread alone.546+ Effect.orElseSucceed(() => true),547+ ),548+ })549+ .pipe(550+ // One thread failing must not skip the rest of the batch.551+ Effect.catchCause((cause) =>
juliusmarminge added labelsmacroscope-review
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed