Skip to content

Commit 93af514

Browse files
committed
fix(server): a held follow-up keeps a finished child's session
delegatedTaskProgress ignores held queued runs, which is right for its own purpose, but a held follow-up still needs this session when its queue resumes.
1 parent 7a53dc2 commit 93af514

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3954,7 +3954,7 @@ const finishedDelegateRunEvent = (input: {
39543954
readonly idAllocator: IdAllocator.IdAllocatorV2["Service"];
39553955
readonly threadId: ThreadId;
39563956
readonly ordinal: number;
3957-
readonly status: "completed" | "queued" | "running";
3957+
readonly status: "completed" | "queued" | "held" | "running";
39583958
readonly now: DateTime.Utc;
39593959
}) =>
39603960
Effect.gen(function* () {
@@ -3981,9 +3981,10 @@ const finishedDelegateRunEvent = (input: {
39813981
}),
39823982
rootNodeId: null,
39833983
activeAttemptId: null,
3984-
status: input.status,
3984+
status: input.status === "held" ? ("queued" as const) : input.status,
3985+
...(input.status === "held" ? { queueHeld: true } : {}),
39853986
requestedAt: input.now,
3986-
startedAt: input.status === "queued" ? null : input.now,
3987+
startedAt: input.status === "queued" || input.status === "held" ? null : input.now,
39873988
completedAt: input.status === "completed" ? input.now : null,
39883989
checkpointId: null,
39893990
contextHandoffId: null,
@@ -3995,7 +3996,7 @@ const finishedDelegateRunEvent = (input: {
39953996
// it as a finished delegate with no clock advance, far inside the idle timeout.
39963997
const runFinishedDelegateScenario = (input: {
39973998
readonly delegated: boolean;
3998-
readonly runs: ReadonlyArray<"completed" | "queued" | "running">;
3999+
readonly runs: ReadonlyArray<"completed" | "queued" | "held" | "running">;
39994000
readonly hasPendingBackgroundWork?: boolean;
40004001
}) =>
40014002
Effect.gen(function* () {
@@ -4093,7 +4094,7 @@ it.effect(
40934094
it.effect.each<{
40944095
readonly name: string;
40954096
readonly delegated: boolean;
4096-
readonly runs: ReadonlyArray<"completed" | "queued" | "running">;
4097+
readonly runs: ReadonlyArray<"completed" | "queued" | "held" | "running">;
40974098
readonly hasPendingBackgroundWork?: boolean;
40984099
}>([
40994100
{ name: "an ordinary thread", delegated: false, runs: ["completed"] },
@@ -4103,6 +4104,11 @@ it.effect.each<{
41034104
delegated: true,
41044105
runs: ["completed", "queued"],
41054106
},
4107+
{
4108+
name: "a delegated child with a held follow-up",
4109+
delegated: true,
4110+
runs: ["completed", "held"],
4111+
},
41064112
{
41074113
name: "a delegated child with pending background work",
41084114
delegated: true,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,8 @@ export const layerWithOptions = (
23912391
Effect.map(
23922392
(records) =>
23932393
records.thread.lineage.relationshipToParent === "subagent" &&
2394+
// Progress ignores held runs, but a held follow-up still needs this session.
2395+
!records.runs.some((run) => run.status === "queued") &&
23942396
delegatedTaskProgress(records).state === "result_available",
23952397
),
23962398
// An unreadable thread may still be working; never kill it unseen.

0 commit comments

Comments
 (0)