# Goals in chat

A Goal keeps an objective active across ordinary turns of the current agent, with the conversation's tools, model, permissions and history. There is no nested working agent.

1. **Working turn** repeats while active
2. **Verifying** separate read-only turn on a candidate missing evidence goes back to work
3. **Achieved** rechecked; one card in the transcript

## Start and plan

Enter `/goal <objective>`, use **Abilities → Programs → Tools → planning → goal → Use**, or ask the agent. The objective shows as your message, labelled Goal. In the Rich REPL `/goal` starts a canonical chat execution and prints its ID.

| Part | Rule |
| --- | --- |
| Plan | `task_start` opens a task with its steps and `task_step` moves it on, for multi-step work; a simple objective needs none. A task belongs to the Goal and revision it was started under and continues over turns, shown as a [task block](https://fzkuji.github.io/OpenProgram/docs/interfaces/web.html#task-list) in each reply. Progress refreshes after each change and when a turn ends; a failed progress notice does not undo steps. |
| Candidate | The agent checks evidence against every requirement, then `update_goal(status="complete")`. This only submits. Unfinished steps prevent it; a dropped step does not. A task with every step done also triggers verification, once per changed plan. |
| Verifying | Assesses the original objective and each step that was not dropped, with trusted built-in inspection tools under normal permissions. No shell, writes or Goal mutation; needed tests go back to the working agent as missing evidence. |
| Achieved | Needs a per-requirement assessment with evidence references. The runtime rechecks requirements, user controls, steps, unfinished executions, unknown effects and evidence. Pause, edit, cancellation, new instructions or changed evidence prevent stale success. A failed execution stays recoverable. |

Semantic verification is an independent model judgment, not a guarantee. Completion describes the time of verification and starts no monitoring. Finishing every step does not prove the objective.

A Goal belongs to the branch it was set on: its automatic turns continue that branch, and a turn on another branch leaves it alone.

## Commands

| Command | Effect |
| --- | --- |
| `/goal` or `/goal status` | Reads the current state |
| `/goal pause` | Saves a pause and requests cancellation of the current execution |
| `/goal resume` | Continues with cumulative usage |
| `/goal verify` | Independently verifies the latest finished work, without marking it achieved |
| `/goal edit <objective>` | Saves a new revision and pauses |
| `/goal clear` | Cancels the Goal |
| `/goal budget max_tokens=10000 max_elapsed_s=3600 max_cost_usd=2` | Token, active-seconds and cost limits; zero removes one |

| Tool | Use |
| --- | --- |
| `create_goal`, `get_goal`, `update_goal` | Short state operations; they do not do the task |
| `blocked` status | Only after the same verified blocker recurs for at least three consecutive Goal turns with no independent work left. The runtime enforces the count; the agent verifies it is the same blocker. |

| Stops or pauses | How |
| --- | --- |
| Budget depleted | Raise or remove with `/goal budget`, then resume. Waiting time is not active time. |
| Failed execution | After a passing failure (a provider error, a lost connection, a short rate limit) the Goal waits a few seconds, then longer, and continues by itself, at most three failures in a row. A failure that would repeat at once (a rejected key, no credit, a spent quota or budget) keeps the pause and its reason until you continue. |
| Cancelled execution | Automatic continuation stops; a turn you stopped is never restarted. An [always-on](https://fzkuji.github.io/OpenProgram/docs/capabilities/always-on-agents.html) wake may restart a Goal the Agent itself started after a failed turn. |
| Two idle automatic turns in a row (no tool call) | **Stalled**. The first is warned. Any tool call or user turn resets; Resume starts over. |
| Paused | Shows why: failed turn, Plan mode, unmet verification prerequisite, restart limit |

Goals have no round limit. The badge names the step in progress and its place, such as **Restyle · 3/5**; otherwise status and steps done. A click goes to the open task block, then to the Goal's details. Limits are optional and use cumulative usage. Automatic continuation does not expand tool permissions.

**In the transcript and details**

- Verification turns are not rendered as replies. Starting, running, pausing and verifying add no transcript cards. An ended Goal leaves one compact card; clicking opens its saved result, progress and usage, read-only and still tied to that Goal after a new one starts.
- Details keep objective, status, usage and progress across reloads, and show each limit next to its usage. They do not edit the budget.
- Add instructions in the normal input, with its queue or steering mode. A queued message goes before the next automatic turn, which waits up to 15 seconds for it.
- Details use the backend's current action eligibility. Disabled Resume or Verify explains the prerequisite. A failed status read is retried quietly; your draft stays. End always stops the Goal intent. Unresolved operations show identifiers, tool names, timestamps and status. Inspect execution opens that exact execution, with pending approvals and questions.

**Restart and recovery**

| Case | Behaviour |
| --- | --- |
| Worker restart | Does not pause a chat Goal: compatible checkpoints resume under the automatic restart policy, and a turn completed during shutdown keeps a durable continuation notification |
| Automatic work prevented by | User pause, cancellation, exhausted budgets, explicit restart limits. Legacy recoverable pauses and Goals with no saved continuation provenance need explicit Resume. External-event wakeups remain a recovery limitation. A wait or unresolved execution is not evidence of completion. |
| Verify needs | Finished work, no unfinished step, available budget and no unresolved relevant work. Goal-owned background processes running or of unknown outcome prevent it; unrelated resources do not. Pause, cancellation, changed versions and duplicate requests cannot bypass this. |
| Resume of an ordinary chat with no owner or active descendants | Can close its interrupted frame and start a restricted inspection turn, without replaying old tool calls. Unknown effects stay unknown; nothing claims an external operation was cancelled. |
| New admission | Has a durable identity, so a crash before saving the Goal cannot duplicate turns. Incompatible checkpoints use a new chat turn; temporary activation or credential errors do not authorize that. Provider-only interrupted background Jobs keep their input and resource admission. Child executions with unresolved effects need inspection. |
| Incomplete tool-call history in provider requests | Repaired without rewriting saved records: missing outputs get an unknown-outcome placeholder, real outputs win, duplicates collapse, interrupted text stays labelled, unpaired results are omitted from the request but stay saved. This does not prove failure or authorize a retry. |
| Ownerless interrupted execution, unknown outcome | The next non-inspection tool result is prefixed with a notice, once per execution. Nothing is held back or replayed. Real built-in `read`, `grep`, `glob` and `list` get no notice; custom tools with those names do. Restarted chat turns included. |

**Metering**

| Part | Rule |
| --- | --- |
| Active time | Keeps observed work across restart and excludes offline time. After abrupt worker loss the last durable heartbeat is a lower bound and the final interval is shown as unknown. Late receipts do not restart a paused timer. An explicit active-time ceiling blocks work if that unknown prevents checking; removing it allows continuation. No default time or round ceiling exists. |
| Chat requests | Capture Goal identity, revision and price before dispatch. Receipts update that Goal even after pause or edit; replacing the Goal moves no charges. Duplicates do not add. A started request without a receipt is unknown, not free; details show known subtotals beside unknown request counts. Receipts rebuild from the ledger after restart without repeating the request. |
| Older totals and failures | Cursor-based totals stay as a legacy subtotal on the next attributed request. Metering failures show unknown. Partial streaming counters are cumulative lower bounds; a final receipt replaces them. |
| Background Jobs | Those admitted by an active Goal inherit its identity, including descendants and cross-session calls; an unrelated Goal in the destination gets no charges. Jobs without saved attribution stay unassigned. Goal and Job reservations start and settle in one accounting transaction. Missing token or price information keeps the reserved exposure. |
| Token or cost limits | Reserve conservative exposure before credentials or provider calls, count parallel requests, and recheck at dispatch. Token limits can reduce the output cap. An unsupported bound, unknown price or unpriced tier cannot bypass a hard limit: the Goal pauses or reports exhaustion. An expired reservation that never started cannot dispatch; a started request never becomes free by time. These bounds need audited provider adapters. |

[Engineering design](https://fzkuji.github.io/OpenProgram/docs/reference/design/runtime/reliability/goal-and-recovery.html)
