[GH-ISSUE #5006] [TUI] strata connect/launch opencode caps output at 4096 (OUTPUT_CAP), which breaks OpenCode auto-compaction on wide-context servers: "Compaction summary reached the output token limit" #2312

Open
opened 2026-11-04 01:58:21 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @davidallan7121-ship-it on GitHub (Nov 2, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5006

Area

[TUI] (the Terminal: strata launch, connect, monitor)

Desktop app, Terminal or source?

Terminal (the strata command)

What happened

Long OpenCode sessions against a 128K Strata server die with "reached token limits" the moment OpenCode's auto-compaction fires. The OpenCode log shows:

level=ERROR message="Failed to drain Session" cause="Session.StepFailedError: Compaction summary reached the output token limit"
    at SessionRunner.runStep ...
sessionID=ses_e636f1907ffeuOcJ6Zsen6fRZk

Once this happens the step fails and the conversation cannot continue until the client is reconfigured.

The chain, from strata_cli/launch/harness.py (strata connect opencode --write / strata launch):

  1. OUTPUT_CAP = 4096 ("the output cap every tested config used") is written into the OpenCode config as limit.output (opencode_file()), and limit.input is set to context - OUTPUT_CAP.
  2. OpenCode caps every completion, including its own compaction summary, at limit.output = 4096 tokens.
  3. compact_at() carries the tested 32K ratio over: on a 131072-token server compaction fires at ≈66.4K tokens — a summarising model with thinking routinely spends the 4096-token budget on reasoning and returns finish_reason: "length" with an empty or truncated summary.
  4. OpenCode treats a truncated summary as a hard failure → Session.StepFailedError: Compaction summary reached the output token limit → the step dies with "reached token limits".

The cap is not only a compaction problem: the same 4096 limit had already been killing ordinary long agent turns on this setup for weeks, surfacing in older OpenCode builds as Session.StepFailedError: Response still truncated after two output token limit continuations (three instances in my logs from 24–25 Oct, sessions ses_e91ad639..., ses_e9183dc0..., ses_e8c95f73...).

The Strata server itself is fine with a larger cap: serve/server.py fits its thinking budget to the requested max_tokens, and at limit.output = 16384 the compaction succeeds and long sessions run clean (verified end-to-end with opencode run).

Related but not the same: #4744 covers the same "summary capped by the headroom it protects, truncation = hard failure" design in the bundled DeepSeek Harness compaction plugin; this report is about the numbers Strata writes for the external harness configs. The same OUTPUT_CAP is also propagated to all of them: CLAUDE_CODE_MAX_OUTPUT_TOKENS=4096 (also documented in _limits_claude), maxTokens: 4096 for omp/pi/openclaw.

Smallest steps or command that reproduce it

  1. strata launch a 128K model, run strata connect opencode --write (writes limit: {context: 131072, input: 126976, output: 4096} into ~/.config/opencode/opencode.json).
  2. In OpenCode, run a session that grows past ≈66K tokens (the compact_at value for this config) — any normal long agentic session.
  3. Auto-compaction fires; the summary request is capped at 4096 output tokens; the step fails with the error above and OpenCode reports it hit its token limit.

Reproduction status

Reproduced locally

Strata version

strata 0.2.9 (build 0.1.55; python 3.12.15) — control component 0.1.55, engine component 0.1.52-linux-x86_64-cuda-cuda13

Graphics card, memory and system

RTX 5070 Ti 16 GB · 60 GB RAM · Omarchy (Arch-based), Linux

Model, size and settings

Qwen3.8-Flash-Next IQ3_S (profile iq3_s-128k, --max-context 131072) · OpenCode v2.2.5

Logs

timestamp=2026-11-02T14:28:50.290Z level=ERROR message="Failed to drain Session"
  cause="Session.StepFailedError: Compaction summary reached the output token limit" sessionID=ses_e636f1907ffeuOcJ6Zsen6fRZk
timestamp=2026-11-02T14:52:09.515Z  (same error, sessionID=ses_e634a8d5fffe79g2szK6Xlhlgr)
timestamp=2026-11-02T14:55:05.591Z  (same error, same session)
earlier, same 4096 cap, normal turns (2026-10-24/25):
  cause="Session.StepFailedError: Response still truncated after two output token limit continuations"

Suggested fix

Raise OUTPUT_CAP (16384 works; the server adapts its thinking budget to whatever max_tokens it is given), or decouple the compaction/summary budget from the per-turn cap so the summary is guaranteed headroom. compact_at()'s comment ("the summarising request still fits the window") only sizes the input side of that request; its output is left at 4096 whatever the context.

Workaround applied locally: set limit.output = 16384 in ~/Work/opencode.jsonc (project level) and patched OUTPUT_CAP in the two installed copies — which a component update will revert, hence the report here.

Originally created by @davidallan7121-ship-it on GitHub (Nov 2, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/5006 ### Area [TUI] (the Terminal: strata launch, connect, monitor) ### Desktop app, Terminal or source? Terminal (the `strata` command) ### What happened Long OpenCode sessions against a 128K Strata server die with "reached token limits" the moment OpenCode's auto-compaction fires. The OpenCode log shows: ``` level=ERROR message="Failed to drain Session" cause="Session.StepFailedError: Compaction summary reached the output token limit" at SessionRunner.runStep ... sessionID=ses_e636f1907ffeuOcJ6Zsen6fRZk ``` Once this happens the step fails and the conversation cannot continue until the client is reconfigured. The chain, from `strata_cli/launch/harness.py` (`strata connect opencode --write` / `strata launch`): 1. `OUTPUT_CAP = 4096` ("the output cap every tested config used") is written into the OpenCode config as `limit.output` (`opencode_file()`), and `limit.input` is set to `context - OUTPUT_CAP`. 2. OpenCode caps **every** completion, including its own compaction summary, at `limit.output` = 4096 tokens. 3. `compact_at()` carries the tested 32K ratio over: on a 131072-token server compaction fires at ≈66.4K tokens — a summarising model with thinking routinely spends the 4096-token budget on reasoning and returns `finish_reason: "length"` with an empty or truncated summary. 4. OpenCode treats a truncated summary as a hard failure → `Session.StepFailedError: Compaction summary reached the output token limit` → the step dies with "reached token limits". The cap is not only a compaction problem: the same 4096 limit had already been killing ordinary long agent turns on this setup for weeks, surfacing in older OpenCode builds as `Session.StepFailedError: Response still truncated after two output token limit continuations` (three instances in my logs from 24–25 Oct, sessions `ses_e91ad639...`, `ses_e9183dc0...`, `ses_e8c95f73...`). The Strata server itself is fine with a larger cap: `serve/server.py` fits its thinking budget to the requested `max_tokens`, and at `limit.output = 16384` the compaction succeeds and long sessions run clean (verified end-to-end with `opencode run`). Related but not the same: #4744 covers the same "summary capped by the headroom it protects, truncation = hard failure" design in the *bundled* DeepSeek Harness compaction plugin; this report is about the numbers Strata writes for the *external* harness configs. The same `OUTPUT_CAP` is also propagated to all of them: `CLAUDE_CODE_MAX_OUTPUT_TOKENS=4096` (also documented in `_limits_claude`), `maxTokens: 4096` for omp/pi/openclaw. ### Smallest steps or command that reproduce it 1. `strata launch` a 128K model, run `strata connect opencode --write` (writes `limit: {context: 131072, input: 126976, output: 4096}` into `~/.config/opencode/opencode.json`). 2. In OpenCode, run a session that grows past ≈66K tokens (the compact_at value for this config) — any normal long agentic session. 3. Auto-compaction fires; the summary request is capped at 4096 output tokens; the step fails with the error above and OpenCode reports it hit its token limit. ### Reproduction status Reproduced locally ### Strata version strata 0.2.9 (build 0.1.55; python 3.12.15) — control component 0.1.55, engine component 0.1.52-linux-x86_64-cuda-cuda13 ### Graphics card, memory and system RTX 5070 Ti 16 GB · 60 GB RAM · Omarchy (Arch-based), Linux ### Model, size and settings Qwen3.8-Flash-Next IQ3_S (profile iq3_s-128k, `--max-context 131072`) · OpenCode v2.2.5 ### Logs ``` timestamp=2026-11-02T14:28:50.290Z level=ERROR message="Failed to drain Session" cause="Session.StepFailedError: Compaction summary reached the output token limit" sessionID=ses_e636f1907ffeuOcJ6Zsen6fRZk timestamp=2026-11-02T14:52:09.515Z (same error, sessionID=ses_e634a8d5fffe79g2szK6Xlhlgr) timestamp=2026-11-02T14:55:05.591Z (same error, same session) earlier, same 4096 cap, normal turns (2026-10-24/25): cause="Session.StepFailedError: Response still truncated after two output token limit continuations" ``` ### Suggested fix Raise `OUTPUT_CAP` (16384 works; the server adapts its thinking budget to whatever `max_tokens` it is given), or decouple the compaction/summary budget from the per-turn cap so the summary is guaranteed headroom. `compact_at()`'s comment ("the summarising request still fits the window") only sizes the *input* side of that request; its output is left at 4096 whatever the context. Workaround applied locally: set `limit.output = 16384` in `~/Work/opencode.jsonc` (project level) and patched `OUTPUT_CAP` in the two installed copies — which a component update will revert, hence the report here.
Author
Owner

@salmun-nister commented on GitHub (Nov 3, 2026):

Confirming this on another 128K setup (Qwen3.8-Flash-Next IQ3_S, Strata 0.1.55, OpenCode 2.2.5). Same failure, same cause.

The failed compaction recorded:

  • input: 86,728 tokens (14,613 uncached + 72,115 cache read)
  • output: 4,096 tokens — exactly limit.output
  • finish_reason: length

The conversation wasn't too long; the summary was cut off. At max_tokens = 4096, serve/server.py's answer-room calculation is:

budget = 4096 - min(max(512, 4096 // 4), 4096 // 2)
       = 4096 - 1024
       = 3072

That leaves 3,072 tokens for thinking and at most 1,024 for the structured summary. The summary needed more than that, so the model hit the cap and OpenCode correctly treats the truncated summary as a hard failure.

The config arithmetic also matches this report: context 131072, input 126976, compact_at 66428, buffer 60548. The session was already at ~86.7K when compaction ran — the trigger is checked at step boundaries, so it overshoots — making the summary larger than in the 32K test case.

Workaround confirmed: set limit.output: 16384, leaving input and buffer as generated. I applied that here; the server accepts 16,384 and adapts the thinking budget (12,288 thinking + 4,096 answer). The same session then re-compacted successfully at 86.7K in / 4.3K out. The summary request used ~4.3K output — just over the old 4,096 cap — so the old limit was marginal rather than far too small. 16,384 gives comfortable headroom.

For the fix: 16,384 is enough at 128K (only 4.3K was used here), but a fixed constant may still be tight on much wider windows. Scaling OUTPUT_CAP with context, or giving compaction its own output budget, would be more robust. Either way, compact_at should stay sized so the summary request's input + output fits with headroom.

The same OUTPUT_CAP is also propagated to the other harness configs (CLAUDE_CODE_MAX_OUTPUT_TOKENS=4096, maxTokens: 4096 for omp/pi/openclaw), so the same truncation risk applies there.

The fix needs to land in the template: strata connect opencode --write overwrites the workaround, and patching the installed harness.py is reverted by component updates.

<!-- gh-comment-id:6594451056 --> @salmun-nister commented on GitHub (Nov 3, 2026): Confirming this on another 128K setup (Qwen3.8-Flash-Next IQ3_S, Strata 0.1.55, OpenCode 2.2.5). Same failure, same cause. The failed compaction recorded: - input: 86,728 tokens (14,613 uncached + 72,115 cache read) - output: 4,096 tokens — exactly `limit.output` - `finish_reason: length` The conversation wasn't too long; the summary was cut off. At `max_tokens = 4096`, `serve/server.py`'s answer-room calculation is: ```text budget = 4096 - min(max(512, 4096 // 4), 4096 // 2) = 4096 - 1024 = 3072 ``` That leaves 3,072 tokens for thinking and at most 1,024 for the structured summary. The summary needed more than that, so the model hit the cap and OpenCode correctly treats the truncated summary as a hard failure. The config arithmetic also matches this report: `context 131072`, `input 126976`, `compact_at 66428`, `buffer 60548`. The session was already at ~86.7K when compaction ran — the trigger is checked at step boundaries, so it overshoots — making the summary larger than in the 32K test case. **Workaround confirmed:** set `limit.output: 16384`, leaving `input` and `buffer` as generated. I applied that here; the server accepts 16,384 and adapts the thinking budget (12,288 thinking + 4,096 answer). The same session then re-compacted successfully at **86.7K in / 4.3K out**. The summary request used ~4.3K output — just over the old 4,096 cap — so the old limit was marginal rather than far too small. 16,384 gives comfortable headroom. **For the fix:** 16,384 is enough at 128K (only 4.3K was used here), but a fixed constant may still be tight on much wider windows. Scaling `OUTPUT_CAP` with context, or giving compaction its own output budget, would be more robust. Either way, `compact_at` should stay sized so the summary request's input + output fits with headroom. The same `OUTPUT_CAP` is also propagated to the other harness configs (`CLAUDE_CODE_MAX_OUTPUT_TOKENS=4096`, `maxTokens: 4096` for omp/pi/openclaw), so the same truncation risk applies there. The fix needs to land in the template: `strata connect opencode --write` overwrites the workaround, and patching the installed `harness.py` is reverted by component updates.
Author
Owner

@Niko1221 commented on GitHub (Nov 5, 2026):

Hello davidallan7121-ship-it,

Thank you for the clear explanation. In Strata 0.2.11 the output cap written by strata connect and launch for OpenCode (limit.output), the other connected clients' output setting and maxTokens is the larger of 4096 and one eighth of the context (16384 at 128K), and a cap you set yourself is kept when the block is rewritten. The input limit and the compaction point are unchanged. We checked the configuration and the tests; we did not run OpenCode. Please try 0.2.11 and tell us if auto-compaction still fails.

The Strata project

<!-- gh-comment-id:6658482786 --> @Niko1221 commented on GitHub (Nov 5, 2026): Hello davidallan7121-ship-it, Thank you for the clear explanation. In Strata 0.2.11 the output cap written by `strata connect` and `launch` for OpenCode (`limit.output`), the other connected clients' output setting and `maxTokens` is the larger of 4096 and one eighth of the context (16384 at 128K), and a cap you set yourself is kept when the block is rewritten. The input limit and the compaction point are unchanged. We checked the configuration and the tests; we did not run OpenCode. Please try 0.2.11 and tell us if auto-compaction still fails. The Strata project
Author
Owner

@davidallan7121-ship-it commented on GitHub (Nov 5, 2026):

Thanks Niko — 0.2.11 fixes the compaction output-cap issue in my setup.

Setup

  • Strata 0.2.11 / control 0.1.57 (active component ~/.local/share/strata/components/control/0.1.57)
  • OpenCode 2.2.5
  • Model: strata/qwen3.8-flash-next-iq3_s, 128K profile
  • strata connect opencode --context 128k --output json now generates limit: {"context": 131072, "input": 126976, "output": 16384} with compaction: {"auto": true, "buffer": 60548} (global config already had output: 16384)

Real OpenCode auto-compaction test (passed)

  • Created a fresh OpenCode session with the 128K Strata model and sent a dense ~362 KB prompt.
  • OpenCode triggered auto-compaction (type: compaction, reason: auto).
  • Compaction completed with a 1,860-char summary (no Session.StepFailedError / no "Compaction summary reached the output token limit").
  • Strata engine log for the summary request: prompt 92119 tokens = 0 reused + 92119 read in 29577 ms (3114.6 tok/s), 727 generated in 7289 ms (99.7 tok/s), drafts accepted 437 of 552, 6 checkpoints.

This is one-machine confirmation (the release note mentioned config-side only), but auto-compaction completed successfully here with the new 16,384 output cap. Thank you for the fix.

<!-- gh-comment-id:6659183780 --> @davidallan7121-ship-it commented on GitHub (Nov 5, 2026): Thanks Niko — 0.2.11 fixes the compaction output-cap issue in my setup. **Setup** - Strata `0.2.11` / control `0.1.57` (active component `~/.local/share/strata/components/control/0.1.57`) - OpenCode `2.2.5` - Model: `strata/qwen3.8-flash-next-iq3_s`, 128K profile - `strata connect opencode --context 128k --output json` now generates `limit: {"context": 131072, "input": 126976, "output": 16384}` with `compaction: {"auto": true, "buffer": 60548}` (global config already had `output: 16384`) **Real OpenCode auto-compaction test (passed)** - Created a fresh OpenCode session with the 128K Strata model and sent a dense ~362 KB prompt. - OpenCode triggered auto-compaction (`type: compaction`, `reason: auto`). - Compaction completed with a 1,860-char summary (no `Session.StepFailedError` / no `"Compaction summary reached the output token limit"`). - Strata engine log for the summary request: `prompt 92119 tokens = 0 reused + 92119 read in 29577 ms (3114.6 tok/s), 727 generated in 7289 ms (99.7 tok/s), drafts accepted 437 of 552, 6 checkpoints`. This is one-machine confirmation (the release note mentioned config-side only), but auto-compaction completed successfully here with the new 16,384 output cap. Thank you for the fix.
Author
Owner

@Niko1221 commented on GitHub (Nov 6, 2026):

0.2.11 is out with the fix: the OpenCode output cap now grows with the context window, and a rewrite keeps a cap you set yourself. Could you check whether OpenCode's auto-config works for you now?

<!-- gh-comment-id:6694476666 --> @Niko1221 commented on GitHub (Nov 6, 2026): 0.2.11 is out with the fix: the OpenCode output cap now grows with the context window, and a rewrite keeps a cap you set yourself. Could you check whether OpenCode's auto-config works for you now?
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#2312
No description provided.