Skip to content

cron/heartbeat: add preHook gate for pre-run script checks - #54239

Closed
scottgl9 wants to merge 17 commits into
openclaw:mainfrom
scottgl9:scottgl9/pre-hook-gate-v2
Closed

scottgl9 wants to merge 17 commits into
openclaw:mainfrom
scottgl9:scottgl9/pre-hook-gate-v2

Conversation

@scottgl9

Copy link
Copy Markdown
Contributor

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 preHook field to cron job and heartbeat configs. When set, OpenClaw runs the specified shell command before launching the agent. If the command exits non-zero, the run is skipped (not failed) and a reason is logged. If it exits 0, the run proceeds normally.

What's changed

  • src/cron/pre-hook.ts — core preHook runner (exec, timeout, skip-on-failure)
  • src/cron/pre-hook.test.ts — unit tests
  • src/cron/normalize.ts — normalization + validation for preHook input; rejects malformed objects (missing/non-string command)
  • src/cron/normalize.test.ts — normalize tests
  • src/cron/types.ts / types-shared.ts — type definitions
  • src/cron/service/jobs.ts / timer.ts — integrate preHook into job execution pipeline
  • src/config/zod-schema.agent-runtime.ts — zod schema with .trim().min(1) on command
  • src/config/types.agent-defaults.ts — TypeScript types
  • src/agents/tools/cron-tool.ts — expose preHook in cron tool schema
  • src/gateway/protocol/schema/cron.ts — protocol schema
  • src/infra/heartbeat-runner.ts — preHook support for heartbeat runs
  • apps/macos/ / apps/shared/ — GatewayModels.swift updated
  • docs/ — config reference, cron-jobs.md, heartbeat.md, config-baseline.json/jsonl

Example usage

{
  "schedule": "cron 0 8 * * 1-5",
  "preHook": {
    "command": "ping -c1 -W2 api.openai.com > /dev/null 2>&1",
    "timeoutSeconds": 10
  }
}

If the ping fails (e.g. no internet), the cron run is skipped with a log entry. No agent spin-up, no wasted tokens.

Clean branch note

This is a clean rebase of #49415 (which was closed by the bot due to unrelated commits on the branch). All changes here are strictly related to the preHook feature.

@scottgl9
scottgl9 requested a review from a team as a code owner March 25, 2026 04:47
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling size: M labels Mar 25, 2026
@greptile-apps

greptile-apps Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds an optional preHook field to cron job and heartbeat configs that runs a shell command before each scheduled execution. Exit code 0 proceeds, exit code 10 skips (no error recorded), and any other non-zero exit or timeout is treated as an error (which feeds into the normal cron backoff/alerting pipeline). The implementation is thorough: a cross-platform execFile-based runner with timeout, maxBuffer handling, AbortSignal forwarding from job timeouts, and proper gateway/protocol schema validation.

Key issues found:

  • Silent safety-gate bypass in src/cron/normalize.ts: The preHook normalization block handles isRecord, null, and undefined, but has no else branch for other primitive types (strings, numbers, booleans). A value like preHook: "ping ..." would pass through unchanged, get stored as a string, and then silently never execute — because timer.ts checks job.preHook?.command, which is undefined on a string. Operators who configure a preHook with a string value would believe they have a safety gate that is actually inactive, with no warning. A malformed object (missing/non-string command) correctly returns null today; primitives should receive the same treatment or at minimum be deleted.

  • Skip/error log context lacks hook output (src/cron/service/timer.ts, src/infra/heartbeat-runner.ts): When a pre-hook returns "skip" or "error", the captured stdout/stderr from the subprocess are available on hookResult but not included in the structured log fields. Since pre-hook scripts are typically small diagnostic commands, their output is usually the most actionable debugging signal — operators trying to understand why a run was skipped would benefit from seeing it logged.

  • normalize.test.ts has no test for primitive preHook values, which corresponds to the above normalization gap.

Confidence Score: 4/5

  • Safe to merge after fixing the normalize.ts primitive-passthrough gap; all other concerns are non-blocking style improvements.
  • The core pre-hook runner, timer integration, heartbeat integration, schema definitions, and tests are all well-implemented. One concrete logic bug exists in normalizeCronJobInput where non-object, non-null preHook primitives bypass all normalization branches and are silently stored as invalid data, potentially disabling the safety gate without any error. This is a one-liner fix (add an else branch) but has meaningful correctness implications for the feature's stated purpose. All other issues are style/debuggability improvements.
  • src/cron/normalize.ts — missing else branch for primitive preHook values; src/cron/normalize.test.ts — companion test case needed
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/cron/service/timer.ts
Line: 1044-1054

Comment:
**Hook stdout/stderr absent from log context on skip/error**

When a pre-hook returns `"skip"` or `"error"`, the `stdout` and `stderr` captured from the process are available on `hookResult` but are not included in the log messages. This makes it difficult for operators to diagnose *why* the hook decided to skip (e.g., a failing `ping`, a missing file check, a disk-space threshold message), especially since those scripts are often the first thing they'd look at.

Suggest including both fields in the structured log context:

```ts
if (hookResult.outcome === "skip") {
  state.deps.log.info(
    { jobId: job.id, jobName: job.name, stdout: hookResult.stdout, stderr: hookResult.stderr },
    "cron: pre-hook returned skip",
  );
  return { status: "skipped", error: "pre-hook: skipped" };
}
if (hookResult.outcome === "error") {
  state.deps.log.warn(
    { jobId: job.id, exitCode: hookResult.exitCode, stdout: hookResult.stdout, stderr: hookResult.stderr },
    `cron: pre-hook failed: ${hookResult.message}`,
  );
  return { status: "error", error: `pre-hook: ${hookResult.message}` };
}
```

The same applies in `src/infra/heartbeat-runner.ts` at the analogous block (lines ~569–576), where the current log lines carry no structured context at all.

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/normalize.ts
Line: 410-446

Comment:
**Primitive `preHook` values bypass validation and silently disable the gate**

The `preHook` normalization block covers `isRecord`, `=== null`, and `=== undefined`, but has no `else` branch. When `"preHook" in base` is true and the value is a primitive (e.g., a string), the spread value from `next = { ...base }` is left untouched — `next.preHook` becomes that invalid primitive.

Downstream, in `createJob`:
```ts
preHook: input.preHook ?? undefined,
```
…the truthy string is stored as-is in the job. Then in `timer.ts`:
```ts
if (job.preHook?.command) { … }
```
Accessing `.command` on a string yields `undefined`, so the check is falsy and the pre-hook **never executes** — silently. An operator writing `preHook: "ping ..."` as a string instead of `preHook: { command: "ping ..." }` believes the safety gate is active but it isn't, with no warning.

Note: a malformed *object* (lines 412-415, missing/non-string `command`) already correctly returns `null`. A primitive value deserves the same protection. Add an `else` branch to delete the invalid field (matching the pattern used for other invalid optional fields throughout this file):

```suggestion
  // Pre-hook normalization
  if ("preHook" in base) {
    if (isRecord(base.preHook)) {
      if (typeof base.preHook.command !== "string") {
        // Reject malformed preHook objects — missing/non-string command must not
        // be silently coerced to "" (which would clear an existing hook in patch mode).
        return null;
      }
      const command = base.preHook.command.trim();
      if (command) {
        const normalized: UnknownRecord = { command };
        if (
          typeof base.preHook.timeoutSeconds === "number" &&
          Number.isFinite(base.preHook.timeoutSeconds)
        ) {
          normalized.timeoutSeconds = Math.min(
            300,
            Math.max(1, Math.floor(base.preHook.timeoutSeconds)),
          );
        }
        next.preHook = normalized;
      } else {
        // Empty command clears the hook.
        // For create (applyDefaults=true): use delete
        // For patch (applyDefaults=false): use null so applyJobPatch sees the key and clears the existing hook.
        if (options.applyDefaults) {
          delete next.preHook;
        } else {
          next.preHook = null;
        }
      }
    } else if (base.preHook === null) {
      // Explicit null from a patch clears the hook.
      next.preHook = null;
    } else if (base.preHook === undefined) {
      delete next.preHook;
    } else {
      // Non-object, non-null, non-undefined (e.g. a bare string or number) — drop it to
      // avoid storing an invalid value. Treat the same as a missing field.
      delete next.preHook;
    }
  }
```

A companion test in `normalize.test.ts` would also be valuable to guard this path.

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

Reviews (1): Last reviewed commit: "fixup: trim command in zod schema; rejec..." | Re-trigger Greptile

Comment thread src/cron/service/timer.ts Resolved
Comment thread src/cron/normalize.ts Resolved

@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: 4154ef65cb

ℹ️ 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".

Comment thread docs/.generated/config-baseline.jsonl Resolved
Comment thread src/infra/heartbeat-runner.ts Resolved
@scottgl9
scottgl9 force-pushed the scottgl9/pre-hook-gate-v2 branch from 4154ef6 to d3f2624 Compare March 26, 2026 04:20

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

ℹ️ 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".

Comment thread src/cron/pre-hook.ts Resolved
Comment thread src/infra/heartbeat-runner.ts Resolved

@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: 8bc78b4c79

ℹ️ 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".

Comment thread src/infra/heartbeat-runner.ts Resolved
@scottgl9

Copy link
Copy Markdown
Contributor Author

Could someone please look into my proposal?

@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: 61eced56fd

ℹ️ 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".

