Skip to content

fix(codex): allow passive Claude Code telemetry reminders in resolved tool tails - #218

Open
chris7iu wants to merge 1 commit into
raine:mainfrom
chris7iu:fix/codex-passive-reminder-tool-tail
Open

chris7iu wants to merge 1 commit into
raine:mainfrom
chris7iu:fix/codex-passive-reminder-tool-tail

Conversation

@chris7iu

Copy link
Copy Markdown
Contributor

Summary

  • Fixes a ~200s 11-retry stall and 503 Codex completed without producing output observed on Claude Code 2.1.270+ when Codex legitimately ends a turn with no additional output immediately after a resolved tool_result (e.g., a final SendMessage status update).
  • Claude Code 2.1.270+ appends passive runtime telemetry reminders (total_tokens_reminder, token_usage, budget_usd, output_token_usage) as <system-reminder>...</system-reminder> text blocks immediately after tool_result (either inside the tool_result user message or as a trailing user message). Previously tail_is_successful_tool_result() only ignored whitespace-only text blocks (text.trim().is_empty()), so those requests fell back to the 11-attempt full-context retry loop and returned 503.
  • Adds a strict, bounded lexical allowlist (is_ignorable_tool_tail_text / is_passive_claude_code_telemetry_reminder) and borrow-peels trailing user messages containing exclusively whitespace or those passive numeric telemetry <system-reminder> blocks.

Preserved Safety Invariants

  • Unknown <system-reminder> envelopes (PostToolUse hook: continue, SessionStart hook additional context, etc.), queued_command user messages, trailing role: "system" messages, arbitrary text outside <system-reminder> tags, nested/malformed tags, non-string/non-text blocks, and partial/unmatched/error tool_result tails remain ineligible and continue to retry / fail closed.
  • Note that Anthropic Message retains only role and content, so this is a narrow lexical allowlist rather than authenticated provenance; body.messages is borrowed rather than mutated, leaving translation and continuation state unchanged.

Verification

  • Ran in rust-baseline-20261018t033240z:1.98.0-bullseye:
    • cargo fmt --all -- --check
    • cargo clippy --locked --offline -j 64 --all-targets -- -D warnings
    • cargo test --locked --offline -j 64: all suites passed (including 979 unit tests, 2 tests in tests/codex_empty_tool_completion.rs covering positive/negative telemetry cases and stateful Auto continuation recovery, and 55 smoke tests).

… tool tails

Claude Code 2.1.270+ appends passive runtime telemetry reminders such as
<system-reminder><total_tokens>N tokens left</total_tokens></system-reminder>,
Token usage, USD budget, and Output tokens after tool_result blocks (either
inside the tool_result user message or as a trailing user message). Because
tail_is_successful_tool_result() only ignored whitespace-only text blocks,
resolved closeout tool exchanges (e.g. SendMessage) fell back to the 11-attempt
full-context retry loop (~200s) and returned HTTP 503.

Add a strict, bounded lexical allowlist for passive Claude Code numeric
telemetry <system-reminder> segments and borrow-peel trailing user messages
that contain exclusively whitespace or those passive telemetry reminders.
Unknown <system-reminder> envelopes (PostToolUse hooks, SessionStart context),
queued user commands, trailing system messages, and unmatched/error tool
results remain ineligible.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant