Skip to content

ASCRegister apply HTTP 409 on first leaderboard POST — wrong Apple API shape #17

Closed

Description

@wei18

Discovered during Phase 10 A2

`swift run ASCRegister apply` hit `HTTP 409` on `POST /v1/gameCenterLeaderboards` for the first leaderboard. ASC rejected with 5+ specific errors that match the inline `// UNCONFIRMED` markers in `ASCClient.swift` / `Config.swift`. Reconciler is idempotent and aborted cleanly — zero entities entered ASC.

ASC error details (verbatim, captured via the recently-added error context DX)

```
path: /v1/gameCenterLeaderboards
status: 409
errors:

  1. ENTITY_ERROR.ATTRIBUTE.TYPE recurrenceRule: Expected STRING but got OBJECT
  2. ENTITY_ERROR.ATTRIBUTE.TYPE defaultFormatter: Expected STRING but got OBJECT
  3. ENTITY_ERROR.ATTRIBUTE.TYPE defaultFormatter: '' not valid; expected one of:
    INTEGER, DECIMAL_POINT_1_PLACE, DECIMAL_POINT_2_PLACE, DECIMAL_POINT_3_PLACE,
    ELAPSED_TIME_CENTISECOND, ELAPSED_TIME_MINUTE, ELAPSED_TIME_SECOND,
    MONEY_POUND_DECIMAL, MONEY_POUND, MONEY_DOLLAR_DECIMAL, MONEY_DOLLAR,
    MONEY_EURO_DECIMAL, MONEY_EURO, MONEY_FRANC_DECIMAL, MONEY_FRANC,
    MONEY_KRONER_DECIMAL, MONEY_KRONER, MONEY_YEN
  4. ENTITY_ERROR.ATTRIBUTE.UNKNOWN scoreFormat: not an attribute on gameCenterLeaderboards
  5. (truncated, 591 more bytes — likely more about scoreRangeStart / scoreRangeEnd)
    ```

Root cause

5 `// UNCONFIRMED:` markers landed during initial ASCRegister authoring (PR #2) were guesses based on incomplete Apple docs. ASC's actual contract is stricter:

Our code (wrong) Apple's actual API
`attributes.scoreFormat` (object) `attributes.defaultFormatter` (string enum)
`attributes.defaultFormatter` (nested object with scoreRangeStart/End) does not exist — those keys belong elsewhere
`attributes.recurrenceRule` (object with frequency/duration) string enum (likely `"DAILY"`)

Design decision (made 2026-05-20 with user)

Apple's elapsed-time formatters max out at `ELAPSED_TIME_CENTISECOND` (1/100 sec, 2 decimal places). `design.md §How.3.1` originally specified `mm:ss.SSS` (milliseconds, 3 decimals). Choice: adopt ASC ceiling.

  • ASC leaderboards use `ELAPSED_TIME_CENTISECOND`
  • `GameCenterClient.submitScore` divides Int64 ms by 10 before submitting (`elapsedMilliseconds / 10`)
  • Internal `PersonalRecord` retains ms precision (no loss internally)
  • `design.md §How.3.1` amended: `mm:ss.SSS` → `mm:ss.SS`, "毫秒" → "百分秒"

Scope of fix

Production code

  • `Packages/SudokuKit/Sources/ASCRegister/Config.swift`: `LeaderboardConfig` — rename/restructure to match ASC fields (`defaultFormatter: String`, `recurrenceRule: String`); remove `scoreFormat`
  • `Packages/SudokuKit/Sources/ASCRegister/ASCClient.swift`: `createLeaderboard` body — `scoreFormat` → `defaultFormatter` (string); `recurrenceRule` → string; remove the nested `defaultFormatter` object
  • `Packages/SudokuKit/Sources/GameCenterClient/GameCenterSink.swift` (or wherever submitScore is wired): divide submitted ms by 10
  • `Packages/SudokuKit/Sources/GameCenterClient/LeaderboardIDs.swift`: confirm no change needed (ID format unchanged)

Spec

  • `docs/design.md §How.3.1`: format spec from `mm:ss.SSS` to `mm:ss.SS`, language updated

Tests

  • `Packages/SudokuKit/Tests/ASCRegisterTests/ConfigConsistencyTests.swift`: assert formatter == `ELAPSED_TIME_CENTISECOND`
  • New GameCenterClient test: submitScore(ms: N) results in actual submission of N/10

Acceptance

  • `swift test` 340 → matches new test count after additions
  • `swift run ASCRegister apply` against the user's tenant succeeds (33/33 actions complete)
  • design.md §How.3.1 reflects centisecond precision

Discovered by

`@wei18 + ASCRegister apply error 2026-05-20`. The 5 `// UNCONFIRMED` markers in source are exactly what got hit — this is the validation they were waiting for.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions