fix(claude): preserve final-answer phases across continuations #38562
OpenCUEB-QF-ZQS(GitHub profile, opens in a new tab)wants to merge 3 commits into
main fromrefs/pull/38562/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -3835,0 +3946,21 @@3946+ );3947+ }3948+ yield* harness.offerAndWait(3949+ snapshot("later-answer", "Verification finished.", "end_turn"),3950+ );3951+ }3952+ yield* harness.offerAndWait(3953+ makeResultFrame({3954+ uuid: "answer-phase-result",3955+ result: delivery === "result only" ? "The complete answer." : "Verification finished.",3956+ }),3957+ );3958+ yield* Queue.take(harness.terminalReceipts);3959+ const latestByText = new Map(3960+ harness.events.flatMap((event) =>3961+ event.type === "turn_item.updated" && event.turnItem.type === "assistant_message"3962+ ? [[event.turnItem.text, event.turnItem] as const]3963+ : [],3964+ ),3965+ );3966+ assert.equal(latestByText.get("The complete answer.")?.phase, "final_answer");@@ -3835,0 +3999,21 @@3999+ yield* harness.offerAndWait(4000+ claudeSdkFrame({4001+ type: "assistant",4002+ uuid: "unconfirmed-answer",4003+ session_id: WAKE_NATIVE_SESSION,4004+ parent_tool_use_id: null,4005+ message: {4006+ id: "unconfirmed-message",4007+ model: "claude-sonnet-4-6",4008+ stop_reason: stopReason,4009+ content: [{ type: "text", text: "Unconfirmed text." }],4010+ },4011+ }),4012+ );4013+ yield* harness.offerAndWait(makeResultFrame({ uuid: "unconfirmed-result", result: "" }));4014+ yield* Queue.take(harness.terminalReceipts);4015+ for (const event of harness.events) {4016+ if (event.type === "turn_item.updated" && event.turnItem.type === "assistant_message") {4017+ assert.equal(event.turnItem.phase, undefined);4018+ }4019+ }
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
Pushed6ca45bb
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -10914,3 +10971,8 @@1091410971 );1091510972 }1091610973 const isWakeTurnStart = isClaudeTurnStartMessage(message);10974+ // Replay only the stream frames that associate an end_turn with a root snapshot.10975+ const isAnswerMetadata =10976+ message.type === "stream_event" &&10977+ message.parent_tool_use_id == null &&10978+ (message.event.type === "message_start" ||
github-actions[bot](GitHub profile, opens in a new tab) removed labelsneeds-rebase
Sign in to join this conversation.
Walkthrough
The Claude adapter now distinguishes buffered wake frames from stream events. It tracks assistant message IDs and marks completed assistant items
final_answerwhen qualifying stream, snapshot, or result signals confirm an end turn. Tests cover completion signals, non-final stop reasons, and a buffered reply delivered in a continuation run.Changes: Claude wake buffering and final-answer tracking
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsstream_eventframes from buffered root frames. Rootmessage_startandend_turnmetadata remain wake evidence. The wake-turn test checks the buffered reply’s phase in the continuation run.apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsend_turnand a matching UUID. Tests cover late and repeated confirmation and non-final cases.Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Possibly related issues
Suggested reviewers:
juliusmarminge,yash-singh1Merge Risk:
Low · up to
6ca45Completed Claude answers are now kept as final answers across continuations, including buffered background wakes. One minor gap remains: a delayed replay of a buffered message start can report a prompt-cache expiry that is too late. This is low impact and can be followed up after merge.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the main change: the Claude adapter now keeps final-answer phases across continuations. It uses a conventional commit prefix and fits the changeset, which marks completed assistant answers as final_answer when end_turn confirms the turn.
Full details: Description check
Explanation
The description follows the template's main ideas. It explains the problem (the adapter dropped the SDK's end_turn signal, so completed answers lacked final_answer) and describes the change (native message ID matching, late metadata upgrades, snapshot reuse, wake replay). It includes a Verification section with focused test results and a full check run. Template sections are not labeled with the template's headings: there is no explicit Scope section, and the issue link is missing. It cites related reports (
#8879,#34501,#36116,#27991) but does not state a linked bug issue or explain why the fix needs no issue. The author also does not state the model and harness used, though the description says GPT-6 through OpenAI Codex. These gaps are minor, so the check passes.Finishing Touches
Generate unit tests (beta)