Skip to content

fix(compaction): pass model through runtime for safeguard summaries#17864

Merged
vincentkoc merged 7 commits intoopenclaw:mainfrom
battman21:fix/3479-compaction-model-init
Feb 23, 2026
Merged

fix(compaction): pass model through runtime for safeguard summaries#17864
vincentkoc merged 7 commits intoopenclaw:mainfrom
battman21:fix/3479-compaction-model-init

Conversation

@battman21
Copy link
Contributor

@battman21 battman21 commented Feb 16, 2026

Summary

Fixes #3479 — compaction always failing with "Summary unavailable due to context limits"

This PR addresses the root cause: ctx.model is undefined during compaction because extensionRunner.initialize() is never called in the compact.ts workflow. The compaction safeguard immediately returns a fallback summary without attempting LLM summarization.

Changes

  1. Pass model through runtime registry
    • Add model field to CompactionSafeguardRuntimeValue type
    • Store params.model when building embedded extension paths
    • Fall back to runtime.model when ctx.model is undefined
    • Add warning when both are missing (diagnostic for future issues)

Why This Approach

Following the established runtime registry pattern (same as maxHistoryShare and contextWindowTokens) rather than attempting to call extensionRunner.initialize() directly, which is SDK-internal and not meant for external access.

Testing

  • Lint passes
  • Build passes
  • Verified against issue reproduction steps

Related

Greptile Summary

This PR addresses a critical bug where compaction always failed with "Summary unavailable due to context limits" because ctx.model was undefined during the compact.ts workflow.

The fix passes the model through the runtime registry (following the established pattern used for maxHistoryShare and contextWindowTokens), allowing the compaction safeguard to fall back to runtime.model when ctx.model is unavailable. The implementation is clean and well-tested:

  • Added model field to CompactionSafeguardRuntimeValue type with clear documentation
  • Modified buildEmbeddedExtensionFactories to store params.model in runtime registry
  • Updated compaction-safeguard.ts to use ctx.model ?? runtime?.model fallback pattern
  • Added diagnostic warning when both models are missing (logged once per session via WeakSet)
  • Comprehensive test coverage including the specific compact.ts workflow scenario and edge cases

Confidence Score: 5/5

  • This PR is safe to merge with no identified risks
  • The fix follows established patterns in the codebase, includes comprehensive test coverage (including edge cases), and the changelog entry is properly formatted. The implementation is minimal, focused, and directly addresses the root cause without introducing new complexity or side effects.
  • No files require special attention

Last reviewed commit: d9b1f0e

Copy link

@mudrii mudrii left a comment

Choose a reason for hiding this comment

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

Code Review

Verdict: APPROVE

What it fixes

Compaction always fails with "Summary unavailable due to context limits" because ctx.model is undefined in the compact.ts workflow — extensionRunner.initialize() is never called there, so the model is never set on the context.

Analysis

Model passthrough via runtime registry — Well done. Adds model field to CompactionSafeguardRuntimeValue, stores params.model in buildEmbeddedExtensionPaths, and uses ctx.model ?? runtime?.model fallback in the safeguard. This follows the exact same pattern already used for maxHistoryShare and contextWindowTokens — consistent and low-risk.

BASE_CHUNK_RATIO: 0.4 → 0.25 — Reasonable and conservative. On 200K context, chunks go from 80K → 50K tokens. MIN_CHUNK_RATIO is 0.15, so there is room to shrink further if needed. The rationale is sound: when compaction triggers reactively at 90%+ usage, oversized chunks can exceed what the summarization model can handle after adding prompt overhead. Trade-off is more summarization calls (slightly higher cost/latency) but significantly more reliable compaction.

Code quality — The runtime variable was already fetched later in the function; the diff just moves its usage earlier for cleaner flow. Type is Model<Api> which is correct. The redundant if (!ctx.model && !runtime?.model) inside the existing if (!model) block is always true at that point (since model = ctx.model ?? runtime?.model), so the inner check is unnecessary but harmless as documentation.

Minor suggestion

No unit tests were added for the ctx.model undefined → runtime fallback path. Would be nice to have but the change surface is small and the pattern is proven.

Overall clean, well-scoped fix. Ship it. 🚀

@battman21 battman21 force-pushed the fix/3479-compaction-model-init branch from ced5b48 to 20ebf07 Compare February 16, 2026 08:28
@battman21
Copy link
Contributor Author

Updated the PR based on review feedback:

Removed:

  • ❌ BASE_CHUNK_RATIO change (0.4 → 0.25) — this is a separate behavioral change affecting all compaction flows, not just the bug fix. Will create a separate PR with perf/quality evidence if needed.

Added:

  • ✅ Once-per-session warning using WeakSet to prevent log spam when both ctx.model and runtime.model are undefined
  • ✅ Regression test verifying runtime.model is stored/retrieved correctly (proves the fallback path works)

The PR now focuses solely on fixing the root cause: ctx.model being undefined in compact.ts workflow.

@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: XS labels Feb 16, 2026
battman21 added a commit to battman21/openclaw that referenced this pull request Feb 16, 2026
Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864
@battman21
Copy link
Contributor Author

Test Coverage Added

Added comprehensive integration tests for the model fallback behavior:

New Tests (4 total)

  1. Runtime registry tests (3 tests):

    • ✅ Stores and retrieves model from runtime (verifies storage mechanism)
    • ✅ Stores and retrieves contextWindowTokens from runtime
    • ✅ Stores and retrieves combined runtime values (maxHistoryShare + contextWindowTokens + model)
  2. Integration tests (2 tests):

    • Uses runtime.model when ctx.model is undefined - Verifies the root-cause fix: when extensionRunner.initialize() is not called (as in compact.ts workflow), the extension falls back to runtime.model and returns gracefully
    • Returns fallback summary when both models are undefined - Verifies graceful degradation when neither ctx.model nor runtime.model are available

Test Results

✓ src/agents/pi-extensions/compaction-safeguard.e2e.test.ts (22 tests) 6ms
  Test Files  1 passed (1)
       Tests  22 passed (22)

All tests pass, covering:

  • Runtime registry storage/retrieval ✓
  • Model fallback logic in extension ✓
  • Graceful degradation when models are missing ✓

Commit: 9ebb455

battman21 added a commit to battman21/openclaw that referenced this pull request Feb 16, 2026
Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864
@battman21 battman21 force-pushed the fix/3479-compaction-model-init branch from 9ebb455 to cf69df1 Compare February 16, 2026 09:22
@battman21
Copy link
Contributor Author

Test Improvements (addressing medium-priority feedback)

Concrete Evidence of Fallback Path

Added explicit assertions to prove the fallback expression ctx.model ?? runtime?.model is exercised:

Test 1: Model fallback path

// Proves handler used runtime.model by verifying getApiKey was called with it
expect(getApiKeyMock).toHaveBeenCalledWith(model);

Test 2: Early return path

// Proves handler returned early without trying to use a model
expect(getApiKeyMock).not.toHaveBeenCalled();

What This Proves

  1. Fallback path exercised: When ctx.model is undefined but runtime.model is present, the handler calls getApiKey with runtime.model
  2. Early return path works: When both models are undefined, handler returns fallback summary without calling getApiKey

The previous version only verified the output and registry state, which could be true even if the fallback path was never used. Now we have direct evidence the handler consumed runtime.model via the getApiKey spy.

Test Classification Note

Acknowledged: test file is named .e2e.test.ts but uses unit-style mocking of extension handlers rather than true end-to-end behavior. This is acceptable for the scope of this fix (testing the extension API boundary).

Commit: cf69df1

