Skip to content

Commit 69a9a9c

Browse files
committed
fix(server): retain confirmed outcomes through Agent results
1 parent b2db626 commit 69a9a9c

2 files changed

Lines changed: 84 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8990,6 +8990,84 @@ describe("ClaudeAdapterV2 background wake turns", () => {
89908990
),
89918991
);
89928992

8993+
it.effect("preserves a confirmed native outcome after the synchronous Agent tool result", () =>
8994+
Effect.scoped(
8995+
Effect.gen(function* () {
8996+
let stopCalls = 0;
8997+
const harness = yield* makeWakeHarnessWithOptions({
8998+
stopTask: () => Effect.sync(() => void stopCalls++),
8999+
});
9000+
yield* harness.runtime.startTurn(
9001+
makeClaudeTestTurnInput({
9002+
threadId: harness.threadId,
9003+
providerThread: harness.providerThread,
9004+
now: yield* DateTime.now,
9005+
attemptId: RunAttemptId.make("attempt-stop-after-agent-result"),
9006+
text: "Run an audit.",
9007+
attachments: [],
9008+
}),
9009+
);
9010+
yield* harness.offerAndWait(
9011+
makeSubagentTaskStartedFrame({
9012+
taskId: "sync-audit",
9013+
toolUseId: "toolu-sync-audit",
9014+
uuid: "00000000-0000-4000-8000-000000004301",
9015+
}),
9016+
);
9017+
yield* Queue.take(harness.subagentReceipts);
9018+
yield* harness.offerAndWait(
9019+
makeSubagentNotificationFrame({
9020+
taskId: "sync-audit",
9021+
toolUseId: "toolu-sync-audit",
9022+
summary: "Native audit outcome.",
9023+
uuid: "00000000-0000-4000-8000-000000004302",
9024+
}),
9025+
);
9026+
const completed = yield* Queue.take(harness.subagentReceipts);
9027+
yield* TestClock.adjust("1 second");
9028+
yield* harness.offerAndWait(
9029+
claudeSdkFrame({
9030+
type: "user",
9031+
message: {
9032+
role: "user",
9033+
content: [
9034+
{
9035+
type: "tool_result",
9036+
tool_use_id: "toolu-sync-audit",
9037+
content: "Audit tool result.",
9038+
},
9039+
],
9040+
},
9041+
parent_tool_use_id: null,
9042+
uuid: "00000000-0000-4000-8000-000000004303",
9043+
session_id: WAKE_NATIVE_SESSION,
9044+
}),
9045+
);
9046+
const updated = yield* Queue.take(harness.subagentReceipts);
9047+
assert.equal(updated.subagent.result, "Audit tool result.");
9048+
const stopping = yield* harness.runtime.stopSubagent!({
9049+
providerThread: harness.providerThread,
9050+
nativeTaskId: "sync-audit",
9051+
}).pipe(Effect.exit, Effect.forkScoped);
9052+
yield* TestClock.adjust("2 seconds");
9053+
const outcome = yield* Fiber.join(stopping);
9054+
assert.isTrue(Exit.isSuccess(outcome));
9055+
if (Exit.isSuccess(outcome)) {
9056+
assert.deepEqual(outcome.value, {
9057+
status: "completed",
9058+
completedAt: completed.subagent.completedAt!,
9059+
result: "Native audit outcome.",
9060+
});
9061+
}
9062+
assert.equal(stopCalls, 0);
9063+
}).pipe(
9064+
Effect.provide(
9065+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
9066+
),
9067+
),
9068+
),
9069+
);
9070+
89939071
it.effect.each(["completed", "failed", "stopped"] as const)(
89949072
"applies an idle native subagent %s notification before replay and confirms its real outcome",
89959073
(status) =>

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5032,7 +5032,11 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
50325032
const subagent = {
50335033
task,
50345034
confirmedOutcome:
5035-
input.nativeOutcome === true ? confirmedSubagentOutcome(task) : undefined,
5035+
input.nativeOutcome === true
5036+
? confirmedSubagentOutcome(task)
5037+
: isReopen
5038+
? undefined
5039+
: existingSubagent?.confirmedOutcome,
50365040
rootNodeId: existingSubagent?.rootNodeId ?? input.context.input.rootNodeId,
50375041
childThreadId,
50385042
childRootNodeId,
@@ -5250,7 +5254,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
52505254
},
52515255
});
52525256

5253-
if (subagent.confirmedOutcome !== undefined) {
5257+
if (input.nativeOutcome === true && subagent.confirmedOutcome !== undefined) {
52545258
const outcome = subagentStopOutcomes.get(input.taskId);
52555259
if (outcome !== undefined) yield* Deferred.succeed(outcome, undefined);
52565260
}

0 commit comments

Comments
 (0)