Skip to content

fix(assign-gpus): specify UTF-8 encoding and catch OSError in topology file reader - #5884

Closed
vaibhavsrv wants to merge 1 commit into
Osmantic:public-betafrom
vaibhavsrv:fix/assign-gpus-topology-encoding
Closed

vaibhavsrv wants to merge 1 commit into
Osmantic:public-betafrom
vaibhavsrv:fix/assign-gpus-topology-encoding

Conversation

@vaibhavsrv

Copy link
Copy Markdown
Contributor

Why this matters

In ods/scripts/assign_gpus.py, the topology file is opened via open(args.topology) without an explicit encoding parameter. On Python's default behavior, open() uses the locale-preferred encoding — cp1252 on Windows, ascii in minimal containers. When the topology JSON file contains non-ASCII characters (e.g. GPU model names with trademark symbols or non-Latin characters), json.load() encounters a UnicodeDecodeError that is not caught by the narrow except FileNotFoundError block, producing an unhandled traceback rather than a clean error exit. Additionally, PermissionError and IsADirectoryError — both subclasses of OSError — also escape the narrow FileNotFoundError handler and crash with a raw Python traceback.

This patch adds encoding="utf-8" to the open() call and widens the exception clause from except FileNotFoundError to except OSError, ensuring all file access failures produce a clean error message and a non-zero exit code consistent with the script's existing error reporting style.

Validation

  • Repro baseline: Wrote a topology file containing a non-ASCII GPU name (RTX™ 4090) as UTF-8; confirmed that open(args.topology) without encoding raised UnicodeDecodeError in locales where the default is not UTF-8. Confirmed that except FileNotFoundError did not catch permission failures.
  • Post-fix: Verified ods/tests/test_assign_gpus_topology_encoding.py passes with exit code 0; missing and invalid-JSON topology files produce clean ERROR messages on stderr with non-zero exit codes.
  • GPU assignment suites: 3 passed. New-test syntax and diff checks pass; new regressions wired into Linux CI.

Overlap check

Risk / AI disclosure

AI-assisted investigation, implementation and CLI regressions. This strengthens portable JSON reading and OSError handling in GPU topology loading; GPU assignment logic, driver interaction, and capacity decisions are not altered. Independent human review and platform/runtime qualification remain gates. No running configuration, deployment or upstream merge changed.

Follow-up integration evidence

Composed with #5883 at 9a254c687 without conflicts. Production and test diffs passed together; adjacent GPU assignment capacity and spare capacity contracts remain intact.
Backlog composition was local-only (production/test diffs, excluding workflow/Makefile wiring); it is not an upstream merge or independent human approval. Declared live-review gates remain open.

@Lightheartdevs

Copy link
Copy Markdown
Collaborator

Thanks for this contribution. public-beta was promoted into main on 2026-09-24 and no longer receives changes, so we're closing pull requests that target it. This isn't a judgment on the change itself. If it's still needed, please rebase onto main and open a focused PR. See #7253 for details and the contribution policy.

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