Skip to content

Skip the trust callback with system roots; retry the iOS protocol test on fresh clients - #2

Merged
gartnera merged 7 commits into
mainfrom
claude/gifted-carson-kzx7k9
Nov 9, 2026
Merged

gartnera merged 7 commits into
mainfrom
claude/gifted-carson-kzx7k9

Conversation

@gartnera

@gartnera gartnera commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Fixes the iOS integration failure on main in run 42427208429. The failing test was negotiates the expected protocol.

What failed

The test's client connected over HTTP/2 on its first call. It then made 10 more calls on that same pooled connection, and a pooled HTTP/2 connection never moves to HTTP/3. The retry loop could not recover.

Why first connections sometimes lose to TCP

URLSession races QUIC against TCP for each new connection, and starts TCP about 100 ms in. A QUIC handshake that's slow past that point loses:

  • Run 42427208429 (the failure on main), mid-suite: the system's certificate evaluation took 151 ms, against 2–10 ms everywhere else. The cause isn't visible; trustd wasn't recorded then.
  • Runs 42671165122 and 42680510479, first call after app launch: both the app and the Go server on the same machine stalled. The client took 66 ms to set up its QUIC connection, and the server processed the client's first QUIC packet 130 ms after it was sent, against 1–5 ms for every later connection. TCP won both times.

The plugin's URLSession delegate isn't the cause. CFNetwork's "Need to invoke to satisfy trust callback" step happens whether or not the delegate implements the trust challenge.

Changes

  • negotiates the expected protocol: now uses a fresh client per attempt. It reuses the helper the HTTP/3-only cases already used (harnessOverHttp3, renamed harnessNegotiating(protocol)). Each attempt is a client's first call, made before any Alt-Svc response, so on iOS reaching HTTP/3 still shows that http3Origins made the client try QUIC first.
  • Strict test removed: the first call to an HTTP/3 origin goes over HTTP/3 is covered by the case above. A fallback is now logged with debugPrint, not failed. README updated to match.
  • Warm-up: setUpAll makes one call on a throwaway client before the cases, so they start on a warm app and server. It logs which protocol the call got, without checking it.
  • URLSessionBridge: with the system's roots, the delegate no longer implements urlSession(_:didReceive:completionHandler:); it only ever answered performDefaultHandling. Only a bridge with its own trusted roots (the native XCTests) implements it, in a TrustingDelegate subclass with an explicit @objc selector. This is simpler, not a fix for the race.
  • CI: records trustd in the simulator's network log.

Verification

All jobs green on 4beab36, including the native XCTests, which trust the test CA only through TrustingDelegate. CI on the warm-up commit is running.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW

…tocol case on fresh clients

Run 42427208429 failed "negotiates the expected protocol" on main: its client's first connection went over HTTP/2,
and the case then made 10 more calls on that same pooled connection, which can never move to HTTP/3.

The simulator's network log shows why the race went to TCP. The server answered the QUIC Initial in 4 ms, but the
client's certificate check ("external verify block") took 151 ms, against 3-8 ms for every other connection in the
run. URLSession started TCP 100 ms in, and TCP finished first. The check goes through the app because
URLSessionBridge's delegate implemented the session trust challenge for every session, even in the plugin, where it
only answered performDefaultHandling. CFNetwork then sends every handshake's certificate check (QUIC and TCP alike)
to the delegate queue: the bridge's single serial queue, which also carries every call's callbacks. Only a bridge
with its own trusted roots (the native tests) now implements the challenge, in a TrustingDelegate subclass.

Tests: the protocol case now uses a fresh client per attempt, sharing the helper the HTTP/3-only cases already used
(harnessOverHttp3, now harnessNegotiating). Each attempt is a client's first call, so on iOS reaching HTTP/3 still
shows that http3Origins made it try QUIC first. That covers the strict "first call goes over HTTP/3" case, which is
dropped: a single fallback under CI load is logged, not failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
…ate callback

URLSessionBridge's delegate no longer implements the authentication challenge at all. URLSession has no other way to
add trust anchors (pinning in Info.plist can only narrow the system's trust), so any custom roots mean a callback that
every TLS handshake's certificate check waits on, through the bridge's serial queue. The previous commit kept that
path for the native XCTests' own CA; this drops it and trustedRoots with it, so the tests exercise the same handshake
path the plugin ships.

The tests trust the server's CA through the trust store instead: run_integration_tests.sh already adds it to the
simulator's keychain before either suite, so the native suite just stops passing SERVER_CA. The macOS swift-core job
adds it to the runner's System keychain, and the README's local loop says how, and how to remove it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
The delegate wasn't what held the QUIC handshake. The simulator log shows CFNetwork's "auth completion disp=1"
(performDefaultHandling) in the same millisecond it asked the delegate; the 151 ms went to the system's own default
trust evaluation, during which the app logged nothing at all for 88 ms: a CPU-starved simulator, not the bridge. The
same evaluation took 218 ms at app launch. Restore the delegate, trustedRoots and the native tests' SERVER_CA as they
are on main, and the swift-core job without the keychain step.

What stays from this branch is the test fix: the protocol case tries fresh clients, since a client that connected
over HTTP/2 keeps that connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
@gartnera gartnera changed the title Stop routing TLS trust checks through the bridge queue; stabilize the iOS protocol test Retry the iOS protocol test on fresh clients Nov 9, 2026
In run 42427208429 one certificate evaluation took 151 ms, against 2-10 ms for the rest of that run and two earlier
green runs, and URLSession's TCP attempt won the race. The bridge's delegate answered performDefaultHandling within a
millisecond; the rest happened in the system's evaluation, which runs in trustd, outside the recorded processes. With
trustd recorded, the next slow evaluation shows what it waited on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
… roots

The plugin's delegate implemented urlSession(_:didReceive:completionHandler:) even though, with no trusted roots of
its own, it only ever answered performDefaultHandling. Implementing it at all makes CFNetwork ask the delegate before
its own certificate check on every TLS handshake ("Need to invoke to satisfy trust callback"), so each handshake
waits for the bridge's serial queue.

In run 42671165122 (attempt 2), at app launch, that answer came 126 ms after CFNetwork asked, while trustd was idle.
The app's network thread did nothing in between, the server's QUIC reply sat unprocessed, and the first call went
over HTTP/2.

Only a bridge with its own trusted roots (the native XCTests) now implements the challenge, in a TrustingDelegate
subclass; the shipped plugin leaves certificate checks to the network stack. The subclass names the Objective-C
selector explicitly, since URLSession finds optional delegate methods by selector.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
@gartnera gartnera changed the title Retry the iOS protocol test on fresh clients Skip the trust callback with system roots; retry the iOS protocol test on fresh clients Nov 9, 2026
Run 42680510479 still logs CFNetwork's "Need to invoke to satisfy trust callback" and "auth completion disp=1" with
no challenge method on the delegate, so that step is CFNetwork's own and not caused by implementing the method; the
126 ms before it in the previous run wasn't the bridge's queue. In both runs the launch-time first call lost the race
because the whole runner was slow then: the client took 66 ms to set up its QUIC connection, and the Go server
processed its first QUIC packet 130 ms after it was sent, against 1-5 ms for every later connection.

Not implementing the challenge with the system's roots stays, as the simpler setup; the comment no longer claims it
fixes the race.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
The first call after the app launches lost URLSession's QUIC/TCP race in both of the last two runs: the simulator took
66 ms to set up its QUIC connection and the test server, on the same runner, answered its first QUIC packet 130 ms after
it was sent. setUpAll now makes one call on a throwaway client first and logs which protocol it got, without checking
it, so the cases start on a warm app and server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
@gartnera
gartnera merged commit 20fa431 into main Nov 9, 2026
6 checks passed
@gartnera
gartnera deleted the claude/gifted-carson-kzx7k9 branch November 9, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants