Skip to content

feat(cron): declarative jobs with owner attribution and richer status - #100480

Merged
steipete merged 1 commit into
mainfrom
feat/cron-declarative-jobs
Jul 6, 2026
Merged

steipete merged 1 commit into
mainfrom
feat/cron-declarative-jobs

Conversation

@steipete

@steipete steipete commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extends canonical cron jobs with the capabilities #98727 built as a separate "routines" registry — as plain additive cron features, per the product decision that a routine is not a new concept. No new table, service, RPC namespace, or CLI noun.

  • Declarative upsert: cron.add gains optional declarationKey. Re-declaring the same key converges the existing job (schedule/payload/delivery/displayName, enablement only when explicitly set) in one store lock + write transaction — {created:false, updated:true|false} — preserving job id, run history, and current enablement. No staged-write state machines, no drift model: with one store there is nothing to drift from. Identity-adjacent fields (name, target, routing, owner) are deliberately outside convergence.
  • Scope-local uniqueness + owner attribution: declaration keys are unique within the caller's scope. Agent-scoped callers are bounded by gateway-owned agentRuntimeIdentity (structural, not marker-based) and get owner stamped automatically; operators may pass explicit owner. Owner is immutable attribution.
  • Richer status on existing reads: declarationKey, displayName, owner, nextRunAtMs, lastRunAtMs/Status/Error, last delivery and failure-notification outcomes — derived from existing job/run/delivery state only.
  • Salvaged from feat: add durable routines registry #98727 (the parts that were always cron improvements): cron-caller-scope.ts and cron-error-classification.ts extractions (gateway cron.ts net −169), delivery-channel-validation.ts wired into add/converge (main-session jobs reject webhook delivery), update preconditions, and blank/duplicate-id validation.
  • Additive cron_jobs columns via the existing ensureColumn pattern; protocol schemas extended additively with regenerated JSON schema + Swift models (defaulted initializers keep source compat); openclaw cron add gains --declaration-key / --display-name; the cron agent tool extended in place.

36 files, +1,784/−411 — replacing #98727's +6,539/−406 (51 files) for the same operator capability, minus the second concept.

Proof

  • pnpm tsgo clean (verified twice: implementation run + independent review run).
  • Vitest: 531 tests / 9 files green on the implementation run; independent re-run of the focused suites (declarative-jobs service, gateway cron validation, cron tool, cron CLI, server-cron-lazy) — 489/489.
  • pnpm protocol:gen && protocol:gen:swift — regeneration byte-identical post-commit.
  • oxfmt/oxlint clean on all changed files; autoreview clean, no actionable findings.

Non-goals

Trigger-kind generalization (repository events, webhooks, channel-watch) is the intended follow-up on this same surface — a job's trigger becomes a kind, schedule being the first. No UI changes.

Supersedes #98727.

Implemented by Codex (gpt-5.6-sol, high reasoning) from a frozen spec; reviewed and independently verified by Claude.

