Skip to content

fix: raise a pre-1.0 engine pin when generating a [runtime] module - #77

Merged
TomChv merged 1 commit into
mainfrom
fix/migrated-engine-version
Oct 9, 2026
Merged

TomChv merged 1 commit into
mainfrom
fix/migrated-engine-version

Conversation

@TomChv

@TomChv TomChv commented Oct 8, 2026

Copy link
Copy Markdown
Member

Problem

#22 [TypeScript SDK] Migrated modules with clients fail: serveModule missing — case G12 (re-run), reproduced by the orchestrator.
Migration keeps engineVersion = v0.21.9, but generated clients call serveModule, which exists only from v1.0.0. Bumping the version and running generate fixes it (confirmed again with v0.21.x dependencies).

From the G8/G12 write-up: "Root cause: Query.serveModule is registered with View(AfterVersion("v1.0.0-0")) (core/schema/module.go:287). Migration keeps engineVersion = "v0.21.9", so the module's schema view and sdk/client.gen.ts have no serveModule. But every generated per-module client (sdk/.gen.ts) calls __dag.serveModule("/dep"). Setting engineVersion = "v1.0.0-beta.15" and regenerating fixes it. SDK-side: on generate, the TS SDK should bump engineVersion (or refuse) when it emits serve-on-use clients. The alternative is for migration to bump it." Case G6 saw the type-level form: sdk/legacy-typescript.gen.ts(134,15): Property 'serveModule' does not exist on type 'Client' — "engineVersion stays v0.21.9".

Source: SDK Main-Engine Test Run, 2026-10-07 — issue #22, case G12.

Root cause

A module is served the core schema view of the release its manifest pins
(dagger core/schema/modulesource.go:4251), and Query.serveModule is registered
View(AfterVersion("v1.0.0-0")) (dagger core/schema/module.go:288).
ModuleSource.introspectionSchemaJSON / clientSchemaIntrospectionJSON are that
same view, so a pre-1.0 pin produces 0.21-shaped bindings paired with this SDK's
1.0 bundle:

  • sdk/client.gen.ts has no serveModule on the core Client.
  • the module's clients still call it — await __dag.serveModule("/legacy/dep") —
    because codegen renders that from its own template
    (helpers/codegen/generator/typescript/templates/src/_client.ts.gtpl:90),
    whatever the schema said.

So the tree generates cleanly and breaks later: tsc reports Property 'serveModule' does not exist on type 'Client' (case G6) and a call that reaches
the serve dies with __dag.serveModule is not a function (case G12).

Two places carried the old pin into a [runtime] manifest:

  • typescript-sdk.dang withModuleManifest (hasJSON branch) — migration loaded the
    dagger.json and re-emitted it as TOML through the sdk-helpers builder, which
    round-trips engineVersion (loadCanonicalConfig copies it into
    legacyEngineVersion, and withLegacyRuntime keeps the loaded value when
    engineVersion is null). The fresh-module branch beside it already pinned
    targetEngineVersion.
  • dagger setup / workspace migrate writes dagger-module.toml itself with the
    pin copied over (dagger core/workspace/migrate.go:524), so a module it migrated
    never passes through this SDK's migration at all — yet regenerating it kept
    emitting 0.21-shaped bindings.

Fix

  • withModuleManifest, hasJSON branch: re-pin the migrated manifest with
    .withLegacyTypescriptRuntime(engineVersion: "v" + targetEngineVersion) — the same
    pairing a fresh module gets. moduleSource is left null, so the loaded source
    is preserved.
  • withClientDependencies (runs for every [runtime] module scope, before the
    schema is read — the one place regeneration can repair a manifest): when the
    loaded manifest's pin is pre-1.0, re-pin it the same way. The existing digest
    comparison is untouched, so an unchanged manifest is still not reported as
    written.
  • hasLegacyEnginePin reads the pin off the file with File.search, the way
    isTypescriptConfig reads its pattern, because the builder keeps
    legacyEngineVersion to itself. Anchored ^engineVersion\s*=\s*"v?0\. so it
    matches the manifest's own top-level key and not a value inside some table.

Only a major version of 0 is raised. A 1.0 pin is a deliberate choice — an
earlier beta a module is known to load on — its view already defines everything the
generated clients call, and rewriting it would turn that choice into a diff on
every dagger generate.

Docstrings on both sites explain why; README's migration paragraph gained a
sentence.

Checks added

Check Asserts
generate-migration-raises-engine-pin-check a pre-1.0 dagger.json pair (fixtures/generate-legacy-pin, both pinned v0.21.9, app depending on dep) comes out pinned at targetEngineVersion, the dep client is generated, the self client carries the __dag.serveModule( call site, and sdk/client.gen.ts carries the serveModule = async ( definition — the observable proof the bindings came from a 1.0 view
generate-raises-legacy-engine-pin-check a dagger setup-shaped dagger-module.toml pinned v0.21.9 (fixtures/managed-toml/legacy-pin) is re-pinned on regeneration
generate-keeps-engine-pin-check one pinned v1.0.0-beta.13 (fixtures/managed-toml/beta-pin) is left untouched — Asserts.untouched, on the changeset layer

The new fixtures sit under the existing fixtures/.typescript-ignore-generate
marker (found with findUp, so one file covers the tree) and are deliberately not
registered as dagger.toml scopes or listed in Fixtures.managedTomlFixtures —
their pins are the point, so dagger generate and fixture-engine-version-check
must leave them alone.

Verification

Engine v1.0.0-beta.17 / 55e112468d5b08e3a8746e7e74a4dc38898cf07a (latest dagger
main with a published build), on the [runtime] layout throughout — Gen.scope
defaults to legacyRuntime: true, and this change only touches that path.

The new checks go red without the fix. Scratch copy with the new checks and
fixtures kept and typescript-sdk.dang reverted to 8a7c580 (exit 1):

==== check exit: 1
  ! migration should raise a pre-1.0 engine pin to the release the bundle is built for
✘ dag://?check=generate/generate-raises-legacy-engine-pin-check 3m48s ERROR
  ! expected modified path: .dagger/modules/e2e/fixtures/managed-toml/legacy-pin/dagger-module.toml
✔ dag://?check=generate/generate-keeps-engine-pin-check 3m28s OK

(generate-keeps-engine-pin-check is a guard, not a discriminator: a 1.0 pin was
already left alone.)

Green with it restored (exit 0):

$ dagger check -m .dagger/modules/e2e \
    --check generate-migration-raises-engine-pin-check \
    --check generate-raises-legacy-engine-pin-check \
    --check generate-keeps-engine-pin-check \
    --check generate-migrates-legacy-config-check \
    --check generate-preserves-manifest-check \
    --check generate-dependency-check
== CHECKS ==  ✔ 6 passed
✔ dag://?check=generate/generate-dependency-check 48.2s OK
✔ dag://?check=generate/generate-keeps-engine-pin-check 32.2s OK
✔ dag://?check=generate/generate-migrates-legacy-config-check 29.7s OK
✔ dag://?check=generate/generate-migration-raises-engine-pin-check 48.7s OK
✔ dag://?check=generate/generate-preserves-manifest-check 48.5s OK
✔ dag://?check=generate/generate-raises-legacy-engine-pin-check 38.6s OK

The two pre-existing checks most at risk from this change —
generate-migrates-legacy-config-check and generate-preserves-manifest-check —
are in that run, plus generate-dependency-check. The full suite is being run by
the coordinator
against the recorded baseline (67/68 green on unmodified main; the
one red, packager/library-bindings/stale, is expected on an engine newer than the
committed library bindings and is unrelated to this change).

Manual repro, end to end

A user-style workspace with this SDK vendored, fixtures/generate-legacy-deps/{dep,app}
copied in as legacy/{dep,app}, app's dagger.json pinned "engineVersion": "v0.21.9",
app's source calling the dependency, and both scopes recorded by hand in
dagger.toml (dep first, with the dep also recorded as a client of app — the
serve-on-use shape issue #22 describes).

Before (typescript-sdk at 8a7c580):

$ dagger -y generate
✔ dag://?generator=typescript-sdk/generate 9m36s OK

$ cat legacy/app/dagger-module.toml
name = "legacy-deps-app"
engineVersion = "v0.21.9"

[runtime]
  source = "typescript"

[[dependencies]]
  name = "legacydep"
  source = "../dep"

$ grep -c 'serveModule = async' legacy/app/sdk/client.gen.ts
0
$ grep -n '__dag.serveModule' legacy/app/sdk/legacydep.gen.ts
97:  await __dag.serveModule("/legacy/dep")

$ dagger -m legacy/app call hello
==== call exit: 1
✘ .hello: String! 6.4s ERROR
! __dag.serveModule is not a function

After (this branch):

$ dagger -y generate
✔ dag://?generator=typescript-sdk/generate 1m25s OK

$ cat legacy/app/dagger-module.toml
name = "legacy-deps-app"
engineVersion = "v1.0.0-beta.15"

[runtime]
  source = "typescript"

[[dependencies]]
  name = "legacydep"
  source = "../dep"

$ grep -c 'serveModule = async' legacy/app/sdk/client.gen.ts
1
$ grep -n '__dag.serveModule' legacy/app/sdk/legacydep.gen.ts
97:  await __dag.serveModule("/legacy/dep")

$ dagger -m legacy/app call hello
==== call exit: 0
✔ .hello: String! 34.4s
hello from dep

The call site is identical in both; only the definition appears or not. That is the
whole bug, and the pin is what decides it.

Not covered / follow-ups

  • Entrypoint modules. withoutLegacyFields drops engineVersion with the
    [runtime] it hangs off, so an [entrypoint] manifest has no pin to raise and
    this change does not touch that path.
  • Dependencies' own pins are not raised. Only the scope being generated is
    re-pinned. A dependency left on a pre-1.0 pin is still served a pre-1.0 view when
    it is generated — which its own scope's generation fixes, so the workspace heals
    one scope at a time rather than all at once.
  • Engine side. dagger setup / workspace migrate still carries a pre-1.0 pin
    into dagger-module.toml (dagger core/workspace/migrate.go:524). This change
    repairs such a manifest on the next generation, but migration writing a current
    pin would be the narrower fix, and is the other half the write-up proposed.
  • Raise, never refuse. The write-up offered "bump or refuse". This bumps:
    refusing would leave a user with a module that generated fine yesterday and
    cannot generate today, with no in-SDK way out.
  • Noticed, out of scope: the legacy fixtures generate-legacy-deps/{app,dep}
    declare "engineVersion": "latest", which migrates to the literal string
    engineVersion = "latest" in the TOML rather than to a resolved version — it is
    accepted everywhere downstream, so it is only an oddity, but it means neither
    legacy fixture ever exercised a real pin (which is why this bug had no coverage).
  • A changeset applied by dagger generate leaves the generated tree untracked, and
    a module whose .gitignore covers sdk/ then hides its own generated files from
    the engine's module context (module "<name>" has runtime codegen disabled but committed generated file "sdk/client.gen.ts" is missing). Pre-existing and
    already noted in .dagger/modules/runtimes/main.dang; it cost a repro round here,
    so it is worth a louder mention somewhere.

A module is served the core schema view of the release its manifest pins
(dagger core/schema/modulesource.go:4251), and `Query.serveModule` exists only
from v1.0.0 — it is registered `View(AfterVersion("v1.0.0-0"))`
(core/schema/module.go:288). `ModuleSource.introspectionSchemaJSON` is that same
view, so a manifest left on a pre-1.0 pin yields 0.21-shaped core bindings —
`sdk/client.gen.ts` without `serveModule` — beside a 1.0 bundle whose module
client calls `__dag.serveModule(...)`, a call codegen renders from its own
template whatever the schema said. The two halves disagree: the module
generates cleanly, `tsc` reports `Property 'serveModule' does not exist on type
'Client'`, and a call that reaches the serve dies with `__dag.serveModule is not
a function`.

Two places carried the old pin. Migration (`withModuleManifest`) round-tripped
the dagger.json through the builder, pin included; and `dagger setup` writes
dagger-module.toml itself with the pin copied over (core/workspace/migrate.go:524),
so a module it migrated never passes through migration here at all.
`withClientDependencies` runs for every `[runtime]` module scope before the
schema is read, which makes it the one place regeneration can repair such a
manifest.

Both now pin the release the committed bundle is built for — the same pairing a
fresh module has gotten all along. Only a major version of 0 is raised: a 1.0
pin is a deliberate choice, its view already defines everything the generated
clients call, and rewriting it would turn that choice into a diff on every
`dagger generate`.

Covered by three checks: a pre-1.0 dagger.json pair is migrated and re-pinned,
a dagger-module.toml still on v0.21.9 is raised on regeneration, and one on
v1.0.0-beta.13 is left untouched.

Signed-off-by: Tom Chauveau <[email protected]>
@grouville
grouville self-requested a review October 9, 2026 06:49
@TomChv
TomChv merged commit e01e089 into main Oct 9, 2026
5 checks passed
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.

2 participants