Repository navigation
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ebcbb7055
ℹ️ 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".
Greptile SummaryThis PR adds an optional Key issues found:
Confidence Score: 4/5
|
5ebcbb7 to
5463c8f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5463c8fd88
ℹ️ 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: 6858cd2740
ℹ️ 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".
…nce delegate The server-cron.ts production delegate was calling runHeartbeatOnce without forwarding opts.abortSignal, so the cron job timeout signal never reached the heartbeat pre-hook shell process. Side-effecting hooks could outlive a timed- out cron job until their own preHook.timeoutSeconds expired.
0d20dd8 to
bd3ce00
Compare
|
closing this in favor of #54239. same preHook work, same author, and this branch currently has no diff to review. if you want this PR kept instead, say so and we can swap the canonical ref. |
Reopening #49415 with a clean rebase onto main (previous branch was closed by the bot due to unrelated commits picked up during merge).
Closes #49370
Summary
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 using platform shell (cmd.exe /con Windows,/bin/sh -celsewhere), configurable timeout (default 30s, max 300s), stdout/stderr capture (64 KB cap), AbortSignal supportsrc/cron/types-shared.ts: addpreHooktoCronJobBase;CronJobPatchre-declares it asobject | nullto allow explicit clearingsrc/config/types.agent-defaults.ts: addpreHookto heartbeat config blocksrc/config/zod-schema.agent-runtime.ts: addpreHooktoHeartbeatSchemawithz.string().trim().min(1)command validationsrc/cron/service/timer.ts: preHook gate inexecuteJobCore()before abort signal check; passes AbortSignal throughsrc/cron/service/jobs.ts: persistpreHookincreateJob()andapplyJobPatch()src/infra/heartbeat-runner.ts: preHook gate inrunHeartbeatOnce()with AbortSignal forwarding; falls back to default config preHook when override omits itsrc/cron/normalize.ts: normalize preHook (trim command, clamp timeoutSeconds 1–300, null clears for patch, delete for create); rejects malformed patch objects (missing/non-string command returns error instead of silently clearing)src/agents/tools/cron-tool.ts: addpreHookto allowed keys for add/update actionssrc/gateway/protocol/schema/cron.ts: addpreHooktoCronAddParamsSchema,CronJobPatchSchema(null allowed for patch), andCronJobSchemadocs/automation/cron-jobs.md,docs/gateway/heartbeat.md: documentationTests
src/cron/pre-hook.test.ts: exit 0/10/1/42, timeout, AbortSignal kill, maxBuffer handling, portablenode -ecommandssrc/cron/normalize.test.ts: valid passthrough, empty/whitespace command, timeoutSeconds clamping, null for patch, malformed patch object rejectionTest plan
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 count incrementpreHook: { command: "exit 1" }→ job blocked,consecutiveErrorsincrements