FE-1470: Split the Python bindings' transport from the session facade - #9278
FE-1470: Split the Python bindings' transport from the session facade#9278kube wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
PR SummaryLow Risk Overview
No change to exported names, signatures, or exception behavior. Tests follow the moved constants and assert the new factories spawn the same CLI invocations. Reviewed by Cursor Bugbot for commit b2ba703. Bugbot is set up for automated code reviews on this repo. Configure here. |
session.py mixed ~300 lines of process machinery with the 50-line model-protocol facade a consumer actually reads. The machinery moves to a private _transport.py (CliTransport: spawn, bootstrap, bounded reads, timeouts, process-group shutdown, the JSON-lines exchange); the session classes each own one transport and keep only their protocol vocabulary. OptimizationSession gains from_manifest and from_manifest_file, mirroring the base class's factories, so both classes construct the same way: name the source, get the session. Both class docstrings now state the superset rule — a manifest-serving process still answers every model-protocol method, and only it answers optimization.*. No public API changes; the suites run unchanged apart from three assertions that reached into _request_timeout_seconds and two module-level monkeypatches, which follow the constants to _transport.
d95943f to
b2ba703
Compare
🌟 What is the purpose of this PR?
Review on #9228 asked when to use
session.pyand when to useoptimization.py, and the honest answer was hard to see in the code:session.pymixed ~300 lines of process machinery with the 50-line model-protocol facade a consumer actually reads, and the two session classes constructed differently. This PR separates the machinery from the vocabulary and makes the two classes construct the same way.Part of stack #9280: sits on FE-1412 (#9229), with the arch-docs PRs above.
🔗 Related links
🔍 What does this change?
New private module
_transport.py.CliTransportowns everything about how the child process is driven: spawn with a scrubbed environment, the bootstrap line and readiness wait, size- and time-bounded reads, the JSON-lines exchange with checked ids, and process-group shutdown. The line-cap constants,encode_bootstrap_line, and the child environment move with it. Nothing in the module knows what any protocol method means.session.pyis now the part a consumer reads.PetrinautSessionkeeps the factories,healthz/metadata/run/request, and delegatesstart/closeto the transport it owns. The file drops from ~470 lines to ~160, all of them protocol surface.OptimizationSessionconstructs like its base class. Newfrom_manifest(manifest)andfrom_manifest_file(path)mirrorfrom_model/from_model_file; the positional constructor stays. Choosing a class is now the same gesture in both cases: name what the process serves.The superset rule is stated where readers look. Both class docstrings now say it: a manifest embeds a model and the CLI serves both from one process, so every
PetrinautSessionmethod works on anOptimizationSession, and only the latter answersoptimization.*.No public API changes: every exported name, signature, and exception is as before.
Pre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
@local/petrinaut-pythonis private to the monorepo.📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
🛡 What tests cover this?
The existing 31 bindings tests and 75
petrinaut-opttests run unchanged, apart from three assertions that reached into_request_timeout_secondsand two module-level monkeypatches, which follow the constants to_transport. One new test pins that the manifest factories spawn the same CLI invocations as the constructor forms.❓ How to test this?
turbo run test:unit lint:ruff lint:types --filter @local/petrinaut-python --filter @apps/petrinaut-opt🤖 Generated with Claude Code