test(hook): re-arm the model-load guard in the import-cost probe's subprocess env - #785
Conversation
…bprocess env `tests/conftest.py` arms BRAINLAYER_FORBID_EMBEDDING_MODEL for every unmarked test and says the point is that subprocesses inherit it -- "a test that SPAWNS a re-embedding script loads a model just as surely as one that imports it, and sys.modules cannot see that happen". `run_probe()` in tests/test_prompt_search_cap.py (added by #782) passes an explicit minimal env to get a clean interpreter, which strips that variable. Its two probes were therefore the exact subprocess hole the guard exists to close. Not a live bug -- both probes only import, then assert nothing heavy reached sys.modules, which is stricter than the guard. But that is a property of what those two probes happen to do, not of the helper, and the next test to use it would inherit the hole. Re-armed explicitly. It also strengthens the probes: a model loaded at hook import time now trips the repo guard as well as the assertion. Found by re-reading AGENTS.md while #782's CI ran, not in review. Split out per fleet canon rule 9 rather than pushed onto #782. Co-Authored-By: brainlayerClaude running claude-opus-5 <noreply@anthropic.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_05e1de9b-5e87-4f5f-9bab-78971f742769) |
|
You have reached your Codex usage limits. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reachedNext included review available in 38 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Team Run ID: 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| Python | Sep 5, 2026 5:11p.m. | Review ↗ | |
| Swift | Sep 5, 2026 5:11p.m. | Review ↗ | |
| JavaScript | Sep 5, 2026 5:11p.m. | Review ↗ | |
| Shell | Sep 5, 2026 5:11p.m. | Review ↗ | |
| Secrets | Sep 5, 2026 5:11p.m. | Review ↗ |
Important
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
BrainLayer ratchetEvery Value below was measured by this run. A row this machine cannot measure says
🟢 GREEN measured, within budget · 🔴 RED measured, out of budget — a finding to clear before merge · ⚪ n/a not measurable on this machine, never guessed. No RED rows. Measured on Linux/x86_64 · measured |
|
@coderabbitai review XS, one file, +11/-1. The change adds Worth checking: the env dict is deliberately minimal (only Heads-up: your free-OSS quota was exhausted on #782 and every pass there returned — brainlayerClaude (worker) · claude-code/claude-opus-5 |
|
Merge freeze on |
🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '=== PR diff ==='
git diff --unified=80 origin/main...HEAD -- tests/test_prompt_search_cap.py tests/conftest.py
printf '%s\n' '=== test_prompt_search_cap.py outline ==='
ast-grep outline tests/test_prompt_search_cap.py --items all
printf '%s\n' '=== conftest.py outline ==='
ast-grep outline tests/conftest.py --items all
printf '%s\n' '=== Guard variable definitions and reads ==='
rg -n -C 5 --glob '*.py' \
'BRAINLAYER_FORBID_EMBEDDING_MODEL|FORBID_EMBEDDING_MODEL' \
tests srcLength of output: 16539 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '=== embeddings guard and model construction sites ==='
sed -n '1,180p' src/brainlayer/embeddings.py
printf '%s\n' '=== conftest guard fixture ==='
sed -n '285,335p' tests/conftest.py
printf '%s\n' '=== import-cost probes ==='
sed -n '390,450p' tests/test_prompt_search_cap.py
printf '%s\n' '=== hook imports and embedding-related references ==='
rg -n -C 4 --glob '*.py' \
'brainlayer\.embeddings|guard_embedding_model_load|SentenceTransformer|FlagEmbedding|embedding' \
hooks/brainlayer-prompt-search.pyLength of output: 13929
The two probes do not call that load path. Their import-cost measurement remains unchanged. The new variable correctly makes an unexpected model load fail.
|
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_d32a5c83-216e-490b-8066-f6acb097172a) |
All six sites: pyproject.toml, src/brainlayer/__init__.py, server.json (root + packages[0]), brain-bar/bundle/Info.plist (short, bundle, release). Casks/brainbar.rb stays 1.5.9: no Swift change this release, declared to scripts/brainlayer-version-check.sh via BRAINLAYER_VERSION_CHECK_CASK_LAG_REASON="no BrainBar release for 1.5.16" (kept in the PR body, never exported into the push env — two tests assert the check fails without a reason). Why a release, 22 minutes after the last one. v1.5.15 was tagged at 51a72a0 (20:12:29). #778 — the index runtime watchdog — merged at 78d92bc (20:34:55), so it is NOT in 1.5.15. Verified: `git merge-base --is-ancestor 78d92bc v1.5.15^{}` -> false, and the installed keg's python raises `ModuleNotFoundError: No module named 'brainlayer.index_watchdog'`. That watchdog is the fix for the M1's nightly `brainlayer index` job, which ran 14h03m at ~100% CPU on 09-05, 10h past its own 4h cap. Both Macs' 03:15 index jobs are `launchctl disable`d as a stopgap and come back ON only after 1.5.16 is installed and the watchdog is proven present. Nine commits ride along: #774 #777 #780 #778 #783 #785 #786 #787 #788. Co-authored-by: brainlayerClaude-c1601b03 running claude-opus-5 <noreply@anthropic.com>
What
XS.
tests/conftest.pyarmsBRAINLAYER_FORBID_EMBEDDING_MODELfor every unmarked test, and its own comment says why the inheritance matters:run_probe()intests/test_prompt_search_cap.py(added by #782) passes an explicit minimal env to get a clean interpreter:That strips the guard variable, so its two import-cost probes were the exact subprocess hole the guard exists to close. Re-armed explicitly, with the reason inline.
Why it is not a live bug, said plainly
Both probes only import and then assert nothing heavy reached
sys.modules— stricter than the guard would be. So nothing was actually unguarded in practice. But that is a property of what those two probes happen to do, not of the helper, and the next test to callrun_probe()would inherit the hole silently.AGENTS.mdcalls suite hygiene "enforced not just written down"; this restores the enforcement.It also makes the probes stronger: a model loaded at hook-import time now trips the repo's guard as well as the assertion.
Provenance
Found by re-reading
AGENTS.mdwhile #782's CI ran — self-caught, not raised in review. Split out per fleet canon rule 9 (a defect found mid-PR opens a NEW PR, never another commit on the same branch) rather than pushed onto #782, on the lead's ruling. Branched fresh offmainat123da9b4.Green
tests/test_prompt_search_cap.py: 63 passed.BRAINLAYER_FORBID_EMBEDDING_MODEL=1read back from inside a spawned interpreter) rather than only asserting the source string is present.ruff check+ruff format --checkclean.Bot policy
brainlayer/AGENTS.md→ "Do not route mandatory reviews to Bugbot or Greptile." Panel: CodeRabbit only. No@codex— Etan's standing rule until Mon 2026-09-07 04:00 (the connector shares the CLI pool, at ~2%). Note CodeRabbit's free-OSS quota was exhausted on #782, so it may returnReview limit reachedhere too; if it does, that is a gap and not a pass, and I will say so rather than let a green check imply a review.— brainlayerClaude (worker) · claude-code/claude-opus-5
Note
Low Risk
Test-only subprocess environment change; no production or runtime behavior is modified.
Overview
run_probe()intests/test_prompt_search_cap.pynow setsBRAINLAYER_FORBID_EMBEDDING_MODEL=1in the subprocess environment alongside the minimalPATH/PYTHONPATHdict.Because an explicit
envreplaces the parent process environment, the import-cost probes were no longer inheriting the guard thatconftestarms for unmarked tests. That left a subprocess path where a spawned interpreter could load an embedding model without tripping the repo-wide forbid check, even though the probes’ ownsys.modulesassertions were still strict. Re-arming the variable restores suite hygiene for any futurerun_probe()callers and makes hook import-time model loads fail the guard as well as the heavy-deps assertion.Reviewed by Cursor Bugbot for commit a4b7314. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Set
BRAINLAYER_FORBID_EMBEDDING_MODEL=1inrun_probesubprocess envThe
run_probetest helper builds an explicit subprocess environment that previously omitted the embedding-model guard. This means child interpreters inherited the default and could load the embedding model during hook import without tripping the guard. The helper now sets the flag so import-time and probe-time loading both fail.Macroscope summarized 44998bd.