[Repo Assist] refactor: eliminate inline JsonSerializerOptions allocations in Shared and SetupEngine#566
Conversation
…d and SetupEngine
Add JsonSerializerOptionsCache.WriteIndented in OpenClaw.Shared and
SetupConfig.JsonWriteOptions in OpenClaw.SetupEngine to replace
10 inline `new JsonSerializerOptions { WriteIndented = true }`
allocations scattered across both projects.
- Create src/OpenClaw.Shared/JsonSerializerOptionsCache.cs with a
shared WriteIndented singleton for pretty-print serialization
- Fix 3 inline allocations in ChannelConfigPatchBuilder, DeviceIdentity,
and Models
- Add SetupConfig.JsonWriteOptions alongside the existing JsonOptions
- Fix 6 inline allocations across Program, SetupContext, SetupSteps,
SetupWizardRunner, and TrayArtifactCleanup
No behavior change: the replacement instances have identical settings.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Codex review: needs maintainer review before merge. Reviewed May 27, 2026, 9:28 PM ET / 01:28 UTC. Summary Reproducibility: not applicable. this is a cleanup PR, not a bug report. Source inspection confirms the edited call sites currently allocate inline Review metrics: 2 noteworthy metrics.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge Security Review detailsBest possible solution: Land the narrow static-options refactor after the required Windows build and Shared/Tray test validation are green or explicitly accepted by maintainers. Do we have a high-confidence way to reproduce the issue? Not applicable; this is a cleanup PR, not a bug report. Source inspection confirms the edited call sites currently allocate inline Is this the best way to solve the issue? Yes; centralizing write-only options per assembly is a narrow maintainable solution, and the proposed settings match the existing inline serializer options. AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 6a5921883c86. Label changesLabel changes:
Label justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
ClawSweeper PR egg ✨ Hatched: 💎 rare Mossy Lint Imp Hatch commandComment Hatchability rules:
Rarity: 💎 rare. What is this egg doing here?
|
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Replaces 9 repeated
new JsonSerializerOptions { WriteIndented = true }inline allocations scattered acrossOpenClaw.SharedandOpenClaw.SetupEnginewith shared static singletons.Motivation
Creating a new
JsonSerializerOptionsinstance at every call site:DataJsoninModels.cs, which is a cached property)Changes
OpenClaw.SharedJsonSerializerOptionsCache.cs:internal static class JsonSerializerOptionsCachewith aWriteIndentedsingleton for pretty-print serializationChannelConfigPatchBuilder.cs,DeviceIdentity.cs,Models.csOpenClaw.SetupEngineSetupConfig.JsonWriteOptionsadded alongside the existingSetupConfig.JsonOptions(which is for reading, with comment/trailing-comma tolerance)Program.cs,SetupContext.cs,SetupSteps.cs(×2),SetupWizardRunner.cs,TrayArtifactCleanup.csNo behavior change
The replacement singletons have identical settings (
WriteIndented = trueonly). Output JSON is byte-for-byte identical.Test Status
./build.ps1— skipped (Linux CI; requires Windows)dotnet build OpenClaw.Shared— ✅ Build succeeded (1 pre-existing warning, unrelated)dotnet build OpenClaw.SetupEngine— ✅ Build succeeded (1 pre-existing warning, unrelated)dotnet test OpenClaw.Shared.Tests— ✅ 2015 passed, 29 skipped, 8 pre-existing failures (Windows-specific path tests)dotnet test OpenClaw.Tray.Tests— ✅ 858 passed, 2 skipped, 0 failures