Skip to content

fix: make the legacyRuntime flip symmetric - #81

Merged
TomChv merged 1 commit into
mainfrom
fix/legacy-runtime-flip
Oct 9, 2026
Merged

TomChv merged 1 commit into
mainfrom
fix/legacy-runtime-flip

Conversation

@TomChv

@TomChv TomChv commented Oct 8, 2026

Copy link
Copy Markdown
Member

Problem

#27 [TypeScript SDK] Turning entrypoint off fails with unclear errors — case H3.
One resolves src at the workspace root. The switch is documented as one-way, but the errors don't say so.

From the H3 write-up: "cd $RUN/typescript/H3 (EP module with a module client; settings entrypoint = false); dg -y generate → dag://typescript-sdk/generate: module manifest legacy runtime is required when legacy fields are set. cd $RUN/typescript/H3-noclient (plain EP module; entrypoint = false); dg -y generate → dag://typescript-sdk/generate: workspace directory "src": failed to get snapshot: ... lstat <ws root>/src: no such file or directory. The switch is documented as one-way, but generate fails with errors that don't say so. In the no-client case it resolves src against the workspace root instead of the module directory. [runtime], engineVersion, [[dependencies]] do not come back; the manifest stays EP and the module still works in EP form."

(SDK Main-Engine Test Run, 2026-10-07 — issue #27, case H3.)

The setting has been renamed since that run. #73 made the [entrypoint] layout the default and inverted the setting: what the matrix exercised as entrypoint = false is today legacyRuntime = true (--legacy-runtime, scope setting legacyRuntime = true). That makes the row more important, not less — #73's own description says the [entrypoint] layout is what a fresh module now gets, while the legacy [runtime] layout is the one every released engine loads. Flipping an entrypoint module back is therefore exactly what a user on a released engine does.

Both quoted errors still reproduce verbatim on v1.0.0-beta.17 · 55e11246 — see Verification.

Root cause

generateScope wrote the entrypoint manifest on every run, but left an existing manifest alone whenever the scope already had one (typescript-sdk.dang:227 on main, } else if (hasToml) {). So with legacyRuntime true and a manifest declaring [entrypoint] and no [runtime], the manifest was kept as it was while the rest of the run generated for a runtime. Both halves of the legacy path then failed on it, and neither error named the setting:

  • withClientDependencies (typescript-sdk.dang:585 on main) calls the builder's withLegacyRuntimeDependency on an entrypoint manifest. ModuleManifest.validate refuses a dependency with no runtime to hang off: module manifest legacy runtime is required when legacy fields are set. This is the with-client half of H3.
  • moduleSourcePath (typescript-sdk.dang:1745 on main, reached from :244) asks the engine for a sourceSubpath that an entrypoint manifest has not got, gets "", reads that as ".", and generation then looks for the module's src/ at the workspace root: workspace directory "src": … lstat <ws root>/src: no such file or directory. This is the no-client half.

The forward flip works only because withEntrypointManifest rewrites the manifest every run; nothing did the mirror image.

Fix

Make the flip symmetric — the setting asks for a [runtime] module, so write that manifest.

  • generateScope now routes an entrypoint manifest through withModuleManifest (typescript-sdk.dang:240), whose no-config branch already emits exactly what is wanted: a fresh legacy manifest pinned to the release this SDK ships for. Nothing from the entrypoint manifest needs carrying over — it holds only the name and the [entrypoint] table — and the scope's clients come back as [[dependencies]] through withClientDependencies on the same run. A [runtime] manifest is still generated as it stands, so no existing behaviour moves.
  • isEntrypointManifest / tomlDeclaresTable (typescript-sdk.dang:468, :477) tell the two manifest shapes apart by reading the file, the way isTypescriptConfig reads tsTomlPattern off one — the builder's loaded manifest exposes neither table.
  • withModuleManifest's docstring now says it serves three arrivals (no config, a dagger.json, an entrypoint manifest moving back); withEntrypointManifest's "It is a one-way trip" is replaced by what does and does not come back; the legacyRuntime setting docstring and README's --legacy-runtime paragraph say the same.

The file half. prunedInactiveDispatch already removed __dagger.dispatch.ts and entrypoint/, and prunedEmbeddedClientsDir already removed clients/ with the packaged clients/dagger and clients/<name>/ in it — both verified in the transcripts below. What was missing was the link into them: package.json kept its file:./clients/<name> dependencies on packages the flip had just deleted, so the runtime's install would fail at call time. config-updater's package-json pass now prunes those (helpers/config-updater/main.go:150), by the same scope-local rule shared-deps already prunes with, so a client the user installed from elsewhere (file:../… or a registry) is left alone.

Note for integration with #75: this adds no new withoutDirectory on clients/. It reuses prunedEmbeddedClientsDir, which on this base already removes the directory wholesale for the earlier embedded-layout migration; only its docstring changed, to say it now also covers an entrypoint module moving back. When #75 lands and that helper becomes a one-liner over prunedOwnedFiles, the flip-back path inherits it unchanged — the only textual conflict is the docstring. One behavioural consequence worth knowing: under ownership-based pruning a user file inside clients/ would keep the directory alive, which is #75's concern and is not widened here.

Verification

Engine v1.0.0-beta.17 · 55e112468d5b08e3a8746e7e74a4dc38898cf07a throughout (DAGGER_LEAVE_OLD_ENGINE=1 dagger --x-release=55e11246… …).

New checks (.dagger/modules/e2e/generate.dang:194, :255). generateFlipsBackToRuntimeCheck generates a scope with legacyRuntime: false, flips it, and asserts the whole move: [runtime] source = "typescript", engineVersion = "v<targetEngineVersion>", no [entrypoint]; __dagger.entrypoint.ts and sdk/client.gen.ts generated; __dagger.dispatch.ts, entrypoint/ and clients/ gone from the resulting tree; the tsconfig alias back; no file:./clients/ left in package.json; and a third generation writing nothing. generateFlipsBackWithClientCheck does the same for a scope with a recorded client and asserts the [[dependencies]] entry, sdk/<target>.gen.ts, and the pruned link.

Both new checks were confirmed to go RED without the fix, on a scratch copy with typescript-sdk.dang and the helper reverted to origin/main and only the checks kept — and they fail with precisely the two errors from the report:

✘ 2 failed
✘ generate/generate-flips-back-to-runtime-check ERROR
  ✘ Container.withDirectory(path: "/work/src", source: Directory.directory(path: "/src")): Container!
  ! stat src: no such file or directory
✘ generate/generate-flips-back-with-client-check ERROR
  ✘ SdkHelpersModuleManifest.generate(ws: withWorkdir …/flip-back-client, lock: false, legacyJson: false): Workspace!
  ! module manifest legacy runtime is required when legacy fields are set

Checks run green with the fix (scratch copy of this branch, workspace.toml/workspace.lock swapped in; command exited 0, per-check durations 4m51s–10m2s):

dagger check -m .dagger/modules/e2e \
  "generate:*flips-back*" "generate:generate-prunes-entrypoint-check" \
  "generate:generate-idempotent-check" "generate:entrypoint-installs-dependencies-check" \
  "manifest:entrypoint-manifest-check"

✔ 6 passed
✔ generate/entrypoint-installs-dependencies-check      9m41s OK
✔ generate/generate-flips-back-to-runtime-check        9m46s OK
✔ generate/generate-flips-back-with-client-check        9m7s OK
✔ generate/generate-idempotent-check                   4m51s OK
✔ generate/generate-prunes-entrypoint-check            5m57s OK
✔ manifest/entrypoint-manifest-check                  10m2s OK

cd helpers/config-updater && go test ./... → ok config-updater, including a new updatePackageJSON case covering the pruned entrypoint links and the kept outside install. Parse gate after every .dang edit: dagger -m . functions and dagger -m .dagger/modules/e2e functions, both load. The full 68-check suite is run by the coordinator; the baseline on unmodified main is 67/68, with packager/library-bindings/stale red (expected on an engine newer than the committed bindings).

Manual repro, both H3 variants

Workspace built the way a user does: vendor the SDK, dagger init -y, module install, module init typescript --name hello (entrypoint layout, the default), then add legacyRuntime = true under [sdks.typescript.scopes.".dagger/modules/hello".settings] and dagger -y generate. The with-client variant adds a second module target and runs dagger module client add ../target from inside hello.

Before (pristine origin/main) — both quoted errors, verbatim.

=== [before/noclient] generate after the flip
✘ FAILED  -y generate
! dag://?generator=typescript-sdk/generate: workspace directory "src": failed to get snapshot:
  failed to snapshot: failed to receive stat message: rpc error: code = NotFound desc = get full
  root path: rpc error: code = NotFound desc = eval symlinks:
  lstat /private/tmp/h3-before/ws/src: no such file or directory

=== [before/noclient] manifest after the flip
name = "hello"

[entrypoint]
  kind = "dang"
  source = "./entrypoint"

=== [before/noclient] tree after the flip
__dagger.dispatch.ts  clients  dagger-module.toml  entrypoint  package.json  src  tsconfig.json
ls: .dagger/modules/hello/sdk: No such file or directory
=== [before/client] generate after the flip
✘ FAILED  -y generate
! dag://?generator=typescript-sdk/generate: module manifest legacy runtime is required when legacy fields are set
  ✘ SdkHelpersModuleManifest.generate(ws: withWorkdir .dagger/modules/hello, …): Workspace! ERROR

=== [before/client] manifest after the flip     # unchanged: still EP
name = "hello"

[entrypoint]
  kind = "dang"
  source = "./entrypoint"

After (this branch) — the flip happens, is idempotent, and the result runs.

=== [after/noclient] generate after the flip
✔ PASSED  -y generate

=== [after/noclient] manifest after the flip
name = "hello"
engineVersion = "v1.0.0-beta.15"

[runtime]
  source = "typescript"

=== [after/noclient] tree after the flip
__dagger.entrypoint.ts  dagger-module.toml  package.json  sdk  src  tsconfig.json
sdk: client.gen.ts core.d.ts core.js hello.gen.ts index.ts loader.gen.ts telemetry.ts
ls: .dagger/modules/hello/clients: No such file or directory

=== [after/noclient] package.json + tsconfig.json after the flip
{ "type": "module", "dependencies": { "typescript": "5.9.3" } }        # file: link pruned
"paths": { "@dagger.io/dagger": ["./sdk/index.ts"],
           "@dagger.io/dagger/telemetry": ["./sdk/telemetry.ts"],
           "@dagger.io/hello": ["./sdk/hello.gen.ts"] }

=== [after/noclient] idempotence
INF no changes to apply

=== [after/noclient] call on the [runtime] form
✔ PASSED  hello container with-exec --args echo,hi stdout
hi
=== [after/client] manifest after the flip
name = "hello"
engineVersion = "v1.0.0-beta.15"

[runtime]
  source = "typescript"

[[dependencies]]
  name = "target"
  source = "../target"

=== [after/client] tree after the flip
__dagger.entrypoint.ts  dagger-module.toml  package.json  sdk  src  tsconfig.json
sdk: client.gen.ts core.d.ts core.js hello.gen.ts index.ts loader.gen.ts target.gen.ts telemetry.ts
ls: .dagger/modules/hello/clients: No such file or directory

=== [after/client] package.json + tsconfig.json after the flip
{ "type": "module", "dependencies": { "typescript": "5.9.3" } }        # both file: links pruned
"paths": { "@dagger.io/dagger": ["./sdk/index.ts"],
           "@dagger.io/dagger/telemetry": ["./sdk/telemetry.ts"],
           "@dagger.io/target": ["./sdk/target.gen.ts"],
           "@dagger.io/hello": ["./sdk/hello.gen.ts"] }

=== [after/client] idempotence
INF no changes to apply

=== [after/client] call on the [runtime] form
✔ PASSED  hello container with-exec --args echo,hi stdout
hi

In every run the entrypoint form itself calls fine on this engine before the flip (hello container with-exec --args echo,hi stdout → hi), matching the matrix's F2/H1/I-series: both layouts load here, so this is a flip bug, not a layout bug.

Not covered / follow-ups

  • source and include are still lost across a round trip. An entrypoint manifest has no field for them, and the way back writes a fresh manifest rather than reading the old one, so a module that declared either loses it going out and does not get it back. Documented in the legacyRuntime docstring, in withEntrypointManifest's docstring and in the README rather than fixed; restoring them would mean preserving state the entrypoint manifest cannot hold.
  • A user file inside clients/ is fix/clients-ownership (fix: remove only what the SDK generates from clients/ #75)'s concern. Not widened here; the flip-back path reuses the existing pruning helper, so it inherits whatever fix: remove only what the SDK generates from clients/ #75 settles.
  • An unrecognized scope setting is silently ignored — found while reproducing this. The engine writes the setting as legacyRuntime = true (camelCase); a legacy-runtime = true spelling under the same […settings] table is accepted and dropped, so dagger generate reports success and "no changes to apply" while the module stays in entrypoint form. That cost two full repro rounds here, and it is the kind of thing that reads as "the flip still doesn't work" in a future test run. Engine-side, not fixable here; worth its own report.
  • The entrypoint layout still cannot serve a client — [[dependencies]] has nowhere to live in an entrypoint manifest. Unchanged by this PR, and the reason the with-client flip is the half that failed loudest.

Turning `legacyRuntime` off moves a module onto an entrypoint, because
withEntrypointManifest rewrites the manifest on every run. Turning it back on
did nothing of the sort: generateScope left an existing manifest alone whenever
the scope already had one, so a module that declared `[entrypoint]` and no
`[runtime]` kept that manifest while the rest of the run generated for a
runtime. Both halves of the legacy path then failed on it, and neither error
named the setting:

  - withClientDependencies asked the builder to hang a dependency off a runtime
    the manifest does not declare, which it refuses: "module manifest legacy
    runtime is required when legacy fields are set".
  - moduleSourcePath asked the engine for a sourceSubpath an entrypoint manifest
    has not got, read the empty answer as ".", and generation looked for the
    module's src/ at the workspace root: "stat src: no such file or directory".

The setting asks for a `[runtime]` module, so write that manifest. generateScope
now routes an entrypoint manifest through withModuleManifest, whose no-config
branch already emits exactly what is wanted — a fresh legacy manifest with the
engine release this SDK ships for — and the scope's clients come back as
`[[dependencies]]` through withClientDependencies on the same run. Nothing from
the entrypoint manifest needs carrying over: it holds only the name and the
`[entrypoint]` table.

The rest of the legacy path already cleaned up after the other layout:
prunedInactiveDispatch takes __dagger.dispatch.ts and entrypoint/, and
prunedEmbeddedClientsDir takes clients/ with the packaged clients/dagger and
clients/<name>/ packages in it. What was missing was the link into them:
package.json kept its `file:./clients/<name>` dependencies on packages the flip
had just removed, so the runtime's install failed at call time. config-updater's
package-json pass now prunes those, by the same scope-local rule shared-deps
already prunes with, leaving a client installed from anywhere else alone.

This matters more since #73 made the entrypoint layout the default: a fresh
module declares `[entrypoint]`, while the `[runtime]` layout is the one every
released engine loads, so flipping back is what a user on a released engine
does.

Signed-off-by: Tom Chauveau <[email protected]>
@grouville
grouville self-requested a review October 9, 2026 06:50
@TomChv
TomChv merged commit 593c7a6 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