Skip to content

Fix Over Extension Use With Protocol Extension Implementation Pattern #399

Closed as not planned

Description

@leogdion
No description provided.

Activity

  1. added this to the v1.0.0-beta.4 milestone on Aug 20, 2026
  2. leogdion commented on Aug 20, 2026

    @leogdion
    MemberAuthor

    Survey: no genuine static-dispatch hazard found in Sources/MistKit/

    The issue body is empty, so I interpreted the title as the classic anti-pattern: a protocol requirement implemented in a protocol extension rather than on the conforming type, which makes the implementation statically dispatched and able to silently shadow a conformer's version.

    I surveyed every protocol declaration in Sources/MistKit/ (excluding the generated Sources/MistKitOpenAPI/), enumerated their declared requirements, and cross-referenced every extension <Protocol> in the module.

    Findings

    Protocol Extension member Location Declared requirement? Verdict
    RecordManaging queryAllRecords(recordType:) Sources/MistKit/RecordManagement/RecordManaging.swift:75 Yes (declared L64) Safe — witness-table dispatch; see note 1
    Authenticator defaultStorageIdentifier Sources/MistKit/Authentication/Authenticator.swift:96 Yes (declared L59) Safe — witness-table dispatch; see note 2
    RecordManaging sync<T>, list<T>, query<T>(_:where:) RecordManaging+Generic.swift:53,85,122 No Legitimate convenience
    RecordManaging where Self: CloudKitRecordCollection syncAllRecords, listAllRecords, deleteAllRecords RecordManaging+RecordCollection.swift:62,94,141 No Legitimate constrained convenience
    OperationInputPath init(containerIdentifier:environment:database:) Sources/MistKit/OpenAPI/OperationInputPath.swift:52 No (distinct signature from the L46 requirement) Textbook-correct
    ContainerOperationInputPath init(containerIdentifier:environment:) Sources/MistKit/OpenAPI/ContainerOperationInputPath.swift:49 No Textbook-correct
    RecordTypeIterating — — — No extension at all; sole conformer RecordTypeSet implements forEach directly
    CloudKitRecord, CloudKitRecordCollection, OperationFailureTarget, CloudKitErrorConvertible, CloudKitResponseType, TokenStorage, TokenManager — — — No protocol extensions at all

    Verdict

    The hazard does not occur anywhere in Sources/MistKit/. Every extension-provided member falls into one of two safe categories:

    1. It is a declared protocol requirement — so it goes through the witness table, and a conformer's implementation correctly wins even through an existential (any RecordManaging, any Authenticator). This is the supported "requirement + default implementation" pattern, not the shadowing bug.
    2. It has a genuinely different signature than anything the protocol declares (convenience overloads, extra defaulted params). These can never shadow a requirement.

    The shadowing bug requires an extension member that is not declared as a requirement but matches a conformer's method — there is no instance of that shape in the module.

    Two observations (not fixed here — deliberately out of scope)

    1. RecordManaging.queryAllRecords default (RecordManaging.swift:67-77) delegates to the deprecated single-page queryRecords(recordType:). It's a semantic trap, not a dispatch trap: a conformer that forgets to implement it compiles fine and silently truncates at 200 records. Dispatch is correct, and it already carries an @available(*, deprecated) annotation spelling out exactly this. All in-repo conformers (CloudKitService, MockRecordManagingService) and both Examples conformers override it, so nothing is currently broken. Deleting the default would force the decision at compile time but is a breaking public API change for external conformers — worth its own issue and a deliberate decision, not a drive-by refactor.
    2. Authenticator.defaultStorageIdentifier default (Authenticator.swift:93-98) is effectively dead: all three concrete authenticators (APITokenAuthenticator, ServerToServerAuthenticator, WebAuthTokenAuthenticator) override it. It is harmless and documents intent for third-party conformers. No behavioral risk either way.

    Neither is the bug this issue describes, and both changes are breaking-API decisions rather than clear fixes — so I implemented nothing for #399 and did not attach Closes #399 to the PR.

    Recommendation: close #399 as "no instances found", or re-scope it with a concrete example of the over-extension you had in mind (e.g. if it was about the CloudKitService+* file split, note that CLAUDE.md documents that split as an intentional organizational pattern, which is a different concern from protocol-extension dispatch).


    Surveyed on branch 398-399-mistdemo-phone-extensions.

  3. leogdion commented on Aug 20, 2026

    @leogdion
    MemberAuthor

    Concern: this issue needs a concrete example or it should be closed

    Following up on the survey above with the reviewer's view, since the outcome here is a judgment call rather than a code change.

    The survey found no instances of the static-dispatch hazard in Sources/MistKit/. I reviewed that conclusion and agree with it: every protocol-extension member in the module is either a declared requirement (so it dispatches through the witness table and a conformer's implementation correctly wins — the supported pattern, not the bug) or has a signature that cannot shadow a requirement.

    The risk I want to flag is that the title, read literally as "over extension use", could be taken as license for a sweeping refactor of the CloudKitService+* file family. That would be a mistake: AGENTS.md documents that split as an intentional organizational pattern, and splitting a concrete type's methods across extension files is unrelated to the protocol-extension dispatch hazard. No agent should act on this issue as written without a specific target.

    Two adjacent findings were deliberately left alone, since both are breaking public-API decisions rather than clear-cut fixes:

    • RecordManaging.queryAllRecords — its default implementation delegates to the deprecated single-page query, which is a semantic trap rather than a dispatch one. It is already annotated @available(*, deprecated) and overridden by every conformer, so the blast radius is small.
    • Authenticator.defaultStorageIdentifier — the default appears to be dead code.

    Recommendation: close this as "no instances found", or re-scope it with one concrete file and symbol that motivated it. As written the issue is not actionable, and an empty body invites a well-meaning agent to invent a refactor to satisfy it.

    If the original intent was one of the two findings above, say which and I'll open a targeted issue for it.

    🤖 Generated with Claude Code

  4. leogdion commented on Aug 28, 2026

    @leogdion
    MemberAuthor

    Closed by the survey in #425 (merged to v1.0.0-beta.4): the audit this issue asked for found no instances of the over-extended protocol-extension pattern in Sources/MistKit, so no code change was made. Reopen if a concrete case turns up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions