Repository navigation
feat: restore pre-1.0 dag.<module>() through a generated compat shim - #78
Merged
Merged
Conversation
grouville
self-requested a review
October 9, 2026 06:50
grouville
approved these changes
Oct 9, 2026
Pre-1.0 codegen merged every dependency's root fields into the one core Client, so a module wrote `dag.myDep().hello()`. Unified clients render each module as its own file with its own Client, its own `dag` and its own top-level functions, and the core Client in client.gen.ts carries no `<module>()`. tsx and bun strip types without checking them, so a migrated module compiles, `generate` and `check` pass, and the call fails only at dispatch with "dag.myDep is not a function". Each module scope now also gets a compat shim — sdk/compat.gen.ts flat, clients/compat.gen.ts packaged — rendered whenever at least one module client is. For every root field of every client it installs a delegating method on the core Client.prototype and declares the type side through a `declare module "@dagger.io/dagger"` augmentation, each member carrying an @deprecated note naming the 1.0 import. The delegation goes through the client's own `dag`, not a raw query, so the client's serve-on-use hook still runs and the module is served before the first query reaches it. Object.defineProperty with enumerable: false keeps the restored methods out of anything that walks a client's own members: this is compatibility surface, not API. A file of its own because core may not reference a module client — that direction is an ESM cycle and would stop sdk/ being a publishable core-only library — so the loader imports it instead, keeping the direction entrypoint -> loader -> compat -> clients. The shim enumerates module clients directly rather than through the loader's class map, which only covers modules owning an object type; a dependency contributing nothing but a scalar root field is restored too. Two kinds of root field are skipped, both still reachable through the module's own client: a name that is a TS keyword, which cannot be a member (the same rule _client.ts.gtpl applies to its top-level functions), and a name a core Query field already has, which would otherwise replace a core method on the prototype everything shares. The entrypoint now imports the loader for its side effect as well as by name. The named import is not always used — a module with no object-typed argument, field or return never calls __loadCoreObject — and a type-stripping loader drops an unused named import outright, which would take the loader, the shim and the restored methods with it. typescript-sdk.dang learns that compat.gen.ts is not a module client: bindingAliasModules excludes it so no @dagger.io/compat alias is written. Pruning needs no change — it is a *.gen.ts in the regenerated set, so a scope that loses its last client loses the shim with it. Signed-off-by: Tom Chauveau <[email protected]>
The reported failure was invisible to every tool a user runs — generate and check passed, and the module failed only when dispatched — so the coverage has to reach both halves. runtimes:dag-dependency-runs is the running half, and the runtimes module is the only place a check loads a generated module for real. A new fixture pair — a dependency, and a module reaching it as `dag.runtimeDep()` — is generated in order and loaded. The fixture resolves the call at module scope rather than only inside a function: a `dag.<dep>()` that is no longer a function throws there while the entrypoint is still importing the user's source, so the module never registers its object and the check goes red. Confirmed against a scratch copy with the shim disabled, where it fails with the reported "TypeError: dag.runtimeDep is not a function". generate-compat-shim-type-checks is the type half, run through the module's own tsconfig unnarrowed — which is what makes the declaration merge apply at all, since an augmentation only takes effect when the augmenting file is in the program and the generated tsconfig carries no `include`. Asserted in both directions, because a passing compile says nothing on its own: the same source is rejected with TS2339 once the shim is taken away. tsc prints nothing for @deprecated; an editor shows the strike-through. generate-compat-shim pins what the shim contains and, as much, what it does not touch: the core bindings stay core-only. generate-compat-shim-pruned covers both ends of when the file exists — an entrypoint scope with no module client gets none, and one left behind is pruned by the same mechanism that takes a departed dependency's bindings. Signed-off-by: Tom Chauveau <[email protected]>
TomChv
force-pushed
the
feat/dag-dep-compat
branch
from
October 9, 2026 11:41
34f74b6 to
8dfad23
Compare
Member
Author
|
Tested and it works fine, however during my testing I noticed another issue with module source failing to load when source points to a directory, I'm fixing this as part of this PR since my agent already has a lot of context on that |
Member
Author
|
I changed my mind, I'll do the fix in a follow up PR since that compat is quite important imo |
This was referenced Oct 9, 2026
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.
Problem
SDK Main-Engine Test Run, 2026-10-07 — issue #26, case G12.
Root cause
Pre-1.0 codegen merged every dependency's root fields into the one core
Client, so a module wrotedag.myDep().hello(). Unified clients render each module as its own file with its ownClient, its owndagand its own top-level functions, and the coreClientinclient.gen.tscarries no<module>().tsxandbunstrip types without checking them, so a migrated module compiles,generateandcheckpass, and the call fails only at dispatch — which is exactly what the report describes.Fix
A backward-compatibility layer that puts each module's root fields back on the core
dag, marked@deprecated.One shim per module scope —
sdk/compat.gen.tsin the flat ([runtime]) layout,clients/compat.gen.tsin the packaged ([entrypoint]) one — rendered whenever at least one module client is, which covers dependencies, recorded targets and the self client alike. For each module client it:dagunder an alias, plus (type-only) whatever its signatures name;<field>()on the coreClient.prototypeper root field, viaObject.definePropertywithenumerable: false, delegating to the client's owndag.<field>(...)— so the client's serve-on-use hook (__serveModule) still runs and the module is served before its first query;tscsee it, oneinterface Clientmember per field with an@deprecatednote naming the 1.0 import.What the augmentation targets, and why that was in question. The brief allowed for augmenting
@dagger.io/daggerto fail, since itsClientis re-exported throughexport *fromindex.tsrather than declared there, with a fallback of augmenting the declaring module (./client.gen.js). It does not fail: a realtscrun against the module's own tsconfig (moduleResolution: "Node",@dagger.io/dagger→./sdk/index.ts) merges the interface through the re-export, enforces the declared signature (dag.dep({ nope: 1 })is rejected asTS2353againstClientDepOpts), and exposes the@deprecatedtag to the language service — checked directly through the TS API, wheregetJsDocTags()returns["deprecated"], which is what gives the editor strike-through. So the shim augments@dagger.io/daggerin both layouts: one specifier, and the class it patches is the same one the user's own source imports.Why a separate file. The core file must not import or mention a module client — core → client is the direction the design forbids (ESM cycle, and
sdk/has to stay a publishable core-only library). So the loader imports the shim instead, keeping the direction entrypoint → loader → compat → clients; the shim's header comment says so.The shim enumerates module clients directly rather than through the loader's class map, which only covers modules owning an object type — so a dependency contributing nothing but a scalar root field is restored too. There is a golden test for exactly that module.
The entrypoint now imports the loader for its side effect as well as by name. The named import is not always used: a module with no object-typed argument, field or return never calls
__loadCoreObject, and a type-stripping loader drops an unused named import outright — which would silently take the loader, the shim and every restored method with it. That is the repro's own shape, so without this the fix would not have worked at all.Skipped root fields, both still reachable through the module's own client:
_client.ts.gtplalready applies to its top-level functions;Queryfield already has — the shim would otherwise replace a core method on the prototype everything shares.typescript-sdk.danglearns the new file is not a module client:bindingAliasModulesexcludes it, so no@dagger.io/compatalias is written, andcompatjoinsloaderas a reserved module name.packagedClientNamesalready globs one level down and so leaves it out. Pruning needs no change — it is a*.gen.tsin the regenerated set, so a scope that loses its last client loses the shim with it, which is whatgenerate-compat-shim-pruned-checkasserts.Verification
Engine
v1.0.0-beta.17/55e112468dthroughout.Go tests —
go test ./...inhelpers/codegen(andhelpers/config-updater): green. New golden tests pin the shim in both layouts (compat_flat_want.ts,compat_packaged_want.ts) plus the skips, the no-client cases, the reservedcompatmodule name, and the side-effect loader import. The three entrypoint goldens gained exactly one line each (that import).Checks run (
dagger --x-release=55e112468d check …in a scratch workspace on the engine-e2eworkspace.toml) — all 7 green, command exited 0:e-2-e:generate:generate-compat-shim-checke-2-e:generate:generate-compat-shim-pruned-checke-2-e:generate:generate-compat-shim-type-checks-checke-2-e:generate:generate-dependency-bindings-checke-2-e:generate:generate-prunes-stale-bindings-checkruntimes:dag-dependency-runs-checkruntimes:node-runs-checkFull suite run by the coordinator against this branch. Baseline on unmodified
mainis 67/68, the one red beingpackager/library-bindings/stale— expected on an engine newer than the committed library bindings, which are untouched here.The new check discriminates. On a scratch copy with the shim disabled,
runtimes:dag-dependency-runs-checkgoes red with the reported error:A first draft of the tsc check narrowed
includeto the probe file and failed the same way a user would — the augmenting file was not in the program. It now runs the module's own tsconfig unnarrowed, which is what a user gets, and asserts both directions.Manual repro, two
--legacy-runtimemodules in a throwaway workspace,appholding a recorded client fordepand calling it the 0.21 way (return await dag.dep().hello()).Before —
generateis clean, the call is not:After, with no change to the module's source:
And the type side, with the module's own generated tsconfig:
(
--skipLibCheckbecause the vendored bundle'score.d.tsreferencesgraphql-requestand@opentelemetry/api, which the module itself does not declare — pre-existing and unrelated; the e2e fixture's tsconfig sets it already.)Not covered / follow-ups
TestGenerateModule_CompatShimOnlyWithClientspins that none is emitted there rather than leaving a dead file behind._client.ts.gtpl, which skips them for its top-level functions for the same reason; the field stays reachable through the module client's owndag.Queryfield is skipped rather than shadowing core. Worth flagging that this is silent: the pre-1.0 merge would have let the module win, so such a module changes behaviour either way. Surfacing it as a generation warning needs somewhere for an SDK to put one.moduleTypedefJSONstages only the*/*.gen.tspackage files, flattened). It makes no difference to any typedef that declares its return type, which the templates and the scan's own requirements make the norm, and the flat layout stages the wholesdk/so the augmentation resolves during the scan there. Staging it under the packaged layout would need its relative client paths rewritten to match the flattening, so it is left alone.library/src/module/introspector/typescript_module/ast.tsskipsclientandloaderwhen synthesizing@dagger.io/<name>aliases for the scan, and says it mirrorsbindingAliasModules. It now also wantscompat. The effect is one unused path alias, so it is harmless, and changing it means rebuilding the committedlibrary/bundle/through the packager — its own change.