Skip to content

fix(claude): stabilize Responses instructions for Muse/Go prompt cache - #2

Closed
Warexpor wants to merge 7 commits into
devfrom
cursor/feat-claude-instructions-cache-stabilize-915b
Closed

fix(claude): stabilize Responses instructions for Muse/Go prompt cache#2
Warexpor wants to merge 7 commits into
devfrom
cursor/feat-claude-instructions-cache-stabilize-915b

Conversation

@Warexpor

@Warexpor Warexpor commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Claude Code through OpenCodex puts system text into OpenAI Responses instructions. Growing <total_tokens>N tokens left</total_tokens> / TaskCreate footers churn that prefix and collapse Muse/Go prompt-cache hit rates.
  • Relocation is opt-in at the translator: stabilizePromptCache?: boolean defaults to false. Ordinary Anthropic callers with that exact unfenced suffix keep instructions and input unchanged. The Claude Code /v1/messages inbound path passes true. This is not inferred from metadata.user_id.
  • Matcher stays the real harness shape (TRAILING_TOTAL_RE for <total_tokens>\d+\s+tokens left</total_tokens>, exact TaskCreate paragraph, trailing unfenced only, unclosed fence through EOF). No match returns the original string byte-for-byte.
  • Desktop prompt_cache_key fallback hashes raw systemParts outside opt-in (previous key). When opted in, that fallback hashes the same string as body.instructions after stabilize.

SOCKS5 / Go session-header work is intentionally out of scope. Related Anthropic thinking-replay issue lidge-jun#3719 stays open (link only).

Upstream review PR: lidge-jun#4052

Verification

  • bun test tests/claude-integration/claude-inbound-cache-stabilize.test.ts tests/claude-integration/claude-inbound.test.ts75 pass
  • bun run typecheck — pass

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.
Open in Web Open in Cursor 

Strip growing <total_tokens> and TaskCreate footers from Claude Code
system text before it becomes Responses instructions, and reattach the
latest notice as a trailing input message so Muse/Go prefix cache can
hit. Paper and measured rates live under docs/claude-instructions-cache-stabilize/.

Co-authored-by: Warexpor <warexpor@gmail.com>
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Sep 8, 2026
cursoragent and others added 6 commits September 8, 2026 18:15
The Claude Code path still uses metadata.user_id. Desktop has no session
id, so the fallback key now fingerprints the cacheable prefix instead of
raw systemParts that still contain <total_tokens> / TaskCreate footers.

Co-authored-by: Warexpor <warexpor@gmail.com>
Restrict strip to standalone integer <total_tokens> footer lines and
the exact Claude Code reminder paragraph so inline docs of those tags
or TaskCreate stay in instructions.

Co-authored-by: Warexpor <warexpor@gmail.com>
Identify Claude Code <total_tokens> / TaskCreate notices as a trailing
suffix outside markdown fences. No match returns the original system
text byte-for-byte so fenced examples and whitespace-only prompts stay
untouched. Translator regressions cover those no-ops.

Co-authored-by: Warexpor <warexpor@gmail.com>
Relocation runs only when metadata.user_id identifies Claude Code.
Unmatched fence openers cover through EOF so an unfinished fenced
example plus a numeric total_tokens line is not a harness suffix.
Desktop keeps the raw systemParts cache-key fallback.

Co-authored-by: Warexpor <warexpor@gmail.com>
Claude Code writes <total_tokens>N tokens left</total_tokens>, not a
bare integer. Digit-only matching left the harness suffix in
instructions and collapsed Muse/Go hit rate to baseline. Match that
shape as a trailing unfenced suffix, run peel on every inbound
translation (no-op when absent), and hash Desktop prompt_cache_key from
the same string used for instructions.

Co-authored-by: Warexpor <warexpor@gmail.com>
Keep the real N tokens left matcher and unclosed-fence-to-EOF handling.
Relocation is now stabilizePromptCache (default false) on the translator,
not metadata.user_id. Ordinary callers keep a matching suffix in
instructions; /v1/messages passes true. Desktop prompt_cache_key hashes
raw systemParts outside opt-in and the instructions string when opted in.

Co-authored-by: Warexpor <warexpor@gmail.com>
@cursor

cursor Bot commented Sep 11, 2026

Copy link
Copy Markdown

@Ingwannu addressed on 0847e21.

Kept the real N tokens left matcher, TaskCreate paragraph, trailing-unfenced-only peel, and unclosed-fence-to-EOF. Relocation is now explicitly opt-in:

  • stabilizePromptCache?: boolean on anthropicToResponsesTranslation / translateAnthropicRequest (default false)
  • ordinary caller with that exact unfenced suffix keeps instructions and input unchanged
  • Claude Code /v1/messages inbound passes true; not inferred from metadata.user_id
  • Desktop prompt_cache_key: raw systemParts outside opt-in; opted-in hashes the same string as body.instructions

Verification: bun test inbound-cache-stabilize + inbound — 75 pass; bun run typecheck running. lidge-jun#3719 left open.

@cursor

cursor Bot commented Sep 11, 2026

Copy link
Copy Markdown

@Ingwannu addressed on 0847e21 (same head as lidge-jun#4052).

Kept the real N tokens left matcher, TaskCreate paragraph, trailing-unfenced-only peel, and unclosed-fence-to-EOF. Relocation is now explicitly opt-in:

  • stabilizePromptCache?: boolean on anthropicToResponsesTranslation / translateAnthropicRequest (default false)
  • ordinary caller with that exact unfenced suffix keeps instructions and input unchanged
  • Claude Code /v1/messages inbound passes true; not inferred from metadata.user_id
  • Desktop prompt_cache_key: raw systemParts outside opt-in; opted-in hashes the same string as body.instructions

Verification: inbound-cache-stabilize + inbound — 75 pass; bun run typecheck pass. lidge-jun#3719 left open.

@Warexpor

Copy link
Copy Markdown
Owner Author

Duplicate of upstream lidge-jun#4052 — same head branch . Closing to avoid split review.

@Warexpor Warexpor closed this Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants