Skip to content

feat: add durable routines registry - #98727

Closed
steipete wants to merge 1 commit into
mainfrom
codex/durable-routines
Closed

steipete wants to merge 1 commit into
mainfrom
codex/durable-routines

Conversation

@steipete

@steipete steipete commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #98515

What Problem This Solves

OpenClaw has cron jobs, tasks, heartbeat, commitments, and channel/session delivery primitives, but no first-class durable registry for recurring team-operations routines. Operators can schedule work today, but they cannot create, inspect, pause, delete, or recover a typed routine as one durable product object with ownership, delivery target, run status, and replay-safe mutation semantics.

Why This Change Was Made

This adds the smallest complete routine slice: a typed routine registry backed by the shared SQLite state DB, Gateway RPC methods, CLI entrypoints, an agent-tool entrypoint, and a schedule trigger that delegates execution to the canonical cron service rather than creating a second scheduler. The design keeps cron as the scheduler owner and routines as the durable registry owner, with internal create/toggle stages so retries recover safely after partial persistence or scheduler failures.

Non-goals for this draft: no Control UI yet, no channel-watch/repository-event/webhook triggers yet, no duplicate scheduler, and no transcript attachment. The trigger model is shaped so those future triggers can share the same routine subsystem instead of growing a second path.

AI-assisted implementation and review were used for this draft PR.

User Impact

Users and operators can now use openclaw routines, Gateway RPC, or the Gateway agent tool to create, list, inspect, enable, disable, and delete durable scheduled routines. Routine inspection shows owner, delivery target, enabled/deleted state, last and next run visibility, status, and last error context. Repeated create/toggle/delete calls are idempotent, and restart/replay behavior preserves the intended routine state instead of silently losing a schedule toggle or rolling scheduler state backward.

Evidence

  • Exact head: 786ba1e63a6953c9c12c95fa99abe3b5aaffe7d3, rebased on origin/main 5bcd25f0fb6de3cc2ba6b6a7688a9361eb355143.
  • LOC gate after final rebase: total 51 files +6542/-409; production 27 files +3103/-390, tests 11 files +2805/-0, docs 9 files +359/-19, generated protocol/state files 4 files +275/-0. Remaining positive production LOC is concentrated in the routine service durability/recovery state machine, narrow CLI/Gateway/protocol entrypoints, and shared cron validation/scope helpers that delete duplicated cron Gateway policy rather than creating a second scheduler.
  • Exact-head local sanity passed: git diff --check origin/main...HEAD, pnpm docs:list, pnpm protocol:check, and clean git status --porcelain=v1.
  • Focused local runtime proof passed before the final app/extension-only rebases: node scripts/run-vitest.mjs <routines/cron/Gateway/CLI/protocol/session/tool-result-truncation tests> completed 5 shards / 156 tests, and targeted node scripts/run-oxlint.mjs <touched runtime/test files> passed. The later rebases touched only iOS/Android/Discord/Feishu owner files outside the routines/cron/Gateway/protocol lane.
  • Testbox-through-Crabbox exact routine scenario passed with provider blacksmith-testbox, id tbx_01kwh57ehx56t754rqjxqttskg, Actions run https://github.com/openclaw/openclaw/actions/runs/28582551404. The proof matched exact tree 0b6d7d0814271c196c8fae82170f3590c1f12bde, built the branch, started an isolated local Gateway, approved the staged device scope request, and drove openclaw routines list/create/list/get/disable/enable/delete through the public CLI and Gateway RPC. Final assertion output: {"routineId":"proof-daily","cronJobId":"routine-cron-61f944366f18f9191d29a9b0425f6694","backing":"linked","status":"enabled","deleted":true,"persistentTarget":"session:agent:ops:main","isolatedTarget":"isolated","isolatedDelivery":"none"}.
  • Testbox-through-Crabbox exact changed/build gate passed with provider blacksmith-testbox, id tbx_01kwh5gdg666jm6dm0sknq6taq, Actions run https://github.com/openclaw/openclaw/actions/runs/28582820315. The proof matched exact tree 0b6d7d0814271c196c8fae82170f3590c1f12bde, then ran corepack pnpm build:strict-smoke and corepack pnpm check:changed with remote changed lanes enabled.
  • Fresh autoreview against origin/main passed clean on exact head with model gpt-5.6-sol, extra-high reasoning: .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --engine codex --model codex=gpt-5.6-sol --thinking codex=xhigh --prompt-file <prompt-file> --output <review-output> --json-output <review-json>. It explicitly reassessed best-fix fit, owner boundaries, LOC pressure, cron helper duplication, idempotent mutations, drift handling, re-enable behavior, docs/generated alignment, and PR evidence hygiene; result: no accepted/actionable findings.

Risks and review focus: routine persistence and cron mutation ordering, idempotent replay after partial failures, schema/client drift, schedule-only routine views over mutable cron backing jobs, and delivery target defaults. No UI screenshot evidence is included because this draft intentionally defers Control UI work.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 4, 2026, 12:36 PM ET / 16:36 UTC.

Summary
The branch adds a SQLite-backed durable routines registry with routines Gateway RPC/protocol methods, an openclaw routines CLI, cron-backed execution, docs, generated clients, and focused tests.

PR surface: Source +2720, Tests +2805, Docs +340, Generated +14, Other +254. Total +6133 across 51 files.

Reproducibility: not applicable. this is a new feature implementation for an open product issue, not a report of broken current behavior.

Review metrics: 2 noteworthy metrics.

  • Public Routine API Surface: 6 Gateway RPC methods added, 1 CLI command group added. These become user/client-facing routine management entry points and need maintainer acceptance before merge.
  • Persistent Routine State Surface: 1 shared SQLite table added. The routine_records table becomes durable upgrade-sensitive state rather than a transient implementation detail.

Stored data model
Persistent data-model change detected: database schema: src/state/openclaw-state-schema.generated.ts, database schema: src/state/openclaw-state-schema.sql, serialized state: src/cron/service/state.ts, serialized state: src/cron/service/store.test.ts, serialized state: src/state/openclaw-state-db.generated.d.ts, unknown-data-model-change: packages/gateway-protocol/src/schema/routines.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Refresh the real CLI/Gateway routines flow proof on head e8096ab.
  • Have maintainers confirm or narrow the routines protocol, CLI, generated-client, shared-state table, and cron ownership boundary.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR has older Testbox CLI/Gateway proof plus current-head tests, but it does not show a fresh exact-head real CLI/Gateway routines run after the latest force-push. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The PR adds public Gateway RPC, CLI, generated-client, and shared SQLite state contracts, so green tests alone do not settle product/API/upgrade compatibility.
  • [P1] The latest current-head comment provides tests and protocol-generation proof, but the real CLI/Gateway Testbox scenario in the PR body still names an older tree, leaving exact-head behavior proof weaker than the merge gate.

Maintainer options:

  1. Refresh Proof And Confirm Contract (recommended)
    Rerun the real CLI/Gateway routines flow on head e8096ab, then have maintainers explicitly accept the new protocol, CLI, generated-client, SQLite table, and cron boundary.
  2. Narrow The First Contract
    If maintainers are not ready to own the full routine surface, split or reduce the PR to the smallest accepted durable contract before landing persisted state.
  3. Accept The New Contract Deliberately
    Maintainers may intentionally merge the full routine registry after exact-head proof if they are ready to own the compatibility and upgrade surface.

Next step before merge

  • [P1] Manual review is required because the PR is draft/protected, adds public protocol and durable state contracts, and still needs exact-head behavior proof rather than a narrow automated repair.

Security
Cleared: No concrete security or supply-chain concern was found; the diff does not change dependencies, workflows, lockfiles, package scripts, or secret-handling paths, and the new write RPCs are operator.admin scoped.

Review details

Best possible solution:

Keep the draft open, refresh exact-head real CLI/Gateway routines proof, and merge only after maintainers accept or narrow the routines protocol, CLI, generated-client, shared SQLite table, and cron ownership boundary.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this is a new feature implementation for an open product issue, not a report of broken current behavior.

Is this the best way to solve the issue?

Unclear as a final merge decision: the cron-backed registry is a plausible owner-boundary fit, but the permanent API/state contract needs maintainer acceptance or narrowing before merge.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 280e8d487627.

Label changes

Label changes:

  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR has older Testbox CLI/Gateway proof plus current-head tests, but it does not show a fresh exact-head real CLI/Gateway routines run after the latest force-push. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • remove status: 🔁 re-review loop: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P2: The PR implements a bounded but broad operator workflow feature without evidence of an urgent shipped regression.
  • merge-risk: 🚨 compatibility: The diff adds public CLI/Gateway protocol methods, generated client models, and shared SQLite state that can affect client and upgrade expectations.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • feature: ✨ showcase: ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. A first-class routine object over cron unlocks recurring team operations while preserving one scheduler and one task ledger.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR has older Testbox CLI/Gateway proof plus current-head tests, but it does not show a fresh exact-head real CLI/Gateway routines run after the latest force-push. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +2720, Tests +2805, Docs +340, Generated +14, Other +254. Total +6133 across 51 files.

View PR surface stats
Area Files Added Removed Net
Source 28 3107 387 +2720
Tests 11 2805 0 +2805
Docs 9 359 19 +340
Config 0 0 0 0
Generated 2 14 0 +14
Other 1 254 0 +254
Total 51 6539 406 +6133

What I checked:

Likely related people:

  • Peter Steinberger: Introduced the original cron scheduler/run-history path and authored the current routines PR, so the new registry builds directly on prior cron ownership. (role: feature-history owner; confidence: high; commits: f9409cbe43d2; files: src/cron/service/ops.ts, docs/automation/cron-jobs.md)
  • Josh Avant: Authored scoped agent cron operations, which are adjacent to the routine handler's operator-only boundary and cron caller-scope model. (role: recent adjacent owner; confidence: high; commits: cee2aca40912; files: src/agents/tools/gateway.ts, src/gateway/server-methods/cron.ts)
  • Vincent Koc: Authored task-ledger SQLite work relevant to keeping routines aligned with durable execution history instead of creating a second activity ledger. (role: adjacent state and task-ledger contributor; confidence: medium; commits: e57b3618fc8d; files: src/tasks/task-registry.store.sqlite.ts, src/tasks/task-registry.ts)
  • Tak Hoffman: Authored cron edit/list/run-history parity work in management surfaces that the routines CLI and Gateway API now extend. (role: historical cron management contributor; confidence: medium; commits: 77c3b142a966; files: src/cron/service/ops.ts, src/gateway/server-methods/cron.ts, packages/gateway-protocol/src/schema/cron.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (1 earlier review cycle)
  • reviewed 2026-07-02T01:45:13.399Z sha c1e55dde9121db7c2070f526d9183a2aa53d6e52 :: needs real behavior proof before merge. :: none

@steipete

steipete commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 1, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 1, 2026
@steipete
steipete force-pushed the codex/durable-routines branch 2 times, most recently from 7ede583 to 0c181be Compare July 1, 2026 22:00
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 1, 2026
@steipete

steipete commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jul 1, 2026
@steipete
steipete force-pushed the codex/durable-routines branch from 3a0d4fb to adba2a3 Compare July 2, 2026 02:58
@clawsweeper clawsweeper Bot added the feature: ✨ showcase ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. label Jul 2, 2026
@steipete
steipete force-pushed the codex/durable-routines branch from adba2a3 to 0bc2292 Compare July 2, 2026 03:10
@steipete

steipete commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Final routines draft refreshed on 0bc22921b7a84d98870591ea7a5947c2b42d8916 after rebasing onto origin/main 8e95e56e2dac8af2ebded2b20126932e2e8ac3ef. Evidence in the PR body is current and sanitized; the failure-alert drift finding is fixed and covered by regression tests plus current Testbox proof.

@clawsweeper

clawsweeper Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 2, 2026
@steipete
steipete force-pushed the codex/durable-routines branch from 0bc2292 to 786ba1e Compare July 2, 2026 10:19
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 🔁 re-review loop A fresh ClawSweeper review was explicitly requested after the latest review. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 2, 2026
Typed routine registry layered on the existing cron scheduler: durable
content-addressed identity, owner and delivery target, idempotent
replay-safe create/enable/disable/delete with staged recovery, live
status/drift projection against the backing cron job, six operator
gateway RPCs, openclaw routines CLI, and generated Swift protocol
models. Cron remains the only scheduler; tasks remain the activity
ledger. Squashed from the 52-commit routines stack for replay onto
current main.
@steipete

steipete commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (post #99816/#99817) — zero conflicts. The 52-commit stack is squashed to a single commit; protocol JSON schema and Swift GatewayModels regenerated on the new base.

Refreshed proof on head (current exact head of this branch): pnpm tsgo clean; pnpm protocol:gen + protocol:gen:swift clean; all 14 test files touched by this PR — 386 passed, 0 failed (routine service state machine incl. staged create/enable/disable recovery and drift projection, gateway routines.* RPC handlers, openclaw routines CLI, cron precondition/update contract, delivery-channel validation, session-target inheritance).

Remaining before merge per prior review: maintainer acceptance of the six new gateway RPCs, the openclaw routines CLI group, and the routine_records SQLite table as durable contracts.

@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #100480.

Product decision: a routine is not a new concept — it is a cron job with missing ergonomics. The registry approach here (separate routine_records store, staged create/enable/disable recovery, drift projection, six routines.* RPCs, openclaw routines CLI) existed to keep a second copy consistent with the first; folding the capabilities into cron directly removes the second copy and with it the machinery: #100480 delivers declaration-key upsert, owner attribution, delivery validation, and richer status as additive cron.* features at ~28% of this PR's diff.

Salvaged into #100480: the caller-scope and error-classification extractions, delivery-channel validation, update preconditions, and the test intents. Trigger-kind generalization (repo events/webhooks) remains the follow-up, now planned directly on cron.

Thanks to the worker session that built this lane — the requirements it proved out (idempotent declaration, ownership, replay safety, status) are exactly what shipped; only the shape changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui cli CLI command changes docs Improvements or additions to documentation feature: ✨ showcase ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Durable routines registry for scheduled team operations

1 participant