Prompt budget should account for non-transcript prompt material (identity, skills, tool schemas)
Problem
The prompt context budget sizes only the transcript. Identity/SYSTEM.md content, skill and memory snippets, channel context, and tool schemas are assembled on top of the transcript allowance without reducing it, so the request the provider receives can exceed the budget the loop believes it is honoring.
This predates #8053: under the compiled-in 128k/20k default, 108k of transcript plus the 20k reserve had the same exposure. #8053 (model-derived budgets) does not widen it for windows ≥ ~89k, where the reserve is the same flat 20k, but for smaller windows the reserve clamps to limit/4 (9k at a 40k window) and the non-transcript material becomes a proportionally larger share — the identity lane alone can admit ~8k.
Surfaced by review on #8053 (thread on crates/loop/ironclaw_turn_runner/src/loop_driver_host.rs); deferred there because the fix belongs at a different seam.
Where the fix belongs
At prompt assembly in ThreadBackedLoopModelPort (crates/loop/ironclaw_loop_host/src/lib.rs), where identity, skill-snippet, and tool-schema sizes are actually known: measure the non-transcript material with the same chars/4 estimator and subtract it from visible_transcript_tokens() before select_prompt_context_messages runs. Compaction's threshold (ironclaw_agent_loop DefaultCompactionStrategy::can_evaluate) should see the same reduced allowance so the two consumers keep sharing one number.
Not a bigger fudge factor on the 90% margin in PromptContextTokenBudget::from_advertised_window — that only moves the cliff.
Acceptance
- A crate-tier test in
ironclaw_loop_hostthat seeds a transcript plus an identity/skill payload near the budget and asserts the provider receives a request whose total estimated tokens ≤context_limit_tokens - reserve. - The existing
None-window tests keep proving unadvertised runs are byte-for-byte today's behavior. - Design note
docs/internal/reborn/design/model-derived-context-budget.mdgains the accounting rule.
Related: #8053.
Source: nearai/ironclaw