Skip to content

cron: optional custom job id and duplicate-id validation - #40218

Closed
Saitop wants to merge 4 commits into
openclaw:mainfrom
NomiciAI:feat/cron-custom-job-id
Closed

Saitop wants to merge 4 commits into
openclaw:mainfrom
NomiciAI:feat/cron-custom-job-id

Conversation

@Saitop

@Saitop Saitop commented Mar 8, 2026

Copy link
Copy Markdown

Summary

  • Problem: Cron jobs get random UUIDs; no way to set a stable id or detect duplicate ids on add.
  • Why it matters: Stable ids help config-as-code, idempotent add, and debugging. Duplicate ids would corrupt store expectations.
  • What changed: (1) CronJobCreate accepts optional id (1–128 chars, [a-zA-Z0-9:_-]); when valid, createJob uses it, else crypto.randomUUID(). (2) add() throws if a job with the same id already exists.
  • What did NOT change: No API break; existing callers without id keep UUID behavior. No change to update/remove or list.

Change Type (select all)

  • Feature

Scope (select all touched areas)

  • API / contracts

Linked Issue/PR

  • Closes #
  • Related #

User-visible / Behavior Changes

  • Cron job create (CLI/Gateway/API) can pass optional id. If provided and valid, that id is used; otherwise a UUID is assigned.
  • Adding a cron job with an id that already exists now throws: cron job with id "…" already exists.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: macOS
  • Runtime: Node 22
  • Relevant: pnpm build && pnpm check && pnpm test --run src/cron/service.jobs.test.ts src/cron/service.get-job.test.ts

Steps

  1. Add a job with custom id, e.g. openclaw cron add --id my-nightly … (or via Gateway cron API with id: "my-nightly").
  2. Add another job with the same id.

Expected

  • First add uses id my-nightly. Second add throws.

Actual

  • As expected.

Evidence

  • New tests: createJob custom id (valid/invalid/omit/trim) and uses custom id when provided and rejects duplicate id on add in service.get-job.test.ts.

@greptile-apps

greptile-apps Bot commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds two related features to the cron service:

  1. Optional stable id field on CronJobCreate: When provided and valid ([a-zA-Z0-9:_-], 1–128 chars after trimming), it is used as the job id; otherwise crypto.randomUUID() is used as before.
  2. Duplicate-id guard in add(): Throws cron job with id "…" already exists when the resolved id collides with an existing job.

The implementation is fully backward-compatible (id is optional), race-condition safe (the duplicate-id check runs inside the existing locked() scope after ensureLoaded()), and is covered by comprehensive unit and integration tests covering all custom-id edge cases (valid, trimmed, invalid, omitted).

Key observations:

  • The duplicate-id check runs after createJob(), so configuration-validation errors (from assertSupportedJobSpec / assertDeliverySupport) surface before the duplicate-id error when both issues are present. This is expected behavior.
  • The regex /^[a-zA-Z0-9:_-]{1,128}$/ correctly places - at the end of the character class to avoid range interpretation.
  • normalizeCronCreateDeliveryInput uses object spread to preserve the id field through to createJob().
  • No changes to update/remove/list operations or public API surface.

Confidence Score: 5/5

  • This PR is safe to merge. The implementation is correct, fully backward-compatible, race-condition safe, and thoroughly tested.
  • The logic is sound: custom id validation with proper trimming and regex, duplicate-id check runs under the existing lock after store reload, and all edge cases are covered by tests. No API breakage. No side-effect risks. No race conditions or concurrency issues. The feature is exactly as specified and matches the PR description.
  • No files require special attention.

Last reviewed commit: 862e2bf

@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: 862e2bfe53

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/cron/types.ts Resolved
Comment thread src/cron/service/jobs.ts Resolved
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime labels Mar 8, 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: 8c6987c8fc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread .pre-commit-config.yaml Resolved
@openclaw-barnacle openclaw-barnacle Bot added the app: macos App: macos label Mar 8, 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: 818bdd39ce

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/cron/service/ops.ts Resolved

@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: 3ca3955082

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@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: de4827c20a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/gateway/protocol/schema/cron.ts Resolved

@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: d23e112ca1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread test-fixtures/talk-config-contract.json Resolved

@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: fb932e0ca3

ℹ️ 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/gateway/protocol/schema/cron.ts Resolved

@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: 6ca0fe21d2

ℹ️ 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/gateway/protocol/schema/cron.ts Resolved

@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: a9ecaa6dba

ℹ️ 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/gateway/protocol/schema/cron.ts Resolved
@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Mar 13, 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: 516e2966f5

ℹ️ 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/gateway/protocol/schema/cron.ts Resolved
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Mar 14, 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: 6bbd31f617

ℹ️ 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".

@Saitop
Saitop requested a review from a team as a code owner March 14, 2026 21:33

@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: 23603da0e8

ℹ️ 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/service/ops.ts Resolved
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Apr 25, 2026
@clawsweeper

clawsweeper Bot commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes:

The PR adds optional stable cron job IDs across cron creation, duplicate-ID validation, cron.add schema and normalization, CLI/tool inputs, docs, tests, and generated Swift Gateway models.

