Skip to content

Fix SnapshotState decoders dropping ChatState#290

Merged
connor4312 merged 1 commit into
microsoft:mainfrom
friggeri:friggeri-fuzzy-couscous
Jun 30, 2026
Merged

Fix SnapshotState decoders dropping ChatState#290
connor4312 merged 1 commit into
microsoft:mainfrom
friggeri:friggeri-fuzzy-couscous

Conversation

@friggeri

Copy link
Copy Markdown
Contributor

Why

SnapshotState is an untagged union; each client distinguishes its variants structurally by probing for distinctive required fields. Those probes still keyed off a summary field that was removed when SessionState was flattened (commit 80454fd), breaking snapshot decoding:

  • Swift and Kotlin never attempted ChatState, so chat snapshots failed to decode (Swift threw; Kotlin fell through to Root).
  • Go probed for summary on both the session and chat branches, so both silently decoded as Root.

Approach

Fixed the decoders in the generators (scripts/generate-*.ts) and regenerated the clients. Disambiguation now uses real required fields: session -> lifecycle, chat -> turns, terminal -> content, changeset -> status + files, resource-watch -> root + recursive, annotations -> annotations, root -> catch-all. Swift and Kotlin gained the missing chat branch. Rust already decoded correctly via its #[serde(untagged)] enum, so only its stale doc comment changed.

Notes for reviewers

  • Session is probed before annotations because SessionState carries an optional annotations summary that reuses the same key.
  • Added a Go regression test (TestSnapshotStateVariants) round-tripping every variant.
  • Verified locally: Go build + tests, Rust build, Swift build, and repo typecheck/lint/verify:changelog/type tests pass. Kotlin couldn't be compiled locally (no JVM); generated output verified by inspection.

The SnapshotState union decoders in the Swift, Kotlin, and Go generators
discriminated variants on a `summary` field that was removed when commit
80454fd flattened SessionState. As a result:

- Swift and Kotlin never attempted ChatState at all, so chat snapshots
  failed to decode (Swift threw; Kotlin fell through to Root).
- Go probed for `summary` on both the session and chat branches, so both
  silently fell through to the Root catch-all.

Switch disambiguation to the real distinctive required fields — session on
`lifecycle`, chat on `turns` — and add the missing chat branch to Swift and
Kotlin. Rust already decoded correctly via its untagged enum; only its stale
doc comment is updated.

Adds a Go regression test covering every SnapshotState variant.

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

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree company="Microsoft"

@connor4312 connor4312 enabled auto-merge (squash) June 30, 2026 16:06
@connor4312 connor4312 closed this Jun 30, 2026
auto-merge was automatically disabled June 30, 2026 17:25

Pull request was closed

@connor4312 connor4312 reopened this Jun 30, 2026
@connor4312 connor4312 merged commit 4a998d5 into microsoft:main Jun 30, 2026
15 checks passed
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.

4 participants