Skip to content

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

Rust

fix(coding-agent): initialize the headless theme in daemon session workers (#2090)

Sebastian Müller9c8230df67b3
diff --git a/packages/coding-agent/.changes/res-1315-worker-theme-init.md b/packages/coding-agent/.changes/res-1315-worker-theme-init.md
new file mode 100644
index 0000000000..b6577d7173
--- /dev/null
+++ b/packages/coding-agent/.changes/res-1315-worker-theme-init.md
@@ -0,0 +1 @@
+- Fixed daemon session workers crashing when a hosted extension touched `ctx.ui.theme` (theme was never initialized in the worker process); workers now initialize the settings theme headlessly at startup, without a theme file watcher.
diff --git a/packages/coding-agent/src/modes/daemon/daemon-mode.ts b/packages/coding-agent/src/modes/daemon/daemon-mode.ts
index 94d456dea5..566761fd6f 100644
--- a/packages/coding-agent/src/modes/daemon/daemon-mode.ts
+++ b/packages/coding-agent/src/modes/daemon/daemon-mode.ts
@@ -111,6 +111,7 @@ import {
} from "../../core/session-manager.js";
import { resolveSessionPath } from "../../core/session-resolver.js";
import type { SessionStats } from "../../core/session-stats.js";
+import { SettingsManager } from "../../core/settings-manager.js";
import { type SideQuestionRun, startSideQuestion } from "../../core/side-question.js";
import { isProcessAlive, spawnHidden, waitForChildProcess } from "../../utils/child-process.js";
import { tryAcquireDirLock } from "../../utils/dir-lock.js";
@@ -123,6 +124,7 @@ import {
import { createAgentConnectionToolDefinition } from "../agent-connection/tool-definition.js";
import type { AgentConnectionHeartbeat, AgentConnectionRlmChildAgentSnapshot } from "../agent-connection/types.js";
import { waitForHeadlessCompletion } from "../headless-completion.js";
+import { initTheme } from "../interactive/theme/theme.js";
import { attachJsonlLineReader, serializeJsonLine } from "../rpc/jsonl.js";
import { encodePrivateFrame, PrivateFrameDecoder } from "../session-worker/private-framing.js";
import {
@@ -595,6 +597,11 @@ export class AgentDaemon {
throw new Error("Daemon config is missing agentDir");
}
this.agentDir = options.defaultSessionConfig.agentDir;
+ // Hosted extensions get ctx.ui.theme; init it headlessly (no TTY, watcher off) or their first access kills the worker.
+ initTheme(
+ SettingsManager.create(options.defaultSessionConfig.cwd ?? process.cwd(), this.agentDir).getTheme(),
+ false,
+ );
this.cronStore = options.worker
? AgentCronJobStore.forSessionArtifacts()
: new AgentCronJobStore(getCronJobsPath(this.agentDir));
diff --git a/packages/coding-agent/test/daemon-mode.test.ts b/packages/coding-agent/test/daemon-mode.test.ts
index 6f7f7a6afc..99e82fd4a6 100644
--- a/packages/coding-agent/test/daemon-mode.test.ts
+++ b/packages/coding-agent/test/daemon-mode.test.ts
@@ -75,8 +75,25 @@ import { activeActivityForSession, type SessionSummary } from "../src/modes/daem
import { DAEMON_WORKER_SUPERVISOR_SOCKET_ENV } from "../src/modes/daemon/daemon-worker-protocol.js";
import { RlmSpawnLedger } from "../src/modes/daemon/rlm-ledger.js";
import { WorkerRecoveryJournal } from "../src/modes/daemon/worker-recovery-journal.js";
+import * as themeModule from "../src/modes/interactive/theme/theme.js";
describe("daemon mode helpers", () => {
+ it("initializes the headless theme for hosted extensions", () => {
+ const initSpy = vi.spyOn(themeModule, "initTheme");
+ try {
+ new AgentDaemon("/tmp/unused-daemon.sock", {
+ defaultSessionConfig: { agentDir: "/tmp", cwd: "/tmp" },
+ createRuntime: vi.fn(),
+ });
+ // Extensions receive this proxy via ctx.ui.theme; the watcher stays off in the headless worker.
+ expect(initSpy).toHaveBeenCalledOnce();
+ expect(initSpy.mock.calls[0]?.[1]).toBe(false);
+ expect(() => themeModule.theme.fg("dim", "worker")).not.toThrow();
+ } finally {
+ initSpy.mockRestore();
+ }
+ });
+
it("preserves envelope client identity while registering prompt admission", () => {
const daemon = new AgentDaemon("/tmp/unused-daemon.sock", {
defaultSessionConfig: { agentDir: "/tmp", cwd: "/tmp" },