mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
The thread metadata rewrite made persisted TokenCount events part of the observable storage path, which exposed an existing ordering issue in a few core tests. We were emitting TokenCount as soon as token usage was computed, even when the turn still had pending tool results or user-input work to finish. Split token usage bookkeeping from TokenCount event emission so the session state can still be updated immediately, while the externally visible TokenCount event is deferred until the turn is actually complete. This keeps turn history ordered around tool continuations and avoids recording a token count before the work it describes has settled. The test updates in this commit are intentionally separate from the storage rewrite: they document the corrected event ordering and remove assertions that were depending on the old premature TokenCount timing.