Repository navigation
Drop stale reasoning replay payloads before tool-call history during compaction - #1199
Merged
Kewton merged 3 commits intoDec 1, 2026
Conversation
Issue #1184: over budget, drop the stale reasoning carries older than the protected tail whole before a single tool-call run is removed, so the older content and its tool_calls/tool pairs survive. Under budget and with replay off, nothing changes. - compact.rs: when the history exceeds the budget, clear the carries older than the two most recent reasoning messages in one sweep (never one block at a time to a threshold, so the prefix cache is not missed each turn), recompute, and only then fall through to the existing Issue #1088 group removal. A single block that is not a plain reasoning.text block (reasoning.encrypted, an unknown type, or one carrying a signature/data member) disables the pass, so only group removal runs. CompactionOutcome reports how many blocks were dropped. - reasoning_replay.rs: a cleared carry keeps only its count as ReasoningShape::Compacted(n). The text is never summarized, truncated, or rewritten: either the blocks are all there or only their count remains. - lm_studio.rs: provider_request gains reasoning_replay_compacted_blocks, the sum over the sent messages, at both the batch and SSE emit sites, only when replay is on and the count is at least one. Zero and replay off add no field. - fixed_identifiers.rs / reasoning_replay_field_keys.rs: register the field as a per-event schema key of provider_request. - tests/compaction_reasoning_replay.rs: end-to-end two-point measurement over a loopback fake for (a) the runs surviving with the count reported, (b) a foreign block reporting nothing, (c) an under-budget and replay-off send unchanged, and (d) a second pass not compacting again, in both non-SSE and SSE. Two-point measurement (each fails on 21b70b2 behavior, passes here): - non-SSE stale clear: a_the_batch_send_reports_compacted_blocks_and_keeps_the_tool_call_runs; - SSE stale clear: a_sse_the_stream_send_reports_compacted_blocks_and_keeps_the_tool_call_runs; - no re-compaction: d_after_clearing_reasoning_the_next_turn_does_not_compact_again. With only the emit disabled, both (a) tests fail at the event assertion and (d) still passes; (b)/(c) stay green; so the tests measure the field at both sites. 判断: the contract asks for the count on ReasoningCarry and warns to STOP if a ConversationMessage field is needed. A ReasoningCarry struct field would break full struct literals in out-of-scope src/provider_call.rs and src/providers/openai_chat_completions_stream.rs, so the count rides on a new ReasoningShape::Compacted(usize) variant instead: every ReasoningShape match outside this issue's files has a wildcard arm, and ConversationMessage gains no field (state.rs is untouched). STOP: the corpus field list cannot be finished within scope. Adding "reasoning_replay_compacted_blocks" to tests/corpus/apps/openrouter-reasoning-replay/expectations.toml makes corpus_regression assert it also appears in fixtures/cases.json (assert_fixture_contains), and that fixture is not in scope.allow; editing it fails the scope gate. expectations.toml and cases.json are left unchanged so the corpus gate stays green and out-of-scope changes remain zero. Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Issue #1184: add reasoning_replay_compacted_blocks to the corpus field list and a synthetic case that shows it, so the provider_request field the compaction pass reports is documented alongside the others. Existing block and case values are unchanged; the new case is appended after them and keeps the ordered ids. - cases.json: event_fields gains reasoning_replay_compacted_blocks, and a new "compaction-drops-stale-reasoning" case records the budget overrun, the protected tail of two, the cleared block count, and that the oldest tool pair stays. - expectations.toml: fixture_contains lists the new field name, mirroring the fixture. Two-point measurement (corpus_regression): - With only expectations.toml changed, corpus_regression fails: "fixture fixtures/cases.json missing expected text reasoning_replay_compacted_blocks". - With the field and case added to cases.json, corpus_regression passes. Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Review fixes for Issue #1184. 1. The stale-reasoning pass now runs only when the resolved replay setting is on. compact_and_record reads it from the Config it is handed (config.field_sources.compatible_reasoning_replay.enabled, the same source the client uses), and compact_if_needed_for carries it into compact.rs. The bare compact_if_needed (no Config) delegates with replay off, so out-of-scope callers keep the pre-#1184 behavior. A replay-on history compacted and sent with replay off is therefore compacted exactly as before: the oldest runs are removed by group removal, not kept by a reasoning clear. loop_run.rs is unchanged. 2. The (d) test now traverses a real next turn: after the bulk clear it takes a reply with reasoning and its tool result from the loopback provider, appends them, and asserts the next compaction clears nothing. 1700-char blocks leave headroom (~3650/4000) so the next turn fits, stated in the test. A further test shows a next turn that pushes the history back over budget clears the now-stale carry again, as specified. 3. The corpus case now states the same input as the batch test: four reasoning assistants, 1900-char blocks, a 1000-token budget, a protected tail of two, two cleared blocks, and an event value of two. Existing case values are unchanged. Two-point measurement: - replay-off body: e_replay_off_compaction_sends_the_base_body fails with the replay gate removed (compacted_blocks is 2, call-0 kept) and passes with the gate; the Config-driven path asserts the same through compact_and_record. - (d) next turn: fails if the first bulk clear does not happen, passes with the real next turn added. Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
6 tasks
Kewton
deleted the
feature/issue-1184-prioritize-dropping-stale-reasoning-replay-paylo
branch
December 2, 2026 00:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #1184
During compaction, stale reasoning replay payloads are dropped before tool-call history is removed.
src/minimal_loop/compact.rs,src/providers/reasoning_replay.rs,src/providers/lm_studio.rs: the replay decision uses the same resolved value as the client; with replay off, the request body matches the base.tests/compaction_reasoning_replay.rs(two-point checks fail on the base), the openrouter-reasoning-replay corpus case (new field only), field-key test updates.loop_run.rs, state, golden files, manifests and guardrail baselines are unchanged.Verification: verify run 864 exit 0 (17/17), Linux clippy 0 warnings, codex APPROVE on re-review. No merge-tree conflict with develop cc6e9b7.
🤖 Generated with Claude Code