battman21 added a commit to battman21/openclaw that referenced this pull request Feb 16, 2026
Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864
@battman21 battman21 force-pushed the fix/3479-compaction-model-init branch from cf69df1 to 15ced77 Compare February 16, 2026 09:52
battman21 added a commit to battman21/openclaw that referenced this pull request Feb 16, 2026
Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864
@battman21 battman21 force-pushed the fix/3479-compaction-model-init branch from 15ced77 to c3ca172 Compare February 16, 2026 10:17
@steipete steipete closed this Feb 16, 2026
@steipete steipete reopened this Feb 17, 2026
battman21 added a commit to battman21/openclaw that referenced this pull request Feb 17, 2026
Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864
@battman21 battman21 force-pushed the fix/3479-compaction-model-init branch 2 times, most recently from f63ea1d to 0488b97 Compare February 17, 2026 03:04
battman21 added a commit to battman21/openclaw that referenced this pull request Feb 17, 2026
Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864
battman21 added a commit to battman21/openclaw that referenced this pull request Feb 17, 2026
Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864
@battman21 battman21 force-pushed the fix/3479-compaction-model-init branch from 0488b97 to cd8f8af Compare February 17, 2026 03:07
battman21 added a commit to battman21/openclaw that referenced this pull request Feb 17, 2026
Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864
@battman21 battman21 force-pushed the fix/3479-compaction-model-init branch from cd8f8af to f9b1fb5 Compare February 17, 2026 07:51
@openclaw-barnacle openclaw-barnacle bot added the channel: telegram Channel integration: telegram label Feb 17, 2026
battman21 added a commit to battman21/openclaw that referenced this pull request Feb 17, 2026
Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864
@battman21 battman21 force-pushed the fix/3479-compaction-model-init branch from 804dbfe to 9122ef6 Compare February 17, 2026 09:43
@openclaw-barnacle openclaw-barnacle bot removed the channel: telegram Channel integration: telegram label Feb 17, 2026
battman21 and others added 4 commits February 23, 2026 09:40
Fixes openclaw#3479

Root cause: extensionRunner.initialize() is never called in compact.ts workflow,
leaving ctx.model undefined. Compaction safeguard checks ctx.model and returns
fallback summary immediately without attempting LLM summarization.

Changes:
1. Pass model through compaction safeguard runtime registry (same pattern as maxHistoryShare)
2. Fall back to runtime.model when ctx.model is undefined
3. Add once-per-session warning when both models are missing (prevents log spam)
4. Add regression test for runtime.model fallback

This follows the established runtime registry pattern rather than attempting to call
extensionRunner.initialize() (which is SDK-internal and not meant for direct access).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864
- Add baseUrl to Model mock objects (now required by Model<Api>)
- Add explicit Model<Api> annotation to prevent provider string widening
- Cast modelRegistry mock through unknown (ModelRegistry expanded)
- Use non-null assertion for compactionHandler (TypeScript strict)
- Type compaction result explicitly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vincentkoc vincentkoc force-pushed the fix/3479-compaction-model-init branch from 6520fcb to 5945769 Compare February 23, 2026 14:41
@vincentkoc vincentkoc added the dedupe:parent Primary canonical item in dedupe cluster label Feb 23, 2026
@vincentkoc
Copy link
Member

Rebase + readiness update:

  • Rebases cleanly onto current main.
  • Added changelog entry under 2026.2.22 (Unreleased) -> Fixes with contributor credit chain.
  • Focused test pi-extensions/compaction-safeguard.test.ts passes after rebase.

Given overlap, #4223 has been closed as duplicate with attribution preserved. This should stay canonical for the ctx.model/runtime-model safeguard path.

@vincentkoc vincentkoc changed the title fix(compaction): pass model through runtime + reduce chunk ratio to 0.25 fix(compaction): pass model through runtime for safeguard summaries Feb 23, 2026
@vincentkoc
Copy link
Member

@greptile review

@vincentkoc vincentkoc merged commit 01380f4 into openclaw:main Feb 23, 2026
6 checks passed
jaydiamond42 pushed a commit to jaydiamond42/bloomtbot that referenced this pull request Feb 23, 2026
…penclaw#17864)

* fix(compaction): pass model through runtime to fix ctx.model undefined

Fixes openclaw#3479

Root cause: extensionRunner.initialize() is never called in compact.ts workflow,
leaving ctx.model undefined. Compaction safeguard checks ctx.model and returns
fallback summary immediately without attempting LLM summarization.

Changes:
1. Pass model through compaction safeguard runtime registry (same pattern as maxHistoryShare)
2. Fall back to runtime.model when ctx.model is undefined
3. Add once-per-session warning when both models are missing (prevents log spam)
4. Add regression test for runtime.model fallback

This follows the established runtime registry pattern rather than attempting to call
extensionRunner.initialize() (which is SDK-internal and not meant for direct access).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* test: add comprehensive tests for compaction-safeguard model fallback

Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864

* fix(test): adapt compaction-safeguard tests to upstream type changes

- Add baseUrl to Model mock objects (now required by Model<Api>)
- Add explicit Model<Api> annotation to prevent provider string widening
- Cast modelRegistry mock through unknown (ModelRegistry expanded)
- Use non-null assertion for compactionHandler (TypeScript strict)
- Type compaction result explicitly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Compaction: add changelog credit for model fallback fix

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
carlosrivera pushed a commit to myascendai/meshiclaw that referenced this pull request Feb 23, 2026
…penclaw#17864)

* fix(compaction): pass model through runtime to fix ctx.model undefined

Fixes openclaw#3479

Root cause: extensionRunner.initialize() is never called in compact.ts workflow,
leaving ctx.model undefined. Compaction safeguard checks ctx.model and returns
fallback summary immediately without attempting LLM summarization.

Changes:
1. Pass model through compaction safeguard runtime registry (same pattern as maxHistoryShare)
2. Fall back to runtime.model when ctx.model is undefined
3. Add once-per-session warning when both models are missing (prevents log spam)
4. Add regression test for runtime.model fallback

This follows the established runtime registry pattern rather than attempting to call
extensionRunner.initialize() (which is SDK-internal and not meant for direct access).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* test: add comprehensive tests for compaction-safeguard model fallback

Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864

* fix(test): adapt compaction-safeguard tests to upstream type changes

- Add baseUrl to Model mock objects (now required by Model<Api>)
- Add explicit Model<Api> annotation to prevent provider string widening
- Cast modelRegistry mock through unknown (ModelRegistry expanded)
- Use non-null assertion for compactionHandler (TypeScript strict)
- Type compaction result explicitly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Compaction: add changelog credit for model fallback fix

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
mreedr pushed a commit to mreedr/openclaw-custom that referenced this pull request Feb 24, 2026
…penclaw#17864)

* fix(compaction): pass model through runtime to fix ctx.model undefined

Fixes openclaw#3479

Root cause: extensionRunner.initialize() is never called in compact.ts workflow,
leaving ctx.model undefined. Compaction safeguard checks ctx.model and returns
fallback summary immediately without attempting LLM summarization.

Changes:
1. Pass model through compaction safeguard runtime registry (same pattern as maxHistoryShare)
2. Fall back to runtime.model when ctx.model is undefined
3. Add once-per-session warning when both models are missing (prevents log spam)
4. Add regression test for runtime.model fallback

This follows the established runtime registry pattern rather than attempting to call
extensionRunner.initialize() (which is SDK-internal and not meant for direct access).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* test: add comprehensive tests for compaction-safeguard model fallback

Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864

* fix(test): adapt compaction-safeguard tests to upstream type changes

- Add baseUrl to Model mock objects (now required by Model<Api>)
- Add explicit Model<Api> annotation to prevent provider string widening
- Cast modelRegistry mock through unknown (ModelRegistry expanded)
- Use non-null assertion for compactionHandler (TypeScript strict)
- Type compaction result explicitly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Compaction: add changelog credit for model fallback fix

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
plgs2005 pushed a commit to plgs2005/openclaw that referenced this pull request Feb 24, 2026
…penclaw#17864)

* fix(compaction): pass model through runtime to fix ctx.model undefined

Fixes openclaw#3479

Root cause: extensionRunner.initialize() is never called in compact.ts workflow,
leaving ctx.model undefined. Compaction safeguard checks ctx.model and returns
fallback summary immediately without attempting LLM summarization.

Changes:
1. Pass model through compaction safeguard runtime registry (same pattern as maxHistoryShare)
2. Fall back to runtime.model when ctx.model is undefined
3. Add once-per-session warning when both models are missing (prevents log spam)
4. Add regression test for runtime.model fallback

This follows the established runtime registry pattern rather than attempting to call
extensionRunner.initialize() (which is SDK-internal and not meant for direct access).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* test: add comprehensive tests for compaction-safeguard model fallback

Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864

* fix(test): adapt compaction-safeguard tests to upstream type changes

- Add baseUrl to Model mock objects (now required by Model<Api>)
- Add explicit Model<Api> annotation to prevent provider string widening
- Cast modelRegistry mock through unknown (ModelRegistry expanded)
- Use non-null assertion for compactionHandler (TypeScript strict)
- Type compaction result explicitly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Compaction: add changelog credit for model fallback fix

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
margulans pushed a commit to margulans/Neiron-AI-assistant that referenced this pull request Feb 25, 2026
…penclaw#17864)

