Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11013,7 +11013,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
);

it.effect(
"uses task_started as an incremental roster fallback, keeps its tool call, and clears internal work on empty snapshot",
"uses task_started as an incremental roster fallback, keeps its tool call, and retains owed wakes on empty snapshot",
() =>
Effect.gen(function* () {
const harness = yield* makeWakeHarness;
Expand Down Expand Up @@ -11161,7 +11161,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
).map((task) => task.taskId),
WAKE_TASK_ID,
);
assert.isFalse(yield* harness.hasPendingBackgroundWork);
assert.isTrue(yield* harness.hasPendingBackgroundWork);
}).pipe(
Effect.provide(
Layer.mergeAll(
Expand Down Expand Up @@ -12185,6 +12185,8 @@ describe("ClaudeAdapterV2 background wake turns", () => {
assert.equal(closes, 0);
assert.isTrue(yield* harness.hasPendingBackgroundWork);

yield* harness.offerAndWait(wakeNotification);
assert.isTrue(yield* harness.hasPendingBackgroundWork);
yield* harness.runtime.interruptTurn({
providerThread: settledThread ?? harness.providerThread,
providerTurnId: harness.terminalEvents()[0]!.providerTurnId,
Expand Down Expand Up @@ -13889,7 +13891,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {

yield* harness.offerAndWait(wakeNotification);
assert.lengthOf(harness.continuationRequests, 0);
assert.isFalse(yield* harness.hasPendingBackgroundWork);
assert.isTrue(yield* harness.hasPendingBackgroundWork);

yield* Queue.offer(harness.sdkMessages, wakeAssistant);
yield* harness.awaitContinuation(1);
Expand All @@ -13902,6 +13904,8 @@ describe("ClaudeAdapterV2 background wake turns", () => {
assert.lengthOf(harness.continuationRequests, 1);
assert.lengthOf(harness.terminalEvents(), 1);
assert.isTrue(yield* harness.hasPendingBackgroundWork);
yield* harness.continuationRequests[0]!.onRunEndedWithoutStarting!();
assert.isFalse(yield* harness.hasPendingBackgroundWork);
}).pipe(
Effect.provide(
Layer.mergeAll(
Expand Down Expand Up @@ -14778,9 +14782,12 @@ describe("ClaudeAdapterV2 background wake turns", () => {
yield* harness.offerAndWait(emptyRoster);
yield* harness.offerAndWait(wakeNotification);
if (emptyLevel === "after") yield* harness.offerAndWait(emptyRoster);
// Query replacement reads the internal roster, which the exit already cleared.
assert.isFalse(yield* harness.hasPendingBackgroundWork);
assert.isTrue(
yield* harness.hasPendingBackgroundWork,
"the completed command still owns a pending native notice turn",
);
yield* harness.offerAndWait(wakeTurnInit);
assert.isTrue(yield* harness.hasPendingBackgroundWork);
yield* harness.runtime.startTurn(
makeClaudeTestTurnInput({
threadId: harness.threadId,
Expand Down Expand Up @@ -14877,6 +14884,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
[],
);
}
assert.isFalse(yield* harness.hasPendingBackgroundWork);
}).pipe(
Effect.provide(
Layer.mergeAll(
Expand Down Expand Up @@ -19095,7 +19103,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
);
yield* Queue.offer(firstProcess, turnOneResult);
yield* changes.until(() => events.some((event) => event.type === "turn.terminal"));
assert.isFalse(yield* hasPendingBackgroundWork);
assert.isTrue(yield* hasPendingBackgroundWork);

const alternateModel = CLAUDE_TEST_RESTART_MODEL_SELECTION;
const activeProviderThread = {
Expand Down Expand Up @@ -19293,7 +19301,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
yield* changes.until(
() => events.filter((event) => event.type === "turn.terminal").length === 2,
);
assert.isFalse(yield* hasPendingBackgroundWork);
assert.isTrue(yield* hasPendingBackgroundWork);
assert.lengthOf(continuationRequests, 0);

yield* Queue.offer(secondProcess, wakeResult);
Expand Down
7 changes: 7 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13103,6 +13103,13 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
return true;
}
}
for (const nativeThreadId of (yield* Ref.get(
lastProviderThreadByNativeThread,
)).keys()) {
if ((yield* owedWakeTasksForNativeThread(nativeThreadId)).length > 0) {
return true;
}
}
for (const subagent of (yield* Ref.get(sessionSubagentsByTaskId)).values()) {
if (subagent.task.status === "running") {
return true;
Expand Down
Loading