Skip to content

fix(codeql): Clear cs/useless-upcast alerts and gate the class at build time - #134

Merged
hoangsnowy merged 1 commit into
mainfrom
fix/codeql-useless-upcast-and-style-gate
Jul 25, 2026
Merged

fix(codeql): Clear cs/useless-upcast alerts and gate the class at build time#134
hoangsnowy merged 1 commit into
mainfrom
fix/codeql-useless-upcast-and-style-gate

Conversation

@hoangsnowy

Copy link
Copy Markdown
Owner

Change description

Clears the three open code-scanning alerts, and — more to the point — stops this class of alert from being filed again by moving the check into the build.

The alerts (#88, #89, #90, all cs/useless-upcast) came from the Returns((string?)null) / Returns((WorkspaceEntity?)null) calls introduced by the NSubstitute 6 upgrade in #132. The null literal converts implicitly, so the cast is redundant → swapped for Returns(default(T)).

The actual fix is the gate. CodeQL runs post-push, so anything it catches is caught late, in the security tab, after review. Every CodeQL C# quality query with a Roslyn twin is now enforced in .editorconfig:

Rule Catches CodeQL query it pre-empts
IDE0004 redundant cast cs/useless-upcast, cs/useless-cast-to-self
IDE0035 unreachable code cs/unreachable-code
IDE0059 unused value assignment cs/useless-assignment-to-local
IDE0060 unused parameter cs/unused-parameter

Set to warning, which the existing EnforceCodeStyleInBuild + TreatWarningsAsErrors promote to build errors — so dotnet build fails locally and the alert is never filed. The convention is documented in CLAUDE.md: when a new code-scanning alert lands, add its Roslyn twin to that block, don't just fix the site.

Note the boundary: this only covers syntactic queries. Taint/dataflow queries (log forging, path traversal, SSRF) have no compiler equivalent and still depend on the CodeQL workflow — fix in code, never dismiss.

Turning the gate on surfaced three pre-existing violations, all fixed here:

  • CostCalculator.cs — two redundant (decimal) casts; int converts implicitly inside a decimal expression.
  • KcLiveBenchTests.cs — redundant (double?)null in a target-typed conditional.
  • PipelineOrchestrator.FailMidway — unused ex parameter. The exception is already logged at the call site (_logger.LogError(ex, …) immediately above), so the parameter and its argument are dropped rather than threaded into an unused field.

Type of change

  • New feature (new agent / endpoint / capability)
  • Bugfix
  • Refactor (no behavior change)
  • Documentation / README
  • Infrastructure / CI configuration

Related issues

Closes code-scanning alerts #88, #89, #90. Follows #132.

Checklist

  • dotnet build AgentOs.slnx --configuration Release passes locally — 0 warnings, 0 errors (with the four new gates active)
  • dotnet test AgentOs.slnx --configuration Release passes — 832 passed, 0 failed, 14 skipped (+ 29 E2E skipped, RUN_AGENTOS_E2E unset)
  • No secrets committed
  • README / docs updated — CLAUDE.md records the CodeQL-parity convention
  • Measurable results provided when related to agent output quality — n/a

No UI surface touched, so no design-system round-trip or desktop screenshot applies.

Code scanning filed three cs/useless-upcast alerts (#88-#90) against the
`Returns((string?)null)` / `Returns((WorkspaceEntity?)null)` calls added
with the NSubstitute 6 upgrade -- the null literal converts implicitly,
so the cast is redundant. Swapped for `Returns(default(T))`.

The alerts are only a symptom: CodeQL runs post-push, so this class of
defect is always found late. Enforce the Roslyn twins in .editorconfig
instead -- IDE0004 (redundant cast), IDE0035 (unreachable code), IDE0059
(unused assignment) and IDE0060 (unused parameter) at `warning`, which
EnforceCodeStyleInBuild + TreatWarningsAsErrors turn into build errors.

Turning the gate on surfaced three pre-existing violations, all fixed:
two redundant `(decimal)` casts in CostCalculator (int converts
implicitly in a decimal expression), a redundant `(double?)null` in a
target-typed conditional in KcLiveBenchTests, and the unused `ex`
parameter on PipelineOrchestrator.FailMidway -- the exception is already
logged at the call site, so the parameter and its argument are dropped.

Documented the convention in CLAUDE.md: when a new code-scanning alert
lands, add its Roslyn twin to the block so the class cannot recur.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@hoangsnowy
hoangsnowy merged commit cb24ebb into main Jul 25, 2026
4 checks passed
@hoangsnowy
hoangsnowy deleted the fix/codeql-useless-upcast-and-style-gate branch August 9, 2026 16:55
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