Skip to content

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

Rust

fix(coding-agent): reset daemon root depth (#1496)

Seth Kartene85a67ac4ad7
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index 87fcba8402..647fbcfd19 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -2,6 +2,8 @@
## [Unreleased]
+- Fixed new top-level daemon sessions inheriting an RLM child depth from the supervisor process.
+
## [0.7.3] - 2026-08-17
- Fixed assistant rendering when provider payloads contain null or sparse content blocks.
diff --git a/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts b/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts
index 56874b8812..ec3711c2b7 100644
--- a/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts
+++ b/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts
@@ -2181,23 +2181,25 @@ export class DaemonSupervisor {
const orphanProcessJournalPath =
existing?.descriptor.orphanProcessJournalPath ?? join(this.descriptorDir, `${workerId}.orphans.jsonl`);
const launch = createCliSubprocessLaunchSpec(["--mode", "daemon", "--daemon-socket", socketPath]);
+ const workerEnvironment = createCliSubprocessEnv({
+ ...process.env,
+ ...launchEnv,
+ [DAEMON_WORKER_ROLE_ENV]: "1",
+ [DAEMON_WORKER_TOKEN_ENV]: token,
+ [DAEMON_WORKER_ACTIVE_SESSION_ID_ENV]: rootActiveSessionId,
+ [DAEMON_WORKER_SUPERVISOR_SOCKET_ENV]: this.socketPath,
+ [DAEMON_WORKER_RECOVERY_JOURNAL_ENV]: recoveryJournalPath,
+ [DAEMON_WORKER_STARTUP_GATE_FD_ENV]: String(WORKER_STARTUP_GATE_FD),
+ [ORPHAN_PROCESS_JOURNAL_ENV]: orphanProcessJournalPath,
+ [SESSION_LEASES_ENABLED_ENV]: "1",
+ [SESSION_LEASE_OWNER_ID_ENV]: rootActiveSessionId,
+ });
+ delete workerEnvironment.RLM_DEPTH;
await this.assertRecoveryAllowed();
const child: ChildProcess = spawn(launch.command, launch.args, {
cwd: createCommand.config?.cwd ?? process.cwd(),
detached: true,
- env: createCliSubprocessEnv({
- ...process.env,
- ...launchEnv,
- [DAEMON_WORKER_ROLE_ENV]: "1",
- [DAEMON_WORKER_TOKEN_ENV]: token,
- [DAEMON_WORKER_ACTIVE_SESSION_ID_ENV]: rootActiveSessionId,
- [DAEMON_WORKER_SUPERVISOR_SOCKET_ENV]: this.socketPath,
- [DAEMON_WORKER_RECOVERY_JOURNAL_ENV]: recoveryJournalPath,
- [DAEMON_WORKER_STARTUP_GATE_FD_ENV]: String(WORKER_STARTUP_GATE_FD),
- [ORPHAN_PROCESS_JOURNAL_ENV]: orphanProcessJournalPath,
- [SESSION_LEASES_ENABLED_ENV]: "1",
- [SESSION_LEASE_OWNER_ID_ENV]: rootActiveSessionId,
- }),
+ env: workerEnvironment,
stdio: ["ignore", "ignore", "pipe", "pipe"],
});
const detachWorkerStderr = child.stderr
diff --git a/packages/coding-agent/test/daemon-supervisor-process.test.ts b/packages/coding-agent/test/daemon-supervisor-process.test.ts
index 27fc3cb3b1..18f8f62ed3 100644
--- a/packages/coding-agent/test/daemon-supervisor-process.test.ts
+++ b/packages/coding-agent/test/daemon-supervisor-process.test.ts
@@ -80,6 +80,7 @@ function spawnSupervisor(
socketPath: string,
cwd: string,
extraArgs: readonly string[] = [],
+ extraEnv: NodeJS.ProcessEnv = {},
): ChildProcess {
daemonSockets.add(socketPath);
const child = spawn(
@@ -89,6 +90,7 @@ function spawnSupervisor(
cwd,
env: {
...process.env,
+ ...extraEnv,
[ENV_AGENT_DIR]: agentDir,
PI_OFFLINE: "1",
TSX_TSCONFIG_PATH: resolve(__dirname, "../../../tsconfig.json"),
@@ -286,6 +288,35 @@ async function startBlockingBash(client: DaemonClient, activeSessionId: string,
}
describe("daemon supervisor resident workers", () => {
+ it("creates top-level sessions at depth zero when the supervisor inherits a child depth", async () => {
+ const root = tempDir();
+ const agentDir = join(root, "agent");
+ const projectDir = join(root, "project");
+ const sessionDir = join(agentDir, "sessions");
+ const socketPath = join(tmpdir(), `prime-supervisor-depth-${process.pid}-${randomUUID().slice(0, 8)}.sock`);
+ mkdirSync(projectDir, { recursive: true });
+
+ const supervisor = spawnSupervisor(agentDir, socketPath, projectDir, [], { RLM_DEPTH: "1" });
+ const client = await connectEventually(socketPath, supervisor);
+ const created = await client.request({
+ type: "create",
+ config: { cwd: projectDir, agentDir, sessionDir, noTools: true, noExtensions: true },
+ });
+ if (!created.success) throw new Error(created.error);
+ const summary = requireSummary(created.data);
+ if (!summary.workerPid || !summary.sessionFile) throw new Error("Worker did not expose its session identity");
+ workerPids.add(summary.workerPid);
+
+ expect(summary).toMatchObject({ runtimeKind: "top-level", rlmDepth: 0 });
+ expect(await readSessionInfo(summary.sessionFile)).toMatchObject({ rlmDepth: 0, parentSessionPath: undefined });
+
+ await client.request({ type: "shutdown" });
+ client.close();
+ await waitForProcessGone(summary.workerPid);
+ workerPids.delete(summary.workerPid);
+ await waitForSocketGone(socketPath);
+ }, 60_000);
+
it("lists, creates, and attaches passive children through their owning worker", async () => {
const root = tempDir();
const agentDir = join(root, "agent");