Skip to content

Commit 7d53c49

Browse files
fix(server): validate question wakes of tasks whose result was handed over
AI-assisted; verified with the tests and tools listed above.
1 parent 62e0657 commit 7d53c49

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,14 @@ it.effect.each([false, true])(
14901490
});
14911491
yield* reactor.handle(childCompleted);
14921492
if (missedEvent) {
1493+
// An acknowledged result drops the task from the parent's command projection.
1494+
yield* orchestrator.dispatch({
1495+
type: "delegated_task.completion-delivery.acknowledge",
1496+
commandId: CommandId.make("ack-stale-question-task"),
1497+
parentThreadId,
1498+
taskId: task.id,
1499+
observedByRunId: parentRun.id,
1500+
});
14931501
// Persisted terminal state can predate the reactor subscription after restart.
14941502
yield* projections.apply({
14951503
id: EventId.make("event:stale-question-parent-finished"),

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
18921892
if (notification?.source.kind !== "delegated_task" || notification.outcome !== "updated")
18931893
return false;
18941894
const source = notification.source;
1895-
const task = projection.subagents.find((candidate) => source.taskIds.includes(candidate.id));
1895+
const threadId = projection.thread.id;
1896+
const task =
1897+
projection.subagents.find((candidate) => source.taskIds.includes(candidate.id)) ??
1898+
// Command projections omit settled tasks whose result was already handed over.
1899+
(yield* projectionStore
1900+
.getThreadRecords(threadId, ["subagents"], { subagentIds: source.taskIds })
1901+
.pipe(Effect.mapError((cause) => new OrchestratorProjectionError({ threadId, cause }))))
1902+
.subagents[0];
18961903
// An unknown task gives no evidence the question is obsolete.
18971904
if (task === undefined) return false;
18981905
const childThreadId = task.childThreadId;
@@ -1912,7 +1919,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
19121919
(request) =>
19131920
request.kind === "user_input" &&
19141921
request.status === "pending" &&
1915-
messageId === `message:delegated-task-question:${projection.thread.id}:${request.id}`,
1922+
messageId === `message:delegated-task-question:${threadId}:${request.id}`,
19161923
);
19171924
});
19181925

0 commit comments

Comments
 (0)