fix(graph): read UTF-16 and Windows-1252 source files into the code graph (t84) #941

Merged
sharang merged 1 commits from fix/t84-graph-encoding into main 2026-11-09 08:13:46 +00:00
Owner

The code graph read source files with read_to_string and silently dropped every file that was not UTF-8. Files Visual Studio saves as UTF-16 and files older .NET and PLC tools save as Windows-1252 were therefore missing from the graph, in every language; that is one reason C# graphs are small. A UTF-8 BOM was also kept as a leading U+FEFF (t84).

  • New decoder: compliance_graph::encoding::read_source. A BOM picks UTF-8 or UTF-16 LE/BE and is removed. Without one it tries UTF-8, then falls back to Windows-1252 (encoding_rs, already in the lock). These count as unreadable:
    • malformed content after a BOM;
    • bytes that are not UTF-8 and contain a NUL (binaries, UTF-16 without a BOM);
    • I/O errors.
  • Counted, not skipped: the graph build counts unreadable files and logs one warning per build, with paths at debug level only. It stores unreadable_file_count on the build run; serde(default) keeps older runs readable. PLC builds don't carry the count yet, because their files are read in the agent.
  • Card: /api/v1/graph/{id}/summary returns unreadable_files. When that is above 0, the target page's Codegraph card shows "N Dateien nicht lesbar" / "N files unreadable".
  • Same decoder elsewhere: it is also used where these files are read again, or within the same stage:
    • graph chunking and the explorer's file view;
    • PLC read_tree and native_projects: a 1252 .st file and a UTF-16 PLCopen XML file now give their POUs;
    • .NET read_text, replacing its own BOM handling;
    • finding snippets (source_text.rs), header version macros (SBOM) and triage context.
    • Side effect: a mobsfscan finding in a non-UTF-8 manifest or plist can now get a line, which shifts its line-based fingerprint. This is rare.
  • Not changed, follow-ups:
    • the GDPR/OAuth pattern scanner (would create new findings);
    • content fingerprints (would change existing fingerprints);
    • the control-check surface search;
    • git diff lines;
    • werkbank-exec's PLC reader (the decoder would first have to move to a shared crate).
  • Delegated tools: semgrep, gitleaks, cppcheck, devskim, mobsfscan, syft, clamav and oelint read files themselves.
  • Backlog: VB, .aspx, .cshtml and .razor parsers, not in this PR.

Tests

  • Decoder: every encoding, malformed input, binary input, I/O errors.
  • Registry and engine: a temp tree in every encoding, with the unreadable files counted.
  • An old build record still reads; the summary shows the count.
  • PLC: 1252 and UTF-16 sources.
  • Dashboard: the singular and plural texts.

Locally: fmt, clippy with -D warnings (graph, core, agent, dashboard server and web, mcp, werkbank-exec, control-map), the lib and dashboard tests, and all agent integration tests against Mongo (94 passed).

🤖 Generated with Claude Code

The code graph read source files with `read_to_string` and silently dropped every file that was not UTF-8. Files Visual Studio saves as UTF-16 and files older .NET and PLC tools save as Windows-1252 were therefore missing from the graph, in every language; that is one reason C# graphs are small. A UTF-8 BOM was also kept as a leading U+FEFF (t84). - **New decoder:** `compliance_graph::encoding::read_source`. A BOM picks UTF-8 or UTF-16 LE/BE and is removed. Without one it tries UTF-8, then falls back to Windows-1252 (`encoding_rs`, already in the lock). These count as unreadable: - malformed content after a BOM; - bytes that are not UTF-8 and contain a NUL (binaries, UTF-16 without a BOM); - I/O errors. - **Counted, not skipped:** the graph build counts unreadable files and logs one warning per build, with paths at debug level only. It stores `unreadable_file_count` on the build run; `serde(default)` keeps older runs readable. PLC builds don't carry the count yet, because their files are read in the agent. - **Card:** `/api/v1/graph/{id}/summary` returns `unreadable_files`. When that is above 0, the target page's Codegraph card shows "N Dateien nicht lesbar" / "N files unreadable". - **Same decoder elsewhere:** it is also used where these files are read again, or within the same stage: - graph chunking and the explorer's file view; - PLC `read_tree` and `native_projects`: a 1252 `.st` file and a UTF-16 PLCopen XML file now give their POUs; - .NET `read_text`, replacing its own BOM handling; - finding snippets (`source_text.rs`), header version macros (SBOM) and triage context. - Side effect: a mobsfscan finding in a non-UTF-8 manifest or plist can now get a line, which shifts its line-based fingerprint. This is rare. - **Not changed, follow-ups:** - the GDPR/OAuth pattern scanner (would create new findings); - content fingerprints (would change existing fingerprints); - the control-check surface search; - git diff lines; - werkbank-exec's PLC reader (the decoder would first have to move to a shared crate). - **Delegated tools:** semgrep, gitleaks, cppcheck, devskim, mobsfscan, syft, clamav and oelint read files themselves. - **Backlog:** VB, .aspx, .cshtml and .razor parsers, not in this PR. **Tests** - Decoder: every encoding, malformed input, binary input, I/O errors. - Registry and engine: a temp tree in every encoding, with the unreadable files counted. - An old build record still reads; the summary shows the count. - PLC: 1252 and UTF-16 sources. - Dashboard: the singular and plural texts. Locally: fmt, clippy with `-D warnings` (graph, core, agent, dashboard server and web, mcp, werkbank-exec, control-map), the lib and dashboard tests, and all agent integration tests against Mongo (94 passed). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 1 commit 2026-11-09 07:54:04 +00:00
fix(graph): read UTF-16 and Windows-1252 source files into the code graph (t84)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m36s
CI / Check (pull_request) Successful in 18m48s
68f73afde6
The graph registry read source files with read_to_string and skipped any
that were not UTF-8, so Visual Studio's UTF-16 files and older .NET/PLC
tools' Windows-1252 files never reached the graph, in every language. A
UTF-8 BOM was kept as a leading U+FEFF.

- compliance_graph::encoding::read_source: a BOM (UTF-8, UTF-16 LE/BE)
  names the encoding and is dropped; otherwise UTF-8, else Windows-1252
  (encoding_rs, already in the lock). Malformed UTF-16, a NUL in non-UTF-8
  bytes (a binary) and I/O errors are errors.
- The registry counts the files it still can't read, warns once per build
  (paths at debug only) and the tree build stores the count on the build
  run (unreadable_file_count, serde default for older runs).
- GET /api/v1/graph/{id}/summary returns unreadable_files; the target
  page's Codegraph card shows "N Dateien nicht lesbar" / "N files
  unreadable" when it is above 0.
- The same decoder where a file is read again or in the same stage: graph
  chunking, the graph's file view, PLC read_tree and native_projects,
  .NET read_text (replaces its own BOM code), finding snippets
  (source_text), embedded header versions, LLM and control triage context.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang force-pushed fix/t84-graph-encoding from 23e9c28166 to 68f73afde6 2026-11-09 07:54:04 +00:00 Compare
sharang merged commit b420b28ea8 into main 2026-11-09 08:13:46 +00:00
Sign in to join this conversation.