Skip to content

Commit 2e3b1b9

Browse files
t3dotggclaude
andcommitted
fix(server): goal commands stop the run, clear while working, no echoes
Goal commands sent into a running turn now stop it and start next instead of failing as a steer. /goal clear and /goal pause stop only goal work. The goal banner keeps Clear while working. Claude and Codex no longer echo goal changes as assistant messages, and Codex pauses a goal it does not continue when the run ends. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1316d48 commit 2e3b1b9

11 files changed

Lines changed: 840 additions & 90 deletions

File tree

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14524,6 +14524,55 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1452414524
),
1452514525
),
1452614526
);
14527+
14528+
it.effect("keeps the CLI's goal confirmation out of the conversation", () =>
14529+
Effect.gen(function* () {
14530+
const harness = yield* makeWakeHarness;
14531+
const condition = "all tests pass";
14532+
yield* harness.runtime.startTurn(
14533+
makeClaudeTestTurnInput({
14534+
threadId: harness.threadId,
14535+
providerThread: {
14536+
...harness.providerThread,
14537+
goal: { objective: condition, status: "active", checks: 1 },
14538+
},
14539+
now: yield* DateTime.now,
14540+
attemptId: RunAttemptId.make("goal-clear-attempt"),
14541+
text: "/goal clear",
14542+
attachments: [],
14543+
}),
14544+
);
14545+
yield* Queue.offer(
14546+
harness.sdkMessages,
14547+
syntheticFrame("goal-clear", `Goal cleared: ${condition}`),
14548+
);
14549+
yield* Queue.offer(
14550+
harness.sdkMessages,
14551+
makeResultFrame({
14552+
uuid: "goal-clear-result",
14553+
result: `Goal cleared: ${condition}\n`,
14554+
numTurns: 0,
14555+
}),
14556+
);
14557+
yield* Queue.take(harness.terminalReceipts);
14558+
assert.isTrue(
14559+
harness.events.some(
14560+
(event) =>
14561+
event.type === "provider_thread.updated" && event.providerThread.goal === null,
14562+
),
14563+
);
14564+
assert.isFalse(
14565+
harness.events.some(
14566+
(event) => event.type === "message.updated" && event.message.role === "assistant",
14567+
),
14568+
);
14569+
}).pipe(
14570+
Effect.scoped,
14571+
Effect.provide(
14572+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
14573+
),
14574+
),
14575+
);
1452714576
});
1452814577
});
1452914578

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,19 @@ function nextClaudeGoal(
17231723
};
17241724
}
17251725

1726+
/** The CLI confirms a goal change as a synthetic reply; the goal row shows that change instead. */
1727+
function isClaudeGoalAcknowledgement(message: SDKMessage): boolean {
1728+
if (
1729+
message.type !== "assistant" ||
1730+
message.parent_tool_use_id !== null ||
1731+
message.message.model !== "<synthetic>"
1732+
) {
1733+
return false;
1734+
}
1735+
const text = textFromClaudeContent(message.message.content).trim();
1736+
return text.startsWith(CLAUDE_GOAL_SET_PREFIX) || text.startsWith("Goal cleared: ");
1737+
}
1738+
17261739
const providerGoalsEqual = Schema.toEquivalence(Schema.NullOr(OrchestrationV2ProviderGoal));
17271740

17281741
function normalizeClaudeResultText(text: string): string {
@@ -8895,6 +8908,13 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
88958908
});
88968909
return;
88978910
}
8911+
if (isClaudeGoalAcknowledgement(message)) {
8912+
// The CLI repeats a local command's output as the turn's result text.
8913+
if (assistantText !== null) {
8914+
context.assistant.noticeTexts.add(normalizeClaudeResultText(assistantText.text));
8915+
}
8916+
return;
8917+
}
88988918
// Claude Code echoes /compact's stdout ("Not enough messages to compact.") as a
88998919
// synthetic assistant message. The compaction item reports that outcome; it is not a
89008920
// reply.
@@ -8967,7 +8987,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
89678987
context.assistant.fallbackText.length === 0 &&
89688988
resultText !== null &&
89698989
resultText.text.length > 0 &&
8970-
!context.assistant.noticeTexts.has(resultText.text)
8990+
!context.assistant.noticeTexts.has(resultText.text) &&
8991+
!context.assistant.noticeTexts.has(normalizeClaudeResultText(resultText.text))
89718992
) {
89728993
context.assistant.fallbackText = resultText.text;
89738994
context.assistant.fallbackNativeItemId = resultText.nativeItemId;

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

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6022,6 +6022,8 @@ describe("CodexAdapterV2 post-settle continuation", () => {
60226022
[providerTurnId("goal-turn-2"), RunAttemptId.make("goal-attempt"), 2],
60236023
],
60246024
);
6025+
// The goal is set paused until its first turn starts; only the result shows.
6026+
assert.notInclude(providerGoals(harness.events), "paused");
60256027
assert.equal(providerGoals(harness.events).at(-1), "complete");
60266028
}).pipe(
60276029
Effect.scoped,
@@ -6204,6 +6206,168 @@ describe("CodexAdapterV2 post-settle continuation", () => {
62046206
),
62056207
);
62066208

6209+
it.effect("pauses a goal Codex does not continue before its run settles", () =>
6210+
Effect.gen(function* () {
6211+
const prompt = "Keep going";
6212+
const transcript = makeCodexReplayTranscript({
6213+
scenario: "goal-continuation-expired",
6214+
entries: [
6215+
...codexReplayPreamble({ nativeThreadId, nativeTurnId: "goal-turn", prompt }),
6216+
notification("goal active", "thread/goal/updated", {
6217+
threadId: nativeThreadId,
6218+
turnId: "goal-turn",
6219+
goal: codexGoal("active", 10),
6220+
}),
6221+
notification("turn done", "turn/completed", {
6222+
threadId: nativeThreadId,
6223+
turn: makeCodexReplayTurn({ id: "goal-turn", status: "completed" }),
6224+
}),
6225+
notification("goal accounted", "thread/goal/updated", {
6226+
threadId: nativeThreadId,
6227+
turnId: null,
6228+
goal: codexGoal("active", 11),
6229+
}),
6230+
...request(
6231+
4,
6232+
"thread/goal/set",
6233+
{ threadId: nativeThreadId, status: "paused" },
6234+
{ goal: codexGoal("paused", 11) },
6235+
),
6236+
],
6237+
});
6238+
const harness = yield* makeCodexReplayHarness(transcript);
6239+
yield* harness.runtime.startTurn(
6240+
makeCodexTestTurnInput({
6241+
threadId: harness.threadId,
6242+
providerThread: harness.providerThread,
6243+
now: yield* DateTime.now,
6244+
attemptId: RunAttemptId.make("goal-expired-attempt"),
6245+
text: prompt,
6246+
}),
6247+
);
6248+
yield* harness.until(() =>
6249+
harness.events.some(
6250+
(event) =>
6251+
event.type === "provider_thread.updated" &&
6252+
event.providerThread.goal?.tokensUsed === 11,
6253+
),
6254+
);
6255+
assert.lengthOf(harness.terminalEvents(), 0);
6256+
yield* TestClock.adjust("5 seconds");
6257+
yield* harness.firstTerminal;
6258+
6259+
assert.deepEqual(providerGoals(harness.events), ["active", "active", "paused"]);
6260+
assert.deepEqual(
6261+
harness.terminalEvents().map((event) => event.status),
6262+
["completed"],
6263+
);
6264+
}).pipe(
6265+
Effect.scoped,
6266+
Effect.provide(
6267+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
6268+
),
6269+
),
6270+
);
6271+
6272+
it.effect("stops a turn Codex starts while the expiry pause is in flight", () =>
6273+
Effect.gen(function* () {
6274+
const prompt = "Keep going";
6275+
const transcript = makeCodexReplayTranscript({
6276+
scenario: "goal-continuation-during-expiry",
6277+
entries: [
6278+
...codexReplayPreamble({ nativeThreadId, nativeTurnId: "goal-turn", prompt }),
6279+
notification("goal active", "thread/goal/updated", {
6280+
threadId: nativeThreadId,
6281+
turnId: "goal-turn",
6282+
goal: codexGoal("active", 10),
6283+
}),
6284+
notification("turn done", "turn/completed", {
6285+
threadId: nativeThreadId,
6286+
turn: makeCodexReplayTurn({ id: "goal-turn", status: "completed" }),
6287+
}),
6288+
notification("goal accounted", "thread/goal/updated", {
6289+
threadId: nativeThreadId,
6290+
turnId: null,
6291+
goal: codexGoal("active", 11),
6292+
}),
6293+
{
6294+
type: "expect_outbound",
6295+
label: "pause",
6296+
frame: {
6297+
id: 4,
6298+
method: "thread/goal/set",
6299+
params: { threadId: nativeThreadId, status: "paused" },
6300+
},
6301+
},
6302+
notification("goal paused", "thread/goal/updated", {
6303+
threadId: nativeThreadId,
6304+
turnId: null,
6305+
goal: codexGoal("paused", 11),
6306+
}),
6307+
notification("late continuation", "turn/started", {
6308+
threadId: nativeThreadId,
6309+
turn: makeCodexReplayTurn({ id: "goal-turn-2", status: "inProgress" }),
6310+
}),
6311+
...request(
6312+
5,
6313+
"thread/goal/set",
6314+
{ threadId: nativeThreadId, status: "paused" },
6315+
{ goal: codexGoal("paused", 11) },
6316+
),
6317+
...request(
6318+
6,
6319+
"turn/interrupt",
6320+
{ threadId: nativeThreadId, turnId: "goal-turn-2" },
6321+
{},
6322+
),
6323+
{
6324+
type: "emit_inbound",
6325+
label: "paused",
6326+
frame: { id: 4, result: { goal: codexGoal("paused", 11) } },
6327+
},
6328+
],
6329+
});
6330+
const harness = yield* makeCodexReplayHarness(transcript);
6331+
yield* harness.runtime.startTurn(
6332+
makeCodexTestTurnInput({
6333+
threadId: harness.threadId,
6334+
providerThread: harness.providerThread,
6335+
now: yield* DateTime.now,
6336+
attemptId: RunAttemptId.make("goal-race-attempt"),
6337+
text: prompt,
6338+
}),
6339+
);
6340+
yield* harness.until(() =>
6341+
harness.events.some(
6342+
(event) =>
6343+
event.type === "provider_thread.updated" &&
6344+
event.providerThread.goal?.tokensUsed === 11,
6345+
),
6346+
);
6347+
yield* TestClock.adjust("5 seconds");
6348+
yield* harness.firstTerminal;
6349+
6350+
assert.deepEqual(
6351+
harness.terminalEvents().map((event) => [event.providerTurnId, event.status]),
6352+
[
6353+
[
6354+
(yield* IdAllocator.IdAllocatorV2).derive.providerTurn({
6355+
driver: CodexAdapterV2.CODEX_DRIVER_KIND,
6356+
nativeTurnId: "goal-turn",
6357+
}),
6358+
"completed",
6359+
],
6360+
],
6361+
);
6362+
assert.equal(providerGoals(harness.events).at(-1), "paused");
6363+
}).pipe(
6364+
Effect.scoped,
6365+
Effect.provide(
6366+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
6367+
),
6368+
),
6369+
);
6370+
62076371
it.effect("pauses an active goal before Stop interrupts its turn", () =>
62086372
Effect.gen(function* () {
62096373
const prompt = "Keep going";

0 commit comments

Comments
 (0)