Skip to content

fix(python): add encoding=utf-8 to file reads and writes in sandbox.py#1912

Open
mesutoezdil wants to merge 1 commit into
NVIDIA:mainfrom
mesutoezdil:fix/python-client-encoding
Open

fix(python): add encoding=utf-8 to file reads and writes in sandbox.py#1912
mesutoezdil wants to merge 1 commit into
NVIDIA:mainfrom
mesutoezdil:fix/python-client-encoding

Conversation

@mesutoezdil

@mesutoezdil mesutoezdil commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

read_text() and fdopen(..., "w") without an explicit encoding use the system locale,
which can be non-UTF-8 on some platforms (e.g. Windows).

4 call sites in sandbox.py read or write UTF-8 config files without specifying encoding:

  • metadata_path.read_text() gateway metadata.json
  • token_path.read_text() oidc_token.json
  • os.fdopen(fd, "w") atomic write of oidc_token.json
  • active_file.read_text() active_gateway name file

All 4 are now explicit with encoding="utf-8".

…ox.py

read_text(), fdopen() without encoding use the system locale, which can
differ on non-UTF-8 systems. All config files (metadata.json,
oidc_token.json, active_gateway) are UTF-8 text.
@mesutoezdil mesutoezdil requested review from a team, derekwaynecarr and mrunalp as code owners June 15, 2026 19:51
@copy-pr-bot

copy-pr-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@johntmyers johntmyers added the gator:in-review Gator is reviewing or awaiting PR review feedback label Jun 15, 2026
@johntmyers

Copy link
Copy Markdown
Collaborator

gator-agent

PR Review Status

Validation: This is a small, concentrated Python SDK bug fix that makes OpenShell's shared gateway config files use an explicit UTF-8 encoding, matching the Rust-side writers for metadata.json, active_gateway, and oidc_token.json.
Head SHA: dba017a42c918bbda280010820f75f0ab4d0811b

Review findings:

  • python/openshell/sandbox.py: _read_oidc_token_bundle() now decodes with explicit UTF-8, but UnicodeDecodeError is not caught. The function contract says unreadable token files return None, so a corrupt/non-UTF-8 oidc_token.json should fail closed like malformed JSON:

    except (OSError, UnicodeDecodeError, json.JSONDecodeError):
        return None
  • Please add focused regression coverage for the locale/encoding behavior. Existing tests mostly use locale-default write_text() / read_text(), so they would not catch a future removal of encoding="utf-8" on non-UTF-8 platforms. A small test that writes non-ASCII UTF-8 bytes directly for metadata.json, active_gateway, and oidc_token.json would cover the important paths.

Docs: not needed; this does not change a documented command, config field, or workflow.

Next state: gator:in-review

@johntmyers

Copy link
Copy Markdown
Collaborator

/ok to test dba017a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gator:in-review Gator is reviewing or awaiting PR review feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants