Skip to content

context-budget early-stop check reports fixed cached_prompt_tokens on turn-0 regardless of actual request size #6332

Description

@bug-ops

Description

While attempting the mandatory LLM Serialization Gate live-session test for #6240 (spec-072 P2, MCP image passthrough), a local Ollama single-provider session (qwen2.5:7b) hit a context-budget early-stop check that reported a fixed cached_prompt_tokens = 100106 on turn 0, before any LLM call had ever been made in the session.

The actual well-formed request, captured in a debug dump once the check was bypassed (context_budget_tokens/auto_budget=false), measured ~17-18K tokens by char/4 estimate (49711+68 char messages + 18401 char tool-schema JSON) — nowhere near 100106.

This number was byte-for-byte identical across every config permutation tried: skills enabled/disabled, index enabled/disabled, working vs. broken embedding provider, instruction_auto_detect on/off. This strongly suggests cached_prompt_tokens is stale/mis-seeded on the very first turn, independent of the real assembled message size.

This is unrelated to spec-072/#6240's own changes — it surfaced only as an environmental blocker while trying to run that PR's live-session gate, and is reproducible with any single-provider Ollama config.

Reproduction Steps

  1. Configure a single-provider Ollama session (e.g. qwen2.5:7b) with debug dumps enabled (format = "raw").
  2. Start a fresh session (no prior turns) with a moderately sized system prompt + tool schemas (~17-18K tokens total).
  3. Observe the turn's context-budget early-stop check in tier_loop.rs::process_single_native_turn (self.context_manager.budget) before any LLM call is made.
  4. Compare the reported cached_prompt_tokens value against the actual assembled request size in the debug dump.

Expected Behavior

On turn 0 (no prior LLM calls in the session), cached_prompt_tokens should reflect the actual size of the request about to be sent (or be absent/zero if no prior cache exists), not a fixed unrelated value.

Actual Behavior

cached_prompt_tokens reports a fixed 100106 on turn 0 regardless of the real request size (~17-18K tokens), identical across every config permutation tried (skills on/off, index on/off, embedding provider working/broken, instruction_auto_detect on/off).

Environment

  • Version: 0.22.1 (unreleased, discovered on branch feat/issue-6240/mcp-media-sanitizer)
  • Features: local Ollama provider, qwen2.5:7b, debug dumps (raw format) enabled

Logs / Evidence

Discovered and documented during the developer handoff for #6240 (PR #6331): .local/handoff/2026-07-16T19-16-56-developer.md, section "Mandatory LLM Serialization Gate — Live Session Test Result", blocker #4.

Metadata

Metadata

Assignees

Labels

P2High value, medium complexitybugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions