Repository navigation
Reconnect and resend when Studio drops an idle connection - #889
Conversation
| auth.rebuild(prepared_request, response.request) | ||
|
|
||
|
|
||
| class IdleConnectionAdapter(HTTPAdapter): |
There was a problem hiding this comment.
This feels like the wrong fix - as you say in your open question "is a 60 second timeout right?" How would we know? Surely the better and more Pythonic alternative is to monitor for session disconnection and retry in that case? Rather than try to anticipate the problem, we catch and handle it. It's significantly easier to test also, and exactly replicates the reported error.
There was a problem hiding this comment.
Agreed. Replaced the idle-timeout eviction with catch-and-retry:
ReconnectingAdapter(request_utils.py) catchesConnectionErrorwrappingRemoteDisconnectedand resends on a fresh connection. It retries up topool_maxsizetimes, enough to work through every stale pooled connection.- Only
RemoteDisconnectedis retried, i.e. Studio closed the connection without responding. Timeouts, refusals and HTTP errors still raise, so a request Studio answered is never resent. - A file body is rewound to where it started before the resend. A body that can't be rewound (e.g. an iterator) raises instead.
STUDIO_CONNECTION_MAX_IDLEand the 60s threshold are gone.- The test is the reported error: the fake Studio reads the request and closes the connection without responding, and the run completes with one
create_channeldropped and resent. - Searched for other copies of the predict-the-idle-limit approach: the eviction adapter was the only one. Every Studio request (7
config.SESSIONcalls incommands.pyandmanagers/tree.py) goes through the mounted adapter.
c3775ea to
f5b3dd8
Compare
rtibbles
left a comment
There was a problem hiding this comment.
Poor test hygiene using real sleeps to simulate idle when we can surely do it a better way.
|
|
||
| class SlowBuildChef(TwoTopicChef): | ||
| def construct_channel(self, **kwargs): | ||
| time.sleep(2 * SERVER_IDLE_LIMIT) |
There was a problem hiding this comment.
Sleeping in a test is a bad idea - we should be making the disconnect happen deterministically, not relying on an idle timeout actually happening.
There was a problem hiding this comment.
Replaced the sleeps with an explicit switch. SilentDropStudio.go_idle() marks every connection that has already answered a request as dead, so the server silently drops the next request on it. Fresh connections still get answered.
- Searched the branch's tests for
time.sleep,time.monotonicandSERVER_IDLE_LIMIT. 3 sleeps matched, and I changed all 3:SlowBuildChef.construct_channel, theidle_reconnecting_sessionfixture, andtest_reconnecting_adapter_resends_through_proxy_after_drop. SERVER_IDLE_LIMITand the server's timing check are gone, and nothing on the branch's tests sleeps now.- With the adapter unmounted, the chef test still fails with
SystemExit.
Written by rtibblesbot, an LLM-based coding agent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
f5b3dd8 to
48c1c3d
Compare
|
Quick check on rtibblesbot's work on this PR: react 👍 helpful · 😕 mixed · 👎 not helpful. Reply with anything specific. |
Summary
config.SESSIONresends a request when a reused keep-alive connection fails withRemoteDisconnected, so the first request after a long build no longer fails.bytes/str, or a file it can rewind; streamed bodies and drops on fresh connections still raise._get_conn, covering proxied connections too.References
Fixes #883. First seen: https://community.learningequality.org/t/sushichef-script-to-import-a-channel-failing-with-connection-aborted/4073
Reviewer guidance
Suggested review: Full code review, then manual QA once the reviewer sets Needs QA.
add_nodes,create_channel) on any reset or broken pipe on a reused connection, since Studio applies it twice if it processed the request before the reset._get_connandpool_classes_by_scheme, pinned viaurllib3==2.8.0; requests'PreparedRequest._body_position, with no upper bound onrequests).RemoteDisconnectedand the channel to appear once with one exercise.tests/test_chef_integration.pyrun on CI only; the agent's sandbox blocks binding local ports.--token=<studio token>.AI usage
Claude Code traced the failure, wrote the adapter, fake-Studio tests and this description. Verified with the full test suite and prek.
Deviations from the issue spec
Written by rtibblesbot, an LLM-based coding agent.
🟡 Waiting for feedback
WAITING · on a reviewerLast updated: 2026-11-10 14:09 UTC