Repository navigation
Scope the runtime encoding scan past vendored laya while its loader supplies UTF-8 - #12230
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 67fdb5625e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if _utf8_by_loader(path): | ||
| continue |
There was a problem hiding this comment.
Restrict the exemption to calls the loader protects
When a future pinned Laya update introduces Path.read_text()/Path.open() or a module-level bare open(), this file-level continue hides it even though laya_runtime._laya() only replaces each module's open global after exec_module returns (studio/backend/core/systemone/laya_runtime.py:149-155). Those calls would still use the platform locale while this guard remains green, so exempt only function-time bare open offenders that the loader actually intercepts rather than skipping the entire vendored file.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, the file-level skip was wider than the swap. Narrowed in 7622813: only bare open(...) calls at function time, where open is not a parameter, assignment or import inside that function, are exempt. Module-level and class-body calls, Path.open, read_text and io.open are still scanned. Added test_loader_swap_exempts_only_the_calls_it_reaches, and a vendored import-time open() or read_text() now fails the scan.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 762281382c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for vendored, (loader, marker) in UTF8_BY_LOADER.items(): | ||
| if vendored.resolve() in parents: | ||
| return loader.is_file() and marker in loader.read_text(encoding = "utf-8") |
There was a problem hiding this comment.
Limit the exemption to eagerly patched modules
When a pinned Laya update adds a lazily imported submodule that is not re-exported from laya/__init__.py, this directory-only check exempts its bare function-time open() calls even though _laya() patches only the modules already present in sys.modules immediately after exec_module; a submodule imported later retains the locale-dependent builtin. Fresh evidence in the narrowed implementation is that _utf8_by_loader() verifies only the file's parent directory and a textual loader marker, not whether that module is among those the loader patches.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Rather than add more rules to guess which calls the loader rebind reaches, ab65955 drops the inference. The scan now exempts exactly three reviewed sites, agent.py:31, :47 and :156. All three are function-body open() calls in a module laya/init.py imports eagerly, and they're exempt only while laya_runtime still rebinds open. The vendored files are pinned by sha256, so the lines can't drift. Any new, moved or removed vendored call, including default-argument, lambda-default or lazily imported submodule cases, turns the scan red until someone re-reviews it. A reviewed site that disappears also fails as stale.
| if isinstance(child, (ast.FunctionDef, ast.AsyncFunctionDef, ast.Lambda)): | ||
| if isinstance(child, ast.Lambda) or not _binds_open(child): | ||
| walk(child, True) |
There was a problem hiding this comment.
Avoid exempting definition-time open calls
For a module-level definition such as def f(handle=open(path)): ..., walking the entire FunctionDef with in_function=True marks the default-expression call as covered, but defaults, decorators, and annotations are evaluated by exec_module before _laya() installs _utf8_open. Fresh evidence in this revision is that the narrowed traversal still equates syntactic containment in a function node with execution after module loading, allowing these import-time locale-dependent reads to escape the guard.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Rather than add more rules to guess which calls the loader rebind reaches, ab65955 drops the inference. The scan now exempts exactly three reviewed sites, agent.py:31, :47 and :156. All three are function-body open() calls in a module laya/init.py imports eagerly, and they're exempt only while laya_runtime still rebinds open. The vendored files are pinned by sha256, so the lines can't drift. Any new, moved or removed vendored call, including default-argument, lambda-default or lazily imported submodule cases, turns the scan red until someone re-reviews it. A reviewed site that disappears also fails as stale.
| def walk(node, in_function): | ||
| for child in ast.iter_child_nodes(node): | ||
| if isinstance(child, (ast.FunctionDef, ast.AsyncFunctionDef, ast.Lambda)): | ||
| if isinstance(child, ast.Lambda) or not _binds_open(child): |
There was a problem hiding this comment.
Honor lambda bindings before exempting open
When vendored code uses reader = lambda p, open=open: open(p), the default captures the builtin during exec_module, so the body never consults the module global that _laya() later patches. The unconditional lambda branch nevertheless marks that body call as covered; fresh evidence in this revision is that named-function parameters go through _binds_open() while lambda parameters bypass it entirely.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Rather than add more rules to guess which calls the loader rebind reaches, ab65955 drops the inference. The scan now exempts exactly three reviewed sites, agent.py:31, :47 and :156. All three are function-body open() calls in a module laya/init.py imports eagerly, and they're exempt only while laya_runtime still rebinds open. The vendored files are pinned by sha256, so the lines can't drift. Any new, moved or removed vendored call, including default-argument, lambda-default or lazily imported submodule cases, turns the scan red until someone re-reviews it. A reviewed site that disappears also fails as stale.
| for node in ast.walk(fn): | ||
| if isinstance(node, ast.Name) and node.id == "open" and isinstance(node.ctx, ast.Store): | ||
| return True |
There was a problem hiding this comment.
Keep nested-scope bindings out of the outer function
When a vendored function uses the patched global open() and also has a nested scope that binds the same spelling—for example, text = open(path).read() followed by [open for open in items]—ast.walk(fn) sees the comprehension target's Store and incorrectly concludes that the outer function rebinds open. The outer call is then reported as an encoding offender even though Python resolves it to the loader-patched global, producing a false CI failure against byte-identical vendored code; binding detection needs to stop at nested lexical scopes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Rather than add more rules to guess which calls the loader rebind reaches, ab65955 drops the inference. The scan now exempts exactly three reviewed sites, agent.py:31, :47 and :156. All three are function-body open() calls in a module laya/init.py imports eagerly, and they're exempt only while laya_runtime still rebinds open. The vendored files are pinned by sha256, so the lines can't drift. Any new, moved or removed vendored call, including default-argument, lambda-default or lazily imported submodule cases, turns the scan red until someone re-reviews it. A reviewed site that disappears also fails as stale.
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…upplies UTF-8 (unslothai#12230) * Scope the runtime encoding scan past vendored laya while its loader supplies UTF-8 * Exempt only the vendored open calls the loader swap reaches * Pin the reviewed vendored laya open sites instead of inferring loader coverage
Summary
tests/test_runtime_text_encoding.py::test_shipping_code_names_an_encodingis red on main. Since #12202 vendoredlaya, the repo-level scan walksstudio/backend/vendor/laya/agent.pyand flags three bareopen()calls (lines 31, 47, 156).That file is kept byte-identical to the wheel and pinned by sha256 in
vendor/laya_manifest.json, so it can't be edited. Its encoding comes fromcore/systemone/laya_runtime.py, which injects_utf8_openinto eachlaya.*module.studio/backend/tests/test_text_io_encoding.py::test_vendored_laya_reads_utf8_config_under_a_non_utf8_localeproves this underLC_ALL=C.Change
UTF8_BY_LOADERto map the vendored tree to the loader that supplies UTF-8, plus a marker string..open = _utf8_open. If the injection is removed, the scan turns red again.truststoreand every other vendored or first-party path is still scanned.Verification
_utf8_openassignment fromlaya_runtime.py. The scan fails again.open(p)tounsloth/save.py. The scan fails.