Repository navigation
fix: replay stateless OpenAI reasoning across chat turns - #30298
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee3c0bf3d6
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a378071862
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a378071862
ℹ️ 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".
a378071 to
5735acb
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5735acb36e
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review
|
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review
|
…ompts A compaction override on a different provider instance cannot resolve the chat provider's reasoning item IDs or encrypted content, so remove those parts from the compaction prompt alongside flattening provider-executed tool history.
Stamp persisted reasoning parts with the provider identity resolved for the step, and let the provider-switch sanitizer prefer that stamp over the row's current model config. Repointing a model config to another AI provider no longer replays the old provider's encrypted reasoning.
Stamp persisted reasoning parts with the model that produced them next to the provider identity, and replay OpenAI reasoning only when both match the current turn. Another model on the same provider can reject the encrypted content with invalid_encrypted_content. Unstamped parts fall back to the row's model config for both values, and a compaction override on the same provider with a different model drops OpenAI reasoning as well.
coder/fantasy d55a867 records a response as unstored when it echoes store=false, as OpenAI does for zero data retention organizations, so later requests do not reference its web search items.
Encrypted reasoning only decrypts for the OpenAI organization that produced it, which can change without a provider or model change, for example when a user adds or removes a personal API key. When a Responses request is rejected with invalid_encrypted_content before any output, retry it once without OpenAI reasoning. The advisor reads the parent transcript as text, so drop OpenAI reasoning from its snapshot. Replayed reasoning could be foreign to the advisor model, and textualized tool calls left reasoning items without their required following item.
coder/fantasy#63 now targets coder_2_33 and merges in #64 and #65, so the pin carries the merged base plus the reasoning replay changes.
coder/fantasy#63 is merged into coder_2_33, which now also carries #66, so the pin moves from the PR branch to the coder_2_33 head.
A rejected reasoning item stays in the chat history, so every later step and turn replayed it, was rejected again, and retried without any reasoning, including reasoning produced after the credential change. chatd now remembers the item IDs of rejected reasoning for each chat and leaves them out of later requests, so newer reasoning keeps replaying and only the first request after the change is rejected. The memory is per process, like the Anthropic drop_block hints.
chatd kept rejected encrypted reasoning in process memory, so a restart or another replica forgot it. The next rejection then marked every reasoning item in the prompt as rejected, including reasoning produced after the credential change, and the memory grew until the process exited. Reasoning parts now also record the credential that produced them (the deployment's or the user's personal key) and a rejection epoch, next to the provider and model. A turn on a different credential leaves out the other credential's reasoning before sending. When a provider rejects encrypted reasoning, chatd retries without reasoning as before and stamps the step's new reasoning with the provider's next epoch, so later steps on any replica leave out the older reasoning and replay the newer. A retried step that returns no reasoning records no new epoch, so the next step is rejected and retried once more.
abccede to
5fb3ce1
Compare
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5fb3ce1689
ℹ️ 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".
A rejection advanced the epoch for every model and credential on the provider, although the rejected request only replayed reasoning from its own model and credential. Switching back to another model, or from a personal key back to the deployment's credential, then dropped reasoning that was still valid. Each provider, model, and credential now has its own epochs. A retried step that returned no reasoning also lost the new epoch, so the next step replayed the rejected reasoning and was rejected again. Such a step now records the epoch on its first part.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 62b5cb532a
ℹ️ 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".
| if part.ProviderIdentity != "" { | ||
| source = stampedReasoningProvenance(part) | ||
| } | ||
| return source != target && hasOpenAIReasoningState(part) |
There was a problem hiding this comment.
Include the OpenAI transport in reasoning provenance
When an administrator changes only openai_config.use_responses_api on an existing model config, the provider UUID, model, credential, and epoch still match here, so Responses-only reasoning is retained even when the target now uses Chat Completions. Empty-summary encrypted reasoning is deliberately preserved by this change, but Chat Completions cannot replay that Responses item and may receive an empty or invalid assistant-history entry. Include the resolved transport in the provenance comparison, or drop OpenAI reasoning whenever the target transport is not Responses.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. Only the openai provider's use_responses_api override can change the transport without changing the model (Azure follows the model list, and openai-compat never uses Responses). After that switch, fantasy's Chat Completions converter (DefaultToPrompt) skips reasoning parts, and it drops an assistant message left with no text and no tool calls, with a warning.
I checked this with a throwaway test against 62b5cb5: one turn on Responses with encrypted reasoning before a tool call, then use_responses_api set to false on the same config, then another turn. That request went to /chat/completions without the reasoning item or blob, with no empty assistant entry, and the chat finished waiting with no error. Switching back to Responses replays the reasoning, which is still valid for that provider, model, and credential.
Xum replied on behalf of @ibetitsmike.
ProviderIdentity, ProviderModel, ProviderCredential, and ReasoningEpoch are stripped before API responses, so they no longer appear in the Swagger spec or the generated API reference.
…-continuity # Conflicts: # coderd/x/chatd/integration_responses_test.go # go.mod # go.sum
|
@codex review
|
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
OpenAI Responses chats default to
store=false, and chatd only replayed reasoning as anitem_reference, which needs provider-side storage. Reasoning was therefore dropped between tool steps and turns, so reasoning models lost their chain of thought mid-task.This pins coder/fantasy
coder_2_33at 6ba8681, which includes fantasy #63 (and #64, #65, and #66). #63 captures each completed reasoning item (ID,encrypted_content, summary) and replays it in full regardless ofstore. In chatd:reasoning.encrypted_content. Thestoredefault and configured includes are unchanged, and Chat Completions requests are untouched.invalid_encrypted_content), for example after the deployment's key is replaced with one from another organization, the request is retried once without reasoning, and the reasoning that step produces is saved with the provider's next rejection epoch. Epochs are kept separately for each provider, model, and credential. Later steps and turns leave out reasoning from earlier epochs, on any replica and after restarts, so only the first request after the change is rejected and newer reasoning keeps replaying. A retried step that returns no reasoning saves its epoch on its first part. The advisor's prompt never includes OpenAI reasoning, as onmain.Testing
Rebased onto main at 98332c7 as 5735acb (same tree as merging the pre-rebase head a378071 with main; older SHAs below refer to the pre-rebase history). 3c17d80 then adds the model to the reasoning record, 21156b2 pins Fantasy d55a867, which treats a response that echoes
store: falseas unstored, bf795da adds the retry and the advisor change, 7eb8b1d moves the pin to 88cffb5 (coder_2_33merged into #63; its OpenAI provider code is identical to d55a867), and f4f4073 pinscoder_2_33at 6ba8681 once #63 merged. That adds fantasy #66, which replays the Responses message phase on assistant text. abccede makes the retry remember rejected reasoning in the process. The branch was then rebased onto main at abc2fae, so every SHA above refers to the pre-rebase history. 5fb3ce1 replaces that memory with the credential and a rejection epoch saved on each reasoning part, and 62b5cb5 keeps epochs per provider, model, and credential and saves the epoch when the retried step returns no reasoning. 1057beb hides the four internal fields from the Swagger spec and API reference, and 29a705e merges main at d68b2c8. Its only conflicts were the fantasy pin (kept at 6ba8681, whosecoder_2_33history includes main's 3510552) and test imports.chatprompt,chatprovider,chatsanitize, the provider-switch sanitizer, andintegration_responses_test.gocover tool-step and durable replay, legacy and incomplete metadata, provider switches, and a web search chat switching fromstore=falsetostore=true. Integration tests also cover the retry, a later tool step after it, the next turn on a fresh server against the same database (with and without reasoning in the retried step), a personal key added mid-chat, and the advisor prompt. Red-green verified, including a config whose model is edited in place. The compaction override's model check has unit tests and UAT coverage but no integration test.go vet, targeted race tests, and the pre-commit hook (gen, fmt, lint, build) pass. Local pre-push hooks were skipped; CI covers them.invalid_encrypted_content. All 14 rejected requests were retried once without reasoning and returned 200, a different 400 was not retried, and advisor requests on the chat model, a same-provider override, and another provider carried no reasoning.storefalse and true: all 18 requests returned 200, and the gpt-5.5 requests replayed encrypted reasoning followed by assistant messages with thecommentaryandfinal_answerphases.go test ./coderd/x/chatd/... ./codersdk/passes (21 packages) on the same fantasy tree.temperatureerror that was not retried. After the first rejection, later steps and turns in that chat were never rejected again and replayed newer reasoning. A coderd restart cost one more rejection, which also dropped reasoning saved after the first one, and a second chat was unaffected. gpt-5.5 requests replayed assistant messages with the phases the model returned, withstorefalse and true.temperatureerror was not retried. After a coderd restart, and on a second coderd against the same database, the chat was not rejected again and kept replaying the reasoning saved after the rejection. Adding a personal key left out the deployment key's reasoning before sending, and removing it brought that reasoning back. A retried step without reasoning, two chats rejected at once, compaction, a model switch after a rejection, and a switch to Chat Completions and back all behaved as described.Review record
main(declined).invalid_encrypted_content, and keep OpenAI reasoning out of the advisor prompt. Both fixed in bf795da. Then: in-process memory is not enough because dogfood restarts on every merge and runs several replicas. Fixed in 5fb3ce1 with his proposed rejection epoch in chat history, plus the credential record, and tested with the next turn on a fresh server. Then: hide the internal fields from Swagger, fixed in 1057beb. Approved on 62b5cb5.store: falseis fixed in d55a867; replaying web searches that had no preceding reasoning is a pre-existing gap, tracked in chatd: OpenAI web searches without a preceding reasoning item are never replayed #30528.cliTestSSHdata race, and atest-go-pgjob timeout that also fails onmain). CI on 21156b2: all checks pass. CI on bf795da: all checks pass. CI on 7eb8b1d: all checks pass. CI on f4f4073: all checks pass. CI on abccede did not run, because the branch conflicted withmain(fix(coderd/x/chatd): return database errors from turn preparation #30492 changed the provider-switch sanitizer to return database errors). CI on 62b5cb5: all checks pass. CI on 29a705e: all checks pass.