Diagnosing Unusual Token Consumption in LLM Coding Assistants: Context Compression and Caching
Quota can drain faster than expected after a tool update, but that alone does not prove a tool defect. This guide explains how automatic context compression, cache misses, sub-agent parallelism, and retries can each raise billed tokens. It also lays out a baseline-first troubleshooting process, using per-request metrics, controlled comparisons, and billing review to separate tool regressions from changes in usage patterns or billing.
1. Define the “Consumption Anomaly” First
Faster quota depletion does not by itself mean the tool is defective. Before investigating, break consumption down into observable metering dimensions. Otherwise, looking only at how fast the balance falls makes it easy to confuse normal fluctuation, changes in the statistics window, changes in caching behavior, and actual tool regressions.
Anonymous feedback reports that after a recent version update, quota consumption of a certain LLM coding assistant accelerated noticeably. Usage that previously accounted for about 20% rose to 50% in a short period. Some users said quota that used to last hours ran out within twenty-odd minutes, even though their workload had not changed significantly. One high-usage user reported roughly 72 automatic context compressions in one day: 17 in the main agent, and 21, 17, and 17 in three sub-agents. Context before compression was about 240K to 250K tokens, and 140K to 160K tokens remained afterward. Other feedback said the original cache prefix was hard to hit after compression, and that compression combined with cache misses may be one reason consumption was amplified.
These signals deserve attention, but they do not prove the tool is at fault. A more rigorous approach starts with a baseline. Under the same task set, model version, tool version, and cache state, compare each request’s raw input tokens, compressed input tokens, output tokens, compression overhead, cache hit and miss tokens, retry count, sub-agent count, and final billed tokens. The core metric is billed tokens per effective output token. Only this metric shows whether consumption is actually abnormal.
2. How Automatic Compression Can Amplify Consumption
Automatic context compression usually triggers when a session approaches a length threshold. The feedback mentions a trigger threshold of about 244,800 tokens, with 240K to 250K tokens before compression and 140K to 160K retained after. Two points matter here. First, compression is not free. Generating a summary or rewriting history consumes input and output tokens. Second, the retained context is still large and sits close to the threshold, so another compression can fire within a short interval.
If the compression strategy keeps too much history, produces a long summary, or fails to free enough space, the session can fall into a cycle of compressing, sending a request, and compressing again. This threshold oscillation is a strong candidate for runaway consumption. Seventy-two compressions in one day is a strong signal, but the count needs normalizing. How many requests, sessions, sub-agents, and effective outputs did it correspond to? If request density and sub-agent count rose together, a higher compression count may simply reflect a change in usage. If request volume and task complexity stayed roughly stable while the compression count and compression overhead share rose significantly, a tool-side regression or a change in compression strategy becomes more likely.
Pay particular attention to sub-agent compression counts. The main agent compressed 17 times, and three sub-agents compressed 21, 17, and 17 times. This suggests compression is not a single-path behavior. Several chains compressed in parallel. If each sub-agent carries its own context, tool results, and compression history, the total token count may far exceed that of the main chain. Troubleshooting must aggregate by session and by parent-child relationship, not just examine individual requests.
3. Cache Prefix Invalidation and Statistical Definitions
Caching in multi-turn conversations usually depends on a stable prefix. Once compression rewrites history messages, system prompts, tool results, or message order, the prefix hash changes, and the existing cache cannot be reused directly. The feedback says both that the cache hit ratio after compression is high and that the original cache cannot be hit directly. These statements look contradictory, but they likely reflect different definitions. The hit ratio may be calculated only within the new compressed prefix, while the original prefix has already been invalidated. Alternatively, the ratio may cover the whole session, which hides misses at the compression boundary.
For this reason, a single “cache hit rate” metric is not enough. Record the prefix hash before compression, the prefix hash after compression, cache hit tokens, cache miss tokens, billed tokens, and the input and output cost of the compression summary. If prefix hashes change frequently after compression, the share of miss tokens rises, and compression summaries are billed, the costs stack up. Compression overhead, cache misses, and normal request output together push consumption higher.
4. Multiplier Effects of Sub-Agent Parallelism and Retries
An architecture with one main agent and several sub-agents easily produces a multiplier effect. Each sub-agent may independently read the same context, call tools repeatedly, and generate similar summaries. If cache keys are designed inconsistently, identical content can be billed more than once. Parallel scheduling also causes retries and replays of failed requests. One failed request may trigger several replays, and each replay carries long context, which further increases consumption.
During troubleshooting, calculate the share of consumption that comes from sub-agents, the duplicate request rate, the retry rate, and the compression count and retained tokens for each sub-agent. If consumption drops significantly after disabling sub-agent parallelism or limiting the maximum number of turns, the cause is more likely in usage patterns or scheduling strategy than in a single tool defect.
5. How to Interpret the Anonymous Feedback
For the report that usage rose from 20% to 50%, confirm whether the statistics window is daily, weekly, or the billing cycle, and whether it includes sub-agents, compression overhead, and retries. Quota that lasted hours and then ran out in twenty-odd minutes may reflect higher request density, cache misses, compression loops, retries, or a combination of these. The 72 compressions need to be normalized against request counts, session counts, and sub-agent counts.
Going from 240K to 250K tokens before compression to 140K to 160K afterward frees roughly 80K to 100K tokens. If the threshold is about 244.8K, the retained context is still close to it, so the risk of recompression within a short interval is high. The original feedback does not list the input values of the first normal request after each of the three compressions. Real troubleshooting must collect the input, cache prefix, output length, and billing details for those requests. Compression counts alone do not support a conclusion.
6. A Practical Troubleshooting Path
Step 1: Build a fixed task set and a control baseline. Record each request’s raw input, compressed input, output, compression overhead, cache hits and misses, billed tokens, retry count, and sub-agent count.
Step 2: Add structured log fields. Include request ID, session ID, parent request ID, model version, tool version, compression count, threshold, retained tokens, prefix hashes before and after compression, cache hit and miss tokens, billed tokens, retry count, and sub-agent count.
Step 3: Calculate core metrics. Track billed tokens per effective output token, compression overhead share, compression interval distribution, cache miss rate, sub-agent share of consumption, and retry rate.
Step 4: Run a bisection comparison. Hold the model version fixed and switch tool versions or configuration. Disable sub-agent parallelism. Adjust the compression threshold or retention ratio. Roll back to the previous version in a canary release.
Step 5: Review billing details. Check whether compression summaries are billed, whether cache misses are billed at a higher rate, and whether tool calls and retries are counted.
The following pseudocode sets up an observation model:
type RequestTrace = {request_id, session_id, parent_id, model_version, tool_version,raw_input_tokens, compressed_input_tokens, output_tokens,compress_count, compress_input_tokens, compress_output_tokens,threshold_tokens, retained_tokens, prefix_hash_before, prefix_hash_after,cache_hit_tokens, cache_miss_tokens, billed_tokens,retry_count, child_agent_count, start_time, end_time}for t in traces:overhead = t.compress_input_tokens + t.compress_output_tokenscompression_ratio = overhead / max(t.billed_tokens, 1)cache_miss_ratio = t.cache_miss_tokens /max(t.cache_hit_tokens + t.cache_miss_tokens, 1)if t.compress_count > 0 and t.retained_tokens is close to t.threshold_tokens:alert("Insufficient headroom after compression, risk of threshold oscillation")
The ratio thresholds in this example are only observation rules. They should not be read as a fixed billing rule for any product. Real judgments must combine version comparisons with billing details.
7. Decision Matrix: Tool Defect, Configuration Issue, or Amplified Usage Pattern
| Symptom | Likely cause | How to verify |
|---|---|---|
| Billing for identical requests rises, compression counts are abnormal, and cache miss rate rises at the same time | Tool-side regression or compression strategy regression | Canary rollback, version comparison, prefix hash comparison |
| Compression summary tokens are billed, and cache misses are billed at a higher cost | Billing rules or caching semantics changed | Billing details review, billing rule check |
| Retained context after compression is too large, and compression repeats at short intervals | Configuration or strategy issue | Compare results with adjusted threshold and retention ratio |
| Sub-agent count increases and retry rate rises | Usage pattern or scheduling amplification | Compare results after limiting concurrency and turns |
| Balance drops quickly, but billed tokens per request stay stable | Statistics window or quota period change | Check quota period and statistics definitions |
8. Optimization and Governance Recommendations
First, control compression frequency. Re
