Repository navigation
job_broadcaster: dst storm scenario pins webhook retry time budget - #291
Merged
Merged
Conversation
added 5 commits
November 13, 2026 21:59
…ayload, no redirects
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.
Unit tests scripted the webhook's 429 responses but never pinned the time the retry policy costs:
RATE_LIMIT_RETRIESsleeps, chunk pacing, and a hostileretry_aftercompose into wall-clock time a cron-window job can't afford, and no test could catch a regression there without sleeping in CI. The tiger review of the brick also found a set of correctness and contract gaps: malformed 429 bodies crashing out ofpost(), an unclampedretry_after(Discord's own shared-limit example is 1336.57s — 22+ minutes), dead embed-limit constants, a docstring contradicting the code on which retry signal wins, naive embed timestamps silently shifted to local time, payloads replayed to redirect targets, and stdlib-json serialization where the repo mandates orjson. A docs pass on Discord's embed limits then revealed the 6000-char sum binds per message across all embeds — our check was per single embed.This PR closes the full findings list for
components/bot_detector/discord_webhook:Transport (
core.py):retry_afterclamped before sleeping:min(max(v, 0.0), MAX_RETRY_AFTER_SECONDS = 60)(constant, cron-window bound). The log line shows the value actually slept._rate_limit_secondsprefers the bodyretry_after— per the docs it's fractional (64.57) while theRetry-Afterheader is its integer ceiling (65), so body-first always waits the exact time; header fills in only when the body omits or garbles the value, sane default last. The docstring now matches the code. Malformed bodies (non-object JSON,retry_after: null, HTML from a proxy) fall back instead of raising —post()keeps its errors-as-values contract.data=orjson.dumps(...)+Content-Typeheader) per repo guidelines.allow_redirects=False— a redirect must never get the embed payload replayed to another host.Structs (
structs.py):Embedtimestamps rejected at construction —astimezone()would have silently treated them as system-local time.colorbounded to its 24-bit RGB domain (0–0xFFFFFF) andthumbnail_urlrequired to be http(s) — the docs' image-url contract; anything else was a guaranteed 400 at send time.Embed/EmbedFieldare frozen andfieldsis a tuple: validators bind only at construction, so post-construction mutation (.fields.append(...),embed.title = ...) was a silent bypass of every size limit; now it's a loud error.Consumer note (
bases/bot_detector/job_broadcaster/embeds.py): 3 mechanical bracket changes — the builders now passfields=()tuples to satisfy the component's type. Zero behavior change.Sim scenario (
test/sim/test_broadcaster_rate_limit_storm.py): the deadline-tripwire test is flipped as documented:retry_after=86_400now asserts broadcast completes — bans applied, all 12 post attempts, inside the same[480s, 600s]virtual budget as the honest 60s storm. One hostile 429 costs exactly what an honest one costs.Tests: 16 new unit tests (cap, negative clamp, body-over-header precedence, header-on-null-body, HTML-body fallback, request timeout, embed-count/empty-payload/message-total guards incl. the exact-6000 boundary, naive timestamp, color range + boundaries, thumbnail scheme, frozen immutability) plus a rename of the misleading "malformed 429" test to what it actually tests.
Gates: full suite 634 passed / 4 skipped,
ruff check,ruff format,mypyall clean.Still open (design-level objections, deliberately not defects): no transport-error retry for idempotent webhook POSTs, errors-as-values carries no typed variant (callers string-match), and the component-wraps-HTTP tension in AGENTS.md's component definition.
Created with GLM-5.3-Flash in T3 Code.