Repository navigation
[P21] ci: stability tooling for 1.x - #350
Merged
Merged
Conversation
What keeps 1.x stable: one manifest at Swift 6.1, a CI job that fails on a breaking API change within the major, a doc comment on every public declaration, libFuzzer on the parsers and the HTTP server transports, and a threat model. Fuzzing found a leak: every started `Server` was kept alive; fixed here.
- FuzzStatelessHTTP: the tools/call header set carries Mcp-Param-Region, so the tools-call seed reaches its handler instead of being refused with -32020; a new tools/list header set does the same for the tools-list seed, which lacked MCP-Protocol-Version. - FuzzSSE copies the parser only at up to 8 offsets named by the input's first bytes, not at every byte, which made long lines quadratic; the header comment now says what the target does. - fuzz.sh runs every target when one fails and fails at the end, naming the failed targets. - api-breakage.sh unshallows a shallow clone before choosing the baseline and fails with a clear message when it cannot fetch the history and tags; outside a git checkout it says it skipped. - Server registers its notifications/cancelled handler once, not on every start, so restarting a server no longer stacks handlers. - Server.stop() cancels the request handlers still running, and those about to start, and the shared tools/list schema pass: their responses can no longer be sent.
- CONTRIBUTING.md and CLAUDE.md: `scripts/ci-linux.sh fuzz 300` ran the `fuzz` job with its default 60 s, because `fuzz` is a job id and `300` became a second id pattern. They run the job as is, or `scripts/ci-linux.sh -- scripts/ci/fuzz.sh <seconds>` for longer runs. - api-breakage.sh: the default baseline is the newest release whatever major version HEAD develops, so a pull request that starts the next major version sets the job line to `api-breakage none` (or a ref) until X.0.0 is tagged. The message without a tag no longer says "1.x".
Server.stop() reset the per-connection request state but kept the handshake: isInitialized, the client info and capabilities, the negotiated protocol version and whether the connection served a stateless request. A stopped and restarted server answered the next handshake client's `initialize` with -32600 "Server is already initialized", and would otherwise have reported the previous client's info and capabilities. A handshake is per connection (2025-11-25 lifecycle, "Initialization"), so stop() now clears that state and the next connection starts from a fresh `initialize`. The stop() doc comment now says so. The new ServerLifecycleTests test restarts a server between two handshake clients with different info and capabilities; it fails without the fix.
Server.stop() set isInitialized to false and marked the requests not yet registered as cancelled before it awaited the transport's disconnect(), and cleared `connection` only afterwards. A request task spawned just before stop() ran its pre-dispatch checks first: with Configuration.strict it was refused with -32600 "Server is not initialized", and the error went out on the transport that was disconnecting, or on the next connection once start(transport:) had attached one. A request still waiting for its HTTP context lost its cancelled mark when the next connection reused its id, and then ran and answered on that connection. A request to the client sent just before stop() kept its id in unsentRequests, so its registration task, running during the disconnect or after a restart, registered a continuation that stop() had already drained and sent the request on the old transport: requestSampling, requestElicitation and listRoots never returned. stop() now increments a connection generation where it cancels the handlers. The receive loop passes the generation of its connection to handleRequest and handleBatch, and send(_:) records it for a request to the client. handleRequest returns without answering when the generation changed: at entry, in reject before any refusal is sent, after the await for the HTTP context, and after the handler. handleBatch sends nothing for a stopped connection. The registration task of a request to the client fails it with -32603 "Server disconnected", the error stop() gives the requests it drains. stop() clears startingRequests and unsentRequests, and a stale request no longer removes entries of startingRequests or pendingRequestTasks that may belong to the next connection. stop() clears `connection` before it awaits disconnect(), so nothing is sent on a transport that is disconnecting. Three ServerLifecycleTests tests fail without the fix: a request held at its HTTP context while the server restarts and the next connection reuses its id; a strict batch whose second call is handled while stop() disconnects; and requestSampling called while stop() disconnects.
- doc-coverage.swift: the `case` alternative of the declaration pattern could never match, because an enum case takes no access modifier, so enum cases were never checked. The script now finds the bodies of public enums by counting braces outside string literals and comments, and checks their `case` lines; the cases of private, internal and package enums (`CodingKeys`) and of `switch` statements are not checked. The 25 undocumented public cases (MCPError, Value, ProgressToken, InputResponse, Elicitation.RequestSchema.SchemaType, CreateElicitation.Result.Action, PrivateKeyJWTAssertionError) now have doc comments. CONTRIBUTING.md says cases are checked. - doc-coverage.swift: the walk over attributes took any line ending in `)` or `,` within 8 lines below an `@` line for the end of a multi-line attribute, so a declaration after one with an attribute, such as `public static let b = Foo(rawValue: "b")` after an `@available` constant, borrowed that constant's doc comment. A line now ends an attribute only when its parentheses balance on the `@` line above it. - fuzz: FuzzStatefulHTTP's only `tools/call` seed was a batch, which StatefulHTTPServerTransport refuses with 400 before the server reads it. The new seed tools-call.json is a single request; batch.json stays for the refusal path. FuzzDecode reuses one decoder and one encoder instead of creating them for each of its probes.
This was referenced Nov 25, 2026
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.
rel/1.0.0in order (previous: P20 (#351) · next: P22 (#349))conformance/p21-stabilityconformance/p20-api(stacked: GitHub retargets this PR torel/1.0.0when the previous part merges)9b0329eci: stability tooling for 1.x78582fcci: review fixes19bb5e5ci: second-pass review fixes5b61b01server: reset the handshake state when the server stops2bb29bbserver: answer nothing for a stopped connection3875c20ci: third-pass review fixesSummary
What keeps 1.x stable: one manifest at Swift 6.1, a CI job that fails on a breaking API change
within the major, a doc comment on every public declaration, libFuzzer on the parsers and the
HTTP server transports, and a threat model. Fuzzing found a leak: every started
Serverwaskept alive; fixed here.
Changes
Swift 6.1
[email protected]is removed.mainbuilds with Swift 6.0, but the stack no longerdoes (a non-
Sendableclosure inClient.swift), and no CI job used 6.0. README, quick start,DEPENDENCY_POLICY.md,CONTRIBUTING.md,CLAUDE.md, the design notes and the migrationguide say 6.1.
API breakage
scripts/ci/api-breakage.shrunsswift package diagnose-api-breaking-changes --products MCPagainst the newest
X.Y.Ztag withX >= 1that is an ancestor ofHEAD, and passes whenthere is none (today). A
jobsentry that gates and a GitHub job (macOS, fullhistory for the tags).
A stopped server is released
The default handlers and the cancellation handler are stored on the server and captured it
strongly, so a started server was never freed: an application with a server per session
leaked one per session. They capture it weakly. A test checks that a stopped server and client
are released; without the fix it fails. The bug is in
main; the migration guide lists itunder the behavior changes.
Doc comments
scripts/doc-coverage.swiftlists the public declarations inSources/MCPwithout a///comment (skipping attributes, including multi-line ones; exempting
Methodplumbing). It found275; each now has one, describing what the code does. The
docsjob runs it.Fuzzing
fuzz/Package.swiftmainfuzz/Sources/FuzzDecodefuzz/Sources/FuzzSSEServerSentEventParser: a body below the line limit never fails, and a parser resumed from a copy after every byte gives the same eventsfuzz/Sources/FuzzStatelessHTTP,FuzzStatefulHTTPinitializefor the stateful one; every answer has a valid status, and the previous input's server and transport must have been releasedfuzz/corpus/scripts/ci/fuzz.sh-sanitize=fuzzer,address, runs each target (60 s by default); a crash input lands in.build/fuzz/artifacts/. Linux only; elsewhere it passes and says soscripts/ci/jobs,ci.yml,scripts/ci-linux.shfuzzjob that gates; GitHub keeps crash inputs;ci-linux.shcopies them outLeakSanitizer is off: Swift stores pointers inside enum payloads (
Data, for one) with sparebits set, so it reports reachable globals (187 bytes, constant). The release check in the HTTP
targets replaces it; before the server fix LeakSanitizer reported 459 MB over 146 000 inputs,
and the release check fails at once.
Threat model
design/threat_model.md: trust boundaries, adversaries, each defense with its default bound(validation pipeline, era confusion, cross-client isolation,
requestState,Mcp-Param-*,client-side bounds, OAuth URL and redirect rules), what the SDK leaves to the HTTP framework,
and how it is tested.
design/design.mdindexes it andlinux.md.API changes
None beyond the Swift 6.1 floor (breaking: in the migration guide).
Behavior changes
A stopped server is released (migration guide, "Server default handlers").
Tests
897 swift-testing tests plus 101 XCTest; 982 on Linux. Fuzzing on ubi9: about 210 000 inputs
for
FuzzDecode, 140 000 forFuzzSSE, 130 000 forFuzzStatelessHTTPand 10 000 forFuzzStatefulHTTPin 30 s each, no failure.Verification
swift test; DocC builds with warnings as errors.9b0329e:scripts/ci/run-jobs.sh --stricton macOS andscripts/ci-linux.sh --strict allon ubi9 (withfuzz, 60 s per target) pass every job.api-breakageagainst a test tag: 0 breaks against P20 ([P20] api: the 1.0 rough edges #351), 126 against P18 ([P18] http: the same client on Linux and macOS #353) (all intended).ci.ymlparses.AI usage disclosure: the changes, the tests, the commit messages and this description were written with Claude Opus 5.5 and reviewed by the authors.