Repository navigation
fix(autoresearch): time the RP HTTP server on stall, not total elapsed - #4219
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe 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 ChangesRP2350W request timeout handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
…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
…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]>
The bug
AutoResearchNet.cppdropped any request still in flight 2 s after accept, closing the socket without writing a response:That is a total elapsed budget measured from accept. A 4096-byte
POST /echobody 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-peerrun:received_hashis0x811C9DC5— the FNV-1a offset basis, i.e. the hash of zero bytes. Combined withreceived_bytes=0andstatus_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
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 /pingandGET /rpc/pingreturning 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
408 Request Timeoutresponse before the connection closes.