Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

13.4 KB
Raw Blame

Goal mode v2 — durable goals, busy-safe room runs, /goal, routine triggers

Status: plan + implementation in progress (Sep 2, 2026). Supersedes nothing; extends the bounded goal-driven team runs that shipped in #617/#661 and composes with the delegation wake work in #690.

Why

Three pieces of community feedback, all real against current main:

  1. "If an agent asked to contribute toward a goal in a room is busy, the goal fails immediately." True. runGroupMemberTurn has two busy gates that append a "skipped this round" chip and return without setting orchestration.result.outcome; runGroupGoalOperation then reads outcome !== "settled" and cannot tell busy from provider crashed, so it ends the run as failed. It is the only orchestration path in the codebase that treats busy as fatal — delegations retry 3× with wake-on-settle, ask_bot degrades to a delegation, routines wait a tick, busy-channel sends queue (#661). A bot parked on a permission card elsewhere (waiting-on-you) kills a goal run just the same.
  2. "/goal mode would bring behaviour closer to Grok Bot." Goal mode today is a one-shot composer toggle, rooms only (1:1 is rejected with 400), and one send is one 13-turn run that ends in limit-reached with "send the goal again". A goal is not a durable object: it lives in the in-memory GroupTurnOperation and a restart loses it silently; there is no live progress (the working card status exists but is never emitted).
  3. "Trigger a goal through a routine." Routines target one bot's detached task; nothing carries a room or a mode, and run completion keys on the first turn.completed.

What we borrow (and from where)

  • Park-and-resume on busy, never fail — our own delegations.ts (waitingOnBusy, bounded attempts, retryDelegationsWaitingOn on every idle release) and steer-queue.ts (key the wake on "this bot is idle", because a bot busy in a room settles on a different thread). Hermes heartbeat.py/goals.py state the invariant crisply: fire once when the session next goes idle, never stack a backlog.
  • The Ralph loop for a single bot — Hermes hermes_cli/goals.py (their /goal, itself adapted from Codex CLI's): a standing objective, a per-turn verdict done | continue | wait, a plain continuation message (no system-prompt mutation), a turn budget with auto-pause, a user message preempts and pauses, fail-open on judge trouble, consecutive-failure auto-pause, and a wait verdict that parks without burning a turn. Hermes cannot run this loop for us over hermes acp (no goal command in the adapter), so the loop is host-side and engine-agnostic.
  • Structured completion + stop conditions — Hermes' completion contract (outcome, verification, constraints, boundaries, stop_when), quality gates, and "repeated identical assignment ⇒ blocked" (we already have the last one for rooms).
  • Board semantics for multi-agent work — Hermes kanban: lifecycle truth lives in one durable record; workers execute but never own status; every handoff is a row a human can read; a claim that never heartbeats is reclaimed, a dead worker is reaped, a stranded task is diagnosed — not silently dropped.

Design

1. A durable Goal record (server/goals.ts, ~/.openmausbot/goals.json)

interface GoalRecord {
  id: string;
  kind: "room" | "bot";
  groupId?: string; botId?: string; threadId: string;
  goal: string;
  status: "working" | "waiting" | "paused" | "completed" | "needs-input" | "blocked"
        | "limit-reached" | "stopped" | "failed";
  turnCount: number; maxTurns: number;
  coordinatorBotId?: string;              // rooms
  waiting?: { onBotId: string; since: number; attempts: number; instruction?: string };
  detail?: string;                        // last visible progress line / terminal reason
  receiptMessageId: string;               // the live `goal.run` card, patched in place
  source?: { routineId: string; runId: string };
  createdAt: number; updatedAt: number; finishedAt?: number;
}

Written with atomic.ts (0o600) like delegations.json. The goal.run transcript card is emitted at start with status: "working" and patched every round (turn count, coordinator's visible detail, "waiting for X") instead of only appended at the end. On boot, any goal still working/waiting becomes paused with detail "OpenMausBot restarted — resume to continue": the goal text survives, nothing runs unattended after a restart.

2. Rooms: busy is a wait, not a failure

  • GroupMemberTurnOutcome gains "busy"; both gates in runGroupMemberTurn set it and the goal step does not count the turn.
  • Worker busy → chip "waiting for X to finish what they're doing", goal status: "waiting", waiting.onBotId = X, the coordinator's pending assignment is kept on the record, and the room operation is released (room becomes usable, finishGroupTurnOperation no longer auto-fails a waiting goal).
  • Wake: the turn.completed subscriber and every explicit idle release already call retryDelegationsWaitingOn(botId); the same hook now also resumes goals waiting on that bot. The resume re-enters through groupQueues (never runs free) with a fresh operation carrying the same goal, continuing at the worker step.
  • Bounds: attempts ≤ 3 distinct busy periods, and a wall-clock cap; on exhaustion the coordinator is given "X could not free up — reassign or report blocked" as its next instruction instead of the run failing. Coordinator busy parks the same way (it is the one bot the run cannot route around).
  • provider_failed / stalled / timed_out get one retry per step before failed.

3. /goal as a first-class command (rooms and 1:1)

Composer: /goal <text> = goal-mode send (room: today's coordinator run; 1:1: a bot goal). /goal status | pause | resume | stop map to /api/goals/:id. The composer toggle stays as the discoverable form; the command is the scriptable one.

1:1 bot goal loop (host-side Ralph loop, server/bot-goal-run.ts): the first turn runs the goal text as a normal message. Each turn's instructions ask the bot to end with the same private <openmaus-goal>{status}</openmaus-goal> envelope rooms use (continue | completed | needs-input | blocked), stripped from the transcript by the existing fold. On turn.completed: parse → continue ⇒ startTurn(botId, continuationPrompt, { threadId, cardContinuation: true }); terminal ⇒ finish. No auxiliary judge model: self-report + budget + stuck detection is engine-agnostic (Claude, Codex, ACP alike). Safeguards mirror Hermes: missing envelope = continue with a nudge, 3 consecutive missing ⇒ paused; identical reply digest twice ⇒ nudge, three times ⇒ blocked; maxTurns 20 ⇒ limit-reached (resume resets the counter). A user message mid-goal preempts: the goal pauses for that turn and re-evaluates after it (steer-queue already delivers the message when the bot is idle). Continuations only fire into an idle bot and never stack.

What "closer to Grok Bot" actually means (verified): Grok Bot has no goal primitive — its long-running feel is persistent bots + background turns that survive closing the app + approvals that stop only the matching action + routines. The /goal people recall is Grok Build's (xAI's coding agent, open-sourced Apache-2.0 as xai-org/grok-build, crates/xai-grok-shell/src/session/goal_*). Parity we take now:

  • Paused is a taxonomy, not a failure. status: "paused" carries reason: "user" | "no-progress" | "budget" | "infra" | "blocked"; every reason is resumable and the card says which one. Unknown or corrupt state restores as paused (reason infra), never self-driving.
  • Premature-stop detector. When the envelope says continue but the visible reply ends with a hand-back phrase ("Stopping here", "Ready for review", "Let me know if…", "Please run … for me", "I can't proceed without…"), the next continuation names it and re-nudges instead of ending — a goal turn is not a chat turn. (Grok Build's goal_stop_detector.rs.)
  • Rate-limited progress frames. The goal frame broadcast on record changes is coalesced to at most one per second per goal (Grok Build's GoalUpdated), and the card shows status, turns/budget, the last detail, and the pause reason.

Who may change what (borrowed from OpenClaw's /goal): the model's envelope may report continue | completed | needs-input | blocked; only the operator (UI/API) may pause, resume, or stop. needs-input is accepted at once (it is a question for the human). A first blocked is answered with a nudge ("name the exact blocker and try one alternative"); blocked is accepted only when the next turn reports the same blocker again — a difficulty is not a blocker.

Stuck heuristics (OpenHands thresholds, scoped to turns since the last user message): identical reply digest ×3 ⇒ blocked (nudge at ×2); identical tool call + identical result ×4 ⇒ nudge, then blocked. Being stuck never ends a goal by itself — the record's status decides, and a resume re-checks real state ("inspect the current workspace; do not rely on memory").

A goal is not a scheduler (OpenClaw/Hermes): a goal is one durable objective attached to a conversation. Routines, heartbeats, and webhooks inject turns into the conversation that carries the goal; they never fork or duplicate it. Starting or resuming a goal needs an idle conversation and says "busy — try again when X finishes" rather than creating an inactive goal (OpenClaw) — except in rooms, where the wait is the feature and the goal parks on the busy member.

No-progress guard (borrowed from Claude Code's /goal): a self-reporting model can claim continue forever without doing anything. The harness sees every tool event, so N consecutive continuation turns with zero tool calls (N = 3) pause the goal with detail "no progress — resume with more direction". This is the deterministic backstop; the envelope is the model's opinion. Idle check-ins while a goal waits on long-running work follow the same shape (bounded count, doubling interval) if/when 1:1 goals learn to wait on a background process.

4. Routines can start a goal

Routine.target?: { kind: "bot" } | { kind: "room"; groupId; mode: "chat" | "goal" } (absent = bot, back-compat). RoutineManagerOptions gains startGroupRun(groupId, prompt, mode, trigger) returning { threadId, goalId? }; the tick's busy gate becomes groupIsWorking(group) for room targets (a run that waits — the semantics we want, no new machinery); completion for a goal run keys on the goal record reaching a terminal status (onGoalFinished), not the first turn.completed. Routine editor gets a target picker; propose_routine grows the same field.

5. Later (not this batch)

Independent verification (Grok Build): before a goal may complete, an evaluator that is not the implementer decides — first a per-round hidden evaluator (continue | candidate_complete | blocked{key}), then on candidate_complete a small adversarial verifier panel (default-refute, majority vote, refutes tagged contradiction | unverifiable pause for a human decision). In OMB this is a fresh detached task on the same bot with the verifier prompt; templates to adapt with attribution: session/templates/goal_verifier_prompt.md, session/goal_evaluator.rs, session/templates/goal_continuation_directive.md, session/goal_stop_detector.rs. Frozen plan contract at goal start (Grok Build goal_planner_prompt.md + Hermes contract): kind, 3–5 gating acceptance criteria stated as outcomes, a verification plan, non-goals, a checklist; the next-step nudge is mined from the first unchecked item. Budgets: a token budget with a bar, and a verification-run cap.

Progress ledger for room goals (Magentic-One): extend the coordinator's envelope with progress: "yes" | "no" and looping: true | false; the harness keeps a stall counter per run (+1 on no-progress or loop, −1 on progress) and, at 3 stalls, hands the coordinator a re-plan instruction ("state what is known, what went wrong, and a new plan") instead of another assignment. last_progress_at on the record (AG2) drives a stale-run diagnostic the same way Beads/Gas Town surface stranded work.

Completion contracts + quality gates on the record; start_goal / goal_status MCP tools so the Chief of Staff can open and inspect goals; resume-in-place after a restart; a spend ceiling alongside the turn budget; goal-run receipts in the iOS companion.

Delivery

The base is the Codex-authored commit ac41eb8 feat(routines): run durable goals in rooms (merged onto main as feat/goal-mode-v2-integration). It already delivers the busy-safe room run (an availability listener waits for a busy coordinator/worker without spending a goal turn), the live card completed in place, routine → room-goal targets with outcome-keyed completion, and restart reconciliation of working cards from SQLite — with 20 e2e scenarios. Two earlier sibling branches (feat/goal-mode-v2: a durable GoalRecord store with park/resume/finish and bounded waits; feat/goal-routine-targets: routine targets) are donors, not bases: their non-overlapping pieces (pause/resume API, bounded waits with a reassign fallback, pause-reason taxonomy) are ported on top.

  • A — base + fixes: review findings on the Codex commit, plus the ports above.
  • B — /goal + 1:1 loop (server + composer + card), built on A.
  • Later as listed in §5.