fix(interpreter): build the HTTP client lazily so start-up needs no CA store - #657
Conversation
…A store `IoClient::new` called `reqwest::Client::new()`, which unwraps the TLS builder rather than returning its error. That builder fails with "No CA certificates were loaded from the system" on any machine whose trust store is empty, so the interpreter aborted before the first statement of *every* WFL program on such a machine - including programs that never make a request. The 2026-07-29 nightly caught this the first night the new static-musl job ran its Debian 12 portability gate: `debian:12-slim` ships no `ca-certificates`, so the shipped tarball panicked running TestPrograms/basic_syntax_comprehensive.wfl. `wfl --version` and `wfl-lsp --version` passed in the same container, so the wfl#616 glibc property the gate exists for is fine - this is a separate defect the gate happened to expose, and it matters most exactly where a static musl binary is meant to shine: minimal container images. Build the client on first use behind a `OnceCell` instead. Start-up no longer touches the trust store, the client is still shared (one connection pool per interpreter), and a genuinely unusable TLS stack now surfaces as an ordinary WFL runtime error at the request that needs it rather than killing the process. Refs: run 30426901237, #616
|
Warning Review limit reached
Next review available in: 51 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesLazy HTTP client initialization
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/interpreter/mod.rs`:
- Around line 17673-17685: Update http_client_is_built_once_and_reused to handle
http_client() as a checked Result, skipping or returning cleanly when TLS
initialization fails while retaining pointer reuse assertions for successful
construction. Add coverage for a WFL request that triggers lazy client
initialization without try/when, ensuring the failure is surfaced as a catchable
RuntimeError rather than terminating interpreter startup.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: b77af559-ce5f-4443-8533-14c4ab94c057
📒 Files selected for processing (1)
src/interpreter/mod.rs
Co-authored-by: Codesmith <codesmith-bot@users.noreply.github.com>
What was broken
The Nightly Build failed this morning — run 30426901237 (2026-07-29 06:02 UTC,
main@cded008).The new
Build WFL for Linux (static musl)job (added yesterday in #656) failed at "Prove portability on Debian 12 (wfl#616 regression gate)". Because the release jobneedsit, no nightly release was published today, even though the Windows build was green.Root cause
IoClient::newbuilt the shared outbound HTTP client eagerly withreqwest::Client::new(), which unwraps the TLS builder instead of returning its error. reqwest 0.13 resolves roots throughrustls-platform-verifier, and that fails when the system trust store is empty — so the interpreter aborted before the first statement of every WFL program on such a machine, whether or not the program touched the network.debian:12-slimships noca-certificates, so the gate hit it immediately. Two things worth separating:./wfl --versionand./wfl-lsp --versionboth ran fine in the same container — those don't construct anInterpreter. The wfl#616 property the gate exists to protect is intact; the gate exposed a different, pre-existing defect on its first night.Installing
ca-certificatesin the gate would have turned CI green while leaving that defect shipped, so this fixes the product instead.The fix
One file,
src/interpreter/mod.rs:IoClient::http_clientbecomes aOnceCell<reqwest::Client>, built on first use by a new fallibleIoClient::http_client()accessor (once_cellwas already a direct dependency).http_get,http_post,http_request,open_http_stream) becomeself.http_client()?.... All four already returnResult<_, HttpClientError>, so a build failure now surfaces through the existinghttp_client_errorpath as a normal WFL runtime error.Behaviour on a healthy system is unchanged: same builder, same settings, still one shared client (one connection pool per interpreter) — a test pins that. On a system with no CA store, start-up now succeeds and only a program that actually performs a request gets an error, instead of the process dying.
Two regression tests added alongside the existing
IoClienttests:io_client_new_does_not_build_the_http_client— the structural invariant. Does not compile against the eager field, which is the point.http_client_is_built_once_and_reused— guards against a naive "build per request" fix that would silently drop connection pooling.Verification
Local, Linux aarch64, rustc 1.97.1:
cargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warningscargo test --libAnd the failure itself was reproduced and confirmed fixed, using
SSL_CERT_FILE/SSL_CERT_DIRpointed at a nonexistent path to simulate the empty trust store:wfl TestPrograms/basic_syntax_comprehensive.wflmain)client.rs:2507:38panicmain)Not run locally:
cargo test --all(integration/database lanes need a release build and DB services, and the sandbox ran out of disk) and the Windows/MSI lanes. CI covers both here.Note
Automated triage PR from the WFL repo warden — opened for a human to review and merge. I have not merged it. Once it lands, a
workflow_dispatchof Nightly Build frommainwill confirm the gate passes and a release publishes.Posted by the WFL repo warden (automated triage pass).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is enabled.Summary by CodeRabbit