[GH-ISSUE #4744] [Other] compaction policy: two fixed ratios decide when it runs, and the checkpoint is capped by the same headroom it protects (2,867 tokens at a 32K window) with truncation as a hard failure #2177

Open
opened 2026-11-04 01:57:16 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @xvcezrqpbxtpzblrt on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4744

2026-11-06 更新:v0.2.10 / v0.2.11 发布说明均未点名本 issue。便于处理起见,本 issue 主要跟踪:触发线与保留率固定、检查点上限与头部保护同源、截断即失败。图片卸载与字符预算两项如需单独排队,请您指出。


Area

[Other] (the agent runtime configuration Strata ships; the policy itself lives in the bundled compaction plugin)

Desktop app, Terminal or source?

Desktop app (Windows), with the arithmetic read from apps/host/server/agent/profile.mjs and apps/host/server/agent/preset.mjs at tag v0.2.8, and from the compaction plugin installed with the app.

What happened

Long sessions lose their thread faster than the numbers should allow. Compaction today is driven by two fixed fractions and one fixed band, and the size of the replacement summary is tied to the same number that protects the window — so a condensation is forced to be tiny, and if it is not tiny enough it is rejected. The retention rule is recency only, and every pass re-summarises the checkpoint from the previous pass, with nothing bounding the drift.

The chain, with numbers that follow from the shipped code (not measurements):

  • Trigger: the compaction plugin listens only between agent steps (installed harness/node_modules/@deepseek-ai/dsh-compaction-basic/lib/index.js:839, agent/pre-step), and the threshold is floor(min(contextWindow * thresholdRatio, contextWindow - reservedCompletionTokens - headroomTokens)) (:130-132) with DEFAULT_THRESHOLD_RATIO = .8 (:15).
  • Strata's only override is headroomTokens, per model, from apps/host/server/agent/profile.mjs:151-153: max(512, min(65536, floor((context - outputBudget) * 0.125))), pushed at profile.mjs:214, :244, :286. It never sets retainRatio, retainTokens or maxTokens.
  • The reply reservation is localOutputBudget = max(4096, min(32768, floor(context * 0.3))) (profile.mjs:137-143).
  • Consequence: the checkpoint's own output cap defaults to the headroom (dsh-compaction-basic/.../index.js:64 and :71 — "maxTokens … from headroomTokens"). The number that protects the window is also the ceiling on the summary that has to replace the older history.

Computed for the three windows a local user actually picks (from the two formulas above):

context reply reserve headroom = checkpoint cap compaction starts at verbatim tail kept history replaced forced ratio
32,768 9,830 2,867 20,071 (61%) 3,670 ≈16,401 ≈5.7 : 1
65,536 19,660 5,734 40,142 (61%) 7,340 ≈32,802 ≈5.7 : 1
393,216 (this PC, IQ3_S) 32,768 45,056 314,572 (80%) 57,671 ≈256,901 ≈5.7 : 1
  • A checkpoint that hits the cap is treated as broken: "summarization truncated at the token cap (incomplete checkpoint)" (dsh-compaction-basic/.../index.js:363); after one retry the turn continues uncompacted with a warning, so a 32K session that needs to shed 16K tokens of history can end up shedding nothing.
  • Retention is recency only: DEFAULT_RETAIN_RATIO = .16 (:17), retainTokens = floor((contextWindow - reservedCompletionTokens) * retainRatio) (:133), and the tail is accumulated newest-first (:416-422). Nothing scores importance, and nothing deduplicates: repeated tool output that never changed is kept, while an early decision the whole task depends on is dropped.
  • Compaction is one-shot per pass over everything older than the tail: the replacement starts at the first non-system node (:415, firstIdx = 1), so the previous checkpoint sits inside the next range and is merged only because the prompt asks the model to fold it in. Lossy re-summarisation of a lossy summary is unbounded.
  • Tool output is pruned only after pressure has already arrived, by characters: the pruner is registered with thresholdChars: 8192, headChars: 4096, tailChars: 1024 (apps/host/server/agent/preset.mjs:77) and runs from the pressure path, not proactively. Character budgets misprice CJK and code alike, and there is no dedup of identical repeated output.
  • Pictures: the harness ships an image-offload plugin (harness/node_modules/@deepseek-ai/dsh-compaction-image-offload) but Strata's compaction group registers only compaction-basic and tool-result-pruner (preset.mjs:73-77), so images stay inline in the surface and are replayed into the summariser request; the app keeps at most three picture slots per request from the newest side (apps/host/src/lib/chat-photos.ts:20).

None of this is the re-read cost already tracked under #3998, #3928, #2228 and (closed) #3701 — this report is about the quality and size policy of the condensation, and it is a separate axis: an engine-side fix to the conversation cache would not change any of the numbers above.

Smallest steps or command that reproduce it

  1. Load a local model at a 32K context and work a task that produces tool output (read files, run commands) until the conversation passes ~20,000 tokens.
  2. Observe: compaction fires, keeps the newest ~3,670 tokens verbatim, and asks for a summary capped at 2,867 tokens to cover roughly 16,400 tokens of history.
  3. Now make the replaced span content-dense — many file paths, commands, and one early decision that everything later depends on. The decision is either inside the newest 3,670 tokens (kept) or in the collapsed part (compressed to a fifth or less of its size, in English, in eight fixed sections).
  4. Ask the assistant something that depends on that early decision. In a Chinese conversation the answer often comes back with the detail lost, and re-asking re-summarises a summary.
  5. Arithmetic check for anyone verifying: localOutputBudget and compactionHeadroom are two pure functions in apps/host/server/agent/profile.mjs:137-143 and :151-153; the threshold and retention formulas are at dsh-compaction-basic/lib/index.js:130-133 in the installed 0.2.8. The table above is those functions evaluated at 32,768 / 65,536 / 393,216.

Reproduction status

Mixed, and stated per part: the arithmetic is confirmed (two functions in the repo, three constants in the installed plugin, evaluated above; the 65,536 case is already asserted by the repo's own test apps/host/tests/agent-context.test.mjs:43-51, which pins 40,142). The behavioural consequence — detail lost and then re-summarised — is reported by the person at the keyboard over long local sessions and is consistent with the numbers; it was not measured with a scripted A/B. The local engine log on this machine contains no compaction at all (the largest prompt seen, 206,881, is below the 314,572 threshold for a 393,216 window), so no log evidence is offered here — see #3998 for the re-read cost side.

Strata version

Strata 0.2.8 — app 0.2.8, Control and engine 0.1.54, agent component deepseek-harness 0.2.1-alpha.3 (the compaction plugin is bundled inside that component; the line numbers quoted for it are from the installed 0.2.8 copy, since the plugin source is not in this repository).

Graphics card, memory and system

NVIDIA GeForce RTX 3080 Ti Laptop GPU 16 GB - 64 GB RAM - Windows 11 Pro build 26300

Model, size and settings

Qwen3.8-Flash-Next IQ3_S, --max-context 393216, rope yarn ×1.5, KV int8, MTP drafting on. The formulas above are model-independent; the model only sets contextWindow and maxTokens.

Logs

C:\Users\123\AppData\Local\Strata\install\strata-iq3_s.log — 194 prompt-read lines, and notably zero compaction lines: the largest prompt in this log is 206,881 tokens, below the 314,572-token threshold this window computes, so compaction never fired here. This log corroborates the re-read pattern (#3998 family), not this issue; it is offered so that nobody reads it as evidence of compaction on this machine.

Searched open and closed issues for compaction, compact, summariz/summaris, context full, keep recent, prune, checkpoint, context window:

  • #3694 (closed) — the 65,536 fixed headroom leaving no pressure budget at a 64K window; it is what produced compactionHeadroom in profile.mjs:151-153. Different problem (the failure to compact at all), same knob.
  • #3998, #3928, #2228 (open) and #3701 (closed) — engine-side re-read cost after a condensation. Orthogonal axis, as said above.
  • #4542 (open) — an external CLI repeatedly compacting and losing task progress: the same symptom from a different client, not this policy.
  • #3442 (open) — context size for new chats; unrelated.
    No issue covers: the checkpoint cap being tied to the headroom, truncation as a hard failure, the fixed .16 recency-only retention with no importance or dedup, unbounded re-summarisation of previous checkpoints, character-based reactive tool pruning, or the image-offload plugin not being registered.

Suggested fix (not tested)

  • Separate the two numbers: let the checkpoint's output budget be its own (say max(1024, min(8192, replacedSpan * k)) for some k) instead of inheriting headroomTokens, and size the headroom from what a checkpoint of that budget actually costs. The 5.7:1 collapse in the table is a consequence of one constant doing two jobs.
  • Truncation: allow the summariser to grow its cap once (or to split into two checkpoints) rather than failing the condensation and leaving the turn uncompacted.
  • Retention: expose retainRatio/retainTokens to Strata the way headroomTokens is exposed, and give a cheap importance signal (nodes named by a later message, file paths that were edited, decisions the plan repeats) instead of pure recency. Dedup identical tool output.
  • Pruning: run the tool-result pruner before the pressure decision instead of inside it, and price it in tokens rather than characters.
  • Register the image-offload plugin in the compaction group (preset.mjs:73-77) or delete it from the bundle, so a reader is not told the harness handles pictures when the app never calls it.
Originally created by @xvcezrqpbxtpzblrt on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4744 **2026-11-06 更新**:v0.2.10 / v0.2.11 发布说明均未点名本 issue。便于处理起见,本 issue 主要跟踪:触发线与保留率固定、检查点上限与头部保护同源、截断即失败。图片卸载与字符预算两项如需单独排队,请您指出。 --- ### Area [Other] (the agent runtime configuration Strata ships; the policy itself lives in the bundled compaction plugin) ### Desktop app, Terminal or source? Desktop app (Windows), with the arithmetic read from `apps/host/server/agent/profile.mjs` and `apps/host/server/agent/preset.mjs` at tag `v0.2.8`, and from the compaction plugin installed with the app. ### What happened Long sessions lose their thread faster than the numbers should allow. Compaction today is driven by two fixed fractions and one fixed band, and the size of the replacement summary is tied to the same number that protects the window — so a condensation is forced to be tiny, and if it is not tiny enough it is rejected. The retention rule is recency only, and every pass re-summarises the checkpoint from the previous pass, with nothing bounding the drift. The chain, with numbers that follow from the shipped code (not measurements): - Trigger: the compaction plugin listens only between agent steps (installed `harness/node_modules/@deepseek-ai/dsh-compaction-basic/lib/index.js:839`, `agent/pre-step`), and the threshold is `floor(min(contextWindow * thresholdRatio, contextWindow - reservedCompletionTokens - headroomTokens))` (`:130-132`) with `DEFAULT_THRESHOLD_RATIO = .8` (`:15`). - Strata's only override is `headroomTokens`, per model, from `apps/host/server/agent/profile.mjs:151-153`: `max(512, min(65536, floor((context - outputBudget) * 0.125)))`, pushed at `profile.mjs:214`, `:244`, `:286`. It never sets `retainRatio`, `retainTokens` or `maxTokens`. - The reply reservation is `localOutputBudget = max(4096, min(32768, floor(context * 0.3)))` (`profile.mjs:137-143`). - Consequence: the checkpoint's own output cap defaults to the headroom (`dsh-compaction-basic/.../index.js:64` and `:71` — "maxTokens … from headroomTokens"). The number that protects the window is also the ceiling on the summary that has to replace the older history. Computed for the three windows a local user actually picks (from the two formulas above): | context | reply reserve | headroom = checkpoint cap | compaction starts at | verbatim tail kept | history replaced | forced ratio | |---|---|---|---|---|---|---| | 32,768 | 9,830 | 2,867 | 20,071 (61%) | 3,670 | ≈16,401 | ≈5.7 : 1 | | 65,536 | 19,660 | 5,734 | 40,142 (61%) | 7,340 | ≈32,802 | ≈5.7 : 1 | | 393,216 (this PC, IQ3_S) | 32,768 | 45,056 | 314,572 (80%) | 57,671 | ≈256,901 | ≈5.7 : 1 | - A checkpoint that hits the cap is treated as broken: "summarization truncated at the token cap (incomplete checkpoint)" (`dsh-compaction-basic/.../index.js:363`); after one retry the turn continues **uncompacted** with a warning, so a 32K session that needs to shed 16K tokens of history can end up shedding nothing. - Retention is recency only: `DEFAULT_RETAIN_RATIO = .16` (`:17`), `retainTokens = floor((contextWindow - reservedCompletionTokens) * retainRatio)` (`:133`), and the tail is accumulated newest-first (`:416-422`). Nothing scores importance, and nothing deduplicates: repeated tool output that never changed is kept, while an early decision the whole task depends on is dropped. - Compaction is one-shot per pass over everything older than the tail: the replacement starts at the first non-system node (`:415`, `firstIdx = 1`), so the previous checkpoint sits inside the next range and is merged only because the prompt asks the model to fold it in. Lossy re-summarisation of a lossy summary is unbounded. - Tool output is pruned only after pressure has already arrived, by characters: the pruner is registered with `thresholdChars: 8192, headChars: 4096, tailChars: 1024` (`apps/host/server/agent/preset.mjs:77`) and runs from the pressure path, not proactively. Character budgets misprice CJK and code alike, and there is no dedup of identical repeated output. - Pictures: the harness ships an image-offload plugin (`harness/node_modules/@deepseek-ai/dsh-compaction-image-offload`) but Strata's compaction group registers only `compaction-basic` and `tool-result-pruner` (`preset.mjs:73-77`), so images stay inline in the surface and are replayed into the summariser request; the app keeps at most three picture slots per request from the newest side (`apps/host/src/lib/chat-photos.ts:20`). None of this is the re-read cost already tracked under #3998, #3928, #2228 and (closed) #3701 — this report is about the *quality* and *size* policy of the condensation, and it is a separate axis: an engine-side fix to the conversation cache would not change any of the numbers above. ### Smallest steps or command that reproduce it 1. Load a local model at a 32K context and work a task that produces tool output (read files, run commands) until the conversation passes ~20,000 tokens. 2. Observe: compaction fires, keeps the newest ~3,670 tokens verbatim, and asks for a summary capped at 2,867 tokens to cover roughly 16,400 tokens of history. 3. Now make the replaced span content-dense — many file paths, commands, and one early decision that everything later depends on. The decision is either inside the newest 3,670 tokens (kept) or in the collapsed part (compressed to a fifth or less of its size, in English, in eight fixed sections). 4. Ask the assistant something that depends on that early decision. In a Chinese conversation the answer often comes back with the detail lost, and re-asking re-summarises a summary. 5. Arithmetic check for anyone verifying: `localOutputBudget` and `compactionHeadroom` are two pure functions in `apps/host/server/agent/profile.mjs:137-143` and `:151-153`; the threshold and retention formulas are at `dsh-compaction-basic/lib/index.js:130-133` in the installed 0.2.8. The table above is those functions evaluated at 32,768 / 65,536 / 393,216. ### Reproduction status Mixed, and stated per part: the arithmetic is confirmed (two functions in the repo, three constants in the installed plugin, evaluated above; the 65,536 case is already asserted by the repo's own test `apps/host/tests/agent-context.test.mjs:43-51`, which pins 40,142). The behavioural consequence — detail lost and then re-summarised — is reported by the person at the keyboard over long local sessions and is consistent with the numbers; it was not measured with a scripted A/B. The local engine log on this machine contains no compaction at all (the largest prompt seen, 206,881, is below the 314,572 threshold for a 393,216 window), so no log evidence is offered here — see #3998 for the re-read cost side. ### Strata version Strata 0.2.8 — app `0.2.8`, Control and engine `0.1.54`, agent component `deepseek-harness` `0.2.1-alpha.3` (the compaction plugin is bundled inside that component; the line numbers quoted for it are from the installed 0.2.8 copy, since the plugin source is not in this repository). ### Graphics card, memory and system NVIDIA GeForce RTX 3080 Ti Laptop GPU 16 GB - 64 GB RAM - Windows 11 Pro build 26300 ### Model, size and settings Qwen3.8-Flash-Next IQ3_S, `--max-context 393216`, rope yarn ×1.5, KV int8, MTP drafting on. The formulas above are model-independent; the model only sets `contextWindow` and `maxTokens`. ### Logs `C:\Users\123\AppData\Local\Strata\install\strata-iq3_s.log` — 194 prompt-read lines, and notably **zero** compaction lines: the largest prompt in this log is 206,881 tokens, below the 314,572-token threshold this window computes, so compaction never fired here. This log corroborates the re-read pattern (#3998 family), not this issue; it is offered so that nobody reads it as evidence of compaction on this machine. ### Duplicate search Searched open and closed issues for `compaction`, `compact`, `summariz/summaris`, `context full`, `keep recent`, `prune`, `checkpoint`, `context window`: - #3694 (closed) — the 65,536 fixed headroom leaving no pressure budget at a 64K window; it is what produced `compactionHeadroom` in `profile.mjs:151-153`. Different problem (the failure to compact at all), same knob. - #3998, #3928, #2228 (open) and #3701 (closed) — engine-side re-read cost after a condensation. Orthogonal axis, as said above. - #4542 (open) — an external CLI repeatedly compacting and losing task progress: the same *symptom* from a different client, not this policy. - #3442 (open) — context size for new chats; unrelated. No issue covers: the checkpoint cap being tied to the headroom, truncation as a hard failure, the fixed .16 recency-only retention with no importance or dedup, unbounded re-summarisation of previous checkpoints, character-based reactive tool pruning, or the image-offload plugin not being registered. ### Suggested fix (not tested) - Separate the two numbers: let the checkpoint's output budget be its own (say `max(1024, min(8192, replacedSpan * k))` for some `k`) instead of inheriting `headroomTokens`, and size the headroom from what a checkpoint of that budget actually costs. The 5.7:1 collapse in the table is a consequence of one constant doing two jobs. - Truncation: allow the summariser to grow its cap once (or to split into two checkpoints) rather than failing the condensation and leaving the turn uncompacted. - Retention: expose `retainRatio`/`retainTokens` to Strata the way `headroomTokens` is exposed, and give a cheap importance signal (nodes named by a later message, file paths that were edited, decisions the plan repeats) instead of pure recency. Dedup identical tool output. - Pruning: run the tool-result pruner before the pressure decision instead of inside it, and price it in tokens rather than characters. - Register the image-offload plugin in the compaction group (`preset.mjs:73-77`) or delete it from the bundle, so a reader is not told the harness handles pictures when the app never calls it.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 30, 2026):

Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:

  • Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes".

Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

<!-- gh-comment-id:6533599648 --> @github-actions[bot] commented on GitHub (Oct 30, 2026): Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing: - [ ] Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes". Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@github-actions[bot] commented on GitHub (Oct 30, 2026):

Thanks, this follows the format now.

<!-- gh-comment-id:6533608476 --> @github-actions[bot] commented on GitHub (Oct 30, 2026): Thanks, this follows the format now.
Author
Owner

@Memosis commented on GitHub (Nov 1, 2026):

Adding a data point from a Windows desktop user, plus a related request.

Setup: Strata desktop app (Windows), context set to 200K.

Observation: automatic compaction starts at about 75% of the window. This matches the formulas in this issue (compactionHeadroom / localOutputBudget in profile.mjs, threshold in the plugin). Evaluated at 200,000:

  • reply reserve = max(4096, min(32768, floor(200000 × 0.3))) = 32,768
  • headroom = max(512, min(65536, floor((200000 − 32768) × 0.125))) = 20,904
  • threshold = min(200000 × 0.8, 200000 − 32768 − 20904) = 146,328 (about 73%)

So at 200K the headroom term, not the 0.8 ratio, decides the trigger point.

Request: besides exposing retainRatio / retainTokens as suggested above, please also expose the trigger point itself as a user-facing setting (for example a percentage, or headroomTokens / reply reserve), in the Models screen or in a config file. I could not find any option for this in the README, docs, release notes or other issues. For users who rely on large contexts, compacting at about 73% means summarising and losing detail while tens of thousands of tokens are still free.

I understand a higher trigger has to leave room for the reply reserve and the checkpoint, so a setting could be clamped to something like context − reply reserve − checkpoint cap. It would also help if the default stayed as it is for small windows (32K/64K), where the current headroom logic matters most.

Happy to test a build if that helps.

<!-- gh-comment-id:6554834067 --> @Memosis commented on GitHub (Nov 1, 2026): Adding a data point from a Windows desktop user, plus a related request. **Setup:** Strata desktop app (Windows), context set to 200K. **Observation:** automatic compaction starts at about 75% of the window. This matches the formulas in this issue (`compactionHeadroom` / `localOutputBudget` in `profile.mjs`, threshold in the plugin). Evaluated at 200,000: - reply reserve = max(4096, min(32768, floor(200000 × 0.3))) = 32,768 - headroom = max(512, min(65536, floor((200000 − 32768) × 0.125))) = 20,904 - threshold = min(200000 × 0.8, 200000 − 32768 − 20904) = 146,328 (about 73%) So at 200K the headroom term, not the 0.8 ratio, decides the trigger point. **Request:** besides exposing `retainRatio` / `retainTokens` as suggested above, please also expose the trigger point itself as a user-facing setting (for example a percentage, or `headroomTokens` / reply reserve), in the Models screen or in a config file. I could not find any option for this in the README, docs, release notes or other issues. For users who rely on large contexts, compacting at about 73% means summarising and losing detail while tens of thousands of tokens are still free. I understand a higher trigger has to leave room for the reply reserve and the checkpoint, so a setting could be clamped to something like `context − reply reserve − checkpoint cap`. It would also help if the default stayed as it is for small windows (32K/64K), where the current headroom logic matters most. Happy to test a build if that helps.
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#2177
No description provided.