@steipete
steipete requested a review from a team as a code owner July 5, 2026 22:24
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes scripts Repository scripts agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Jul 5, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 53ee8646e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cron/delivery-channel-validation.ts Outdated
Comment on lines +122 to +123
if (job.sessionTarget === "main" && job.delivery?.mode === "webhook") {
throw new Error("main-session cron jobs do not support webhook delivery");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep main-session webhook cron creation working

When a caller creates a main-session systemEvent job with delivery.mode="webhook", this new guard rejects it before the cron service sees the request. That breaks the existing Gateway/CLI path: addWebhookCronJob defaults sessionTarget to main in src/gateway/server.cron.test.ts:312, and the webhook delivery test creates exactly that shape at src/gateway/server.cron.test.ts:1486; the service contract still preserves main-session webhook jobs in src/cron/service.get-job.test.ts:49. Since webhook delivery is standalone and does not require an isolated chat target, keep validating the URL/channel fields without rejecting sessionTarget: "main".

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 5, 2026, 10:28 PM ET / 02:28 UTC.

Summary
The PR adds declaration-keyed cron convergence, immutable owner attribution, richer cron status projections, CLI/tool fields, protocol/Swift schema updates, and SQLite cron_jobs metadata columns.

PR surface: Source +619, Tests +767, Generated +8, Other +105. Total +1499 across 43 files.

Reproducibility: not applicable. as a feature PR; the relevant behavior is source-testable through the new service/gateway tests and should be validated through exact-head cron add/convergence scenarios.

Review metrics: 2 noteworthy metrics.

  • Cron public surfaces: 1 RPC result union, 2 CLI flags, 3 agent-tool fields, 4 SQLite columns. These are client, tool, and upgrade surfaces that need compatibility review before merge.
  • PR size: 43 files changed, +1923/-424. The XL diff crosses protocol, gateway, CLI, agent, state, Swift, and snapshot surfaces, so owner-boundary review matters.

Stored data model
Persistent data-model change detected: serialized state: src/cron/service/state.ts, serialized state: src/state/openclaw-state-db.generated.d.ts, unknown-data-model-change: packages/gateway-protocol/src/schema/cron.ts, vector/embedding metadata: src/cli/cron-cli/shared.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🌊 off-meta tidepool
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

  • [P2] Get exact-head required CI green.
  • Have a maintainer explicitly accept the cron declaration/result/schema and upgrade contract.

Risk before merge

  • [P1] This adds compatibility-sensitive cron RPC/result, CLI, agent-tool, Swift, and SQLite surfaces; existing clients and upgrades need maintainer-approved contract and upgrade proof before merge.
  • [P1] Owner/session-scoped declaration convergence can affect which job an agent sees or mutates, so the product boundary needs maintainer sign-off even though focused tests cover key cases.
  • [P1] Exact-head CI was still unstable at review time with checks-node-compact-large-whole-1 failed and QA Smoke in progress, so merge should wait for a clean required-check rollup.

Maintainer options:

  1. Approve the cron contract after green validation (recommended)
    Maintainers can accept the new cron declaration/result/schema/SQLite surface after reviewing upgrade compatibility and waiting for exact-head checks to pass.
  2. Add or require upgrade proof first
    Before merge, require evidence that existing cron rows and clients continue working across the new columns and result union.
  3. Pause if the API is too broad
    If declarationKey or owner attribution is not the desired product contract, pause or close this in favor of the RFC/routines direction.

Next step before merge

  • [P1] Protected maintainer/product review is needed for the new cron API/data-model contract and exact-head validation, not an autonomous repair PR.

Maintainer decision needed

  • Question: Should OpenClaw make declaration-keyed cron jobs with immutable owner attribution the supported product/API replacement for the superseded routines registry?
  • Rationale: The implementation is coherent, but it creates new public cron result/schema fields, CLI/tool inputs, Swift models, and persisted columns, so automation cannot decide the permanent product contract or upgrade tolerance.
  • Likely owner: vincentkoc — Their recent cron delivery/protocol work is closest to the compatibility and gateway contract choices in this PR.
  • Options:
    • Accept cron-native declarations (recommended): Approve this as the supported routines-like contract once exact-head CI is green and upgrade behavior is reviewed.
    • Narrow the public surface: Keep only the internal cron cleanup and defer declarationKey, owner, and result-shape APIs until the contract is smaller or documented.
    • Pause for the routines RFC: Hold this PR and resolve the broader routines/product naming question before changing cron public surfaces.

Security
Cleared: The diff does not add dependencies, workflow privilege, package-resolution changes, secret handling, or new third-party code execution paths; no concrete security concern found.

Review details

Best possible solution:

Land the cron-native declarative job surface only after maintainers accept the protocol/data-model contract and exact-head validation proves fresh-install and upgrade behavior.

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

Not applicable as a feature PR; the relevant behavior is source-testable through the new service/gateway tests and should be validated through exact-head cron add/convergence scenarios.

Is this the best way to solve the issue?

The cron-native approach appears better than the superseded routines registry because it keeps one scheduler/store/RPC noun, but final API and upgrade acceptance is a maintainer product decision.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9d9661e47375.

Label changes

Label changes:

  • add P2: This is a normal-priority feature/improvement to cron scheduling rather than an active user-facing outage or release blocker.
  • add merge-risk: 🚨 compatibility: The PR changes public cron schemas/results, CLI flags, Swift models, service contracts, and persisted SQLite columns that existing clients/upgrades may observe.
  • add merge-risk: 🚨 session-state: Declaration convergence and owner/caller scoping determine which session/agent-owned cron job is reused or mutated.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add feature: ✨ showcase: ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. The feature is strategically notable because it provides routine-like durability through the existing cron scheduler instead of adding a second registry and product noun.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository proof gate treats this as a maintainer-team PR and skipped external-contributor proof requirements, so no contributor action is required.
  • remove P1: Current review triage priority is P2, so this older priority label is no longer current.

Label justifications:

  • P2: This is a normal-priority feature/improvement to cron scheduling rather than an active user-facing outage or release blocker.
  • merge-risk: 🚨 compatibility: The PR changes public cron schemas/results, CLI flags, Swift models, service contracts, and persisted SQLite columns that existing clients/upgrades may observe.
  • merge-risk: 🚨 session-state: Declaration convergence and owner/caller scoping determine which session/agent-owned cron job is reused or mutated.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • feature: ✨ showcase: ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. The feature is strategically notable because it provides routine-like durability through the existing cron scheduler instead of adding a second registry and product noun.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository proof gate treats this as a maintainer-team PR and skipped external-contributor proof requirements, so no contributor action is required.
Evidence reviewed

PR surface:

Source +619, Tests +767, Generated +8, Other +105. Total +1499 across 43 files.

View PR surface stats
Area Files Added Removed Net
Source 25 1023 404 +619
Tests 14 786 19 +767
Docs 0 0 0 0
Config 0 0 0 0
Generated 2 8 0 +8
Other 2 106 1 +105
Total 43 1923 424 +1499

What I checked:

  • Current PR scope: Live this PR is open at c871157 with 43 changed files, +1923/-424, and a single feature commit adding declarative cron jobs. (c87115783e55)
  • Declarative cron convergence: CronService.add now converges jobs by declarationKey inside the existing store lock, preserving job id/history and only updating schedule, payload, delivery, displayName, and explicit enabled state. (src/cron/service/ops.ts:616, c87115783e55)
  • Gateway API handling: Gateway cron.add validates new declaration/display fields, applies caller-scope defaults, checks scoped declaration matching, and returns the new declarative result shape when applicable. (src/gateway/server-methods/cron.ts:433, c87115783e55)
  • Public protocol surface: The gateway protocol adds declarationKey, displayName, owner, top-level status projections, and a CronAddResult union for imperative versus declarative add results. (packages/gateway-protocol/src/schema/cron.ts:461, c87115783e55)
  • Stored data model: State DB bootstrap adds four cron_jobs columns via the existing additive ensureColumn path: declaration_key, display_name, owner_agent_id, and owner_session_key. (src/state/openclaw-state-db.ts:689, c87115783e55)
  • Previous webhook finding fixed: Current tests still create webhook cron jobs with sessionTarget defaulting to main and assert a valid main-session webhook delivery path, addressing the prior ClawSweeper blocker. (src/gateway/server.cron.test.ts:312, c87115783e55)

Likely related people:

  • vincentkoc: Recent cron delivery validation and protocol/list projection work overlaps the new delivery validation and read-projection surfaces. (role: recent area contributor/reviewer; confidence: medium; commits: f236217d5b1f, ca1a53aca4ba; files: src/gateway/server-methods/cron.ts, packages/gateway-protocol/src/schema/cron.ts)
  • Josh Avant: Recently changed gateway cron operations to scope agent calls, which is directly adjacent to the PR's owner/caller-scope behavior. (role: recent area contributor; confidence: medium; commits: cee2aca40912; files: src/gateway/server-methods/cron.ts)
  • Yuval Dinodia: Recently worked on cron service mutation and schedule preservation behavior, which overlaps declaration convergence and update preconditions. (role: recent scheduler invariant contributor; confidence: medium; commits: e38d64c5f88b, c854e4e93f06; files: src/cron/service/ops.ts)
  • Cameron Beeley: Recent cron protocol and agent-tool schema work is adjacent to the new cron fields and dynamic tool snapshots. (role: recent protocol/agent-tool contributor; confidence: medium; commits: 68bfa42b9bfc, 9aea104cc88a; files: packages/gateway-protocol/src/schema/cron.ts, src/agents/tools/cron-tool.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-05T22:41:57.135Z sha 53ee864 :: needs real behavior proof before merge. :: [P1] Keep main-session webhook delivery valid

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jul 5, 2026
@steipete
steipete force-pushed the feat/cron-declarative-jobs branch from 53ee864 to f43f44e Compare July 6, 2026 01:53
@steipete

steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Repaired the three red checks on head f43f44e90e:

  • check-test-types / check-additional-boundaries-a: the cron.add mock in cron.validation.test.ts kept the old 1-arg signature while an assertion indexed the new options argument — mock updated to the 2-arg contract.
  • checks-node-compact-small-8 (server.cron.test.ts): a spec error on my side, not the implementation — I had ordered the routines-only "main-session jobs reject webhook delivery" rule mirrored onto cron, but shipped cron behavior allows main+webhook (and main's integration suite asserts it). The rule is removed from all four enforcement sites (create validation, update patch validation, declarative convergence, error classifier); the tests that asserted rejection now assert the shipped acceptance behavior, and the declarative-convergence test asserts delivery converges while the session target stays outside convergence.

Local pnpm tsgo:test clean on the repair. Full suites left to CI — the local box is saturated by concurrent worker sessions (load ~780).

@steipete
steipete force-pushed the feat/cron-declarative-jobs branch 2 times, most recently from 7a9ba26 to 9f507a4 Compare July 6, 2026 02:05
Adds scope-local declaration-key convergence, immutable owner attribution, richer status projection, and delivery validation to canonical cron jobs.

Supersedes the #98727 routines registry approach; no parallel registry, RPC namespace, or CLI noun.
@steipete
steipete force-pushed the feat/cron-declarative-jobs branch from 9f507a4 to c871157 Compare July 6, 2026 02:16
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. feature: ✨ showcase ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. labels Jul 6, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 6, 2026
@steipete
steipete merged commit fdc9aa8 into main Jul 6, 2026
203 of 217 checks passed
@steipete
steipete deleted the feat/cron-declarative-jobs branch July 6, 2026 02:35
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 6, 2026
…openclaw#100480)

Adds scope-local declaration-key convergence, immutable owner attribution, richer status projection, and delivery validation to canonical cron jobs.

Supersedes the openclaw#98727 routines registry approach; no parallel registry, RPC namespace, or CLI noun.
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 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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant