Repository navigation
Conversation
Additional Comments (2)
You need to add Prompt To Fix With AIThis is a comment left during a code review.
Path: src/cron/service/jobs.ts
Line: 253:270
Comment:
**`preCheck` is silently dropped on job creation**
`createJob` constructs the `CronJob` object with an explicit field listing and does not include `preCheck: input.preCheck`. Since `CronJobCreate` inherits the `preCheck?: CronPreCheck` field from `CronJob`, any `preCheck` passed during job creation will be silently discarded. The job will be created without a pre-check gate, even though the user specified one.
You need to add `preCheck` to the object literal:
```suggestion
const job: CronJob = {
id,
agentId: normalizeOptionalAgentId(input.agentId),
name: normalizeRequiredName(input.name),
description: normalizeOptionalText(input.description),
enabled,
deleteAfterRun,
createdAtMs: now,
updatedAtMs: now,
schedule,
sessionTarget: input.sessionTarget,
wakeMode: input.wakeMode,
payload: input.payload,
preCheck: input.preCheck,
delivery: input.delivery,
state: {
...input.state,
},
};
```
How can I resolve this? If you propose a fix, please make it concise.
This means users cannot update or remove a pre-check gate on an existing job via patch. You need to add handling for Prompt To Fix With AIThis is a comment left during a code review.
Path: src/cron/service/jobs.ts
Line: 277:327
Comment:
**`preCheck` is not handled in `applyJobPatch`**
`applyJobPatch` handles patching of `name`, `description`, `enabled`, `deleteAfterRun`, `schedule`, `sessionTarget`, `wakeMode`, `payload`, `delivery`, `state`, and `agentId` — but not `preCheck`. The `CronJobPatch` type now includes `preCheck?: CronPreCheckPatch | null`, and `normalize.ts` already normalizes it (including `null` for explicit removal), but this function never applies it.
This means users cannot update or remove a pre-check gate on an existing job via patch. You need to add handling for `preCheck`, for example:
```
if ("preCheck" in patch) {
if (patch.preCheck === null) {
job.preCheck = undefined;
} else if (patch.preCheck) {
job.preCheck = { ...job.preCheck, ...patch.preCheck } as CronPreCheck;
}
}
```
How can I resolve this? If you propose a fix, please make it concise. |
|
📋 Discussion: https://github.com/openclaw/openclaw/discussions/17553 Per CONTRIBUTING.md, opened a Discussion for this feature proposal. Happy to adjust the API surface, naming, or approach based on maintainer feedback. Recent updates (addressing Greptile review):
This aligns with the "Optimizing token usage" priority from the roadmap. |
|
Addressed all feedback: Greptile review (commit 2):
Windows CI (commit 4):
All 17 tests passing on Linux, should now pass Windows CI too. |
|
@greptile-apps All identified issues in \ have been addressed in recent commits:
|
d455ff3 to
063e2be
Compare
Update: All Greptile Concerns Addressed ✅Greptile Review Issues Fixed:
Additional Improvements:
Current CI Status:
This feature directly aligns with OpenClaw's roadmap priority: "Optimizing token usage". Ready for review and merge. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
This pull request has been automatically marked as stale due to inactivity. |
063e2be to
c5057aa
Compare
|
clawmander
left a comment
There was a problem hiding this comment.
Resolved the dynamic import review thread.
|
Let me know what changes should be made to get this feature added into openclaw. This has been my biggest grievance with openclaw, that it unnecessarily uses tokens on no-ops, when a gating script could prevent this waste. |
Remaining CI fixesSecond-pass CI sweep complete. Fixed two failures: 1. Format drift (
|
|
Any follow up on this PR? |
7a20c2b to
a2e8294
Compare
|
Closing this PR because it looks dirty (too many unrelated or unexpected changes). This usually happens when a branch picks up unrelated commits or a merge went sideways. Please recreate the PR from a clean branch. |
Problem
Recurring cron jobs wake an agent every N minutes even when there's nothing to act on. This wastes tokens on "nothing new" /
HEARTBEAT_OKresponses. Users currently have no way to gate a cron job on a lightweight condition check — every scheduled tick triggers a full agent turn.Real-world example: A cron job that reviews open PRs every 30 minutes. If there are no open PRs, it still spends tokens asking the agent to check and getting "no PRs to review" back.
Solution
Add an optional
preCheckfield to cron jobs: a lightweight shell command that runs before the agent turn. If the command fails or returns empty output, the job is skipped entirely — no tokens spent.How it works
skipped)preCheck fields
commandtimeoutSecondsoutputMode"prepend"|"replace"|"ignore""prepend"Output modes
[Pre-check context]Use cases
gh pr list)grep -c ERROR log | awk '$1>0')Implementation
src/cron/types.ts—CronPreChecktype, added toCronJobandCronJobPatchsrc/cron/pre-check.ts—runPreCheck()executor andapplyPreCheckOutput()helpersrc/cron/service/timer.ts— Integrated gate intoexecuteJobCore()src/cron/service/jobs.ts— Wired preCheck into create and patch logicsrc/cron/normalize.ts— preCheck field normalizationdocs/automation/cron-jobs.md— Added 'Pre-check gate' section with examplesTesting
preCheckare unaffectedNotes
--pre-check,--pre-check-timeout,--pre-check-output) not included in this PR to keep scope focused; can add in a follow-upGreptile Summary
Adds an optional
preCheckgate to cron jobs — a lightweight shell command that runs before the agent turn and skips the job (saving tokens) when the command fails or returns empty output. The implementation cleanly threads through the existing cron architecture: types, normalization, create/patch, and bothmainandisolatedexecution paths. Tests cover core pre-check behavior and patch lifecycle.src/cron/pre-check.ts— TherunPreCheckfunction is missing asettledguard flag that exists in the codebase's established pattern (src/process/exec.ts:146-179). WhenmaxBufferis exceeded, Node.jsexec()emits botherrorandcloseevents, causingresolve()to be called twice.src/cron/service/timer.ts— Usesawait import("node:path")dynamically insideexecuteJobCoreon every job tick; should be a static top-level import.Confidence Score: 3/5
settledguard in the pre-check executor to prevent double-resolution edge cases.settledguard inrunPreCheckis a real (though low-probability) correctness issue whenmaxBufferis exceeded, and should be fixed before merge to match the codebase's established pattern. The dynamic import is a minor style issue.src/cron/pre-check.tsneeds asettledguard to prevent double-resolution whenerrorandcloseboth fire.Last reviewed commit: 063e2be