Commit 968c567
committed
fix(openai): align reasoning capture with codex official pattern
Three changes to bring fantasy's Responses API streaming into parity
with OpenAI's official codex CLI (codex-rs/codex-api/src/sse/responses.rs):
1. **Defer activeReasoning cleanup to end-of-stream.** The previous
implementation deleted the entry on `response.output_item.done`,
which meant any subsequent event for the same reasoning item (e.g.
late delta or duplicate done) silently dropped. The codex official
parser keeps items addressable until the full stream completes.
2. **Capture done.Item.Summary on output_item.done.** The streaming
summary delta path may already populate state.metadata.Summary via
reasoning_summary_text.delta events, but the done event carries the
authoritative final list. Prefer it when non-empty so partial-summary
streams are corrected to the final shape.
3. **Add response.reasoning_text.delta handler.** Some gpt-5.x reasoning
variants stream reasoning via this event channel (raw reasoning text
keyed by ItemID + ContentIndex) instead of, or in addition to,
reasoning_summary_text.delta. The official codex parser handles both;
fantasy previously only handled the summary path, dropping raw
reasoning text for affected models.
Background: empirical lenos session 35dd39ec (codex 5.4 multi-turn
audit) showed turn 1 captured encrypted_content cleanly via the
existing output_item.done capture (PR charmbracelet#71's Fix 2), but follow-up
turns and gpt-5.5 high sessions (ab022528) showed
state.metadata.EncryptedContent stuck at empty despite the API
streaming reasoning text. Investigation against the official codex CLI
source + multiple reverse-engineered backend proxies (MetaFARS/codex-relay,
hermes-agent issue #5732, satoriweb's protocol notes) confirmed:
- response.completed.output is unreliable on the Codex backend (can be
empty even when output_item.done events delivered the data).
- The reasoning_text.delta event is a separate channel from
reasoning_summary_text.delta; both must be handled to capture all
thinking text emitted by gpt-5.x reasoning variants.
This commit reverts the Fix 3 attempt (commit 7ce6466 — re-emitting
ReasoningEnd from response.completed.output) which was based on the
incorrect assumption that completed.output is the source of truth.1 parent 549fffa commit 968c567
1 file changed
Lines changed: 58 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1127 | 1127 | | |
1128 | 1128 | | |
1129 | 1129 | | |
1130 | | - | |
1131 | | - | |
1132 | | - | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
1140 | 1144 | | |
1141 | 1145 | | |
1142 | 1146 | | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
1143 | 1159 | | |
1144 | 1160 | | |
1145 | 1161 | | |
| |||
1149 | 1165 | | |
1150 | 1166 | | |
1151 | 1167 | | |
1152 | | - | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
1153 | 1173 | | |
1154 | 1174 | | |
1155 | 1175 | | |
| |||
1251 | 1271 | | |
1252 | 1272 | | |
1253 | 1273 | | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
1254 | 1301 | | |
1255 | 1302 | | |
1256 | 1303 | | |
| |||
0 commit comments