Skip to content

feat(events): throttle error emails per fingerprint and globally (#4694) - #4721

Merged
bpamiri merged 2 commits into
developfrom
feat/error-email-throttle
Dec 1, 2026
Merged

bpamiri merged 2 commits into
developfrom
feat/error-email-throttle

Conversation

@bpamiri

@bpamiri bpamiri commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Implements #4694 Part 1 from the approved brief (.ai/wheels/design/error-email-throttling.md, #4719): opt-in error-email throttling with all defaults unlimited, so an unconfigured app's email behaviour is unchanged.

setting range default
errorEmailRateLimit (per fingerprint, per window) 0–1000 0 (unlimited)
errorEmailRateWindowMinutes (fixed window) 1–1440 15
errorEmailGlobalRateLimit (all error emails, per window) 0–10000 0 (unlimited)

Behaviour

  • Defaults are inert. With both caps 0 $errorEmailThrottleReserve() returns {allowed=true, summary=""} before computing a fingerprint or touching state. The spec sends five emails with the defaults and asserts five calls and no throttle state key created; it fails if an unconfigured app's email count changes.
  • Fingerprint = root cause, not the engine wrapper: rootCause.type|rootCause.message (first 1000 chars)|first application frame basename:line, lowercased, SHA-256. Framework frames under vendor/wheels are skipped; no app frame → first frame; no frames → no-frame. tagContext may be absent, a struct, a Lucee-style {file,line} or an Adobe-style {template,line} — all handled defensively and covered by specs.
  • State: one application.wheels.errorEmailThrottle struct (created lazily under the lock), fixed window, per-fingerprint + global counters. Bounded to 512 fingerprints (expired unsuppressed entries pruned, then oldest windowStart evicted). Only hashes and counters are stored.
  • Lock/fail-open: named exclusive lock wheels.errorEmailThrottle.<applicationName>, 5s timeout. If the lock cannot be acquired the email is sent unthrottled and one warning is logged — a throttling failure never loses an error. Per-node/approximate semantics are documented (no shared store; multi-server caps are per node).
  • Summary: suppressed occurrences are counted and, on the next allowed email, a numbers-only paragraph is prepended to the existing body (N occurrence(s) of this error and M error email(s) were suppressed in the last W minute(s).). No exception text; no separate summary email.
  • Invalid settings never throw: digits-only whole-number parsing (the JobTickEndpoint.$wholeSetting() precedent; 0 valid for caps, window falls back to 15 when 0/invalid/fractional/scientific/signed/array/struct or out of range), one warning per setting. No on/off switch — opt-in is via the caps, as approved.
  • The reservation happens after the recipient check (no state for an unconfigured app) and before body construction/send; a throwing $mail still consumes the reservation by design.

Settings inventory and docs

  • vendor/wheels/events/init/debugging.cfm — defaults next to sendEmailOnError.
  • vendor/wheels/public/views/info.cfm — Error Handling inventory.
  • cli/src/commands/wheels/get/settings.cfc — CLI defaults inventory.
  • Generated app templates: commented example (not active) in cli/lucli/templates/app/config/settings.cfm and .../production/settings.cfm.
  • Consumer docs: docs/consumer-ai/.ai/views.md and cli/lucli/templates/app/.ai/views.md (shipped tier); tools/build/scripts/ship-consumer-docs.sh check → consumer-docs check OK.
  • changelog.d/4694-error-email-throttling.added.md.

Tests

vendor/wheels/tests/specs/events/ErrorEmailThrottleSpec.cfc (recording OnErrorEventDouble.$mail(), no SMTP): defaults inert, per-fingerprint cap, different fingerprint still sends, global cap, window reset + summary, global-only summary, fingerprint isolation and frame skipping, defensive tagContext shapes, no-recipient no-state, invalid-setting fallbacks, mail-failure safety, and the rendered error path.

Verification

  • Focused spec: 11 passed (Lucee 7).
  • Full local suite: 7,440 passed, 0 failed (Lucee 7 + SQLite).
  • CLI suite: 2,462 pass, 0 fail, 0 error.
  • tools/test-matrix.sh lucee7,adobe2023,adobe2025 sqlite → Lucee 7 pass, adobe2023 pass; adobe2025 u06 was verified separately on a clean engine home: full core suite 7,416 pass / 0 fail / 0 error (the matrix's local adobe2025 container had inherited a stale u14 engine volume, which is a local-environment issue, not this change).
  • Complexity gate: cfml-complexity.py vendor/wheels --gate 30 → PASS (the fingerprint helper was split into root-details/frame/fingerprint to stay under 30).
  • Consumer-docs tier check OK; cfformat clean.

Unverified / notes

  • The fail-open lock path is implemented and reviewed but not exercised by a spec (forcing a lock timeout deterministically is not practical here); the mail-failure and invalid-setting paths are exercised.
  • Cross-node exactness is explicitly out of scope: counters are per application instance and reset on reload; documented in the consumer docs.
  • BoxLang/RustCFML legs are CI/release-matrix only (this PR runs the normal PR checks, which include Lucee, Adobe 2023 and RustCFML); no local BoxLang run was made.

CI status on 299c25a5f

All checks pass except box install -> serve (CommandBox), which fails before any Wheels request with a CommandBox-environment error, not this diff:

ERROR: Sorry, no config provider could be found for [luceeServer@8.0.0+310].
  at /modules/commandbox-cfconfig/.../CFConfigService.cfc:78
##[error]server did not bind in development

This is base-image drift in ghcr.io/wheels-dev/mirror/ortussolutions/commandbox:latest (the bundled commandbox-cfconfig does not know the Lucee 8 provider); this PR touches no CommandBox/CFConfig/image file, and the workflow's previous run in this repo's history (Oct 16) passed with the older image. Rerunning the job reproduces the identical provider error.

The four required contexts still pass: Lucee 7 + SQLite (LuCLI), Validate Commit Messages, RustCFML (Linux), Consumer AI docs in sync. Also green: cold-start (adobe2023/adobe2025/boxlang/lucee7), smoke testing/production Adobe 2023 and Lucee 7, adobe2023 + sqlite, boxlang + sqlite, lucee7 + h2, complexity gate, CLI suite, Deploy CLI tests + verb smoke, Tutorial E2E.

Review round 2 (head 32aa5d824)

D1 — the lock-failure warning now logs once per application. $warnErrorEmailThrottleLockFailure() sets application.wheels["$errorEmailThrottleLockWarned"] and returns early on later failures, mirroring $legacyDebugIpBlockWarned in settings.cfm; fail-open behaviour is unchanged (the email is still sent unthrottled). A missing lock on every error no longer writes a line per error.

D2 — a 0-minute window is out of range, not silently clamped. Added $errorEmailWholeSetting(name, fallback, maximum, minimum); the caps keep the allow-zero wrapper, and errorEmailRateWindowMinutes is parsed with minimum=1. 0 / fractional / signed / scientific / out-of-range now falls back to 15 with one warning via the same one-warning-per-setting path; the silent clamp is gone.

D3 — named, no behaviour change. The ^[0-9]+(\.0+)?$ regex still accepts a .0 tail; this mirrors the JobTickEndpoint.$wholeSetting() precedent, whose comment documents the same engine-double allowance. The new helper's docblock says so explicitly so it is not re-litigated.

Mutation proof (specs bite against the old behaviour, then restored green):

  • Reverting D1 (warn on every failure, no flag): 13 passed, 1 failed — "warns once, not per failure, when the throttle lock is unavailable: Expected [false] to be true".
  • Reverting D2 (allow-zero + clamp): 13 passed, 1 failed — "rejects a 0-minute window with a warning instead of silently clamping it: the reserve path must warn for a 0-minute window".
  • Restored: focused spec 14 passed; full local suite 7,443 passed (the previous 7,440 + 3 new specs); complexity gate PASS; cfformat clean.

qa's verified properties are untouched: the inert-defaults guard (5 sends → 5 mails, no throttle state), per-fingerprint cap, global cap across unique fingerprints, summary counts, fail-open no-throw, fingerprint isolation and the rest of the 11 original specs are unchanged and still pass.

CI on 32aa5d824: every check passes except box install -> serve (CommandBox), which is the pre-existing #4722 drift being fixed separately in #4723 (verified green there: runs 46603184614 / 46603242450). Nothing else is red.

Rebase onto develop af3a9a3c9 (head 4d6b43938)

Rebased onto current develop so this branch picks up the #4723 CommandBox smoke fix (af3a9a3c9); no code changes beyond the rebase, and the diff for the D1/D2 files is empty against the previous head (git diff 32aa5d824 4d6b43938 -- vendor/wheels/events/EventMethods.cfc vendor/wheels/tests/specs/events/ErrorEmailThrottleSpec.cfc = no output).

  • box install -> serve (CommandBox) is now GREEN on the rebased head: job run — the ci(commandbox): pin the smoke image and engine, add dispatch (#4722) #4723 digest/engine pins make it pass for real, with all its assertions executing.
  • D1 verified present: $warnErrorEmailThrottleLockFailure() + application.wheels["$errorEmailThrottleLockWarned"] (one-time warning, fail-open unchanged).
  • D2 verified present: errorEmailRateWindowMinutes parsed with minimum = 1; the 0-minute range spec and the once-lock-warning spec are unchanged.
  • All checks on 4d6b43938: 26 total, 0 failing (the LuCLI leg's first run hit the known Maven Central 429 flake on the sqlite-jdbc download; gh run rerun --failed passed).

Add the three approved settings with their approved ranges and defaults
(all defaults unlimited, so unconfigured apps behave exactly as before):

  errorEmailRateLimit          0..1000   default 0
  errorEmailRateWindowMinutes  1..1440   default 15
  errorEmailGlobalRateLimit    0..10000  default 0

The send path reserves a slot after the recipient check and before building
the email. A fingerprint is a SHA-256 of root-cause type + message (first 1000
chars) + the first application frame's basename and line, so framework frames
are skipped and engine tagContext differences fall back safely. The per-node
application-scope state is bounded to 512 fingerprints, uses a fixed window
under a named lock, fails open if the lock is unavailable, and keeps suppressed
counts until the next allowed email carries a numbers-only summary paragraph.

Settings are surfaced in the info page, the CLI defaults inventory, and as a
commented example in the generated app's settings files. Consumer AI docs are
updated in both the shipped tier and the wheels-new template, with a changelog
fragment.

Specs drive the recording mail stub: defaults inert, per-fingerprint cap,
global cap, window reset, summary counts, fingerprint isolation, no-recipient
behaviour, invalid-setting fallbacks, mail-failure safety and the rendered
error path.

Signed-off-by: Peter Amiri <peter@alurium.com>
… window

Two review deviations from the approved brief (#4694):
- The fail-open lock path logged a warning on every failure, which moves the
  flood the feature prevents into the log. Warn once per application via
  application.wheels["$errorEmailThrottleLockWarned"], mirroring
  $legacyDebugIpBlockWarned; fail-open behaviour is unchanged.
- errorEmailRateWindowMinutes was parsed with the allow-zero helper, so 0 was
  accepted and then silently clamped to 15. The approved range is 1..1440, so
  the window now uses a range-aware whole-number helper: 0 is out of range and
  falls back to 15 with one warning.

The ".0" tail allowance is unchanged and now documented as mirroring
JobTickEndpoint.$wholeSetting() (D3). Specs cover the once-only lock warning,
the range helper, and the reserve path warning for a 0-minute window; both new
specs fail against the previous behaviour.

Signed-off-by: Peter Amiri <peter@alurium.com>
@bpamiri
bpamiri force-pushed the feat/error-email-throttle branch from 32aa5d8 to 4d6b439 Compare December 1, 2026 09:22
@bpamiri
bpamiri merged commit c6fb3af into develop Dec 1, 2026
31 of 32 checks passed
@bpamiri
bpamiri deleted the feat/error-email-throttle branch December 1, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant