Skip to content

Commit ea048ec

Browse files
wtfsayoclaude
authored andcommitted
fix(devin): never replay a Claude signature, and pin the signature-only wire
Cognition streams Claude's thinking as a summary while the signature covers the original, so replaying the pair fails validation. Live on claude-opus-5-5 the next turn of a tool loop was refused with invalid_argument in 5 of 6 signed replays and 0 of 3 text-only ones, and dev already failed the same way intermittently (3 of 6) because it paired a single signed block. An Anthropic signature is now dropped and the thinking text replayed alone; a signature stored before its type was recorded falls back to the model being called. Through the proxy the failing tool loop then completed 6 of 6. Tests now check the signature-only turn's wire (#12 and #18, no #11) and that a signature-only turn with no text and no tool call is kept. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> (cherry picked from commit e61c7c3)
1 parent 3346f0a commit ea048ec

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

‎src/adapters/devin.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,13 @@ export function mapOcxMessagesToDevin(parsed: OcxParsedRequest): ChatHistoryItem
477477
if (system) items.push({ role: "system", content: system });
478478

479479
for (const message of parsed.context.messages) {
480-
const mapped = mapOneMessage(message);
480+
const mapped = mapOneMessage(message, parsed.modelId);
481481
if (mapped) items.push(mapped);
482482
}
483483
return items;
484484
}
485485

486-
function mapOneMessage(message: OcxMessage): ChatHistoryItem | undefined {
486+
function mapOneMessage(message: OcxMessage, modelId: string): ChatHistoryItem | undefined {
487487
if (message.role === "user" || message.role === "developer") {
488488
const content = mapOcxContentToWire(message.content);
489489
// An image with no caption text is a complete user message on its own.
@@ -495,7 +495,7 @@ function mapOneMessage(message: OcxMessage): ChatHistoryItem | undefined {
495495
if (message.role === "assistant") {
496496
const toolCalls = assistantToolCalls(message);
497497
const text = assistantText(message);
498-
const reasoning = devinAssistantReasoning(message);
498+
const reasoning = devinAssistantReasoning(message, modelId);
499499
// A turn that produced only reasoning is still worth replaying: dropping it
500500
// is what makes the next turn re-derive the same chain.
501501
if (!text && toolCalls.length === 0 && !reasoning.thinking && !reasoning.signature) return undefined;

‎src/adapters/devin/reasoning-signature.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,17 @@ export function decodeDevinSignature(stored: string): { signature: string; signa
4545
* GPT or Gemini row, where the signature is the only reasoning there is.
4646
* Any other mix (two signed blocks, a signed block beside unsigned text) has no
4747
* single attestation for the joined text, so the turn is replayed unsigned.
48+
*
49+
* An Anthropic signature is never replayed. Cognition streams Claude's thinking
50+
* as a summary while the signature covers the original, so the pair fails
51+
* validation: live on claude-opus-5-5 the next turn was refused with
52+
* `invalid_argument` in 5 of 6 signed replays and 0 of 3 text-only ones. The
53+
* text still goes back. A stored signature from before the type was recorded
54+
* falls back to the model being called.
4855
*/
4956
export function devinAssistantReasoning(
5057
message: OcxAssistantMessage,
58+
modelId = "",
5159
): { thinking?: string; signature?: string; signature_type?: string } {
5260
const blocks = message.content.filter(
5361
(part): part is Extract<typeof part, { type: "thinking" }> => part.type === "thinking",
@@ -61,7 +69,8 @@ export function devinAssistantReasoning(
6169
} else if (textBlocks.length <= 1 && signatureOnly.length === 1) {
6270
stored = signatureOnly[0]!.signature;
6371
}
64-
const decoded = stored ? decodeDevinSignature(stored) : undefined;
72+
let decoded = stored ? decodeDevinSignature(stored) : undefined;
73+
if (decoded && (decoded.signatureType ?? (/claude/i.test(modelId) ? "anthropic" : undefined)) === "anthropic") decoded = undefined;
6574
return {
6675
...(text ? { thinking: text } : {}),
6776
...(decoded ? { signature: decoded.signature } : {}),

‎tests/providers/devin-reasoning-continuation.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ describe("Devin reasoning continuation across turns", () => {
7373
expect(assistant?.thinking).toBeUndefined();
7474
expect(assistant?.signature).toBe(openaiSig);
7575
expect(assistant?.signature_type).toBe("openai");
76+
const wire = assistantPrompt(history);
77+
expect(wire.has(11)).toBe(false);
78+
expect(wire.get(12)).toBe(openaiSig);
79+
expect(wire.get(18)).toBe("openai");
80+
81+
// No text, no tool call: the signature alone still keeps the assistant turn.
82+
const bare = mapOcxMessagesToDevin(parseRequest({
83+
model: "devin/gemini-3-8-flash",
84+
input: [
85+
{ role: "user", content: [{ type: "input_text", text: "go" }] },
86+
{ type: "reasoning", id: "rs_sig", summary: [], encrypted_content: encodeReasoningEnvelope({ sig: encodeDevinSignature("AY89gemini", "gemini") }) },
87+
{ role: "user", content: [{ type: "input_text", text: "and then?" }] },
88+
],
89+
}));
90+
const kept = bare.find(m => m.role === "assistant");
91+
expect(kept?.signature).toBe("AY89gemini");
92+
expect(kept?.signature_type).toBe("gemini");
93+
expect(assistantPrompt(bare).get(12)).toBe("AY89gemini");
7694
});
7795

7896
test("two late signatures beside one thinking block cannot be paired", () => {
@@ -90,4 +108,25 @@ describe("Devin reasoning continuation across turns", () => {
90108
expect(assistant?.thinking).toBe("thought");
91109
expect(assistant?.signature).toBeUndefined();
92110
});
111+
112+
test("an Anthropic signature is never replayed, only the thinking text", () => {
113+
// Cognition streams Claude's thinking as a summary while the signature covers the
114+
// original; live, a signed replay was refused with invalid_argument 5 of 6 times.
115+
const turn = (sig: string, model: string) => mapOcxMessagesToDevin(parseRequest({
116+
model,
117+
input: [
118+
{ role: "user", content: [{ type: "input_text", text: "go" }] },
119+
{ type: "reasoning", id: "rs", summary: [], encrypted_content: encodeReasoningEnvelope({ txt: "summarised thought", sig }) },
120+
{ type: "function_call", call_id: "call_1", name: "get_time", arguments: "{}" },
121+
{ type: "function_call_output", call_id: "call_1", output: "12:00" },
122+
],
123+
})).find(m => m.role === "assistant");
124+
const typed = turn(encodeDevinSignature("EpcBClaude", "anthropic"), "devin/claude-opus-5-5");
125+
expect(typed?.thinking).toBe("summarised thought");
126+
expect(typed?.signature).toBeUndefined();
127+
expect(typed?.signature_type).toBeUndefined();
128+
// A signature stored before its type was recorded falls back to the model being called.
129+
expect(turn("EpcBClaude", "devin/claude-opus-5-5")?.signature).toBeUndefined();
130+
expect(turn(SEALED, "devin/swe-2")?.signature).toBe(SEALED);
131+
});
93132
});

0 commit comments

Comments
 (0)