openclaw - 💡(How to fix) Fix compaction safeguard may inherit polluted runtime/model via sessionManager-scoped state [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#52700Fetched 2026-04-08 01:20:10
View on GitHub
Comments
2
Participants
2
Timeline
2
Reactions
0
Author
Timeline (top)
commented ×2

We observed a main session running on Opus (1M ctx) suddenly recording model-snapshot -> zai/glm-5, after which compaction safeguard evaluated the session against a ~200k context window and triggered unnecessary compaction / timeout behavior. Temporary mitigation via compaction.model=anthropic/claude-opus-4-6 fully stops the issue, which suggests the compaction path is trusting a polluted runtime/model source.

Root Cause

We observed a main session running on Opus (1M ctx) suddenly recording model-snapshot -> zai/glm-5, after which compaction safeguard evaluated the session against a ~200k context window and triggered unnecessary compaction / timeout behavior. Temporary mitigation via compaction.model=anthropic/claude-opus-4-6 fully stops the issue, which suggests the compaction path is trusting a polluted runtime/model source.

Fix Action

Fix / Workaround

Summary

We observed a main session running on Opus (1M ctx) suddenly recording model-snapshot -> zai/glm-5, after which compaction safeguard evaluated the session against a ~200k context window and triggered unnecessary compaction / timeout behavior. Temporary mitigation via compaction.model=anthropic/claude-opus-4-6 fully stops the issue, which suggests the compaction path is trusting a polluted runtime/model source.

Temporary mitigation already confirmed

  1. compaction.model = anthropic/claude-opus-4-6
  2. heartbeat.model = anthropic/claude-sonnet-4-6

This is a mitigation, not a root fix.

Code Example

provider = (params.provider ?? "anthropic").trim() || "anthropic";
   modelId = (params.model ?? "claude-opus-4-6").trim() || "claude-opus-4-6";
RAW_BUFFERClick to expand / collapse

Submit-ready Draft — compaction safeguard runtime pollution

Title

compaction safeguard may inherit polluted runtime/model via sessionManager-scoped state, causing wrong model-snapshot + false compaction on main session

Summary

We observed a main session running on Opus (1M ctx) suddenly recording model-snapshot -> zai/glm-5, after which compaction safeguard evaluated the session against a ~200k context window and triggered unnecessary compaction / timeout behavior. Temporary mitigation via compaction.model=anthropic/claude-opus-4-6 fully stops the issue, which suggests the compaction path is trusting a polluted runtime/model source.

Impact

  1. Main session may compact too early
  2. /new or follow-up turns may request the wrong model
  3. model-snapshot can be overwritten by non-main runtime context
  4. User-visible result: long timeout + unexpected fallback despite main session being configured for Opus

Strong clues

Code evidence (confirmed from local dist)

  1. registry$1 = new WeakMap(), keyed by sessionManager object reference
  2. setCompactionSafeguardRuntime(params.sessionManager, { ..., model: params.model, ... }) — the safeguard stores the model including provider/contextWindow, keyed only by sessionManager
  3. When compaction.model is NOT set in config, compactEmbeddedPiSessionDirect uses:
    provider = (params.provider ?? "anthropic").trim() || "anthropic";
    modelId = (params.model ?? "claude-opus-4-6").trim() || "claude-opus-4-6";
    These values come directly from params, which is caller-provided runtimeContext — not from the session's canonical model config.
  4. Behavior stops immediately when compaction.model=anthropic/claude-opus-4-6 is set in config (which short-circuits the params path)

Implication

Any embedded run (heartbeat, cron, subagent) that shares or reuses the same sessionManager object reference and calls setCompactionSafeguardRuntime with a different provider/model will silently overwrite the compaction model for the main session.

Hypothesis

Compaction safeguard runtime is stored via a module-level WeakMap, keyed by sessionManager object reference. If the same sessionManager instance is reused across different embedded runs (e.g. heartbeat running on glm-5 vs main session on Opus), the last writer wins — and compaction will use that polluted provider/model/contextWindow for the main session.

Expected behavior

  1. Compaction model selection should be isolated per run / session key
  2. Main session model-snapshot should never be overwritten by heartbeat/cron/auxiliary runtime context
  3. Compaction-internal model choice should not mutate the conversational session model unless explicitly intended

Suggested areas to inspect

  1. Scope/key used by setCompactionSafeguardRuntime
  2. Callers that pass runtimeContext/params into compactEmbeddedPiSessionDirect
  3. Whether model-snapshot writes are using compaction runtime instead of canonical session runtime
  4. Whether sessionManager is reused across unrelated embedded runs

Temporary mitigation already confirmed

  1. compaction.model = anthropic/claude-opus-4-6
  2. heartbeat.model = anthropic/claude-sonnet-4-6

This is a mitigation, not a root fix.

Repro notes

Precise deterministic repro is not yet isolated. Current evidence is production-observed, code-correlated, and mitigation-confirmed.

extent analysis

Fix Plan

To address the compaction safeguard runtime pollution issue, we need to isolate the compaction model selection per run/session key. Here are the steps:

  • Modify the setCompactionSafeguardRuntime function to use a unique key for each session, instead of just the sessionManager object reference.
  • Use a combination of sessionManager and sessionKey as the key for the WeakMap.
  • Update the compactEmbeddedPiSessionDirect function to use the canonical session model config instead of the params object.

Example code changes:

// Modified setCompactionSafeguardRuntime function
const registry = new WeakMap();
function setCompactionSafeguardRuntime(sessionManager, sessionKey, params) {
  const key = `${sessionManager}-${sessionKey}`;
  registry.set(key, { ...params });
}

// Updated compactEmbeddedPiSessionDirect function
function compactEmbeddedPiSessionDirect(params) {
  const sessionManager = params.sessionManager;
  const sessionKey = params.sessionKey;
  const key = `${sessionManager}-${sessionKey}`;
  const compactionRuntime = registry.get(key);
  // Use the canonical session model config
  const modelId = compactionRuntime.model;
  const provider = compactionRuntime.provider;
  // ...
}

Verification

To verify that the fix worked, you can:

  • Test the compaction safeguard with different session keys and verify that the correct model is used for each session.
  • Check the model-snapshot writes to ensure that they are not being overwritten by heartbeat/cron/auxiliary runtime context.

Extra Tips

  • Make sure to update all callers of setCompactionSafeguardRuntime to pass the sessionKey parameter.
  • Consider adding additional logging or monitoring to detect any potential issues with the compaction safeguard runtime.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

  1. Compaction model selection should be isolated per run / session key
  2. Main session model-snapshot should never be overwritten by heartbeat/cron/auxiliary runtime context
  3. Compaction-internal model choice should not mutate the conversational session model unless explicitly intended

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING