Fix Teams 413 error: add charset=utf-8 to Content-Type header and retry on 413#2162
Fix Teams 413 error: add charset=utf-8 to Content-Type header and retry on 413#2162devin-ai-integration[bot] wants to merge 2 commits intomasterfrom
Conversation
…ry on 413 Co-Authored-By: Michael Myaskovsky <michael@elementary-data.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
| 👋 @devin-ai-integration[bot] |
| No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe Teams webhook handler now sets Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed. Inline comments: In `@elementary/messages/messaging_integrations/teams_webhook.py`: - Around line 122-123: The retry payload still contains large top-level fields because _minimal_card(card) clones the entire original card and only swaps out body; change _minimal_card to build and return a brand-new minimal dict (do not copy the original) that includes only the small required keys (e.g., card type/summary/title if needed) plus the new body, ensuring any large fields from the original card are omitted before calling _build_payload; update callers using _minimal_card(card) accordingly so payload only contains those minimal keys. - Around line 107-128: The two requests.post calls that send Teams webhooks (the initial call and the retry in the branch that builds a minimal card) lack an explicit timeout and can block indefinitely; update both calls to pass a reasonable timeout value (e.g. timeout=5 or a configured constant) to requests.post so the worker won't hang, and ensure the same timeout constant is used for both the initial send and the retry paths that call _build_payload and _minimal_card. ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 72f4a384-745c-4c03-816c-fd7c00202f35
📒 Files selected for processing (1)
elementary/messages/messaging_integrations/teams_webhook.py
Co-Authored-By: Michael Myaskovsky <michael@elementary-data.com>
Summary
Fixes persistent HTTP 413 (Request Entity Too Large) errors from Microsoft Teams webhooks, even after the payload truncation logic from #2160.
Root cause: The Teams webhook connector converts the request body to UTF-16 when
charsetis not specified in theContent-Typeheader, effectively doubling the payload size before enforcing the 28KB limit. A 14KB payload becomes ~28KB after conversion, triggering a 413. (Source)Changes:
Content-Type: application/json; charset=utf-8so the connector skips the UTF-16 conversionReview & Testing Checklist for Human
charset=utf-8fix works with Prendio's specific webhook type (old O365 connector vs new Power Automate workflow webhook — behavior may differ)"413" in response.textsubstring match won't false-positive on legitimate response text from Teams_minimal_card(card)fallback produces a payload small enough for Teams in all cases (it uses**cardwhich preserves non-body fields)Notes
send_message— no behavior regression.Link to Devin session: https://app.devin.ai/sessions/d746de1f2743489995cc5070957c91c6
Summary by CodeRabbit