-
Notifications
You must be signed in to change notification settings - Fork 864
fix: enable call_id thought-signature replay for Claude Code #2281
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
Merged
lidge-jun
merged 2 commits into
lidge-jun:dev
from
Hsia97:fix/claude-code-thought-signature-replay
Aug 22, 2026
+153
−3
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,111 @@ | ||
| /** | ||
| * Regression coverage for the Claude Code thought-signature replay scope: | ||
| * | ||
| * Claude Code speaks Anthropic Messages and does not send Codex's | ||
| * `x-codex-parent-thread-id`. The server must still create a reasoning-replay | ||
| * scope for a real per-session `prompt_cache_key` (derived from | ||
| * `metadata.user_id`) so Gemini/Antigravity thought signatures can be remembered | ||
| * by call_id. The shared Desktop `prompt_cache_key` cohort must NOT get a scope. | ||
| */ | ||
| import { afterEach, describe, expect, mock, test } from "bun:test"; | ||
|
|
||
| import type { ProviderAdapter } from "../src/adapters/base"; | ||
| import type { AdapterEvent, OcxConfig, OcxParsedRequest, OcxProviderConfig } from "../src/types"; | ||
|
|
||
| const actualResolver = await import("../src/server/adapter-resolve"); | ||
|
|
||
| let adapterFactory: ((provider: OcxProviderConfig) => ProviderAdapter) | undefined; | ||
|
|
||
| mock.module("../src/server/adapter-resolve", () => ({ | ||
| ...actualResolver, | ||
| resolveAdapter(provider: OcxProviderConfig, cacheRetention?: "none" | "short" | "long") { | ||
| return adapterFactory?.(provider) ?? actualResolver.resolveAdapter(provider, cacheRetention); | ||
| }, | ||
| })); | ||
|
|
||
| const { handleResponses } = await import("../src/server/responses"); | ||
|
|
||
| afterEach(() => { | ||
| adapterFactory = undefined; | ||
| }); | ||
|
|
||
| function captureAdapter(captured: OcxParsedRequest[]): ProviderAdapter { | ||
| return { | ||
| name: "capture-replay-scope", | ||
| buildRequest: () => ({ url: "https://capture.test", method: "POST", headers: {}, body: "{}" }), | ||
| async *parseStream(): AsyncGenerator<AdapterEvent> { | ||
| yield { type: "done" }; | ||
| }, | ||
| async runTurn(parsed: OcxParsedRequest, _incoming, emit) { | ||
| captured.push(parsed); | ||
| emit({ type: "done" }); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function testConfig(): OcxConfig { | ||
| return { | ||
| port: 0, | ||
| defaultProvider: "a", | ||
| providers: { | ||
| a: { | ||
| adapter: "openai-chat", | ||
| baseUrl: "https://capture.test", | ||
| authMode: "key", | ||
| apiKey: "capture-key", | ||
| models: ["m1"], | ||
| }, | ||
| }, | ||
| } as OcxConfig; | ||
| } | ||
|
|
||
| async function drive(options: { | ||
| promptCacheKey?: string; | ||
| promptCacheKeyIsSharedCohort?: boolean; | ||
| }): Promise<OcxParsedRequest> { | ||
| const captured: OcxParsedRequest[] = []; | ||
| adapterFactory = () => captureAdapter(captured); | ||
| const body: Record<string, unknown> = { | ||
| model: "m1", | ||
| stream: true, | ||
| input: [{ type: "message", role: "user", content: [{ type: "input_text", text: "hello" }] }], | ||
| }; | ||
| if (options.promptCacheKey !== undefined) body.prompt_cache_key = options.promptCacheKey; | ||
|
|
||
| const response = await handleResponses( | ||
| new Request("http://localhost/v1/responses", { | ||
| method: "POST", | ||
| headers: { "content-type": "application/json" }, | ||
| body: JSON.stringify(body), | ||
| }), | ||
| testConfig(), | ||
| { model: "", provider: "" }, | ||
| { | ||
| inboundWire: "anthropic", | ||
| ...(options.promptCacheKeyIsSharedCohort === undefined | ||
| ? {} | ||
| : { promptCacheKeyIsSharedCohort: options.promptCacheKeyIsSharedCohort }), | ||
| }, | ||
| ); | ||
| await response.text(); | ||
| expect(captured.length).toBe(1); | ||
| return captured[0]!; | ||
| } | ||
|
|
||
| describe("Claude Code Anthropic inbound reasoning-replay scope", () => { | ||
| test("a real per-session prompt_cache_key creates a call_id replay scope", async () => { | ||
| const parsed = await drive({ promptCacheKey: "session-key-123", promptCacheKeyIsSharedCohort: false }); | ||
| expect(parsed._clientThreadId).toBeUndefined(); | ||
| expect(parsed._reasoningReplayScope?.clientThreadId).toBe("session-key-123"); | ||
| }); | ||
|
|
||
| test("the shared Desktop prompt_cache_key cohort does not create a scope", async () => { | ||
| const parsed = await drive({ promptCacheKey: "shared-cohort-key", promptCacheKeyIsSharedCohort: true }); | ||
| expect(parsed._reasoningReplayScope).toBeUndefined(); | ||
| }); | ||
|
|
||
| test("an Anthropic replay without prompt_cache_key does not create a scope", async () => { | ||
| const parsed = await drive({}); | ||
| expect(parsed._reasoningReplayScope).toBeUndefined(); | ||
| }); | ||
| }); |
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.
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.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Normalize the prompt-cache key before using it as the replay scope.
anthropicSessionKeyFromPartsinsrc/oauth/anthropic-routing.ts:573-594trims the key and hashes values longer than 128 characters. This branch only checkstrim()but stores the original value at Line 1896. Therefore," session "can produce one Anthropic session-affinity key but a different reasoning-replay cache key, which can miss athought_signatureon a later call. Long client-provided values also bypass the shared identity bound.Reuse
anthropicSessionKeyFromPartshere and use its result for_reasoningReplayScope. Add tests for whitespace, long keys, and shared-cohort exclusion.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents