Skip to content

Stop automatic memory compaction from firing repeatedly and from running while results are being gathered#5458

Open
andrescera wants to merge 2 commits into
code-yeongyu:devfrom
andrescera:fix/preemptive-compaction-refire-and-result-collection
Open

Stop automatic memory compaction from firing repeatedly and from running while results are being gathered#5458
andrescera wants to merge 2 commits into
code-yeongyu:devfrom
andrescera:fix/preemptive-compaction-refire-and-result-collection

Conversation

@andrescera

@andrescera andrescera commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Stop automatic memory compaction from firing repeatedly and from running while results are being gathered

The problem. To keep long sessions healthy, the assistant automatically condenses its memory when it gets close to full. In practice this kept happening over and over: it would condense, work for a moment, and condense again almost immediately — and it could even condense in the middle of gathering results from background work, throwing away the very information it had just collected. The point at which condensing kicks in was also fixed in the code with no way to adjust it.

When it started. This automatic condensing was introduced in v3.2.2 (commit 62e1687) and has behaved this way since.

The solution. Condensing now happens once when memory genuinely gets close to full, and does not trigger again until memory has actually come back down, so it no longer repeats every turn. It also holds off while the assistant is still collecting results from background work, so freshly gathered information is not discarded. Finally, the threshold and the cooldown are now configurable, with defaults that match today's behavior, for anyone who wants to tune when condensing happens.


Summary by cubic

Prevents auto memory compaction from re-firing each turn and from running while background results are being collected. Adds a configurable compaction block (threshold, cooldown, enabled) with defaults that keep current behavior.

  • Bug Fixes

    • Re-arms compaction only after usage drops below (threshold − 15%) to stop immediate re-compaction.
    • Enforces a cooldown per session before compaction can run again.
    • Skips compaction when handling background_output so fresh results aren’t discarded.
  • New Features

    • Adds compaction config: preemptive_threshold (0–1, default 0.78), cooldown_ms (default 60000), enabled (default true).
    • Root config and JSON schema updated; compaction logic now reads these values at runtime.

Written for commit 5c36808. Summary will update on new commits.

Review in cubic

Introduce CompactionConfigSchema (preemptive_threshold, cooldown_ms,
enabled) with behavior-preserving defaults (0.78 / 60000ms / true), wire
it into the root config schema, and regenerate the JSON schema.
…ing result collection

Re-arm a compacted session only after its usage ratio drops below
(threshold - REARM_MARGIN) instead of every assistant message, skip
compaction while background_output results are being collected, and
read the threshold/cooldown from the new compaction config.
@github-actions github-actions Bot added the opencode OpenCode edition: packages/omo-opencode label Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

opencode OpenCode edition: packages/omo-opencode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant