Repository navigation
fix(context): restore the startup rule allowance to ~37,000 characters - #12657
Conversation
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsFINDING -- docs/system-specs/modules/memory-skills-hooks.md:2782 -- “under the |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Confirm #11996's fivefold base cut never intended to shrink the startup rule tier — this PR treats that as collateral, not a decision. [DESIGN-REVIEWED] 66af9a4 |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify #12431 meant the ~500K-ceiling allowance, not 7,458: this PR reverses the base spec's "22.6% of the 33,000 base" pin on that premise. The premise is well-evidenced in the checkout — the 22.6% fraction predates the base cut (165,000 × 0.226 = 37,290 matches, and What this change shipsInventory (5 items) — 5 justifiedIntent: restore the startup standing-rules block that a budget-base cut plus a later budget-binding change silently shrank ~5x — a FIX.
[FIRST-PRINCIPLES-REVIEWED] 66af9a4 |
The startup "Learned corrections" block collapsed from ~36,900 characters to ~7,158, so only 8 of a user's 607 standing rules reached the model on a fresh session. Nothing was deleted from the library; two landed changes combined: `kirodotdev#11996` moved `_CONTEXT_BUDGET_BASE` from 165,000 to 33,000, shrinking every `_budget(fraction)` cap about fivefold including `_LESSONS_CAP` (37,290 -> 7,458), and `kirodotdev#12431` then began passing `directive_budget=caps.lessons` at the four startup lesson renderers, which binds the authored rule tier at that value unconditionally. The fivefold cut was invisible until the second change, because before it the background path filled the ~500,000-character protected ceiling and dropped nothing. Bind the startup rule tier to a window-INDEPENDENT allowance instead of a fraction of the shared base: add `_LESSONS_STARTUP_CAP = 37_000` (the 165,000 x 0.226 allowance a 1M-window session shipped with before the base was pinned) plus a matching `caps.lessons_startup`, and pass that as the four startup renderers' `directive_budget`. `kirodotdev#12431`'s mechanism is kept intact; only its value changes. No budget arithmetic moves: both stores compute the tier as `min(directive_budget, <ceiling>)`, so `min(37,000, ceiling)` binds the block symmetrically on the vector path (`hard_cap`) and the JSONL path (`cap`). Tests: `test_startup_directive_tier_is_bound_by_lessons_startup_both_paths` drives the full startup path through `ContextBuilder.build_session_context` for both stores and pins the block above `caps.lessons` and inside `caps.lessons_startup`; mutation-verified (reverting a renderer to `caps.lessons` reddens it at `assert 7458 < 7027`). `test_all_caps_at_reference_window_equal_module_constants` pins `caps.lessons_startup == _LESSONS_STARTUP_CAP`. `TestLessonsCap::test_over_cap_preserves_complete_explicit_rules` sized its overflow fixture off `_LESSONS_CAP`, which the larger budget now fits, so it is sized off `_LESSONS_STARTUP_CAP` instead -- it still proves whole-entry trimming, full omission accounting, and the block staying inside its budget. Measured on a synthetic 200-rule store: JSONL 36,685 characters, vector 36,571.
37cf523 to
66af9a4
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Blocking on one number, which I checked against main rather than against the body.
37,000 is larger than the whole admission budget, so a full rule block zeroes the discretionary pool.
context.py:498--_CONTEXT_BUDGET_BASE = 33_000.context.py:1121-1123--max_contextreturnsbase, i.e. 33,000, and its own docstring says "One shared admission budget; section limits do not add capacity."context.py:3747--max_context_chars = caps.max_context.context.py:4164--remaining = max(0, max_context_chars - protected_chars).
The rule block is append_required, so it counts into protected_chars. A 37,000-character block therefore drives remaining to exactly 0 before anything discretionary is considered, and [DOCUMENTATION] (:3741), [USER PROFILE] (:3713) and the member-memory-unavailable notice (:3899) are all dropped with only "[Context budget: omitted background context]" to show for it.
The guard that looks like it would catch this does not fire. caps.protected_context is max(_PROTECTED_CONTEXT_FLOOR, window * 4 * 0.125) (:1177-1179) and _PROTECTED_CONTEXT_FLOOR = _CONTEXT_BUDGET_BASE * 3 (:1097), so it floors at 99,000 and is 500,000 at the reference window. The lessons-trimming path at :4144 needs protected_chars > caps.protected_context, which a 37,000 block never reaches. So nothing trims it and nothing warns.
This lands hardest on precisely the user the PR is for: the 607-rule user at ~36.9K loses their profile and documentation blocks to get their rules back. That is a trade, possibly the right one, but the body does not mention it and no test covers it.
Second thing, smaller: 7,458 reads as chosen, not collateral. #12431's body table assigns [Learned corrections] "the existing lessons cap (22.6% of the 33,000 base)" explicitly. _LESSONS_CAP = _budget(0.226) at context.py:1023 matches. So "value regression" is the wrong framing for a number another PR picked on purpose six hours earlier. Both AI lanes flagged this same open premise.
To clear the block, either of these works for me:
- Bound
_LESSONS_STARTUP_CAPbelowmax_contextwith enough headroom that the profile and documentation blocks still fit, and say in the body what the resulting rule allowance is; or - Keep 37,000 and land a test that asserts what actually survives when the rule block is full -- if the answer is "nothing discretionary", the test should say so and the body should state it as the accepted cost, with a word from #12431's author that the 22.6% binding is being deliberately unwound.
Also needs fixing either way: docs/system-specs/modules/memory-skills-hooks.md:2782 still opens "renders in [Learned corrections] under the lessons budget (22.6% of the 33,000 base)" and then says the tier is bound by lessons_startup. The GPT lane reported it and it is unanswered.
The rest of the diff is clean -- the four renderers at :4053/:4070/:4082/:4094 all move to caps.lessons_startup consistently, and test_default_context_admission.py:479-550 does go red if any one of them is reverted.
kirodotdev#12657) The startup "Learned corrections" block collapsed from ~36,900 characters to ~7,158, so only 8 of a user's 607 standing rules reached the model on a fresh session. Nothing was deleted from the library; two landed changes combined: `kirodotdev#11996` moved `_CONTEXT_BUDGET_BASE` from 165,000 to 33,000, shrinking every `_budget(fraction)` cap about fivefold including `_LESSONS_CAP` (37,290 -> 7,458), and `kirodotdev#12431` then began passing `directive_budget=caps.lessons` at the four startup lesson renderers, which binds the authored rule tier at that value unconditionally. The fivefold cut was invisible until the second change, because before it the background path filled the ~500,000-character protected ceiling and dropped nothing. Bind the startup rule tier to a window-INDEPENDENT allowance instead of a fraction of the shared base: add `_LESSONS_STARTUP_CAP = 37_000` (the 165,000 x 0.226 allowance a 1M-window session shipped with before the base was pinned) plus a matching `caps.lessons_startup`, and pass that as the four startup renderers' `directive_budget`. `kirodotdev#12431`'s mechanism is kept intact; only its value changes. No budget arithmetic moves: both stores compute the tier as `min(directive_budget, <ceiling>)`, so `min(37,000, ceiling)` binds the block symmetrically on the vector path (`hard_cap`) and the JSONL path (`cap`). Tests: `test_startup_directive_tier_is_bound_by_lessons_startup_both_paths` drives the full startup path through `ContextBuilder.build_session_context` for both stores and pins the block above `caps.lessons` and inside `caps.lessons_startup`; mutation-verified (reverting a renderer to `caps.lessons` reddens it at `assert 7458 < 7027`). `test_all_caps_at_reference_window_equal_module_constants` pins `caps.lessons_startup == _LESSONS_STARTUP_CAP`. `TestLessonsCap::test_over_cap_preserves_complete_explicit_rules` sized its overflow fixture off `_LESSONS_CAP`, which the larger budget now fits, so it is sized off `_LESSONS_STARTUP_CAP` instead -- it still proves whole-entry trimming, full omission accounting, and the block staying inside its budget. Measured on a synthetic 200-rule store: JSONL 36,685 characters, vector 36,571.
kirodotdev#12657) The startup "Learned corrections" block collapsed from ~36,900 characters to ~7,158, so only 8 of a user's 607 standing rules reached the model on a fresh session. Nothing was deleted from the library; two landed changes combined: `kirodotdev#11996` moved `_CONTEXT_BUDGET_BASE` from 165,000 to 33,000, shrinking every `_budget(fraction)` cap about fivefold including `_LESSONS_CAP` (37,290 -> 7,458), and `kirodotdev#12431` then began passing `directive_budget=caps.lessons` at the four startup lesson renderers, which binds the authored rule tier at that value unconditionally. The fivefold cut was invisible until the second change, because before it the background path filled the ~500,000-character protected ceiling and dropped nothing. Bind the startup rule tier to a window-INDEPENDENT allowance instead of a fraction of the shared base: add `_LESSONS_STARTUP_CAP = 37_000` (the 165,000 x 0.226 allowance a 1M-window session shipped with before the base was pinned) plus a matching `caps.lessons_startup`, and pass that as the four startup renderers' `directive_budget`. `kirodotdev#12431`'s mechanism is kept intact; only its value changes. No budget arithmetic moves: both stores compute the tier as `min(directive_budget, <ceiling>)`, so `min(37,000, ceiling)` binds the block symmetrically on the vector path (`hard_cap`) and the JSONL path (`cap`). Tests: `test_startup_directive_tier_is_bound_by_lessons_startup_both_paths` drives the full startup path through `ContextBuilder.build_session_context` for both stores and pins the block above `caps.lessons` and inside `caps.lessons_startup`; mutation-verified (reverting a renderer to `caps.lessons` reddens it at `assert 7458 < 7027`). `test_all_caps_at_reference_window_equal_module_constants` pins `caps.lessons_startup == _LESSONS_STARTUP_CAP`. `TestLessonsCap::test_over_cap_preserves_complete_explicit_rules` sized its overflow fixture off `_LESSONS_CAP`, which the larger budget now fits, so it is sized off `_LESSONS_STARTUP_CAP` instead -- it still proves whole-entry trimming, full omission accounting, and the block staying inside its budget. Measured on a synthetic 200-rule store: JSONL 36,685 characters, vector 36,571.
Problem / Motivation
The startup "Learned corrections" rule block collapsed from ~36,900 characters to
~7,158 characters, so only 8 of a user's 607 standing rules reach the model on a
fresh session. The omission notice reads:
Nothing was deleted from the library. Two landed changes combined to produce this:
#11996changed_CONTEXT_BUDGET_BASEfrom165_000to33_000(
src/kiro_crew/context.py). Every_budget(fraction)section cap shrank aboutfivefold with it, including
_LESSONS_CAP = _budget(0.226): 37,290 -> 7,458.#12431started passingdirective_budget=caps.lessonsat the four startuplesson renderers. When
directive_budgetis set,get_lessons_context/get_contextbind the authored rule tier at that value unconditionally, so therule block is pinned at 7,458 characters on every session.
The 5x cut in step 1 was invisible until step 2, because before step 2 the
background path filled the ~500,000-character protected ceiling and dropped
nothing.
Why it matters
Standing rules are the corrections a user taught the agent after a past mistake --
"never run the full pytest suite on this box", "force-push is allowed to non-main
branches", "close only bug issues, never feature issues". They are not
discretionary background material; the whole point is that they arrive on every
session. Dropping 599 of 607 means the agent silently loses almost all of its
learned corrections at startup and repeats mistakes the user already corrected.
What changed
The chain from symptom to root cause: the rule block is small (symptom) because
the authored rule tier is bounded by
caps.lessons(mechanism), andcaps.lessonsis small because it is a fraction of
_CONTEXT_BUDGET_BASE, which#11996pinnedto its smallest-window value (root cause). Standing rules were bound to a pool that
was never meant to size them.
This restores the startup rule allowance to the pre-
#119961M-window level as awindow-INDEPENDENT constant, without touching the shared budget base:
_LESSONS_STARTUP_CAP = 37_000(the 165,000 x 0.226 = 37,290 allowance a1M-window session shipped with before the base was pinned) and a matching
caps.lessons_startupresolved cap.directive_budget=caps.lessons_startupinstead ofcaps.lessons.This is a restoration of a historical allowance, not a new cost: 37,000 characters
is what a 1M-window session carried before 2026-09-19.
#12431's mechanism -- awindow-independent authored-tier budget passed as
directive_budget-- is keptintact; only its value changes.
Both store paths compute the rule-tier bound as
min(directive_budget, <ceiling>),where the ceiling is the model-safe protected bound each renderer hands in (about
500,000 characters at the 1M reference window, smaller on a smaller model). The
vector store names that outer bound
hard_cap; the JSONL store names itcap, andthe JSONL renderers already pass the ceiling into
cap. Somin(37,000, ceiling)= 37,000 binds the rule block symmetrically on both paths whenever the ceiling
exceeds it, and no budget arithmetic changes.
Tests
TestBackgroundBudgetintest/test_default_context_admission.pywithtest_startup_directive_tier_is_bound_by_lessons_startup_both_paths, driving thefull startup path through
ContextBuilder.build_session_contextfor both theJSONL and vector stores: a background render of ~200 rules (~165,000 characters)
must bound the
[Learned corrections]block atcaps.lessons_startup-- greaterthan
caps.lessons(7,458, the regression) and no larger thancaps.lessons_startupplus header/footer framing (so not the ceiling).Mutation-verified: reverting
directive_budgetat a renderer tocaps.lessonsreddens it (
assert 7458 < 7027). Ran only that file,-n0: 6 passed.test_all_caps_at_reference_window_equal_module_constantsintest/test_context_dynamic_budget.pyto pincaps.lessons_startup == _LESSONS_STARTUP_CAP. 1 passed.change applied: JSONL path 36,685 characters, vector path 36,571 characters --
both restored to ~37,000, versus ~7,000 on the pre-fix build.
Pattern harvest
Not generalizable: this is a value regression, not a code smell that semgrep could
catch. The reusable lesson is procedural -- a section cap derived from a shared
_budget(fraction)base couples an invariant that must not scale (standing rules)to a pool that was rescaled for an unrelated reason (
#11996). When a value musthold across model windows it should be a named window-independent constant, not a
fraction of a base another change is free to move. The two callers here also name
the same role differently (
hard_capvscap), which briefly masked the fix.Any other suggestions on the work
learn.py'sget_contextusescapfor the SAME role thatvector_memory.py'sget_lessons_contextcallshard_cap: the outer ceiling the authored tier istaken smaller than, NOT the ordinary
caps.lessonsbudget. This naming collisionis a real footgun (it briefly looked like the JSONL path needed a different fix)
and is worth a standalone cleanup -- out of scope here.
_CONTEXT_BUDGET_BASEcut from 165,000 to 33,000 in#11996also shrank everyOTHER section cap (preferences, projects, history, semantic, episodic, skills,
steering) about fivefold. This PR deliberately addresses only the standing-rule
tier and does not touch the shared base or the other caps.