Repository navigation
fix(facade): host the dspy facade in in-process interpreters without replacing host dspy - #10627
Merged
Merged
Conversation
Contributor
|
isaacbmiller
force-pushed
the
3.4.1/flex-inprocess-refused
branch
from
October 12, 2026 16:39
fa82784 to
98556b3
Compare
…replacing host dspy The shim refused any interpreter whose code runs in the host's memory, so dspy.Flex failed every forward on exec()-based interpreters such as dspy_interpreters.InProcessInterpreter (RLM degraded to no sub-agents). The refusal removed no capability: in-process code already has the host's memory. What it prevented was the shim replacing the host's sys.modules["dspy"]. In the host's memory, the shim now binds dspy through the interpreter namespace's own __import__ and leaves sys.modules alone. Isolated sandboxes keep registering the shim in sys.modules. Docs say an in-process interpreter isolates nothing. Amp-Thread-ID: https://ampcode.com/threads/T-01a12205-a696-77cb-8f91-6b213cec210f Co-authored-by: Isaac Miller <isaac@cmpnd.ai>
Addresses review: the in-process regression test only exercised a bare 'import dspy'. The generated module now also checks that 'import dspy.predict' raises ModuleNotFoundError instead of reaching the host's dspy package. Amp-Thread-ID: https://ampcode.com/threads/T-01a12205-a696-77cb-8f91-6b213cec210f Co-authored-by: Isaac Miller <isaac@cmpnd.ai>
isaacbmiller
force-pushed
the
3.4.1/flex-inprocess-refused
branch
from
October 12, 2026 19:18
98556b3 to
1a4f7aa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Changes Description
Since #10478, the sandbox
dspyfacade shim (_facade_shim.py) refuses any interpreter that runs code in the host's memory.dspy.Flexinstalls the facade with no fallback, so every forward on an exec()-based interpreter, includingdspy_interpreters.InProcessInterpreter, raisesCodeExecutionError: ... the dspy facade needs an isolated interpreter. RLM falls back to running without sub-agents. 3.4.0 works with these interpreters, but its shim could leave itself in the host'ssys.modules["dspy"].The refusal doesn't remove any capability: in-process code already shares the host's memory. What it actually prevented was the shim replacing the host's
dspymodule. Only an explicit choice reaches an in-process interpreter: the module'sinterpreter_factoryordspy.settings.interpreter_factory. The default isPythonInterpreter, andLocalInterpreteris a fresh subprocess.This PR:
dspythrough the interpreter namespace's own__import__(a per-namespace copy of__builtins__) instead ofsys.modules. Sandboxedimport dspygets the shim,import dspy.<sub>raisesModuleNotFoundErroras it does in a real sandbox, and the host'ssys.modulesis untouched. Isolated sandboxes still register the shim insys.modules.sys.modules, plus a host tool that checkssys.modules["dspy"] is dspyduring the forward. It also flips the RLM anddspy_interpretersconformance tests that pinned the refusal.Verification:
sys.modulesfails the new Flex test.pytest -n auto --deno tests/flex tests/predict/test_rlm.py tests/primitives: 547 passed, 5 skipped.Predict+ChainOfThought+ host tool) onInProcessInterpretersucceeds with the host'sdspyintact.✅ Contributor Checklist
Targeted for 3.4.1. Sibling fixes R2 (#10625) and R7 (facade opt-out) also touch
_facade_shim.pyandrlm.py; this diff changes only the finalifblock of the shim, so a rebase conflict would be small. Prepared with Amp in a maintainer-directed session.