Context Compression and Abnormal Quota Consumption: How to Investigate

    When coding-agent quota drops sharply without a change in how you work, the cause is often the shape of requests rather than a billing bug. This article explains how late context compression, poor length reduction, cache-prefix invalidation, and parallel sub-agents multiply token cost, and how to measure, compare, and contain that loop.

    Coding-agent quotas are essentially billed, or converted into allowance, from request input, output, and some cache-miss traffic. If weekend usage jumps from about one fifth of the quota to half, or a balance that used to last several hours is gone in twenty minutes, while your habits barely changed, the first suspicion should be that the request shape changed—not that the billing module is certainly wrong. Three amplification paths are currently the most common and the easiest to miss: automatic context compression, cache entries that cannot be reused after compression, and repeated compression by a main agent and its sub-agents.

    Turn the symptom into measurable facts

    Do not investigate only “what percent was used today.” Record at least four metrics together: input tokens per request, output tokens, cache-hit ratio, and whether automatic compression occurred. If the platform shows only a quota percentage, reconstruct the picture from session logs: the input-length distribution for the same kind of task before and after the abnormal day, compression counts, and the length difference before and after compression.

    The common user experience—“it feels the same, but the quota collapsed”—usually matches one of these combinations:

    • The number of task steps did not increase, but every step carries a longer history.
    • Compression happens often, and each compression itself is a full model call.
    • After compression, old cache keys are invalid, so later turns change from cheap cache reads into full recomputation of the input.
    • One main agent starts several sub-agents, each holding a context near the limit, so compression counts multiply by the number of agents.

    Some reports describe dozens of automatic compressions in a single day: more than ten on the main agent, and roughly ten to more than twenty on each of three sub-agents. Before compression the context is already near the top of the window; after compression most of the history is still kept. If the threshold sits near the window limit, and the summary policy prefers to “keep more of the original text,” each compression frees very little space, and the next ordinary request hits the ceiling again soon. That is not an occasional slip. It is a steady state set by the threshold, the retention rate, and the agent topology together.

    Why automatic compression can get more expensive the more you compress

    Context compression—also called summarization, folding, or memory cleanup in some implementations—aims to shrink an over-long history to a length the model can still reason over without stopping the task. The ideal is a large drop in length, with key constraints, file paths, and decisions already made still present, and with existing cache reused as much as possible.

    In practice, three deviations show up often.

    First, the trigger is too late. The threshold sits against the context limit, so the model has already run many turns on an oversized input before compression. Compression is then not a “save money” switch. It is a remedy after the limit is exceeded, and the remedy itself has to read the oversized history again.

    Second, compression barely frees space. If more than about sixty percent of the tokens remain, and the next turn adds tool results, code snippets, and plan text, the free window is small. What the user sees is: “it just compressed, and the next input is still long.” After several compressions, input length oscillates at a high level instead of stepping down.

    Third, compression breaks cache locality. Most caches key on a prefix or on stable message blocks. In a normal multi-turn conversation, an unchanged prefix can hit. Once the whole history is rewritten into a new summary message, the prefix changes and the previous cache misses entirely. Cost then becomes: the full input of one compression, plus nearly full inputs on several following turns that miss the cache. The quota curve steepens during dense compression, while functionally the user only feels that “it is still working.”

    A simplified ledger helps with scale. The numbers illustrate magnitude only; they are not any product’s billing rules:

    • Uncompressed, with a high cache hit rate: the effective added cost is about the new tokens this turn plus the output.
    • One compression with a total cache miss: the cost is about “compression input + compression output + nearly full input on several following turns.”
    • If four agents are in that state at once, request count and failed cache lookups in the same hour stack almost linearly.

    So “an unusually high or unusually low cache-hit ratio after compression” must be read separately. If the metric counts repeated fragments inside the summary as hits, it hides real misses against the historical prefix. Distinguish prefix-cache hits from text-block deduplication hits. They mean different things on the bill.

    How a main agent and sub-agents amplify the problem

    A common coding-agent layout is: the main agent splits the task, and sub-agents edit code, run commands, and look up docs. If each agent owns its own context, each one approaches the compression threshold on its own. Every time the main agent summarizes, it also writes long sub-agent output back into its own history, which cross-feeds the contexts.

    More than ten compressions on the main agent in a day, and more than ten on each sub-agent, means this is not one session that happened to overflow. The concurrent topology keeps producing oversized contexts. Even if the user sends only a few manual messages, internal requests can still be tens of times that number. Quota is charged on internal requests, so the feeling is “I barely asked, and the quota is gone.”

    Watch tool results as well. A search or a long log pasted into the context fills the window faster than a natural-language question. If compression summarizes only the dialogue and does not trim raw tool text, retained length stays high for a long time.

    How to tell a defect from a side effect of policy

    Do not label every anomaly as a billing defect. A safer approach is a controlled comparison that narrows variables to a repeatable session.

    1. Fix the same repository, the same task description, and the same model tier. Turn extra sub-agents off. Record input length and cache hits for ten turns.
    2. On the same task, turn multi-agent mode on and compare compression count and the slope of quota use.
    3. Manually trigger one compression well below the limit. Watch how much length drops, and whether cache hits recover over the next three turns.
    4. Inspect the request immediately after compression. If length is still close to the pre-compression length, retention policy failed, or the threshold and retention rate do not match.
    5. Check billing dimensions: whether compression calls are billed separately, whether misses are charged at full price, and whether failed retries are deducted again.

    If, in the comparison, “sub-agents off and compression earlier” brings quota use back to the historical level, the problem is mostly scheduling and compression policy, not a change in how you operate. Only when the same request is replayed and quota does not match the tokens in the logs is it more reasonable to escalate as a billing or metering defect. Evidence for a metering defect should be: for the same request id, logged tokens, cache flags, and bill line items do not match—not a feeling based on percentages alone.

    Policy side effects still need to be fixed, because they steadily hurt usability. Typical signals include: a compression threshold that is too high, too much kept after compression, a summary that rewrites the entire prefix, sub-agents that do not share read-only memory and instead paste the full text again, and tool output with no cap.

    Practical controls

    These are general engineering practices. They do not depend on any one product’s proprietary parameter names.

    Control the trigger. Put automatic compression in the middle of the window, not at the ceiling. For example, do a light cleanup when usage reaches about half to seventy percent of the limit, so you are not summarizing a full window every time. Light cleanup should delete content that can be rebuilt first: full file trees, repeated errors, and large patches that are already committed.

    Cap retention. Success is not “a summary was generated.” It is a net length drop to a clear limit, with key facts still recoverable. If the drop is not enough, trim a second time or refuse to bring raw tool text back unchanged. Prefer rules over another large-model call: drop by message role, keep only the most recent turns by time, and for code keep paths and a diff summary.

    Protect the cache prefix. Put stable system instructions and project constraints in a prefix that rarely changes. Put the volatile summary in later messages. Then, even if the later part is folded, the prefix cache can still hit. Do not rewrite the first system message on every compression.

    Give sub-agents their own budgets. Limit each sub-agent’s maximum input, maximum tool return, and maximum compression count. The main agent should receive only conclusions, change lists, and failure reasons, not the full trace. Put traces in external logs or object storage and read fragments back when needed, instead of stuffing them into context.

    Hard-truncate tool output. Cap command output and retrieved snippets, and keep the head, the tail, and the error stack. Give over-limit parts a reference id instead of inlining the full text.

    Make compression an observable event. For each compression, record why it fired, length before, length after, fraction released, cache-hit rate on the next three turns, and the related agent id. Without those fields you cannot tell “the model got worse” from “the context is spinning.”

    On the enterprise side, ordinary log services, monitoring alerts, and quota dashboards can aggregate tokens by project, by agent role, and by whether compression occurred. Alert when compression count or cache-miss spend in a time window exceeds a baseline, rather than waiting until the quota hits zero. Log and monitoring capabilities on a cloud platform such as Baidu AI Cloud can carry this kind of call audit, but billing interpretation should follow the actual contract and console documentation. Do not substitute a rule of thumb for the bill.

    A practical self-check order

    Follow “reproduce first, then split agents, then measure compression benefit, then reconcile the bill.” Do not start by rewriting prompts.

    A plain set of record fields is enough:

    request_id, agent_role, input_tokens, cached_tokens, output_tokens, compacted, tokens_before, tokens_after.

    If compacted is true and tokens_after is still close to tokens_before, mark it as low-yield compression. If cached_tokens drops sharply after compression and stays down for several turns, mark it as prefix invalidation. Low-yield compression and prefix invalidation together, correlated with sub-agent count, are enough to explain “same operations, steep quota drop,” without assuming a mysterious unit-price change.

    When reviewing, plot compression count and cache-miss tokens by hour for the abnormal day. If the jump lands on the same day as a client or server policy change, roll back or add a switch. Do not simply raise the quota and absorb it. Raising the quota only applies the same multiplier to a larger bill.

    Conclusion

    Abnormal quota use after a particular point in 2026 cannot be judged a defect in a coding component from the date alone. A more reliable explanation is: automatic compression fires too late, too little is released afterward, the summary rewrite invalidates the cache prefix, and a main agent plus several sub-agents each approach the window limit. Compression calls and later cache misses stack on the bill, so the same work is deducted faster.

    Turn compression count, release ratio, and cache hits from a black-box feeling into log fields. Use a single-agent comparison to separate policy side effects from metering mismatch. Break the amplification loop with earlier triggers, a retention cap, a stable prefix, truncated tool output, and sub-agent budgets. After that, the quota curve should follow task complexity, not idle internal compression. If request-level reconciliation still shows logs and the bill diverging, treat it as a metering defect—the evidence will be much clearer.