Skip to content

scripts/regress: load each revision's tool with its own imports - #3190

Closed
dpadr wants to merge 1 commit into
seedds:mainfrom
dpadr:nutmeg/regress-tree-imports
Closed

dpadr wants to merge 1 commit into
seedds:mainfrom
dpadr:nutmeg/regress-tree-imports

Conversation

@dpadr

@dpadr dpadr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Summary

regress.py check loads pso_offline.py from both the baseline's and the candidate's trees in one process, for the interface check. The tool imports its helpers by name: dmsh_abi, dmsh_side, shader_lib, romfs, vol_space. A module imported by name is cached in sys.modules, so whichever tree loaded first supplied those modules to the other.

How it showed up: a candidate that adds a dmsh_abi constant (#3176, DMSH_BLEND_OFF_FC) failed the interface check of every NVN game. The candidate's tool looked the constant up in the baseline's header:

File ".../trees/a7710c43169e/dm/gfx/tools/pso_offline.py", line 59, in <module>
  HOST_CONSTANTS = {..., 'dm_blend_off': (abi.BLEND_OFF_FC, True)}
File ".../trees/656f88440210/dm/gfx/tools/dmsh_abi.py", line 38, in __getattr__
AttributeError: .../trees/656f88440210/dm/gfx/tools/../nvn/dmsh_abi.h defines no DMSH_BLEND_OFF_FC

The same sharing could also hide a real difference between the trees, quietly checking both with one tree's helpers.

The fix: load_tree_module loads a revision's tool with its own imports.

  • The non-stdlib modules already loaded are hidden while the tool runs, then put back.
  • The modules the tool loads itself stay bound in its globals and are removed from sys.modules.
  • sys.path is restored.
  • The interface check is the only place that loads a tree's tool, and it now uses this.

Tests

  • New: test_regress.TreeModules. Two temporary trees each ship a helper with the same name and a tool that imports it. Each tool must get its own helper; sys.path and sys.modules must come back unchanged.
  • The suite: python3 -m unittest dm.tools.tests.test_regress passes 71/71.
  • On the real trees: loading pso_offline.py from 656f884 and a7710c4 in one process, in either order, each gets its own dmsh_abi. Main's tree gets only dm_border_off; the candidate gets dm_border_off and dm_blend_off.
  • End to end: with this fix, regress.py check --baseline 656f8844 --candidate a7710c43 on SR, Animal Well and UFO 50 finished with exit 0. The same check without it gave exit 2, with SR and Animal Well erroring.

🤖 Generated with Claude Code

regress.py loads pso_offline.py from the baseline's and the candidate's trees in one
process. The tool imports dmsh_abi, dmsh_side, shader_lib and others by name, so the
second tree got the first tree's copies from sys.modules: a candidate that adds a
dmsh_abi constant (DMSH_BLEND_OFF_FC) failed the interface check of every NVN game with
the baseline's header. load_tree_module hides the non-stdlib modules already loaded
while the tool runs, drops the ones it loaded afterwards (they stay bound in its globals)
and restores sys.path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the tools Tools and scripts (dm/tools, scripts) label Nov 22, 2026
seedds added a commit that referenced this pull request Nov 22, 2026
…(PR #3190)

interface_check was the only place in scripts/regress.py that loaded a revision tree's Python tool in-process via load_module. Because pso_offline.py imports dmsh_abi, dmsh_side, romfs, shader_lib and vol_space by name, the baseline and candidate shared sys.modules (and got the harness checkout's romfs), causing a candidate that adds a dmsh_abi constant (such as PR #3176's DMSH_BLEND_OFF_FC) to fail with AttributeError against the baseline's header and risking silently masking helper differences.

Run pso_offline.read_pairs/pair_text and (when suspects exist) pso_offline.plan through Tree.py with JSON over stdin instead, matching how regress.py already isolates dmsh_chain and game.py.

Co-authored-by: David Padron-Harris <34929160+dpadr@users.noreply.github.com>
@seedds

seedds commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Thank you @dpadr for finding and reproducing this cross-revision import sharing bug on #3176!

Landed on main in e531be8 (with Co-authored-by credit for your diagnosis). Instead of hiding and restoring sys.modules in-process—which could drop newly imported standard-library modules, leave the checkout's paths on sys.path, and miss lazy imports inside functions—interface_check now runs each revision's pso_offline.py in its own Python subprocess via Tree.py (passing JSON on stdin), matching how scripts/regress.py already isolates other revision-tree tools.

Checked with the full test_regress suite (71/71, including a new test covering two trees with different dmsh_abi constants, romfs helpers, and lazy imports in both orders), ruff, and a direct run of interface_check against the repository's pso_offline.py. Nothing left open here.

@seedds seedds closed this Nov 22, 2026
Aznracer pushed a commit to Aznracer/Mighty-Green-Kokiri-Kid that referenced this pull request Nov 25, 2026
…(PR seedds#3190)

interface_check was the only place in scripts/regress.py that loaded a revision tree's Python tool in-process via load_module. Because pso_offline.py imports dmsh_abi, dmsh_side, romfs, shader_lib and vol_space by name, the baseline and candidate shared sys.modules (and got the harness checkout's romfs), causing a candidate that adds a dmsh_abi constant (such as PR seedds#3176's DMSH_BLEND_OFF_FC) to fail with AttributeError against the baseline's header and risking silently masking helper differences.

Run pso_offline.read_pairs/pair_text and (when suspects exist) pso_offline.plan through Tree.py with JSON over stdin instead, matching how regress.py already isolates dmsh_chain and game.py.

Co-authored-by: David Padron-Harris <34929160+dpadr@users.noreply.github.com>
(cherry picked from commit e531be8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools Tools and scripts (dm/tools, scripts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants