Repository navigation
Commit 8e826b4
committed
fix(codex): count spawned subagent requests stamped at the fork instant
When a forked rollout's parent log is unavailable, the parser falls back
to skipping the "rewritten burst": the run of usage events Codex writes
back to back at the fork instant when it copies the parent's history.
The burst only ends at a pause of more than a second, because the
heuristic assumes the child's own turns follow the replay after a real
delay.
Some Codex VS Code rollouts (0.164.0-alpha.11.1) carry the session_meta
timestamp on every line, including the child's own token_count events.
With no pause anywhere, the burst runs to the end of the file and the
whole rollout counts as zero, even though its token_usage_record lines
have response IDs that exist in no other rollout.
Timestamps cannot separate replay from the child's own usage in such a
file, but the records can. Since TokenUsageRecord was introduced
(openai/codex#41912), Codex drops the parent's records from the history
it hands a spawned subagent ("child threads inherit model context, not
the parent's cumulative usage state"). So in a session whose session_meta
names a source.subagent.thread_spawn parent, a token_usage_record is a
request the child sent itself, and nothing after it can be replayed
history. The replay filter now ends at that record, whether it was
matching the parent prefix or skipping a rewritten burst.
User forks (thread/fork) copy every rollout item, records included, so
for them a record proves nothing and the existing timestamp handling is
unchanged. A regression test pins that double-count protection.
To carry the spawn signal, the replay plan now hands the parser a
CodexForkReplay (prefix plus whether records end the replay), and the
replay state machine moves into a small filter so the main loop can
observe records alongside usage events.
Closes #20461 parent 3297d33 commit 8e826b4
5 files changed
Lines changed: 231 additions & 80 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
299 | | - | |
| 299 | + | |
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
237 | 232 | | |
238 | 233 | | |
239 | 234 | | |
| |||
288 | 283 | | |
289 | 284 | | |
290 | 285 | | |
291 | | - | |
| 286 | + | |
292 | 287 | | |
293 | 288 | | |
294 | 289 | | |
| |||
2242 | 2237 | | |
2243 | 2238 | | |
2244 | 2239 | | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
| 2321 | + | |
| 2322 | + | |
| 2323 | + | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
2245 | 2346 | | |
2246 | 2347 | | |
2247 | 2348 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
104 | 116 | | |
105 | 117 | | |
106 | 118 | | |
| |||
205 | 217 | | |
206 | 218 | | |
207 | 219 | | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
226 | 224 | | |
227 | 225 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
245 | 231 | | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
252 | 238 | | |
253 | 239 | | |
254 | 240 | | |
| |||
258 | 244 | | |
259 | 245 | | |
260 | 246 | | |
261 | | - | |
| 247 | + | |
262 | 248 | | |
263 | 249 | | |
264 | 250 | | |
265 | | - | |
| 251 | + | |
266 | 252 | | |
267 | 253 | | |
268 | 254 | | |
| |||
271 | 257 | | |
272 | 258 | | |
273 | 259 | | |
274 | | - | |
275 | | - | |
| 260 | + | |
| 261 | + | |
276 | 262 | | |
277 | 263 | | |
278 | 264 | | |
| |||
284 | 270 | | |
285 | 271 | | |
286 | 272 | | |
287 | | - | |
| 273 | + | |
288 | 274 | | |
289 | 275 | | |
290 | | - | |
| 276 | + | |
291 | 277 | | |
292 | 278 | | |
293 | 279 | | |
294 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
295 | 326 | | |
296 | 327 | | |
297 | 328 | | |
| |||
310 | 341 | | |
311 | 342 | | |
312 | 343 | | |
313 | | - | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
314 | 350 | | |
315 | 351 | | |
316 | 352 | | |
| |||
320 | 356 | | |
321 | 357 | | |
322 | 358 | | |
323 | | - | |
| 359 | + | |
324 | 360 | | |
325 | 361 | | |
326 | 362 | | |
| |||
329 | 365 | | |
330 | 366 | | |
331 | 367 | | |
332 | | - | |
| 368 | + | |
333 | 369 | | |
334 | 370 | | |
335 | 371 | | |
| |||
0 commit comments