Skip to content

[code-improvement] code-quality: handle invalid UTF-8 sandbox state - #151

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
code-improvement/sandbox-json-utf8-810d161569205c5d
Sep 21, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
code-improvement/sandbox-json-utf8-810d161569205c5d

Conversation

@ppenna

Copy link
Copy Markdown
Contributor

Scope

Category: code-quality

Sandbox lifecycle JSON readers promise actionable ScriptError failures for unreadable or malformed state. Invalid UTF-8 currently escapes that boundary as a raw UnicodeDecodeError, producing an internal traceback instead of the existing failed to read ... diagnostic.

Evidence and novelty

  • Reproduced on current dev (c7630757b716ea7f3b5e5e3be63b3ddc4b736689): _read_json() raised UnicodeDecodeError for a one-byte invalid UTF-8 file.
  • The prepared current-head baseline passed, so this is the deterministically selected code-quality category rather than a stale CI-failure fix.
  • Searched open NVX issues and pull requests for invalid UTF-8, UnicodeDecodeError, sandbox lifecycle JSON, and ScriptError; no matching active work exists.
  • Reviewed the recent code-improvement history and live outcomes. Reuse versioned JSON reader for OpenVMM outcomes #144 is a merged positive proposal that reused the versioned JSON reader, but it does not handle decoding failures. The other observed proposals concern workflow infrastructure, so this is neither a duplicate nor a cosmetic variant of a rejected proposal.

Change

  • scripts/nvx_tools/sandbox_lifecycle.py: normalize invalid UTF-8 decoding failures to the existing actionable ScriptError path.
  • scripts/test_nvx_tools.py: add focused regression coverage for invalid UTF-8 sandbox configuration.

Patch size: 2 files, 9 additions + 1 deletion = 10 changed lines.

Validation

All commands passed:

  • python -m unittest scripts.test_nvx_tools.SandboxTests.test_versioned_json_reader_rejects_invalid_utf8 -v
  • python3 -m compileall -q scripts
  • python3 -m unittest scripts/test_performance.py scripts/test_nvx_tools.py scripts/test_microvm_tests.py scripts/test_development_release.py -v
  • python3 .github/skills/nvx-host-connect/scripts/test_hosts.py -v
  • python3 scripts/nvx.py --help
  • python3 scripts/nvx.py test-openvmm-unit --help
  • python3 scripts/nvx.py test-openvmm --help
  • python3 scripts/nvx.py test-microvm --help
  • python3 scripts/nvx.py benchmark --help
  • python3 -m ruff check scripts
  • python3 -m pyright --pythonplatform Linux
  • python3 -m pyright --pythonplatform Windows
  • python3 -m ruff format --check scripts
  • git diff --check

No dependency, public API/CLI/ABI, gitlink, or OpenVMM change was made.

Generated by code-improvement · copilot · gpt56 · 79.1 AIC · ⌖ 25.6 AIC · ⊞ 15.9K ·

  • expires on Oct 4, 2026, 11:46 PM UTC

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 20, 2026 23:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused error handling is correct and covered by an appropriate regression test.

Review effort: Balanced
Findings: None

What changed in this PR

Normalizes invalid UTF-8 sandbox state errors into actionable ScriptError diagnostics.

Changes:

  • Catch UnicodeDecodeError in the shared JSON reader.
  • Add focused regression coverage.
File Description
scripts/​test_nvx_tools.py Tests invalid UTF-8 handling.
scripts/​nvx_tools/​sandbox_lifecycle.py Converts decoding failures to ScriptError.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ppenna
Pedro Henrique Penna (ppenna) marked this pull request as ready for review September 20, 2026 23:49
@ppenna
Pedro Henrique Penna (ppenna) merged commit c09557a into dev Sep 21, 2026
40 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the code-improvement/sandbox-json-utf8-810d161569205c5d branch September 21, 2026 00:14
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.

2 participants