A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
[RSI, performance] perf(coding-agent): cap cell source attached to kernel host requests (#2475)
Sebastian Müller561401b273b5
diff --git a/packages/coding-agent/.changes/cap-spawn-cell-source.md b/packages/coding-agent/.changes/cap-spawn-cell-source.mdnew file mode 100644index 0000000000..1aec54affb--- /dev/null+++ b/packages/coding-agent/.changes/cap-spawn-cell-source.md@@ -0,0 +1 @@+- Capped the spawning cell source attached to kernel host requests at 2KB with a truncation marker, so oversized cells stop re-shipping their full source on every spawn/progress-note/collect round trip and in each child's persisted spawnCode.diff --git a/packages/coding-agent/src/core/kernel/repl-manager.ts b/packages/coding-agent/src/core/kernel/repl-manager.tsindex 584e5e76f0..7c7ef2c6f6 100644--- a/packages/coding-agent/src/core/kernel/repl-manager.ts+++ b/packages/coding-agent/src/core/kernel/repl-manager.ts@@ -74,6 +74,11 @@ const MAX_BACKGROUND_OUTPUT_CHARS = 64 * 1024;// MAX_ATTACHMENT_DATA_CHARS; a line that cannot complete within this ceiling is// corruption the protocol repair owns, not output worth buffering until OOM.const MAX_PROTOCOL_LINE_CHARS = 32 * 1024 * 1024;+// The spawning cell's source rides every host-request round trip and persists per child+// as runtimeMetadata.spawnCode, so cap it once at this boundary.+// Keep below SPAWN_CODE_MAX_CHARS in daemon-session-list.ts so its 4000-char display slice stays a no-op.+const MAX_CELL_SOURCE_CHARS = 2 * 1024;+const CELL_SOURCE_TRUNCATION_MARKER = ` [... cell source truncated at ${MAX_CELL_SOURCE_CHARS} chars ...]`;const MAX_KERNEL_STDERR_CHARS = 8 * 1024;const MAX_KERNEL_STDERR_LOG_BYTES = 5 * 1024 * 1024;@@ -91,6 +96,11 @@ function writeFullySync(fd: number, data: Buffer): void {}}+function capCellSourceCode(code: string | undefined): string | undefined {+ if (code === undefined || code.length <= MAX_CELL_SOURCE_CHARS) return code;+ return `${code.slice(0, MAX_CELL_SOURCE_CHARS)}${CELL_SOURCE_TRUNCATION_MARKER}`;+}+/** ExecuteResult plus the raw fields of the request's `done` event (state ops). */interface InternalExecuteResult extends ExecuteResult {doneFields?: Record<string, unknown>;@@ -1344,7 +1354,7 @@ export class ReplKernelManager {// Tag the request with the cell that triggered it. A blocking call is still// the in-flight execution; detached spawns (asyncio.create_task) fire after// the scheduling cell goes idle, so fall back to that last cell's source.- const cellSourceCode = this.activeExecution?.code ?? this.lastCellCode;+ const cellSourceCode = capCellSourceCode(this.activeExecution?.code ?? this.lastCellCode);return handler({ ...data, cellSourceCode });}diff --git a/packages/coding-agent/test/repl-kernel-execute.test.ts b/packages/coding-agent/test/repl-kernel-execute.test.tsindex 5365fcdd16..17a2870184 100644--- a/packages/coding-agent/test/repl-kernel-execute.test.ts+++ b/packages/coding-agent/test/repl-kernel-execute.test.ts@@ -120,6 +120,11 @@ describeIf("ReplKernelManager execute (real runtime)", () => {const unknown = await manager.execute("import rlm\nawait rlm.host_request('test.unknown')");expect(unknown.status).toBe("error");expect(unknown.error?.evalue).toContain('host request type "test.unknown" is not available');++ const padded = `${"# pad\n".repeat(500)}import rlm\nreply = await rlm.host_request('test.echo', {'value': 9, 'cellSourceCode': 'FAKE'})\n[len(reply['cell']), reply['cell'].endswith(' [... cell source truncated at 2048 chars ...]'), reply['cell'] == 'FAKE']`;+ const capped = await manager.execute(padded);+ expect(capped.status).toBe("ok");+ expect(capped.result).toBe("[2094, True, False]");}, 30_000);it("spawns through rlm.spawn over the unchanged rlm.run wire type, requires a child name, and refuses a direct rlm call", async () => {