Skip to content

feat: Alma/Codex Responses multi-turn tool replay#10

Merged
Futureppo merged 2 commits into
Futureppo:mainfrom
starlight02:feat/alma-codex-tool-replay
Jul 13, 2026
Merged

feat: Alma/Codex Responses multi-turn tool replay#10
Futureppo merged 2 commits into
Futureppo:mainfrom
starlight02:feat/alma-codex-tool-replay

Conversation

@starlight02

@starlight02 starlight02 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #9 by adding a process-local tool-call replay cache and tightening Responses ModelInput hygiene so Alma/Codex multi-turn tool results work against Grok CLI (no previous_response_id / item_reference support upstream).

What this PR does

Area Change
Cache ToolReplayCache: index completed function_call / custom_tool_call by prev-resp:{id}, optional cache:{prompt_cache_key}, and item:{item.id}
Prepare pipeline expand item_reference → re-insert missing calls for tool outputs → normalize → prune orphan outputs
ModelInput drop server-tool history (web_search_call, …); force arguments string; flatten tool output; strip null reasoning fields
Stream remember calls from output_item.done (item ids immediately; session keys on response.completed, patch empty completed.output)
Safety only tool calls are cached — never encrypted reasoning (not portable across the credential pool)

Pipeline order

expand item_reference
  → applyToolCallReplay (prev-resp / cache)
  → normalizeInputItem (ModelInput)
  → pruneOrphanToolOutputs

Out of scope

  • WebSocket / multi-provider executor changes
  • inject build-search defaults
  • header fingerprinting / 403 broadening
  • cross-account encrypted reasoning replay

Test plan

  • go test ./internal/openai ./internal/server
  • Unit: previous_response_id restore, item_reference expand, orphan prune, stream index, free-tier client model key, arguments/output harden, server-tool drop, null reasoning strip
  • Live: Alma/Codex new session — tool call → tool result → answer without re-requesting the same tool
  • Live: payload with web_search_call / reasoning.content: null history does not 422

Notes

Inspired by CLIProxyAPI xAI tool/replay + normalize path; adapted to this repo’s single-process Responses compatibility layer (tool-call subset only).

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a tool-call replay cache (ToolReplayCache) to support multi-turn continuity for OpenAI Responses clients, allowing them to continue with only previous response IDs or item references and tool outputs. It integrates this cache into the server's streaming and non-streaming response handlers, handles compatibility adjustments (such as flattening tool outputs, stringifying arguments, and stripping null reasoning fields), and adds comprehensive unit tests. The review feedback focuses on performance and type-safety improvements, specifically suggesting that flattenToolOutput return a concrete string instead of any, and recommending a lazy allocation (copy-on-write) pattern in expandItemReferences and pruneOrphanToolOutputs to avoid unnecessary slice allocations when no modifications are made.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread internal/openai/responses_compat.go Outdated
Comment thread internal/openai/tool_replay.go
Comment thread internal/openai/tool_replay.go
@Futureppo

Copy link
Copy Markdown
Owner

@codex review

@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: f18c3405d9

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

Comment thread internal/openai/tool_replay.go
@starlight02 starlight02 force-pushed the feat/alma-codex-tool-replay branch from caa3767 to 7d4496d Compare July 13, 2026 09:48
@Futureppo Futureppo merged commit aa83459 into Futureppo:main Jul 13, 2026
@starlight02 starlight02 deleted the feat/alma-codex-tool-replay branch July 14, 2026 12:57
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.

Alma/Codex multi-turn tool results fail on Responses path (previous_response_id / item_reference)

2 participants