mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1222] [CLOSED] serve: render a Codex compaction with that conversation's tool prefix #3319
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3319
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1222
Author: @softbearlolz
Created: 10/6/2026
Status: ❌ Closed
Base:
main← Head:codex/compaction-tool-prefix-v2📝 Commits (5)
d3fef20serve: answer Codex thread-title turns without reading them6bdf6d1docs: Codex's thread-title request in the Responses API tablebc68a22serve: render a Codex compaction with that conversation's tool prefix4cb9cb0docs: rewrap the Codex compaction paragraph at 120 columns7dbbee1docs: Codex compaction numbers from a real-engine A/B on an RTX 2080 Ti📊 Changes
4 files changed (+412 additions, -8 deletions)
View changed files
📝
docs/DETAILS.md(+20 -3)📝
serve/responses.py(+121 -2)📝
serve/server.py(+28 -1)📝
serve/test_responses.py(+243 -2)📄 Description
Stacked on #1221. This branch carries its commits; only the last 3 commits are new.
Codex's local compaction (
tools: []) reuses 12,875 of 12,976 tokens (3 s) instead of reading 10,789 tokens from scratch (48 s) on main.Supersedes #924 (closed when main was rewritten).
Codex CLI's local compaction (when context fills up or on
/compact) sends the conversation again withtools: []. This server's chat template writes tool definitions at the front of the prompt, so a request without tools shares only initial system tokens with the prefix the engine is holding. The compaction prompt, the conversation at its longest, is then read again from the start.For a request marked
request_kind: "compaction", with the samesession_idandthread_idas the conversation that last rendered a prompt, and with no tools of its own, render the prompt with those tools; if the prompt is too long for the context with the kept tools, the request is rendered as sent. The output parser and the response still see the tools Codex sent, which are none.Turn metadata is extracted using
_codex_turn_metadata(req)from the base branch (#1221), reading onlyclient_metadata["x-codex-turn-metadata"]. A thread-title turn does not update the stored tool entry.I found it from the logs: I noticed the server re-reading the whole prompt on every turn (the server log showed very few tokens reused), saved the requests with my own request-dump script and compared consecutive ones. That showed the compaction request (
request_kind: "compaction",tools: []) rendering without the conversation's tool definitions, so its prompt diverged from the cached one right after the first system tokens.Measured
One RTX 2080 Ti, Qwen3.8-Flash-Next-IQ3_XXS, 262144 context, strata:v0.1.39-sm75-compact. Only this change between the two runs.
v2's Turn 1 reuse of 7,572 is left over from the previous set (Set 1) run in the same container, not part of this change; Turn 2 is the comparison.
On main, Turn 2 stripped tools and had 0 reused tokens, taking 48 s and writing a request dump miss. On Branch v2, Turn 2 restored the tool prefix, reused 12,875 tokens, and finished in 3 s without triggering a dump.
Tests
Command:
python -m unittest discover -s serve -p 'test_*.py' -t .main: 452 tests (446 passed, 6 errors)codex/thread-title-v2: 454 tests (448 passed, 6 errors)codex/compaction-tool-prefix-v2: 465 tests (459 passed, 6 errors)The 6 errors are pre-existing on
main(test_detok.HeapBpex3,test_server.LiteralControlTokensx2,test_server.LiteralThinkTagsx1). The 11 new tests (CodexCompactionx8,CodexCompactionOverHttpx3) exercise functions the basecodex/thread-title-v2does not have (prompt_tools,prompt_made), so they cannot run there; the base's behaviour is what ## Measured shows.The commits add a 'Codex's compaction' paragraph to the Codex section of
docs/DETAILS.mdand update the 'stateless' paragraph to note the prompt-cache hint kept between requests, matched by the module docstring ofserve/responses.py; the last commit replaces the paragraph's measurement with these A/B numbers.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.