Commit 1219cb4
authored
fix: keep OpenAI reasoning responses stateful (#4557)
## Executive Summary
Built-in OpenAI/OpenAI Codex reasoning model payloads now force `store:
true` so OpenAI Responses continuations can replay reasoning/tool-call
state reliably. This prevents follow-up agent steps from failing with
missing `rs_*` reasoning item errors.
## Root Cause
OpenAI Responses reasoning/tool-call continuations can include prior
`rs_*` reasoning items in subsequent requests. The upstream Responses
payload defaults to `store: false`, which means OpenAI does not persist
those items server-side. When a later request references one of those
non-persisted item ids, OpenAI can return:
> Item with id ... not found
## Approach
When applying built-in provider payload defaults for OpenAI reasoning
models, keep the existing reasoning-effort normalization and also force
the Responses payload to be stateful:
```ts
return {
...body,
store: true,
reasoning: {
...existingReasoning,
effort,
},
}
```
The test coverage verifies that:
- OpenAI reasoning payloads get `store: true`.
- An incoming `store: false` is intentionally overridden.
- Non-OpenAI providers, such as DeepSeek, do not receive this payload
override.
## Key Invariants
- Only built-in OpenAI/OpenAI Codex reasoning model payload defaults
should force `store: true`.
- Existing payload fields should be preserved unless intentionally
overridden.
- Existing reasoning effort normalization should continue to apply.
## Non-goals
- This does not change non-OpenAI provider behavior.
- This does not implement a stateless/ZDR-compatible encrypted reasoning
replay path.
- This does not patch `@mariozechner/pi-ai`; it applies the built-in
agent payload default at our integration layer.
## Trade-offs
The alternative is to keep `store: false` and preserve/replay full
`reasoning.encrypted_content` for stateless operation. That is more
complex and unnecessary for the built-in agent default path. Using
`store: true` matches OpenAI's stateful Responses flow and directly
fixes the observed continuation failure.
## Verification
```bash
GITHUB_BASE_REF=main node scripts/check-changeset.mjs
pnpm --filter @electric-ax/agents exec vitest run test/model-catalog.test.ts
pnpm --filter @electric-ax/agents typecheck
```
Also attempted the prep command's suggested Vitest thread flag:
```bash
pnpm --filter @electric-ax/agents exec vitest run test/model-catalog.test.ts --pool-options.threads.maxThreads=2
```
That failed because this Vitest version rejects the flag as an unknown
option (`--poolOptions`). The same targeted test passes without that
unsupported flag.
## Files Changed
- `.changeset/openai-reasoning-store-true.md` — patch changeset for
`@electric-ax/agents`.
- `packages/agents/src/model-catalog.ts` — forces `store: true` for
built-in OpenAI reasoning payload defaults.
- `packages/agents/test/model-catalog.test.ts` — updates expectations
and adds regression coverage for OpenAI-only `store: true` behavior.1 parent 63f4107 commit 1219cb4
3 files changed
Lines changed: 52 additions & 0 deletions
File tree
- .changeset
- packages/agents
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
270 | 275 | | |
271 | 276 | | |
272 | 277 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| |||
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| 149 | + | |
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
152 | 194 | | |
153 | 195 | | |
154 | 196 | | |
| |||
0 commit comments