Required change before merge:

A concrete PR-branch repair is available: update Swift protocol generation for optional initializer defaults and regenerate the two generated Swift model copies, without needing product or security judgment.

Security review:

Security review cleared: The diff adds constrained cron data handling plus docs, tests, and generated Swift models, with no concrete security or supply-chain regression found.

Review findings:

  • [P2] Preserve CronAddParams initializer compatibility — apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift:3619
Review details

Best possible solution:

Keep the stable cron-id feature direction, but make additive generated Swift protocol fields source-compatible by defaulting optional initializer parameters to nil, regenerate both Swift model copies, and land with the cron, protocol, CLI/tool, and Swift checks green.

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

Yes. The latest diff adds a new non-default id: String? argument to CronAddParams.init, so Swift source that compiles today with CronAddParams(name:agentid:...) would need a new id: argument after this PR.

Is this the best way to solve the issue?

No, not as currently proposed. The TypeScript cron service, gateway, CLI, and tool changes are narrow, but the generated Swift API needs a generator-backed compatibility fix before the patch is mergeable.

Full review comments:

  • [P2] Preserve CronAddParams initializer compatibility — apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift:3619
    The PR adds optional wire field id to the public CronAddParams initializer as id: String? without a default. Existing Swift callers that construct CronAddParams(name:agentid:...) now have to pass id:, so this additive protocol field becomes source-breaking. Update the Swift generator to emit = nil for optional initializer parameters and regenerate both generated model copies.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.92

Acceptance criteria:

  • pnpm protocol:check
  • pnpm test src/cron/service.jobs.test.ts src/cron/service.get-job.test.ts src/gateway/protocol/cron-validators.test.ts src/cli/cron-cli.test.ts src/agents/tools/cron-tool.flat-params.test.ts
  • swift test --package-path apps/shared/OpenClawKit
  • git diff --check
  • pnpm check:changed in Testbox if changed lanes expand beyond targeted local proof

What I checked:

  • current_main_random_ids_only: Current main still assigns new cron job IDs with crypto.randomUUID() and does not read an input id in createJob. (src/cron/service/jobs.ts:558, 52e2d4e16a29)
  • current_main_gateway_schema_has_no_id: Current main's CronAddParamsSchema has additionalProperties: false and no id property, so stable cron IDs are not already available through cron.add. (src/gateway/protocol/schema/cron.ts:297, 52e2d4e16a29)
  • pr_diff_swift_initializer_requires_id: The latest public PR diff adds id: String? to CronAddParams.init without a default, so existing Swift callers must pass the new argument. (apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift:3619, b76d14a6ab0f)
  • swift_generator_no_optional_defaults: The current Swift protocol generator emits optional initializer parameters as Type? but does not append = nil, so regenerating keeps additive optional fields source-breaking. (scripts/protocol-gen-swift.ts:193, 52e2d4e16a29)
  • latest_diff_addresses_earlier_cron_surface_gaps: The latest diff includes no-colon custom-id validation, case-insensitive duplicate checking, gateway id acceptance, CLI --id wiring, flat cron-tool id recovery, and non-string stored-id guards, leaving the Swift initializer compatibility issue as the remaining concrete blocker. (src/cron/service/ops.ts:315, b76d14a6ab0f)

Likely related people:

  • steipete: GitHub path history shows repeated recent work on cron service behavior, cron gateway schema, Swift protocol generation, and generated Swift model refreshes. (role: recent cron and protocol maintainer; confidence: high; commits: 4bca42d9331f, b6be42230672, bdba90a20b2b; files: src/cron/service/jobs.ts, src/gateway/protocol/schema/cron.ts, scripts/protocol-gen-swift.ts)
  • mvanhorn: GitHub path history shows recent cron service maintenance around loading defaults and supported-job-spec validation near the service path this PR changes. (role: recent cron service maintainer; confidence: medium; commits: b33eb93aac8a; files: src/cron/service/jobs.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 52e2d4e16a29.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation and removed stale Marked as stale due to inactivity labels Apr 27, 2026
@Saitop

Saitop commented Apr 27, 2026

Copy link
Copy Markdown
Author

Updated this PR with a clean rebase/narrow commit on the cron custom-id change. The previous protocol-generation failure is fixed: the latest PR run has checks-fast-protocol passing, and local pnpm protocol:check plus the targeted cron/gateway tests pass.\n\nCurrent remaining red checks appear unrelated to this PR diff and reproduce on current upstream/main (checked at 91e835ebe0):\n- pnpm check:madge-import-cycles reports the existing src/cli/argv.ts -> ... -> subcli-descriptors.ts cycle.\n- pnpm test src/cli/command-registration-policy.test.ts src/cli/program/root-help.test.ts fails command-registration-policy.\n- pnpm lint:docs reports duplicate headings in docs/channels/matrix.md.\n\nThis branch intentionally stays scoped to the cron stable-id work and does not include those unrelated main fixes.

@NomiciAI NomiciAI closed this by deleting the head repository Apr 30, 2026
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: macos App: macos app: web-ui App: web-ui cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants