Skip to content

Commit bfc56f5

Browse files
wtfsayoclaude
andcommitted
fix(devin): retry a refused Claude turn even after it streamed reasoning
Live, Cognition's refusal of a signed Claude replay usually arrives after the model has streamed its reasoning, its signature and a finish frame, and nothing visible. Only visible output (text or tool calls) now blocks the retry, so those turns are retried without the signature instead of failing. Through the proxy the stress case completed 10 of 10 (dev failed 3 of 6) and recalled the hidden number 7 of 10. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent ecd9eaa commit bfc56f5

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎src/adapters/devin.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,9 @@ export function createDevinAdapter(
663663
let produced = false;
664664
try {
665665
for await (const event of request(signedMessages)) {
666-
produced ||= event.kind === "text" || event.kind === "reasoning" || event.kind === "tool_call_start" || event.kind === "tool_call_args";
666+
// Only visible output makes a retry unsafe. Live, the refusal often lands after the
667+
// model has streamed its reasoning, its signature and a finish frame, and nothing else.
668+
produced ||= event.kind === "text" || event.kind === "tool_call_start" || event.kind === "tool_call_args";
667669
yield event;
668670
}
669671
} catch (error) {

‎tests/providers/devin-anthropic-signature-fallback.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe("Devin Anthropic signature fallback", () => {
2424
const previousFetch = globalThis.fetch;
2525
let home = "";
2626
let requests: Buffer[] = [];
27-
let responses: Array<"refuse" | "ok" | "text-then-refuse"> = [];
27+
let responses: Array<"refuse" | "ok" | "text-then-refuse" | "reasoning-then-refuse"> = [];
2828

2929
const frame = (body: Buffer, flags = 0) => {
3030
const header = Buffer.alloc(5);
@@ -71,6 +71,8 @@ describe("Devin Anthropic signature fallback", () => {
7171
const next = responses.shift() ?? "ok";
7272
const body = next === "refuse" ? refusal
7373
: next === "text-then-refuse" ? Buffer.concat([frame(encodeString(3, "partial")), refusal])
74+
// The live shape: reasoning, its signature and a finish frame, then the refusal trailer.
75+
: next === "reasoning-then-refuse" ? Buffer.concat([frame(Buffer.concat([encodeString(9, "thinking"), encodeString(10, "EpcBNew"), encodeString(21, "anthropic"), encodeVarintField(5, 2)])), refusal])
7476
: ok;
7577
return new Response(body, { headers: { "content-type": "application/connect+proto" } });
7678
}) as typeof fetch;
@@ -94,6 +96,15 @@ describe("Devin Anthropic signature fallback", () => {
9496
expect(events).toContainEqual({ type: "text_delta", text: "ok" });
9597
});
9698

99+
test("a refusal after reasoning alone is still retried", async () => {
100+
responses = ["reasoning-then-refuse", "ok"];
101+
const events = await run(encodeDevinSignature("EpcBClaude", "anthropic"), "claude-opus-5-5-medium");
102+
expect(requests).toHaveLength(2);
103+
expect(assistantSignature(requests[1]!).signature).toBeUndefined();
104+
expect(events.some(e => e.type === "error")).toBe(false);
105+
expect(events).toContainEqual({ type: "text_delta", text: "ok" });
106+
});
107+
97108
test("an accepted signed Claude turn is sent once, signature included", async () => {
98109
responses = ["ok"];
99110
await run(encodeDevinSignature("EpcBClaude", "anthropic"), "claude-opus-5-5-medium");

0 commit comments

Comments
 (0)