Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
Remove the group-chat watchdog wake-commander mechanism
wyt3f1e11badd9c
diff --git a/src/main/features/group_chat/bus.ts b/src/main/features/group_chat/bus.tsindex 2c1c2c4b..2de7a618 100644--- a/src/main/features/group_chat/bus.ts+++ b/src/main/features/group_chat/bus.ts@@ -1781,41 +1781,6 @@ export function dropConv(uid: string, cid: string): void {_cids.delete(k);}-/**- * Watchdog hook — synthesise a system message into commander's worker- * queue so it gets a turn to self-diagnose when a long-running plan has- * gone silent. Bypasses `enqueue` (no main jsonl write, no visibility- * slice, no UI message event) on purpose: the ping is a backend- * mechanism, not group content. Commander's reply (if any) goes through- * the normal `enqueue` path inside its `runTurn` post-turn → user sees- * commander's actual response, never the ping itself.- *- * Idempotent / cheap: if the commander worker has anything queued, we- * skip — no point doubling up. If state already aborted, also skip.- */-export async function pingCommanderForWatchdog(uid: string, cid: string, reason: string): Promise<boolean> {- const state = getOrInitCid(uid, cid);- await seedReservedActors(uid, cid);- const cur = await readState(uid, cid);- if (cur.status === 'aborted') return false;- // Find or seed commander actor in the roster.- const members = await readMembers(uid, cid);- const commander = members.actors.find((a) => a.id === COMMANDER_ID);- if (!commander) return false;- const w = ensureWorker(state, commander);- if (w.queue.length > 0 || w.running) return false; // already busy / pending- const llmPayload = `<msg from="system" to="commander">\n[watchdog] ${reason}\n</msg>`;- w.queue.push({- msgId: genId12(),- fromActorId: 'system',- llmPayload,- });- const wake = w.wake; w.wake = null;- wake?.();- log.info(`watchdog ping user=${uid} cid=${cid} reason=${reason}`);- return true;-}-export function _cidStateForTest(uid: string, cid: string): CidState | null {return _cids.get(cidKey(uid, cid)) || null;}diff --git a/src/main/features/group_chat/index.ts b/src/main/features/group_chat/index.tsindex 10a1ffc3..cfc2c52a 100644--- a/src/main/features/group_chat/index.ts+++ b/src/main/features/group_chat/index.ts@@ -39,7 +39,6 @@ export const busIsQuiescent = isQuiescent;* if subscribe runs after send, those first events are lost. */export const subscribeBus = subscribe;-export { startWatchdog, stopWatchdog } from './watchdog';import type { GroupMessage } from './visibility';import {type ChatFormPayload, encodeSubmission, buildMention,diff --git a/src/main/features/group_chat/watchdog.ts b/src/main/features/group_chat/watchdog.tsdeleted file mode 100644index 6e8e96d1..00000000--- a/src/main/features/group_chat/watchdog.ts+++ /dev/null@@ -1,148 +0,0 @@-/**- * Group-chat watchdog — periodically scans every conversation and pings- * commander for self-diagnosis when a long task has gone silent.- *- * Triggers a ping when ALL of:- * - plan.md has at least one unfinished step (pending or in_progress —- * i.e. the plan as a whole is not yet finished). This covers both- * "task in flight" and "agent waiting on the user" stalls; we don't- * gate on `state.status` because a conv that's quietly waiting for- * a human reply is `idle`, and that's exactly the case we want to- * bring back to commander's attention.- * - `state.last_active_at` is older than `STALE_THRESHOLD_MS` (default- * 30 minutes — tunable)- * - `state.status !== 'aborted'` (a stopped conversation stays stopped)- *- * Implementation notes:- * - **One global interval** for the whole process (not per-cid). Each- * tick walks the on-disk index of every uid; cheap because state.json- * reads are tiny + we early-bail on idle convs.- * - The ping is fire-and-forget into commander's queue (see- * `bus.pingCommanderForWatchdog`); commander wakes up, re-reads plan,- * decides what to do, replies. If it judges "false positive" it can- * stay silent — the ping itself never appears in the group jsonl.- * - Threshold + interval are constants here for now; if user feedback- * wants UI control later it's a one-line lift to read from- * preferences.json.- */--import * as fs from 'node:fs';-import * as fsp from 'node:fs/promises';-import * as path from 'node:path';--import { WS_ROOT, userChatsDir } from '../../paths';-import { readState } from './state';-import { readPlan } from './plan';-import { pingCommanderForWatchdog } from './bus';-import { createLogger } from '../../logger';--const log = createLogger('group_chat.watchdog');--/** How often the watchdog scans every conv. Cheap (state.json reads) so- * 60s gives prompt response without flooding the disk. */-const WATCHDOG_INTERVAL_MS = 60_000;--/** Conversation must have been silent at least this long while the plan- * is still unfinished (any step pending / in_progress) for the ping to- * fire. 30 minutes is the user-facing default; shorter values risk- * pinging during a user's legit thinking pause, longer values delay- * recovery on real stalls. */-const STALE_THRESHOLD_MS = 30 * 60 * 1000;--/** Cooldown between consecutive watchdog pings for the same cid so a- * conversation that's genuinely user-paused doesn't get pinged on every- * tick. Reset by any new bus enqueue (which bumps last_active_at). */-const PING_COOLDOWN_MS = 5 * 60 * 1000;--let _interval: NodeJS.Timeout | null = null;-const _lastPingedAt = new Map<string, number>(); // `${uid}:${cid}` → ms--interface IndexEntry {- conversation_id: string;-}--async function _readConvIndex(uid: string): Promise<string[]> {- const file = path.join(userChatsDir(uid), '_index.json');- if (!fs.existsSync(file)) return [];- try {- const raw = await fsp.readFile(file, 'utf-8');- const data = JSON.parse(raw);- const items: IndexEntry[] = Array.isArray(data) ? data- : (data && Array.isArray(data.items) ? data.items : []);- return items.map((c) => c.conversation_id).filter((s): s is string => typeof s === 'string');- } catch (err) {- log.warn(`read index failed user=${uid}: ${(err as Error).message}`);- return [];- }-}--async function _scanUid(uid: string): Promise<void> {- const cids = await _readConvIndex(uid);- if (!cids.length) return;- const now = Date.now();- for (const cid of cids) {- let s;- try { s = await readState(uid, cid); }- catch { continue; }- if (s.status === 'aborted') continue;- const lastActive = Date.parse(s.last_active_at);- if (!Number.isFinite(lastActive)) continue;- if (now - lastActive < STALE_THRESHOLD_MS) continue;-- const plan = await readPlan(uid, cid);- if (!plan) continue;- const unfinished = plan.steps.find(- (step) => step.status === 'pending' || step.status === 'in_progress',- );- if (!unfinished) continue;-- const key = `${uid}:${cid}`;- const prev = _lastPingedAt.get(key) || 0;- if (now - prev < PING_COOLDOWN_MS) continue;-- const idleMin = Math.round((now - lastActive) / 60_000);- const stepLabel = unfinished.status === 'in_progress' ? 'in_progress step' : 'pending step';- const reason = `The conversation has been idle for ${idleMin} minutes while the plan is still unfinished. Current ${stepLabel}: Step ${unfinished.index} "${unfinished.title}"${unfinished.assignee ? ` (assigned to ${unfinished.assignee})` : ''}. Please review the state and decide whether to keep going, nudge the user / assignee, or mark it failed.`;- try {- const fired = await pingCommanderForWatchdog(uid, cid, reason);- if (fired) _lastPingedAt.set(key, now);- } catch (err) {- log.warn(`ping failed user=${uid} cid=${cid}: ${(err as Error).message}`);- }- }-}--async function _tick(): Promise<void> {- if (!fs.existsSync(WS_ROOT)) return;- let entries;- try { entries = await fsp.readdir(WS_ROOT, { withFileTypes: true }); }- catch (err) { log.warn(`scan WS_ROOT failed: ${(err as Error).message}`); return; }- for (const entry of entries) {- if (!entry.isDirectory()) continue;- const uid = entry.name;- // Reject the well-known top-level non-uid dirs early; uid is generated- // by `genUserId()` (8 digits) so we filter to digit-only strings.- if (!/^\d{4,16}$/.test(uid)) continue;- try { await _scanUid(uid); }- catch (err) { log.warn(`scan failed user=${uid}: ${(err as Error).message}`); }- }-}--export function startWatchdog(): void {- if (_interval) return; // already running- _interval = setInterval(() => {- _tick().catch((err) => log.warn(`tick threw: ${(err as Error).message}`));- }, WATCHDOG_INTERVAL_MS);- // Don't keep the event loop alive on this timer alone — Electron main- // has other reasons to stay up; the watchdog just rides along.- if (typeof _interval.unref === 'function') _interval.unref();- log.info(`watchdog started interval=${WATCHDOG_INTERVAL_MS}ms threshold=${STALE_THRESHOLD_MS}ms`);-}--export function stopWatchdog(): void {- if (_interval) {- clearInterval(_interval);- _interval = null;- }- _lastPingedAt.clear();-}diff --git a/src/main/index.ts b/src/main/index.tsindex f16ccf4d..aa3d86fb 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -280,15 +280,6 @@ async function runBootSelfCheck(): Promise<void> {try { await chatsFeature.sweepStaleProcessing(); }catch (err) { log.warn('chats sweep failed', { error: (err as Error).message }); }- // Stage 3.5: start the group-chat watchdog. Self-paced 60s scan; pings- // commander when a `running` conv with an `in_progress` plan step has- // been silent past STALE_THRESHOLD_MS (10min default). See- // features/group_chat/watchdog.ts.- try {- const groupChat = await import('./features/group_chat');- groupChat.startWatchdog();- } catch (err) { log.warn('watchdog start failed', { error: (err as Error).message }); }-// Stage 4: file_cache orphan sweep — cheap stat-based scan.try {const uid = users.getActiveUserId();diff --git a/src/main/prompts/chat_commander.md b/src/main/prompts/chat_commander.mdindex a92e7d1d..f4171a74 100644--- a/src/main/prompts/chat_commander.md+++ b/src/main/prompts/chat_commander.md@@ -33,7 +33,6 @@ In the final text, **whenever you write an agent's name, prefix it with `@`** (e| User sends a message (no `@` or `@commander`) | Process via the "Decision tree" below || You are the commander step in a plan and dispatched to | Execute per `step.input` || `<plan-complete>` system message | Write the wrap-up report (final must be present, cannot be empty) |-| `<msg from="system">[watchdog] ...</msg>` | Long-silence self-check (see "Plan exception handling" below) |You are NOT woken up in scenarios outside the table (e.g. agent X replies to the user — the bus does not notify you, and you don't need to care).@@ -208,11 +207,6 @@ plan_set({- You notice a step going off-track mid-flight → `plan_update` mark failed + rewrite.- During normal progression, **do NOT** call `plan_update`.-**watchdog**: if no one has spoken in the group for over 10 minutes AND the plan has an `in_progress` step → the system sends `<msg from="system">[watchdog] ...</msg>` to wake you:-- Genuinely stuck → `plan_update(step_index, 'failed', notes=...)` + `plan_set` a new path.-- Agent is still busy → empty reply (the system auto-discards it).-- User stopped on their own → a friendly confirming line.-**Forbidden**:- Writing a plan AND then `dispatch_to`-ing yourself — the bus auto-dispatches; the duplicate hits the agent twice.- Stuffing "please proceed step-by-step in detail..." into `step input` — the agent's own prompt already has those instructions.