Skip to content

fix(claude): stop re-attaching the token footer as a user turn - #6714

Merged
lidge-jun merged 2 commits into
devfrom
codex/claude-footer-not-user-turn
Oct 7, 2026
Merged

lidge-jun merged 2 commits into
devfrom
codex/claude-footer-not-user-turn

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • With claudeCode.stabilizePromptCache: true, keep peeling recognized trailing <total_tokens>N tokens left</total_tokens> footers from Claude Messages system instructions, but drop them instead of re-attaching them as a trailing user message. Tool-result requests therefore no longer acquire a synthetic user turn from the token footer.
  • Preserve TaskCreate notices and their existing trailing user role. Keep fence/unmatched-text handling, stabilized instructions, cache-key derivation, opt-out behavior, and native Anthropic passthrough unchanged. The existing inbound truthiness guard already appends nothing when no notice remains.
  • Update the English opt-in guide and structure contract; register the new regression file in both layout inventories without growing layout.json (1,998 lines).

Closes #6646

Verification

  • Translation consistency follow-up at 6095abb78f6ee3bd1d4e1296a8f72702b3da4da4: updated only the stabilization paragraph in the Korean, French, Japanese, Russian, Turkish, Simplified Chinese, and Traditional Chinese guides. All seven now document removal of recognized token footers (including repeats), preservation of TaskCreate reminders in the trailing user message, and no added input message for footer-only notices. Existing runtime regression tests and both layout registrations are unchanged.
  • Fresh validation after the translation fix: bun test ./tests/claude-integration/claude-inbound-token-footer.test.ts ./tests/claude-integration/claude-inbound-cache-stabilize.test.ts ./tests/claude-integration/claude-inbound.test.ts ./tests/claude-integration/claude-native-passthrough.test.ts ./tests/test-layout.test.ts ./tests/test-layout-tooling.test.ts ./tests/ci-workflows/file-size-ratchet.test.ts — 213 pass / 0 fail across 7 files.
  • Fresh bun run typecheck and bun run structure:check — both exit 0; structure SSOT checks passed. git diff --cached --check — exit 0. wc -l scripts/test-layout/layout.json — 1,998 lines (below 2,000).
  • Fresh documentation validation: bun install --frozen-lockfile in docs-site/ — exit 0, no changes; bun run build in docs-site/ — exit 0, 561 pages and 78,111 internal links checked.
  • Red before the production fix: bun test ./tests/claude-integration/claude-inbound-token-footer.test.ts — 0 pass / 4 fail. All four failures showed the extra footer user item or footer contamination of the TaskCreate notice.
  • Green after the fix: the same command — 4 pass / 0 fail.
  • Focused validation: bun test ./tests/claude-integration/claude-inbound-token-footer.test.ts ./tests/claude-integration/claude-inbound-cache-stabilize.test.ts ./tests/claude-integration/claude-inbound.test.ts ./tests/claude-integration/claude-native-passthrough.test.ts ./tests/test-layout.test.ts ./tests/test-layout-tooling.test.ts ./tests/ci-workflows/file-size-ratchet.test.ts — 213 pass / 0 fail across 7 files, including footer-only, repeated and mixed notices, tool-result pairing, fences/unmatched text, cache keys, explicit opt-out and live local native passthrough with opt-in enabled.
  • bun run typecheck — exit 0.
  • bun run structure:check — exit 0, SSOT checks passed.
  • bun run privacy:scan — exit 0.
  • bun run --cwd docs-site build — initial exit 127 because the docs-site Astro dependency was absent. After bun install --cwd docs-site --frozen-lockfile (exit 0, no lockfile change), the same build passed: 561 pages and 78,111 internal links checked.
  • git diff --cached --check — exit 0.
  • The full local suite was not run, as directed for this bounded parallel lane. Broader and cross-platform execution remains with the coordinator's final Cross-platform CI. No hosted CI success is claimed; this lane does not wait for, rerun, or cancel workflow runs.

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. No authentication, credential, permission, dependency-version, or workflow behavior changes.

Summary by CodeRabbit

  • Bug Fixes
    • Claude prompt-cache stabilization removes recognized trailing token-count footers without adding synthetic user messages. TaskCreate reminders continue to appear in a trailing user message.
    • Native Anthropic passthrough requests remain unchanged.
  • Documentation
    • Clarified token-footer handling, TaskCreate reminders, and that stabilization remains off by default.
  • Tests
    • Added coverage for repeated footers, mixed reminders, tool-result turns, and native passthrough.

@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 7, 2026 13:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-07T13:52:22.801643Z 04b5e31 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 5025db65-e0a3-4a4c-9f01-dac5b6a28e51
📥 Commits

Reviewing files that changed from the base of the PR and between 04b5e31 and 6095abb.

📒 Files selected for processing (7)
  • docs-site/src/content/docs/fr/guides/claude-code.md
  • docs-site/src/content/docs/ja/guides/claude-code.md
  • docs-site/src/content/docs/ko/guides/claude-code.md
  • docs-site/src/content/docs/ru/guides/claude-code.md
  • docs-site/src/content/docs/tr/guides/claude-code.md
  • docs-site/src/content/docs/zh-cn/guides/claude-code.md
  • docs-site/src/content/docs/zh-tw/guides/claude-code.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

With prompt-cache stabilization enabled, recognized trailing token footers are removed from translated Claude instructions and are not added as user input. TaskCreate nudges remain available as trailing user messages. Tests cover translated requests and unchanged native passthrough.

Changes

Claude inbound prompt-cache stabilization

Layer / File(s) Summary
Drop token footers from stabilization
src/claude/inbound-cache-stabilize.ts, src/claude/inbound.ts, tests/claude-integration/claude-inbound-cache-stabilize.test.ts
Peeled token footers are no longer included in dynamicNotice. The latest recognized TaskCreate nudge remains available. Tests cover repeated footers, parsing boundaries, and nudge handling.
Verify translated input and passthrough
tests/claude-integration/claude-inbound-token-footer.test.ts, tests/claude-integration/claude-inbound-cache-stabilize.test.ts, tests/claude-integration/claude-native-passthrough.test.ts, docs-site/src/content/docs/*/guides/claude-code.md, structure/clients/claude-desktop.md, structure/data-planes/inbound-compat.md, scripts/test-layout/layout.json, tests/fixtures/test-layout-expected.json
Translation tests verify that token footers do not add input messages and that TaskCreate nudges remain trailing user messages. A native passthrough test checks that the request body is forwarded unchanged. Documentation describes the behavior, and test-layout entries register the added coverage.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 6095a

Recognized token footers no longer become translated user input, while TaskCreate notices and native passthrough retain their documented behavior. No material merge-blocking risk is evident.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (7 skipped: 7… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed [#6646] requires translated Claude Messages requests to drop recognized trailing token footers without changing prompt-cache stability. The reviewed PR summary and prior whole-PR evidence show that `s…
Out of Scope Changes check ✅ Passed The reviewed changes support [#6646]. The runtime change and regression tests address synthetic user turns from peeled token footers. The English guide, structure contract, and seven translation updat…
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: preventing the peeled Claude token footer from being re-attached as a trailing user turn.
Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (7 skipped: 7 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the bug Something isn't working label Oct 7, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 04b5e3118f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

route. Pass `"haiku"` as the model placeholder.

Set `claudeCode.stabilizePromptCache` to `true` in `config.json` to relocate supported trailing Claude harness notices from system instructions to a trailing user message on translated routes. The default is `false`. Enable it only when this role change is appropriate for your clients. It preserves fenced examples and unmatched text; native Anthropic passthrough is unchanged. The metadata-less prompt-cache key then follows stabilized instructions. This does not create conversation identity or guarantee upstream cache hits.
Set `claudeCode.stabilizePromptCache` to `true` in `config.json` to peel supported trailing Claude harness notices from system instructions on translated routes. Recognized `<total_tokens>N tokens left</total_tokens>` footers are dropped, including repeated footers. TaskCreate reminders still move to a trailing user message; if only token footers were peeled, no input message is added. The default is `false`. Enable it only when this role change is appropriate for your clients. It preserves fenced examples and unmatched text; native Anthropic passthrough is unchanged. The metadata-less prompt-cache key then follows stabilized instructions. This does not create conversation identity or guarantee upstream cache hits.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Synchronize the localized cache-stabilization documentation

The Korean, Russian, French, Traditional Chinese, Japanese, Simplified Chinese, and Turkish versions of this guide still state that every supported trailing notice is moved to a final user message. With this change, <total_tokens> footers are instead discarded, so users reading those locales receive instructions that directly contradict both the updated English page and runtime behavior. Update the corresponding localized paragraphs to distinguish dropped token footers from relocated TaskCreate reminders.

AGENTS.md reference: docs-site/AGENTS.md:L7-L10

Useful? React with 👍 / 👎.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration into dev (MAINTAINERS.md dev-only maintainer integration; not a self-approval) under the maintainer's delegated decision to proceed with truly necessary held items (2026-10-07, devlog/_plan/261007_held_items).

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.

1 participant