Skip to content

[P34] ci: build for iOS and run the tests on its simulator - #337

Merged
jeanmatthieu merged 4 commits into
rel/1.0.0from
conformance/p34-apple-platforms
Nov 25, 2026
Merged

jeanmatthieu merged 4 commits into
rel/1.0.0from
conformance/p34-apple-platforms

Conversation

@jeanmatthieu

@jeanmatthieu jeanmatthieu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
Part P34 of P0–P35, merged into rel/1.0.0 in order (previous: P33 (#338) · next: P35 (#336))
Branch conformance/p34-apple-platforms
Base conformance/p33-transport-release (stacked: GitHub retargets this PR to rel/1.0.0 when the previous part merges)
Commits 4e87ad8 client: cancel the task of a tools/call cancelled as its answer arrives
d181ebc ci: build for iOS and run the tests on its simulator
ad57600 docs: bring AGENTS.md up to date with the stack
91be03f client: review fixes for the iOS PR
Size 15 files, +606 / -187

Summary

The package builds for iOS, and CI checks it: a new apple-ios job builds every target, test bundles included, for the iOS device SDK and runs MCPTests and SnippetTests on an iOS simulator. The job script takes any platform of Package.swift (iOS, tvOS, watchOS, visionOS, Mac Catalyst), so gating another one later is one line in scripts/ci/jobs and one matrix entry in ci.yml. Running the suite on simulators also found a client race that could leave a server task running after its caller was cancelled; the first commit fixes it. A last commit brings AGENTS.md, which arrived with main (#318), up to date with the whole stack.

Motivation

Building the mcp-swift-sdk-Package scheme for iOS failed:

interop/swift-client/main.swift:821:26: error: cannot find type 'Process' in scope

Process does not exist on iOS, tvOS, watchOS or visionOS (Mac Catalyst is os(iOS)). The interop client, the HelloClient example and a docs snippet use it to start a server. Nothing in CI built for those platforms, so nothing caught it.

Changes

client: cancel the task of a tools/call cancelled as its answer arrives

  • Cancelling the caller of a tools/call resolves the request's slot at once and leaves the rest (marking the call abandoned, telling the server) to cancelRequest, which runs later on the actor. A response handled in between found the call neither pending for the caller nor abandoned: the slot dropped it, and with it the only copy of the id of the task the server had created, so the task ran on. A heavily loaded visionOS simulator hit it in "Cancelling the caller cancels the task on the server".
  • ResponseSlot.resolve and AnyPendingRequest.resume report whether their outcome is the one the sender gets (Sources/MCP/Base/PendingRequest.swift).
  • handleResponse treats a tools/call answer the slot refused as abandoned and sends tasks/cancel for the task in it, as it already did for an answer that arrives after cancelRequest (Sources/MCP/Client/Client.swift).

ci: build for iOS and run the tests on its simulator

  • The interop client's --stdio, HelloClient and the transport-stdio-client snippet sit behind #if !(os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)) (the snippet behind os(macOS), like its sibling in Client.swift). There --stdio throws and HelloClient prints why and exits 1. The woven docs are unchanged.
  • scripts/ci/apple-platform.sh <iOS|tvOS|watchOS|visionOS|macCatalyst> [<destination id>]:
    • xcodebuild build-for-testing of the mcp-swift-sdk-Package scheme (every target, test bundles included) for the device SDK, unsigned;
    • then xcodebuild test on the first simulator -showdestinations offers (this Mac for Mac Catalyst), with the result bundle in .build/apple/<platform>/Tests.xcresult;
    • a missing SDK or simulator runtime fails with the command that installs it; on Linux the job passes and says so, as fuzz does on macOS.
  • scripts/ci/jobs gains apple-ios; .github/workflows/ci.yml an apple-platforms matrix (iOS) on macos-latest that uploads the result bundle on failure.
  • Conformance and interop do not run on these platforms: their harnesses start the fixtures as host processes.
  • CONTRIBUTING.md, CLAUDE.md and CHANGELOG (Fixes) describe the job and the fix.

docs: bring AGENTS.md up to date with the stack

  • AGENTS.md described main's tree. It now gives the two revisions the SDK serves (2025-11-25 through the handshake, 2026-07-28 per request) and ProtocolProfile, the repository map (conformance/, interop/, fuzz/, Examples/, docs/src/, design/, scripts/ci/; one manifest), the dependencies, toolchains and platform gates, the commands, VERSIONING.md from 1.0.0 with the api-breakage job, the generated files not to edit by hand, and the test and documentation rules.
  • One rule is reversed: handlers that Client or Server store on themselves capture self weakly, because a strong capture is a retain cycle that keeps every started server alive (fixed in P21 ([P21] ci: stability tooling for 1.x #350)).

Behavior changes

  • A tools/call cancelled while the server's answer creating a task is already on its way now gets tasks/cancel for that task; before, the task could keep running until its TTL.
  • On iOS, tvOS, watchOS and visionOS, mcp-interop-client --stdio fails with a message and HelloClient exits 1. Both only compile there.

Tests

  • LateTaskAnswerTests.cancelRacesAnswer: a hand-driven peer answers each of 500 tools/calls with a new task and cancels the caller as it answers; every task must get tasks/cancel. Without the fix about one run in five leaves an orphan on macOS (the window is narrow, hence the 500 calls).
  • Three tests that waited a fixed time failed once each under simulator load and now wait for the event: callerCancellation (up to 10 s instead of 2 s), testServerInitializeMetadata (MockTransport.waitForSentMessages instead of a 200 ms sleep) and the discovery timeout test (up to 10 s instead of 1 s).

Review notes

  • Only iOS gates. tvOS, visionOS and Mac Catalyst pass locally with the same script; watchOS was not run (no SDK on the test machine). Adding them costs one macOS runner each.
  • drive (ClientTasks.swift) still has a smaller window: at 2026-07-28 its first tasks/get, which runs only when the create result is not working, is outside the block that sends tasks/cancel on cancellation.

Verification

  • iOS, tvOS, visionOS and Mac Catalyst: device build and simulator xcodebuild test, 1237 + 113 tests each; scripts/ci/run-jobs.sh apple-ios passes (77 s).
  • macOS: swift test 1237 tests in 135 suites + 113 snippet tests (twice); swift scripts/weave.swift --check; mcp-interop-client --stdio against HelloServer.
  • Linux (swift:6.1-rhel-ubi9, scripts/ci-linux.sh build-test): 1334 tests and the hello example; apple-ios skips there.

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.

Cancelling the caller of a tools/call resolves the request's slot at
once and leaves the rest (marking the call abandoned, telling the
server) to cancelRequest, which runs later on the actor. A response
handled in between found the call neither pending for the caller nor
abandoned: the slot dropped it, and with it the only copy of the id of
the task the server had created, so the task ran on. A heavily loaded
visionOS simulator hit it in "Cancelling the caller cancels the task on
the server".

- ResponseSlot.resolve and AnyPendingRequest.resume report whether
  their outcome is the one the sender gets.
- handleResponse treats a tools/call answer the slot refused as
  abandoned and sends tasks/cancel for the task in it, as it does for
  an answer that arrives after cancelRequest.

Tests: LateTaskAnswerTests.cancelRacesAnswer, a hand-driven peer that
answers each of 500 calls with a task and cancels the caller as it
answers; every task must get tasks/cancel. Without the fix about one
run in five leaves an orphan on macOS. callerCancellation waits up to
10 s instead of 2 s for the server task to stop.
Building the package scheme for iOS failed: the interop client, the
HelloClient example and a docs snippet start a server with Process,
which does not exist on iOS, tvOS, watchOS or visionOS (Mac Catalyst is
os(iOS)).

- The interop client's --stdio, HelloClient and the
  transport-stdio-client snippet sit behind
  `#if !(os(iOS) || os(tvOS) || os(watchOS) || os(visionOS))` (the
  snippet behind `os(macOS)`, like its sibling in Client.swift). There
  --stdio throws and HelloClient prints why and exits 1; the woven docs
  are unchanged.
- scripts/ci/apple-platform.sh <iOS|tvOS|watchOS|visionOS|macCatalyst>
  [<destination id>]: xcodebuild build-for-testing of the
  mcp-swift-sdk-Package scheme (every target, test bundles included)
  for the device SDK, unsigned, then xcodebuild test on the first
  simulator -showdestinations offers (this Mac for Mac Catalyst), with
  the result bundle in .build/apple/<platform>/. A missing SDK or
  runtime fails with the command that installs it; on Linux the job
  passes and says so, as fuzz does on macOS.
- scripts/ci/jobs gains apple-ios; ci.yml an apple-platforms matrix
  (iOS) on macos-latest that uploads the result bundle on failure.
  Another platform is a line in each. Conformance and interop do not
  run there: their harnesses start the fixtures as host processes.
- Two tests that waited a fixed time failed once each under the
  simulator's load: testServerInitializeMetadata waits for the sent
  message (MockTransport.waitForSentMessages), and the discovery
  timeout test waits up to 10 s for its POST to stop.
- CONTRIBUTING, CLAUDE.md and CHANGELOG describe the job.

Verified with Xcode 27.1: iOS, tvOS, visionOS and Mac Catalyst build for
the device and pass on the simulator (1350 tests); watchOS is not
installed here. macOS swift test, and build-test on Linux (RHEL UBI 9
through scripts/ci-linux.sh), pass.
AGENTS.md arrived with main (#318) and describes main's tree. Update
the facts that the conformance stack changed:

- The spec revisions: the SDK serves 2025-11-25 through the handshake
  and 2026-07-28 per request; code that serves both reads
  ProtocolProfile flags, and Version.supported lists both eras.
- The repository map: conformance/ (fixtures and baselines), interop/,
  fuzz/, Examples/ with the doc snippets, docs/src/, design/, and
  scripts/ci/. There is one manifest, Package.swift.
- Dependencies (swift-crypto and Yams; no eventsource), toolchains,
  the iOS simulator job, and the platform gates (SSE streams through
  the same code everywhere; Crypto with CryptoKit only for Secure
  Enclave keys; the Process gate).
- Commands: the conformance legs, doc coverage, weave, and the CI job
  runner.
- Stability: VERSIONING.md from 1.0.0, the api-breakage job, enum
  categories, and a deprecated shim that exists (Version.latest).
- Concurrency: handlers that Client or Server store on themselves
  capture self weakly, because a strong capture keeps the server
  alive; the previous text said the opposite.
- Tests and docs: expectWire golden tests, the handshake test
  configuration, the conformance baselines, the woven guides, the
  migration guide and CHANGELOG, and ROADMAP's SEP coverage table.
- Generated files (docs, README, baselines, interop results) are not
  edited by hand.
The late-answer tests drove only the 2026-07-28 shape, where the task is
the tools/call result; at 2025-11-25 it is nested in `task`, which
handleResponse also reads. A hand-driven peer, LatePeer, now answers in
either revision (initialize, a tool that runs only as a task, flat
tasks/get and tasks/cancel results at 2025-11-25), and both tests run at
both. Dropping the nested lookup fails both 2025-11-25 cases.

- cancelRacesAnswer expects every call to have reached the peer and
  created a task (race.isSettled): a callTool that failed before sending
  created no task and passed. A one-minute time limit turns a missed
  cancellation into a failure instead of a hang. At 2025-11-25 it also
  checks that every call asked for a task.
- clientCancelsOrphan waits up to 10 s for each step instead of sharing
  one 2 s deadline, and checks that tasks/cancel names the late task.
- callerCancellation waits for the task to run on the server instead of
  sleeping 100 ms before it cancels the caller.

scripts/ci/apple-platform.sh: a Mac whose Xcode lacks the platform's
SDK or a simulator runtime skips the job and says so unless CI is set
(GitHub Actions sets it), where it still fails. Before, running every
job locally failed on such a Mac.

Docs:
- CHANGELOG: the tasks/cancel of a call cancelled as its answer arrives
  joins the tasks feature, which is new in 1.0.0, and says that over
  HTTPClientTransport at 2026-07-28 an answer not yet read when the
  cancellation closes the response stream is lost and its task keeps
  running. The platform line says that CI checks iOS only.
- AGENTS.md: withTasks(_:) and withSkills(_:listInResources:) register
  their defaults, not Server.start; the process snippets gate on
  canImport(System) && os(macOS) because they also use System's
  FileDescriptor; swift-nio also backs the HTTP server example.
- CLAUDE.md: the job scripts include api-breakage, fuzz and
  conformance-scripts; the apple-* skip rule.
varun06
varun06 previously approved these changes Nov 25, 2026

@varun06 varun06 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already reviewed and still looking good.

Base automatically changed from conformance/p33-transport-release to rel/1.0.0 November 25, 2026 12:55
@jeanmatthieu
jeanmatthieu dismissed varun06’s stale review November 25, 2026 12:55

The base branch was changed.

@jeanmatthieu
jeanmatthieu merged commit 28063b9 into rel/1.0.0 Nov 25, 2026
@jeanmatthieu
jeanmatthieu deleted the conformance/p34-apple-platforms branch November 25, 2026 12:56
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