Skip to content

feat(cli): add the outbound webhook outbox format and its fold - #925

Merged
ajianaz merged 2 commits into
developfrom
feat/webhook-outbox-format
Nov 18, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/webhook-outbox-format

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 3c of #911: webhook_out::outbox, the format of <cron dir>/outbox.jsonl and 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

  • Lines: enqueue (the redacted body once, so every attempt is byte-identical), lease, attempt, done, dead, all keyed by (destination, id). encode refuses a line over 32 KiB; separator says when a writer must end a torn tail first.
  • Fold::feed is 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 no enqueue or after a terminal line is ignored, the first enqueue wins, and a lease claiming more than the largest timeout + 5 s + 60 s ahead is ignored.
  • due returns one event per destination, oldest first, skipping leased, waiting, finished and expired events. expired lists events past the 6 h deadline. queue_full applies the 10 000 pending per destination bound.
  • validate re-checks an enqueue before every send: body at most 16 KiB, schema v1, the line's own destination (which must be configured) and id, a type the destination lists in events, and the age of at (not in the future, not past the deadline). It returns the code the event is marked dead with.
  • CHANGELOG entry.

Testing

  • 21 unit tests: round trips, byte-identical body, torn tail resume, fragment terminated by a later writer, garbage and overlong lines, lines with no enqueue, first-enqueue-wins, forged far-future lease, due ordering and skips, bounds, and every validate rule including a body built by the real event builder.
  • Clippy clean, layering test passes.
  • Needs the focused review the design asks for (outbox validation).

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 {
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🔍 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).
@ajianaz
ajianaz merged commit 61643f1 into develop Nov 18, 2026
19 checks passed
@ajianaz
ajianaz deleted the feat/webhook-outbox-format 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.

2 participants