eca icon indicating copy to clipboard operation
eca copied to clipboard

After update, eca chat compacting doesn't work correctly anymore

Open ovistoica opened this issue 8 months ago • 22 comments

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

Describe the bug

On latest eca version, autocompacting shows 0 / 200 context but then immediately baloons to 140k without any relevant reasons. In the screenshot below you see only a sub agent started that I stopped after 1 small step. This leads to unusable agents because they baloon context and have to compact 5 times in 5 minutes and having to restart the tasks they were doing

To Reproduce

Steps to reproduce the behavior:

  1. Start a session
  2. Give agent a relatively complex task
  3. See context baloon
  4. See autocompacting
  5. Immediately after 1 step after compacting, context goes to 140k

Expected behavior

After compaction, the context should be 20-30k tokens max.

Doctor

ECA version: 0.112.1

Server cmd: /home/ovistoica/.config/emacs/eca/eca server

Workspaces: /home/ovistoica/workspace/proj, /home/ovistoica/workspace/proj-worktrees/some-branch

Default model: anthropic/claude-sonnet-4-6 (Subscription (oauth), expires 2026-03-13 14:41)

Logged providers: anthropic: Subscription (oauth), expires 2026-03-13 14:41

Relevant env vars: DEBUGINFOD_URLS=https://debuginfod.archlinux.org

Credential files: None found

Screenshots If applicable, add screenshots to help explain your problem.

Image

Additional context Add any other context about the problem here.

ovistoica avatar Mar 13 '26 05:03 ovistoica

I cannot replicate it anymore but will update here if it continues to happen

ovistoica avatar Mar 13 '26 14:03 ovistoica

Yeah that's pretty weird, I can't repro as well

ericdallo avatar Mar 13 '26 14:03 ericdallo

I wonder if it's related with you stopping the prompt but it should not

ericdallo avatar Mar 13 '26 14:03 ericdallo

No, I stopped after I saw the context fill up immediately after compacting. My impression at the time was that it was because of the subagent spawning

ovistoica avatar Mar 13 '26 14:03 ovistoica

Hi,

Three of six buddies have the Same issue. Compacting never ends. Manual stop and prompt again works. I never got this. We have all absolutly same Environment with emacs win11 zulu17. V0.112.1

snoopier avatar Mar 14 '26 14:03 snoopier

Folks, I can't repro and after some research I could not find anything wrong, can you update to latest server version and confirm this still happens?

ericdallo avatar Mar 14 '26 19:03 ericdallo

It hasn't happened to me since the first time, even on that same version and even after upgrades still didn't happen again 🤷

I propose we keep this issue open for 1 more week and if nobody else experiences it, we can close it

ovistoica avatar Mar 15 '26 16:03 ovistoica

Finding from my colleague (V0.114.2). in case "Compacting" runs and says "Successfully ..." Emacs waiting for ever in the emacs error log is "[2026-03-17 14:25:04] handle-message: No applicable method: project-root, nil" maybe this correlated ?!

snoopier avatar Mar 17 '26 14:03 snoopier

@snoopier don't think it's related, but we might know more if user toggle-debug-on-error on emacs, so we have the stacktrace.

ericdallo avatar Mar 17 '26 19:03 ericdallo

But the Code catch most of the (rpc) errors isn't it ?

Maybe a debug Feature to disable catching ?

snoopier avatar Mar 17 '26 19:03 snoopier

From what I can see that's a emacs error, not related eca server

ericdallo avatar Mar 17 '26 20:03 ericdallo

Yes but toggle debug on error doesn't help if the elisp code catch the error thats avoid to get the Stack trace. So a variable to disable would be nice or i miss something ? I take a Look tomorrow

snoopier avatar Mar 17 '26 21:03 snoopier

I will improve that elisp catch we have to add to eca-emacs-errors buffer + throw

ericdallo avatar Mar 17 '26 22:03 ericdallo

Finding from my colleague (V0.114.2). in case "Compacting" runs and says "Successfully ..." Emacs waiting for ever in the emacs error log is "[2026-03-17 14:25:04] handle-message: No applicable method: project-root, nil" maybe this correlated ?!

Confirmed this issue is unrelated to emacs Not detection Finishing of compacting

snoopier avatar Mar 18 '26 11:03 snoopier

Now i have the same issue as my colleagues.

Output: Compacted successfully!
Generating...

Never ends

Toggle on Error not triggered eca emacs errors (releated ?) -> handle-message: Wrong type argument: stringp, nil

How can i help to find the root cause ? From my point of view most important to catch the handle message issues

snoopier avatar Mar 18 '26 13:03 snoopier

Any eror that happens on eca-emacs side should be on eca-emacs-errors buffer, check for that first. Does that error only happens when compact happens? What model are you using so I can try to repro?

ericdallo avatar Mar 18 '26 14:03 ericdallo

using 0.114.2

eca:emacs-errors:1 Buffer [2026-03-18 10:40:43] handle-message: Wrong type argument: stringp, nil [2026-03-18 10:40:43] handle-message: Wrong type argument: stringp, nil [2026-03-18 11:07:32] handle-message: Wrong type argument: stringp, nil [2026-03-18 11:07:32] handle-message: Wrong type argument: stringp, nil [2026-03-18 11:07:32] handle-message: Wrong type argument: stringp, nil [2026-03-18 11:07:32] handle-message: Wrong type argument: stringp, nil [2026-03-18 11:39:21] handle-message: Wrong type argument: stringp, nil [2026-03-18 13:34:16] handle-message: Wrong type argument: stringp, nil [2026-03-18 14:11:47] handle-message: Wrong type argument: stringp, nil [2026-03-18 14:50:37] handle-message: Wrong type argument: stringp, nil [2026-03-18 15:18:07] handle-message: Wrong type argument: stringp, nil [2026-03-18 15:18:07] handle-message: Wrong type argument: stringp, nil [2026-03-18 15:20:40] handle-message: Wrong type argument: stringp, nil

my feeling is, that correleated to Issues with communication between server and emacs

snoopier avatar Mar 18 '26 14:03 snoopier

I'm take a closer look right now to see if I can add some guardrails

ericdallo avatar Mar 18 '26 17:03 ericdallo

@snoopier I just pushed improvement in logs, now toggle-debug-on-error will catch the logs, please do so we can fix that error.

Also, I confirmed server is good, so this is more a visual problem than anything not really compacting AFAICS

ericdallo avatar Mar 18 '26 17:03 ericdallo

ECA:

When the ECA server sends a chat/contentReceived notification for a subagent chat (e.g. "Auto-compacted chat" system message) without a parentChatId field, the client crashes with:

(wrong-type-argument stringp nil)

Root Cause

Two defects interact to produce the crash:

1. eca-chat--get-chat-buffer inserts nil entries into session chats

When called with a chat-id that has no existing buffer and no 'empty buffer is available, the function still executes the setf branch. Since empty-chat-buffer is nil, it inserts (chat-id . nil) into the alist and returns nil.

;; eca-chat.el:565
(defun eca-chat--get-chat-buffer (session chat-id)
  (or (eca-get (eca--session-chats session) chat-id)
      ;; BUG: `let` always runs the body, even when empty-chat-buffer is nil
      (let ((empty-chat-buffer (eca-get (eca--session-chats session) 'empty)))
        (setf (eca--session-chats session)           ;; ← poisons the alist with nil
              (-> (eca--session-chats session)
                  (eca-assoc chat-id empty-chat-buffer)  ;; chat-id → nil
                  (eca-dissoc 'empty)))
        empty-chat-buffer)))                          ;; ← returns nil

This is observable in the session state from the backtrace:

:chats (("subagent-4ba73345-...") ("ec507344-..." . #<buffer <eca-chat:1:0>>))
;;       ^^^^^^^^^^^^^^^^^^^^^^^^
;;       nil-valued entry (cons cell with no cdr)

2. eca-chat-content-received doesn't guard against a nil buffer

When a subagent message arrives without parentChatId, the else branch calls eca-chat--get-chat-buffer which returns nil, then passes it directly into eca-chat--with-current-buffer → with-current-buffer nil → (wrong-type-argument stringp nil).

;; eca-chat.el:2609
(let ((chat-buffer (eca-chat--get-chat-buffer session chat-id)))
  (eca-chat--with-current-buffer chat-buffer   ;; ← chat-buffer is nil → CRASH
    (eca-chat--render-content session chat-buffer role content roots)))

Trigger

The server sends a notification like this for a subagent chat:

{
  "jsonrpc": "2.0",
  "method": "chat/contentReceived",
  "params": {
    "chatId": "subagent-4ba73345-...",
    "role": "system",
    "content": { "type": "text", "text": "Auto-compacted chat" }
  }
}

Note: no parentChatId is present. The client has the subagent chat-id registered in eca-chat--subagent-chat-id->tool-call-id (buffer-local on the parent), but on the session-level chats alist there is no entry for it.

Suggested Fix

  1. eca-chat--get-chat-buffer: Change let to when-let* so the alist is only modified when an empty buffer actually exists.

  2. eca-chat-content-received: Add a nil guard (when chat-buffer) before entering eca-chat--with-current-buffer, so messages for unknown/orphan chat IDs are silently ignored.

Backtrace (abbreviated)

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  signal(wrong-type-argument (stringp nil))
  eca--handle-message(#s(eca--session ...) (:jsonrpc "2.0" :method "chat/contentReceived" :params (:chatId "subagent-4ba73345-..." :role "system" :content (:type "text" :text "Auto-compacted chat"))))




`Debugger entered--Lisp error: (wrong-type-argument stringp nil) signal(wrong-type-argument (stringp nil)) eca--handle-message(#s(eca--session :id 1 :status started :process #<process eca> :chats (("subagent-4ba73345-5f35-4bbb-b318-0635a1215c72") ("ec507344-03b1-450d-990f-267d52c61f3e" . #<buffer <eca-chat:1:0>>)) :last-chat-buffer #<buffer <eca-chat:1:0>> :workspace-folders ("d:/Programme/My/CoronaEmacs/") :request-handlers nil :response-handlers nil :models ["github-copilot/claude-haiku-4.5" "github-copilot/claude-opus-4.5" "github-copilot/claude-opus-4.6" "github-copilot/claude-opus-41" "github-copilot/claude-sonnet-4" "github-copilot/claude-sonnet-4.5" "github-copilot/claude-sonnet-4.6" "github-copilot/gemini-2.5-pro" "github-copilot/gemini-3-flash-preview" "github-copilot/gemini-3-pro-preview" "github-copilot/gemini-3.1-pro-preview" "github-copilot/gpt-4.1" "github-copilot/gpt-4o" "github-copilot/gpt-5" "github-copilot/gpt-5-mini" "github-copilot/gpt-5.1" "github-copilot/gpt-5.1-codex" "github-copilot/gpt-5.1-codex-max" "github-copilot/gpt-5.1-codex-mini" "github-copilot/gpt-5.2" "github-copilot/gpt-5.2-codex" "github-copilot/gpt-5.3-codex" "github-copilot/gpt-5.4" "github-copilot/gpt-5.4-mini" "github-copilot/grok-code-fast-1" "my/Mistral-Small-24B-Instruct-2501-FP8-dynamic" "my/bge-m3" "my/bge-reranker-v2-m3" "my/deepseek-r1-0528-qwen3-8b" "my/devstral-small-2-24b-instruct-2512" "my/devstral-small-2505" "my/glm-5" ...] :tool-servers (("ECA" :type "native" :name "ECA" :status "running" :tools [... ... ... ... ... ... ... ... ... ... ... ...])) :chat-agents ["code" "plan" "docs-hdl" "git-commit"] :chat-variants ("high" "low" "max" "medium") :chat-welcome-message "Welcome to CoronaEmacs Code Assistant!\n\n- <C-c C-c> Send prompt\n- <C-c C-b> Switch behavior\n- <C-c C-m> Select model\n- <C-c C-t> Toggle trust mode\n- <C-c C-e> Toggle (Un)folding blocks\n- <C-c .  > Quick help\n\n- /login to authenticate with providers\n- /init to create/update AGENTS.md\n- /doctor or /config to troubleshoot") (:jsonrpc "2.0" :method "chat/contentReceived" :params (:chatId "subagent-4ba73345-5f35-4bbb-b318-0635a1215c72" :role "system" :content (:type "text" :text "Auto-compacted chat")))) apply(eca--handle-message (#s(eca--session :id 1 :status started :process #<process eca> :chats (("subagent-4ba73345-5f35-4bbb-b318-0635a1215c72") ("ec507344-03b1-450d-990f-267d52c61f3e" . #<buffer <eca-chat:1:0>>)) :last-chat-buffer #<buffer <eca-chat:1:0>> :workspace-folders ("d:/Programme/My/CoronaEmacs/") :request-handlers nil :response-handlers nil :models ["github-copilot/claude-haiku-4.5" "github-copilot/claude-opus-4.5" "github-copilot/claude-opus-4.6" "github-copilot/claude-opus-41" "github-copilot/claude-sonnet-4" "github-copilot/claude-sonnet-4.5" "github-copilot/claude-sonnet-4.6" "github-copilot/gemini-2.5-pro" "github-copilot/gemini-3-flash-preview" "github-copilot/gemini-3-pro-preview" "github-copilot/gemini-3.1-pro-preview" "github-copilot/gpt-4.1" "github-copilot/gpt-4o" "github-copilot/gpt-5" "github-copilot/gpt-5-mini" "github-copilot/gpt-5.1" "github-copilot/gpt-5.1-codex" "github-copilot/gpt-5.1-codex-max" "github-copilot/gpt-5.1-codex-mini" "github-copilot/gpt-5.2" "github-copilot/gpt-5.2-codex" "github-copilot/gpt-5.3-codex" "github-copilot/gpt-5.4" "github-copilot/gpt-5.4-mini" "github-copilot/grok-code-fast-1" "my/Mistral-Small-24B-Instruct-2501-FP8-dynamic" "my/bge-m3" "my/bge-reranker-v2-m3" "my/deepseek-r1-0528-qwen3-8b" "my/devstral-small-2-24b-instruct-2512" "my/devstral-small-2505" "my/glm-5" ...] :tool-servers (("ECA" :type "native" :name "ECA" :status "running" :tools ...)) :chat-agents ["code" "plan" "docs-hdl" "git-commit"] :chat-variants ("high" "low" "max" "medium") :chat-welcome-message "Welcome to CoronaEmacs Code Assistant!\n\n- <C-c C-c> Send prompt\n- <C-c C-b> Switch behavior\n- <C-c C-m> Select model\n- <C-c C-t> Toggle trust mode\n- <C-c C-e> Toggle (Un)folding blocks\n- <C-c .  > Quick help\n\n- /login to authenticate with providers\n- /init to create/update AGENTS.md\n- /doctor or /config to troubleshoot") (:jsonrpc "2.0" :method "chat/contentReceived" :params (:chatId "subagent-4ba73345-5f35-4bbb-b318-0635a1215c72" :role "system" :content (:type "text" :text "Auto-compacted chat"))))) #f(compiled-function (&rest args2) #<bytecode -0x5f8ca161fbe63b6>)((:jsonrpc "2.0" :method "chat/contentReceived" :params (:chatId "subagent-4ba73345-5f35-4bbb-b318-0635a1215c72" :role "system" :content (:type "text" :text "Auto-compacted chat")))) mapc(#f(compiled-function (&rest args2) #<bytecode -0x5f8ca161fbe63b6>) ((:jsonrpc "2.0" :method "chat/contentReceived" :params (:chatId "subagent-4ba73345-5f35-4bbb-b318-0635a1215c72" :role "system" :content (:type "text" :text "Auto-compacted chat"))))) #f(compiled-function (proc raw-output) #<bytecode 0xc524f4b3625a6a0>)(#<process eca> "Content-Length: 188\15\n\15\n{\"jsonrpc\":\"2.0\",\"method\":\"chat/contentReceived\",\"params\":{\"chatId\":\"subagent-4ba73345-5f35-4bbb-b318-0635a1215c72\",\"role\":\"system\",\"content\":{\"type\":\"text\",\"text\":\"Auto-compacted chat\"}}}")`

snoopier avatar Mar 19 '26 14:03 snoopier