check_writes holds a class by any name, another module's names, sys reached other ways, code run from text and a command a shell runs (#640)
Closes #640.
What changes
tools/check_writes.py now refuses the routes the reads of #596 left open, all but one. It also refuses the routes this PR's own reads found. Each route is one only code written to hide a write would take. On main, only tools/make_corpus.py takes one, and it only reads.
| Route | Now |
|---|---|
| A class, or another module's name, reached through another name | A new _traced reads what an attribute or a key is set on back through the names it is given. That covers a module's constants (P = Port, D = other.TABLE) and a name stored under an if, a try or a walrus. It covers a name a function or a function around it is given, by a default (read where the function is defined), an assignment, a walrus (in a comprehension too) or a tuple's part. It covers a name declared global or nonlocal, and an attribute of a module a local name holds (m.P). vars(m) is read as m. A name a nested scope binds is not the function's own |
| An object's class | An attribute set on type(x), x.__class__, __mro__, __bases__ or __base__, or on a name that holds one, is refused. So are setattr and setitem named as values, and their dunders |
An attribute set as a for, with or comprehension target | Read as an assignment is |
A setter under a module-level if or try, and a text constant shadowed by a nested def, class or catch | Both read |
| Another module's names set from outside | Refused, to anything but text: an attribute or a key set, a container filled by update, append or their kind, or its namespace handed to a call (vars(m), m.__dict__). This covers an instance, a dict, a function or the module itself |
sys.modules and loads reached another way | Refused as a load by name: .modules read on anything; sys as a value, its namespace, through or from another module, or by a literal getattr or key; __builtins__; __import__ as an attribute; pkgutil and runpy; and a loader re-exported by a repo module or reached as its attribute |
| Code run from text | exec, eval and compile are refused, unless the module imports or defines the name (from re import compile passes). exec and eval called as attributes are refused too |
| A command a shell runs | gh or git in any case, by a POSIX or a Windows path, with .exe, and as bytes. It is caught after a new line, ;, &, |, (, { or !; after a word that runs the next one (env, exec, if, while, then, nohup, xargs, sudo, and others), with options and their values; after timeout and its duration; after FOO=1; or quoted. It is caught when it ends at a space, at the end of the text, or at a shell's mark |
from adapters import * on a namespace package | Refused, as for a regular package |
Still not held, as the record says:
- A RUNNERS helper that runs git with whatever arguments its caller gives. Holding each helper to read-only subcommands would change most of the twelve RUNNERS files, six of them hooks.
- A name given by a loop, a
with, a container, a call's return or a starred part. sysor a module reached by agetattrwhose name is not a literal, bymock.patchgiven a module's name, or by running another Python process.- A command after a backtick, built from parts, or read from outside the code.
- A shadow from a
matchcapture. Python 3.9 can't parse amatch, so it refuses the whole file. - A class attribute that holds another class.
- The routes the last reads found: an aliased stored name, a second class traced,
execlet through by a binding that never runs, and others. These are #655's. - Text that runs nothing but reads as a command, a local named
eval, andtype(self).n += 1are all refused. Each fails safe.
Boundary cases are in tests/test_tools.py::Writes. There are 88 mutants under "Issue 640", and earlier mutants whose lines changed were repointed. All 183 check_writes mutants are killed. The check takes about 4s on main, against 3.5s before this PR.
Record 0171 amends decision 0167's row "Still not held".
Allowlist entries, pre-approved by the Maintainer 2026-11-08, ruled by the Factory Builder. No protected path is touched.
- A new list,
PATCHERS = {"tools/make_corpus.py": {"sim.world.decide"}}. That file puts its recorder insim.world's place, which the new rule would refuse. The entry names the one name the file may set, and an entry for a name the file does not set is refused. Adding to it is the Maintainer's call. - RUNNERS +
tools/hooks/shell.py. It is a hook that reads shell commands, and it holds a regex for git and gh. - RUNNERS +
tools/check_workflows.py. It holds the text of the reusable workflows it checks, and that text includestimeout 60 gh api ...lines.
Verify
make verify on an export of 21d76e0, up to date with main and numbered 0171: 1716 tests, OK (8 expected failures). check_decisions, run in the worktree with its history, passes. All 183 check_writes mutants are killed.
Reviews
| Read | State |
|---|---|
| Claude + security | First read (b0a1f36): 3 major, 5 minor, 2 notes, fixed in round 1 (5a99290). Round 1's read: 2 blocking regressions (exec once the name was bound anywhere; global and nonlocal), 1 major (a re-exported importlib) and minors. All are fixed in round 2, the last fix round. Round 2's read: nothing blocking. One finding restored a refusal main holds, a write to sys.modules, fixed in 21d76e0. Its other routes are #655's |
| Argon | First read: 5 major and 1 minor; 4 were real, all fixed in round 1. Round 1's read: 5 major and 1 minor; 5 were real, all fixed in round 2. The minor one, a local import shadow, is already refused as a name bound two ways. Round 2's read: 2 major and 1 minor, all routes in the new reading, now #655's |
| Muse | not run (quota); owed after 2026-11-09 |
| Astra | not run (quota) |
| Codex | out of quota |
š¤ Generated with Claude Code