ECA becomes unresponsive when tool output causes LLM context overflow
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
调研方向
Start by reproducing the freeze with a large tool output, then read eca-process.el for synchronous JSON parsing and eca-chat.el for content insertion and buffer-wide fontification and table alignment. The issue identifies server-side context overflow recovery and client-side rendering as contributing areas, but does not specify a single fix. Done means large tool output and context overflow no longer leave ECA or Emacs unresponsive.
由索引模型根据 Issue 内容生成。
描述
Description
When a tool (especially shell commands) produces very large output, ECA hits the LLM provider's token limit with:
LLM response status: 400 body: {"error":{"message":"prompt token count of 174837 exceeds the limit of 168000","code":"model_max_prompt_tokens_exceeded"}}
After this error, the ECA server and Emacs become unresponsive/frozen, requiring a restart.
Root Cause Analysis
The issue involves multiple contributing factors on both server and client side.
Server-side
-
No proactive token budget check before API call: The server sends the full message history to the LLM provider without estimating token usage. Context overflow is only detected reactively (HTTP 400 response) and recovered via prune + auto-compact. While the recovery logic works, it doesn't prevent the initial expensive roundtrip and the cascade of effects on the client.
-
Tool output truncation exists but may be insufficient:
outputTruncationdefaults to 2000 lines / 50 KB, but a single tool result at the maximum (50 KB ≈ 12,500 tokens) combined with a long conversation history can still exceed the context limit. The truncation also doesn't account for the cumulative token budget across all messages. -
Potential infinite recovery loop: If auto-compact succeeds but the subsequent resume prompt still triggers context overflow,
auto-compacting?has already been reset tofalse, allowing another compact cycle. There is no counter orrecovery-attempted?guard to preventCompact → Resume → Overflow → Compact → …loops (analogous to the existingauto-continued?guard for truncated responses).
Client-side (Emacs)
-
Synchronous JSON parsing of large messages: The process filter in
eca-process.elparses incoming JSON messages synchronously with no size limit. Before the overflow error, the server sendstoolCallednotifications containing the full tool output. Parsing a multi-MB JSON message blocks the Emacs main thread. -
font-lock-ensurerefontifies entire buffer: After each text content insertion (eca-chat.el),font-lock-ensureruns over the entire chat buffer. Ingfm-modewithmarkdown-fontify-code-blocks-natively, this becomes very expensive for large buffers. -
align-tables/beautify-tablesscan entire buffer: On"finished"status, both functions are called with(point-min), scanning the entire chat buffer for markdown tables — expensive for long conversations. -
Expandable content has no size limit: Tool call outputs are stored and rendered in expandable overlays without any truncation. Large outputs bloat the buffer.
These client-side issues compound: large tool output → expensive JSON parse → expensive rendering → expensive fontification → expensive table alignment, all running synchronously on the Emacs main thread.
Steps to Reproduce
- Start an ECA chat session with a model that has a moderate context window (e.g., 128K-168K tokens)
- Have a conversation long enough to consume a significant portion of the context
- Execute a tool/shell command that produces very large output (e.g.,
find / -name "*.log"or similar) - The LLM provider returns HTTP 400 (token limit exceeded)
- Emacs becomes unresponsive
- 主要语言
- Clojure
- 星标
- 1k
- 派生
- 82
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 18
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
editor-code-assistant/eca 的其他 Issue
-
Models doesn't work when fetchModels: false is used可能已有人在做 @zikajk 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
editor-code-assistant/eca#661 · 已指派 1 人 ·
维护者通常 2 天内回复
-
难度 3/5 1-2 天 新手友好度 56/100
editor-code-assistant/eca#662 · 1 个 reaction ·
维护者通常 2 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 25/100
editor-code-assistant/eca#652 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 5/5 一周以上 新手友好度 12/100
editor-code-assistant/eca#648 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 3/5 1-2 天 新手友好度 35/100
editor-code-assistant/eca#644 · 1 条评论 · 1 个 reaction ·
维护者通常 2 天内回复
查看 editor-code-assistant/eca 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
nrepl/piggieback#163 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
clojure-emacs/orchard#436 ·
-
Priority:P3
难度 1/5 1-3 小时 新手友好度 82/100
metabase/metabase#85025 · 1 条评论 ·
维护者通常 1 天内回复
-
Page titles with `$$`, `$&`, `` $` `` or `$'` change when block refs are resolved可能已有人在做 @RaphaelFakhri 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
-
measured/expr fails for array-typed locals: tag from getCanonicalName ("long[]") cannot be resolved未关闭Bug
难度 2/5 1-3 小时 新手友好度 66/100
hugoduncan/criterium#156 ·