Skip to content

feat(cron): reconcile the ledger and the webhook outbox after a crash - #930

Merged
ajianaz merged 13 commits into
developfrom
feat/webhook-reconcile
Nov 18, 2026
Merged

ajianaz merged 13 commits into
developfrom
feat/webhook-reconcile

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 4e of #911: a reconcile pass that closes the two gaps a crash leaves between the cron ledger and the webhook outbox. After this, part 4 of #911 is complete; part 5 (approval events, tole webhook test, the real-binary e2e, threat model, README) follows.

Why

The tick settles a run (ledger), then queues its event (outbox); the sender settles an event (outbox), then writes the ledger row. A crash between either pair loses something: a run whose event never existed, or an event that finished with no ledger row. Without a pass that repairs this, tole cron runs would show nothing for such a run, or the receiver would never hear of it.

Changes

  • cron::webhook::reconcile:
    1. A run that settled in the last 6 h, whose job names a configured destination, with neither an outbox event nor a ledger row of any status, is queued (or recorded skipped for a silent run, failed for a refusal). A row of any status counts as terminal, so a silent run is not queued again on every pass.
    2. An event that reached done or dead without a ledger row gets its row from the outbox's terminal line.
      It collects what is missing with no lock held, then queues (an atomic duplicate check under the outbox lock) and writes rows (under the ledger lock, once per run and destination). The two locks are never held together. At most 100 events per pass.
  • A run younger than 10 minutes is left to the live tick: its event is queued after its other targets (a command target can take minutes), and a pass in that window would race it.
  • A kept output file that is missing is never read as "silent". The live tick writes the file (even an empty one) before it settles the run, so a missing file means the run never went through the live path (settled at claim time by the daily cap, or recovered as interrupted) or the write failed; it is left alone, which also keeps those runs from becoming new webhooks.
  • The output file is read without following a symlink and without blocking (a planted FIFO), up to 64 KiB.
  • The live tick now also writes a webhook row once per run and destination (reconcile may have recorded it while the tick was delivering to a slow target).
  • It runs at the start of tole serve and every 5 minutes (a panic is caught), and before the drain of a standalone tole cron tick or tole cron run.
  • Outbox::terminal_events for step 2, limited to events of the window. CHANGELOG entry.

Known limit

Reconcile reads a job as it is now, not as it was claimed. A job that gained a webhook: target within the window can announce runs that settled before the change; this is bounded by the 6 h window and the 100 cap.

Testing

  • 9 new end-to-end tests with a real HTTP receiver: a run whose event was lost is queued and delivered (summary and fire id checked) and a second pass is a no-op; an event finished without a row gets its row and is not sent again; a silent run is not queued again and one whose skipped row was lost is recorded; runs older than 6 h, unknown destinations and a forged terminal line (id not that run's event id) are ignored or write no row; a fresh run is left to the live tick; a missing output file is never read as silent; a symlink is not followed and a FIFO does not block; a claim-time run is not announced.
  • Full cargo test -p tole-cli passes, clippy clean, layering test passes. cron_webhook_send passes 15 runs in a row under CPU load.
  • Independent read-only review. Major findings, all applied: a race between a pass and the live tick (duplicate rows, or a skipped row for a message that was sent), an unbounded, symlink-following, FIFO-blocking read of the output file, and a panic that could end the serve sender. Minor ones (work per pass, window of the terminal events, one restricted test) are applied or listed above.

Part 4b of #911. webhook_out::send::drain_pass leases one due event per
destination through the store, sends with no lock held, and appends the
result under a short lock.

Before every send the line is re-validated against the destination of the
loaded config and signed with the key that destination names, so a
forged line cannot choose a destination, an event type or a key, and the
key is not read for a line that fails validation. A result line and its
terminal line are one write, and a send must end inside its lease.

Retry and no-retry follow the design; result codes are a closed set and
no receiver text is stored or printed. The network, the key source and
the clock are injected.

Nothing calls it yet.
… standalone tick

Part 4c of #911. A webhook:<name> target is now delivered. The tick (and
an approval-resumed run, which goes through the same path) only appends
the redacted cron_run_finished event to the outbox; the sender writes the
ledger delivery row when the event settles. A silent ok run records
skipped, a failed run with no output still notifies, and a refusal to
queue records failed with a closed code.

The standalone tole cron tick and tole cron run send for about 20 s after
their jobs. A row is written once per run and destination and only for a
run whose job names the destination. The destination URL is redacted
like its key. Events of a destination that is no longer configured are
never sent and never make a drain wait.
Part 4e of #911. reconcile closes the two gaps a crash leaves: a run that
settled but whose event was never queued, and an event that finished
without a ledger row. A row of any status counts as terminal, so a silent
run is not queued again.

A run younger than 10 minutes is left to the live tick. A missing kept
output is never read as silent, and the file is read without following a
symlink or blocking on a FIFO. A webhook row is written once per run and
destination by the live tick too. It runs at the start of tole serve and
every 5 minutes, and before the drain of a standalone tick.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 16eac77 into develop Nov 18, 2026
23 checks passed
@ajianaz
ajianaz deleted the feat/webhook-reconcile branch November 20, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant