-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(claude): preserve Devin answers with late reasoning signatures #6299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
foxytanuki
wants to merge
6
commits into
lidge-jun:dev
from
foxytanuki:fix/claude-late-reasoning-signatures
+582
−6
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bd44e03
fix(claude): order devin signatures before messages answers
foxytanuki eb76c96
fix(claude): drain devin messages after raw-event preflight
foxytanuki 794d61a
fix(claude): preserve cancellation during devin output drain
foxytanuki fd7c9d4
Merge dev and address Devin output review feedback
foxytanuki 8ff448c
Merge current dev discovery-policy fix
foxytanuki b67d38c
docs(claude): scope Devin buffering to Messages API
foxytanuki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import type { AdapterEvent } from "../types"; | ||
| import { | ||
| isTranslatorBudgetExceededError, | ||
| releaseTranslatedEvent, | ||
| retainTranslatedEvent, | ||
| type TranslatorBudget, | ||
| } from "../lib/translator-budget"; | ||
|
|
||
| /** | ||
| * Cognition signs reasoning after text/tools. Claude Code treats a trailing empty | ||
| * thinking block as its final result, so Messages needs reasoning before content. | ||
| * Consume after raw-event preflight and drain on demand, avoiding a queue burst. | ||
| */ | ||
| export async function* orderDevinMessagesOutput( | ||
| source: AsyncIterable<AdapterEvent>, | ||
| budget: TranslatorBudget, | ||
| signal: AbortSignal, | ||
| abortProducer: () => void, | ||
| ): AsyncGenerator<AdapterEvent> { | ||
| const held: Array<AdapterEvent | undefined> = []; | ||
| let cancelled = signal.aborted; | ||
| let terminalDelivered = false; | ||
| let delivering: AdapterEvent | undefined; | ||
| const release = () => { | ||
| for (const event of held) if (event) releaseTranslatedEvent(event, budget); | ||
| held.length = 0; | ||
| if (delivering) releaseTranslatedEvent(delivering, budget); | ||
| }; | ||
| const cancel = () => { cancelled = true; release(); }; | ||
| signal.addEventListener("abort", cancel, { once: true }); | ||
| const cancelledTerminal = (event: AdapterEvent): AdapterEvent => { | ||
| if (event.type !== "done" && event.type !== "incomplete") return event; | ||
| return { type: "error", status: 499, message: "client closed request", retryable: false, | ||
| ...(event.usage ? { usage: event.usage } : {}) }; | ||
| }; | ||
| async function* drain() { | ||
| for (let index = 0; index < held.length && !cancelled; index++) { | ||
| delivering = held[index]; | ||
| held[index] = undefined; | ||
| try { | ||
| if (delivering) { | ||
| terminalDelivered = delivering.type === "done" || delivering.type === "error" || delivering.type === "incomplete"; | ||
| yield delivering; | ||
| } | ||
| } | ||
| finally { | ||
| if (delivering) releaseTranslatedEvent(delivering, budget); | ||
| delivering = undefined; | ||
| } | ||
| } | ||
| held.length = 0; | ||
| } | ||
| try { | ||
| for await (const event of source) { | ||
| const terminal = event.type === "done" || event.type === "error" || event.type === "incomplete"; | ||
| if (cancelled) { | ||
| // The adapter's cancellation terminal retains its measured usage. Client | ||
| // stream cancellation instead returns this iterator and stops consumption. | ||
| if (terminal) { yield cancelledTerminal(event); return; } | ||
| continue; | ||
| } | ||
| if (event.type === "heartbeat" || event.type === "thinking_delta" | ||
| || event.type === "thinking_signature" || event.type === "redacted_thinking" | ||
| || event.type === "reasoning_raw_delta" || event.type === "kiro_redacted_reasoning") { | ||
| yield event; | ||
| continue; | ||
| } | ||
| // Retention owns a snapshot, including nested usage, so later producer or | ||
| // consumer mutations cannot change the bytes measured by the budget. | ||
| const copy = structuredClone(event); | ||
| try { | ||
| retainTranslatedEvent(copy, budget, held.at(-1)); | ||
| held.push(copy); | ||
| } catch (error) { | ||
| if (!isTranslatorBudgetExceededError(error)) throw error; | ||
| release(); | ||
| // Stop only the producer: aborting the request signal here would let the | ||
| // hosted-search loop replace the typed overflow with a client-cancel error. | ||
| abortProducer(); | ||
| yield { type: "error", status: 413, errorType: "request_too_large", | ||
| code: "translation_buffer_limit", message: error.message }; | ||
| return; | ||
| } | ||
| if (terminal) { | ||
| yield* drain(); | ||
| if (cancelled && !terminalDelivered) yield cancelledTerminal(event); | ||
| return; | ||
| } | ||
| // Raw preflight already observed real output; feed the stream watchdog while | ||
| // the answer waits for its signature. Original heartbeats stay verbatim. | ||
| yield { type: "heartbeat" }; | ||
| } | ||
| if (!cancelled) yield* drain(); | ||
| } finally { | ||
| signal.removeEventListener("abort", cancel); | ||
| release(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: lidge-jun/opencodex
Length of output: 2152
The translated Claude Code guides do not document the new Devin/SWE-2 Messages API output-order behavior. They mention the Messages API, but they do not state that text and tool calls wait for the upstream turn to complete or that a late reasoning signature can precede the answer. Update the
ja,ko,ru, andzh-cnguides when this behavior applies to those locales.🤖 Prompt for AI Agents
Sources: Coding guidelines, Path instructions