Skip to content

fix(swift): advertise generated PROTOCOL_VERSION on initialize#232

Open
colbylwilliams wants to merge 3 commits into
mainfrom
colbylwilliams/fix-swift-advertise-protocol-version
Open

fix(swift): advertise generated PROTOCOL_VERSION on initialize#232
colbylwilliams wants to merge 3 commits into
mainfrom
colbylwilliams/fix-swift-advertise-protocol-version

Conversation

@colbylwilliams

Copy link
Copy Markdown
Member

Problem

HostRuntime.swift contained a stale hard-coded constant:

/// ... the Swift types library doesn't ship one yet, so this is a constant string ...
/// TODO(codegen): source from generated types.
private let supportedProtocolVersion = "0.2.0"

This was wrong on two counts:

  1. The value "0.2.0" is stale — the protocol is now 0.4.0.
  2. The comment's premise was false — Version.generated.swift already exports PROTOCOL_VERSION and SUPPORTED_PROTOCOL_VERSIONS, and HostRuntime.swift already import AgentHostProtocol, so those symbols were always in scope.

Changes

  • HostRuntime.swift — replaced both protocolVersions: [supportedProtocolVersion] call sites (fresh-connect path at line 335, and the fall-back-from-reconnect path at line 347) with protocolVersions: SUPPORTED_PROTOCOL_VERSIONS. Deleted the stale constant and its now-incorrect doc comment/TODO.
  • MultiHostClientTests.swift — added testHostRuntimeAdvertisesSupportedProtocolVersionsOnInitialize: spins up a MultiHostClient with an InMemoryTransport fake host, captures the protocolVersions list sent in the initialize request, and asserts it equals SUPPORTED_PROTOCOL_VERSIONS and does not contain "0.2.0".
  • clients/swift/CHANGELOG.md — added a ### Fixed bullet under ## [Unreleased].

This is not a codegen change — no *.generated.swift file was modified and scripts/generate-swift.ts was not touched.

Validation

cd clients/swift/AgentHostProtocol && swift build && swift test
# All tests passed including testHostRuntimeAdvertisesSupportedProtocolVersionsOnInitialize

npm run verify:changelog   # ✅
npm run typecheck          # ✅
npm run lint               # ✅

Closes #224

Remove the stale hard-coded `private let supportedProtocolVersion = "0.2.0"`
constant from HostRuntime.swift. The comment attached to it claimed the Swift
types library didn't ship a version constant yet — that was already false.
The generated file Version.generated.swift has exported PROTOCOL_VERSION
and SUPPORTED_PROTOCOL_VERSIONS since protocol 0.4.0 (and HostRuntime.swift
already imports AgentHostProtocol, so those symbols were always in scope).

Changes:
- Replace both `protocolVersions: [supportedProtocolVersion]` call sites
  (lines 335 and 347, the fresh-connect and fall-back-from-reconnect paths)
  with `protocolVersions: SUPPORTED_PROTOCOL_VERSIONS`, so the client
  advertises the full negotiation list ["0.4.0", "0.3.0"] on every
  initialize call instead of the stale single version "0.2.0".
- Delete the now-obsolete constant declaration and its TODO(codegen) comment.
- Add MultiHostClientTests.testHostRuntimeAdvertisesSupportedProtocolVersionsOnInitialize
  which spins up a MultiHostClient with an InMemoryTransport fake host,
  captures the protocolVersions list sent in the initialize request, and
  asserts it equals SUPPORTED_PROTOCOL_VERSIONS and does not contain "0.2.0".
- CHANGELOG: add Fixed bullet to clients/swift/CHANGELOG.md.

Closes #224

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Swift MultiHostClient/HostRuntime protocol negotiation drift by removing a stale hard-coded protocol version and advertising the generated SUPPORTED_PROTOCOL_VERSIONS during initialize, with a regression test and changelog entry.

Changes:

  • Updated HostRuntime to pass SUPPORTED_PROTOCOL_VERSIONS into AHPClient.initialize(...) (including the reconnect→initialize fallback path).
  • Added an integration test that captures the initialize request’s protocolVersions and asserts it matches SUPPORTED_PROTOCOL_VERSIONS (and does not include "0.2.0").
  • Added a Swift client changelog bullet under ## [Unreleased]### Fixed.
Show a summary per file
File Description
clients/swift/AgentHostProtocol/Sources/AgentHostProtocolClient/Hosts/HostRuntime.swift Replaces stale per-runtime version constant usage with generated SUPPORTED_PROTOCOL_VERSIONS during initialize.
clients/swift/AgentHostProtocol/Tests/AgentHostProtocolClientTests/MultiHostClientTests.swift Adds a fake-host test harness to capture and assert advertised protocolVersions.
clients/swift/CHANGELOG.md Documents the user-visible fix in the Swift package changelog.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 3

Comment thread clients/swift/CHANGELOG.md Outdated
- CHANGELOG: remove hard-coded version list from Fixed bullet so it
  stays accurate if SUPPORTED_PROTOCOL_VERSIONS changes before release.
- InitVersionCapture: use explicit hasStored flag so subsequent store()
  calls are no-ops regardless of whether the first went through the
  waiter or captured path.
- testHostRuntimeAdvertises...: wrap capture.wait() in a 2-second
  timeout (withThrowingTaskGroup + TestTimeoutError) so the test fails
  quickly with a useful error rather than hanging indefinitely if the
  initialize params are never captured.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

AgentHostProtocol (Swift): MultiHostClient advertises a stale hard-coded protocolVersion "0.2.0" instead of PROTOCOL_VERSION (now 0.4.0)

3 participants