kimi-code/packages/agent-core/test/agent/background
Kai c434b4c3e6
fix(agent-core): cap foreground shell output to prevent OOM crash (#1285)
* fix(agent-core): cap foreground shell output to prevent OOM crash

A foreground command that streams a very large or unbounded amount of output (e.g. `b3sum --length 18446744073709551615`) grew the live-output buffer until Node aborted with a JavaScript heap out-of-memory error (exit 134). The per-command output is now capped at 16 MiB: on breach the command is gracefully terminated (SIGTERM -> grace -> SIGKILL) and the result carries a message pointing at redirecting large output to a file. The per-task output ring buffer is also made O(1) per chunk (was O(n^2)), which previously starved the event loop and the foreground timeout. Background/detached tasks are exempt.

* fix(agent-core): stop buffering output after the foreground cap trips

After the 16 MiB foreground ceiling tripped, appendOutput still enqueued every subsequent chunk into the per-task disk write chain during the SIGTERM grace window. A producer that ignores SIGTERM could keep that chain — and the chunk strings each pending write retains — growing until SIGKILL, re-introducing the same out-of-memory risk the cap prevents. Once the cap has tripped, keep only the bounded in-memory ring buffer and stop feeding the disk write chain. Interrupt/timeout capture behaviour is unchanged (they do not set outputLimitTripped).
2026-07-02 13:42:39 +08:00
..
agent-timeout.test.ts feat: detach foreground tasks to background (#821) 2026-06-20 21:24:22 +08:00
foreground-persistence.test.ts feat: detach foreground tasks to background (#821) 2026-06-20 21:24:22 +08:00
heartbeat-stale.test.ts refactor: background task manager persistence (#285) 2026-06-02 12:48:31 +08:00
helpers.ts feat: detach foreground tasks to background (#821) 2026-06-20 21:24:22 +08:00
ids.test.ts feat: detach foreground tasks to background (#821) 2026-06-20 21:24:22 +08:00
manager.test.ts feat: add shell mode (!) to the CLI (#1079) 2026-06-25 21:24:53 +08:00
output-access.test.ts fix: dispose process stdio after managed commands (#822) 2026-06-16 22:09:11 +08:00
output-limit.test.ts fix(agent-core): cap foreground shell output to prevent OOM crash (#1285) 2026-07-02 13:42:39 +08:00
persist.test.ts ci: run unit tests on windows (#1037) 2026-06-26 11:56:41 +08:00
persistence-compat.test.ts refactor: background task manager persistence (#285) 2026-06-02 12:48:31 +08:00
reconcile.test.ts refactor: background task manager persistence (#285) 2026-06-02 12:48:31 +08:00
rpc-events.test.ts refactor: standardize telemetry property names (#1184) 2026-06-29 12:34:38 +08:00