You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[deep-review][duplication] D7: Per-file JsonSerializerOptions singletons with drifted defaults #370
Five separate per-file JsonSerializerOptions singletons in the codebase, with subtly different defaults. The two most consequential drifts:
WindowsNodeClient sets DefaultIgnoreCondition = WhenWritingNull (deliberate; documented at WindowsNodeClient.cs:47 — keeps auth/error absent rather than null on the wire).
OpenClawGatewayClient does not set this — so its outbound payloads emit "error": null instead of omitting the key.
Other smaller drifts: PropertyNameCaseInsensitive, WriteIndented, presence of custom converters.
Where
Five JsonSerializerOptions declarations to consolidate:
src/OpenClaw.Tray.WinUI/Services/... — at least one site for diagnostics or settings.
src/OpenClaw.WinNode.Cli/Program.cs:213-310 — uses Utf8JsonWriter directly with its own conventions.
grep -rn "JsonSerializerOptions" src/ for the full list.
Why it matters
Wire-shape drift. Operator and node messages can have different null semantics, even though they share an envelope shape and the same gateway parses both. A gateway-side change that becomes strict about null vs missing breaks one side without the other.
Per-file caching is fine; per-file defaults are not. The pattern is correct in principle (cache the options once, reuse), but each cache snapshot has subtly different rules.
Adding a custom converter (e.g., a typed JsonValueConverter for A2UIValue) means hunting down all five sites and updating them — easy to miss one.
The pull request was not created — a fallback review issue was created instead due to protected file changes: #431
🤖 This is an automated response from Repo Assist.
The JsonOptions central-config approach from the issue is the right fix. A few implementation notes to smooth the migration:
The key decision: WhenWritingNull as the wire default
The issue flags the WindowsNodeClient vs OpenClawGatewayClient drift. Looking at the wire shape: the gateway parses both operator and node envelopes, and the protocol treats absent fields and null values differently (e.g. "error": null vs omitting "error"). WhenWritingNull should be the default for outbound wire serialization — absent is cleaner than explicit null for optional envelope fields.
Suggested JsonOptions.cs structure:
// src/OpenClaw.Shared/Json/JsonOptions.cspublicstaticclassJsonOptions{/// Standard outbound wire serialization: null fields omitted, camelCase.publicstaticJsonSerializerOptionsWire{get;}=new(JsonSerializerDefaults.Web){DefaultIgnoreCondition=JsonIgnoreCondition.WhenWritingNull,};/// Human-readable indented variant for logs and diagnostics.publicstaticJsonSerializerOptionsIndented{get;}=new(Wire){WriteIndented=true};}
Using JsonSerializerDefaults.Web sets PropertyNameCaseInsensitive = true and PropertyNamingPolicy = CamelCase, which matches the current WindowsNodeClient options.
Migration order: start with WindowsNodeClient and OpenClawGatewayClient (sites 1 and 2 from the issue). The McpToolBridge JSON-RPC site (site 3) should be validated separately — MCP JSON-RPC has its own schema requirements and may need a distinct options instance. Don't assume Wire is a drop-in there without checking what the current options look like.
Site 5 (WinNode.Cli/Program.cs): Utf8JsonWriter bypasses JsonSerializerOptions entirely — it's a direct writer. Leave that site for a separate pass once the JsonSerializer sites are consolidated.
Closing during the post-refactor deep-review cleanup. JsonSerializerOptions drift is consolidated into #372 for a fresh bounded audit. This keeps the signal while reducing stale one-off issue noise.
Activity
github-actions commentedon May 17, 2026
Note
The pull request was not created — a fallback review issue was created instead due to protected file changes: #431
🤖 This is an automated response from Repo Assist.
The
JsonOptionscentral-config approach from the issue is the right fix. A few implementation notes to smooth the migration:The key decision:
WhenWritingNullas the wire defaultThe issue flags the
WindowsNodeClientvsOpenClawGatewayClientdrift. Looking at the wire shape: the gateway parses both operator and node envelopes, and the protocol treats absent fields andnullvalues differently (e.g."error": nullvs omitting"error").WhenWritingNullshould be the default for outbound wire serialization — absent is cleaner than explicit null for optional envelope fields.Suggested
JsonOptions.csstructure:Using
JsonSerializerDefaults.WebsetsPropertyNameCaseInsensitive = trueandPropertyNamingPolicy = CamelCase, which matches the currentWindowsNodeClientoptions.Migration order: start with
WindowsNodeClientandOpenClawGatewayClient(sites 1 and 2 from the issue). TheMcpToolBridgeJSON-RPC site (site 3) should be validated separately — MCP JSON-RPC has its own schema requirements and may need a distinct options instance. Don't assumeWireis a drop-in there without checking what the current options look like.Site 5 (
WinNode.Cli/Program.cs):Utf8JsonWriterbypassesJsonSerializerOptionsentirely — it's a direct writer. Leave that site for a separate pass once theJsonSerializersites are consolidated.shanselman commentedon May 18, 2026
Closing during the post-refactor deep-review cleanup. JsonSerializerOptions drift is consolidated into #372 for a fresh bounded audit. This keeps the signal while reducing stale one-off issue noise.