Repository navigation
Studio: build the blocked-command alternation once instead of per call - #10927
Conversation
_find_blocked_commands rebuilt its blocked-word regex on every command it screened. _BLOCKED_COMMANDS is a module-level frozenset assigned at import and never mutated, so that alternation is a compile-time constant and the work was pure waste: an re.escape per blocked name per command, then a fresh re.compile behind re.findall's cache lookup. It showed up as the top entry when profiling the scan over a 2637 command corpus, 567k calls to re.escape and 0.60s cumulative out of 3.9s. Hoisting it to a module-level compile takes the median from about 101 us to about 86 us per command, measured on interleaved pairs against main (the hoist wins all five pairs; absolute figures run high because the host is loaded, so only the pairing is meaningful). No behaviour change, and not taken on trust: verdicts were dumped for 1829 payloads on both sides, covering the corpus plus the command-position substitution shapes from #10860, path-qualified and .exe spellings, and ordinary commands. Zero differences. tests/test_sandbox_tools.py, tests/test_permission_mode.py, tests/test_bypass_permissions.py and tests/test_windows_bash_shell.py stay green (2199 passed, 5 skipped). This is per command screened, not per token, so it changes nothing about inference throughput. It is worth doing because the scan runs on every command a model issues.
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. |
|
@codex review |
|
@codex security review |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
_find_blocked_commandsrebuilt its blocked-word regex on every command it screened._BLOCKED_COMMANDSis a module-level frozenset assigned at import and never mutated, so that alternation is a compile-time constant and rebuilding it was pure waste: anre.escapeper blocked name per command, then a fresh pattern string handed tore.findallfor its cache to look up.It is the top entry when profiling the scan over a 2637 command corpus:
Measurement
Interleaved pairs against
main, alternating trees to cancel host drift:About 15 percent off the median, and the branch wins all five pairs. The absolute figures run high because the host is under heavy load right now, so the pairing is the part worth reading, not the numbers themselves.
This is per command screened, not per token, so it changes nothing about inference throughput. It earns its place because the scan runs on every command a model issues.
Behaviour
No change, and not taken on trust. Verdicts were dumped on both sides for 1829 payloads covering the test corpus plus the command-position substitution shapes from #10860, path-qualified spellings (
/usr/bin/rm,./rm), the.exevariants, and ordinary commands. Zero differences.ruff checkandscripts/run_ruff_format.pyboth pass.Note
The
Nonebranch is there because_BLOCKED_COMMANDSis built conditionally per platform (line 192), so an empty set stays representable rather than compiling an alternation with nothing in it.Found while benchmarking #10860 before merge. Independent of that change and of #10907 and #10895, which touch different functions in the same file.