[deep-review] A9: Build hygiene gaps — no analyzers on Tray/Shared, no dotnet format, no Debug.Assert, 12 ThrowIfNull sites
Summary
Five build-hygiene defaults that every modern .NET reference app has are missing from this repo:
-
EnableNETAnalyzersis set only onOpenClaw.CommandPalette(src/OpenClaw.CommandPalette/Directory.Build.props:7). Not onOpenClaw.Shared, not onOpenClaw.Tray.WinUI, not on the CLIs. This was flagged inDEVELOPMENT.md:662as a known gap. -
TreatWarningsAsErrorsis set only on test projects (tests/Directory.Build.props:13). Production code can land with warnings. -
No
dotnet format --verify-no-changesstep in CI.ci.ymlhas no formatter check. -
Zero
Debug.Assertinsrc/. Invariants are documented in comments instead of enforced at runtime in Debug builds. -
Only 12
ArgumentNullException.ThrowIfNullsites across the entiresrc/tree. Most public methods don't null-check their parameters.
Where
- Analyzer config:
Directory.Build.propsat repo root (setsNuGetAuditModeonly); add<EnableNETAnalyzers>and<AnalysisLevel>recommended</AnalysisLevel>here for repo-wide effect. - Format check: extend
.github/workflows/ci.ymltestjob.
Why it matters
These are the cheapest possible safety nets, and they're absent. Concrete consequences observed in this review:
App.xaml.csgrew 11% during the docs period (4148 → 4617 lines) with no warning anywhere.- The 106 empty try/catch blocks would have been flagged by
CA1031if analyzers were on. - The 527 inline
TryGetPropertywalks would have been flagged by a custom analyzer if anyone wrote one. - Subtle nullability bugs in JSON helpers (A5) survive because nullable annotations aren't enforced.
Proposed fix
Land in one PR (low risk):
- Move
EnableNETAnalyzers=true,AnalysisLevel=recommended,EnforceCodeStyleInBuild=trueinto the rootDirectory.Build.props. Expect ~50-200 warnings the first time. Convert them to errors in a follow-up PR after triaging. - Add a CI step:
dotnet format --verify-no-changes --no-restoreagainstsrc/. Auto-format any straggler files first. - Land an
.editorconfigif one doesn't exist; pick reasonable defaults. - Add a
Guardstatic class withGuard.NotNull(arg, nameof(arg))etc. Migrate the most-touched public entry points first (WindowsNodeClient,OpenClawGatewayClient, capability constructors). - Sprinkle
Debug.Asserton documented invariants — e.g., the single-threaded-receive-loop assertion inWebSocketClientBase.
Each step is independently shippable.
Severity
Medium — process gap; downstream cause of many other findings.
Closing during the post-refactor deep-review cleanup. Analyzer/build hygiene is consolidated into #372; the stale analyzer PR was closed rather than left to rot. This keeps the signal while reducing stale one-off issue noise.