config: fix UTF-8 decode crash + null config-value TypeError on Windows (doctor/resource_plan) (#184)

Two related crash bugs in the Python planning layer:

P1: Path.read_text() without encoding= defaults to locale.getpreferredencoding()
    (cp1252 on most Windows installs). HuggingFace config.json is UTF-8 — if it
    contains any non-ASCII byte (Chinese fields, accented chars, emoji in
    metadata), read_text() raises UnicodeDecodeError. In doctor.py this is
    caught and mis-reported as 'config.json is missing or invalid' (false
    negative); in build_plan() called directly it is an uncaught crash.

    Fixed: read_text(encoding='utf-8') in both resource_plan.py and doctor.py.

P2: int(cfg.get('kv_lora_rank', 0)) crashes with TypeError if the key is
    present but null (JSON null). dict.get() returns the default only when
    the key is ABSENT; a null value returns None, and int(None) raises
    TypeError. The engine validates against malformed configs in C but the
    Python planner did not.

    Fixed: int(cfg.get(key) or 0) — coerces both missing and null to 0.
    Applied to all 8 int(cfg.get(...)) calls in build_plan().

Co-authored-by: woolcoxm <13604288+woolcoxm@users.noreply.github.com>
This commit is contained in:
woolcoxm
2026-07-14 08:17:42 -04:00
committed by GitHub
parent 39dcebf39a
commit 35ed9bc921
2 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ def run_doctor(model, ram_gb=0, context=4096, gpu_indices=None, vram_gb=0, *,
config = model / "config.json"
try:
valid_config = isinstance(json.loads(config.read_text()), dict)
valid_config = isinstance(json.loads(config.read_text(encoding="utf-8")), dict)
except (OSError, ValueError):
valid_config = False
checks.append(_check("model.config", "pass" if valid_config else "fail",