Skip to content

Preemptive compaction fires at ~16% of context instead of 80% (model-limit lookup falls back to 200K) #88

Description

@mcj777

The documented "Preemptive Compaction" (triggers at 80% context) actually fires at ~14–17% for 1M-token models, compacting sessions repeatedly and prematurely.

Root cause: getModelLimit() relies on a fire-and-forget ctx.client.provider.list() at plugin init. When it fails (intermittent TypeError: terminated / fetch failed), modelLimits stays empty and compaction falls back to DEFAULT_CONTEXT_LIMIT = 200000. For a 1M model: 0.8 × 200_000 = 160_00016%.

Evidence (~/.opencode-supermemory.log):

[compaction] checking: {... "totalUsed":150933, "contextLimit":200000, "usageRatio":"0.75", "threshold":0.8}
[compaction] triggering compaction: {... "usageRatio":0.84566}

The model's real limit is 1M (limit.context = 1000000), so 160K is 16% of capacity.

Proposed fix:

  1. Retry the model-limit load (with backoff) instead of one fire-and-forget attempt.
  2. Raise DEFAULT_CONTEXT_LIMIT (200K is outdated for 1M models) or derive it per-model.
  3. Optionally make the fallback configurable via supermemory.json.

Environment: opencode 1.18.x (desktop 1.18.32), opencode-supermemory 2.0.12 (also 2.0.13), model deepseek/deepseek-v4-pro (1M context).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions