Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: computer use grants follow the server grant epoch

ogsamratd61b72ae915b
diff --git a/apps/desktop/electron/computer-use.mjs b/apps/desktop/electron/computer-use.mjs
index bd137182..251c1e8c 100644
--- a/apps/desktop/electron/computer-use.mjs
+++ b/apps/desktop/electron/computer-use.mjs
@@ -168,7 +168,7 @@ const approve = {
function hostSettings() {
const setting = server?.setting ?? {};
- return { enabled: server?.enabled === true, real_screen: setting.real_screen !== false, limits: setting.limits ?? null, deny_apps: setting.deny_apps ?? [], mode: server?.mode ?? "normal", message: setting.message ?? null, ask_send_delete: setting.ask_send_delete === true };
+ return { enabled: server?.enabled === true, real_screen: setting.real_screen !== false, limits: setting.limits ?? null, deny_apps: setting.deny_apps ?? [], mode: server?.mode ?? "normal", message: setting.message ?? null, ask_send_delete: setting.ask_send_delete === true, grant_epoch: Number.isSafeInteger(setting.grant_epoch) ? setting.grant_epoch : null, chat_bound_read: setting.chat_bound_read === true };
}
async function hostContext() {
@@ -302,7 +302,7 @@ async function getComputerUseMcpCommand() {
await startHost();
const relay = app.isPackaged ? path.join(process.resourcesPath, "computer-use", "relay.mjs") : path.join(__dirname, "computer-use-relay.mjs");
// The copied CLI connection: its own token (cli-connection.json), so its calls belong to no chat of this app
- // and never keep or reuse "Allow for this chat". The engine's relay alone reads connection.json.
+ // and never keep or reuse "Allow for this chat". The engine's relay alone reads engine-connection.json.
return [process.execPath, relay, listener.externalDiscoveryPath];
}
diff --git a/apps/server/src/computer-use/desktop.test.ts b/apps/server/src/computer-use/desktop.test.ts
index 5507fdcf..c4d828e7 100644
--- a/apps/server/src/computer-use/desktop.test.ts
+++ b/apps/server/src/computer-use/desktop.test.ts
@@ -66,7 +66,9 @@ describe("switch and built-in entry", () => {
expect(chats.only(null)).toBeNull();
expect(chats.only([])).toBeNull();
expect(chats.only(["ses_b"])).toBe("ses_b");
- expect(chats.only(["ses_b", "ses_child_of_b"])).toBe("ses_b");
+ // Running chats come without sub-agent sessions; an unmarked running chat (steered, not captured) counts.
+ expect(chats.only(["ses_b", "ses_b"])).toBe("ses_b");
+ expect(chats.only(["ses_b", "ses_unmarked"])).toBeNull();
expect(chats.only(["ses_a", "ses_b"])).toBeNull();
expect(chats.only(["ses_unmarked"])).toBeNull();
expect(sessionEventOf({ event: "opened", by: "agent", app_id: "/usr/bin/gedit", screen: { id: "0", width: 10, height: 5, scale: 1 }, junk: 1 })).toEqual({ event: "opened", by: "agent", app_id: "/usr/bin/gedit", screen: { id: "0", width: 10, height: 5, scale: 1 } });
diff --git a/apps/server/src/computer-use/desktop.ts b/apps/server/src/computer-use/desktop.ts
index d8a52dcf..5df0a0b9 100644
--- a/apps/server/src/computer-use/desktop.ts
+++ b/apps/server/src/computer-use/desktop.ts
@@ -72,7 +72,7 @@ export function expectedHostCommand(env: Record<string, string | undefined> = pr
const resources = (process as { resourcesPath?: string }).resourcesPath;
const packaged = resources ? join(resources, "computer-use", "relay.mjs") : null;
const relay = packaged && existsSync(packaged) ? packaged : fileURLToPath(new URL("../../../desktop/electron/computer-use-relay.mjs", import.meta.url));
- return { command: [process.execPath, relay, join(profile, "computer-use", "connection.json")], environment: { ELECTRON_RUN_AS_NODE: "1" } };
+ return { command: [process.execPath, relay, join(profile, "computer-use", "engine-connection.json")], environment: { ELECTRON_RUN_AS_NODE: "1" } };
}
export function computerUseEngineEnv(stateDir: string, env: Record<string, string | undefined> = process.env): Record<string, string> {
@@ -175,13 +175,14 @@ export function createChatTracker(limit = 64) {
if (order.length > limit) order.splice(0, order.length - limit);
},
/**
- * The one chat a call can belong to, for "Allow for this chat": exactly one prompted chat is running.
- * Running unknown (null), none or several: null, so no grant is kept or reused (the person is asked).
+ * The one chat a call can belong to, for "Allow for this chat": `running` (the engine's running top-level
+ * chats, marked or not) is exactly one chat, and the person prompted it here. Unknown (null), none,
+ * several, or one never prompted here: null, so no grant is kept or reused (the person is asked).
*/
only(running: string[] | null): string | null {
if (!running) return null;
- const live = order.filter((id) => running.includes(id));
- return live.length === 1 ? live[0]! : null;
+ const chats = [...new Set(running)];
+ return chats.length === 1 && order.includes(chats[0]!) ? chats[0]! : null;
},
/** The chat to record a trace event on: the latest prompted chat still running, else the latest. */
resolve(running: string[] | null): string | null {
diff --git a/apps/server/src/computer-use/portable-host.test.ts b/apps/server/src/computer-use/portable-host.test.ts
index 7845a38f..c05f57dd 100644
--- a/apps/server/src/computer-use/portable-host.test.ts
+++ b/apps/server/src/computer-use/portable-host.test.ts
@@ -72,7 +72,8 @@ function rig(mode: "careful" | "normal" | "auto", options: { decision?: "chat" |
const events: Array<Record<string, unknown>> = [];
const opens: OpenRequest[] = [];
const acts: ActRequest[] = [];
- const settings = { enabled: options.enabled ?? true, real_screen: true, limits: options.limits ?? {}, deny_apps: [], mode };
+ // As a fresh server read gives them: the grant epoch and the chat bound the server sent.
+ const settings: Record<string, unknown> & { enabled: boolean; limits: Record<string, number> } = { enabled: options.enabled ?? true, real_screen: true, limits: options.limits ?? {}, deny_apps: [], mode, grant_epoch: 1, chat_bound_read: true };
const hostPromise = createPortableHost({
native,
spool: createMediaSpool(path.join(dir, "spool")),
@@ -288,6 +289,45 @@ describe("portable host: MCP surface and consent", () => {
await host.close();
});
+ test("grant epoch: off -> on with no open asks again; no epoch or no chat bound: never reused; a Deny withdraws the grant", async () => {
+ const open = { app_id: "/usr/bin/gedit", mode: "control", purpose: "Write" };
+ const cycle = async (c: { handle: (m: unknown) => Promise<unknown> }) => { const x = await call(c, "computer_open_session", open); if (x.state.session_id) await call(c, "computer_close_session", { session_id: x.state.session_id }); return x; };
+ // Same epoch: reused. The server switched off and on (epoch 1 -> 3): asked again.
+ {
+ const r = rig("normal", { decision: "chat" });
+ const host = await r.hostPromise; const c = host.connect();
+ await cycle(c); await cycle(c);
+ expect(r.opens.length).toBe(1);
+ r.settings.grant_epoch = 3;
+ await cycle(c);
+ expect(r.opens.length).toBe(2);
+ await host.close();
+ }
+ // No epoch (an older server), or the bound not sent: asked every time.
+ for (const change of [{ grant_epoch: null }, { grant_epoch: undefined }, { chat_bound_read: false }]) {
+ const r = rig("normal", { decision: "chat" });
+ Object.assign(r.settings, change);
+ const host = await r.hostPromise; const c = host.connect();
+ await cycle(c); await cycle(c);
+ expect(r.opens.length).toBe(2);
+ await host.close();
+ }
+ // Allow for this chat, then (the epoch moved, so asked) Deny, then the old epoch again: still asked.
+ {
+ const r = rig("normal");
+ const answers = ["chat", "deny", "chat"];
+ const host = await createPortableHost({ native: r.native, settings: () => r.settings, context: () => ({ ancestors: [], chat: "ses_1" }), approve: { open: async (request: OpenRequest) => { r.opens.push(request); return { decision: answers.shift() as "chat" | "deny", window_id: request.window_id }; }, act: async () => ({ allow: true }) } });
+ const c = host.connect();
+ await cycle(c);
+ r.settings.grant_epoch = 2;
+ expect((await cycle(c)).state).toMatchObject({ ok: false, code: "approval_denied" });
+ r.settings.grant_epoch = 1;
+ await cycle(c);
+ expect(r.opens.length).toBe(3);
+ await host.close();
+ }
+ });
+
test("off by the server: no session", async () => {
const r = rig("normal", { enabled: false });
const host = await r.hostPromise;
diff --git a/apps/server/src/computer-use/routes.ts b/apps/server/src/computer-use/routes.ts
index 92bfd599..234a49a8 100644
--- a/apps/server/src/computer-use/routes.ts
+++ b/apps/server/src/computer-use/routes.ts
@@ -54,7 +54,7 @@ export function registerComputerUseRoutes(deps: ComputerUseRouteDeps): void {
const chat = deps.chats.only(await deps.runningSessions().catch(() => null));
return {
enabled: setting.enabled,
- setting: { enabled: setting.enabled, real_screen: setting.real_screen, virtual_display: setting.virtual_display, limits: setting.limits, deny_apps: setting.deny_apps, models: setting.models, message: setting.message, ask_send_delete: setting.ask_send_delete === true, reason: setting.reason, source: setting.source },
+ setting: { enabled: setting.enabled, real_screen: setting.real_screen, virtual_display: setting.virtual_display, limits: setting.limits, deny_apps: setting.deny_apps, models: setting.models, message: setting.message, ask_send_delete: setting.ask_send_delete === true, grant_epoch: setting.grant_epoch ?? null, chat_bound_read: setting.chat_bound_read === true, reason: setting.reason, source: setting.source },
mode,
dir,
spool: mediaSpoolDir(deps.stateDir()),
diff --git a/apps/server/src/computer-use/shared/PARITY.sha256 b/apps/server/src/computer-use/shared/PARITY.sha256
index a8eebc5f..66c82dd4 100644
--- a/apps/server/src/computer-use/shared/PARITY.sha256
+++ b/apps/server/src/computer-use/shared/PARITY.sha256
@@ -2,12 +2,12 @@
# A change to one must be ported to the other and this list updated in both.
59abb350a935c9462f3ea2e863396cdc785634dd2907f2f8947d87e9b30ec209 contract.mjs
aef0973f520f56ab8ad2699c14428bb2dd7ddb4b00dff823e4598e64d0c4a35b contract.d.mts
-7d823cbd1db3b6a5200f173cfd1567e92804c09267eb06e462e72c5f8f82e3c2 policy.mjs
-31c50348ee77d5f61ba10a59e3ca7ff384c051dd70c60ed10e52b3186ad371d0 policy.d.mts
+afde13ef4a34121c2d2b6cf1e2d4f592e48540979759d73b47ee9a721b8a36ac policy.mjs
+3422c097d4a598017d242ac5b517f30e96f91cdbe93b844d6b238ae6a7c9dea7 policy.d.mts
a96246342720364eb3e5843ba70fbbf640365f94597fc4dbb6a7be7d95254ec4 image.mjs
5eac31868aedd3e1d1e71b445f9a55d01316da7397f27f6db11472453bee4588 image.d.mts
e47c9ff67b9fce2ec12307737e973ce22551719c482b87f601569bd4f8a77e17 media.mjs
eabdf78c56733577d05aad490d9d7d5ece6c22e9b3ea9e6e9803d1a4a546fdd4 media.d.mts
a0bd964a5d0c7c5e26b4ce4ed8e8300f80a0a3a9da5d7f49c36f6ac2c907e934 native-worker.mjs
-3b4b35b82a2e757bc3bd3a6c5bdae032329f49e6eb5eb031882bfbcdaffc263c portable-host.mjs
-94c69e638fa62df889ee5e65d924066ba2b9416d82061490ffc947204379c9fd portable-host.d.mts
+2210a0bf9337cbd2d3ee49f60337c0dc1aefca08705d449a596e20673f70905d portable-host.mjs
+fb2c1dae95e233af20798e0d6700e6f32197f6d4dbf226911beb35fcbff934d9 portable-host.d.mts
diff --git a/apps/server/src/computer-use/shared/policy.d.mts b/apps/server/src/computer-use/shared/policy.d.mts
index e0e5fa25..135f2ce4 100644
--- a/apps/server/src/computer-use/shared/policy.d.mts
+++ b/apps/server/src/computer-use/shared/policy.d.mts
@@ -20,6 +20,10 @@ export type ComputerUseBlock = {
message: string | null;
/** The send/delete asks in Normal (off unless the server says true). */
ask_send_delete: boolean;
+ /** The server's grant epoch (null: not sent): a grant is reused only under the epoch it was given in. */
+ grant_epoch: number | null;
+ /** Whether the server sent limits.chat_approval_seconds itself (false: no grant is reused). */
+ chat_bound_read: boolean;
};
export type ComputerUseSetting = ComputerUseBlock & {
source: "env" | "server" | "default";
diff --git a/apps/server/src/computer-use/shared/policy.mjs b/apps/server/src/computer-use/shared/policy.mjs
index 87bc54f0..c7032507 100644
--- a/apps/server/src/computer-use/shared/policy.mjs
+++ b/apps/server/src/computer-use/shared/policy.mjs
@@ -35,10 +35,11 @@ function text(value, limit = 400) {
* missing or malformed block is off. The server already applied
* `rollout_percent` (and the account) to `enabled`.
* Shape: { enabled, clients, os, models, real_screen, virtual_display,
- * deny_apps, limits, message, ask_send_delete } (null lists: no restriction).
+ * deny_apps, limits, message, ask_send_delete, grant_epoch, chat_bound_read }
+ * (null lists: no restriction).
*/
export function normalizeComputerUse(block) {
- if (!isRecord(block)) return { enabled: false, clients: null, os: null, models: null, real_screen: false, virtual_display: false, deny_apps: [], limits: normalizeLimits(null), message: null, ask_send_delete: false };
+ if (!isRecord(block)) return { enabled: false, clients: null, os: null, models: null, real_screen: false, virtual_display: false, deny_apps: [], limits: normalizeLimits(null), message: null, ask_send_delete: false, grant_epoch: null, chat_bound_read: false };
const denyApps = Array.isArray(block.deny_apps)
? block.deny_apps.flatMap((item) => {
if (typeof item === "string" && item.trim()) return [{ match: item.trim().slice(0, 200), reason: null }];
@@ -58,6 +59,11 @@ export function normalizeComputerUse(block) {
message: text(block.message),
// The send/delete asks in Normal (actApproval options.sendDelete): only an explicit true turns them on.
ask_send_delete: block.ask_send_delete === true,
+ // "Allow for this chat" is reused only under the epoch it was given in (the server bumps it when the
+ // switch or the bound changes) and only when the server sent the bound itself: else null / false.
+ grant_epoch: Number.isSafeInteger(block.grant_epoch) && block.grant_epoch >= 0 ? block.grant_epoch : null,
+ // (A block normalized here once already keeps its answer: its limits are filled in by then.)
+ chat_bound_read: block.chat_bound_read === false ? false : isRecord(block.limits) && typeof block.limits.chat_approval_seconds === "number" && Number.isFinite(block.limits.chat_approval_seconds),
};
}
diff --git a/apps/server/src/computer-use/shared/portable-host.d.mts b/apps/server/src/computer-use/shared/portable-host.d.mts
index 975f4503..6a06dac3 100644
--- a/apps/server/src/computer-use/shared/portable-host.d.mts
+++ b/apps/server/src/computer-use/shared/portable-host.d.mts
@@ -16,7 +16,7 @@ export type NativeWorker = {
};
export function createNativeWorker(options?: { workerPath?: string; nodePath?: string; nodeEnv?: Record<string, string>; koffiPath?: string; timeoutMs?: number }): NativeWorker;
-export type HostSettings = { enabled: boolean; real_screen?: boolean; limits?: Partial<Limits> | null; deny_apps?: Array<DenyEntry | string>; mode?: PermissionMode | string | null; message?: string | null; ask_send_delete?: boolean };
+export type HostSettings = { enabled: boolean; real_screen?: boolean; limits?: Partial<Limits> | null; deny_apps?: Array<DenyEntry | string>; mode?: PermissionMode | string | null; message?: string | null; ask_send_delete?: boolean; grant_epoch?: number | null; chat_bound_read?: boolean };
export type HostContext = { ancestors?: ProcessInfo[]; self_pids?: number[]; tty_pids?: number[]; chat?: string | null };
export type AppRef = { app_id: string; app_name: string; bundle_or_exe: string; pid: number };
export type OpenRequest = { session_id: string; request_id: string; app: AppRef; windows: Array<{ id: string; title: string }>; window_id: string; mode: "observe" | "control"; purpose: string; os: string; seconds: number; /** "Allow for this chat": 0 = until the chat ends, else at most this many seconds. */ chat_seconds: number; /** The chat the request belongs to (null: none named, e.g. the copied CLI connection). */ chat: string | null };
@@ -77,7 +77,7 @@ export type PortableHost = {
os: string;
/** internal false: a connection from outside the app's own engine (no chat, never keeps or reuses a grant). */
connect(options?: { internal?: boolean }): McpConnection;
- /** discoveryPath: the app's own engine relay; externalDiscoveryPath: the copied CLI connection (external). */
+ /** discoveryPath (engine-connection.json): the app's own engine relay; externalDiscoveryPath (cli-connection.json): the copied CLI connection (external). */
listen(dir: string): Promise<{ discoveryPath: string; externalDiscoveryPath: string; close(): Promise<void> }>;
control(input: { session_id: string; action: "stop" | "takeover" | "continue" | "hide" | "show" }): Promise<void>;
stopAll(by?: SessionEvent["by"], event?: SessionEvent["event"]): Promise<void>;
diff --git a/apps/server/src/computer-use/shared/portable-host.mjs b/apps/server/src/computer-use/shared/portable-host.mjs
index 55f743b7..c636040a 100644
--- a/apps/server/src/computer-use/shared/portable-host.mjs
+++ b/apps/server/src/computer-use/shared/portable-host.mjs
@@ -500,9 +500,13 @@ export async function createPortableHost({ native: firstNative, nativeFactory =
lease = s.id; sessions.set(s.id, s);
update();
const grantKey = `${s.chat ?? ""}\0${preferred.appId}\0${s.mode}`;
- const grant = s.chat && policyRead ? grants.get(grantKey) : null;
+ // A grant is kept and reused only with a fresh read that carries the server's grant epoch and its own
+ // chat bound, under the same epoch it was given in (off -> on, or a new bound, bumps the epoch).
+ const epoch = Number.isSafeInteger(config.grant_epoch) ? config.grant_epoch : null;
+ const grantable = Boolean(s.chat) && policyRead && epoch !== null && config.chat_bound_read === true;
+ const grant = grantable ? grants.get(grantKey) : null;
// The server's bound now (it may have been lowered since): 0 = until the chat ends.
- const fresh = grant && (l.chat_approval_seconds === 0 || Date.now() - grant.at < l.chat_approval_seconds * 1000);
+ const fresh = grant && grant.epoch === epoch && (l.chat_approval_seconds === 0 || Date.now() - grant.at < l.chat_approval_seconds * 1000);
let answer;
if (fresh) answer = { decision: "chat", window_id: String(preferred.id), reused: true };
else {
@@ -517,6 +521,8 @@ export async function createPortableHost({ native: firstNative, nativeFactory =
}
if (!sessions.has(s.id)) return mcpResult(failure("approval_denied", "The request ended without access."));
if (!answer || !["chat", "once"].includes(answer.decision)) {
+ // A Deny (or no answer) withdraws any earlier "Allow for this chat" for this app in this chat.
+ for (const key of [...grants.keys()]) if (key.startsWith(`${s.chat ?? ""}\0${preferred.appId}\0`)) grants.delete(key);
sessions.delete(s.id); if (lease === s.id) lease = null;
s.approval = null;
emit(s, "denied", answer?.timeout ? "limit" : "person");
@@ -540,7 +546,7 @@ export async function createPortableHost({ native: firstNative, nativeFactory =
// server's chat_approval_seconds (checked again at each reuse). Kept in memory only, keyed to the chat: never
// another chat, never a restart; the person's Stop and the server's switch clear it. A call no chat can be
// named for gets no grant (it works as "Allow once").
- if (answer.decision === "chat" && !answer.reused && s.chat) grants.set(grantKey, { at: Date.now() });
+ if (answer.decision === "chat" && !answer.reused && grantable) grants.set(grantKey, { at: Date.now(), epoch });
s.phase = "working"; s.lastOperation = Date.now();
s.expiresAt = Date.now() + l.session_seconds * 1000;
s.approved = { window_id: String(s.window.id), app_id: s.window.appId };
@@ -610,12 +616,13 @@ export async function createPortableHost({ native: firstNative, nativeFactory =
};
}
- /** Desktop transport: a loopback socket with a token, found through `<dir>/connection.json` (the bundled relay reads it). */
+ /** Desktop transport: a loopback socket with a token, found through `<dir>/engine-connection.json` (the bundled relay reads it; the copied CLI connection reads `<dir>/cli-connection.json`). */
async function listen(dir) {
await mkdir(dir, { recursive: true, mode: 0o700 });
- // Two tokens: the app's own engine relay reads connection.json; the copied CLI connection reads
- // cli-connection.json, and its connections are external (no chat, no grants).
- const discoveryPath = path.join(dir, "connection.json");
+ // Two tokens: the app's own engine relay reads engine-connection.json; the copied CLI connection reads
+ // cli-connection.json, and its connections are external (no chat, no grants). (A CLI connection copied
+ // before these names pointed at connection.json, which is no longer written: it fails to connect.)
+ const discoveryPath = path.join(dir, "engine-connection.json");
const externalDiscoveryPath = path.join(dir, "cli-connection.json");
const token = randomBytes(32).toString("hex");
const externalToken = randomBytes(32).toString("hex");
diff --git a/apps/server/src/engine-pool.ts b/apps/server/src/engine-pool.ts
index 08669422..e03db791 100644
--- a/apps/server/src/engine-pool.ts
+++ b/apps/server/src/engine-pool.ts
@@ -731,6 +731,52 @@ export class EnginePool {
return { sessions: [...sessions], unknown };
}
+ /** Each session's parent (null: a top-level chat), as the engine reported it; it never changes. */
+ private readonly sessionParents = new Map<string, string | null>();
+
+ /**
+ * The running top-level chats (sub-agent sessions left out), for computer use's "Allow for this chat".
+ * `unknown` counts engines or sessions that could not be read; callers then name no chat.
+ */
+ async activeChats(directories: string[]): Promise<{ sessions: string[]; unknown: number }> {
+ const chats = new Set<string>();
+ let unknown = 0;
+ const targets = this.generations.filter(isRoutableGeneration);
+ await Promise.all(targets.flatMap((generation) => directories.map(async (directory) => {
+ if (!generation.handle.isAlive()) return;
+ const headers = { Authorization: buildEngineAuthProbeHeader(generation.handle.username, generation.handle.password) };
+ try {
+ const url = new URL("/session/status", generation.handle.url);
+ url.searchParams.set("directory", directory);
+ const response = await loopbackFetch(url.toString(), { headers, signal: AbortSignal.timeout(5_000) });
+ if (!response.ok) throw new Error(`status ${response.status}`);
+ const payload: unknown = await response.json();
+ if (!isRecord(payload)) throw new Error("unreadable status");
+ for (const [sessionId, status] of Object.entries(payload)) {
+ if (!isRecord(status) || status.type === "idle") continue;
+ if (!this.sessionParents.has(sessionId)) {
+ const info = new URL(`/session/${encodeURIComponent(sessionId)}`, generation.handle.url);
+ info.searchParams.set("directory", directory);
+ const answer = await loopbackFetch(info.toString(), { headers, signal: AbortSignal.timeout(5_000) });
+ if (!answer.ok) throw new Error(`session ${answer.status}`);
+ const session: unknown = await answer.json();
+ if (!isRecord(session)) throw new Error("unreadable session");
+ this.sessionParents.set(sessionId, typeof session.parentID === "string" && session.parentID ? session.parentID : null);
+ if (this.sessionParents.size > 4096) this.sessionParents.delete(this.sessionParents.keys().next().value!);
+ }
+ if (this.sessionParents.get(sessionId) === null) chats.add(sessionId);
+ }
+ } catch {
+ unknown += 1;
+ }
+ })));
+ // Prompts on their way (the engine may not report them busy yet): chats the person prompted.
+ for (const owned of this.activeSessionsByGeneration.values()) {
+ for (const sessionId of owned) if (!this.sessionParents.get(sessionId)) chats.add(sessionId);
+ }
+ return { sessions: [...chats], unknown };
+ }
+
/** Whether `baseUrl` is the engine new work goes to (not a draining one). */
isPrimaryUrl(baseUrl: string): boolean {
return this.isPrimaryEndpoint(baseUrl);
diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts
index 79ea032a..e01ebd9b 100644
--- a/apps/server/src/server.ts
+++ b/apps/server/src/server.ts
@@ -4977,9 +4977,13 @@ function createRoutes(
},
applyEngine: () => applyComputerUseEngine(config),
chats: computerUseChats(config),
- // The engine's running sessions (null when any engine could not be read: no chat is named then).
+ // The engine's running top-level chats, marked or not (null when any engine or session could not be
+ // read: no chat is named then).
runningSessions: async () => {
- const busy = await collectBusyEngineSessions(config);
+ const pool = enginePoolForConfig(config);
+ if (!pool) return null;
+ const directories = new Set(engineInstanceReaperForConfig(config)?.snapshot().map((instance) => instance.directory) ?? []);
+ const busy = await pool.activeChats([...directories]);
return busy.unknown > 0 ? null : busy.sessions;
},
recordTrace: (sessionId, type, data) => recordOpenSessionTrace(config, sessionId, type, data),