Skip to content

feat(sdk): basilica.distributed(command=...) factory shape (fixes one-covenant/basilica-backend#662)#486

Merged
epappas merged 1 commit into
mainfrom
sdk-simplification/662-command-factory
May 18, 2026
Merged

feat(sdk): basilica.distributed(command=...) factory shape (fixes one-covenant/basilica-backend#662)#486
epappas merged 1 commit into
mainfrom
sdk-simplification/662-command-factory

Conversation

@epappas
Copy link
Copy Markdown
Contributor

@epappas epappas commented May 18, 2026

Summary

SDK-S3 from the SDK API simplification plan. Collapses BYO-launcher deploys
into the canonical basilica.distributed surface, dropping the _managed
suffix as the user-facing entry point.

  • Today: client.deploy_distributed_managed(command=[...]) for BYO
    launcher. The _managed suffix signals SDK plumbing; users must learn
    both suffixed/unsuffixed variants and pick on cleanup-contract grounds.
  • After: basilica.distributed(command=[...], ...) invoked WITHOUT a
    decorated function returns a DistributedTraining directly (factory
    mode). Same symbol still works as a decorator on a function (decorator
    mode unchanged). with training: opens the canonical context manager
    (wired in SDK-S1).

Plan + ticket

  • Plan: docs/plans/SDK-API-SIMPLIFICATION-PLAN.md on basilica-backend main, Problem 4
  • Tracking issue: one-covenant/basilica-backend#662
  • Builds on S1 (one-covenant/basilica#484, merge 0860a995) and S2
    (one-covenant/basilica#483, merge ca2d2e75; #485 test patch merge
    b7ce2bdc). Both already landed DistributedTraining.__enter__ /
    __exit__ and the _emit_deprecation=False plumbing that this S3
    factory path reuses.

Implementation

  • crates/basilica-sdk-python/python/basilica/decorators.py
    • Add command: Optional[List[str]], args: Optional[List[str]], and
      client: Optional[BasilicaClient] parameters to distributed(...).
    • When command is set, short-circuit to _deploy_command_factory
      (new helper) which materializes a BasilicaClient if none was
      supplied, calls deploy_distributed(..., _emit_deprecation=False),
      and returns the DistributedTraining directly.
    • Decorator mode (no command) is byte-for-byte identical to the
      pre-fix shape; the new branch is additive.
    • Return type widened to Union[Callable[[Callable], DistributedFunction], DistributedTraining].
  • crates/basilica-sdk-python/tests/test_distributed_command_factory.py
    • 8 new tests (file:line of the fix targets: decorators.py:481-650).
    • 4 pre-fix-failing tests pin the new factory shape
      (TestDistributedCommandFactory).
    • 4 pre-fix-passing tests pin regressions
      (TestDecoratorFormStillWorks, TestManagedBYORedirection,
      TestFactoryArgumentValidation).
  • Version: 0.29.5 -> 0.29.6 (pyproject.toml, Cargo.toml,
    Cargo.lock). CHANGELOG entry under [0.29.6].

Failing-then-passing test evidence

Pre-fix (against main source):

FAILED ...test_factory_call_with_command_returns_distributed_training
FAILED ...test_factory_training_is_context_manager_able
FAILED ...test_factory_call_does_not_emit_deprecation_warning
FAILED ...test_factory_uses_default_client_when_none_supplied
========================= 4 failed, 4 passed in 0.18s ==========================

Post-fix (this branch):

8 passed in 0.13s

Full SDK suite post-fix (excluding pre-existing test_dns_propagation_e2e.py
which needs httpx): 201 passed, 0 failed.

Cross-repo deserialization impact

None. The wire shape stays unchanged -- command and args already
flow through deploy_distributed -> _build_distributed_request ->
spec.distributed.command / spec.command. This PR only changes the
Python user-facing entry point; no operator / CRD / basilica-backend
deserializer touched. Per feedback_cross_repo_types.md audited.

Lint / CI gates

  • cargo fmt --all -- --check clean
  • cargo check -p basilica-sdk-python clean
  • cargo clippy -p basilica-sdk-python -- -D warnings clean
  • Example syntax-check clean (no examples touched)
  • Version-consistency: Cargo.toml + pyproject.toml + Cargo.lock all on 0.29.6

What is NOT in this PR

  • Removal of deploy_distributed_managed / deploy_distributed /
    DistributedTrainingManaged[Async] -- they stay deprecated-but-functional
    for two minor versions per the plan; removed in SDK-S7 at the next major.
  • Migration of examples/21_distributed_torchrun.py and
    examples/22_distributed_with_bench.py to the factory form -- that is
    SDK-S5.
  • source: Union[str, Path] deprecation -- that is SDK-S4.
  • PyPI publish of 0.29.6 -- pending separate user authorization.

Test plan

  • Failing pre-fix tests captured (8 tests, 4 fail pre-fix)
  • Post-fix tests pass (8/8)
  • Full SDK suite green (201/201)
  • cargo fmt --check / cargo check / cargo clippy -- -D warnings clean
  • Version drift check passes (Cargo.toml / pyproject.toml / Cargo.lock)
  • CI green on this PR
  • Merged via --merge (NOT --squash)

…-covenant/basilica-backend#662)

basilica-backend issue 662 / SDK-S3. Collapses the BYO-launcher path into
the canonical basilica.distributed surface used for function-body deploys.

Today: BYO launcher requires client.deploy_distributed_managed(command=[...]).
The _managed suffix signals SDK plumbing rather than user-facing semantics;
callers had to learn both the suffixed and unsuffixed shapes and pick
between them on cleanup-contract grounds.

After: basilica.distributed(command=[...], ...) called WITHOUT decorating a
function returns a DistributedTraining directly (factory mode). The same
symbol still works as a decorator when given a function. Internally the
factory path calls deploy_distributed(_emit_deprecation=False) -- the
canonical surface stays silent for both decorator and factory shapes.
Pass client= to inject an existing BasilicaClient; otherwise a default
one is built lazily (mirrors the decorator's .deploy() semantics).

Implementation:
- crates/basilica-sdk-python/python/basilica/decorators.py: add
  command=, args=, client= params on distributed(); when command is set,
  short-circuit to _deploy_command_factory which builds (or accepts)
  the client and calls deploy_distributed with _emit_deprecation=False.
- crates/basilica-sdk-python/tests/test_distributed_command_factory.py:
  8 new tests pinning the factory shape (returns DistributedTraining,
  is context-manager-able, does not warn, accepts client=, regression-
  pins the decorator-on-function path, re-pins the managed-BYO
  DeprecationWarning).
- Version bump 0.29.5 -> 0.29.6 (pyproject.toml, Cargo.toml, Cargo.lock).
- CHANGELOG entry under [0.29.6].

Refs: SDK API simplification plan (docs/plans/SDK-API-SIMPLIFICATION-PLAN.md
on basilica-backend main), Problem 4 / SDK-S3 ticket. Builds on the S1
context-manager wiring (basilica-backend#660 / PR #484) and the S2
bench-bool collapse (basilica-backend#661 / PRs #483, #485).
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

Warning

Rate limit exceeded

@epappas has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 29 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4145b1c6-f3a3-42c6-9ca4-a323692f8677

📥 Commits

Reviewing files that changed from the base of the PR and between b7ce2bd and 2f7fce9.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • crates/basilica-sdk-python/CHANGELOG.md
  • crates/basilica-sdk-python/Cargo.toml
  • crates/basilica-sdk-python/pyproject.toml
  • crates/basilica-sdk-python/python/basilica/decorators.py
  • crates/basilica-sdk-python/tests/test_distributed_command_factory.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sdk-simplification/662-command-factory

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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