Repository navigation
Conversation
Greptile SummaryThis PR adds an optional Two issues were found:
Confidence Score: 3/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/cron/normalize.ts
Line: 423-425
Comment:
**`null` is dropped instead of preserved — patch will never clear `preHook`**
When `preHook: null` is passed in a patch, the normalization silently removes the key from the output (`delete next.preHook`) rather than keeping an explicit `null`. Downstream patch logic typically only touches fields that are present in the patch object; because the key is absent, the stored `preHook` will never be cleared.
Compare to how `agentId: null` is handled just a few lines above (line 328–330), where the code explicitly does `next.agentId = null` to preserve the clear-signal:
```typescript
} else if (base.preHook === null || base.preHook === undefined) {
delete next.preHook; // ← drops the key; patch won't touch the stored value
}
```
The documentation says _"Set `preHook` to `null` in a patch to remove it from an existing job"_, but this normalization makes that impossible. The fix is to mirror the `agentId` pattern:
```suggestion
} else if (base.preHook === null) {
next.preHook = null;
} else if (base.preHook === undefined) {
delete next.preHook;
}
```
The `normalize.test.ts` assertion `expect("preHook" in normalized).toBe(false)` would also need updating to `expect(normalized.preHook).toBeNull()`.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/cron/pre-hook.ts
Line: 17-18
Comment:
**No upper bound on `timeoutSeconds`**
The normalization in `normalize.ts` clamps `timeoutSeconds` to a minimum of 1 but imposes no maximum. A user (or an agent via the cron tool) could configure `timeoutSeconds: 86400` (24 hours), blocking the cron executor thread for a full day before the hook times out.
Consider adding a reasonable cap (e.g., 300 s) both in `normalize.ts` and as a constant here:
```typescript
export const MAX_PRE_HOOK_TIMEOUT_SECONDS = 300;
const timeoutMs = Math.min(
config.timeoutSeconds ?? DEFAULT_PRE_HOOK_TIMEOUT_SECONDS,
MAX_PRE_HOOK_TIMEOUT_SECONDS,
) * 1000;
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/cron/pre-hook.ts
Line: 36
Comment:
**`ETIMEDOUT` string check is dead code for `execFile` timeouts**
When `execFile` fires its `timeout`, Node.js kills the child and sets `error.killed = true`. The `code` property on an `ExecException` carries the numeric process exit code (or `null` when killed), never the string `"ETIMEDOUT"`. Casting to `NodeJS.ErrnoException` and comparing `.code === "ETIMEDOUT"` will never be true for a subprocess-timeout scenario — the `error.killed` branch already handles it exclusively.
The only real case for `"ETIMEDOUT"` would be a network-level errno, which `execFile` doesn't surface. The second condition can be safely removed to reduce confusion:
```suggestion
if (error.killed) {
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: "Cron/Heartbeat: add ..." |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4b37733b21
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8e16f69d5
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6e7c6a25d3
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e228fdff41
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 954b916bd4
ℹ️ 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".
37568da to
4e38764
Compare
|
If someone has the time to review this, please let me know what you would like me to change, so I can get this feature upstreamed. Going forward I need this or a similar feature to continue using openclaw. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b8bfe6930
ℹ️ 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".
b096d7c to
c726aaf
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c726aaf898
ℹ️ 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".
c726aaf to
d7f8465
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7f8465e8a
ℹ️ 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".
8a9553f to
ddf357d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ddf357d00a
ℹ️ 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".
1186a4d to
7b7245a
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. |
23 similar comments
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01c1a793e4
ℹ️ 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".
| const preHookConfig = heartbeat?.preHook ?? resolvedHb?.preHook; | ||
| if (preHookConfig?.command) { | ||
| const { runPreHook } = await import("../cron/pre-hook.js"); | ||
| const hookResult = await runPreHook(preHookConfig, opts.abortSignal); |
There was a problem hiding this comment.
Propagate cron abort signal into wake-now heartbeat runs
runHeartbeatOnce now accepts opts.abortSignal and passes it to runPreHook, but cron wake-now execution still does not provide that signal, so heartbeat pre-hook subprocesses can continue after a cron timeout. This leaves side-effecting commands running in the background while the cron run is already marked failed/timed out. Fresh evidence: in this commit, executeJobCore still calls state.deps.runHeartbeatOnce({ ... heartbeat: { target: "last" } }) without abortSignal in src/cron/service/timer.ts, so opts.abortSignal here is undefined for that path.
Useful? React with 👍 / 👎.
Summary
Closes #49370
Operators running OpenClaw on resource-constrained hosts (Raspberry Pi, shared VMs, metered cloud instances) currently have no native way to gate cron or heartbeat agent runs on system preconditions — things like checking disk space, network reachability, API availability, or whether a dependent service is healthy. Everyone ends up rebuilding custom wrapper logic independently outside of OpenClaw, which is fragile and hard to maintain.
This PR adds an optional
preHookconfig for cron jobs and heartbeats that runs a shell command before agent execution, using exit codes to decide whether to proceed, skip, or abort.consecutiveErrorsstays 0)The timeout is capped at 300s to prevent blocking the executor thread.
Changes
src/cron/pre-hook.ts: sharedrunPreHook()function usingchild_process.execFilewith/bin/sh -c, configurable timeout (default 30s, max 300s), stdout/stderr capture (capped at 64 KB)src/cron/types-shared.ts: addpreHookfield toCronJobBase(flows toCronJob,CronJobCreate,CronJobPatch)src/config/types.agent-defaults.ts: addpreHookto the heartbeat config blocksrc/config/zod-schema.agent-runtime.ts: addpreHooktoHeartbeatSchemafor config validationsrc/cron/service/timer.ts: insert preHook gate at top ofexecuteJobCore(), before abort signal checksrc/cron/service/jobs.ts: persistpreHookincreateJob()andapplyJobPatch()src/infra/heartbeat-runner.ts: insert preHook gate inrunHeartbeatOnce()after cheap guards (disabled, active hours, queue size) but before preflightsrc/cron/normalize.ts: normalize preHook input (trim command, clamp timeoutSeconds 1-300, null clears)src/agents/tools/cron-tool.ts: addpreHookto allowed keys for add and update actionssrc/gateway/protocol/schema/cron.ts: addpreHooktoCronAddParamsSchemaandCronJobPatchSchemadocs/automation/cron-jobs.md: new "Pre-run hooks" section with config shape, exit code contract, examplesdocs/gateway/heartbeat.md: add preHook to example config and new sectionTests
src/cron/pre-hook.test.ts: unit tests (exit 0/10/1/42, timeout, stdout/stderr capture)src/cron/normalize.test.ts: normalization tests (valid passthrough, empty command clears, timeoutSeconds clamped, null preserves as null for patch clearing)Test plan
pnpm tsgopasses (pre-existing errors onmainunrelated to this PR)pnpm test -- src/cron/pre-hook.test.tspassespnpm test -- src/cron/normalize.test.tspassespreHook: { command: "exit 0" }→ job runs normallypreHook: { command: "exit 10" }→ job skipped, no error incrementpreHook: { command: "exit 1" }→ job errors, consecutiveErrors incrementscc @steipete @vincentkoc @BunsDev for review