Skip to content

Commit d3471b1

Browse files
fix(server): no unconfirmed-steer notice on a CLI that never echoes prompt uuids
A CLI that never echoes prompt uuids leaves every steer unread, so Stop warned about steers Claude had answered. Each unread steer now remembers its live query, and the notice is emitted only when that query has proven it echoes (early or result_only). AI-assisted; verified with the tests and tools listed above.
1 parent d7ae4b9 commit d3471b1

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4872,15 +4872,30 @@ describe("ClaudeAdapterV2 background wake turns", () => {
48724872
it.effect.each([
48734873
{
48744874
readBy: "none",
4875+
echoes: true,
48754876
title: "warns that a steer Claude never read before Stop was not delivered",
48764877
},
4877-
{ readBy: "assistant", title: "does not warn about a steer Claude read before Stop" },
4878-
{ readBy: "stream", title: "does not warn about a steer a stream event echoed before Stop" },
4878+
{
4879+
readBy: "none",
4880+
echoes: false,
4881+
title: "does not warn about a steer on a CLI that never echoes prompt uuids",
4882+
},
4883+
{
4884+
readBy: "assistant",
4885+
echoes: true,
4886+
title: "does not warn about a steer Claude read before Stop",
4887+
},
4888+
{
4889+
readBy: "stream",
4890+
echoes: true,
4891+
title: "does not warn about a steer a stream event echoed before Stop",
4892+
},
48794893
{
48804894
readBy: "result",
4895+
echoes: true,
48814896
title: "does not warn about a steer only a steering result echoed before Stop",
48824897
},
4883-
] as const)("$title", ({ readBy }) =>
4898+
] as const)("$title", ({ readBy, echoes }) =>
48844899
Effect.gen(function* () {
48854900
const harness = yield* makeWakeHarnessWithOptions({
48864901
close: (sdkMessages) => Queue.shutdown(sdkMessages),
@@ -4906,6 +4921,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
49064921
uuid: "00000000-0000-4000-8000-000000015701",
49074922
session_id: WAKE_NATIVE_SESSION,
49084923
parent_tool_use_id: null,
4924+
...(echoes ? { user_message_uuids: [harness.promptUuid(0)] } : {}),
49094925
message: {
49104926
id: "msg_unread_steer_bash",
49114927
type: "message",
@@ -5010,7 +5026,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
50105026
const undelivered = notices.find((message) =>
50115027
/not (have )?(been )?delivered|never (reached|delivered)/i.test(message ?? ""),
50125028
);
5013-
if (readBy !== "none") {
5029+
if (readBy !== "none" || !echoes) {
50145030
assert.isUndefined(undelivered);
50155031
return;
50165032
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4392,7 +4392,10 @@ interface ActiveClaudeTurnContext {
43924392
// Steer text by prompt uuid until a reply frame echoes the uuid. A steer the
43934393
// CLI still holds in its queue (behind a foreground tool call) is dropped
43944394
// when Stop closes the query, so the turn says which ones may not have arrived.
4395-
readonly unreadSteers: Map<string, string>;
4395+
readonly unreadSteers: Map<
4396+
string,
4397+
{ readonly text: string; readonly liveQuery: ClaudeLiveQueryContext }
4398+
>;
43964399
// Set as finalization starts: a steer admitted later would miss the
43974400
// unread-steer snapshot, so it fails and the orchestrator follows up instead.
43984401
steersClosed: boolean;
@@ -8116,7 +8119,14 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
81168119
const unreadSteers = [...input.context.unreadSteers];
81178120
input.context.unreadSteers.clear();
81188121
if (input.status === "interrupted") {
8119-
for (const [uuid, text] of unreadSteers) {
8122+
for (const [uuid, { text, liveQuery }] of unreadSteers) {
8123+
// Only a CLI proven to echo prompt uuids can leave a steer unconfirmed.
8124+
if (
8125+
liveQuery.promptEchoMode !== "early" &&
8126+
liveQuery.promptEchoMode !== "result_only"
8127+
) {
8128+
continue;
8129+
}
81208130
const nativeItemId = `unread-steer:${uuid}`;
81218131
const notice = `Claude did not confirm reading your steer before Stop. It may not have been delivered. Resend it if needed: "${text}"`;
81228132
yield* emitProviderEvent({
@@ -11808,7 +11818,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1180811818
detail: `Claude provider turn ${turnInput.providerTurnId} ended before the steer was sent.`,
1180911819
});
1181011820
}
11811-
currentTurn.unreadSteers.set(steerUuid, turnInput.message.text);
11821+
currentTurn.unreadSteers.set(steerUuid, {
11822+
text: turnInput.message.text,
11823+
liveQuery: existing,
11824+
});
1181211825
yield* Ref.update(steeredTurns, (current) => {
1181311826
const next = new Set(current);
1181411827
next.add(turnInput.providerTurnId);

0 commit comments

Comments
 (0)