Repository navigation
sdk(python): adopt no-codegen-at-runtime + slim module runtime - #13593
Conversation
|
Added a follow-up commit: Every module function call boots a fresh interpreter, so import cost is paid 2–3× per Numbers: entrypoint import 301→165ms (−45%); end-to-end scenario (playground, dev engine): cold call 5613→5007ms, first call of a new function 2704→2450ms, fully-warm calls unchanged (their cost is the per-session module-loading protocol, everything engine-side is already cached — separate topic). |
adfcda9 to
5d05854
Compare
5d05854 to
a2718f7
Compare
a2718f7 to
c969be3
Compare
a49d4b4 to
500cd6c
Compare
eabe3df to
12c084e
Compare
de313be to
7822a35
Compare
| # Engine provisioning (doesn't make sense in modules: connections always come | ||
| # from the session environment there, so don't pay its import cost on every | ||
| # function call) | ||
| if not os.getenv("DAGGER_MODULE"): |
There was a problem hiding this comment.
In a module runtime this drops Connection, connection, Config, DownloadError, ProvisionError, SessionError from the dagger namespace. I checked the SDK's own runtime code doesn't reference any of them (only this file imports dagger.provisioning), so it's internally safe. Just confirming it's intended that user module code can no longer reference e.g. dagger.connection at top level — reasonable since you never provision inside a module, but a subtle removal worth a conscious call (and maybe a changelog line).
There was a problem hiding this comment.
Is it something we are using on other SDKs? To provision engines from inside of a module? If not, I think it's just fine to remove it
There was a problem hiding this comment.
This was part of the "leaner interpreter boot" commit, which has since been dropped from the PR — the small per-call win was not worth the behavior changes you flagged here. So this no longer applies. Thanks for the review!
| conf=BeartypeConf( | ||
| violation_param_type=TypeError, | ||
| violation_verbosity=BeartypeViolationVerbosity.MINIMAL, | ||
| if os.getenv("DAGGER_MODULE"): |
There was a problem hiding this comment.
Nice boot-time win. One DX note: with decoration off, a Python-level type mismatch on a generated client call now surfaces as an engine/API error rather than a local TypeError. The golden traceback is updated so this is clearly intended — worth a changelog mention alongside the codegen rule, since it (and the provisioning change) are user-observable in modules.
There was a problem hiding this comment.
This was part of the "leaner interpreter boot" commit, which has since been dropped from the PR — the small per-call win was not worth the behavior changes you flagged here. So this no longer applies. Thanks for the review!
There was a problem hiding this comment.
I left 2 design comment caught from claude but I'll approve the PR since I tested manually and it works as expected.
Manual test I did using a dev engine and beta.6 + python-sdk on main.
- Install the python sdk
- Create a module hello
- Run generate -> the skip correctly work and so my generation is completed
- dagger api functions
- dagger api call --help (quite fast btw that's pleasant)
- add function to the code and run
dagger api call <my-mod> --help - call the function I just added
- delete the
sdkdir and do api call -> fails as expected, the error message is clear:run dagger generate - dagger generate work after and the module is back to normal 🚀
Multi module test
- creating 2 python module and run generate -> work
- delete
sdkfrom one module and run api functions -> fails, should we still allow loading the working module or it is expected? - Run generate after -> work
- Add 1 module as a dependency of the other and run generate: FAIL -> click to go to the repro message
|
I found a bug, here's the repro: # Init 2 local python module
dagger sdk install python
dagger module init python hey
dagger module init python hello
dagger generate
# Add code to each module (whatever functions)
# Add one module has a dependency of the other
cd .dagger/modules/hello
dagger module deps add ../hey
# Regenerate to get new bindings
dagger generate # THIS FAILSThe generate will fail, see trace: https://dagger.cloud/Quartz/traces/9d328197968d11ae724ba374f9f5f3b9?listen=8fa3bceb980e10e8 EDIT: this bug also happen with #13621 so I assume it's an engine issue |
|
@TomChv could you explain a bit more this one please?
If the thing is "when a module can't be loaded |
Yeah that's it! |
Got it, it's the python-sdk not up to date, fixed by sdk-sdk polyfill. I'm fixing it |
7822a35 to
d91c655
Compare
|
We should wait for #13706 to be complete before merging this PR so we have a nice DX. |
070cfab to
42bc47e
Compare
|
@TomChv @eunomie I tried to verify the claim in the PR body that I added an integration test that starts from a real generated I also wanted to make sure docker run --rm --network none [...] uv lock --check --offline
Resolved 3 packages in 0.52msSo the freshness check is local. This doesn't make installation offline—both modes can still download missing locked packages—but There is a small performance cost because I pushed the fix and the test in |
348fd72 to
842b27e
Compare
842b27e to
c277ecf
Compare
The engine detects the moduleTypes SDK capability by exact GraphQL field name (core/sdk/module.go sdk.funcs["moduleTypes"]); this method renders as moduleTypesExp, so the engine has never matched it and the function is unreachable from module loading. Type discovery for Python goes through the runtime container (moduleDefViaRuntime) and keeps doing so. Signed-off-by: Yves Brissaud <[email protected]>
…is skipped When the engine omits introspectionJson from moduleRuntime (dagger-module.toml modules never run codegen at runtime), build the runtime container straight from the committed context directory: keep the committed vendored sdk/ (instead of stripping and re-vendoring it), verify the generated files are present with an actionable error, skip the codegen exec and the uv lock refresh, and sync dependencies with --frozen so a stale committed lockfile fails loudly instead of being silently re-resolved. The codegen path (dagger develop / generate and legacy dagger.json modules) is unchanged. Signed-off-by: Yves Brissaud <[email protected]>
Python analogs of the Go RuntimeCodegen tests: a dagger-module.toml module with nothing committed fails with the dagger-generate error, a legacy dagger.json module keeps regenerating at runtime, and the happy path serves calls from the materialized files (dropping the committed vendored sdk makes the same call fail, proving the committed files are what runs). Also adds the Go trusted-files happy-path test. Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
The trusted no-codegen path is meant to fail when the committed uv.lock no longer matches pyproject.toml. However, uv sync --frozen skips that freshness check and uses the stale lock as-is. Use --locked so uv validates the committed lock without updating it. Add an integration test that generates a valid lock, changes only pyproject.toml, then proves the native no-codegen path rejects the stale generated state. The test also uses a native workspace fixture rather than the legacy config, which would regenerate the lock and hide this behavior. Signed-off-by: Guillaume de Rouville <[email protected]>
c277ecf to
caf5e78
Compare
Signed-off-by: Tibor Vass <[email protected]>
e898b4a to
5d02a72
Compare
Builds on #13598 (the config-format runtime-codegen gate), now merged into
main. This PR adopts that rule for the Python SDK and slims the module runtime.Python SDK adopts the rule. The Python SDK declares
moduleRuntime'sintrospectionJsonargument optional. Fordagger-module.tomlmodules the engine omits it, and the runtime container is built from the module's committed vendoredsdk/— no vendoring step, no codegen exec, nouvlock refresh.uv sync --frozenmeans a stale committed lockfile fails loudly instead of silently re-resolving. Missing generated files give a clear "rundagger generate" error.Drop the dead
ModuleTypesExppath from the Python runtime.Tests. Python integration coverage for the adoption: missing-files error, legacy
dagger.jsonkeeps regenerating, and trusted-files happy paths for Go and Python.