Skip to content

LCORE-4764: size the compaction tiers with the summarizer model's context window - #3356

Merged
tisnik merged 1 commit into
lightspeed-core:mainfrom
max-svistunov:lcore-4764-compaction-context-window
Nov 27, 2026
Merged

tisnik merged 1 commit into
lightspeed-core:mainfrom
max-svistunov:lcore-4764-compaction-context-window

Conversation

@max-svistunov

@max-svistunov max-svistunov commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

LCORE-4764: the agent builder's CompactionFactory (#3204) attached TieredCompaction with context_window = None, so every tier sized its work against the harness default instead of the selected model's window. This resolves the window for the summarizer model the settings name, through resolve_context_window from LCORE-4765: catalog metadata first, then the configured context_windows map, then the bundled model data, then the default. Settings that name no provider and model leave the window to the harness, as before.

With this, the attach the ticket asks for is complete on the new builder: the capability comes from build_tiered_compaction (LCORE-4692), announces itself on the run stream (LCORE-4693), and now knows the model's window. What still does not exist is a request going through the new builder; that is the endpoint switch-over (LCORE-4727 to 4729), and the live check of compaction waits for it and for continuation (LCORE-4719).

One commit, 43 lines, no API or configuration change.

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library [pyproject.toml + uv.lock]
  • Bump-up dependent library [requirements.*.txt for Konflux]
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement
  • Benchmarks improvement

Tools used to create PR

Identify any AI code assistants used in this PR (for transparency and review context)

  • Assisted-by: Claude Opus 4.8
  • Generated by: Claude Opus 4.8

Related Tickets & Documents

  • Related Issue # LCORE-4764
  • Closes # LCORE-4764

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

uv run pytest tests/unit/agent/capabilities/compaction/test_factory.py tests/unit/utils/test_tiered_compaction.py tests/unit/utils/test_context_window.py -v

41 passed. The factory tests now patch the resolver and check that it is called with provider/model and the inference configuration and that its result reaches build_tiered_compaction; a new test checks that settings without a provider and model look nothing up and pass None. ruff, black, pydocstyle, mypy and pylint (10.00) are clean on the two files; the two pyright errors in the test file are on main already. No stack run: no request reaches the new builder yet.

Summary by CodeRabbit

  • Improvements
    • Compaction now accounts for the configured model’s context window when available, helping summaries better fit the model’s capacity.
    • When provider or model settings are unavailable, compaction continues to use the existing default behavior.

…text window

The agent builder's CompactionFactory attached TieredCompaction with no
context window, so every tier sized its work against the harness default
instead of the model's. Resolve the window for the summarizer model the
settings name, through resolve_context_window (LCORE-4765): catalog
metadata first, then the configured map, then the bundled model data, then
the default. Settings that name no provider and model leave the window to
the harness, as before.

The factory tests patch the resolver and check that its result reaches
build_tiered_compaction, and that nothing is looked up without a model.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The compaction factory now resolves the summarizer model’s context window when provider and model settings are available. It passes the resolved value to the tiered builder. Without both settings, it passes None.

Changes

Compaction context window

Layer / File(s) Summary
Resolve and test the summarizer context window
src/agent/capabilities/compaction/factory.py, tests/unit/agent/capabilities/compaction/test_factory.py
The factory resolves the context window using the combined provider/model name and inference configuration when both settings are present. Tests verify the resolved value and the None fallback when provider or model is unspecified.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Possibly related PRs

Suggested reviewers: jrobertboos, tisnik

Merge Risk: Minimal · up to 8d04b

The compaction factory now sizes its tiers using the summarizer model's context window when provider and model settings are present. Requests do not yet go through this builder, so production impact is minimal and no merge-blocking risk is evident.

Pre-merge checks: Passed 6

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: compaction tiers are now sized using the summarizer model's context window. The raw summary confirms that CompactionFactory.build_capability resolves the window for th…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Performance And Algorithmic Complexity Passed Performance and Algorithmic Complexity: clean. Changed code (src/agent/capabilities/compaction/factory.py, +13/-4): - CompactionFactory.build_capability now calls `resolve_context_window(f"{provider…
Security And Secret Handling Passed PASSED. Scope checked: the two changed files, src/agent/capabilities/compaction/factory.py and tests/unit/agent/capabilities/compaction/test_factory.py. - Secrets: no hardcoded or logged secrets. …
Full details: Title check

Explanation

