Repository navigation
sdk-python: break the client/template import cycle; use Client.attach in the openai adapter - #354
Merged
Merged
Conversation
template.py imported _claim_body and _template_query from client inside two methods to dodge the client -> sandbox -> template -> client cycle. Both are pure request builders, so they now live in template.py beside their main caller, which depends only on the volumes leaf at import time. client.py imports them at the top. No behavior change.
The adapter rebuilt the handle by hand with Sandbox(client=..., id=..., token=..., owner=...), which is exactly what Client.attach does.
CMGS
force-pushed
the
refactor/py-sdk-import-cycle
branch
from
October 17, 2026 16:27
c9a4b12 to
4332c66
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.
Summary
Template.newandTemplate.deleteimported_claim_bodyand_template_queryfromclientinside the method bodies to avoid the client -> sandbox -> template -> client cycle. Both functions are pure request builders, so they move totemplate.py, next to their main caller.template.pynow depends only on thevolumesleaf at import time, andclient.pyimports the builders at the top. The two function-local imports and the comment explaining them are gone.Sandbox(client=..., id=..., token=..., owner=...), which is exactly whatClient.attach(owner, id, token)does. It now callsattach.No behavior change and no public API change;
checkpoint.pyhas no function-local imports, so it needed no fix.Test plan
CI commands run locally (Python 3.12 venv, CI-pinned ruff 0.15.22, pytest 8.4.2, mypy 1.20.2):
ruff format --check . && ruff check .: 36 files already formatted, all checks passedcd sdk/python && python -m pytest -q: 251 passedcd sdk/python && python -m mypy: no issues found in 10 source filescd sdk/openai && python -m pytest -q: 10 passedcd sdk/langchain && python -m pytest -q: 15 passedpython -I -c "import cocoonsandbox.template"as the first import succeeds