Skip to content

fix(autoresearch): time the RP HTTP server on stall, not total elapsed - #4219

Merged
zackees merged 1 commit into
masterfrom
fix/rp-http-server-stall-timeout
Sep 8, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/rp-http-server-stall-timeout

Conversation

@zackees

@zackees zackees commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

The bug

AutoResearchNet.cpp dropped any request still in flight 2 s after accept, closing the socket without writing a response:

if (static_cast<int32_t>(millis() - state.request_started_ms) >= 2000) {
    state.client->stop();     // no response written
    state.client.reset();
    resetRpPeerRequest(state);
    return;
}

That is a total elapsed budget measured from accept. A 4096-byte POST /echo body arrives across several TCP segments over CYW43 SoftAP and can legitimately outrun it, so the server reaped the connection mid-transfer.

Captured signature

From the ESP32-C6 side of a --net-peer run:

POST /echo 4096-byte FNV-1a   passed=False
  expected_hash=4277923066    received_hash=2166136261
  received_bytes=0            status_code=-1

received_hash is 0x811C9DC5 — the FNV-1a offset basis, i.e. the hash of zero bytes. Combined with received_bytes=0 and status_code=-1, the client got no response at all rather than a corrupted one.

The body-accumulation loop is not at fault; it correctly returns to await more data on a partial body. It was the deadline above that killed the connection out from under it.

This is the server-side twin of #4173 / #4196, which fixed the same "to a deadline, not to completion" mistake in the RP HTTP client.

The fix

  • Refresh a progress watermark on every header and body byte consumed.
  • Drop only after 2 s of no progress (a genuinely stalled peer is still reaped as fast as before).
  • Keep a 10 s absolute ceiling so a slow-loris cannot occupy the single-client server indefinitely.
  • Answer 408 Request Timeout instead of closing mutely, so a real timeout is reported as one rather than surfacing as a transport error.

Honest limit on verification

This is diagnosed from the captured signature plus the code path — not demonstrated end-to-end.

The peer link on this bench is currently flaky for reasons unrelated to this change. Across four runs today the failure moved between three different points (4 KiB echo returning zero bytes; GET /ping and GET /rpc/ping returning an empty status line with the RP as client; WiFi association failing outright), and critically an unmodified baseline run fails too — at association. So no configuration reaches a clean 10/10 right now, and I cannot honestly claim this change fixes the observed symptom.

What it does stand on: the signature above is unambiguous about what happened, and the deadline it names is unambiguously capable of causing it. The same code shape was already accepted as a bug on the client side in #4196.

Worth re-running when the bench link is stable. I did not want to either sit on the diagnosis or overstate it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

Summary by CodeRabbit

  • Bug Fixes
    • Improved request timeout handling for single-client servers.
    • Slow requests now remain active while data continues to arrive, subject to an overall time limit.
    • Timed-out requests now receive a clear 408 Request Timeout response before the connection closes.

The RP peer server dropped any request still in flight 2 s after accept,
closing the socket without writing a response:

    if (millis() - state.request_started_ms >= 2000) {
        state.client->stop();   // no response written
    }

A 4096-byte POST /echo body arrives across several TCP segments over
CYW43 SoftAP and can legitimately outrun that budget, so the server
killed it mid-transfer. Captured signature from the C6 side:

    POST /echo 4096-byte FNV-1a  passed=False
      expected_hash=4277923066  received_hash=2166136261
      received_bytes=0          status_code=-1

received_hash is 0x811C9DC5, the FNV-1a offset basis -- the hash of zero
bytes. The body accumulation loop itself is correct and returns to await
more data; it was the deadline above that reaped the connection.

This is the server-side twin of #4173/#4196, which fixed the same
"to a deadline, not to completion" mistake in the RP HTTP *client*.

Measure a stall instead: refresh a progress watermark on every header
and body byte consumed, drop only after 2 s of no progress, and keep a
10 s absolute ceiling so a slow-loris cannot hold the single-client
server open. Answer 408 rather than closing mutely, so a real timeout is
reported as a timeout instead of as a transport error.

Honest limit: this is diagnosed from the captured signature and the code
path, not demonstrated end-to-end. The peer link on this bench is
currently flaky for unrelated reasons -- an unmodified baseline run
fails too, at WiFi association -- so no configuration reaches a clean
10/10 right now. The reasoning stands on the signature and the deadline
it names; it should be re-run when the bench link is stable.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51
@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: f5655392-12cb-4072-ab85-45d3ffb887bb

📥 Commits

Reviewing files that changed from the base of the PR and between 3ee4009 and 3ad5e4f.

📒 Files selected for processing (1)
  • examples/AutoResearch/AutoResearchNet.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The RP2350W peer server replaces the fixed two-second request deadline with a two-second stall timeout and a ten-second total limit. It updates progress during header and body reads and returns 408 Request Timeout before closing timed-out requests.

Changes

RP2350W request timeout handling

Layer / File(s) Summary
Progress tracking state
examples/AutoResearch/AutoResearchNet.cpp
RpPeerState stores last_progress_ms. Request reset and client acceptance initialize this watermark.
Bounded timeout flow
examples/AutoResearch/AutoResearchNet.cpp
pollNetServer refreshes progress during header and body reads, enforces stall and total request limits, and sends 408 Request Timeout before closing an incomplete exchange.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 3ad5e

The peer HTTP server now allows requests that continue making progress, caps total request duration, and returns HTTP 408 for stalled clients. No merge-blocking current-head risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: replacing the fixed total-elapsed timeout with stall-based timing for the RP HTTP server.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rp-http-server-stall-timeout

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.

@zackees
zackees merged commit d984bc2 into master Sep 8, 2026
26 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 8, 2026
zackees added a commit that referenced this pull request Sep 8, 2026
…on't

charge the peer for unserviced time

Three deadline corrections in the RP networking path, all the same shape
as the server-side fix merged in #4219.

1. runRpHttpRequestTest set one flat 2 s deadline covering the
   first-byte wait, the status line, every header and the body. A peer
   merely slow to start therefore failed the whole request, reported as
   an empty status line with body_read=0 -- which reads as a transport
   fault rather than a timeout. Now measures a stall refreshed by every
   byte read, with a 4 s ceiling.

2. runRpHttpPayloadEchoTest had the same flat shape (4 s for an entire
   4 KiB round trip) and reported its timeout as a hash mismatch against
   the FNV-1a offset basis, i.e. against zero bytes.

3. The server stall timer from #4219 measured wall time, but
   pollNetServer() is called once per loop() *after* the RPC queue is
   drained -- so a blocking handler starves it for seconds and the gap
   is charged to a peer that never went quiet. Service gaps over 100 ms
   are now credited back to both the stall watermark and the request
   budget.

Honest limit: none of these is demonstrated to fix the intermittent
peer-link failures on this bench. Each is justified by inspection and by
the precedent in #4219; the failures move between association, client
reads and server timeouts from run to run, so no configuration reaches a
clean 10/10 at present. Landing them as correctness fixes, not as a
claimed repair.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51
zackees added a commit that referenced this pull request Sep 9, 2026
…4221)

* fix(autoresearch): stall-based timeouts for the RP HTTP client, and don't
charge the peer for unserviced time

Three deadline corrections in the RP networking path, all the same shape
as the server-side fix merged in #4219.

1. runRpHttpRequestTest set one flat 2 s deadline covering the
   first-byte wait, the status line, every header and the body. A peer
   merely slow to start therefore failed the whole request, reported as
   an empty status line with body_read=0 -- which reads as a transport
   fault rather than a timeout. Now measures a stall refreshed by every
   byte read, with a 4 s ceiling.

2. runRpHttpPayloadEchoTest had the same flat shape (4 s for an entire
   4 KiB round trip) and reported its timeout as a hash mismatch against
   the FNV-1a offset basis, i.e. against zero bytes.

3. The server stall timer from #4219 measured wall time, but
   pollNetServer() is called once per loop() *after* the RPC queue is
   drained -- so a blocking handler starves it for seconds and the gap
   is charged to a peer that never went quiet. Service gaps over 100 ms
   are now credited back to both the stall watermark and the request
   budget.

Honest limit: none of these is demonstrated to fix the intermittent
peer-link failures on this bench. Each is justified by inspection and by
the precedent in #4219; the failures move between association, client
reads and server timeouts from run to run, so no configuration reaches a
clean 10/10 at present. Landing them as correctness fixes, not as a
claimed repair.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

* fix(autoresearch): start the exchange clock before connect(), and bound
the inner drain loop

Two review points, both valid.

The deadline was armed after WiFiClient::connect() returned, so the time
spent inside connect() -- exactly where an unreachable or slow peer
stalls -- fell outside the budget it was supposed to bound. Both request
paths now take their start timestamp before connect().

The echo receive loop drained bytes in an inner `while
(client.available())` that never re-checked expiry, so a peer streaming
without pause could hold it past the hard deadline; the outer check is
only reached once available() goes false. It now breaks on
echo_expired().

Verification is partial and I am not claiming more: the peer link is
intermittently failing on this bench for unrelated reasons, and the run
after this change failed in the C6 -> RP direction with the RP server
answering 408 on POST /echo -- the server-side path, which these
client-side changes do not touch. The client requests in the RP -> C6
direction ran without issue.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

* fix(autoresearch): keep the request ceiling absolute when crediting gaps

Review catch, and a bug I introduced in the previous commit. Crediting
an unserviced poll gap to request_started_ms as well as to the stall
watermark pushes the absolute ceiling forward on every gap, so a peer
that sends nothing at all can hold the single-client server
indefinitely -- which is precisely the case that ceiling exists to
bound. I defeated my own guard.

Only the stall watermark is credited now. That keeps the fairness
property intended (a peer is not judged silent over a window nobody was
reading) while the wall-clock budget stays a real bound.

Verification remains partial: this bench's peer link is intermittently
failing for unrelated reasons and the run after this change failed in
the C6 -> RP direction again, which is the server path these
client-side deadlines do not touch.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

* revert(autoresearch): drop the server-side service-gap credit from this PR

It was a regression, and the A/B is unambiguous.

Fix 3 of this PR credited unserviced poll gaps back to the RP peer
server's stall watermark and request budget. The intent was sound --
pollNetServer() runs once per loop(), so a blocking RPC handler starves
it and the gap should not be charged to the peer -- but the result was
worse than the problem:

  master (this change absent)   5 cycles, no 408 responses at all
  with the credit              cycle 1, server answers 408 on POST /echo
  with an absolute ceiling     cycle 1, server answers 408 on POST /rpc discover
  with a serviced-time ceiling cycle 1, server answers 408 on POST /rpc unknown
  with the change removed      10/10 cycles, zero 408s, exit 0

Three formulations, each moving the failing request without fixing it,
against a master that does not exhibit it. That is enough to stop: the
change is causing the 408s, whatever the mechanism.

The two client-side fixes remain and are what this PR is for: the
exchange clock now starts before connect(), and the echo drain loop
honours the hard deadline.

The starvation concern is real and still unaddressed. It wants the
netServerStats diagnostic from #4222 to establish which budget actually
fires before anyone tries again -- which is what I should have done
instead of guessing three times.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@zackees
zackees deleted the fix/rp-http-server-stall-timeout branch November 5, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant