Skip to content

Commit 75d4b52

Browse files
authored
Merge branch 'main' into feat/table-copy-as-html-2
2 parents 1f8e1dc + 2b65ffb commit 75d4b52

4 files changed

Lines changed: 55 additions & 19 deletions

File tree

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

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8728,13 +8728,23 @@ describe("ClaudeAdapterV2 background wake turns", () => {
87288728
it.effect.each([
87298729
{ outcome: "result", turnStatus: "completed", itemStatus: "failed" },
87308730
{ outcome: "interrupt", turnStatus: "interrupted", itemStatus: "interrupted" },
8731+
{ outcome: "interrupt_aborted", turnStatus: "interrupted", itemStatus: "interrupted" },
87318732
{ outcome: "query_exit", turnStatus: "failed", itemStatus: "failed" },
87328733
] as const)(
87338734
"settles unfinished compaction before the $outcome terminal receipt",
87348735
({ outcome, turnStatus, itemStatus }) =>
87358736
Effect.gen(function* () {
8737+
const interruptSent = yield* Deferred.make<void>();
8738+
const abortReported = yield* Deferred.make<void>();
87368739
const harness = yield* makeWakeHarnessWithOptions({
87378740
close: (sdkMessages) => Queue.shutdown(sdkMessages),
8741+
...(outcome === "interrupt_aborted"
8742+
? {
8743+
interrupt: Deferred.succeed(interruptSent, undefined).pipe(
8744+
Effect.andThen(Deferred.await(abortReported)),
8745+
),
8746+
}
8747+
: {}),
87388748
});
87398749
const attemptId = RunAttemptId.make(`claude-compact-${outcome}`);
87408750
yield* harness.runtime.startTurn(
@@ -8758,15 +8768,34 @@ describe("ClaudeAdapterV2 background wake turns", () => {
87588768
);
87598769
if (outcome === "query_exit") {
87608770
yield* Queue.shutdown(harness.sdkMessages);
8761-
} else if (outcome === "interrupt") {
8771+
} else if (outcome === "interrupt" || outcome === "interrupt_aborted") {
87628772
const idAllocator = yield* IdAllocator.IdAllocatorV2;
8763-
yield* harness.runtime.interruptTurn({
8764-
providerThread: harness.providerThread,
8765-
providerTurnId: idAllocator.derive.providerTurn({
8766-
driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
8767-
nativeTurnId: `turn:${attemptId}`,
8768-
}),
8769-
});
8773+
const interrupting = yield* harness.runtime
8774+
.interruptTurn({
8775+
providerThread: harness.providerThread,
8776+
providerTurnId: idAllocator.derive.providerTurn({
8777+
driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
8778+
nativeTurnId: `turn:${attemptId}`,
8779+
}),
8780+
})
8781+
.pipe(Effect.forkScoped);
8782+
if (outcome === "interrupt_aborted") {
8783+
// The CLI reports the aborted compaction as failed.
8784+
yield* Deferred.await(interruptSent);
8785+
yield* harness.offerAndWait(
8786+
claudeSdkFrame({
8787+
type: "system",
8788+
subtype: "status",
8789+
status: null,
8790+
compact_result: "failed",
8791+
compact_error: "API Error: Request was aborted.",
8792+
uuid: "00000000-0000-4000-8000-000000000223",
8793+
session_id: WAKE_NATIVE_SESSION,
8794+
}),
8795+
);
8796+
yield* Deferred.succeed(abortReported, undefined);
8797+
}
8798+
yield* Fiber.join(interrupting);
87708799
} else {
87718800
yield* Queue.offer(
87728801
harness.sdkMessages,
@@ -8787,6 +8816,11 @@ describe("ClaudeAdapterV2 background wake turns", () => {
87878816
const [running, settled] = updates;
87888817
assert.equal(running?.status, "running");
87898818
assert.equal(settled?.status, itemStatus);
8819+
assert.equal(
8820+
settled?.title,
8821+
itemStatus === "failed" ? "Context compaction failed" : "Context compaction stopped",
8822+
);
8823+
if (outcome === "interrupt_aborted") assert.isUndefined(settled?.summary);
87908824
assert.equal(settled?.id, running?.id);
87918825
assert.equal(settled?.ordinal, running?.ordinal);
87928826
assert.deepEqual(settled?.startedAt, running?.startedAt);

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9179,9 +9179,12 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
91799179
(message.compact_result !== undefined ||
91809180
(message.status === null && message.permissionMode === undefined))
91819181
) {
9182+
// The CLI reports a compaction it aborted for our interrupt as failed.
9183+
const failed =
9184+
message.compact_result === "failed" &&
9185+
!(yield* Ref.get(interruptedTurns)).has(context.providerTurnId);
91829186
if (message.compact_result !== undefined) {
9183-
context.compactionFailure =
9184-
message.compact_result === "failed" ? { message: message.compact_error } : null;
9187+
context.compactionFailure = failed ? { message: message.compact_error } : null;
91859188
}
91869189
if (context.compaction?.status === "running") {
91879190
const now = yield* DateTime.now;
@@ -9190,18 +9193,16 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
91909193
status:
91919194
message.compact_result === "success"
91929195
? "completed"
9193-
: message.compact_result === "failed"
9196+
: failed
91949197
? "failed"
91959198
: "interrupted",
91969199
title:
91979200
message.compact_result === "success"
91989201
? "Context compacted"
9199-
: message.compact_result === "failed"
9202+
: failed
92009203
? "Context compaction failed"
92019204
: "Context compaction stopped",
9202-
...(message.compact_result === "failed" && message.compact_error
9203-
? { summary: message.compact_error }
9204-
: {}),
9205+
...(failed && message.compact_error ? { summary: message.compact_error } : {}),
92059206
completedAt: now,
92069207
updatedAt: now,
92079208
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8700,7 +8700,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
87008700
nativeThreadId,
87018701
nativeTurnId: "goal-turn-1",
87028702
prompt: objective,
8703-
sentPrompt: `Start working toward this goal: ${objective}`,
8703+
sentPrompt: `This thread's goal is already set. Do not call create_goal. Start working on it now: ${objective}`,
87048704
}).slice(5),
87058705
5,
87068706
),
@@ -8840,7 +8840,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
88408840
nativeThreadId,
88418841
nativeTurnId: "goal-turn-limit",
88428842
prompt: atLimit,
8843-
sentPrompt: `Start working toward this goal: ${atLimit}`,
8843+
sentPrompt: `This thread's goal is already set. Do not call create_goal. Start working on it now: ${atLimit}`,
88448844
}).slice(5),
88458845
5,
88468846
),

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6976,15 +6976,16 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
69766976
const activation = { stopped: false };
69776977
goalActivations.set(threadId, activation);
69786978
yield* Effect.gen(function* () {
6979-
// A bare objective reads like a statement, so the model echoes it back.
6979+
// A bare objective gets echoed back, and "start this goal" gets a
6980+
// create_goal call that Codex rejects because the goal already exists.
69806981
yield* startNativeTurn(
69816982
turnInput,
69826983
command.type === "set"
69836984
? yield* toCodexInput({
69846985
...turnInput,
69856986
message: {
69866987
...turnInput.message,
6987-
text: `Start working toward this goal: ${command.objective}`,
6988+
text: `This thread's goal is already set. Do not call create_goal. Start working on it now: ${command.objective}`,
69886989
},
69896990
})
69906991
: [],

0 commit comments

Comments
 (0)