Skip to content

fix(delivery): bound webhook/stream backlogs, fix duplicate listeners, wire ignored config (#64 W4) - #69

Merged
CodingAnarchy merged 1 commit into
masterfrom
fix/delivery-config
Oct 10, 2026
Merged

CodingAnarchy merged 1 commit into
masterfrom
fix/delivery-config

Conversation

@CodingAnarchy

Copy link
Copy Markdown
Owner

Part of #64 (workstream W4): H11, H12, H13, M3, M4, M7, M9.

Fixes

Finding Fix
H11 update_webhook duplicated delivery update_webhook now swaps the config in the map in place. The one listener reads the current config on every event, and statistics are kept. Each listener selects on a stop signal (task_tracker::ListenerHandle, a oneshot whose sender is dropped). Removing a webhook or stream, or calling add_webhook/add_stream again with the same id, stops the old listener at once, even while it waits in recv(). Streams had the same bug for re-adds.
H12 unbounded delivery backlog The listener takes a pending slot before it spawns a delivery. Webhooks have a per-webhook semaphore sized by the new WebhookManagerConfig::max_pending_deliveries (default 1000, also webhooks.global_settings.max_pending_deliveries). Streams have a per-stream semaphore of BufferConfig::max_events events, so the existing setting now bounds in-flight events. Policy: backpressure. When a webhook or stream is full, its listener waits. New events stay in the EventManager broadcast buffer, and once that overflows the oldest are dropped for that listener, logged at warn, and counted in the new WebhookStats::dropped_events / StreamStats::dropped_events. Memory stays bounded however long the endpoint is down. Retries now take the global max_concurrent_deliveries / max_concurrent_processors permit per attempt, so a dead endpoint waiting out backoff no longer starves the other webhooks.
H13 timeout didn't cover the body One deadline (timeout_at) covers send and body read. The body is read chunk by chunk up to max_response_body_size, then the connection is dropped. If the status arrived but the body timed out, the attempt counts by its status, so a 2xx is not retried and duplicated.
M9 missed events after add_* The subscription is created in add_webhook/add_stream, and its receiver moves into the listener task (no resubscribe()). The 100 ms "let the listener start" sleeps are gone from the webhook and stream tests. The remaining waits poll a condition.
M7 O(n) stats hot path InMemoryStatsCollector keeps a timestamp-ordered VecDeque. Inserts are amortised O(1): append, with a rare near-back insert for late events, and pruning from the front by age and size. A query binary-searches the window start and aggregates in one pass by reference, with no 100k-event clone per alert poll.
M3 with_fairness_factor ignored Deprecated (see below).
M4 accepted-but-ignored config Wired: WebhookManagerConfig::default_timeout_secs applies when a webhook has timeout_secs = 0, which is now also the serde default. StreamManagerConfig::global_flush_interval_secs caps every stream's buffer time. MetricsConfig::update_interval sets the worker monitoring interval, previously hard-coded to 30 s, with a 1 s minimum. StatsConfig::max_event_age_secs is applied on insert. StatsConfig::collect_timing works. [logging] is applied by the new LoggingConfig::try_init(): EnvFilter level, JSON, file/line, and OTLP export with the tracing feature (init_tracing's provider setup was factored into install_tracer_provider). JobBatch::with_batch_size is documented as what it actually is, the into_chunks size. Deprecated (no sound meaning): AutoscaleConfig::idle_timeout, StatsConfig::cleanup_interval_secs (pruning now happens on every insert), AlertingConfig::custom_thresholds, and web DashboardConfig::request_timeout. warp 0.4 has no request-timeout hook, and wiring one would need a custom hyper server. All of these keep compiling and parsing, and are #[serde(default)] where they were required. Note: request_timeout was not wired by W1 on master. Web session_timeout and the WebSocket limits were.

M3: why deprecate rather than implement

Weighted selection (pick_weighted_priority, and TestQueue's equivalent) already picks each priority that has runnable jobs with probability w / Σw, so a non-zero weight cannot starve. A fairness blend such as (1-f)·w/Σw + f/n is well defined. But implementing it would:

  • silently change scheduling for every default user, because PriorityWeights::new() already sets 0.1;
  • contradict the documented weight-0 semantics ("only when nothing with a weight is runnable");
  • need changes in all three dequeue implementations in src/queue/*, which W2 is editing.

Raising a weight already does what users wanted. The value still parses from config files and is stored, but is documented as having no effect.

Behaviour changes

  • Webhook stats survive update_webhook, and an unknown id is still added.
  • timeout_secs = 0 uses the manager default; before, it timed out immediately.
  • A stream flushes when its oldest buffered event has waited min(max_buffer_time_secs, global_flush_interval_secs). The listener sleeps until that deadline instead of polling every second. Before, a lone event after an idle period was flushed immediately.
  • With a metrics collector, worker monitoring runs every update_interval (15 s default) instead of 30 s.
  • InMemoryStatsCollector drops events older than max_event_age_secs (1 h default) automatically.
  • Breaking for struct literals: new fields on WebhookManagerConfig, WebhookGlobalSettings, WebhookStats and StreamStats.
  • tracing-subscriber enables json, which adds tracing-serde to Cargo.lock.
  • Webhook delivery logs now redact the URL path, as add_webhook already did.

Coordination with W2

src/worker.rs has a small diff (+23/−7):

  • the monitoring interval, which is 6 lines in start_monitoring_task, where W2's M8/M10 also work;
  • the idle_timeout deprecation attributes in AutoscaleConfig, next to W2's H9;
  • removal of three test lines that used idle_timeout.

Nothing in src/queue/* or migrations changed. Expect at most trivial conflicts.

Tests

New tests:

  • M9: an event published right after add (webhook and stream).
  • H11: N updates and re-adds deliver exactly once, with one subscription and one attempt.
  • H11: an update applies the new filter and keeps stats.
  • H12: a gated endpoint/processor leaves ≤ max_pending in flight, then delivered + dropped = published and dropped > 0 (webhook and stream).
  • H13: headers then a stalled body finish within the 1 s timeout; an endless chunked body is read only up to the limit.
  • M4: zero-timeout default and serde, global flush cap, logging subscriber (levels, JSON, invalid level, missing feature), ListenerHandle/clamp_permits.
  • M7: bounded buffer, out-of-order inserts, age pruning, collect_timing, priority and queue aggregates.
  • M3: deprecated fairness still parses and is ignored.

Results:

  • cargo fmt --all --check and cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.
  • cargo clippy -p hammerwork --lib --tests --no-default-features with "", postgres, postgres,webhooks, postgres,streaming and mysql,tracing: clean.
  • cargo test -p hammerwork --lib --no-default-features with "" (266 tests), postgres,webhooks (337) and postgres,streaming (334): pass.
  • PostgreSQL style, cargo test --workspace --all-features --no-fail-fast -- --include-ignored --skip mysql: 1816 passed, 0 failed.
  • MySQL style, -- --include-ignored mysql with both URLs set to MySQL: 150 passed, 0 failed.
  • Doctests with --features postgres,mysql,test,encryption,tracing,streaming,kafka: 525 passed.
  • New timing-sensitive tests: 3 runs, no flakes.

There is no automated "unread config field" guard. I didn't find a cheap, reliable way to write one.

🤖 Generated with Claude Code

…, wire ignored config (#64 W4)

- H11: update_webhook swaps the config in place; removing or re-adding a
  webhook or stream stops its old listener (ListenerHandle drop signal).
- H12: at most max_pending_deliveries per webhook and BufferConfig::max_events
  per stream are pending; listeners wait, overflow is dropped oldest-first and
  counted in dropped_events. Retry backoff no longer holds a concurrency slot.
- H13: the webhook timeout covers the response body, which is read up to
  max_response_body_size.
- M9: subscribe before add_webhook/add_stream return; remove the test sleeps.
- M7: InMemoryStatsCollector uses a time-ordered VecDeque, O(1) amortised
  inserts and in-place window aggregation.
- M3: deprecate PriorityWeights::with_fairness_factor (never applied; the
  weighted pick already prevents starvation).
- M4: wire default_timeout_secs, global_flush_interval_secs,
  MetricsConfig::update_interval, StatsConfig max_event_age_secs and
  collect_timing, and [logging] (LoggingConfig::try_init); deprecate
  idle_timeout, cleanup_interval_secs, custom_thresholds and web
  request_timeout; document JobBatch::with_batch_size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CodingAnarchy
CodingAnarchy merged commit ea466e5 into master Oct 10, 2026
17 checks passed
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.

1 participant