On this page

0247. Shared libcurl-multi HTTP transport

Context

HTTP, OpenAI-chat and agent transports duplicate curl subprocess code and buffer SSE bodies. A shared pull-based transport supports streaming, not one HTTP/MCP/A2A service. Harness must not implement cryptography. ADR-0166 rejected libcurl through FFI; ADR-0167 rejected shared transport. ADR-0181 specifies curl-config boundaries and remains Proposed.

Decision

Define capability-free http.transport.Transport: start(req) -> result<StreamId, HttpError>, poll(wait_ms) -> vec<Ready>, cancel(id) -> unit; implementations hold authority. Ready carries a stream id, chunks and optional terminal error. Requests carry Limits (connect_ms, optional total_ms, idle_ms, max_bytes). Pull results carry Chunk.Head(status, headers), Chunk.Data(bytes) and Chunk.End; failures use only the fixed HttpError: Connect, Tls, Timeout(str), Idle, TooLarge, Cancelled, Protocol, Denied.

Provide CurlMulti in runtime hrt_http.h, a CurlProcess adapter over the existing Runner (buffered; idle timeout degrades to total timeout), and Fake. Net.http requires libcurl >=8.4: detect with curl-config, then pkg-config, then -lcurl; compile-check LIBCURL_VERSION_NUM >= 0x080400 and check curl_version_info at runtime. Missing headers/library produce a diagnostic only for programs using Net.http; other programs are unaffected.

TLS always sets VERIFYPEER=1, VERIFYHOST=2. Use only libcurl's default CA store or the explicit HARNESS_CA_BUNDLE; never allow insecure mode. The interpreter will later use a compiled ffi-host-style helper for the same C implementation. Preserve ADR-0181 request boundaries on CurlProcess; the multi transport supports binary bodies and retains exact host grants, fixed errors, and no redirects, proxies or netrc. Raw libcurl errors/server bodies never become errors.

This supersedes ADR-0166's libcurl-via-FFI rejection while preserving no Harness crypto and serving TLS through a proxy. It partly supersedes ADR-0167 for shared HTTP/LLM transport only; no cross-protocol Service is introduced. It amends ADR-0181 so its request-config boundaries apply to CurlProcess.

Alternatives considered

Consequences

Core work: PR2 (types/Fake/CurlProcess), PR3 (multi runtime), PR9 (benchmarks). Held, not approved by this ADR: PR6 (shared SSE/redaction, OpenAI migration) and M14 PR4 (Net.http CLI native), PR5 (interpreter), PR7 (Anthropic/agent), PR8 (async ModelPort), PR10 (cleanup). All held work needs separate approval. Only Net.http users require libcurl development files; explicit CurlProcess remains available. This ADR ships no implementation; platform detection and TLS-on measurements remain work.

Acceptance notes (2026-11-15)

Maintainer accepted this ADR on 2026-11-15 and approved merging PR1–3 and PR9. The PR9 benchmark's p95 time-to-first-byte regression at 50 concurrent streams (80 ms with CurlMulti versus 58 ms with CurlProcess) is accepted for now; a multi-threaded reactor is possible future work if it matters. PR6 (shared SSE/redaction and the OpenAI codec migration) waits until M14 is done, together with the other held PRs.