Skip to content

fix(bin): record files semgrep's errors[] names but its notices omit - #22

Open
Portll wants to merge 1 commit into
mainfrom
fix/semgrep-json-errors-20261206
Open

Portll wants to merge 1 commit into
mainfrom
fix/semgrep-json-errors-20261206

Conversation

@Portll

@Portll Portll commented Dec 6, 2026 •

Copy link
Copy Markdown
Owner

The defect

Semgrep writes two records of the same run: the SARIF invocations' toolExecutionNotifications, and the JSON errors[] array. They are not the same set.

Measured on the Hercules tree (SDL-Hercules-390/hyperion @ 8ab5c3f1, 436k lines of C):

record files named
SARIF notices 252
JSON errors[] 249
in the JSON alone 1 (machdep.h, "Other syntax error")

Only the notices reach monitor/sarif-read.mjs. A file the notices omit is a file the lane reports clean — the silent-clean class the coverage accounting exists to close. A short result list read as a clean tree.

The fix

semgrep-retry.mjs already copies the JSON's time.fixpoint_timeouts into the SARIF for exactly this reason (properties.commitworkFixpoint). This does the same for errors[], under properties.commitworkJsonErrors, and only for the types that mean "read only in part":

Syntax error, Other syntax error, Lexical error, Timeout, PartialParsing

A type the script does not map is counted in the receipt as unclassified rather than guessed at, so a type Semgrep adds later is visible.

Two ways it must not fire, both pinned by a test

  • A file the notices already name is left alone. Injecting it again would inflate the notice count without changing the file count.
  • A file the retry already re-measured is left alone. partialLedger cleared its row because the retry resolved it, not because the notices omitted it. Injecting it back would claim a recovery that is not one.

Measured on the Hercules tree

jsonErrors: {"measured":true,"count":347,"unclassified":0,"injected":1}
partial files before: 233  after: 234
second pass injected: 0

CLI:

semgrep-retry: disabled — CW_SEMGREP_RETRY is off; ...; 31 fixpoint timeout(s) recorded
from semgrep.json; 1 file(s) named by errors[] but not by the notices recorded from semgrep.json

A trap worth knowing

Semgrep writes type as a string for a syntax error and as an array for a partial parse (["PartialParsing", {...}]). String(type) never matches the latter — that is how 196 entries first read as unclassified. The map is keyed on the first element when it is an array.

Tests

6 new cases in bin/test/semgrep-retry.test.mjs:

  • readJsonErrors maps a string type and an array type, dedupes per file+reason, and counts what it cannot map
  • a file errors[] names and the notices do not is injected, and only that file
  • a file the notices already name is not injected again
  • a file the retry already resolved is not injected back
  • a second pass injects nothing
  • no --json leaves the SARIF byte-identical and says so

bin/test/semgrep-retry.test.mjs 62/62 on this base (56 existing + 6 new).

Rebased

Rebased onto 5e2bf407 fix(bin): retry timed-out files in batches inside the budget. The first cut of this branch was cut from a local main that predated that commit and would have reverted it; the diff here is additive only (2 intentional line changes in each file).

What this does NOT fix

The magnitude of the loss, not its honesty. On this tree 222 files fail to parse and 24 time out. All of it is reported as degraded with the files named, and 5e2bf407 already raised the retry cap to 500 files across batches, so the cap is no longer the binding constraint here. What remains is Semgrep's C parser on this codebase, which is a tool limitation rather than a lane defect.

Refs: cw-hercules-scan-20261129 F6

Correction (2026-12-06): #23 explains the measured instance

The one file this PR injected on the Hercules tree was machdep.h. The reason it was missing from
the notices is a case-sensitive regex in monitor/sarif-read.mjs that does not match Semgrep's
lower-case Other syntax error. PR #23 fixes that.

With #23 applied the two records agree exactly on this tree: 249 files from the SARIF notices, 249
from the JSON errors[], zero difference in either direction. On the only tree measured, this PR's
injection is a no-op once #23 lands.

It stays open as a cross-check between two independent records, not as a fix for that instance. A
file the notices genuinely omit, for a reason other than a message shape the reader cannot parse,
is still invisible without it. The honest reading is that the measured divergence had a single
cause, and that cause was #23's.

Semgrep writes two records of the same run: the SARIF invocations'
toolExecutionNotifications, and the JSON errors[] array. They are not the same
set. On a 436k-line C tree the notices named 252 files and errors[] named 249.
machdep.h ("Other syntax error") appeared in the JSON alone.

Only the notices reach monitor/sarif-read.mjs. A file the notices omit is a file
the lane reports clean. That is the silent-clean class the coverage accounting
exists to close: a short result list read as a clean tree.

semgrep-retry.mjs already copies the JSON's time.fixpoint_timeouts into the
SARIF for exactly this reason. This does the same for errors[], under
properties.commitworkJsonErrors, and only for the types that mean "read only in
part": Syntax error, Other syntax error, Lexical error, Timeout, PartialParsing.
A type the script does not map is counted in the receipt as unclassified rather
than guessed at. A type Semgrep adds later is then visible.

Two ways it must not fire, both pinned by a test. A file the notices already
name is left alone, because injecting it again would inflate the notice count
without changing the file count. A file the retry already re-measured is left
alone too: partialLedger cleared its row because the retry resolved it, not
because the notices omitted it. Injecting it back would claim a recovery that is
not one.

Measured on the Hercules tree: 1 file injected (machdep.h), 233 to 234 files
read only in part, and a second pass injects nothing.

Note: Semgrep writes `type` as a string for a syntax error and as an ARRAY for a
partial parse (["PartialParsing", {...}]). The map is keyed on the first element
when it is an array. String(type) would never match the latter, which is how 196
entries first read as unclassified.

Refs: cw-hercules-scan-20261129 F6
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