Conversation
a842aa4 to
46f245b
Compare
Uniquify reused call_ids after an earlier call/output pair closes so cross-turn Codex reuse stays pairable while hybrid Pro duplicate repair still dedupes within a turn. Flatten chat assistant.tool_calls into Responses function_call/output pairs on the xAI input path only, preserving OpenCode Pro chat tool history.
46f245b to
629debd
Compare
…ration Fix tool history hygiene on current main (integrates #36)
|
Thank you @jt-wang. By the time this PR was reviewed, the gateway source had already drifted from the original base, including its native relay API and shared tool-history normalization path. We preserved your tool-history contribution and original author attribution, adapted it to current main, and carried it forward in #39, which is now merged as The adaptation puts mixed Chat/Responses conversion before the common pairing/deduplication pass. It also covers duplicate pending copies, reuse after completion, alias collisions, structured outputs and reasoning, rather than maintaining a second provider-specific pairing path. Verification: the full local suite passed (1,141 pass, 7 skip, 0 fail), and all three CI jobs on #39 passed, including the actual macOS mock-install step. The built-bundle regression replays the sanitized 1,659-item captured session with the full Codex tool envelope, eight additional mixed tool rounds, Chat/Responses switching, compaction and resumption. Live provider checks were attempted but blocked by OpenCode Go credit exhaustion and Command Code's weekly quota; these are not claimed as successful inference tests. Closing this original PR as superseded by the merged #39, not because the contribution was discarded. No release version was changed and no installed gateway/local model was restarted. |
Integrate jt-wang's PR architectds#36 (629debd). The original patch predates current gateway/native relay changes. Preserve its reused-call identity and Chat-to-Responses conversion work and tests, adapting them into the current shared pairing boundary. Flatten mixed dialects before identity, pairing and deduplication. Keep completed invocations distinct, coalesce identical pending copies, avoid alias collisions, and retain structured output and visible reasoning. Reject genuinely ambiguous pending calls instead of guessing their results. Test all routed normalizers and the Chat bridge from one history fixture. Replay a sanitized 1,659-item session plus eight mixed tool rounds through the built bundle, including Chat/Responses switching and compaction. Full Windows suite: 1141 passed, 7 skipped, 0 failed (1148 total). Live Go and Command Code probes were blocked by account quota limits; no successful live-provider inference is claimed. Original-PR: architectds#36 Original-Commit: 629debd
Summary
uniquifyReusedToolCallIdsso Codex histories that reuse short call_ids (e.g.exec_command_0across turns) stay pairable instead of losing later turns during dedupe/pairing.flattenChatToolCallsToResponsesso assistanttool_callsrows paired with top-levelfunction_call_outputitems are rewritten into standard Responsesfunction_call/function_call_outputpairs before forwarding.normalizeGatewayInputahead of the existing pairing and dedupe passes.Motivation
Long Codex sessions with repeated shell/tool turns can produce histories where:
call_idappears in multiple turns (Codex reuse pattern).tool_calls.Strict upstream validators then reject the request or drop valid turns. These rewrites are provider-neutral bridge fixes — they do not change routing, profiles, or product features.
Test plan
test/gateway.test.mjsnpm testMade with Cursor