Repository navigation
fix(http): pre-warm CA bundle to stop concurrent-subagent TLS races (#131) - #150
Merged
Merged
Conversation
…es (#131) Parallel subagents (workflow/judge) share one std.http.Client across pool threads. On their first HTTPS connect they each lazily rescan the client's CA bundle (std.http.Client.zig: rescan → std.mem.swap into client.ca_bundle, then set client.now; later connects skip it once client.now is set). When several pool threads hit that cold path at once, two of them both pass the `client.now == null` check and both rescan+swap+deinit the bundle — one thread's swap/deinit yanks the bundle another thread is mid-handshake with, so its tls.Client.init fails instantly with error.TlsInitializationFailed (ms=0, resp_bytes=0). Zig std flags the race itself: "TODO data race here on ca_bundle". This is exactly #131 (4 gpt-5.5 subagent calls, ms=0/resp_bytes=0) and the "TlsInitializationFailed (gave up after 6 attempts)" seen in #132. Fix: prewarmCaBundle() loads the bundle single-threaded right after each std.http.Client is created (main.zig session + oneshot paths), setting client.now so every later connect — including concurrent subagents — skips the rescan entirely and just reads the stable, immutable bundle. No race window. Verified: zig build; zig build test 152/152; a normal HTTPS turn still works (pre-warm is transparent). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #131.
Root cause — a CA-bundle data race in
std.http.Client, triggered by concurrent subagentsHer evidence: 4 gpt-5.5 subagent calls failed with
is_error:true, ms:0, resp_bytes:0; #132 names the actual error —network error: TlsInitializationFailed (gave up after 6 attempts).ms:0= failure at the transport layer before any network round-trip, and it only happens on concurrent subagent calls, never the sequential main agent.Parallel subagents (workflow/judge) share one
std.http.Clientacross pool threads (subagent.zig.client = ctx.client;http.zigeven notes it assumesfetchis thread-safe). On the first HTTPS connect,std.http.Clientlazily rescans the CA bundle:and the TLS handshake reads
&client.ca_bundle:When several pool threads make their first HTTPS connect simultaneously on a cold client, two both see
client.now == nulland both rescan →swap→deinit. One thread's swap/deinit yanks the bundle another thread is mid-handshake with → instanterror.TlsInitializationFailed. Onceclient.nowis set the path is skipped, so it only bites the first concurrent burst — exactly the intermittent subagent failures she saw.Fix
prewarmCaBundle()loads the bundle single-threaded right after each client is created (session + oneshot paths), settingclient.now. Every later connect — including all concurrent subagents — then skips the rescan and just reads the stable, immutable bundle. No race window, regardless of which client the subagents share.Verified
zig build·zig build test152/152 · a normal HTTPS turn still works (the pre-warm is transparent).Related
#132/#134 (the stall/drop-mislabeled-as-Esc issues) are a separate path already addressed by the #133/#134 stream work; this PR is only the
TlsInitializationFailedroot cause.🤖 Generated with Claude Code