Repository navigation
feat(agent): compact ChatGPT context before model switches - #6979
Conversation
Generated-by: Codex
There was a problem hiding this comment.
[kabi-sol]
Automated review notice: This comment was posted by an automated review agent operated by jackwener. It is not an independent human review and does not replace one.
Update (2026-11-18): the P2 below is fixed in final raw a10ecbd730f1c6ad52334c1c36ab86f95672bc06. I reviewed the complete two-file increment from 95501d69. The planner now falls back to the sealed input-token estimate when terminal usage is absent. The unchanged independent same-hash stopped/downshift probe and its different-hash control both pass: previous-model compaction occurs, followed by a 1,439-byte target inference request. All seven selected tests passed (the five existing targeted regressions plus both independent probes; 97.92s).
Final raw merged with the landing parent produces the exact tree of landing 12083302f17796b464418770cb3decf8bfc85570. The four production files involved in this finding and the updated switch regression are unchanged from final raw through landing to current Rust 99b0dff69b1676af13a4c697c3773af8d526591a; changes in other overlapping PR files were also inspected. No new P0–P2 found in this increment. Runtime tests were run on final raw, not the full landed/current workspace. Final-raw CI still has failed checks; no green-CI certification, live-account validation, approval or merge is claimed.
The original review below remains as historical evidence for 95501d69; its P2 is no longer outstanding on the verified revisions.
Reviewed all 24 changed files at 95501d69022417e218dfb5511ebdb00771552e70. The previous-model/continuing-model separation and durable pre-turn checkpoint address the real need in #6579, but one P2 remains: a stopped request without terminal usage can bypass downshift compaction entirely (inline finding).
Independent validation: the five existing targeted Native/replay/continuation tests passed. An added real Native Host regression with equal compatibility hashes, a 128k-to-8k downshift, 108KB of prior input, and stop/resume failed: the target received an uncompressed 115,841-byte inference request without previous-model compaction. An otherwise identical different-hash control passed, issuing previous-model compaction and then a 1,439-byte target inference request. These use local HTTP/WebSocket response fixtures, not a live subscription account.
The current rust-preview integration is conflict-free; this is a merge-tree check, not an integration-suite pass. Exact-head CI run 44125574942 is failing. The Windows Markdown failure also occurs on the PR base; I have not established attribution for the other CI failures. No approval or merge performed.
| let tokens = main.closed.as_ref().and_then(|closed| { | ||
| closed | ||
| .usage | ||
| .input_tokens | ||
| .zip(closed.usage.output_tokens) | ||
| .and_then(|(a, b)| a.checked_add(b)) |
There was a problem hiding this comment.
Resolved in a10ecbd730f1c6ad52334c1c36ab86f95672bc06 (verified 2026-11-18). The caller now uses sealed input-token evidence when this optional usage is absent. The original same-hash stopped/downshift regression now passes: old-model compaction precedes a 1,439-byte target request. The repair is present in landing 12083302 and current Rust 99b0dff6; see the updated review summary for validation boundaries.
Original finding on 95501d69:
[P2] Retain a size estimate when stopped requests have no usage
A stopped/aborted Main normally has no terminal token usage, so this returns tokens: None. initial_switch_plan then treats both capacity checks as false (tokens.zip(...).is_some_and(...)). If the source and target hashes match, a smaller target gets no preflight at all; the new first-Main Codex suppression also disables the existing estimate-based compaction check. In a real Native Host stop/resume regression (128k source, 8k target, equal hashes, 108KB of prior input), the next wire request was a 115,841-byte target inference, with no old-model compaction. Changing only the hashes made the control pass and reduced target input to 1,439 bytes after old-model compaction. A real target enforcing its window will reject the first path, and the new Codex overflow branch terminates it. Use sealed request/history estimates when terminal usage is absent, and cover the equal-hash stopped downshift rather than treating unknown usage as below threshold.
|
Verified the same-hash window downshift on 95501d6 with a real ChatGPT subscription backend and a temporary Host state root. Both models reported The Host recorded exactly three requests in order: Sol inference → Sol native compaction → Astra inference. Sol’s compaction input excluded the new question. The encrypted checkpoint returned by Sol matched the ciphertext in Astra’s frozen input byte for byte. Astra’s input contained the new question and no plaintext copy of the passphrase. Astra returned the exact passphrase. The live catalog for this account returned 12 models, all with |
|
I reproduced the stopped-turn downshift issue on 95501d6 with a live ChatGPT subscription and a temporary Host state root. I stopped On 95501d6, the first request after resume was Astra inference with an estimated 9,836 input tokens. Sol skipped compaction. I tested a local fix that uses the original request’s recorded input estimate when final usage is missing. Repeating the live run produced Sol compaction followed by Astra inference with an estimated 1,501 input tokens. The ciphertext in Astra’s input matched Sol’s checkpoint byte for byte, and Astra replied I also updated the existing stop/resume regression to use equal hashes and a smaller target window. Its request-order assertion failed on 95501d6 and passed with the local fix. |
Summary
Finish the ChatGPT subscription model-switch flow from #6579 after #6654. On a new Turn (send or resume), differing known compaction hashes or an over-budget context downshift trigger native compaction with the previous model before the target model sees the new input.
The native driver owns switch planning. Engine/State persist and validate the pre-turn checkpoint independently of a pending Main, retaining both the actual producer and the intended continuing model. A qualifying, definitively failed previous-model compaction may transfer once to the target model through an explicit recovery fact. Unknown outcomes and cancellation do not grant that transfer. The target may compact the replacement again if its threshold is still reached; ordinary target context-overflow remains an error.
This covers stopped/resumed conversations and inherited fork history. It adds no background model-switch coordination, account-based replay prohibition, text-summary fallback, or catalog timer.
Fixes #6579
Verification
TMPDIR=/home/me2seeks/project cargo test --locked -p maka-agent-native --lib -- switching_compacts_with_previous_model_before_target_input replay_admission::tests continue_run_with_web_tools_reaches_the_model codex_compaction_checkpoint_satisfies_continuation_replay_boundary.git diff --check.AI use
Tool(s) and scope: Codex implemented and tested the change. A separate GPT-6.1 Sol agent at medium reasoning reviewed the implementation using first-principles and simplicity criteria; its actionable findings were addressed. Upstream Codex behavior attribution is recorded in
docs/code-origin-audit.md.Checklist
Does this PR entail a change in behavior?