The title names the main change: compaction tiers are now sized using the summarizer model's context window. The raw summary confirms that CompactionFactory.build_capability resolves the window for the configured provider and model and passes it on, and that the tests cover the resolved and omitted cases. The title is specific and matches the changeset. The objectives note that endpoint switch-over is still pending, but that does not make the title misleading.

Full details: Performance And Algorithmic Complexity

Explanation

Performance and Algorithmic Complexity: clean. Changed code (src/agent/capabilities/compaction/factory.py, +13/-4): - CompactionFactory.build_capability now calls resolve_context_window(f"{provider}/{model}", configuration.inference) once per build, only when both provider and model are set. The call sits outside any loop. - No O(n^2) work, N+1 pattern, pagination gap, or unbounded cache is introduced. Cost of the called code (src/utils/context_window.py, unchanged by this PR): - resolve_context_window makes a catalog lookup, a dict .get, a model search, and, on a miss, resolve_context_window_automatically. - The latter is @lru_cache(maxsize=256) and reads bundled genai-prices data with no network call. Its docstring states this. - The cache is bounded, so it does not add unbounded growth. Call frequency: the factory runs from src/agent/factory.py line 75. The PR states that no request reaches the new builder yet, so the added lookup is not on a request hot path. Even if it were, it is a single bounded lookup per build. Test changes do not affect runtime behavior.

Full details: Security And Secret Handling

Explanation

PASSED. Scope checked: the two changed files, src/agent/capabilities/compaction/factory.py and tests/unit/agent/capabilities/compaction/test_factory.py. - Secrets: no hardcoded or logged secrets. The test diff has no added lines matching key, token, secret, password, log, or api. - Auth/authz: no API endpoints or auth paths are added or changed. - Injection: the only new logic builds the string f"{settings.provider}/{settings.model}" and passes it to resolve_context_window. This is a model-identifier lookup, not a SQL, shell, or path operation. It is internal config, not user request input in this diff. - Sensitive data exposure: no API responses, WebSocket messages, or logs are changed. - K8s/RH secrets: no manifests or secret objects are changed. The PR replaces a None context window with a resolver call. The diff adds no security-relevant behavior.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Simplify code

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1721e78 and 8d04b64.

Files selected for processing: 2

  • src/agent/capabilities/compaction/factory.py
  • tests/unit/agent/capabilities/compaction/test_factory.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 17

  • GitHub Check: E2E: ci / shields
  • GitHub Check: E2E: ci / mcp
  • GitHub Check: E2E: ci / default
  • GitHub Check: E2E: ci / authorized
  • GitHub Check: E2E: ci / rbac
  • GitHub Check: E2E: ci / other
  • GitHub Check: E2E: ci / skills
  • GitHub Check: dispatch / Harness dispatch
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: unit_tests (3.14)
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: integration_tests (3.14)
  • GitHub Check: integration_tests (3.12)
  • GitHub Check: mypy
  • GitHub Check: integration_tests (3.13)
  • GitHub Check: Pylinter
  • GitHub Check: build-pr
Additional context used

Code guidelines: 2

AGENTS.md — auto-discovered
CLAUDE.md — auto-discovered
Path-based instructions: 4

Source excerpt: **Required**: Use pytest for all unit and integration tests Source excerpt: **Forbidden**: Do not use unittest - pytest is the standard for this project Source excerpt: **Coverage**: Unit tests require 60% coverage, integrat...

CodeRabbit inference engine (AGENTS.md)

Files:

  • tests/unit/agent/capabilities/compaction/test_factory.py
Source excerpt: **Required**: Use pytest for all unit and integration tests Source excerpt: **Forbidden**: Do not use unittest - pytest is the standard for this project Source excerpt: **Mocking**: `pytest-mock` for AsyncMock objects

CodeRabbit inference engine (CLAUDE.md)

Files:

  • tests/unit/agent/capabilities/compaction/test_factory.py
Source excerpt: **Coverage**: Unit tests require 60% coverage, integration 10% Source excerpt: **Async tests**: Use marker `pytest.mark.asyncio`

CodeRabbit inference engine (CLAUDE.md)

Files:

  • tests/unit/agent/capabilities/compaction/test_factory.py
Source excerpt: **Mocking**: `pytest-mock` for AsyncMock objects Source excerpt: **Async tests**: Use marker `pytest.mark.asyncio`

CodeRabbit inference engine (AGENTS.md)

Files:

  • tests/unit/agent/capabilities/compaction/test_factory.py

@tisnik tisnik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@tisnik
tisnik merged commit f09972f into lightspeed-core:main Nov 27, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants