[PR #1222] [CLOSED] serve: render a Codex compaction with that conversation's tool prefix #3319

Closed
opened 2026-11-07 14:40:36 +07:00 by bsakaguchi · 0 comments
Owner

📋 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)

  • d3fef20 serve: answer Codex thread-title turns without reading them
  • 6bdf6d1 docs: Codex's thread-title request in the Responses API table
  • bc68a22 serve: render a Codex compaction with that conversation's tool prefix
  • 4cb9cb0 docs: rewrap the Codex compaction paragraph at 120 columns
  • 7dbbee1 docs: 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 with tools: []. 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 same session_id and thread_id as 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 only client_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.

Arm Turn 1 Prompt Turn 1 Reused / Elapsed Turn 2 Prompt Turn 2 Reused / Elapsed Turn 2 Dump
Main 12,880 0 / 58 s 10,789 0 (0.0%) / 48 s miss-20261006T142850-996 (reused=0)
Branch v2 12,880 7,572 / 24 s 12,976 12,875 (99.2%) / 3 s None (cache hit)

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 .

  • Upstream 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.HeapBpe x3, test_server.LiteralControlTokens x2, test_server.LiteralThinkTags x1). The 11 new tests (CodexCompaction x8, CodexCompactionOverHttp x3) exercise functions the base codex/thread-title-v2 does 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.md and update the 'stateless' paragraph to note the prompt-cache hint kept between requests, matched by the module docstring of serve/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.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1222 **Author:** [@softbearlolz](https://github.com/softbearlolz) **Created:** 10/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `codex/compaction-tool-prefix-v2` --- ### 📝 Commits (5) - [`d3fef20`](https://github.com/Niko1221/Strata/commit/d3fef20f31e753edb70b5313bdd662bcd7980ac8) serve: answer Codex thread-title turns without reading them - [`6bdf6d1`](https://github.com/Niko1221/Strata/commit/6bdf6d16065dce9d13e2847c86f44c599c37bae9) docs: Codex's thread-title request in the Responses API table - [`bc68a22`](https://github.com/Niko1221/Strata/commit/bc68a22eda84fc5bb07e8d965478f4a179e63720) serve: render a Codex compaction with that conversation's tool prefix - [`4cb9cb0`](https://github.com/Niko1221/Strata/commit/4cb9cb01dcd099080e6b3b3e82ffc48101736972) docs: rewrap the Codex compaction paragraph at 120 columns - [`7dbbee1`](https://github.com/Niko1221/Strata/commit/7dbbee15f232953328f83dab5344567c8fdfdc61) docs: Codex compaction numbers from a real-engine A/B on an RTX 2080 Ti ### 📊 Changes **4 files changed** (+412 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+20 -3) 📝 `serve/responses.py` (+121 -2) 📝 `serve/server.py` (+28 -1) 📝 `serve/test_responses.py` (+243 -2) </details> ### 📄 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 with `tools: []`. 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 same `session_id` and `thread_id` as 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 only `client_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. | Arm | Turn 1 Prompt | Turn 1 Reused / Elapsed | Turn 2 Prompt | Turn 2 Reused / Elapsed | Turn 2 Dump | |---|---|---|---|---|---| | Main | 12,880 | 0 / 58 s | 10,789 | 0 (0.0%) / 48 s | miss-20261006T142850-996 (reused=0) | | Branch v2 | 12,880 | 7,572 / 24 s | 12,976 | 12,875 (99.2%) / 3 s | None (cache hit) | 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 .` - Upstream `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.HeapBpe` x3, `test_server.LiteralControlTokens` x2, `test_server.LiteralThinkTags` x1). The 11 new tests (`CodexCompaction` x8, `CodexCompactionOverHttp` x3) exercise functions the base `codex/thread-title-v2` does 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.md` and update the 'stateless' paragraph to note the prompt-cache hint kept between requests, matched by the module docstring of `serve/responses.py`; the last commit replaces the paragraph's measurement with these A/B numbers. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:40:36 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3319
No description provided.