cxFastPrompt decoded each user message's whole text with json.Unmarshal
to take its first 160 runes for a title. A pasted log or file made all
of it again (512MB on a cold read of a year of real Codex history,
5% of everything allocated). cxTextPrompt now decodes the first ~1KB
when that settles the title. A text with nothing to unescape is read
where it is, and only the title is a string of its own. The rest is
only checked to be what json.Unmarshal takes. Whatever the head doesn't
settle is still decoded whole: a title short of 160 runes, spaces to the
end, a cut that isn't clean, or an unclosed string. title is split into
titleCut, which says whether words were left past it.
Run on mote:
- TestCxTextPromptAsTheWholeText holds it to the old path (strAt then
cxPrompt), title for title. It covers 4000 random texts of 50 to 20k
bytes with escapes, surrogates, bytes not UTF-8, space runs, Codex's
own texts and refusals late in the string, plus 16 cases made by hand.
- TestCxTextPromptDecodesItsHead: a 5.3MB prompt's title makes 5.2KB,
was 9.8MB. A plain prompt makes no allocation beyond title's own.
- Broken by hand, each red: no check of the rest, a cut at any byte, a
head that doesn't hold the title, plain without the UTF-8 or control
byte check, whole decode, no plain view.
- Cold run of real history copies, 120s: cxFastPrompt over claudeLine
(the workload's measure) 0.094, was 0.311 at v0.1.3164's base.
- gofmt; go vet ./internal/sessions for darwin, linux and windows;
go test -count=1 ./internal/sessions at the pushed head. The full
suite was not run.