* fix(compaction): pass model through runtime to fix ctx.model undefined

Fixes openclaw#3479

Root cause: extensionRunner.initialize() is never called in compact.ts workflow,
leaving ctx.model undefined. Compaction safeguard checks ctx.model and returns
fallback summary immediately without attempting LLM summarization.

Changes:
1. Pass model through compaction safeguard runtime registry (same pattern as maxHistoryShare)
2. Fall back to runtime.model when ctx.model is undefined
3. Add once-per-session warning when both models are missing (prevents log spam)
4. Add regression test for runtime.model fallback

This follows the established runtime registry pattern rather than attempting to call
extensionRunner.initialize() (which is SDK-internal and not meant for direct access).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* test: add comprehensive tests for compaction-safeguard model fallback

Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864

* fix(test): adapt compaction-safeguard tests to upstream type changes

- Add baseUrl to Model mock objects (now required by Model<Api>)
- Add explicit Model<Api> annotation to prevent provider string widening
- Cast modelRegistry mock through unknown (ModelRegistry expanded)
- Use non-null assertion for compactionHandler (TypeScript strict)
- Type compaction result explicitly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Compaction: add changelog credit for model fallback fix

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
brianleach pushed a commit to brianleach/openclaw that referenced this pull request Feb 26, 2026
…penclaw#17864)

* fix(compaction): pass model through runtime to fix ctx.model undefined

Fixes openclaw#3479

Root cause: extensionRunner.initialize() is never called in compact.ts workflow,
leaving ctx.model undefined. Compaction safeguard checks ctx.model and returns
fallback summary immediately without attempting LLM summarization.

Changes:
1. Pass model through compaction safeguard runtime registry (same pattern as maxHistoryShare)
2. Fall back to runtime.model when ctx.model is undefined
3. Add once-per-session warning when both models are missing (prevents log spam)
4. Add regression test for runtime.model fallback

This follows the established runtime registry pattern rather than attempting to call
extensionRunner.initialize() (which is SDK-internal and not meant for direct access).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* test: add comprehensive tests for compaction-safeguard model fallback

Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864

* fix(test): adapt compaction-safeguard tests to upstream type changes

- Add baseUrl to Model mock objects (now required by Model<Api>)
- Add explicit Model<Api> annotation to prevent provider string widening
- Cast modelRegistry mock through unknown (ModelRegistry expanded)
- Use non-null assertion for compactionHandler (TypeScript strict)
- Type compaction result explicitly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Compaction: add changelog credit for model fallback fix

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
Yuyang-0 pushed a commit to Yuyang-0/openclaw that referenced this pull request Feb 26, 2026
…penclaw#17864)

* fix(compaction): pass model through runtime to fix ctx.model undefined

Fixes openclaw#3479

Root cause: extensionRunner.initialize() is never called in compact.ts workflow,
leaving ctx.model undefined. Compaction safeguard checks ctx.model and returns
fallback summary immediately without attempting LLM summarization.

Changes:
1. Pass model through compaction safeguard runtime registry (same pattern as maxHistoryShare)
2. Fall back to runtime.model when ctx.model is undefined
3. Add once-per-session warning when both models are missing (prevents log spam)
4. Add regression test for runtime.model fallback

This follows the established runtime registry pattern rather than attempting to call
extensionRunner.initialize() (which is SDK-internal and not meant for direct access).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* test: add comprehensive tests for compaction-safeguard model fallback

Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864

* fix(test): adapt compaction-safeguard tests to upstream type changes

- Add baseUrl to Model mock objects (now required by Model<Api>)
- Add explicit Model<Api> annotation to prevent provider string widening
- Cast modelRegistry mock through unknown (ModelRegistry expanded)
- Use non-null assertion for compactionHandler (TypeScript strict)
- Type compaction result explicitly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Compaction: add changelog credit for model fallback fix

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
mylukin pushed a commit to mylukin/openclaw that referenced this pull request Feb 26, 2026
…penclaw#17864)

* fix(compaction): pass model through runtime to fix ctx.model undefined

Fixes openclaw#3479

Root cause: extensionRunner.initialize() is never called in compact.ts workflow,
leaving ctx.model undefined. Compaction safeguard checks ctx.model and returns
fallback summary immediately without attempting LLM summarization.

Changes:
1. Pass model through compaction safeguard runtime registry (same pattern as maxHistoryShare)
2. Fall back to runtime.model when ctx.model is undefined
3. Add once-per-session warning when both models are missing (prevents log spam)
4. Add regression test for runtime.model fallback

This follows the established runtime registry pattern rather than attempting to call
extensionRunner.initialize() (which is SDK-internal and not meant for direct access).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* test: add comprehensive tests for compaction-safeguard model fallback

Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864

* fix(test): adapt compaction-safeguard tests to upstream type changes

- Add baseUrl to Model mock objects (now required by Model<Api>)
- Add explicit Model<Api> annotation to prevent provider string widening
- Cast modelRegistry mock through unknown (ModelRegistry expanded)
- Use non-null assertion for compactionHandler (TypeScript strict)
- Type compaction result explicitly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Compaction: add changelog credit for model fallback fix

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
…penclaw#17864)

* fix(compaction): pass model through runtime to fix ctx.model undefined

Fixes openclaw#3479

Root cause: extensionRunner.initialize() is never called in compact.ts workflow,
leaving ctx.model undefined. Compaction safeguard checks ctx.model and returns
fallback summary immediately without attempting LLM summarization.

Changes:
1. Pass model through compaction safeguard runtime registry (same pattern as maxHistoryShare)
2. Fall back to runtime.model when ctx.model is undefined
3. Add once-per-session warning when both models are missing (prevents log spam)
4. Add regression test for runtime.model fallback

This follows the established runtime registry pattern rather than attempting to call
extensionRunner.initialize() (which is SDK-internal and not meant for direct access).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* test: add comprehensive tests for compaction-safeguard model fallback

Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864

* fix(test): adapt compaction-safeguard tests to upstream type changes

- Add baseUrl to Model mock objects (now required by Model<Api>)
- Add explicit Model<Api> annotation to prevent provider string widening
- Cast modelRegistry mock through unknown (ModelRegistry expanded)
- Use non-null assertion for compactionHandler (TypeScript strict)
- Type compaction result explicitly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Compaction: add changelog credit for model fallback fix

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…penclaw#17864)

* fix(compaction): pass model through runtime to fix ctx.model undefined

Fixes openclaw#3479

Root cause: extensionRunner.initialize() is never called in compact.ts workflow,
leaving ctx.model undefined. Compaction safeguard checks ctx.model and returns
fallback summary immediately without attempting LLM summarization.

Changes:
1. Pass model through compaction safeguard runtime registry (same pattern as maxHistoryShare)
2. Fall back to runtime.model when ctx.model is undefined
3. Add once-per-session warning when both models are missing (prevents log spam)
4. Add regression test for runtime.model fallback

This follows the established runtime registry pattern rather than attempting to call
extensionRunner.initialize() (which is SDK-internal and not meant for direct access).


* test: add comprehensive tests for compaction-safeguard model fallback

Add integration tests to verify the model fallback behavior:
- Test runtime.model fallback when ctx.model is undefined (compact.ts workflow)
- Test fallback summary when both ctx.model and runtime.model are undefined
- Test contextWindowTokens runtime storage/retrieval
- Test combined runtime values (maxHistoryShare + contextWindowTokens + model)

These tests verify the fix for issue openclaw#3479 where compaction fails due to
ctx.model being undefined in the compact.ts workflow. The runtime registry
pattern allows model to be passed when extensionRunner.initialize() is not
called, ensuring summarization works in all code paths.

Related: PR openclaw#17864

* fix(test): adapt compaction-safeguard tests to upstream type changes

- Add baseUrl to Model mock objects (now required by Model<Api>)
- Add explicit Model<Api> annotation to prevent provider string widening
- Cast modelRegistry mock through unknown (ModelRegistry expanded)
- Use non-null assertion for compactionHandler (TypeScript strict)
- Type compaction result explicitly


* Compaction: add changelog credit for model fallback fix

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling dedupe:parent Primary canonical item in dedupe cluster size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compaction always fails to generate summaries - falls back to static text

4 participants