Skip to content

fix(codex): cross-turn reasoning cache missing for custom_tool_call and tool_search_call #258

@thedavidweng

Description

@thedavidweng

Problem

The cross-turn reasoning cache in Codex Chat history only handles function_call type items. When Codex uses custom_tool_call (e.g. apply_patch) or tool_search_call, their reasoning_content is not cached and cannot be restored in follow-up turns.

This causes upstream providers like Kimi/Moonshot and DeepSeek to reject requests with errors like reasoning_content is missing in assistant tool call message, because the proxy cannot reconstruct the reasoning context that was present in the original tool call.

Current Behavior

In src-tauri/src/proxy/providers/codex_chat_history.rs:

  • cached_function_call() (line ~439) only matches type == "function_call" and returns None for all other types
  • record_response() (line ~57) uses .filter_map(cached_function_call), so only function_call items are recorded
  • enrich_request() (line ~110) only matches "function_call" and "function_call_output", skipping "custom_tool_call", "tool_search_call", and their *_output counterparts

Expected Behavior

The reasoning cache should generalize to the full tool-call triad:

  • function_call / function_call_output (already handled)
  • custom_tool_call / custom_tool_call_output (missing)
  • tool_search_call / tool_search_output (missing)

This ensures that when Codex sends a follow-up request with previous_response_id plus a custom_tool_call_output, the missing custom_tool_call with its reasoning_content is restored from the cache, matching the existing function_call behavior.

References

The streaming layer (streaming_codex_chat.rs) and transform layer (transform_codex_chat.rs) already handle all three tool types correctly. The gap is specifically in the cross-turn history cache.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions