Skip to content

feat: generate the manifest-v2 module entrypoint alongside the current one - #52

Merged
TomChv merged 14 commits into
mainfrom
design/module-entrypoint
Sep 15, 2026
Merged

TomChv merged 14 commits into
mainfrom
design/module-entrypoint

Conversation

@TomChv

@TomChv TomChv commented Sep 14, 2026

Copy link
Copy Markdown
Member

A manifest v2 module names an entrypoint instead of a runtime: a Dang program implementing ModuleEntrypoint, whose types() returns the module's typedefs and whose call() dispatches one call. The engine evaluates types() in-process, so type discovery stops building a container entirely, and the container becomes a private detail of call().

This generates both halves. Nothing reads them yet.

What lands

hello/
├── entrypoint/main.dang      types() + call() + the baked container recipe   (new)
├── __dagger.dispatch.ts      stdin -> invoke -> stdout, no register()        (new)
├── __dagger.entrypoint.ts    unchanged, still generated, still what runs
└── sdk/ ...

types() is a retarget of the renderer that already emits register(), reading the same typedef.json, so the two stay derived from one scan. The introspector now runs once and feeds all three renderers instead of once per file.

The recipe bakes the image, the loader and the mount layout at generation time — it never re-derives them, so changing a module's runtime means regenerating. It also bakes the module's own path, because call() is handed the caller's workspace, whose cwd is wherever the caller happened to be.

Why this is safe to land now

No released engine loads a module through an [entrypoint] table — dagger/dagger#14038 is an unmerged draft. Both files are written beside __dagger.entrypoint.ts, never in place of it, and nothing here writes [entrypoint] into a manifest. This is inert output that cannot regress a module still loading through the built-in runtime.

Writing the manifest is deliberately left out: it is the one step that depends on how #14038 settles after its rebase.

Two things found by running it, not reading it

Dang has two JSON types that do not convert. A schema field such as withArg's defaultValue wants Dagger.JSON; call()'s own return stays bare JSON!, because that is what the engine writes into the interface it injects. The declared type and the cast have to agree:

declared cast result
JSON! JSON! works
Dagger.JSON! Dagger.JSON! works
mixed mixed return type mismatch

stdout is the result channel now, so the session's logs move to stderr. Crossing them corrupts the result.

Developer mode

The dispatcher gains a second mode, as the Go SDK example has it, so an author can run a function without the engine loading the module at all:

$ npx tsx __dagger.dispatch.ts call greet --name World --loud
hello, World!

Verification

what how result
renderers unit + golden tests pass
generated Dang loaded on a beta.13 engine as a throwaway Dang module parses, type-checks, types() evaluates
typedef correctness walked the evaluated TypeDefs matches register() function for function
dispatcher tsc --strict clean
dispatch protocol real stdin/stdout runs constructor, void, list, object→ID, nonzero exit, developer mode
whole repo dagger check engine-e-2-e:checks-check 59/59

Walking the evaluated typedefs gives exactly what register() declares:

object Smoke fns=[ctr,greet,greetAll,nothing,read,withGreeter] fields=[greeting,source] ctorArgs=[source,greeting]
enum Volume members=[LOUD,QUIET]
interface Greeter fns=[greet]

generate-idempotent-check passing matters most here: the new files are stable across regeneration. runtimes:{node,bun,deno}-runs-check confirm a generated module still loads and executes.

Caveat on those numbers

All three check runs used the rewritten dagger.lock from #51, so 59/59 was measured with sdk-helpers v1.0.4, not the v1.0.1 this branch pins. sdk-helpers is what writes manifests, so a difference could in principle surface in generation. No evidence that it does, but it is untested. Rebasing on #51 closes it.

Not done here

  • The manifest. Nothing writes [entrypoint]; gated on #14038's rebase.
  • __dagger.entrypoint.ts is not renamed. Both files are generated so the old path keeps working and the new one is testable side by side.
  • No dependency install in the recipe. A default module declares none once the typescript pin is dropped, and an install path cannot be tested against an engine that does not load entrypoints. The recipe mounts the workspace excluding node_modules, sets the workdir, and mounts sdk/ as node_modules/@dagger.io/dagger for node and bun; deno resolves through its import map.

Open question for #14038

A module-level description has nowhere to go. The TypeScript renderer emits mod.withDescription(...), but v2's types() returns [TypeDef!]! with no module object, so a module docstring is dropped. Worth raising alongside the manifest question.

Commits

The first six are the design doc this implements, previously unpushed. feat: is the implementation.

@TomChv
TomChv force-pushed the design/module-entrypoint branch 4 times, most recently from e3abbcc to 686e492 Compare September 15, 2026 00:24
…odules

Successor to the runtime-module proposal: `dagger generate` emits a
self-contained runtime.dang next to dagger-module.toml and modules record
`[runtime] source = "embed:runtime.dang"`, which the engine evaluates
in-process. Covers what goes in each of the three JS runtimes and the two
engine-image mounts the embedded runtime loses.

Signed-off-by: Tom Chauveau <[email protected]>
Measured on a beta.12 dev engine: the global tsx install is 3.6s once per
engine and provably reuses its layer across modules; a typescript install,
if the pin were kept, is 1.6s per module manifest. Adds the prebuilt base
image option, the import-edge evidence for dropping the typescript pin,
and the offline-reachability caveat.

Signed-off-by: Tom Chauveau <[email protected]>
Generation detects the runtime, package manager, base image and whether the
module installs anything, then emits one of three sources (node/bun/deno)
with those answers spliced in — so the runtime does no detection, no
branching and no codegen at call time, just install and run.

Signed-off-by: Tom Chauveau <[email protected]>
Detection happens at codegen and nowhere else: the emitted runtime carries
answers, not rules, and never re-checks the package manager, runtime or
base image at call time. Changing those inputs means re-running
dagger generate.

Signed-off-by: Tom Chauveau <[email protected]>
Engine PR 14038 replaces the module runtime contract with a module
entrypoint: a generated Dang directory implementing types() and call().
Type discovery stops needing a container entirely — the typedefs become
generated Dang literals evaluated in-engine — and the container becomes a
private detail of call(), driven by a stdin/stdout dispatch protocol.

Signed-off-by: Tom Chauveau <[email protected]>
Records the manifest disagreement between the two engine PRs (versioned
manifestVersion=2 vs additive [entrypoint] beside [runtime]), rebases the
generation plumbing onto generateScope/findClientRoot and the sdk-helpers
manifest builder, and marks the bundle half of the typescript prerequisite
as already landed in typescript-sdk#42.

Signed-off-by: Tom Chauveau <[email protected]>
…t one

A manifest v2 module names an entrypoint instead of a runtime: a Dang program
implementing ModuleEntrypoint, whose types() returns the module's typedefs and
whose call() dispatches one call. The engine evaluates types() in-process, so
type discovery stops building a container entirely, and the container becomes a
private detail of call().

Generate both halves:

  entrypoint/main.dang    types() + call() + the baked container recipe
  __dagger.dispatch.ts    stdin -> invoke -> stdout, no register()

types() is a retarget of the renderer that already emits register(), against the
same typedef.json, so the two stay derived from one scan. The recipe bakes the
image, the loader and the mount layout at generation: it never re-derives them,
which means changing a module's runtime means regenerating. It also bakes the
module's own path, because call() is handed the *caller's* workspace, whose cwd
is wherever the caller happened to be.

Both files are written beside __dagger.entrypoint.ts, never in place of it, and
nothing yet writes [entrypoint] into a manifest. No released engine loads a
module this way (dagger/dagger#14038 is an unmerged draft), so this is inert
output that cannot regress a module still loading through the built-in runtime.

Two things worth recording, both found by running it rather than reading it:

  - Dang has two JSON types that do not convert. A schema field such as
    withArg's defaultValue wants Dagger.JSON; call()'s own return stays bare
    JSON!, because that is what the engine writes into the interface it injects.
    The declared type and the cast have to agree or evaluation fails.
  - stdout is the result channel now, so the session's logs move to stderr.
    Crossing them corrupts the result.

The dispatcher also grows a developer mode, so a module author can run a
function by hand without the engine loading the module at all:

  npx tsx __dagger.dispatch.ts call message --giant

Signed-off-by: Tom Chauveau <[email protected]>
The generated entrypoint opened with runtime(), a private helper, so reading the
file meant scrolling past a container recipe before reaching the two functions
the engine actually calls. Order it the way it is read instead: types(), call(),
then the recipe they share.

Dang resolves a member call regardless of declaration order, so call() reaching
runtime() from above it is fine — confirmed by loading the reordered program on
an engine and walking the typedefs it returns, which are unchanged.

Signed-off-by: Tom Chauveau <[email protected]>
The generated dispatcher had a second mode meant to let an author run a function
without the engine loading the module:

  npx tsx __dagger.dispatch.ts call greet --name World

It could not have worked for the module the SDK's own default template creates.
That template's constructor takes a Workspace, and a module cannot obtain one:
the module-facing schema has no currentWorkspace root field, no host access, and
Address.workspace() only resolves an installed <module>:<function>. The mode ran
the constructor with no arguments, so `ws` arrived undefined and the first
`ws.directory(...)` threw.

The one route that does reach a Workspace —
moduleSource(".").contextDirectory().asWorkspace() — returns the module's
*context* directory, not the workspace: its root holds only .dagger/, and its cwd
is "/" rather than the module's scope. A mode that works for greet(name: string)
and silently hands a different tree to anything touching the workspace is worse
than no mode at all, so drop it rather than approximate it.

What the engine needs is unaffected: engine-call still reads one JSON request on
stdin and writes one JSON result on stdout. It now rejects any other mode with a
readable error instead of blocking on a stdin that never arrives.

Everything else a hand-invoked mode would need is already solvable — every core
object except Workspace has a root constructor, and invoke() takes IDs — so this
can come back as its own change if it earns one.

Signed-off-by: Tom Chauveau <[email protected]>
Everything a module entrypoint needs was already generated — entrypoint/main.dang
and __dagger.dispatch.ts land on every generate — but nothing pointed the engine
at them. Add the manifest that does, behind `entrypoint`, off by default.

The manifest cannot go through the sdk-helpers builder. That builder never emits
`manifestVersion`, and the engine dispatches on exactly that key: without it the
legacy parser runs and reads `[entrypoint]` as an unknown key it silently
ignores, so the module loads the old way and the entrypoint is inert. What is
needed is four values and no others, which is four lines of TOML.

Two consequences, both forced by the engine rejecting every other key rather
than ignoring it (validateModuleManifestV2TOML):

  - The manifest is rewritten rather than merged. Nothing in it is worth
    preserving, and rewriting is what lets an existing module be flipped onto an
    entrypoint by turning the setting on.
  - withClientDependencies is skipped. Upserting [[dependencies]] would not add a
    dependency to a v2 manifest, it would make the file unparseable. So a module
    with an entrypoint cannot serve a client yet. That is the schema's gap, not
    a choice made here.

Also drops `engineVersion`, `source`, `[codegen]` and `[[clients]]`, which the
schema has nowhere to put. The engine fills the engine version in from whatever
is running.

Verified against the engine's own parser on the rebased #14038: the emitted bytes
parse to the four expected values, round-trip byte-identically so generate does
not report the manifest as churned, and the same bytes plus a [[dependencies]]
table are rejected — confirming the skip above is required rather than tidy.

Signed-off-by: Tom Chauveau <[email protected]>
Generation failed at `stat src: no such file or directory` for any module with a
v2 manifest.

moduleSourcePath asks the engine where a module's files live, because migration
can aim a legacy manifest's `source` away from the directory holding it. A v2
manifest has no `source` field at all, so sourceSubpath comes back unset — and
the helper reads unset as ".", which is indistinguishable from "the module is at
the workspace root". Generation then looked for src/ beside dagger.toml instead
of inside the module.

Under an entrypoint there is nothing to resolve: with no `source` field, a
module's files are its scope. Use that rather than asking.

Signed-off-by: Tom Chauveau <[email protected]>
A module with a v2 manifest was getting both dispatchers: the one its entrypoint
execs, and __dagger.entrypoint.ts, which nothing loads. Two files with nearly the
same name, one of them dead, is an invitation to edit the wrong one.

Write the legacy dispatcher only for a module that still declares a [runtime].
Skipping it also skips rendering it — the File is never pulled, so the codegen
exec behind it never runs.

Prune it too, or turning the setting on would leave the dead copy behind:
generation layers over the module's existing tree and layering only ever adds.
Guarded on existence, because withoutFiles takes a path rather than a pattern and
the file is absent for every module created under an entrypoint.

Renames the local `entrypoint` File binding to spell out which dispatcher it is.
It had been shadowing the setting of the same name ever since that setting was
added, which read as though the branch below tested a File for truth.

Signed-off-by: Tom Chauveau <[email protected]>
A module with a v2 manifest could not call another module. Its bindings were
generated — sdk/<dep>.gen.ts and all — but nothing served the dependency at run
time, so every call died on `Cannot query field "dep" on type "Query"`.

The manifest cannot help: v2 has no [[dependencies]] table and the engine rejects
the key. So establish it at run time instead. The generated dispatcher now serves
its scope's client targets into its own session before dispatching.

It has to be that session. Serving from the Dang entrypoint that spawned the
container does not reach it — a nested exec takes its schema from the active
module's dependencies at the moment it is created. Tested rather than assumed:
the serve was reached (pointing it at a bogus path errored, so the binding was
not merely unevaluated) and `dep` still was not on Query.

A local target goes through a raw GraphQL query, because `currentWorkspace` is
deliberately kept out of a module's generated bindings — see
dagger/dagger#14148, which is about that restriction not actually being a
boundary. The path must be workspace-root-absolute: the workspace a module is
handed has its cwd at the module's own directory, so ".dagger/modules/dep" from a
module at ".dagger/modules/app" resolves to ".dagger/modules/app/.dagger/modules/dep".
A git target needs none of this and uses the typed bindings.

Only the targets' metadata is staged into the codegen container, not their
schemas: the dispatcher needs to know how to address a module, not what it
contains, and the schemas run to megabytes.

Nothing is emitted for a module that binds no clients — no serve function, and no
dag import that would send a reader looking for its use. The self target is
skipped; the engine already serves a module into its own session.

The legacy dispatcher is untouched. It has [[dependencies]] and it works.

Signed-off-by: Tom Chauveau <[email protected]>
The engine's builtin TypeScript runtime checks that a module's committed
generated files are present before it builds its container, and names the file
plus `dagger generate` when one is not. Under an entrypoint nothing runs that
runtime: this program builds the container itself, so the check went with it.
Without one a gitignored sdk/ surfaced as a module-resolution error from inside
a container, several layers from the cause.

Generated into call(), never into types(). Typedefs are literals and need none
of these files, so a module whose generated tree is missing still lists its
functions and fails on the first real call — which is where the name of the file
is worth having.

Only what this module's own recipe mounts or execs: the dispatcher and
sdk/{index,client.gen,core.js} everywhere, tsconfig.json for node because tsx
loads it, deno.json for deno because its import map is how @dagger.io/dagger
resolves. Bun needs neither. sdk/core.js is checked here though the engine's
guard does not check it — a .gitignore of `*.js` hides the bundle while leaving
client.gen.ts behind, and that failed opaquely.

The module name comes from the workspace rather than the typedef JSON, which
carries the pascalized *object* name: the error read `module "EptestDev"` for a
module called eptest-dev.

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv force-pushed the design/module-entrypoint branch from 686e492 to da28b97 Compare September 15, 2026 01:09
@TomChv
TomChv merged commit a90117c into main Sep 15, 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.

1 participant