Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

Merge #187: stop stale inbox nudges waking agents against an empty inbox

Chaitanya Giri85529967c5bc
diff --cc src/main/index.ts
index 3ff9004e,45d288e4..e7238f7c
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@@ -58,10 -58,8 +58,11 @@@ import { IntegrationBroker } from './in
import * as integrations from './integrations';
import { validateBaseUrl, buildAuthHeaders, resolveUpstreamUrl, secretRefFor, INTEGRATION_TEMPLATES } from '../shared/integrations';
import { RosterStore } from './roster';
+import { buildWorkerLaunch } from './workerLaunch';
import { ControlRegistry } from './control';
- import { WorkerWakeWatchdog, WORKER_WAKE_NUDGE, type WorkerWakeFacts } from './workerWake';
-import { fetchHireManifest, readHireManifestFile } from './hire';
++import { WorkerWakeWatchdog, type WorkerWakeFacts } from './workerWake';
++import { inboxNudgeText } from '../shared/hiveNudge';
+import { fetchHireManifest, readHireManifestFiles } from './hire';
import { parseHireDeepLink, type HireManifest } from '../shared/hire';
import { ClosingTimeController } from './closingTime';
import {
@@@ -4758,64 -4623,6 +4759,73 @@@ function bootstrapHiveServices(): void
armAlwaysOnBeats();
}
+/** Cadence of the worker inbox-wake watchdog (#151). Well under the renderer's
+ * own nudge cooldown so a throttled window is caught within ~15s of a stall. */
+const WORKER_WAKE_POLL_MS = 15_000;
+let workerWakeTimer: ReturnType<typeof setInterval> | null = null;
+
+/** Type the renderer's guarded nudge into one worker's PTY — text first, Enter a
+ * tick later (the exact submitToPty pattern: a single-chunk write would land the
+ * "\r" inside the input box and never submit). Best-effort + never throws. */
- function nudgeWorker(ptyId: string): void {
- const wrote = ptyManager.write(ptyId, WORKER_WAKE_NUDGE);
++function nudgeWorker(ptyId: string, ids: string[] = []): void {
++ // Same text the renderer queues (#187's inboxNudgeText), so the two wake paths
++ // produce byte-identical nudges: the queue's one-pending rule recognises either
++ // via isInboxNudge, and a watchdog nudge names its ids so the agent can still
++ // tell "I filed this last turn" from "woken for nothing".
++ const wrote = ptyManager.write(ptyId, inboxNudgeText(ids));
+ if (!wrote.ok) { console.warn(`[worker-wake] write failed for ${ptyId}: ${wrote.error}`); return; }
+ setTimeout(() => {
+ try {
+ const submitted = ptyManager.write(ptyId, '\r');
+ if (!submitted.ok) console.warn(`[worker-wake] submit failed for ${ptyId}: ${submitted.error}`);
+ } catch (e) { console.error('[worker-wake] submit threw:', e); }
+ }, 140);
+}
+
+/** Main-process inbox-wake beat (issue #151, fix A): the renderer's idle nudge
+ * (useHive.ts) is the only path that wakes a worker parked on an undrained
+ * inbox — and it lives on a setInterval in the renderer, which a throttled or
+ * occluded window stops honoring. This beat is the renderer-INDEPENDENT fallback:
+ * it gathers live-worker facts (PTY quiescence, inbox depth, control flags) and
+ * lets WorkerWakeWatchdog.decide apply the exact renderer guards (idle-only,
+ * post-boot-grace, not paused/halted, no pending HITL, cooldown), then types the
+ * same nudge the renderer would have. God is never a candidate (its heartbeat
+ * path already re-engages it). */
+function runWorkerWakeBeat(): void {
+ if (!hive.enabled()) return;
+ const reg = hive.registry();
+ if (!reg?.agents || !reg.godId) return;
+ const now = Date.now();
+ const facts: WorkerWakeFacts[] = [];
+ for (const [agentId, a] of Object.entries(reg.agents)) {
+ if (agentId === reg.godId || a?.archived) continue;
+ const ptyId = ptyForAgent(agentId);
+ if (!ptyId) continue;
+ const snap = control.snapshot(agentId);
+ facts.push({
+ agentId,
+ isGod: agentId === reg.godId,
+ ptyId,
+ lastOutputAt: ptyManager.lastOutputAt(ptyId) ?? 0,
+ inboxCount: hive.inbox(agentId).length,
+ autoDeliveryPaused: snap.autoDeliveryPaused,
+ paused: snap.paused,
+ halted: snap.halted
+ });
+ }
+ for (const agentId of workerWake.decide(facts, now)) {
+ const ptyId = ptyForAgent(agentId);
+ if (!ptyId) continue;
- console.log(`[worker-wake] nudging ${agentId} on ${ptyId}`);
- nudgeWorker(ptyId);
++ // Re-read at delivery time, not from the facts snapshot: the agent may have
++ // drained the mail during the beat, and a nudge naming ids it already filed
++ // is the exact staleness #187 exists to stop.
++ const ids = hive.inbox(agentId).map((m) => m.id).filter(Boolean);
++ if (!ids.length) { console.log(`[worker-wake] ${agentId} drained before delivery, skipping`); continue; }
++ console.log(`[worker-wake] nudging ${agentId} on ${ptyId} (${ids.length} pending)`);
++ nudgeWorker(ptyId, ids);
+ }
+}
+
/** (Re)arm the always-on beats (decoupled from the optional heartbeat): the live
* fleet snapshot Michael reads (~8s) + the breaker/cost-ledger beat (~30s).
* Guarded (clear-then-set) so a re-bootstrap (changeHome recovery) OR a
diff --cc src/renderer/src/hooks/useHive.ts
index cbf660d2,1633588f..24ab71fd
--- a/src/renderer/src/hooks/useHive.ts
+++ b/src/renderer/src/hooks/useHive.ts
@@@ -16,10 -16,9 +16,11 @@@ import
} from '../../../shared/providerAutomation';
import { DEFAULT_CONTEXT_TRIGGER, type ContextRule } from '../../../shared/triggers';
import type { AgentProvider } from '../../../shared/agentProvider';
+import { bridgeOf, providerPreset } from '../../../shared/agentProvider';
+import { isDurableRole, preferredAgentRole, roleForHiveSpawn } from '../../../shared/agentRole';
+ import { inboxNudgeText } from '../../../shared/hiveNudge';
import { acquireTerminal, resetTerminal, isTerminalAutomationSafe } from '@/components/terminalPool';
-import { deliverWithAcknowledgement } from './queueDelivery';
+import { canDeliverToAgent, deliverWithAcknowledgement } from './queueDelivery';
import { OFFICE_CAST, DEFAULT_CHARACTER } from '@/scene/office/cast';
const GOD_ID = 'god';
diff --cc src/renderer/src/store/store.ts
index 4a4c8781,f051e623..6138ee0b
--- a/src/renderer/src/store/store.ts
+++ b/src/renderer/src/store/store.ts
@@@ -5,16 -5,9 +5,17 @@@ import type { ThemeId } from '@/scene/o
import type { StatusKind } from '@/components/PixelBadge';
import type { AgentProvider } from '@shared/agentProvider';
import type { HireManifest } from '@shared/hire';
+import {
+ EMPTY_HIRE_QUEUE,
+ clearHireQueue,
+ enqueueHires,
+ finishCurrentHire,
+ type HireReviewQueue
+} from '@shared/hireQueue';
import { DEFAULT_ORG_TRIGGER, type OrgTriggerConfig, type WebhookTrigger } from '@shared/triggers';
import { isCompactionCommand } from '@shared/providerAutomation';
+import { preferredAgentRole } from '@shared/agentRole';
+ import { isInboxNudge } from '@shared/hiveNudge';
export type ToolKind =
| 'Read' | 'Edit' | 'Write' | 'Bash' | 'WebFetch' | 'WebSearch'