Skip to content

Sanitize leaked tool-history markers, simplify normalization, and add managed token refresh#135

Merged
CJackHwang merged 4 commits intodevfrom
codex/add-global-token-refresh-logic
Mar 21, 2026
Merged

Sanitize leaked tool-history markers, simplify normalization, and add managed token refresh#135
CJackHwang merged 4 commits intodevfrom
codex/add-global-token-refresh-logic

Conversation

@CJackHwang
Copy link
Owner

Motivation

  • Prevent accidental leakage of synthetic tool-history markers ([TOOL_CALL_HISTORY] / [TOOL_RESULT_HISTORY]) into user-visible responses across streaming and non-streaming paths.
  • Simplify message normalization to pass tool outputs through transparently instead of injecting synthetic history markers.
  • Add managed account token refresh heuristics to avoid stale tokens for pooled accounts.

Description

  • Add sanitizeLeakedToolHistory in internal/adapter/openai/tool_history_sanitize.go to strip TOOL_CALL_HISTORY and TOOL_RESULT_HISTORY blocks using a regex and integrate it where final text or incremental chunks are emitted, including calls in chat_stream_runtime, responses_stream_runtime_core, handler_chat, and responses_handler.
  • Change streaming/process logic to drop empty results after sanitization and ensure emitted deltas use sanitized content (e.g. sanitize chunk evt.Content and parsed parts p.Text).
  • Remove synthetic injection of [TOOL_CALL_HISTORY]/[TOOL_RESULT_HISTORY] markers from message normalization and prompt-building logic by simplifying message_normalize.go and corresponding tests to treat tool outputs as passthrough content.
  • Update the tool-sieve logic to detect and swallow legacy history blocks when JSON start isn't found by adding extractToolHistoryBlock in tool_sieve_core.go and the JS equivalent in internal/js/helpers/stream-tool-sieve/sieve.js.
  • Add unit tests for sanitizer and sieve behavior in tool_history_sanitize_test.go and update existing normalization and prompt tests to reflect the passthrough model; update node sieve tests to assert swallowed history blocks.
  • Add managed token refresh state and logic to auth.Resolver in internal/auth/request.go, including ensureManagedToken, shouldForceRefresh, markTokenRefreshedNow, and clearTokenRefreshMark with a default refresh interval, and add a test verifying forced refresh behavior in request_test.go.

Testing

  • Ran Go unit tests for the adapter and auth packages (tests updated in message_normalize_test.go, prompt_build_test.go, tool_history_sanitize_test.go, and request_test.go), and they passed locally.
  • Ran the JS sieve unit tests (tests/node/stream-tool-sieve.test.js) after adding history-block coverage, and the changes passed locally.

Codex Task

@vercel
Copy link

vercel bot commented Mar 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ds2api Ready Ready Preview, Comment Mar 21, 2026 5:04pm

Copy link

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

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: 6758514c61

ℹ️ 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".

@CJackHwang CJackHwang merged commit 65312fc into dev Mar 21, 2026
3 checks passed
@CJackHwang CJackHwang deleted the codex/add-global-token-refresh-logic branch March 21, 2026 17:05
CJackHwang added a commit that referenced this pull request Mar 21, 2026
Merge pull request #135 from CJackHwang/codex/add-global-token-refresh-logic

Sanitize leaked tool-history markers, simplify normalization, and add managed token refresh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant