The best way to control Claude Code, Codex and more from any computer or phone
test(server): idle-resume replays wait for the session release before the next prompt (#35720)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 12, 2026 at 16:26 UTC
48a56faaa2f1b9c3695bb4b506e32fbf249fb626
6 files changed
+50
-8
apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts
+37
-3
@@ -14,6 +14,7 @@ import type {
14
TurnItemId,
15
} from "@t3tools/contracts";
16
import * as Clock from "effect/Clock";
17
+import * as Deferred from "effect/Deferred";
18
import * as Duration from "effect/Duration";
19
import * as Effect from "effect/Effect";
20
import * as Fiber from "effect/Fiber";
@@ -37,6 +38,8 @@ export type OrchestratorV2ScenarioStep =
38
| {
39
readonly type: "advance_clock";
40
readonly duration: Duration.Input;
41
+ /** Wait until the jump idle-releases this thread's provider session. */
42
+ readonly awaitProviderSessionRelease?: ThreadId;
43
}
44
| {
45
readonly type: "await";
@@ -271,9 +274,21 @@ export function runOrchestratorV2Scenario(
274
const orchestrator = yield* Orchestrator.OrchestratorV2;
275
const storedEventGroups: Array<ReadonlyArray<OrchestrationV2StoredEvent>> = [];
276
const observedStoredEvents = yield* Ref.make<Array<OrchestrationV2StoredEvent>>([]);
277
+ let releaseWatch:
278
+ | { readonly threadId: ThreadId; readonly released: Deferred.Deferred<void> }
279
+ | undefined;
280
yield* orchestrator.streamStoredEvents.pipe(
275
- Stream.runForEach((event) =>
276
- Ref.update(observedStoredEvents, (existing) => [...existing, event]),
281
+ Stream.runForEach((stored) =>
282
+ Ref.update(observedStoredEvents, (existing) => [...existing, stored]).pipe(
283
+ Effect.andThen(
284
+ releaseWatch !== undefined &&
285
+ stored.event.type === "provider-session.updated" &&
286
+ stored.event.threadId === releaseWatch.threadId &&
287
+ stored.event.payload.status === "stopped"
288
+ ? Deferred.succeed(releaseWatch.released, undefined)
289
+ : Effect.void,
290
+ ),
291
+ ),
292
),
293
Effect.forkScoped,
294
);
@@ -647,9 +662,28 @@ export function runOrchestratorV2Scenario(
662
);
663
break;
664
}
650
- case "advance_clock":
665
+ case "advance_clock": {
666
+ if (step.awaitProviderSessionRelease === undefined) {
667
+ yield* TestClock.adjust(step.duration);
668
+ break;
669
+ }
670
+ // The release runs on a woken fiber; a dispatch before it commits cancels it.
671
+ const released = yield* Deferred.make<void>();
672
+ releaseWatch = { threadId: step.awaitProviderSessionRelease, released };
673
yield* TestClock.adjust(step.duration);
674
+ const settled = yield* Deferred.await(released).pipe(
675
+ Effect.timeoutOption(Duration.millis(SCENARIO_WAIT_DEADLINE_MS)),
676
+ Effect.provideService(Clock.Clock, Clock.Clock.defaultValue()),
677
+ );
678
+ releaseWatch = undefined;
679
+ if (Option.isNone(settled)) {
680
+ return yield* new OrchestratorV2ScenarioStepError({
681
+ scenario: scenario.name,
682
+ step: `advance_clock:${step.awaitProviderSessionRelease}:no_provider_session_release`,
683
+ });
684
+ }
685
break;
686
+ }
687
case "await":
688
yield* awaitDispatch(step.key);
689
break;
apps/server/src/orchestration-v2/testkit/fixtures/claude_compact_after_resume_wake/input.ts
+1
-1
@@ -5,7 +5,7 @@ export function claudeCompactAfterResumeWakeInput(): OrchestratorFixtureInput {
5
return {
6
steps: [
7
{ type: "message", text: CLAUDE_COMPACT_FIRST_PROMPT },
8
- { type: "advance_clock", duration: "31 minutes" },
8
+ { type: "advance_clock", duration: "31 minutes", releasesProviderSession: true },
9
{ type: "message", text: "/compact" },
10
],
11
};
apps/server/src/orchestration-v2/testkit/fixtures/claude_idle_resume/input.ts
+1
-1
@@ -7,7 +7,7 @@ export function claudeIdleResumeInput(): OrchestratorFixtureInput {
7
return {
8
steps: [
9
{ type: "message", text: CLAUDE_IDLE_RESUME_PROMPT_1 },
10
- { type: "advance_clock", duration: "31 minutes" },
10
+ { type: "advance_clock", duration: "31 minutes", releasesProviderSession: true },
11
{ type: "message", text: CLAUDE_IDLE_RESUME_PROMPT_2 },
12
],
13
};
apps/server/src/orchestration-v2/testkit/fixtures/provider_thread_resume/input.ts
+1
-1
@@ -9,7 +9,7 @@ export function providerThreadResumeInput(): OrchestratorFixtureInput {
9
return {
10
steps: [
11
{ type: "message", text: PROVIDER_THREAD_RESUME_FIRST_PROMPT },
12
- { type: "advance_clock", duration: "31 minutes" },
12
+ { type: "advance_clock", duration: "31 minutes", releasesProviderSession: true },
13
{ type: "message", text: PROVIDER_THREAD_RESUME_SECOND_PROMPT },
14
],
15
};
apps/server/src/orchestration-v2/testkit/fixtures/shared.ts
+9
-1
@@ -268,6 +268,8 @@ export type OrchestratorFixtureInputStep =
268
| {
269
readonly type: "advance_clock";
270
readonly duration: Duration.Input;
271
+ /** The jump idle-releases the provider session; later steps wait for that release. */
272
+ readonly releasesProviderSession?: boolean;
273
}
274
| {
275
/** Picks another model of the same provider instance; later messages use it. */
@@ -883,7 +885,13 @@ export function materializeFixtureInput(input: {
885
});
886
break;
887
case "advance_clock":
886
- steps.push({ type: "advance_clock", duration: step.duration });
888
+ steps.push({
889
+ type: "advance_clock",
890
+ duration: step.duration,
891
+ ...(step.releasesProviderSession === true
892
+ ? { awaitProviderSessionRelease: ids.threadId }
893
+ : {}),
894
+ });
895
break;
896
case "set_model":
897
modelSelection = { ...input.modelSelection, model: step.model };
apps/server/src/orchestration-v2/testkit/fixtures/stop_background_work_after_failed_turn/input.ts
+1
-1
@@ -16,7 +16,7 @@ export function stopBackgroundWorkAfterReleaseInput(): OrchestratorFixtureInput
16
return {
17
steps: [
18
{ type: "message", text: STOP_BACKGROUND_WORK_AFTER_FAILED_TURN_PROMPT },
19
- { type: "advance_clock", duration: "31 minutes" },
19
+ { type: "advance_clock", duration: "31 minutes", releasesProviderSession: true },
20
{ type: "stop_background_work", targetRunIndex: 1 },
21
],
22
};