fix: pass model to compaction-safeguard via runtime for compact.js workflow#6800
fix: pass model to compaction-safeguard via runtime for compact.js workflow#6800earlook99 wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Additional Comments (1)
Consider adjusting these assertions to only check the fields under test (e.g. Prompt To Fix With AIThis 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. |
bfc1ccb to
f92900f
Compare
|
Closing as superseded by #22349, which fixes the underlying extension loading path rather than model fallback workarounds. |
Problem
When using
compaction.mode: "safeguard", the compaction summarization fails becausectx.modelisundefinedin thesession_before_compactevent handler.This happens because
compact.jscallscreateAgentSessiondirectly without going throughExtensionRunner.initialize(), which is the only place that setsctx.model.As a result, compaction falls back to a static summary instead of LLM-generated summarization, causing context loss.
Solution
Pass the
modelthrough the runtime registry (same pattern used forcontextWindowTokensandmaxHistoryShare):modelfield toCompactionSafeguardRuntimeValuetypeparams.modelinsetCompactionSafeguardRuntime()callruntime?.modelwhenctx.modelis undefinedTesting
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
modelinto the compaction safeguard runtime so thesession_before_compacthandler can still perform LLM summarization whenctx.modelis unset (notably in thecompact.jsworkflow that bypassesExtensionRunner.initialize()). Concretely, it (1) adds amodelfield to the session-scopedCompactionSafeguardRuntimeValue, (2) storesparams.modelwhen building embedded extension paths, and (3) falls back toruntime?.modelincompaction-safeguardwhenctx.modelisundefined.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
modelin runtime could introduce subtle identity/serialization assumptions elsewhere (though none are evident in the reviewed code).(2/5) Greptile learns from your feedback when you react with thumbs up/down!