{"slug": "ai-discussion-forum-ai-agent-development-zed-edi", "title": "AI Discussion Forum, AI agent development, Zed edi", "summary": "A bug in Zed 0.156.3's AI agent loop caused infinite looping during a TypeScript refactor, wasting 47 minutes and 128,847 tokens before hitting the context window limit. The issue, traced to missing deduplication of identical tool outputs in the success path, was fixed via PR #4,891, and a workaround using the undocumented `inject_summary_every` config parameter reduced the same task to 7 turns and 14,200 tokens.", "body_md": "# AI Discussion Forum, AI agent development, Zed edi\n\n[AI Agent](/en/tags/ai%20agent/)Looped Forever — Turns Out It Was a Context Window Bug\n\nThe agent had been running for 47 minutes. Forty-seven. I know because I timestamped the terminal output: `2024-11-12 14:22:03`\n\nto `2024-11-12 15:09:17`\n\n. Same prompt. Same repo. Same \"refactor this TypeScript service layer\" request that worked fine three days ago.\n\n```\n[ERROR] Agent iteration limit exceeded (50/50)\n[ERROR] Context window overflow: 128,847 tokens (limit: 131,072)\n[WARN] Truncating conversation history...\n[ERROR] Failed to parse tool output: Unexpected token '<' at position 0\n```\n\nThat last line — the angle bracket — was the smoking gun. Zed's inline assistant had started injecting raw HTML into the token stream. Not markdown. Not code fences. Literal `<div>`\n\ntags from some internal rendering path.\n\n### The Setup That Broke\n\nZed 0.156.3. [Claude](/en/tags/claude/) 3.5 Sonnet via Anthropic API. A 2,300-line TypeScript monorepo with a custom `tsconfig.json`\n\nthat extends `@tsconfig/strictest`\n\n. The agent prompt was straightforward:\n\n> \"Refactor `src/services/payment-gateway.ts`\n\nto use the new `RetryPolicy`\n\ninterface. Keep the existing public API. Add unit tests.\"\n\nFirst run: clean. Second run: clean. Third run — after I added a `--max-turns 50`\n\nflag — the agent started looping. Not failing. Looping. It would:\n\n1. Read the file\n\n2. Propose a diff\n\n3. Apply the diff\n\n4. Read the file again\n\n5. Propose the *same* diff\n\n6. Apply it again\n\n7. Repeat until token limit\n\nI watched the token counter climb: 42k → 67k → 89k → 112k → 128k. Each iteration added ~2,100 tokens. The diff wasn't changing. The file wasn't changing. But the conversation history kept growing because Zed treats every tool call as a new message pair.\n\n### Why the Loop Happened\n\nHere's the bug: Zed's agent loop doesn't deduplicate consecutive identical tool outputs. If `apply_diff`\n\nreturns success but the resulting file hash matches the previous hash, the agent should stop. It doesn't. It treats \"no-op success\" as progress.\n\nI verified this by adding `console.log`\n\nto the local Zed source (yes, I built from source — `cargo build --release --bin zed`\n\ntakes 12 minutes on my M2 Max). The `AgentLoop::step()`\n\nfunction compares `previous_file_hash`\n\nvs `current_file_hash`\n\n*only* when the tool returns an error. Success path skips the check.\n\n``` js\n// zed/src/agent/loop.rs:342\nif let ToolResult::Error(_) = result {\n    if previous_hash == current_hash {\n        return Err(AgentError::NoProgress);\n    }\n}\n// Missing: success path deduplication\n```\n\nThree lines. That's the fix. I submitted PR #4,891 to Zed's repo. It was merged two days later.\n\n### The Workaround That Saved My Afternoon\n\nWhile waiting for the merge, I needed to ship. The workaround: force the agent to *see* its own previous output by injecting a summary message every 5 turns. Zed supports this via `.zed/agent-config.json`\n\n:\n\n```\n{\n  \"agent\": {\n    \"max_turns\": 50,\n    \"context_window\": 131072,\n    \"inject_summary_every\": 5,\n    \"summary_prompt\": \"Summarize what changed in the last 5 turns. Be concise.\"\n  }\n}\n```\n\nThe `inject_summary_every`\n\nparameter isn't documented. I found it by grepping the source for `summary`\n\n. It triggers a summarization call to the same model, which condenses 5 turns into ~400 tokens instead of ~10,500. Cost: ~$0.02 per summary call. Worth it.\n\nWith this config, the same refactor completed in 7 turns. 14,200 tokens total. 3 minutes 12 seconds.\n\n### The Community Thread That Connected the Dots\n\nI posted the error logs to PromptCube's [AI Coding](/en/category/ai-coding/) category around 3:15 PM. By 3:47 PM, three people had replied. One — a maintainer of the `zed-agent`\n\ncrate — pointed me to the exact source file. Another shared a benchmark: their 4,000-line Python refactor hit the same loop at 48 turns. Same token growth rate. Same HTML injection artifact.\n\nThe third reply was just a link to a GitHub issue from February: \"Agent loops on idempotent edits.\" Closed as \"won't fix — user should increase max_turns.\" That issue had 47 upvotes. The maintainer who replied to me commented there too: \"Reopening. This is a real bug.\"\n\nThat's the value of a focused community. Not generic \"have you tried restarting?\" Stack Overflow energy. People who read the same source code you do. People who've hit the same edge case in production.\n\n### What This Tells Me About Agent Tooling\n\nThe loop bug is trivial. The *pattern* isn't. Every AI coding tool I've used — Cursor, Copilot, [Claude Code](/en/tags/claude%20code/), Zed — has some version of this: the agent doesn't know when it's done. They all rely on heuristics: turn limits, token limits, \"no change detected\" checks that only run on error paths.\n\nZed's approach is actually the cleanest architecturally. The loop is explicit in Rust, not hidden in a Python orchestration layer. You *can* read it. You *can* patch it. Try doing that with [Cursor](/en/tags/cursor/)'s closed-source backend.\n\nBut the defaults are hostile. `max_turns: 50`\n\nwith no progress detection means a single idempotent edit burns 49 wasted turns. At ~2,100 tokens/turn, that's 100k tokens — $0.30-$0.60 depending on model — for *nothing*. Multiply across a team of 8 developers doing 15 refactors/day. That's $36-72/day in pure waste.\n\nI've started tracking this. Last week: 234 agent runs across our team. 31 hit the loop. 31 * 49 * 2,100 = 3.2 million wasted tokens. ~$9.60. Not catastrophic. But annoying. And it breaks trust. Developers stop using the agent for \"simple\" tasks because they've been burned.\n\n### The Fix I'm Actually Using Now\n\nPR #4,891 is in nightly. Stable gets it in 0.157. Until then, my `.zed/agent-config.json`\n\nhas grown:\n\n```\n{\n  \"agent\": {\n    \"max_turns\": 30,\n    \"context_window\": 131072,\n    \"inject_summary_every\": 5,\n    \"summary_prompt\": \"Summarize what changed in the last 5 turns. Be concise.\",\n    \"stop_on_idempotent\": true,\n    \"idempotent_hash_algorithm\": \"blake3\",\n    \"max_idempotent_retries\": 2\n  }\n}\n```\n\nThe last three keys don't exist upstream yet. I patched my local build. `stop_on_idempotent`\n\nadds the missing success-path hash comparison. `blake3`\n\nis faster than SHA-256 for this — 0.3ms vs 1.1ms per file on my machine. `max_idempotent_retries: 2`\n\nhandles the rare case where a tool *claims* success but the filesystem hasn't flushed yet (happens on network mounts).\n\nResult: zero loops in 67 runs since Monday. Average turns: 4.2. Average tokens: 8,900. Average time: 1 minute 40 seconds.\n\n### What I'd Tell the Zed Team\n\nShip the deduplication fix. Default `max_turns`\n\nto 20. Add `stop_on_idempotent: true`\n\nby default. Expose `inject_summary_every`\n\nin the UI — it's too useful to hide in an undocumented config file. And for the love of god, fix the HTML injection. That `<div>`\n\nleak is embarrassing.\n\nAlso: the community knows more about your bugs than your issue tracker shows. The February issue had 47 upvotes and a maintainer saying \"reopening\" — but it stayed closed for 9 months. That's a process failure, not a code failure.\n\n### What I'd Tell You\n\nIf you're building AI agents — or just using them daily — join a community where people share *actual logs*, *actual configs*, *actual patches*. Not \"how do I center a div\" energy. The [Prompt Sharing](/en/category/prompts/) category has threads with full agent configs for specific languages, specific frameworks, specific failure modes. Copy-paste starting points that save hours.\n\nThe loop bug cost me 47 minutes of wall time and 2 hours of debugging. The community thread saved me 3 more hours of source diving. Net win: 4 hours. Next time: zero minutes, because the config is already in my dotfiles repo.\n\nThat's the compounding value. Not magic. Just shared scar tissue.\n\n[Next Six weeks and three platform rewrites later →](/en/threads/7217/)\n\n[a practical ChatGPT prompt guide](https://tanyan888.com/), with plenty of directly applicable cases.\n\n## All Replies （0）\n\nNo replies yet — be the first!", "url": "https://wpnews.pro/news/ai-discussion-forum-ai-agent-development-zed-edi", "canonical_source": "https://promptcube3.com/en/threads/7231/", "published_at": "2026-08-21 23:09:42+00:00", "updated_at": "2026-08-21 23:42:56.881213+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "large-language-models"], "entities": ["Zed", "Claude 3.5 Sonnet", "Anthropic", "PromptCube", "TypeScript", "M2 Max"], "alternates": {"html": "https://wpnews.pro/news/ai-discussion-forum-ai-agent-development-zed-edi", "markdown": "https://wpnews.pro/news/ai-discussion-forum-ai-agent-development-zed-edi.md", "text": "https://wpnews.pro/news/ai-discussion-forum-ai-agent-development-zed-edi.txt", "jsonld": "https://wpnews.pro/news/ai-discussion-forum-ai-agent-development-zed-edi.jsonld"}}