Skip to content

Commit 46168fd

Browse files
committed
fix(orchestration): adapt handoff lifecycle to current main
Preserve current handoff completion and Stop semantics, settle detached root items in ingestion order, and handle terminal item updates across provider continuations. Adapt subscription fixtures and synchronize integration assertions with persisted completion.
1 parent 3d28639 commit 46168fd

5 files changed

Lines changed: 182 additions & 153 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6475,7 +6475,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
64756475
if (
64766476
!source ||
64776477
!(
6478-
(source.id === worktreeContinuationOfRunId && isBlockingRun(source)) ||
6478+
(source.id === worktreeContinuationOfRunId && isActiveRun(source)) ||
64796479
isRestartContinuationSource(source, projection.providerTurns) ||
64806480
continuationFailedBeforePrompt(source, projection.providerTurns)
64816481
) ||
@@ -14480,7 +14480,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1448014480
command.worktreeContinuation === undefined
1448114481
? undefined
1448214482
: (yield* getProjectionWithPendingEvents(command.threadId, events)).runs.find(
14483-
isBlockingRun,
14483+
isActiveRun,
1448414484
);
1448514485
yield* dispatchThreadMutation(command, events, effects);
1448614486
if (command.worktreeContinuation !== undefined) {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,8 +1787,8 @@ it.effect(
17871787
modelSelection,
17881788
runtimePolicy,
17891789
});
1790-
const firstClient = yield* runtime.subscribeEvents!;
1791-
const secondClient = yield* runtime.subscribeEvents!;
1790+
const firstClient = yield* runtime.subscribeEvents!();
1791+
const secondClient = yield* runtime.subscribeEvents!();
17921792
const oldQueue = (yield* Ref.get(state)).eventQueues.get(String(providerSessionId));
17931793
assert.isDefined(oldQueue);
17941794
const statuses = [{ key: "watch", text: "Watching 4 files" }];
@@ -1843,7 +1843,7 @@ it.effect(
18431843
modelSelection,
18441844
runtimePolicy,
18451845
});
1846-
const replacementClient = yield* replacement.subscribeEvents!;
1846+
const replacementClient = yield* replacement.subscribeEvents!();
18471847
const newQueue = (yield* Ref.get(state)).eventQueues.get(String(providerSessionId));
18481848
assert.isDefined(newQueue);
18491849
yield* Queue.offer(oldQueue!, {
@@ -1908,7 +1908,7 @@ it.effect.each(["session metadata", "session status changes", "provider work"] a
19081908
modelSelection,
19091909
runtimePolicy,
19101910
});
1911-
const subscriber = yield* runtime.subscribeEvents!;
1911+
const subscriber = yield* runtime.subscribeEvents!();
19121912
const observed = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
19131913
yield* subscriber.events.pipe(
19141914
Stream.runForEach((event) => Queue.offer(observed, event)),
@@ -2141,7 +2141,7 @@ it.effect("ProviderSessionManagerV2 fails a turn whose provider retry never resu
21412141
modelSelection,
21422142
runtimePolicy,
21432143
});
2144-
const subscription = yield* runtime.subscribeEvents!;
2144+
const subscription = yield* runtime.subscribeEvents!();
21452145
const published = yield* Queue.unbounded<void>();
21462146
// The pump updates the stall watch before it publishes a turn item.
21472147
const collected = yield* subscription.events.pipe(
@@ -4328,7 +4328,7 @@ it.effect.each([
43284328
modelSelection: selection,
43294329
runtimePolicy,
43304330
});
4331-
const subscription = yield* secondRuntime.subscribeEvents!;
4331+
const subscription = yield* secondRuntime.subscribeEvents!();
43324332
const terminal = yield* subscription.events.pipe(
43334333
Stream.filter((event) => event.type === "turn.terminal"),
43344334
Stream.runHead,
@@ -4877,7 +4877,7 @@ it.effect.each([
48774877
runtimePolicy,
48784878
});
48794879
// The pump marks the thread idle before subscribers see its terminal.
4880-
const subscription = yield* runtime.subscribeEvents!;
4880+
const subscription = yield* runtime.subscribeEvents!();
48814881
yield* Queue.offer((yield* Ref.get(state)).eventQueues.get(String(providerSessionId))!, {
48824882
type: "turn.terminal",
48834883
driver: CODEX_DRIVER,

‎apps/server/src/orchestration-v2/RunExecutionService.test.ts‎

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,21 +2643,22 @@ it.effect("settles native subagents when a workspace handoff completes the root
26432643
providerSessionId: ProviderSessionId.make("session:subagent-workspace-handoff"),
26442644
session: {
26452645
events: Stream.empty,
2646-
subscribeEvents: Effect.succeed({
2647-
// The provider event stream stays open: only settled children may end ingestion.
2648-
events: Stream.concat(
2649-
Stream.fromIterable([
2650-
childThreadCreatedEvent(ids),
2651-
{ type: "subagent.updated", driver, subagent: runningSubagent },
2652-
{ type: "node.updated", driver, node: runningNode },
2653-
{ type: "node.updated", driver, node: runningChildNode },
2654-
{ type: "turn_item.updated", driver, turnItem: runningTurnItem },
2655-
rootTerminalEvent(ids, "interrupted"),
2656-
] satisfies ReadonlyArray<ProviderAdapter.ProviderAdapterV2Event>),
2657-
Stream.never,
2658-
),
2659-
close: Deferred.succeed(ingestionDone, undefined),
2660-
}),
2646+
subscribeEvents: () =>
2647+
Effect.succeed({
2648+
// The provider event stream stays open: only settled children may end ingestion.
2649+
events: Stream.concat(
2650+
Stream.fromIterable([
2651+
childThreadCreatedEvent(ids),
2652+
{ type: "subagent.updated", driver, subagent: runningSubagent },
2653+
{ type: "node.updated", driver, node: runningNode },
2654+
{ type: "node.updated", driver, node: runningChildNode },
2655+
{ type: "turn_item.updated", driver, turnItem: runningTurnItem },
2656+
rootTerminalEvent(ids, "interrupted"),
2657+
] satisfies ReadonlyArray<ProviderAdapter.ProviderAdapterV2Event>),
2658+
Stream.never,
2659+
),
2660+
close: Deferred.succeed(ingestionDone, undefined),
2661+
}),
26612662
startTurn: () => Effect.void,
26622663
} as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime,
26632664
run: {
@@ -2900,6 +2901,7 @@ it.effect("interrupts open tool items but preserves completed tools on a planned
29002901
const ids = backgroundScenarioIds(key);
29012902
const runningId = TurnItemId.make(`${ids.itemId}:running`);
29022903
const completedId = TurnItemId.make(`${ids.itemId}:completed`);
2904+
const now = yield* DateTime.now;
29032905
const { ingested, observed } = yield* captureRootRunTermination({
29042906
key,
29052907
shouldFinalizeRun: () => Effect.succeed(true),
@@ -2910,6 +2912,21 @@ it.effect("interrupts open tool items but preserves completed tools on a planned
29102912
backgroundTurnItemEvent(ids, "dynamic_tool", "pending", 1),
29112913
backgroundTurnItemEvent(ids, "dynamic_tool", "running", 2, runningId),
29122914
backgroundTurnItemEvent(ids, "dynamic_tool", "running", 3, completedId),
2915+
{
2916+
type: "provider_turn.updated" as const,
2917+
driver,
2918+
providerTurn: {
2919+
id: ProviderTurnId.make(`${ids.rootProviderTurnId}:continuation`),
2920+
providerThreadId: ids.providerThreadId,
2921+
nodeId: ids.rootNodeId,
2922+
runAttemptId: ids.attemptId,
2923+
nativeTurnRef: null,
2924+
ordinal: 2,
2925+
status: "running" as const,
2926+
startedAt: now,
2927+
completedAt: null,
2928+
},
2929+
},
29132930
backgroundTurnItemEvent(ids, "dynamic_tool", "completed", 3, completedId),
29142931
]),
29152932
Stream.fail(
@@ -4250,27 +4267,28 @@ function runBackgroundItemScenario(
42504267
...(options?.hasPendingBackgroundWorkForThread === undefined
42514268
? {}
42524269
: { hasPendingBackgroundWorkForThread: options.hasPendingBackgroundWorkForThread }),
4253-
subscribeEvents: () => Effect.gen(function* () {
4254-
yield* options?.onSubscribe ?? Effect.void;
4255-
const source = makeEvents(ids);
4256-
const events = (Stream.isStream(source) ? source : Stream.fromIterable(source)).pipe(
4257-
Stream.concat(
4258-
Stream.fromEffect(
4259-
Effect.andThen(
4260-
options?.onEventsConsumed ?? Effect.void,
4261-
options?.afterEvents?.(previewActivity) ?? Effect.void,
4262-
),
4263-
).pipe(Stream.drain),
4264-
),
4265-
);
4266-
return {
4267-
events:
4268-
options?.keepEventStreamOpen === true
4269-
? events.pipe(Stream.concat(Stream.never))
4270-
: events,
4271-
close: Deferred.succeed(ingestionDone, undefined),
4272-
};
4273-
}),
4270+
subscribeEvents: () =>
4271+
Effect.gen(function* () {
4272+
yield* options?.onSubscribe ?? Effect.void;
4273+
const source = makeEvents(ids);
4274+
const events = (Stream.isStream(source) ? source : Stream.fromIterable(source)).pipe(
4275+
Stream.concat(
4276+
Stream.fromEffect(
4277+
Effect.andThen(
4278+
options?.onEventsConsumed ?? Effect.void,
4279+
options?.afterEvents?.(previewActivity) ?? Effect.void,
4280+
),
4281+
).pipe(Stream.drain),
4282+
),
4283+
);
4284+
return {
4285+
events:
4286+
options?.keepEventStreamOpen === true
4287+
? events.pipe(Stream.concat(Stream.never))
4288+
: events,
4289+
close: Deferred.succeed(ingestionDone, undefined),
4290+
};
4291+
}),
42744292
startTurn: () => Effect.void,
42754293
} as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime,
42764294
run: {

0 commit comments

Comments
 (0)