Skip to content

Commit 97359ff

Browse files
committed
test(server): run delegated recovery after runtime reconciliation
1 parent f9bc3b5 commit 97359ff

2 files changed

Lines changed: 2 additions & 41 deletions

File tree

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,6 @@ it.layer(TestLayer)("delegated tasks across a server restart", (it) => {
20072007
);
20082008
});
20092009

2010-
20112010
it.effect.each([
20122011
{
20132012
heldQueue: true,
@@ -2221,23 +2220,10 @@ it.effect.each([
22212220
return Effect.gen(function* () {
22222221
const orchestrator = yield* Orchestrator.OrchestratorV2;
22232222
const beforeRuntimeRecovery = yield* orchestrator.getThreadProjection(parentId);
2224-
assert.equal(beforeRuntimeRecovery.subagents[0]?.status, heldQueue ? "pending" : "running");
2225-
const sink = yield* EventSink.EventSinkV2;
2226-
const afterSequence = yield* sink.latestSequence();
2223+
assert.equal(beforeRuntimeRecovery.subagents[0]?.status, "running");
22272224
const runtimeRecovery = yield* ProviderRuntimeRecoveryService.ProviderRuntimeRecoveryService;
22282225
yield* runtimeRecovery.recover;
2229-
if (!heldQueue) {
2230-
yield* sink.stream({ afterSequence, eventType: "subagent.updated" }).pipe(
2231-
Stream.filter(
2232-
(stored) =>
2233-
stored.event.type === "subagent.updated" &&
2234-
stored.event.payload.id === taskId &&
2235-
stored.event.payload.status === "cancelled",
2236-
),
2237-
Stream.take(1),
2238-
Stream.runDrain,
2239-
);
2240-
}
2226+
yield* orchestrator.recoverDelegatedTasks;
22412227
const parent = yield* orchestrator.getThreadProjection(parentId);
22422228
const child = yield* orchestrator.getThreadProjection(childId);
22432229
if (heldQueue) {

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -163,31 +163,6 @@ function resolveStaleBackgroundItemProviderInstanceId(
163163
return projection.providerThreads[0]?.providerInstanceId ?? projection.thread.providerInstanceId;
164164
}
165165

166-
/**
167-
* Provider threads with background work reconciliation would cancel and
168-
* record for their next turn.
169-
*/
170-
function providerThreadsWithOpenBackgroundWork(
171-
projection: ProjectionStore.ProjectionRuntimeRecoveryState,
172-
): ReadonlySet<ProviderThreadId> {
173-
const ids = new Set<ProviderThreadId>();
174-
const taskIds = appOwnedSubagentIds(projection);
175-
for (const item of projection.turnItems ?? []) {
176-
if (isAppOwnedSubagentItem(item, taskIds)) continue;
177-
if (!isBackgroundCapableTurnItemType(item.type) || !isNonterminalTurnItemStatus(item.status))
178-
continue;
179-
const providerThreadId =
180-
item.providerThreadId ??
181-
projection.runs.find((run) => run.id === item.runId)?.providerThreadId;
182-
if (providerThreadId != null) ids.add(providerThreadId);
183-
}
184-
for (const thread of projection.providerThreads ?? []) {
185-
if (thread.ownerNodeId === null && providerThreadHasPendingBackgroundTasks(thread))
186-
ids.add(thread.id);
187-
}
188-
return ids;
189-
}
190-
191166
/**
192167
* A provider thread's latest started run: the last turn that provider saw.
193168
* Restart recovery records the thread's cancelled background work on it, and

0 commit comments

Comments
 (0)