Preserve reasoning token accounting across resume and fork (#57839)

## Why

Resuming or forking a thread loses the session flag indicating that reported token usage already includes retained reasoning. Counting that reasoning again can trigger automatic compaction too early.

## What changed

Persist `last_usage_includes_reasoning` with `TokenUsageInfo` and use it when estimating context usage. Record the flag with completed sampling and compaction usage, and mark local estimates as including reasoning. Older records without the field retain the existing accounting behavior.

## Testing

Add coverage for saved inclusive, exclusive, and legacy token counts. Extend the encrypted-reasoning compaction test to verify the compaction threshold for live, forked, and cold-resumed threads.

GitOrigin-RevId: 9f22262a693111ec0406dce11804eb4844ad8983
This commit is contained in:
andrewgu-oai
2026-10-28 21:22:06 +00:00
committed by copyberry
parent b91f2515f5
commit c62e9df39f
20 changed files with 191 additions and 91 deletions