From 013b779e3076becb4ccb71770a4629aa1f51033b Mon Sep 17 00:00:00 2001 From: HAL9000 Date: Fri, 8 May 2026 06:04:22 +0000 Subject: [PATCH 1/6] fix(v3.7.1): Align ContextTierService default budget values with TierBudget model (#1443) The DEFAULT_MAX_TOKENS_HOT was 8000 (should be 16000), DEFAULT_MAX_DECISIONS_WARM was 500 (should be 100), and DEFAULT_MAX_DECISIONS_COLD was 5000 (should be 500). These values in context_tier_settings.py did not match the canonical defaults defined in TierBudget model (tiers.py) or Settings class defaults, causing incorrect budget enforcement when settings were None. ISSUES CLOSED: #1443 --- CHANGELOG.md | 2 + CONTRIBUTORS.md | 1 + .../tdd_context_tier_defaults_1443_steps.py | 105 ++++++++++++++++++ .../tdd_context_tier_defaults_1443.feature | 46 ++++++++ .../services/context_tier_settings.py | 6 +- 5 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 features/steps/tdd_context_tier_defaults_1443_steps.py create mode 100644 features/tdd_context_tier_defaults_1443.feature diff --git a/CHANGELOG.md b/CHANGELOG.md index 55341d793..db171f2c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -235,6 +235,8 @@ ensuring data is stored with proper parameter values. under `.opencode/` are covered by the lint gate. ### Fixed +- **ContextTierService defaults aligned with TierBudget model** (#1443): Fixed three budget default constants in ``context_tier_settings.py`` that did not match the canonical ``TierBudget`` model defaults. ``DEFAULT_MAX_TOKENS_HOT`` was 8000 but should match the ``TierBudget`` default of 16000; ``DEFAULT_MAX_DECISIONS_WARM`` was 500 but should be 100; and ``DEFAULT_MAX_DECISIONS_COLD`` was 5000 but should be 500. These incorrect values caused wrong budget enforcement when settings were not provided (i.e. ``budget_from_settings(None)``). + - **ACMS execute-phase assembler respects project-level hot_max_tokens** (#11035): Fixed ``_resolve_hot_max_tokens()`` to read ``hot_max_tokens`` from ``context_policy_json["acms_config"]["hot_max_tokens"]`` — the correct sub-key written diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 8b384231f..6c6a7a35f 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -108,6 +108,7 @@ Below are some of the specific details of various contributions. * HAL 9000 has contributed the ContextStrategy protocol and plugin registration system (PR #11106 / issue #8616): implemented the domain-model `ContextStrategy` Protocol with BackendSet, PlanContext, StrategyCapabilities, StrategyConfig, ContextStrategyResult, and StrategyRegistryEntry models. Six built-in strategies each implement real backend query logic respecting budget constraints. The StrategyRegistry service provides thread-safe registration/unregistration, Pydantic-validated config updates with immutable MappingProxyType fields, plugin discovery via register_from_module() with CWE-706 module-prefix allowlist guard, enabled list management, deterministic fragment ordering, and validation warnings. Comprehensive BDD test coverage in features/context_strategies.feature and features/context_strategy_registry.feature (120+ scenarios) (#8616). * HAL 9000 has contributed the A2A stdio transport for local mode (#691): implemented ``A2aStdioTransport`` class with JSON-RPC 2.0 message framing over stdin/stdout for subprocess communication, including process lifecycle management (connect/disconnect), request/response serialization, graceful shutdown with timeout-based termination, and type-safe path resolution for Python modules vs. executable scripts. Added full BDD test coverage (18 scenarios) in ``features/a2a_stdio_transport.feature`` with mock subprocess behavior in step definitions. * HAL 9000 has contributed the `plan apply --format json` spec-compliant envelope fix (PR #9817 / issue #9449): replaced raw plan dictionary output with a spec-required JSON envelope containing structured data fields for artifacts, changes, validation, sandbox cleanup, and lifecycle metrics across all output formats. Full BDD test suite in behave + Robot Framework integration tests added. +* HAL 9000 has contributed the ContextTierService defaults fix (PR #1485 / issue #1443): corrected spec-aligned default values for `max_tokens_hot` (16000), `max_decisions_warm` (100), and `max_decisions_cold` (500) in ``context_tier_settings.py``. Added comprehensive BDD regression tests verifying all three interface contracts. (Parent Epic: #935) # Details (PR Contributions) diff --git a/features/steps/tdd_context_tier_defaults_1443_steps.py b/features/steps/tdd_context_tier_defaults_1443_steps.py new file mode 100644 index 000000000..88fd5d96b --- /dev/null +++ b/features/steps/tdd_context_tier_defaults_1443_steps.py @@ -0,0 +1,105 @@ +"""Step definitions for TDD Issue #1443 regression tests. + +Verifies that :file:`context_tier_settings.py` uses spec-aligned default values +(hot=16000, warm=100, cold=500) rather than the old wrong values +(hot=8000, warm=500, cold=5000). + +Tests ``budget_from_settings(None)`` and module-level :data:`DEFAULT_MAX_*` constants. + +See: https://git.cleverthis.com/cleveragents/cleveragents-core/issues/1443 +""" + +from __future__ import annotations + +from typing import Any + +from behave import given, then, when + +from cleveragents.application.services.context_tier_settings import ( + DEFAULT_MAX_DECISIONS_COLD, + DEFAULT_MAX_DECISIONS_WARM, + DEFAULT_MAX_TOKENS_HOT, + budget_from_settings, +) + +__all__: list[str] = [] + +# Spec-aligned correct defaults and old wrong values (for assertion in steps) +_SPEC_HOT: int = 16000 +_SPEC_WARM: int = 100 +_SPEC_COLD: int = 500 +_OLD_HOT: int = 8000 +_OLD_WARM: int = 500 +_OLD_COLD: int = 5000 + + +# --- budget_from_settings scenario steps --- + + +@given("the budget helper has not been called yet") +def step_given_budget_helper_not_called(context: Any) -> None: + if not hasattr(context, "_budget_result"): + context._budget_result = None + + +@when("I invoke budget_from_settings with None config") +def step_when_invoke_budget_helper(context: Any) -> None: + context._budget_result = budget_from_settings(None) + + +# --- Budget capacity assertions (avoid collision with {val:d} param patterns) --- + +@then("the budget hot capacity matches 16000") +def step_then_budget_hot_16000(context: Any) -> None: + """Verify budget.max_tokens_hot is the spec value, not the old wrong one.""" + assert context._budget_result.max_tokens_hot == _SPEC_HOT + assert context._budget_result.max_tokens_hot != _OLD_HOT + + +@then("the budget warm capacity matches 100") +def step_then_budget_warm_100(context: Any) -> None: + """Verify budget.max_decisions_warm is the spec value, not the old wrong one.""" + assert context._budget_result.max_decisions_warm == _SPEC_WARM + assert context._budget_result.max_decisions_warm != _OLD_WARM + + +@then("the budget cold capacity matches 500") +def step_then_budget_cold_500(context: Any) -> None: + """Verify budget.max_decisions_cold is the spec value, not the old wrong one.""" + assert context._budget_result.max_decisions_cold == _SPEC_COLD + assert context._budget_result.max_decisions_cold != _OLD_COLD + + +# --- Module constant scenarios --- + +@given("the module default constants exist") +def step_given_module_constants_exist(context: Any) -> None: + """Verify we can import the module-level DEFAULT_MAX_* constants.""" + pass # Already imported at module level above + + +@when( + "I read DEFAULT_MAX_TOKENS_HOT, DEFAULT_MAX_DECISIONS_WARM and " + "DEFAULT_MAX_DECISIONS_COLD" +) +def step_when_read_module_constants(context: Any) -> None: + context._hot_const = DEFAULT_MAX_TOKENS_HOT + context._warm_const = DEFAULT_MAX_DECISIONS_WARM + context._cold_const = DEFAULT_MAX_DECISIONS_COLD + + +@then("all three module constants must equal spec-aligned values") +def step_then_module_constants_correct(context: Any) -> None: + assert context._hot_const == _SPEC_HOT + assert context._warm_const == _SPEC_WARM + assert context._cold_const == _SPEC_COLD + + +# --- Anti-regression assertion --- + +@then("every budget field must NOT be an old wrong default value") +def step_then_budget_not_legacy(context: Any) -> None: + """Ensure none of the three fields reverted to old wrong defaults.""" + assert context._budget_result.max_tokens_hot not in (_OLD_HOT,) + assert context._budget_result.max_decisions_warm not in (_OLD_WARM,) + assert context._budget_result.max_decisions_cold not in (_OLD_COLD,) diff --git a/features/tdd_context_tier_defaults_1443.feature b/features/tdd_context_tier_defaults_1443.feature new file mode 100644 index 000000000..d024eee81 --- /dev/null +++ b/features/tdd_context_tier_defaults_1443.feature @@ -0,0 +1,46 @@ +# TDD regression test for bug #1443 - context_tier_settings.py wrong defaults. +# +# Issue #1443 documented that DEFAULT constants in ``context_tier_settings.py`` +# were hardcoded to wrong values (hot=8000, warm=500, cold=5000) instead of the +# spec-aligned values (hot=16000, warm=100, cold=500). This test verifies that +# ``budget_from_settings(None)`` and module-level default constants use correct +# spec-defined values. +# +# See: https://git.cleverthis.com/cleveragents/cleveragents-core/issues/1443 + +@tdd_issue @tdd_issue_1443 +Feature: TDD Issue #1443 - Correct defaults in context_tier_settings.py + + As a developer calling budget_from_settings with no configuration + I want the returned TierBudget to use spec-defined capacity limits + So that hot/warm/cold tier eviction behavior matches the specification + + @tdd_issue @tdd_issue_1443 + Scenario: budget_from_settings(None) hot value meets spec 16000 + Given the budget helper has not been called yet + When I invoke budget_from_settings with None config + Then the budget hot capacity matches 16000 + + @tdd_issue @tdd_issue_1443 + Scenario: budget_from_settings(None) warm value meets spec 100 + Given the budget helper has not been called yet + When I invoke budget_from_settings with None config + Then the budget warm capacity matches 100 + + @tdd_issue @tdd_issue_1443 + Scenario: budget_from_settings(None) cold value meets spec 500 + Given the budget helper has not been called yet + When I invoke budget_from_settings with None config + Then the budget cold capacity matches 500 + + @tdd_issue @tdd_issue_1443 + Scenario: Module-level DEFAULT_MAX constants match spec values + Given the module default constants exist + When I read DEFAULT_MAX_TOKENS_HOT, DEFAULT_MAX_DECISIONS_WARM and DEFAULT_MAX_DECISIONS_COLD + Then all three module constants must equal spec-aligned values + + @tdd_issue @tdd_issue_1443 + Scenario: budget_from_settings result differs from old wrong defaults entirely + Given the budget helper has not been called yet + When I invoke budget_from_settings with None config + Then every budget field must NOT be an old wrong default value diff --git a/src/cleveragents/application/services/context_tier_settings.py b/src/cleveragents/application/services/context_tier_settings.py index d52f74831..6c3b65f9c 100644 --- a/src/cleveragents/application/services/context_tier_settings.py +++ b/src/cleveragents/application/services/context_tier_settings.py @@ -18,9 +18,9 @@ from cleveragents.domain.models.acms.tiers import TierBudget # Default budget when settings are not provided # --------------------------------------------------------------------------- -DEFAULT_MAX_TOKENS_HOT = 8000 -DEFAULT_MAX_DECISIONS_WARM = 500 -DEFAULT_MAX_DECISIONS_COLD = 5000 +DEFAULT_MAX_TOKENS_HOT = 16000 +DEFAULT_MAX_DECISIONS_WARM = 100 +DEFAULT_MAX_DECISIONS_COLD = 500 # --------------------------------------------------------------------------- # Default runtime policy values -- 2.52.0 From e517f22b4f88fe88906538e829edeafc3894ec37 Mon Sep 17 00:00:00 2001 From: controller-ci-rerun Date: Fri, 29 May 2026 22:45:29 -0400 Subject: [PATCH 2/6] chore: re-trigger CI [controller] -- 2.52.0 From 15555c2264215f50eb85b9e8d39c6f2b4dbe3742 Mon Sep 17 00:00:00 2001 From: CleverThis Date: Sat, 30 May 2026 00:27:59 -0400 Subject: [PATCH 3/6] style(acms): apply ruff format to tdd_context_tier_defaults_1443_steps.py ISSUES CLOSED: #1443 --- features/steps/tdd_context_tier_defaults_1443_steps.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/features/steps/tdd_context_tier_defaults_1443_steps.py b/features/steps/tdd_context_tier_defaults_1443_steps.py index 88fd5d96b..321ed5f79 100644 --- a/features/steps/tdd_context_tier_defaults_1443_steps.py +++ b/features/steps/tdd_context_tier_defaults_1443_steps.py @@ -49,6 +49,7 @@ def step_when_invoke_budget_helper(context: Any) -> None: # --- Budget capacity assertions (avoid collision with {val:d} param patterns) --- + @then("the budget hot capacity matches 16000") def step_then_budget_hot_16000(context: Any) -> None: """Verify budget.max_tokens_hot is the spec value, not the old wrong one.""" @@ -72,6 +73,7 @@ def step_then_budget_cold_500(context: Any) -> None: # --- Module constant scenarios --- + @given("the module default constants exist") def step_given_module_constants_exist(context: Any) -> None: """Verify we can import the module-level DEFAULT_MAX_* constants.""" @@ -97,6 +99,7 @@ def step_then_module_constants_correct(context: Any) -> None: # --- Anti-regression assertion --- + @then("every budget field must NOT be an old wrong default value") def step_then_budget_not_legacy(context: Any) -> None: """Ensure none of the three fields reverted to old wrong defaults.""" -- 2.52.0 From 7bf25857ae274958f50950da2ec1340f34e7c101 Mon Sep 17 00:00:00 2001 From: controller-ci-rerun Date: Tue, 16 Jun 2026 18:17:49 -0400 Subject: [PATCH 4/6] chore: re-trigger CI [controller] -- 2.52.0 From b6ff615335d81609adf7d0baa4cb9e3ab2658dee Mon Sep 17 00:00:00 2001 From: controller-ci-rerun Date: Tue, 16 Jun 2026 20:23:27 -0400 Subject: [PATCH 5/6] chore: re-trigger CI [controller] -- 2.52.0 From 60aa41553bafac3df38fbda607faf71280b4701b Mon Sep 17 00:00:00 2001 From: controller-ci-rerun Date: Tue, 16 Jun 2026 20:50:35 -0400 Subject: [PATCH 6/6] chore: re-trigger CI [controller] -- 2.52.0