chat-ui
5b882729 - Budget the whole outgoing history, not just the replayed part

Commit
62 days ago
Budget the whole outgoing history, not just the replayed part Addresses review r3702849229. The cap was only charged for turns replay could expand, so system, user, multimodal and plain assistant messages passed uncounted and a history that already filled a context window could still be handed another 100k characters on top. Charging every message as the walk reaches it is not enough on its own: the messages that cannot degrade are not all at the newest end, so a large older user turn would be counted only after every newer turn had already been granted its replay. Now computed in two passes — the floor is the request with no enrichment at all, which is the pre-replay shape, and whatever remains of the cap is spent upgrading turns newest-first, paying only the difference over that floor. A history that already exceeds the cap therefore sends exactly what it used to. Images are charged a nominal size rather than their base64 length: a data URL runs to hundreds of thousands of characters while the image costs the model on the order of a thousand tokens, so charging the encoding would let one attachment flatten every replayable turn behind it.
Author
Parents
Loading