Skip to content

Commit 8dac6a7

Browse files
committed
fix(claude): snapshot steer command eligibility at acceptance
1 parent a1f8389 commit 8dac6a7

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5564,13 +5564,39 @@ describe("ClaudeAdapterV2 background wake turns", () => {
55645564
Effect.forkChild,
55655565
);
55665566
yield* Deferred.await(accepted);
5567+
const acceptedOfferCount = harness.offeredMessages.length;
5568+
const permission = yield* Effect.promise(() =>
5569+
harness.getOpenedOptions()!.canUseTool!(
5570+
"Bash",
5571+
{ command: "git status" },
5572+
{
5573+
signal: new AbortController().signal,
5574+
toolUseID: "post-acceptance",
5575+
requestId: "post-acceptance-request",
5576+
},
5577+
),
5578+
).pipe(Effect.forkScoped);
5579+
const request = yield* Queue.take(harness.runtimeRequestReceipts);
5580+
yield* harness.runtime.respondToRuntimeRequest({
5581+
requestId: request.runtimeRequest.id,
5582+
decision: "accept",
5583+
});
5584+
yield* Fiber.join(permission);
5585+
registered.add("post-acceptance");
55675586
yield* Fiber.interrupt(cancelled);
55685587
cancelOffer = false;
55695588
yield* through("cancelled");
5589+
yield* taskStarted("post-acceptance");
55705590
yield* harness.offerAndWait(
55715591
makeResultFrame({ uuid: uuid(), result: "", terminalReason: "aborted_tools" }),
55725592
);
55735593
yield* steer("Continue after the accepted steer.");
5594+
yield* through("post-acceptance");
5595+
assert.isTrue(
5596+
moves
5597+
.filter((move) => move.id === "post-acceptance")
5598+
.every((move) => move.offered > acceptedOfferCount),
5599+
);
55745600
}).pipe(
55755601
Effect.provide(
55765602
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10969,30 +10969,31 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1096910969
detail: `Claude provider turn ${turnInput.providerTurnId} ended before the steer was sent.`,
1097010970
});
1097110971
}
10972-
let queued = false;
10972+
let queuedCommands: ReadonlyArray<string> | undefined;
1097310973
yield* Effect.uninterruptibleMask((restore) =>
1097410974
restore(
1097510975
existing.query.offer(userMessage, () => {
10976-
queued = true;
10976+
queuedCommands = [...currentTurn.rootCommands.keys()];
1097710977
pdfReservation.commit();
1097810978
}),
1097910979
).pipe(
1098010980
// Queue acceptance survives cancellation during protocol logging.
1098110981
Effect.onExit((exit) =>
1098210982
Effect.gen(function* () {
10983-
if (!queued && !Exit.isSuccess(exit)) return;
10983+
if (queuedCommands === undefined && !Exit.isSuccess(exit)) return;
10984+
const running = queuedCommands ?? [...currentTurn.rootCommands.keys()];
1098410985
pdfReservation.commit();
1098510986
yield* Ref.update(steeredTurns, (current) => {
1098610987
const next = new Set(current);
1098710988
next.add(turnInput.providerTurnId);
1098810989
return next;
1098910990
});
10990-
for (const [toolUseId, state] of currentTurn.rootCommands) {
10991-
if (state === "foreground") {
10991+
for (const toolUseId of running) {
10992+
if (currentTurn.rootCommands.get(toolUseId) === "foreground") {
1099210993
currentTurn.rootCommands.set(toolUseId, "steered");
1099310994
}
1099410995
}
10995-
for (const toolUseId of currentTurn.rootCommands.keys()) {
10996+
for (const toolUseId of running) {
1099610997
yield* backgroundForSteer(currentTurn, existing.query, toolUseId);
1099710998
}
1099810999
}),

0 commit comments

Comments
 (0)