Comment thread src/cron/service/timer.ts Resolved
@scottgl9
scottgl9 force-pushed the scottgl9/pre-hook-gate-v2 branch from c05702c to 79d854b Compare April 3, 2026 20:27

@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

https://github.com/openclaw/openclaw/blob/79d854b0676e012995e86757cc200ebaed716186/src/agents/tools/cron-tool.ts#L561
P2 Badge Recover preHook in flattened cron job params

The flat-params recovery block for cron.add still filters keys through CRON_RECOVERABLE_OBJECT_KEYS, which does not include preHook, so a top-level preHook from flattened tool calls is silently dropped and the created job runs without its intended gate. This directly affects the non-frontier fallback path this code is meant to support (the same pattern is repeated in the cron.update recovery loop), so users can believe they configured preHook when it was actually discarded.

ℹ️ 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".

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

ℹ️ 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".

Comment thread src/agents/tools/cron-tool.ts Resolved
Comment thread src/agents/tools/cron-tool.ts Resolved
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed agents Agent runtime and tooling size: L labels Apr 3, 2026

@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: 708f7c6268

ℹ️ 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".

Comment thread src/cron/service/timer.ts Resolved
@openclaw-barnacle openclaw-barnacle Bot added size: L agents Agent runtime and tooling and removed size: M labels Apr 3, 2026
@scottgl9
scottgl9 force-pushed the scottgl9/pre-hook-gate-v2 branch from f03392b to 9e66ca4 Compare April 3, 2026 23:27

@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: 9e66ca4e98

ℹ️ 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".

Comment thread docs/gateway/configuration-reference.md Resolved
@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Apr 3, 2026
@scottgl9
scottgl9 force-pushed the scottgl9/pre-hook-gate-v2 branch from 6cc8e12 to 7977b73 Compare April 4, 2026 15:55

@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: 7977b73e03

ℹ️ 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".

Comment thread docs/gateway/configuration-reference.md Resolved
@scottgl9

scottgl9 commented Apr 4, 2026

Copy link
Copy Markdown
Contributor Author

CI Status Update

All review threads are now resolved. Here is a summary of current CI:

✅ Passing (new in this run)

  • android tests: all pass
  • build-artifacts, build-smoke, check, check-docs, checks-fast-bundled, security-fast

❌ Still Failing — Pre-existing on main (not caused by this PR)

These same checks fail on the most recent merged PRs (e.g. #60918 merged today off main):

Check Root cause
check-additional / lint:plugins:plugin-sdk-subpaths-exported openclaw/plugin-sdk/secret-input-runtime not in package exports — pre-existing on main
extension-fast (synology-chat) / checks-fast-extensions-shard-* createSubsystemLogger is not a function in ollama extension — pre-existing on main
checks-fast-contracts-protocol missing bundled channel plugin: slack — pre-existing on main
checks-node-channels Same ollama/slack import chain failures — pre-existing on main

This PR's own changes are clean: pnpm check passes, cron/pre-hook/normalize/heartbeat tests all pass, and no regressions were introduced.

scottgl9 added 16 commits April 6, 2026 16:55
Add a preHook config to cron jobs and heartbeat that runs a shell script
before the agent turn. If the script exits non-zero, the run is skipped.
This enables lightweight pre-flight checks (e.g. are there new emails?)
without waking an LLM agent.

Changes:
- Add preHook config to cron job schema and heartbeat config
- Wire preHook execution into cron isolated runner and heartbeat scheduler
- Wire abort signal into pre-hook subprocess
- Handle maxBuffer overrun as error to preserve non-zero exit codes
- Support Windows shell (cmd.exe) and Unix shells
- Allow null preHook in CronJobPatch type for clearing via cron.update
- Add Zod schema validation for preHook fields
- Add tests for pre-hook gating behavior
…reHook after preflight

- pre-hook.ts: undefined exit status on maxBuffer now resolves as 'error' instead
  of 'skip' — prevents broken hooks that print >64KB from being silently masked
  as intentional skips, suppressing error/backoff/failure-alert behavior.

- heartbeat-runner.ts: moved preHook execution to after resolveHeartbeatPreflight
  so the shell command only runs for heartbeats that will actually proceed.
  Previously the hook ran before preflight, causing side effects for runs that
  preflight would skip (e.g. empty-heartbeat-file).
Without emitHeartbeatEvent, a heartbeat blocked by preHook never updated
system.last-heartbeat or event subscribers. Monitoring surfaces would show
stale state when preHook starts failing in production. Now emits a skipped
or failed event (with reason and durationMs) before each early return.
- pre-hook.ts: use exitCode: -1 instead of undefined for unknown maxBuffer
  exit status (PreHookResult type requires exitCode: number)
- state.ts: add abortSignal?: AbortSignal to runHeartbeatOnce opts type
- heartbeat-runner.ts: fix log.info/warn call signature (message first,
  meta second — subsystem logger is not pino-style)
- schema.base.generated.ts: regenerate stale output (new preHook fields)
…on.ts

The runHeartbeatOnce call in the CronServiceDeps adapter was not forwarding
opts.abortSignal to runHeartbeatOnce, so in wakeMode=now runs with a heartbeat
preHook, a cron job timeout would not cancel the pre-hook shell process — it
would continue running until its own timeout even after the cron job was already
marked timed out.

Fix: pass abortSignal: opts?.abortSignal to the runHeartbeatOnce call.
…beatNow call

requestHeartbeatNow opts type only supports { reason, agentId, sessionKey }.
The heartbeat.target and abortSignal properties were passed here but not
defined in the type. Since requestHeartbeatNow is fire-and-forget (void),
the heartbeat.target override belongs only on the runHeartbeatOnce path
where it already exists correctly (~line 1210).
…-tool.ts

These constants were declared but never used — the recovery loop uses
CRON_RECOVERABLE_OBJECT_KEYS instead. oxlint 1.58+ correctly flags them
as unused variables. Removing the dead declarations.
…efore pre-hook launch

- Add 'preHook' to CRON_RECOVERABLE_OBJECT_KEYS so flat-param recovery in both
  cron.add and cron.update correctly forwards preHook when models omit the job/patch
  wrapper object. Without this, a top-level preHook field was silently dropped,
  creating an ungated job instead of one with the pre-run check.

- Add abortSignal check before the pre-hook gate in executeJobCore so that an
  already-cancelled job does not launch the pre-hook shell command. Previously,
  a timed-out run could start the subprocess after cancellation had already fired.
…nnectionDetails mock

Parameters<> for a function with a default parameter resolves to [] in newer
tsgo, causing 'Expected 0 arguments, but got 1' when spreading. Cast via any[]
to preserve the pass-through mock behavior without the false tsgo error.
Both the heartbeat and cron preHook descriptions incorrectly stated that
any non-zero exit skips the run. The actual behavior (per PRE_HOOK_SKIP_EXIT_CODE=10
in src/cron/pre-hook.ts) is:
- Exit code 10 → skip (heartbeat/cron run is skipped)
- Any other non-zero → error (heartbeat still fires; cron job is marked failed)

Updated both occurrences in configuration-reference.md to match the implementation.
@scottgl9
scottgl9 force-pushed the scottgl9/pre-hook-gate-v2 branch from 9d3069c to 087249c Compare April 6, 2026 21:56

@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: 087249c62c

ℹ️ 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".

Comment thread src/agents/tools/cron-tool.ts Resolved
preHook was added to CRON_RECOVERABLE_OBJECT_KEYS for flat-argument
recovery but was absent from CronJobObjectSchema (add) and
CronPatchObjectSchema (update). Tool-calling models had no schema
signal to generate the field, making preHook effectively hidden.

- CronJobObjectSchema: preHook as optional Type.Object (command, timeoutSeconds)
- CronPatchObjectSchema: preHook as Type.Unsafe<...| false> with clear-sentinel
  description, mirroring the failureAlert pattern
- cron-tool.schema.test.ts: updated field snapshots for both job and patch

Fixes PRRT_kwDOQb6kR855It1h.

@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: 0d5b735208

ℹ️ 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".

Comment thread src/cron/normalize.ts
Comment on lines +525 to +527
} else {
// Non-object, non-null, non-undefined (e.g. a bare string or number) — drop it.
delete next.preHook;

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 Preserve preHook clear sentinel during patch normalization

The new cron.update tool schema describes preHook: false as the way to clear an existing hook (src/agents/tools/cron-tool.ts), but this normalization branch drops every non-object/non-null preHook value. When a tool caller follows that contract and sends false, the field is removed from the patch instead of being converted to a clear operation, so the stored preHook remains active and continues blocking runs unexpectedly. Please map this sentinel to null (clear) rather than deleting it.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Closing this as duplicate or superseded after Codex automated review.

PR #54239 is an older v2 implementation of cron/heartbeat preHook support and is superseded by the newer open PR #62195, which tracks the same feature and explicitly carries forward review feedback from #54239. Current main does not yet implement preHook, so this should close as superseded rather than implemented.

Best possible solution:

Close #54239 as superseded and continue review on #62195, the newer open v3 PR for the same cron/heartbeat preHook feature. Do not treat this as implemented until the canonical PR or another implementation lands on main.

What I checked:

So I’m closing this here and keeping the remaining discussion on the canonical linked item.

Codex Review notes: model gpt-5.5, reasoning high; reviewed against 06d409dc2738.

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

Labels

agents Agent runtime and tooling app: macos App: macos app: web-ui App: web-ui cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: pre-run script hook/gate for heartbeat and cron agent triggers

1 participant