Skip to content

fix: pass model to compaction-safeguard via runtime for compact.js workflow#6800

Closed
earlook99 wants to merge 1 commit intoopenclaw:mainfrom
earlook99:fix/compaction-safeguard-model-fallback
Closed

fix: pass model to compaction-safeguard via runtime for compact.js workflow#6800
earlook99 wants to merge 1 commit intoopenclaw:mainfrom
earlook99:fix/compaction-safeguard-model-fallback

Conversation

@earlook99
Copy link

@earlook99 earlook99 commented Feb 2, 2026

Problem

When using compaction.mode: "safeguard", the compaction summarization fails because ctx.model is undefined in the session_before_compact event handler.

This happens because compact.js calls createAgentSession directly without going through ExtensionRunner.initialize(), which is the only place that sets ctx.model.

As a result, compaction falls back to a static summary instead of LLM-generated summarization, causing context loss.

Solution

Pass the model through the runtime registry (same pattern used for contextWindowTokens and maxHistoryShare):

  1. Add model field to CompactionSafeguardRuntimeValue type
  2. Store params.model in setCompactionSafeguardRuntime() call
  3. Fall back to runtime?.model when ctx.model is undefined

Testing

Tested locally with compaction.mode: "safeguard" - compaction now produces proper LLM summaries instead of falling back to static text.


AI-assisted (Claude) - fully tested on local OpenClaw instance.

Greptile Overview

Greptile Summary

This PR threads the selected model into the compaction safeguard runtime so the session_before_compact handler can still perform LLM summarization when ctx.model is unset (notably in the compact.js workflow that bypasses ExtensionRunner.initialize()). Concretely, it (1) adds a model field to the session-scoped CompactionSafeguardRuntimeValue, (2) stores params.model when building embedded extension paths, and (3) falls back to runtime?.model in compaction-safeguard when ctx.model is undefined.

This fits the existing “session-scoped runtime registry keyed by sessionManager identity” pattern already used for compaction/pruning runtimes, and should reduce fallback-to-static-summary behavior when compaction runs outside the normal initialization path.

Confidence Score: 4/5

  • This PR is likely safe to merge and addresses a real initialization-path gap, with minor risk around tests/typing edge cases.
  • Changes are small and follow an existing runtime-registry pattern. Main risk is that existing tests or strict equality checks against the runtime object may break now that the runtime type includes an extra field, and that storing model in runtime could introduce subtle identity/serialization assumptions elsewhere (though none are evident in the reviewed code).
  • src/agents/pi-extensions/compaction-safeguard.test.ts (update expectations if failing); src/agents/pi-extensions/compaction-safeguard-runtime.ts (type import usage)

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 2, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 2, 2026

Additional Comments (1)

src/agents/pi-extensions/compaction-safeguard.test.ts
[P1] Tests for runtime registry will now fail after adding model to the runtime shape.

getCompactionSafeguardRuntime(sm) will currently return the full stored object (including model: undefined if set via buildEmbeddedExtensionPaths or in future tests), but the assertions here use toEqual({ maxHistoryShare: ... }). With the new optional field, this can start failing if any code stores model (even as undefined) into the runtime.

Consider adjusting these assertions to only check the fields under test (e.g. expect(runtime?.maxHistoryShare).toBe(0.3)), or include model in the expected object when appropriate.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-extensions/compaction-safeguard.test.ts
Line: 215:220

Comment:
[P1] Tests for runtime registry will now fail after adding `model` to the runtime shape.

`getCompactionSafeguardRuntime(sm)` will currently return the full stored object (including `model: undefined` if set via `buildEmbeddedExtensionPaths` or in future tests), but the assertions here use `toEqual({ maxHistoryShare: ... })`. With the new optional field, this can start failing if any code stores `model` (even as `undefined`) into the runtime.

Consider adjusting these assertions to only check the fields under test (e.g. `expect(runtime?.maxHistoryShare).toBe(0.3)`), or include `model` in the expected object when appropriate.

How can I resolve this? If you propose a fix, please make it concise.

@Takhoffman
Copy link
Contributor

Closing as superseded by #22349, which fixes the underlying extension loading path rather than model fallback workarounds.

@Takhoffman Takhoffman closed this Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants