fix: reuse OpenAI Responses previous_response_id across turns#22149
fix: reuse OpenAI Responses previous_response_id across turns#22149YanzheL wants to merge 4 commits intoanomalyco:devfrom
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate FoundPR #20848 — fix(opencode): wire OpenAI previous_response_id session caching This PR appears to be directly related to the current PR (#22149). According to the PR description, #20848 is explicitly listed as "follow-up implementation path for wiring OpenAI response reuse/session caching." This suggests #20848 may have been a previous attempt or partial implementation of the same feature that PR #22149 is now completing or refining. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
This definitely overlaps with #20848, but I think it is still worth considering because it makes a different tradeoff. The main difference is where continuity is sourced from:
I think that is a better fit here for a few reasons:
So I do not think this is just a duplicate with different formatting. It is a smaller message-history-based implementation of the same fix. If maintainers prefer the session-row approach in #20848, that is fine, but I wanted to make the tradeoff explicit because I think there is a legitimate reason to keep this implementation open for comparison. |
|
Codex itself doesnt use the previous response id. |
|
Fair point. My reasoning here is that OpenAI Responses documents So this PR wires the documented OpenAI response-level continuity path into opencode’s existing OpenAI Responses flow, rather than trying to mirror Codex internals exactly. |
2054a0f to
c4df761
Compare
Issue for this PR
Closes #20847
Related: #9045, #20848
Type of change
What does this PR do?
This PR fixes the OpenAI Responses continuity bug that makes long-running sessions slower over time.
Today, follow-up OpenAI Responses requests can miss
previous_response_id, which means later turns fall back to replaying more history instead of continuing the existing response chain. The practical cost is worse latency and weaker cache continuity as the conversation grows.This PR fixes that by persisting the response id in message history and reusing the latest matching one on later OpenAI follow-ups, including compaction follow-ups.
The reason this PR exists separately from #20848 is that it takes a smaller, more local approach:
So the benefit is the same user-facing fix with less persistence surface and tighter coupling to the actual request context.
How did you verify your code works?
bun typecheckbun test test/session/llm.test.tsbun test test/session/message-v2.test.tsbun test test/provider/transform.test.tsI also pushed the branch through the repo hook/typecheck path during
git push, which passed.Screenshots / recordings
N/A
Checklist