Skip to content

sdk-python: break the client/template import cycle; use Client.attach in the openai adapter - #354

Merged
CMGS merged 2 commits into
mainfrom
refactor/py-sdk-import-cycle
Oct 17, 2026
Merged

CMGS merged 2 commits into
mainfrom
refactor/py-sdk-import-cycle

Conversation

@CMGS

@CMGS CMGS commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Template.new and Template.delete imported _claim_body and _template_query from client inside the method bodies to avoid the client -> sandbox -> template -> client cycle. Both functions are pure request builders, so they move to template.py, next to their main caller. template.py now depends only on the volumes leaf at import time, and client.py imports the builders at the top. The two function-local imports and the comment explaining them are gone.
  • The openai adapter built a handle with Sandbox(client=..., id=..., token=..., owner=...), which is exactly what Client.attach(owner, id, token) does. It now calls attach.

No behavior change and no public API change; checkpoint.py has 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 passed
  • cd sdk/python && python -m pytest -q: 251 passed
  • cd sdk/python && python -m mypy: no issues found in 10 source files
  • cd sdk/openai && python -m pytest -q: 10 passed
  • cd sdk/langchain && python -m pytest -q: 15 passed
  • python -I -c "import cocoonsandbox.template" as the first import succeeds

CMGS added 2 commits October 18, 2026 00:17
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
CMGS force-pushed the refactor/py-sdk-import-cycle branch from c9a4b12 to 4332c66 Compare October 17, 2026 16:27
@CMGS
CMGS merged commit 914a296 into main Oct 17, 2026
2 checks passed
@CMGS
CMGS deleted the refactor/py-sdk-import-cycle branch October 17, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant