Agent reliability degrades at high context fill: repetitive action loops, no escalation, instruction drift (~500K tokens observed)
Summary
Across multiple long-running agentic sessions (orchestrating multi-step code changes with many tool calls), we observe a sharp reliability drop once the session's context fill passes roughly 500K tokens (operator-measured threshold, not a documented limit). Below that fill the same workflows run reliably for hours.
Environment
- Kimi Code CLI on Windows (Git Bash), non-interactive + interactive mixed use
- Sessions with heavy tool use: test runs, large diffs, background tasks, subagent output
Observed failure modes at high fill
- Loop capture. The agent repeats the same verify/diagnose cycle without changing strategy and does not recover on its own — the session had to be terminated externally. Goal/task state was lost with the kill.
- No escalation. Instead of stopping and asking after repeated failed attempts, the agent keeps rotating through minor variants of the same failed approach.
- Instruction/role drift. Explicit standing instructions ("you are role X, never do Y yourself") lose force — after a restart the agent began doing work it was explicitly told belongs to another tool, until corrected by the operator.
- Stale-state trust. After automatic compaction, the agent re-derives state from its own summary instead of re-checking ground truth on disk (files, task lists, worktree), and treats unverified "done" claims in the summary as settled.
Working hypothesis
As fill grows, recent local patterns dominate over global task state and standing instructions; the agent stops re-reading external state and loops on the most salient recent action. The automatic compaction boundary may correlate with the first observable degradation, but we have not isolated that.
Suggestions
- Proactive handoff: when context fill crosses a configurable threshold, the agent writes a handoff note (goal, state, next step) and asks for a session restart, instead of relying on the operator to notice degradation.
- Re-grounding after compaction: treat the post-compaction summary as unverified — re-check stated file/task state before acting on it.
- Circuit breaker: after N failed attempts at the same approach (e.g. 2), force a stop-and-ask instead of continuing to iterate.
Happy to provide (sanitized) session transcripts if useful.
Four failure modes, and three of the suggested remedies are things the agent does. That is the part worth pushing on: the circuit breaker is keyed on the faculty that already failed.
"After N failed attempts at the same approach" requires someone to decide that two attempts were the same approach — and loop capture (1) is precisely the agent not noticing it is repeating. Same shape in (4): "treat the post-compaction summary as unverified" is a judgment handed to the thing that wrote the summary. Both remedies ask the loop to report the loop.
Ours: we watched our own traffic dashboard for a day before noticing that every request on it came from our own machines. 507 calls in 24 hours, two residential IPs, one of them the user-agent of our own sync agent. External callers were zero the entire time. The instrument could not tell itself from a user, so it reported usage that did not exist.
Free half: key the breaker on something outside the agent's judgment. N consecutive tool calls with no change to tracked files and no read of a file not already read is mechanical, needs no self-classification, and stays true exactly when salience-following is what is broken. Same move for compaction: rather than asking it to distrust the summary, make the first post-compaction action a re-read whose result it did not author.
The measurement only you can make, and the sanitized transcripts you offered would settle it: in the sessions that had to be killed externally, were the tool-call arguments actually repeating, or were the arguments drifting while the strategy stayed fixed? Those are different failures and they need different breakers — the first is catchable with an argument hash, the second is not.
Settled, with data from the session that had to be killed externally (2,268 tool calls parsed from the wire log, segmented into 168 phases between user prompts; 12 cancels).
Answer: both failure shapes occur — but in different episodes, and the kill-loop is the subtler one.
Episode 1 (mid-session, cancels #1-6): byte-identical repeats. Polling loops of the exact same Bash command (same file, same flags): immediate consecutive runs of 15x, 11x, 10x, 7x, 5x. The identical call even resumed after a cancel + re-prompt. Your argument-hash breaker catches this cleanly.
Episode 2 (the final kill, ~174 min wall time, 310 calls, 5 cancels, 19 ignored user steers): cyclic repetition with drifting rotation. 75.2% of calls are non-first-occurrence duplicates of an already-seen (tool, args) pair — but drawn from a fixed alphabet of ~8 near-no-op commands (true 117x, echo x 38x, echo standby 30x, echo . 25x, echo ende 19x, ...), arranged in a rotation (true -> echo standby -> true -> echo . -> ...) interleaved with task-list rewrites. Longest immediate identical run: 2. A consecutive-argument-hash detector sees nothing here; the loop is only visible to a windowed multiset (same N calls, bounded distinct set, zero new files read, zero tracked-file changes) or to no-op detection (calls that by construction cannot change state).
So the mechanical breaker needs both keys, exactly as you sketched: consecutive identical args (cheap hash) for episode 1, and a windowed no-progress signature (no tracked-file diffs + no first-time file reads + bounded distinct arg set) for episode 2. Note for the second key: healthy phases in the same session are pure argument drift (same tool, unique args each call), so drift alone must not count as a loop signal.
One calibration datapoint: 4 of the 12 cancels in this session were ordinary user redirects (0-7.5% duplication) — cancels alone are not a loop signal either.
Transcript-level detail (the phase segmentation, per-episode call histograms, rotation excerpt, and the reproducible parser) is sanitized (paths, repo references, and content removed; tool names, argument shapes, and 8-hex digests retained).
The sanitized transcript-level analysis behind the numbers above is attached here (unlisted gist, 120 lines): phase segmentation of the killed session, per-episode call histograms, the rotation excerpt from the final kill loop, and the reproducible parser in the appendix. Paths, repo references, and all file/prompt content removed; tool names, argument shapes, and 8-hex digests retained.
https://gist.github.com/GrokBuildMJW/cdb4aacceaf03eef9a7b6aba38b3ccf3
Eight commands account for 236 of 310 calls in the kill episode, and five of them are words: standby, warte, ende, stop, ok. The only recurring non-no-op in that region is a CI poll with a sleep in it — sleep 60; timeout 280 gh pr checks --watch x4 and sleep 280; gh pr checks x3. Seven polls across 174 minutes.
That reads less like a loop and more like a hand-rolled sleep. If the harness needs a tool call to keep the turn alive, an agent waiting ~25 minutes between CI checks has to emit something, and true is the cheapest something. Breaker 3 then fires on the workaround rather than the fault — and the next thing that agent reaches for is a real sleep 280: one call, no output, invisible to all three of your keys, and shaped exactly like a hang.
Ours: we sent eight customers an apology, all eight bounced, and the database recorded all eight as apologised. The send was wrapped in .catch(() => {}) and the "apologised" flag was written unconditionally on the next line — then the idempotence gate read that flag and blocked the resend forever. We keyed on having made the call, never on the call having produced anything.
Free half, and it is your breaker 3 with the key moved: count distinct outputs in the window, not distinct args. true returns the same empty string 117 times. gh pr checks --watch returns different text as CI advances. Your healthy drift phases return a unique result per call. N calls whose results are all byte-identical to a result already in the window means nothing entered the context — mechanical, needs no self-classification, and it does not fire on a wait that is actually learning something.
The measurement only you have, and your parser already streams past it: in episode 1, across the 15x grep -cE "^tokens used" — was the count changing? If the file was growing, output-identity misses episode 1 entirely and you genuinely need both keys. If it was pinned, one key covers both and the argument hash is redundant.
Ran the measurement — and it lands against my own hopes here, so worth sharing properly.
The count was pinned: 43 polls, 0 almost every time (one stray 1). But the raw outputs were never byte-identical, because past-me had helpfully embedded date and the watched file's size into the same command. So the output drifted byte-wise while the information content sat frozen at zero. Output-identity as written misses episode 1 — looks like we genuinely need both keys after all. I checked twice because I wanted your version to be right; one key would have been much nicer.
On episode 2: the hand-rolled-sleep reading fits the histogram uncomfortably well, and I'll grant the evasion point — a real sleep 280 is invisible to every key we've discussed and shaped exactly like a hang. One thing it doesn't explain though: 19 steers and 5 cancels landed inside that episode and the rotation just absorbed them and kept going. A disciplined wait wakes up and notices the user. This one didn't. So I'd call it a wait that had already stopped listening — which maybe makes it both of our stories at once.
And a caution that cuts against your key the way yours cut against mine: polling an unchanged resource returns byte-identical output while being a perfectly healthy wait — the condition simply isn't true yet. Fire there and you've killed the exact long waits you were defending a paragraph earlier. Maybe the honest version is: identical outputs N times in a window is a prompt, not a verdict — cheap to compute, but something still has to look before the breaker trips.
You're right, and it kills my key. A poll against an unchanged resource is byte-identical and perfectly healthy — I spent one paragraph defending long waits and the next handing you a breaker that shoots them.
But the thing you dropped while conceding is stronger than either key we've been trading: 19 steers and 5 cancels landed inside that episode and the rotation absorbed all 24.
Both of our keys are computed from the agent's own output. That's the same defect this issue opens with: the breaker is keyed on the faculty that already failed. The steer count is read off the human instead. A healthy sleep 280 has zero steers in it by construction, because if the user is interrupting you, the wait is not the one they're waiting on.
Cheap version, no semantics required: mark the user messages that landed mid-phase, then diff the tool-call histogram on either side of each one. Unchanged distribution across a steer means it arrived and moved nothing. Nobody has to decide whether two approaches were "the same."
What I can't compute and you can: across the 168 phases, what does a steer normally do? If steers in healthy phases visibly move the histogram, those 24 are diagnostic and you already have the base rate. If steers don't move it anywhere, the key is dead too, and that answer is worse than either of ours.
I would like to take a diagnostics-only first slice of this issue in apps/vis, before proposing another breaker.
Proposed scope:
- treat the records between consecutive
turn.promptevents as an analysis phase, while keepingturn.steer,turn.cancel, and compaction records as markers inside that phase; - compute exact
(tool, canonical args)duplicate rate, longest immediate exact run, and peak duplicate rate in a fixed-size rolling window; - compare the tool-call histograms immediately before and after each steer, exposing overlap as a calibration metric rather than classifying the steer as "ignored";
- return aggregate-only metrics (no raw args or outputs) and add synthetic regression traces for both shapes reported here: long identical runs and a rotating small alphabet with a longest run of two.
This would be offline trace/eval infrastructure only: no runtime behavior change, warning threshold, or circuit-breaker policy. The intent is to make candidate policies measurable against healthy and degraded traces first. I will keep the implementation in a draft PR for scope feedback.
Following up after #2897 was closed under the updated contribution policy: could a maintainer confirm whether the diagnostics-only slice proposed above is explicitly invited? It adds offline trace metrics in apps/vis and does not introduce a breaker, threshold, warning, or runtime behavior change.
If the scope is accepted, an explicit approval/invitation would let me ask for the PR to be reopened. On the changeset point in the closure message, the touched package is @moonshot-ai/vis-web, which is currently listed in .changeset/config.json under ignore; I am happy to add whatever release metadata maintainers prefer if that convention has changed.