Skip to content

fix(cron): deliver and record primary webhook outcomes - #117783

Merged
steipete merged 2 commits into
mainfrom
codex/fix-cron-webhook-command-jobs
Aug 2, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/fix-cron-webhook-command-jobs

Conversation

@steipete

@steipete steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cron jobs configured with --webhook could complete successfully, produce their payload, deliver nothing, and record deliveryStatus: "unknown" — a silent failure indistinguishable from success in run history.

Reproduced on the production team host (dist 120fa5d): a command job with a webhook target fired twice on schedule, both runs status: ok with the payload in summary, zero POSTs observed, deliveryStatus: "unknown" recorded. Both command jobs and isolated agent jobs were affected. docs/cli/cron.md explicitly promises command jobs "route output through the same announce, webhook, or none delivery modes".

Why This Change Was Made

The root cause was split ownership. Command execution only handled announce delivery (server-cron.ts); webhook mode returned delivered: false without sending. Cron then finalized state/history, converting that into terminal "unknown" (timer-trigger.ts). Only afterwards did the gateway dispatch a detached webhook from the finished event, whose errors were logged and swallowed — they could never repair the already-persisted history. (For loopback URLs specifically, the SSRF guard correctly rejects private addresses — that boundary is intentional and unchanged; the bug was that the rejection, like every other delivery failure, vanished into "unknown".)

Provenance: not a recent regression. Command jobs plus their webhook docs arrived together in #89712 (author @mbelinky, merged by Vincent Koc) already relying on the detached path; per-job webhook delivery originated in #17901 (author Advait Paliwal, merged by Tyler Yust); #116923 later made the unobserved state explicitly unknown without adding reconciliation.

The fix makes primary webhook delivery a recorded part of the cron run:

  • Delivery executes inside the run's tracked lifetime, sharing the run's abort controller and watchdog deadline — a hanging endpoint finalizes the run at its configured deadline as not-delivered/timeout, and operator cancellation interrupts an in-flight send immediately (both proven with real-HTTP regressions; review round 2 required this).
  • The settled delivery result is published before the delivery promise resolves, and cancellation/timeout branches consult it first — an endpoint that already accepted the POST can never be overwritten to not-delivered by a late cancellation (review round 3).
  • Success records delivered; HTTP, timeout, secret-owner, invalid-target, and SSRF failures record not-delivered plus a concrete deliveryError. unknown is no longer the terminal state for a configured webhook.
  • A trigger that intentionally evaluates false keeps its not-requested status rather than being misrecorded as a failed delivery (review round 4).
  • Transient errors retry only when provably unsent, reusing the existing 5/10/20 s policy; HTTP and SSRF failures do not retry. The detached finished-event fanout now owns only secondary completionDestination webhooks, preventing double POSTs.

No announce/channel behavior, Discord code, config surface, or schema changed.

User Impact

Webhook-configured jobs now actually deliver, and every outcome is honestly recorded: delivered on success, not-delivered with the concrete error otherwise — including the previously invisible SSRF-blocked case. Runs finalize within their configured deadline even against dead endpoints, and shutdown/cancellation cannot strand a run in delivery.

Evidence

  • Real-HTTP regressions: 204 → exactly one POST containing the payload, recorded delivered; 503 → one POST, not-delivered with HTTP 503; hanging endpoint → finalized at the job deadline, command result preserved ok, delivery not-delivered/timeout; cancellation mid-hang → finalized in under a second with the cancellation reason; accepted-POST-then-cancel race → stays delivered; trigger-evaluates-false → not-requested status, no deliveryError; isolated-agent webhook sibling → delivered.
  • node scripts/run-vitest.mjs src/cron: 160 files, 1,934 tests passed. Gateway webhook/cron suites: 113 passed. Timeout/watchdog regressions: 69/69.
  • Changed-scope gate passed locally (Testbox backend unavailable; documented trusted-source fallback), plus formatting, oxlint, core typechecks, git diff --check.
  • Autoreview (Codex gpt-5.6-sol, high): three review rounds surfaced an abort-scope escape, a settled-delivery cancellation race, and the trigger-not-fired mapping — each fixed with regressions; final round clean, "patch is correct" (0.86).

Production delta net +311 (delivery moved into the run lifecycle with signal/deadline plumbing — an ownership move, not a patch); tests net +541.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Aug 2, 2026
@steipete steipete self-assigned this Aug 2, 2026
@steipete
steipete marked this pull request as ready for review August 2, 2026 03:44
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 1:23 AM ET / 05:23 UTC.

ClawSweeper review

What this changes

Moves primary cron webhook delivery into the tracked cron-run lifetime, records delivered or failed outcomes before finalization, and leaves only completion-destination webhooks on detached fanout.

Merge readiness

⛔ Blocked until real behavior proof is added - 3 items remain

Keep this PR open for human merge review. The source-backed repair correctly targets a real silent-delivery path, and the latest commit addresses the previously reported cancellation and trigger-state cases, but the PR still lacks inspectable after-fix real HTTP evidence for the integrated Gateway path. Likely related people: @steipete (high), @mbelinky (medium), and @advaitpaliwal (medium).

Priority: P1
Reviewed head: b1d9f148cce1e998f1652b75414bc6d1f03d80e6

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is well-targeted and regression-oriented, but missing inspectable real behavior proof remains a merge gate.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR body reports real-HTTP checks, but this review has no inspectable after-fix terminal capture, receiver output, runtime log, recording, or linked artifact for the integrated Gateway path; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body reports real-HTTP checks, but this review has no inspectable after-fix terminal capture, receiver output, runtime log, recording, or linked artifact for the integrated Gateway path; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Current-main defect path: Current main resolves a webhook-mode delivery target for detached finished-event fanout, while cron delivery-state projection records a requested webhook as unknown before that detached send can report an outcome.
Tracked-delivery repair: The proposed runner invokes the injected primary-webhook sender before returning the cron result, publishes a settled 2xx acknowledgement before asynchronous cleanup, and maps failed delivery to a recorded delivery trace.
Network and security contract retained: The new primary sender continues to use the existing guarded fetch path, forwarding the run abort signal and bounded deadline; the guard’s public options support both signal and timeoutMs.
Findings None None.
Security None None.

How this fits together

Gateway cron executes command, script, or agent jobs, records a terminal run and delivery state, then emits a finished event. On current main, webhook-mode delivery is dispatched after that event; this PR makes the primary webhook part of the owned run while retaining detached secondary completion notifications.

flowchart LR
  Job[Scheduled cron job] --> Execute[Execute command or agent payload]
  Execute --> Primary[Primary webhook delivery]
  Primary --> Record[Persist delivery outcome]
  Record --> Event[Finished cron event]
  Event --> Secondary[Detached completion notification]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body reports real-HTTP checks, but this review has no inspectable after-fix terminal capture, receiver output, runtime log, recording, or linked artifact for the integrated Gateway path; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P2) - Before merge, the changed primary-delivery lifecycle needs an inspectable, redacted real HTTP receiver or Gateway runtime artifact proving exactly one POST and truthful persisted outcomes for success, timeout, cancellation, and a blocked target; the PR body’s assertions alone cannot establish that gate.
  • Complete next step (P2) - The remaining blocker is contributor or maintainer-supplied real behavior proof, not a narrow mechanical repair; the maintainer label also requires explicit human handling.
Agent review details

Security

None.

PR surface

Source +346, Tests +631. Total +977 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 10 420 74 +346
Tests 7 670 39 +631
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 1090 113 +977

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/cron/service/state.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Add integrated webhook proof (recommended)
    Attach a redacted terminal capture, receiver log, or runtime artifact that shows one primary POST and the matching persisted cron delivery outcome after this head.
  2. Pause for maintainer verification
    If production evidence cannot be shared, hold merge until a maintainer independently verifies the changed Gateway path against an HTTP receiver.

Technical review

Best possible solution:

Keep primary webhook delivery and its terminal record in the cron-run owner, keep only explicit completion destinations detached, and attach redacted integrated HTTP proof showing the persisted run state and receiver result before merge.

Do we have a high-confidence way to reproduce the issue?

Yes—source-reproducible. Current main resolves webhook-mode jobs for detached finished-event delivery while the run-state projection records the requested webhook as unknown before the detached result is available.

Is this the best way to solve the issue?

Yes in design: making primary webhook delivery part of the run owner is the narrowest way to make delivery and history agree, while retaining detached fanout only for completion destinations. Real integrated evidence is still required before merge.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 03c28795f8c6.

Labels

Label justifications:

  • P1: Cron jobs configured for webhooks can otherwise complete without delivery while run history conceals the failed outcome.
  • merge-risk: 🚨 message-delivery: This branch changes when primary cron webhooks send and which final delivery state is persisted.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports real-HTTP checks, but this review has no inspectable after-fix terminal capture, receiver output, runtime log, recording, or linked artifact for the integrated Gateway path; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current-main defect path: Current main resolves a webhook-mode delivery target for detached finished-event fanout, while cron delivery-state projection records a requested webhook as unknown before that detached send can report an outcome. (src/gateway/server-cron-notifications.ts:130, 03c28795f8c6)
  • Tracked-delivery repair: The proposed runner invokes the injected primary-webhook sender before returning the cron result, publishes a settled 2xx acknowledgement before asynchronous cleanup, and maps failed delivery to a recorded delivery trace. (src/cron/service/timer-job-runner.ts:49, b1d9f148cce1)
  • Network and security contract retained: The new primary sender continues to use the existing guarded fetch path, forwarding the run abort signal and bounded deadline; the guard’s public options support both signal and timeoutMs. (src/gateway/server-cron-notifications.ts:309, b1d9f148cce1)
  • Patch provenance: The current PR head is a follow-up commit whose parent is the initial primary-webhook recording change; its commit message and timestamp establish that the accepted-delivery race repair is part of this exact review head. (src/cron/service/timer-job-runner.ts:108, b1d9f148cce1)
  • Real-behavior proof gap: The PR body describes real-HTTP regressions, but the supplied discussion contains no inspectable terminal capture, receiver output, redacted runtime log, recording, or linked artifact demonstrating the after-fix integrated Gateway run.

Likely related people:

  • steipete: The current-main cron delivery path was recently touched by Peter Steinberger, and the reviewed head’s two commits implement the primary-webhook lifecycle repair and accepted-delivery race handling. (role: recent cron delivery contributor; confidence: high; commits: e49e9e2aa193, 66ba1e91e955, b1d9f148cce1; files: src/gateway/server-cron.ts, src/gateway/server-cron-notifications.ts, src/cron/service/timer-job-runner.ts)
  • mbelinky: The related merged command-cron work introduced the command execution path whose documented delivery behavior exposes this failure mode. (role: command-cron feature contributor; confidence: medium; commits: b8adc11977ab; files: src/gateway/server-cron.ts, docs/cli/cron.md)
  • advaitpaliwal: The related merged webhook-mode work established per-job cron webhook delivery and is the historical owner boundary this repair refines. (role: webhook delivery feature contributor; confidence: medium; commits: bc67af6ad89b; files: src/gateway/server-cron-notifications.ts, src/cron/delivery-plan.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach a redacted real HTTP receiver or Gateway runtime artifact that shows the post-fix request and persisted delivery record.
  • Let the remaining CI matrix complete against the reviewed head.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-08-02T03:54:50.501Z sha 1205ce4e251fddc98d75e5c2f2977e93a549bbd6 :: needs real behavior proof before merge. :: [P1] Preserve completed webhook acknowledgements across cancellation
  • reviewed August 2, 2026, 12:12 AM ET / 04:12 UTC sha unknown :: needs real behavior proof before merge. :: [P1] Preserve accepted webhook outcomes across cancellation
  • reviewed 2026-08-02T04:37:33.958Z sha 7674061f5008197157c2ba1911cee411ab58ae6f :: needs real behavior proof before merge. :: [P2] Preserve skipped-trigger delivery state during interruption
  • reviewed 2026-08-02T04:58:38.084Z sha b43a410b24b1483ae87775473840fcb8369e9766 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T05:08:50.990Z sha 0b340e22e9d873be2e781becca6e1247a4370c83 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 2, 2026
@steipete
steipete force-pushed the codex/fix-cron-webhook-command-jobs branch from 1205ce4 to 7674061 Compare August 2, 2026 04:32
@steipete
steipete force-pushed the codex/fix-cron-webhook-command-jobs branch 2 times, most recently from b43a410 to 0b340e2 Compare August 2, 2026 05:03
@steipete
steipete force-pushed the codex/fix-cron-webhook-command-jobs branch from 0b340e2 to b1d9f14 Compare August 2, 2026 05:17
@steipete
steipete merged commit c91979c into main Aug 2, 2026
188 of 190 checks passed
@steipete
steipete deleted the codex/fix-cron-webhook-command-jobs branch August 2, 2026 06:06
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant