Skip to content

Kotlin/.NET/Go: select snapshot state by resource URI scheme - #595

Open
Connor Peet (connor4312) wants to merge 3 commits into
mainfrom
connor4312/snapshot-resource-dispatch
Open

Connor Peet (connor4312) wants to merge 3 commits into
mainfrom
connor4312/snapshot-resource-dispatch

Conversation

@connor4312

@connor4312 Connor Peet (connor4312) commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #593, as requested in review. Stacked on #593. It needs #593's scripts/snapshot-channels.ts and the ahp-annotations: scheme. Retarget it to main once #593 merges.

Kotlin, .NET, and Go chose a Snapshot.state type by looking for distinctive keys, which caused two bugs:

  • Terminal snapshots failed to decode. lifecycle was checked before content, and TerminalState has both, so every valid terminal snapshot was decoded as SessionState and failed.
  • Unrecognized states could fail too. A state from an unrecognized (for example x-) channel that happened to have a content, lifecycle, or entries key was decoded strictly as a known type. The whole subscribe or reconnect call then failed, which violates the Snapshot.state contract.

This PR makes them work like Swift and Rust in #593:

  • Choose by resource. The state type is chosen from the URI scheme of Snapshot.resource, using the shared table, and is decoded strictly. Unrecognized schemes keep their raw JSON as Unknown.
  • New public helpers for decoding a state when you know its resource: Kotlin SnapshotState.decode, .NET SnapshotState.FromResource, and Go SnapshotStateFromResource.
  • Decoding a state without its snapshot now preserves any JSON as Unknown and no longer guesses a type from keys. Kotlin Unknown.raw is now a JsonElement.
  • Two shared round-trip fixtures: 094 is a valid terminal snapshot, and 095 is an x-ext: snapshot with lookalike keys that must stay Unknown.

Validation (local): root npm test, go vet / go test ./..., Kotlin ./gradlew test, .NET dotnet test (702 passed), and the Rust and Swift round-trip corpora with the new fixtures all pass.

Replaces key-based SnapshotState selection, which routed every valid
TerminalState (it has both content and lifecycle) to SessionState and could
strictly decode unrecognized extension states as known types. Uses the shared
scripts/snapshot-channels.ts table that Swift and Rust use.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Base automatically changed from connor4312/issues-586-592 to main November 12, 2026 23:21

This branch has not been deployed

No deployments
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.

1 participant