Skip to content

Routines

Routines save a prompt with an optional project. Run one by hand, give it a schedule, or trigger it with a webhook. Choose how each routine uses agent sessions:

  • New session starts a fresh session for every run. This is the default.
  • Reuse session starts a session on the first run and continues it later.
  • Existing session continues a session you select from the project.

Routines automatically wake a project stopped by idle-project cleanup before creating or continuing its session. Future scheduled runs do not keep an idle instance running; a claimed or active run prevents cleanup.

A session a routine starts is titled with the routine’s name and launch time (for example Daily check 2026-09-30 15:04) and tagged as a routine session. A webhook run whose body has a top-level number, as forge pull request and issue events do, also names it and its action, for example Review PRs 2026-09-30 15:04 #12 opened. Subagents of a routine session carry the same routine tag. The session sidebar hides routine sessions and their children until you check Show routines under Filter sessions. Opened and pinned sessions stay visible through these filters and search, but must match the selected project. With the default Always show prompts toggle enabled, sessions awaiting permission or an answer bypass all sidebar filters. Existing sessions a routine continues stay yours and are not tagged.

Create and manage routines

Open Routines from the main navigation, then select New routine. Enter a unique name, the prompt, the target project, session behavior, and a schedule. The model selector shares the session composer’s search, ranking, badges, and named-platform tabs. For new sessions, selecting a model also selects its platform and loads that platform’s agents. Existing sessions use their own catalog. Select the default option to let the platform choose. You can also disable a routine without deleting it.

When no platform is supplied, new routines use the target machine’s configured default connection. Before allocating a session, ocman resolves omitted model and agent selections from that connection’s directory catalog and applies them at creation. A live catalog reporting an unavailable selected model fails the run before creating a session. MCP patches preserve the saved connection unless platform is explicitly changed.

If a run reports that its platform is disabled after a platform rename, open Settings → Session and model, select the model under the intended platform, and Save changes. Future runs use that platform. Saving other settings preserves the platform of an existing model selection.

Startup also repairs obsolete legacy platform references for routines that have not bound a reused or existing session. The first enabled platform on the same machine with the same native tool and saved model is selected. Explicit named platform choices and historical runs remain unchanged; a model absent from every eligible catalog still needs manual selection.

Select Choose when running to leave the project unset. Run now then asks for a known project on the routine’s machine. Each run records its own project; the routine stays unbound. These routines require New session and cannot have a schedule. Existing routines with a fixed project keep their current manual, scheduled, reused-session and webhook behavior.

Name, prompt, project, schedule, and enabled status stay visible at the top. Expand Session and model, After a run, or Permissions for optional settings. These groups start collapsed when you create or edit a routine.

Routines default to Current checkout on the selected machine. With New session, choose Worktree to create a separate routine/<run-id> branch and checkout for each run. Worktrees are not offered for reused or existing sessions.

For a worktree, Clean up worktree after a successful run removes its checkout after the session settles. Its branch and session transcript remain available. Failed or interrupted runs keep their workspace. Cleanup never forces removal: uncommitted files, an active child session, or a changed workspace identity keep the worktree. A cleanup problem appears in the run history without changing the successful run result. Each run keeps the cleanup choice it started with.

Use Settings to change any of these fields, then Save changes. The change applies to future runs. Existing history keeps the name, prompt, project, session behavior, agent, model, and trigger recorded when each run started.

Select a routine row to open its side drawer with History, Settings, and Stats tabs. History and stats are read-only. Settings replaces the edit form and keeps unsaved changes while you switch tabs. Drawers fill half the screen on desktop and iPad, and 95% on mobile.

Each selection has a shareable URL, for example /routines?routine=<id> for history, or /routines?routine=<id>&view=settings and /routines?routine=<id>&view=stats. Reloading or opening the link restores the routine and tab. Closing the drawer returns to the list URL; browser Back restores the previous selection.

Stats count all recorded runs and show successful, failed, interrupted, and running totals. Average duration uses finished runs with valid start/end times. Total and average session costs use recorded billing; estimated total cost uses token pricing. Linked sessions count once, including their subagents. Reused or existing sessions include their full lifetime usage, not only routine prompts. Missing or disconnected sessions are reported as unavailable rather than zero. Stats refresh at most every 30 seconds while open. Remote usage is read on the owning machine; older owners without the usage RPC report costs unavailable.

When a run fails or is interrupted, ocman adds an Inbox item with the run status and the session’s final assistant message. Successful runs stay out of the Inbox unless you turn on Notify in the Inbox after a successful run under After a run (notify_on_success in the MCP routines tool). A run uses the setting that was in force when it started.

Webhook deliveries

A webhook inbox only captures deliveries. Routines subscribe to an inbox and decide which deliveries run them, so one inbox (for example, every event from a Forgejo repository) can drive several routines.

Agents can also create inboxes and subscribe routines through the webhooks MCP tool. See Webhook triggers for the setup sequence and author-only GitHub PR filters.

  1. Configure the relay URL under Settings → Webhooks, then choose Connect relay → Sign in to relay. Choose a provider offered by the relay to complete the connection. Ocman saves your enrollment token automatically, without a second confirmation on the relay. An empty relay URL falls back to the share relay. Self-hosted relays without SSO can use Manual enrollment with an operator-provided token instead.
  2. Open Routines → Webhook inboxes → New inbox, name it, and optionally set a shared secret and the header that carries it. Forgejo can send an Authorization header: use Authorization with a Bearer … secret. Copy the ingestion URL into the provider’s webhook settings.
  3. Edit a routine and pick the inbox as its Trigger, then add conditions. The trigger is either a schedule or one webhook inbox, not both; choosing a webhook clears the schedule.

For an unbound routine, set Webhook project field to an RFC 6901 JSON pointer, for example /repository/clone_url. The field must contain a nonempty string matching exactly one known, non-archived project on this machine by repository URL, project key or absolute directory. Repository URLs use the same normalized identity as the project index, so HTTPS and SSH forms can identify the same repo. Missing, unknown or ambiguous values fail the delivery without starting a session. The payload cannot select another machine, clone an unknown repository or override a routine’s fixed project. Fixed-project routines ignore this field.

Through MCP, omit directory when creating the routine and pass project_pointer when subscribing with webhooks. For manual MCP runs, pass project to routines action run. The REST run endpoint accepts an optional {"project":"/path/to/project"} body; existing empty-body requests still work for fixed-project routines.

Conditions combine header and RFC 6901 JSON Pointer predicates with AND. They support only equals, is one of, exists, and is missing; scripts and regular expressions are not evaluated. With no conditions, every delivery runs the routine.

Values compare by JSON type. Strings, booleans and null must be equal; numbers compare by exact decimal value, so 5, 5.0 and 5e0 are equal while 9007199254740992 and 9007199254740993 are not. Arrays and objects compare element by element under the same rules. A string, which is how the routine form stores every value, also equals a number, boolean or null whose JSON text it is ("5" and "5.0" match 5, "true" matches true), but "01" or " 5" match nothing, and an array or object never equals a string. Header values are text: they match strings and booleans case-insensitively and numbers by the same exact value. Pointers follow RFC 6901 strictly: an array index is 0 or a number without a leading zero (/items/01 and /items/- match nothing), and ~ must be followed by 0 or 1.

A matching delivery sends the routine prompt unchanged, followed by this fixed untrusted-data envelope:

{
  "inboxId": "...",
  "deliveryId": "...",
  "method": "POST",
  "query": {},
  "receivedAt": 0,
  "headersPath": "/…/ocman/webhook-deliveries/<hash>.headers",
  "bodyPath": "/…/ocman/webhook-deliveries/<hash>.body",
  "bodyBytes": 0
}

Headers and body are not inlined. Both paths are absolute 0600 files: headersPath holds a JSON object of canonical header name to values (for example {"X-Forgejo-Event":["pull_request"]}) and bodyPath holds the raw request body. The session reads only what it needs, for example jq -r '."X-Forgejo-Event"[0]' "<headersPath>" or jq -r .number "<bodyPath>". Allow the routine’s session to read <state dir>/webhook-deliveries/* (an external_directory permission rule), and query the files with jq rather than reading them whole. The files follow the 30-day history retention below.

A webhook runs its routine on the machine that received it. A subscription can only point at a routine that runs on this machine; a routine later moved to a remote is skipped with “routine runs on another machine”.

Select an inbox row to open its drawer: the ingestion URL, key reset and revoke, renaming, replacing or removing the shared secret (the URL stays the same; this needs a relay with the PUT /inboxes/{id}/secret endpoint), the subscribed routines, and the ten most recent deliveries with their filtered headers, body, and what happened for each subscriber (ran, no match, skipped because the routine is disabled, or failed). Use it to check a condition against what the provider actually sent. The shared secret is filled in and masked; use the eye button to inspect it. Inboxes created before ocman kept the secret show that one is set but can’t display it until you enter it again. The relay only removes a secret on an explicit "secret": ""; a request without a secret field is rejected. Redeliver replays a logged delivery as a new one: every subscriber is matched and run again, and the replay gets its own log entry. It carries the original headers, query and body; deliveries logged before the query was kept replay without one.

Deliveries are logged, not posted to the Inbox. The Inbox only hears about failures: a delivery ocman gave up on after 8 attempts, or a routine that could not be started for a delivery.

Disabled routines are skipped, while deleted routines cancel queued dispatches. Revoking an inbox removes its subscriptions. Delivery and dispatch history is retained for 30 days.

Relay inboxes expire after 30 days without a successful authenticated delivery poll. Empty polls renew the inbox too; incoming webhooks alone do not. Pending, unacknowledged relay messages expire after 48 hours from receipt, even if fetched for a failed processing attempt. Acknowledging a message removes it immediately. The relay’s hourly sweep removes expired inboxes and messages. These defaults can be changed with ocman-relay -inbox-ttl and -inbox-delivery-ttl. Messages stored by an older relay without retention timestamps receive a full 48-hour window from the first sweep after upgrading. Existing inboxes without polling timestamps also receive a full 30-day inactivity window. This relay retention is separate from ocman’s local 30-day delivery and dispatch history.

Use Delete to remove a routine from the UI and stop future scheduled runs. Deletion is soft: ocman retains the routine and its run history in state.db.

The Delete after a successful run option performs the same soft delete only after a run succeeds. A failed run leaves the routine available.

Enable Archive session after a successful run to hide completed sessions from the active session list. This is off by default and applies to scheduled and manual runs. Failed or interrupted runs stay visible. The routine and its schedule remain active, and history still links to the archived session. The setting is captured when each run starts; edits apply to future runs.

Run a routine

The Routines page and the composer provide different actions:

  • Run now starts or selects a session according to the routine and sends the saved prompt. It records a manual run in the routine’s history.
  • /routines in a session composer opens a picker and inserts the chosen prompt into the composer. It does not send the prompt, start a session, or create a history entry. Edit the text or send it like any other message.

Scheduled runs use the same session behavior as manual runs.

Schedule semantics

  • None has no automatic run time. Use Run now when needed.
  • Timeout accepts a delay from now. When you save the routine, ocman turns that relative delay into one absolute due time. Restarting ocman or editing the routine later does not restart the original countdown. Saving an edit with a timeout calculates a new due time from that save. A timeout missed while ocman is offline expires at startup instead of running late.
  • Once runs at one absolute date and time. The selected local time is saved as an absolute instant.
  • Cron uses a standard five-field cron expression plus an IANA timezone, such as 0 9 * * 1-5 with Europe/Brussels. Ocman calculates each next occurrence in that timezone after the previous run settles. An expression with no occurrence in the next five years, such as 0 0 31 2 * (February 31), is rejected when saved. Routines saved with such an expression before this check are not repaired and never run; edit their schedule to fix them.

The scheduler checks due routines every five seconds. Disable a routine to stop automatic runs without deleting it. Webhook delivery polling is independent of the scheduler and runs on the machine that owns the inbox, which also runs the subscribed routines.

Completion and history

A run remains running while its session is active or waiting for the session to settle. Session done marks the run success. Session error marks it failure. An interrupted or unavailable session marks the run interrupted. Dispatch errors, including an unavailable host or a session that could not be created or prompted, also produce a failed history entry.

Open a routine row to see when each run started, whether it was manual or scheduled, and its current result. Failed runs show their error. Runs with a linked session include an Open link. The drawer shows the newest 50 runs; Load older runs pages further back.

The routine list refreshes every five seconds. GET /api/routines includes each routine’s newest run as latestRun, so the list’s status and Last run columns need no history request. GET /api/routines/{id}/history returns one page, newest first: limit (default 50, at most 200), and for older runs the last shown run’s beforeCreatedAt and beforeId.

Run records preserve their routine snapshot and remain available after a restart. Ocman resumes observing linked running sessions after startup. If a restart interrupted dispatch before ocman linked a session, the run fails instead of starting a duplicate session.

Recover legacy Workflow data

Older ocman versions stored DAG definitions and runs in workflow_* tables. Routines never read, executed or migrated them. A DAG cannot be converted losslessly to one prompt because its nodes, dependencies, approvals, commands, outputs, and branching have no equivalent in a routine.

Schema v128 removes these tables from state.db, together with the agent loop and prompt schedule tables that preceded them. The upgrade first saves a pre-migration backup beside state.db, named state.db.backup-v<old>-to-v128-<unique>.db; see Configuration . The old data remains in that backup and in any database that has not been upgraded to v128.

There are no compatibility APIs. Use SQLite in read-only mode to inspect or export the old data from the backup.

DB="$(ls -t "$HOME"/.local/share/ocman/state.db.backup-v*-to-v128-*.db | head -n 1)"
sqlite3 -readonly "$DB" ".tables 'workflow_*'"
sqlite3 -readonly "$DB" ".dump 'workflow_*'" > legacy-workflows.sql
sqlite3 -readonly -json "$DB" "SELECT * FROM workflow_definition ORDER BY created_at;" > workflow-definitions.json
sqlite3 -readonly -json "$DB" "SELECT * FROM workflow_version ORDER BY workflow_id, revision;" > workflow-versions.json
sqlite3 -readonly -json "$DB" "SELECT * FROM workflow_run ORDER BY created_at;" > workflow-runs.json
sqlite3 -readonly -json "$DB" "SELECT * FROM workflow_node_run ORDER BY run_id, position;" > workflow-node-runs.json
sqlite3 -readonly -json "$DB" "SELECT * FROM workflow_node_attempt ORDER BY run_id, node_id, seq;" > workflow-node-attempts.json

The full authored DAG is in workflow_version.definition_json. To list the saved definitions in a readable form:

SELECT d.name, v.revision, v.created_at, v.definition_json
FROM workflow_definition AS d
JOIN workflow_version AS v ON v.workflow_id = d.id
ORDER BY d.name COLLATE NOCASE, v.revision;

Open that query without modifying the database:

sqlite3 -readonly -header -column "$DB"

Paste the SQL at the SQLite prompt. Extract any useful agent prompt from definition_json, then create a routine manually. Keep commands, approval steps, dependencies, and output handling outside the routine prompt unless the agent can safely perform them itself.