Skip to content

fix(llm_proxy): exempt task from TWDT during blocking HTTP call - #182

Open
primalkz wants to merge 1 commit into
memovai:mainfrom
primalkz:fix/llm-wdt-reset
Open

fix(llm_proxy): exempt task from TWDT during blocking HTTP call#182
primalkz wants to merge 1 commit into
memovai:mainfrom
primalkz:fix/llm-wdt-reset

Conversation

@primalkz

@primalkz primalkz commented May 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes WDT-triggered hard resets during slow LLM responses. Removes the task from TWDT monitoring for the duration of the blocking HTTP call, on both the direct and proxy paths.

Problem

Calling esp_task_wdt_reset() before and after esp_http_client_perform() does not work. A task parked in a locking call cannot execute any code, watchdog resets.

Ask MimiClaw to summarize a long document. The LLM accepts the connection but takes 18s to generate the response. The TWDT fires at t=5s the call, abort() is called, and the chip resets cold. The user sees startup blink sequence mid-conversation, session gone. UART shows rst:0xc (SW_CPU_RESET)`. The post-call reset never executes.

Fix

esp_task_wdt_delete(NULL) removes the calling task from TWDT monitoring the blocking call. esp_task_wdt_add(NULL) and esp_task_wdt_reset() restore it after. wdt_was_subscribed guards against accidentally subscribing the task if it was not previously registered. Applied to both llm_http_direct and llm_http_via_proxy.

Validation

  • idf.py build passes on v5.5.2, target esp32s3.

Note: Builds on v5.5.0/v5.5.1 require PR #181 (websocket dependency fix) to be merged first.

  • Flashed to ESP32-S3 dev board, asked MimiClaw a multi-step reasoning question. Previous firmware rebooted mid-response with rst:0xc. With this fix the response completed in 23 s without a reset.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced application stability during network operations by preventing unexpected timeouts that could occur during extended HTTP communication. Improved handling of blocking network requests provides greater reliability during slow or unstable network conditions, reducing potential application crashes and unexpected restarts.

Review Change Stack

  - prevents reboot when HTTP call blocks up to 120s
  - covers both direct and proxy paths
  - guards against phantom subscription if task was not previously subscribed
@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR adds Task Watchdog Timer (TWDT) protection to blocking HTTP operations in llm_proxy.c. The watchdog is temporarily disabled before network I/O and conditionally re-enabled afterward to prevent spurious timeout interrupts during legitimate blocking network calls.

Changes

Task Watchdog Protection for Blocking HTTP Operations

Layer / File(s) Summary
Watchdog handling around blocking HTTP operations
main/llm/llm_proxy.c
Header include of esp_task_wdt.h enables watchdog control APIs. Watchdog is conditionally disabled via esp_task_wdt_delete(NULL) before the direct HTTP request (esp_http_client_perform()) and before the proxy-path response read loop, then conditionally re-added and reset after blocking operations complete. Both code paths use the same pattern: capture success of deletion, perform I/O, then conditionally restore the watchdog.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A watchdog watched with patient care,
But blocked on network, unaware—
Now timers rest when I/O flows,
And HTTP dances while async glows! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: exempting a task from the Task Watchdog Timer (TWDT) during blocking HTTP calls in llm_proxy, which directly addresses the core fix for preventing unintended software CPU resets.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@primalkz

Copy link
Copy Markdown
Contributor Author

@IRONICBo Would appreciate a review. Without this fix using local LLMs or models with slow inference times causes reboot mid gen, wasting tokens and breaking the session.

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