Skip to content

fix(cron): guard list sorting against malformed legacy jobs#28896

Merged
Takhoffman merged 2 commits intoopenclaw:mainfrom
Sid-Qin:fix/28862-cron-list-localecompare-guard
Mar 1, 2026
Merged

fix(cron): guard list sorting against malformed legacy jobs#28896
Takhoffman merged 2 commits intoopenclaw:mainfrom
Sid-Qin:fix/28862-cron-list-localecompare-guard

Conversation

@Sid-Qin
Copy link
Copy Markdown
Contributor

@Sid-Qin Sid-Qin commented Feb 27, 2026

Summary

  • Problem: Cron list APIs can throw TypeError: Cannot read properties of undefined (reading 'localeCompare') when legacy/corrupted records are missing name or id.
  • Why it matters: Users lose cron visibility in UI/CLI and cannot inspect or manage jobs after upgrade/data drift.
  • What changed: Hardened sortJobs in src/cron/service/ops.ts to safely normalize missing name/id before localeCompare; added regression tests in src/cron/service.list-page-sort-guards.test.ts.
  • What did NOT change: No behavior changes for valid jobs, no scheduling logic changes.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • cron.list/cron.listPage no longer crash on malformed entries missing name/id.
  • Listing returns stable output instead of throwing runtime errors.

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 26.3
  • Runtime: Node.js + pnpm test runner
  • Integration/channel: Cron service list/read ops

Steps

  1. Prepare cron in-memory/store data with missing name or missing id fields.
  2. Call list-page sorting by name or with tied sort requiring id tie-break.

Expected

  • List APIs return jobs without throwing.

Actual

  • Before fix: localeCompare could be called on undefined and throw.
  • After fix: sorting uses safe string fallbacks, no crash.

Evidence

  • Added regression tests:
    • src/cron/service.list-page-sort-guards.test.ts
  • Test run:
    • pnpm --dir /Users/sidqin/Desktop/openclaw-contrib exec vitest src/cron/service.list-page-sort-guards.test.ts
    • Result: 1 file passed, 2 tests passed.

Human Verification (required)

  • Verified scenarios:
    • Missing name does not break sortBy: "name".
    • Missing id does not break tie-break sorting path.
  • Edge cases checked:
    • Both malformed entries still return deterministic page results.
  • What I did not verify:
    • Full UI E2E list rendering against a live gateway instance.

Compatibility / Migration

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

Failure Recovery (if this breaks)

  • How to disable/revert: Revert this commit.
  • Files/config to restore: src/cron/service/ops.ts.
  • Known bad symptoms: Cron list operations may throw again on malformed data.

Risks and Mitigations

  • Risk: Fallback sorting for malformed records may group unnamed/unidentified jobs together.
  • Mitigation: Only affects invalid data; valid records keep existing ordering behavior.

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 27, 2026

Greptile Summary

Adds defensive guards to sortJobs in src/cron/service/ops.ts to prevent TypeError crashes when legacy or corrupted cron job records have missing name or id fields.

  • Wraps name and id comparisons with typeof x === "string" checks, defaulting to empty string for non-string values
  • Fixes crashes in cron.list and cron.listPage operations that could occur during name-based sorting (lines 167-169) or tie-break sorting by id (lines 188-190)
  • Adds regression tests in src/cron/service.list-page-sort-guards.test.ts covering both failure scenarios
  • No changes to sorting behavior for valid records

Confidence Score: 5/5

  • Safe to merge - minimal defensive fix with focused test coverage
  • Simple defensive guards that only affect malformed data; backward compatible with no behavior changes for valid jobs; comprehensive tests verify the fix prevents crashes in both name sorting and id tie-breaking scenarios
  • No files require special attention

Last reviewed commit: b59d759

@Takhoffman Takhoffman merged commit 29a5594 into openclaw:main Mar 1, 2026
27 checks passed
hwb96 pushed a commit to hwb96/openclaw that referenced this pull request Mar 1, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
zooqueen added a commit to hanzoai/bot that referenced this pull request Mar 1, 2026
ansh pushed a commit to vibecode/openclaw that referenced this pull request Mar 2, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
safzanpirani pushed a commit to safzanpirani/clawdbot that referenced this pull request Mar 2, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
robertchang-ga pushed a commit to robertchang-ga/openclaw that referenced this pull request Mar 2, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
hanqizheng pushed a commit to hanqizheng/openclaw that referenced this pull request Mar 2, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
execute008 pushed a commit to execute008/openclaw that referenced this pull request Mar 2, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
dorgonman pushed a commit to kanohorizonia/openclaw that referenced this pull request Mar 3, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
sachinkundu pushed a commit to sachinkundu/openclaw that referenced this pull request Mar 6, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
zooqueen added a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
Mateljan1 pushed a commit to Mateljan1/openclaw that referenced this pull request Mar 7, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 16, 2026
…#28896)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------

Co-authored-by: Tak Hoffman <[email protected]>
(cherry picked from commit 29a5594)
alexey-pelykh added a commit to remoteclaw/remoteclaw that referenced this pull request Mar 16, 2026
…#28896) (#1518)

* fix(cron): guard list sorting against malformed legacy jobs

Prevent list operations from crashing when old or corrupted cron entries are missing name/id fields by hardening sort comparators.

Closes openclaw#28862

* cron: format list sort guard test imports

---------


(cherry picked from commit 29a5594)

Co-authored-by: Sid <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
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 not able to use anymore

2 participants