Skip to content

fix(webhooks): send payload as JSON object instead of double-encoded string#623

Open
MateoLostanlen wants to merge 1 commit into
mainfrom
fix/webhook-double-serialization
Open

fix(webhooks): send payload as JSON object instead of double-encoded string#623
MateoLostanlen wants to merge 1 commit into
mainfrom
fix/webhook-double-serialization

Conversation

@MateoLostanlen

@MateoLostanlen MateoLostanlen commented Jun 11, 2026

Copy link
Copy Markdown
Member

Bug

dispatch_webhook passed model_dump_json() (a str) to httpx's json=, which JSON-encoded it a second time. Every generic webhook consumer received a double-encoded body: a quoted JSON string like "{\"id\": 123, ...}" instead of the object {"id": 123, ...}, so any parser got a str instead of a dict. Present since the mechanism was introduced (#367).

Why Slack notifications were never affected

The Slack messages we receive go through the dedicated organization.slack_hook path (slack_client.notify, #478), which formats a proper Slack message. The recurring 400 invalid_payload errors in the prod logs came from the same Slack URL being also registered in the generic webhook table, a leftover from before #478 that never worked and only produced log noise. That row has been removed from the prod table.

Why fix the payload anyway

Removing the bad row only stops the log noise: the generic webhook mechanism itself stays broken for its intended use. Any legitimate consumer registered in the webhook table (partner system, internal service expecting the detection JSON) would still receive a double-encoded string. This fixes the mechanism for the next consumer.

Changes

  • Use model_dump(mode="json") and let httpx do the encoding.
  • Log httpx.RequestError (timeouts, connection failures) instead of letting them bubble up, consistent with best-effort dispatch.
  • Add a regression test asserting the dispatched body is a JSON object.

…string

model_dump_json() returns a str, which httpx json= encodes a second
time, so consumers received a quoted JSON string instead of an object
(Slack rejects it with 400 invalid_payload). Use model_dump(mode="json")
and let httpx do the encoding. Also log connection/timeout errors
instead of letting them bubble up to callers.
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.07%. Comparing base (9d6216a) to head (f57f28c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #623      +/-   ##
==========================================
- Coverage   93.27%   90.07%   -3.21%     
==========================================
  Files          58        3      -55     
  Lines        2946      131    -2815     
==========================================
- Hits         2748      118    -2630     
+ Misses        198       13     -185     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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