Repository navigation
feat(cron): reconcile the ledger and the webhook outbox after a crash - #930
Merged
Merged
Conversation
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.
…x text out of logs
… make the backlog test robust
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.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 runswould show nothing for such a run, or the receiver would never hear of it.Changes
cron::webhook::reconcile:skippedfor a silent run,failedfor a refusal). A row of any status counts as terminal, so a silent run is not queued again on every pass.doneordeadwithout 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.
tole serveand every 5 minutes (a panic is caught), and before the drain of a standalonetole cron tickortole cron run.Outbox::terminal_eventsfor 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
skippedrow 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.cargo test -p tole-clipasses, clippy clean, layering test passes.cron_webhook_sendpasses 15 runs in a row under CPU load.skippedrow 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.