Repository navigation
IPython tool stops working after ~1,170 cells: the kernel client never reads execute_reply, so the kernel stops answering
#3966
peymanr
started this conversation in
Bug reports
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Version: prime-agent 0.8.1 (TypeScript, release tarball); Python 3.11 kernel (ipykernel / jupyter_client); Linux x86_64. Running headless (
--print --mode json) with theipythontool.What happens
In a long session, after roughly 570–600
ipythontool calls, every call returns:From then on the session can't run code. A headless session can't answer the wait/kill choice, so it is stuck until the process is restarted.
It always happens at about the same number of cells, no matter what the cells do: the cell just before the first error is usually trivial and took milliseconds.
Cause
The kernel client in
packages/coding-agent/src/core/kernel/index.ts(dist/core/kernel/index.js):execute_requeston the shell channel;status: idlemessage (handleExecutionMessage);execute_replythat the kernel sends for every request.After each successful cell the tool also runs a snapshot cell, so one tool call is about two executions. The unread replies accumulate, and once about 1,180 have piled up the kernel takes no further requests. Its threads are idle and no iopub
idlearrives. The next execution, usually a snapshot cell with a 5 s limit, gets interrupted, and the "previously interrupted cell" error follows from then on.The exact limit depends on the host. On one Linux server it was 1,179 executions every time. On a WSL2 machine a client ran 16,000 executions without hanging, which may be why this doesn't show up in development.
Reproduction (no LLM needed)
jupyter_clientclient that sendsexecute_requeston the shell channel, waits for iopubstatus: idle, and never receives from the shell socket. It stops gettingidleat execution 1,179, every time, on the affected host.execute_reply): it runs 2,800+ executions without a problem.ipythoncalls such asprint(1): it hangs at around cell 1,169. With the workaround below, it runs past 1,300.Suggested fix
Have the kernel client consume the shell channel:
execute_replyfor each request, matched byparent_header.msg_id;idle, or at least drain it;Workaround we use
Start each session's kernel with its own IPython profile (
IPYTHONDIR) whoseipython_kernel_config.pymakesSession.senddropexecute_replymessages, so nothing accumulates. This is safe only because 0.8.1 never reads them. It would break a client that waits for them.We also set
HistoryManager.hist_file = ":memory:". All kernels on a host otherwise share one history SQLite file, which grows quickly because the snapshot cells are large.All reactions