Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

Remove unused kernel seams (#1835)

Sebastian Müller5e0e288a883f
diff --git a/packages/coding-agent/.changes/remove-unused-kernel-seams.md b/packages/coding-agent/.changes/remove-unused-kernel-seams.md
new file mode 100644
index 0000000000..90986ab262
--- /dev/null
+++ b/packages/coding-agent/.changes/remove-unused-kernel-seams.md
@@ -0,0 +1 @@
+- Removed unused host-request capability helpers and the `kernelManagerRef` option from `IpythonToolOptions`.
diff --git a/packages/coding-agent/src/core/kernel/shared.ts b/packages/coding-agent/src/core/kernel/shared.ts
index bdaec97126..5d08f027a2 100644
--- a/packages/coding-agent/src/core/kernel/shared.ts
+++ b/packages/coding-agent/src/core/kernel/shared.ts
@@ -27,85 +27,9 @@ export class KernelBusyAfterInterruptError extends Error {
/**
* Handles one typed request from Python code running in the kernel.
* The returned record is sent back verbatim as the reply payload.
- *
- * The unary form is the dispatcher and registration contract; context-aware
- * handlers are declared separately below.
*/
export type HostRequestHandler = (payload: Record<string, unknown>) => Promise<Record<string, unknown>>;
-/**
- * Per-call authority supplied by the host-request dispatcher.
- * `requestId` is an opaque host-minted correlation token and `isCurrent()`
- * lets an implementation reject work after its authority is revoked.
- */
-export interface HostRequestContext {
- readonly requestId: string;
- readonly generation: number;
- readonly signal: AbortSignal;
- isCurrent(): boolean;
-}
-
-const hostRequestHandlerBrand = Symbol("hostRequestHandler");
-
-/** A context-aware implementation that must receive dispatcher authority. */
-export type HostRequestHandlerImplementation = (
- payload: Record<string, unknown>,
- context: HostRequestContext,
-) => Promise<Record<string, unknown>>;
-
-/** A factory-minted, context-aware host-request handler capability. */
-type HostRequestHandlerCapability = HostRequestHandlerImplementation & { readonly [hostRequestHandlerBrand]: true };
-
-/** Runtime provenance cannot be recreated by copying the nominal symbol property. */
-const factoryCreatedHostRequestHandlers = new WeakSet<object>();
-
-function assertGenuineHostRequestContext(context: unknown): asserts context is HostRequestContext {
- if (
- typeof context !== "object" ||
- context === null ||
- typeof (context as HostRequestContext).requestId !== "string" ||
- !(context as HostRequestContext).requestId ||
- !Number.isSafeInteger((context as HostRequestContext).generation) ||
- typeof (context as HostRequestContext).isCurrent !== "function" ||
- typeof (context as HostRequestContext).signal !== "object" ||
- (context as HostRequestContext).signal === null ||
- typeof (context as HostRequestContext).signal.aborted !== "boolean" ||
- typeof (context as HostRequestContext).signal.addEventListener !== "function"
- ) {
- throw new Error("host request context is invalid");
- }
-}
-
-/**
- * Creates a branded wrapper rather than mutating its implementation. Both its
- * generic shape and runtime arity reject unary callbacks before they can run.
- */
-export function createHostRequestHandler<T extends HostRequestHandlerImplementation>(
- implementation: T,
- ..._unaryRejection: Parameters<T> extends [unknown, unknown, ...unknown[]]
- ? []
- : ["host request handlers must accept payload and context"]
-): HostRequestHandlerCapability {
- if (implementation.length < 2) throw new Error("host request handlers must accept payload and context");
- const handler = async (payload: Record<string, unknown>, context: HostRequestContext) => {
- assertGenuineHostRequestContext(context);
- return implementation(payload, context);
- };
- factoryCreatedHostRequestHandlers.add(handler);
- return Object.defineProperty(handler, hostRequestHandlerBrand, { value: true }) as HostRequestHandlerCapability;
-}
-
-/** Reject copied-symbol and raw-function forgeries before they observe authenticated payloads. */
-export function assertHostRequestHandler(value: unknown): asserts value is HostRequestHandlerCapability {
- if (
- typeof value !== "function" ||
- (value as Partial<HostRequestHandlerCapability>)[hostRequestHandlerBrand] !== true ||
- !factoryCreatedHostRequestHandlers.has(value)
- ) {
- throw new Error("host request handler is not a dispatcher-created capability");
- }
-}
-
/** Host request handlers keyed by request type (e.g. "rlm.run", "goal.complete"). */
export type HostRequestHandlers = Record<string, HostRequestHandler>;
diff --git a/packages/coding-agent/src/core/tools/ipython.ts b/packages/coding-agent/src/core/tools/ipython.ts
index 50933ea1c2..bedf72d0ea 100644
--- a/packages/coding-agent/src/core/tools/ipython.ts
+++ b/packages/coding-agent/src/core/tools/ipython.ts
@@ -287,8 +287,6 @@ export interface IpythonToolOptions {
/** Resolves before this kernel starts — e.g. the previous provisioner's dispose, so a
* /reload's old-kernel snapshot flush can't race the new kernel's restore. */
readyGate?: Promise<unknown>;
- /** Filled with the live kernel client after the first kernel start; cleared on construction. */
- kernelManagerRef?: { current?: KernelClient };
/**
* Fires once per kernel start when a previous session's namespace was revived
* (some names restored or some failed), so the session can tell the model.
@@ -317,11 +315,7 @@ export class IpythonKernelProvisioner {
constructor(
private readonly cwd: string,
private readonly options?: Omit<IpythonToolOptions, "provisioner">,
- ) {
- if (options?.kernelManagerRef) {
- options.kernelManagerRef.current = undefined;
- }
- }
+ ) {}
/** The kernel manager, once a startup has completed successfully. */
get manager(): KernelClient | undefined {
@@ -365,9 +359,6 @@ export class IpythonKernelProvisioner {
const pending = this.managerPromise;
this.managerPromise = undefined;
this.startedManager = undefined;
- if (this.options?.kernelManagerRef) {
- this.options.kernelManagerRef.current = undefined;
- }
if (!pending) return;
try {
const m = await pending;
@@ -381,9 +372,6 @@ export class IpythonKernelProvisioner {
const pending = this.managerPromise;
this.managerPromise = undefined;
this.startedManager = undefined;
- if (this.options?.kernelManagerRef) {
- this.options.kernelManagerRef.current = undefined;
- }
if (!pending) return;
try {
const m = await pending;
@@ -530,9 +518,6 @@ export class IpythonKernelProvisioner {
this._lastRestore = pendingRestore;
this.options?.onRestore?.(pendingRestore);
}
- if (this.options?.kernelManagerRef) {
- this.options.kernelManagerRef.current = m;
- }
return m;
} finally {
startupAbort.cleanup();
diff --git a/packages/coding-agent/test/host-request-context.ts b/packages/coding-agent/test/host-request-context.ts
deleted file mode 100644
index a74f1a4ee2..0000000000
--- a/packages/coding-agent/test/host-request-context.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-import {
- createHostRequestHandler,
- type HostRequestContext,
- type HostRequestHandlerImplementation,
-} from "../src/core/kernel/index.js";
-
-let nextSyntheticHostRequestId = 0;
-
-/** Create a distinct, current dispatcher context for direct host-handler tests. */
-export function createSyntheticHostRequestContext(): HostRequestContext {
- const requestNumber = ++nextSyntheticHostRequestId;
- const controller = new AbortController();
- return {
- requestId: `test-host-request-${requestNumber}`,
- generation: requestNumber,
- signal: controller.signal,
- isCurrent: () => !controller.signal.aborted,
- };
-}
-
-/** Invoke a production-shaped handler with a synthetic dispatcher context. */
-export function invokeHostRequest(
- handler: HostRequestHandlerImplementation,
- payload: Record<string, unknown>,
-): Promise<Record<string, unknown>> {
- return handler(payload, createSyntheticHostRequestContext());
-}
-
-/** Build staged context-aware fixture handlers through the production factory. */
-export function createTestHostHandlers<
- T extends Record<
- string,
- (payload: Record<string, unknown>, context: HostRequestContext) => Promise<Record<string, unknown>>
- >,
->(handlers: T): Record<keyof T, HostRequestHandlerImplementation> {
- return Object.fromEntries(
- Object.entries(handlers).map(([type, handler]) => [type, createHostRequestHandler(handler)]),
- ) as unknown as Record<keyof T, HostRequestHandlerImplementation>;
-}
diff --git a/packages/coding-agent/test/host-request-contract.test.ts b/packages/coding-agent/test/host-request-contract.test.ts
deleted file mode 100644
index 2a22ceae02..0000000000
--- a/packages/coding-agent/test/host-request-contract.test.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { describe, expect, it } from "vitest";
-import {
- assertHostRequestHandler,
- createHostRequestHandler,
- type HostRequestContext,
-} from "../src/core/kernel/index.js";
-
-describe("staged host-request handler authority", () => {
- it("rejects unary factory inputs before they run", () => {
- let calls = 0;
- const unary = async (_payload: Record<string, unknown>): Promise<Record<string, unknown>> => {
- calls += 1;
- return {};
- };
-
- expect(() => {
- // @ts-expect-error Staged handlers must accept dispatcher context as their second argument.
- createHostRequestHandler(unary);
- }).toThrow("host request handlers must accept payload and context");
- expect(calls).toBe(0);
- });
-
- it("rejects missing or invalid context before a genuine handler runs", async () => {
- let calls = 0;
- const handler = createHostRequestHandler(async (_payload, _context) => {
- calls += 1;
- return {};
- });
-
- assertHostRequestHandler(handler);
- // @ts-expect-error A staged handler cannot be invoked without dispatcher context.
- await expect(handler({})).rejects.toThrow("host request context is invalid");
- await expect(handler({}, {} as HostRequestContext)).rejects.toThrow("host request context is invalid");
- expect(calls).toBe(0);
- });
-
- it("rejects copied-symbol forgeries through WeakSet provenance before they run", () => {
- const genuine = createHostRequestHandler(async (_payload, _context) => ({}));
- let calls = 0;
- const forged = async (): Promise<Record<string, unknown>> => {
- calls += 1;
- return {};
- };
- const brand = Object.getOwnPropertySymbols(genuine)[0];
- Object.defineProperty(forged, brand, Object.getOwnPropertyDescriptor(genuine, brand)!);
-
- expect(() => assertHostRequestHandler(forged)).toThrow(
- "host request handler is not a dispatcher-created capability",
- );
- expect(calls).toBe(0);
- });
-});