Skip to content

fix(cron-ui): accept timeoutSeconds: 0 as no-timeout mode (closes #41272) - #46003

Closed
Br1an67 wants to merge 1 commit into
openclaw:mainfrom
Br1an67:fix/41272
Closed

Br1an67 wants to merge 1 commit into
openclaw:mainfrom
Br1an67:fix/41272

Conversation

@Br1an67

@Br1an67 Br1an67 commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: Cron job UI validation rejects timeoutSeconds: 0, which should represent "no timeout" mode for long-running jobs.
  • Why it matters: Users cannot disable timeout for long-running cron jobs via the UI.
  • What changed:
    • ui/src/ui/controllers/cron.ts: Changed validation from timeout <= 0 to timeout < 0 so zero is accepted. Updated buildCronPayload() to include timeoutSeconds: 0 in payload when explicitly set.
    • ui/src/ui/controllers/cron.test.ts: Updated existing test expectation and added new test verifying negative values are rejected while zero is allowed.
  • What did NOT change: Backend cron handling, positive timeout values, empty timeout field behavior.

Change Type

  • Bug fix

Scope

  • Control UI

Linked Issue/PR

Security Impact

  • 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

  1. Create a cron job, set timeoutSeconds to 0
  2. Before fix: validation error cron.errors.timeoutInvalid
  3. After fix: form submits successfully with timeoutSeconds: 0 in payload

Evidence

  • Test updated: existing validation test now expects zero to pass
  • New test added: verifies negative → rejected, zero → accepted
  • AI-assisted: generated by Copilot, lightly tested (unit test logic verified by code review)

Human Verification

  • Verified scenarios: validation logic for 0, negative, positive, and empty values
  • Edge cases checked: empty string (no timeout field) still omits from payload
  • What you did NOT verify: browser-level UI rendering

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

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

ℹ️ 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 ui/src/ui/controllers/cron.ts Outdated
@@ -139,7 +139,8 @@ export function validateCronForm(form: CronFormState): CronFieldErrors {
const timeoutRaw = form.timeoutSeconds.trim();
if (timeoutRaw) {
const timeout = toNumber(timeoutRaw, 0);
if (timeout <= 0) {
// 0 = no timeout (valid), negative = invalid
if (timeout < 0) {

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 Reject non-numeric timeout values in cron form

Using timeout < 0 here makes malformed values pass validation because toNumber maps NaN to 0 (ui/src/ui/format.ts). With this change, inputs like "abc" no longer produce cron.errors.timeoutInvalid, and the new payload logic then serializes that non-empty invalid input as timeoutSeconds: 0 (no-timeout mode). Since the timeout field is plain text (ui/src/ui/views/cron.ts), this regression can occur in normal UI usage and silently changes job behavior.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a legitimate UX bug where entering 0 in the timeoutSeconds field was incorrectly rejected by the cron job UI. The core intention is correct: 0 should mean "no timeout" and be valid. However, the fix introduces a regression by changing the validation guard from timeout <= 0 to timeout < 0 without accounting for how toNumber handles non-numeric input.

Key issues found:

  • Regression — non-numeric strings silently pass validation: toNumber returns its fallback (0) for any non-parseable string. Under the old <= 0 guard, strings like "abc" were caught (fallback 0 <= 0 was true). Under the new < 0 guard they pass, then buildCronPayload incorrectly emits timeoutSeconds: 0 as if the user had opted into no-timeout mode. The fix is to use a negative fallback (e.g. toNumber(timeoutRaw, -1)) or add an explicit Number.isFinite check.
  • Payload builder has the same gap: The new else if (timeoutSeconds === 0 && form.timeoutSeconds.trim() !== "") branch in buildCronPayload does not verify the raw string is actually numeric, so non-numeric input would reach this branch and set payload.timeoutSeconds = 0. Adding a Number.isFinite(Number(form.timeoutSeconds.trim())) guard here would make the builder independently safe.
  • Test suite misses the regression: The new test only checks "-5" and "0", and does not add a case for a non-numeric string like "abc", which would have caught the regression above.

Confidence Score: 2/5

  • Not safe to merge as-is — the validation change unblocks a real bug but introduces a regression for non-numeric input that silently corrupts the submitted payload.
  • The intent is correct and the happy-path fix works, but the change from <= 0 to < 0 removes the implicit guard that caught non-numeric strings (which fall back to 0 via toNumber). Those strings now pass validation and cause timeoutSeconds: 0 to be silently included in the payload. The test suite does not cover this case, so the regression would ship undetected.
  • ui/src/ui/controllers/cron.ts — specifically the validation block at line 141 and the payload builder at line 582.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: ui/src/ui/controllers/cron.ts
Line: 141-145

Comment:
**Non-numeric strings now silently pass validation**

Changing `<= 0` to `< 0` introduced a regression for non-numeric input. `toNumber` returns its fallback (`0`) for any non-parseable string, so `toNumber("abc", 0)` → `0`. Previously `0 <= 0` was `true`, so garbage input triggered a validation error. Now `0 < 0` is `false`, meaning strings like `"abc"` or `"foo"` silently pass validation.

This then flows into `buildCronPayload` where the same `toNumber("abc", 0)` call returns `0`, `0 === 0 && "abc" !== ""` is `true`, and `payload.timeoutSeconds = 0` is incorrectly emitted as if the user had explicitly opted into "no timeout" mode.

The fix is to use a fallback that would still fail the `< 0` check when the raw string is not a valid number, or to add an explicit `isFinite` guard:

```suggestion
      const timeout = toNumber(timeoutRaw, -1);
      // -1 fallback: non-numeric strings → -1 → caught by timeout < 0
      // 0 = no timeout (valid), negative = invalid
      if (timeout < 0) {
        errors.timeoutSeconds = "cron.errors.timeoutInvalid";
      }
```

Alternatively:
```ts
const timeout = toNumber(timeoutRaw, NaN);
if (!Number.isFinite(timeout) || timeout < 0) {
  errors.timeoutSeconds = "cron.errors.timeoutInvalid";
}
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: ui/src/ui/controllers/cron.ts
Line: 582-583

Comment:
**Payload builder also affected by non-numeric strings**

Even after fixing validation, the `buildCronPayload` path has the same implicit assumption: `toNumber(form.timeoutSeconds, 0)` returns `0` for any non-numeric input, and the condition `timeoutSeconds === 0 && form.timeoutSeconds.trim() !== ""` is `true` for strings like `"abc"`. If validation is hardened (as suggested above), this path will not be reached in the normal flow, but for robustness consider an explicit numeric-validity check here too:

```suggestion
  } else if (timeoutSeconds === 0 && form.timeoutSeconds.trim() !== "" && Number.isFinite(Number(form.timeoutSeconds.trim()))) {
    payload.timeoutSeconds = 0;
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: ui/src/ui/controllers/cron.test.ts
Line: 852-868

Comment:
**Test doesn't cover non-numeric input regression**

The new test only checks `"-5"` (rejected) and `"0"` (accepted), but misses the case where a non-numeric string like `"abc"` is entered. After the change from `<= 0` to `< 0`, non-numeric strings silently pass validation (see comment on `cron.ts:141`). A test for this case would catch the regression:

```ts
const errorsNonNumeric = validateCronForm({
  ...DEFAULT_CRON_FORM,
  payloadKind: "agentTurn",
  payloadText: "run",
  timeoutSeconds: "abc",
});
expect(errorsNonNumeric.timeoutSeconds).toBe("cron.errors.timeoutInvalid");
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: b3b97c9

Comment on lines 141 to 145
const timeout = toNumber(timeoutRaw, 0);
if (timeout <= 0) {
// 0 = no timeout (valid), negative = invalid
if (timeout < 0) {
errors.timeoutSeconds = "cron.errors.timeoutInvalid";
}

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.

Non-numeric strings now silently pass validation

Changing <= 0 to < 0 introduced a regression for non-numeric input. toNumber returns its fallback (0) for any non-parseable string, so toNumber("abc", 0) → 0. Previously 0 <= 0 was true, so garbage input triggered a validation error. Now 0 < 0 is false, meaning strings like "abc" or "foo" silently pass validation.

This then flows into buildCronPayload where the same toNumber("abc", 0) call returns 0, 0 === 0 && "abc" !== "" is true, and payload.timeoutSeconds = 0 is incorrectly emitted as if the user had explicitly opted into "no timeout" mode.

The fix is to use a fallback that would still fail the < 0 check when the raw string is not a valid number, or to add an explicit isFinite guard:

Suggested change
const timeout = toNumber(timeoutRaw, 0);
if (timeout <= 0) {
// 0 = no timeout (valid), negative = invalid
if (timeout < 0) {
errors.timeoutSeconds = "cron.errors.timeoutInvalid";
}
const timeout = toNumber(timeoutRaw, -1);
// -1 fallback: non-numeric strings → -1 → caught by timeout < 0
// 0 = no timeout (valid), negative = invalid
if (timeout < 0) {
errors.timeoutSeconds = "cron.errors.timeoutInvalid";
}

Alternatively:

const timeout = toNumber(timeoutRaw, NaN);
if (!Number.isFinite(timeout) || timeout < 0) {
  errors.timeoutSeconds = "cron.errors.timeoutInvalid";
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/ui/controllers/cron.ts
Line: 141-145

Comment:
**Non-numeric strings now silently pass validation**

Changing `<= 0` to `< 0` introduced a regression for non-numeric input. `toNumber` returns its fallback (`0`) for any non-parseable string, so `toNumber("abc", 0)` → `0`. Previously `0 <= 0` was `true`, so garbage input triggered a validation error. Now `0 < 0` is `false`, meaning strings like `"abc"` or `"foo"` silently pass validation.

This then flows into `buildCronPayload` where the same `toNumber("abc", 0)` call returns `0`, `0 === 0 && "abc" !== ""` is `true`, and `payload.timeoutSeconds = 0` is incorrectly emitted as if the user had explicitly opted into "no timeout" mode.

The fix is to use a fallback that would still fail the `< 0` check when the raw string is not a valid number, or to add an explicit `isFinite` guard:

```suggestion
      const timeout = toNumber(timeoutRaw, -1);
      // -1 fallback: non-numeric strings → -1 → caught by timeout < 0
      // 0 = no timeout (valid), negative = invalid
      if (timeout < 0) {
        errors.timeoutSeconds = "cron.errors.timeoutInvalid";
      }
```

Alternatively:
```ts
const timeout = toNumber(timeoutRaw, NaN);
if (!Number.isFinite(timeout) || timeout < 0) {
  errors.timeoutSeconds = "cron.errors.timeoutInvalid";
}
```

How can I resolve this? If you propose a fix, please make it concise.

Comment thread ui/src/ui/controllers/cron.ts Outdated
Comment on lines +582 to +583
} else if (timeoutSeconds === 0 && form.timeoutSeconds.trim() !== "") {
payload.timeoutSeconds = 0;

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.

Payload builder also affected by non-numeric strings

Even after fixing validation, the buildCronPayload path has the same implicit assumption: toNumber(form.timeoutSeconds, 0) returns 0 for any non-numeric input, and the condition timeoutSeconds === 0 && form.timeoutSeconds.trim() !== "" is true for strings like "abc". If validation is hardened (as suggested above), this path will not be reached in the normal flow, but for robustness consider an explicit numeric-validity check here too:

Suggested change
} else if (timeoutSeconds === 0 && form.timeoutSeconds.trim() !== "") {
payload.timeoutSeconds = 0;
} else if (timeoutSeconds === 0 && form.timeoutSeconds.trim() !== "" && Number.isFinite(Number(form.timeoutSeconds.trim()))) {
payload.timeoutSeconds = 0;
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/ui/controllers/cron.ts
Line: 582-583

Comment:
**Payload builder also affected by non-numeric strings**

Even after fixing validation, the `buildCronPayload` path has the same implicit assumption: `toNumber(form.timeoutSeconds, 0)` returns `0` for any non-numeric input, and the condition `timeoutSeconds === 0 && form.timeoutSeconds.trim() !== ""` is `true` for strings like `"abc"`. If validation is hardened (as suggested above), this path will not be reached in the normal flow, but for robustness consider an explicit numeric-validity check here too:

```suggestion
  } else if (timeoutSeconds === 0 && form.timeoutSeconds.trim() !== "" && Number.isFinite(Number(form.timeoutSeconds.trim()))) {
    payload.timeoutSeconds = 0;
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +852 to +868
it("rejects negative timeoutSeconds but allows zero (no-timeout mode)", () => {
const errorsNeg = validateCronForm({
...DEFAULT_CRON_FORM,
payloadKind: "agentTurn",
payloadText: "run",
timeoutSeconds: "-5",
});
expect(errorsNeg.timeoutSeconds).toBe("cron.errors.timeoutInvalid");

const errorsZero = validateCronForm({
...DEFAULT_CRON_FORM,
payloadKind: "agentTurn",
payloadText: "run",
timeoutSeconds: "0",
});
expect(errorsZero.timeoutSeconds).toBeUndefined();
});

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.

Test doesn't cover non-numeric input regression

The new test only checks "-5" (rejected) and "0" (accepted), but misses the case where a non-numeric string like "abc" is entered. After the change from <= 0 to < 0, non-numeric strings silently pass validation (see comment on cron.ts:141). A test for this case would catch the regression:

const errorsNonNumeric = validateCronForm({
  ...DEFAULT_CRON_FORM,
  payloadKind: "agentTurn",
  payloadText: "run",
  timeoutSeconds: "abc",
});
expect(errorsNonNumeric.timeoutSeconds).toBe("cron.errors.timeoutInvalid");
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/ui/controllers/cron.test.ts
Line: 852-868

Comment:
**Test doesn't cover non-numeric input regression**

The new test only checks `"-5"` (rejected) and `"0"` (accepted), but misses the case where a non-numeric string like `"abc"` is entered. After the change from `<= 0` to `< 0`, non-numeric strings silently pass validation (see comment on `cron.ts:141`). A test for this case would catch the regression:

```ts
const errorsNonNumeric = validateCronForm({
  ...DEFAULT_CRON_FORM,
  payloadKind: "agentTurn",
  payloadText: "run",
  timeoutSeconds: "abc",
});
expect(errorsNonNumeric.timeoutSeconds).toBe("cron.errors.timeoutInvalid");
```

How can I resolve this? If you propose a fix, please make it concise.

@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: 6866fc68a1

ℹ️ 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 ui/src/ui/controllers/cron.ts Outdated
Comment on lines +141 to +143
const timeout = toNumber(timeoutRaw, 0);
if (timeout <= 0) {
// 0 = no timeout (valid), negative = invalid
if (timeout < 0) {

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 Reject non-numeric timeout values in cron form

Fresh evidence in this commit: validateCronForm now only rejects values < 0, but it parses with toNumber(timeoutRaw, 0), so non-numeric input like "abc" becomes 0 and passes validation; then buildCronPayload's new timeoutSeconds === 0 && trim() !== "" branch serializes that invalid input as timeoutSeconds: 0 (no-timeout mode). This means a malformed timeout entered in the text field silently changes job behavior instead of surfacing cron.errors.timeoutInvalid.

Useful? React with 👍 / 👎.

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

ℹ️ 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 ui/src/ui/controllers/cron.ts Outdated
payload.timeoutSeconds = timeoutSeconds;
const timeoutRaw = form.timeoutSeconds.trim();
const timeoutSeconds = toNumber(timeoutRaw, 0);
if (!isNaN(Number(timeoutRaw)) && timeoutRaw !== "") {

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.

P2 Badge Reject non-finite timeout values in cron form

Fresh evidence in this commit: the new guard !isNaN(Number(timeoutRaw)) treats non-finite inputs like "Infinity" or "1e309" as valid numbers, while toNumber(timeoutRaw, 0) collapses them to 0. That means malformed timeout text can pass validation and then be serialized as timeoutSeconds: 0 (no-timeout mode) instead of raising cron.errors.timeoutInvalid, which silently changes cron job behavior from user-entered free-text input.

Useful? React with 👍 / 👎.

…nclaw#41272)

Change validation from `timeout <= 0` to `timeout < 0` so that 0 is
accepted as a valid value meaning "no timeout". Also update the payload
builder to include `timeoutSeconds: 0` when explicitly set by the user.

Co-authored-by: Copilot <[email protected]>
@Br1an67

Br1an67 commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing to manage active PR count. Will reopen when slot is available.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Cron job UI rejects timeoutSeconds: 0 (no-timeout mode)

1 participant