fix(contracts): decode growing config unions forward-compatibly #5055
main fromrefs/pull/5055/head·merged by juliusmarminge View on GitHubWhat Changed#
- Added
ForwardCompatibleArrayto contracts: a wire codec for server→client arrays whose element unions grow over time. Decoding drops elements the current build cannot decode instead of failing the whole payload; encoding is the plain array encoding, byte-identical to before. - Applied it to the three growing sets in the config payloads: resolved keybindings (
ResolvedKeybindingsConfig), server config issues (ServerConfigIssues), andavailableEditors. - Authoring/upsert inputs (
KeybindingRule,ServerUpsertKeybindingInput) stay strict — clients only create bindings for commands they know.
Why#
Nightly 0.0.32-nightly.20260730.957 added filePicker.toggle / projectSearch.toggle, and 0.0.31 clients rejected the entire serverGetConfig response during connect (the session's ready gate awaits initialConfig, so a config decode failure means the client never reaches the connected state). The root cause is that clients validate server-owned, growing literal unions as closed sets.
#5018 worked around this with per-connection command-set version negotiation and server-side filtering. That treats the symptom: every future command addition would require a version bump plus a new filter branch on the WS hot path, and the same break class remained for issue kinds, editor ids, and when-node types. This PR fixes the class instead: clients tolerate unknown members by dropping them. This is safe because every dispatch site matches commands by string equality (an unknown command is already an inert no-op), and the settings UI renders any command string.
Old servers are unaffected (encoded output is unchanged). Already-shipped 0.0.31 clients still need a new store build to pick this up — this intentionally replaces the OTA/negotiation hotpatch.
Verification#
- New contracts tests: unknown commands / unknown
when-node types / malformed entries dropped, known rules preserved in order, encode round-trip unchanged; unknown issue kinds and editor ids dropped. - New client-runtime session test: a mock newer server sends a config containing an unknown command, unknown issue kind, and unknown editor id over the raw wire — the session reaches
readyand exposes only the known subset (this is the exact incident scenario). vp test run packages/contracts packages/client-runtime apps/server/src/server.test.ts apps/server/src/keybindings.test.ts packages/shared— all passing (1000+ tests)vp run --filter @t3tools/contracts --filter @t3tools/client-runtime --filter t3 --filter @t3tools/shared --filter web --filter mobile typecheck— clean- Targeted lint + format checks for all changed files
Checklist#
- This PR is small and focused
- I explained what changed and why
- I added regression coverage
🤖 Generated with Claude Code
Note
Medium Risk
Changes wire decoding for core connect-time ServerConfig fields; behavior is intentionally permissive (drop unknowns) but affects every client session bootstrap path.
Overview
Older clients were failing the entire serverGetConfig decode when a newer server sent unknown keybinding commands, issue kinds, or editor IDs—blocking the session ready gate. This PR introduces ForwardCompatibleArray, which filters out array elements the current schema cannot decode instead of rejecting the whole payload; wire encoding stays unchanged.
That codec is applied to ResolvedKeybindingsConfig, ServerConfigIssues, and availableEditors on server→client config paths. Client authoring inputs (KeybindingRule, upsert payloads) remain strict.
Regression tests cover per-element dropping (unknown commands, when node types, malformed entries), encode round-trips, and a client-runtime session test where a mock newer server still reaches ready with only the known subset.
Note
Decode growing config unions forward-compatibly by dropping unknown entries#
- Introduces
ForwardCompatibleArrayinbaseSchemas.ts, which decodes arrays by silently dropping elements that fail to decode rather than failing the entire array. - Applies
ForwardCompatibleArraytoResolvedKeybindingsConfig,ServerConfigIssues, andServerConfig.availableEditorsso that unknown commands, issue kinds, or editor IDs from a newer server are dropped instead of breaking the config decode. - Behavioral Change: previously, a single unrecognized entry in these arrays would cause the entire decode to fail; now such entries are silently filtered out.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved c0b2abc
This is a defensive forward-compatibility fix that makes schema decoding more resilient by dropping unrecognized union variants instead of failing entirely. Changes are self-contained to schema definitions with comprehensive test coverage.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).juliusmarminge merged thisdf78cda
juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
0db506c1-7341-418a-8f72-da17e1e8aa12You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.