Repository navigation
feat(cli): add the outbound webhook outbox format and its fold - #925
Merged
Merged
Conversation
Part 3c of #911. webhook_out::outbox defines the append-only JSONL lines (enqueue, lease, attempt, done, dead), their encoding, and a fold over bytes. Nothing here opens a file, takes a lock or reads a clock. The fold treats the file as untrusted input: a line over 32 KiB or unparseable is counted and skipped, a torn tail is not consumed until it is complete, a line with no enqueue or after a terminal line is ignored, the first enqueue wins, and a far-future lease is ignored. validate re-checks a line before every send: size, schema v1, the destination (which must be configured and list the event type), the id and the age. Nothing calls it yet.
| if at > now + SKEW_SECS { | ||
| return Err(BAD_LINE); | ||
| } | ||
| if now - at > CRON_DEADLINE_SECS { |
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
validate read the body timestamp from the file and computed now - at, so at = i64::MIN overflowed: a panic in debug builds, and in release a wrap that passed the age check. Use saturating arithmetic for the timestamp, the deadline and the lease checks, and add regression tests with i64::MIN and i64::MAX (the test panics on the old code).
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 3c of #911:
webhook_out::outbox, the format of<cron dir>/outbox.jsonland its fold. Bytes in, state out: no file, lock or clock. Nothing calls it yet.Why
The sender will read an append-only file that another process of the same account can also write, and it signs whatever a line says. Pinning the format, the defensive fold and the pre-send validation as pure code first keeps the sender PRs small and lets this get a focused security review.
Changes
enqueue(the redacted body once, so every attempt is byte-identical),lease,attempt,done,dead, all keyed by (destination, id).encoderefuses a line over 32 KiB;separatorsays when a writer must end a torn tail first.Fold::feedis incremental and treats the file as untrusted: a line over 32 KiB or unparseable is counted and skipped, a torn tail is not consumed until complete, a line with noenqueueor after a terminal line is ignored, the firstenqueuewins, and a lease claiming more than the largest timeout + 5 s + 60 s ahead is ignored.duereturns one event per destination, oldest first, skipping leased, waiting, finished and expired events.expiredlists events past the 6 h deadline.queue_fullapplies the 10 000 pending per destination bound.validatere-checks anenqueuebefore every send: body at most 16 KiB, schema v1, the line's own destination (which must be configured) and id, atypethe destination lists inevents, and the age ofat(not in the future, not past the deadline). It returns the code the event is markeddeadwith.Testing
enqueue, first-enqueue-wins, forged far-future lease,dueordering and skips, bounds, and everyvalidaterule including a body built by the real event builder.