Troubleshooting Unexpected Usage Spikes in Subscription-Based Coding Agents
A practical guide to investigating unusually fast quota consumption in AI coding agents. It explains how to distinguish subscription quotas from usage-based billing, identify the main cost multipliers, diagnose repeated context compaction and cache invalidation, design request-level observability, and run controlled experiments before attributing the issue to a platform defect.
1. What Community Reports Can—and Cannot—Prove
Since a certain point in time, some developers have reported that subscription-based AI coding agents consume quotas much faster than before. Tasks that previously used roughly 20% of the available quota reportedly consumed nearly 50%, while quotas that once supported several hours of work were exhausted in about 20 minutes, even when the task itself appeared unchanged.
More detailed reports from high-quota subscribers describe approximately 72 automatic context compactions in a single day. The primary agent reportedly compacted 17 times, while three sub-agents compacted 21, 17, and 17 times respectively. Contexts of approximately 240K–250K tokens before compaction still retained 140K–160K tokens afterward.
Other reports place the automatic compaction threshold near 244,800 tokens. After three compactions, the next normal requests still contained 241,860, 241,604, and 242,041 input tokens. This suggests that the space released by compaction may be quickly consumed again by historical content, tool output, and injected configuration, creating a cycle of “compact, grow, and compact again.”
Public issue trackers also include reports of a single session consuming 88.96% of a weekly quota. One reporting period included 15 related records, 1,044 replies, and 4,649 views.
These observations deserve attention, but they do not by themselves prove a metering defect or establish that all reports share the same cause. Any investigation must distinguish among task size, model settings, tool-call patterns, automatic compaction behavior, caching, and quota-accounting rules. Community samples are more likely to collect users with unusual experiences and often lack consistent task baselines, model parameters, and quota snapshots. They are therefore useful investigation leads, not final evidence.
2. Separate the Two Accounting Systems: Subscription Quotas and Usage-Based Billing
The first step in investigating unexpected usage is to distinguish between two different accounting systems.
The first is usage-based billing, which can be decomposed by token count, request count, and rate. It is useful for analyzing cost structure: input tokens, output tokens, tool-return content, cache hits, and retries can be attributed request by request.
The second is the aggregate quota used by a subscription service. Official documentation typically explains that quota consumption depends on the model, task, and settings. It should not be treated as a direct conversion of usage-based billing components. A subscription quota may be calculated through a server-side aggregate metric that includes factors such as model weighting, task type, cache discounts, compaction work, and tool calls that are not fully disclosed.
Client-side displays of consumption percentage, remaining quota, or reset time may also involve reporting delays, different time windows, or different display definitions.
For this reason, use token-level accounting as a reference framework, but do not treat it as proof of the platform’s quota calculation. Align the time window, quota unit, reset rules, cache-accounting policy, and whether compaction requests count toward the quota. If client statistics differ from server-side quota snapshots, treat the authoritative server record as the source of truth and retain request-level logs for cross-checking.
3. Four Multipliers That Can Increase Consumption
Unexpected quota growth is often caused by several multipliers rather than a single issue. A useful diagnostic model is:
Session quota consumption ≈ request rounds × tokens per request × model/task weight × cache discount factor + compaction cost + retry and redundancy cost
The actual weighting and discount factors depend on the platform. This formula is intended only for investigation.
3.1 Agent Sessions Can Expand the Token Count per Request
An agent session is not a simple question-and-answer exchange. Every round may include large amounts of historical content, including conversation history, tool results, code diffs, large-file excerpts, agent instruction files injected on every round, and JSON Schemas declared by external tools.
A single large-file read or full diff can add thousands of tokens. If instruction files and tool declarations are injected repeatedly, their fixed overhead is multiplied by the number of rounds.
For example, suppose a long-running task injects 8K tokens of instructions and tool declarations on every round, receives an average of 6K tokens from tools, and carries 30K tokens of conversation history. Each round may then exceed 40K input tokens. After 20 tool-call rounds, input alone can reach roughly 800K tokens. From the user’s perspective, the task may appear unchanged, while the structure of the agent session has substantially increased consumption.
3.2 Request Rounds and Tool Calls Matter
An agent loop may include planning, reading, editing, validation, and retry steps. Each step can trigger one or more model requests. If tool output is incomplete, errors cause retries, or sub-agents explore in parallel, the request count can increase rapidly.
Sub-agents require particular attention. Each may have an independent context window and compaction threshold. During a long parallel task, the primary agent and multiple sub-agents can each trigger requests and compactions. The combined session-level usage can therefore be much higher than expected.
For diagnosis, track the number of requests, tool calls, retries, and sub-agents per task rather than looking only at tokens per request.
3.3 Automatic Compaction Can Become Repetitive
Automatic compaction is intended to control context length, but the compaction process itself may introduce additional cost. The system must read a long context and generate a compacted version. The retained content must then be sent with the next request.
If the threshold is approximately 244,800 tokens and compaction retains 140K–160K tokens, only about 80K–100K tokens may be released. One large tool result, several rounds of history, and repeatedly injected content can quickly push the context close to the threshold again.
Compaction can also change the context prefix and invalidate existing cache entries. Compaction cost combined with cache misses can further increase perceived usage.
Reports in which the next normal request after three compactions still contains approximately 241K–242K input tokens are a typical warning sign. They may indicate that the compaction strategy retains too much content, or that the context grows too quickly after compaction, causing repeated cycles.
3.4 Cache Hits and Invalidation Need to Be Interpreted Carefully
Caching in multi-turn conversations often depends on a stable prefix. When the system prefix, tool declarations, and early history remain stable, subsequent requests may reuse cached content and reduce the effective cost of input tokens.
Automatic compaction rewrites history and changes the prefix, which can invalidate the existing cache. Even if the new compacted prefix is cached later, the first request after the change may still incur the cost of a cache miss.
Distinguish between the cache-hit ratio and cache-prefix stability. A high hit ratio does not necessarily mean that the absolute number of uncached tokens is small. If the newly compacted prefix is reused, the ratio may look healthy even though the original session cache was invalidated.
When optimizing, prioritize a stable prefix, minimize content that changes on every round, and place volatile content later in the context.
4. How Repeated Compaction Happens
The risk of a compaction loop can be represented with the following pseudocode:
threshold = 244_800retain_target = 150_000context = build_context(history, injected_docs, tool_schemas)while estimate_tokens(context) > threshold:before = estimate_tokens(context)context = compress(context, retain_target)record_compaction(before, estimate_tokens(context))context += next_tool_result()
If compress leaves 140K–160K tokens and each subsequent round adds 20K–30K tokens through tool output and conversation history, the context can exceed the threshold again after only a few rounds.
During reproduction, record:
- Token count before compaction
- Token count after compaction
- Compaction duration or input and output size
- Input tokens in the next request
- Cache-related fields
- Quota changes
- Agent role and number of sub-agents
If the input remains close to the threshold after three compactions, focus on the retention policy, tool-output size, and content injected on every round.
5. A Diagnostic and Observability Plan
A practical investigation can follow four steps: baseline, instrumentation, comparison, and attribution.
Step 1: Establish a Baseline
Fix the task type, model settings, tool set, and approximate context length. Record quota snapshots before and after the task, along with request count, tool-call count, and compaction count.
Without a baseline, it is impossible to distinguish a change in task size from a metering problem.
Step 2: Add Request-Level Instrumentation
At minimum, record:
- Request ID and session ID
- Agent role
- Input and output tokens
- Tool-result size in bytes or estimated tokens
- Size of injected documents
- Size of tool declarations
- Cache-related fields
- Compaction events
- Retry count
- Remaining quota
A session-level dashboard should show requests per task, compactions, tokens before and after compaction, number of sub-agents, and quota increase per task.
Step 3: Run Controlled Comparisons
Test the effect of individual changes by disabling sub-agents, limiting tool-output length, reducing repeated injections, stabilizing the context prefix, or adjusting the automatic compaction threshold or retention ratio.
Only test settings supported by the platform. Do not assume that undocumented parameters exist.
Step 4: Build an Attribution Matrix
Classify the anomaly across several categories:
- Task size
- Model settings
- Accounting definitions
- Tool loops
- Compaction strategy
- Cache strategy
- Server-side metering
Eliminate each category systematically. A tool defect or metering issue should be concluded only after establishing a consistent baseline, reproducible steps, and authoritative quota records.
6. Engineering Practices for Reducing Usage
Engineering teams can prioritize the following measures:
- Truncate or paginate tool output, and retrieve only the required sections.
- Summarize large files before expanding specific portions.
- Reduce repeated per-round injections.
- Keep the context prefix stable and move volatile content later.
- Isolate sub-agent tasks and require structured summaries instead of full context.
- Set daily and weekly quota alerts.
- Alert on abnormal quota slopes for individual sessions.
- Split long tasks into stages and persist summaries between stages.
- If supported by the platform, tune the compaction threshold, retention ratio, and cache-friendly ordering.
Organizations should also include quota governance in their observability systems. Useful components include request-level log retention, session-level cost dashboards, budget alerts, anomaly audits, and fallback policies.
General cloud capabilities such as logging, monitoring, alerting, and object storage can support this type of instrumentation and budget monitoring at relatively low cost. Services offered by platforms such as Baidu AI Cloud may also be used for these general observability functions, but the applicable quota and metering rules must be confirmed in the documentation for the service actually being used.
7. Conclusion
Current community reports are not sufficient to prove a single, universal metering defect. Nor should unexpected quota consumption be attributed automatically to one tool defect.
A more reasonable interpretation is that several factors can combine: agent session structure increases the number of tokens in each request; tool calls and sub-agents increase the number of request rounds; automatic compaction repeatedly triggers near the context threshold; compaction invalidates caches; and differences between subscription quotas and usage-based billing make the resulting behavior harder to interpret.
The investigation should begin by separating the two accounting systems. Then use request-level instrumentation and controlled comparisons to examine four key multipliers:
- Tokens per request
- Number of request rounds
- Compaction frequency and cost
- Cache hits and invalidations
Only after task size, model settings, accounting definitions, and tool behavior have been separated can teams determine whether the issue comes from an agent defect, an unsuitable configuration, a change in task shape, or a difference in quota reporting.
For development teams, a reproducible quota baseline, observable session costs, and actionable budget alerts provide more engineering value than simply debating whether the behavior is a defect.
