Skip to content

Load workspace modules on demand (per-module typedefs) - #13543

Closed
eunomie wants to merge 7 commits into
dagger:mainfrom
eunomie:per-module-typedefs
Closed

eunomie wants to merge 7 commits into
dagger:mainfrom
eunomie:per-module-typedefs

Conversation

@eunomie

@eunomie eunomie commented Jun 24, 2026 •

Copy link
Copy Markdown
Member

Problem

dagger call|functions <module> builds its command tree from currentTypeDefs(returnAllTypes: true), which serves every workspace module. Running one module pays for all its siblings, and a single broken or stale sibling blocks operating on any module — including the one you ran dagger generate to fix.

Solution

Discover module names without loading anything, then fetch only the targeted module's typedefs:

  • WorkspaceModule.typeDefs(returnAllTypes, hideCore) (new engine field): loads only the named workspace module on demand via EnsureWorkspaceModules, then builds its typedefs through the closure logic shared with currentTypeDefs. Siblings stay pending, so a broken one can't block the call.
  • CLI: dagger call|functions resolve the leading token to an installed module (currentWorkspace.moduleList, kebab-mapped to the config name) and request only that module's typedefs via moduleList(module:).typeDefs. An unmatched token falls back to the workspace entrypoint module; bare / no-token falls back to load-all currentTypeDefs.

currentTypeDefs itself is unchanged — still used by the in-engine MCP/LLM tool builder and by bare dagger functions.

Flow

sequenceDiagram
    autonumber
    actor U as User
    participant CLI as dagger CLI
    participant ENG as Engine

    U->>CLI: dagger call backend test
    CLI->>ENG: connect session
    Note over ENG: no modules loaded yet
    CLI->>ENG: currentWorkspace.moduleList (names, no load)
    ENG-->>CLI: backend, frontend, docs (+ entrypoint flag)
    Note over CLI: backend is an installed module
    CLI->>ENG: moduleList(module: backend).typeDefs
    Note over ENG: load backend only — siblings stay pending
    ENG-->>CLI: Query + backend typedefs
    CLI->>ENG: execution backend.test
    ENG-->>CLI: result
Loading

Tests

TestGenerators/TestWorkspace*Narrows (generate / check / up / call): a broken sibling no longer blocks a scoped dagger call; kebab-case and entrypoint targets are covered; bare dagger functions still loads everything (and surfaces the broken module).

Design notes: hack/designs/per-module-typedefs.md.


Builds on the additive demand-loading foundation from #13406 (included here). Supersedes #13539, which carried the target in an encoded operation name; here it enters the query as a normal argument.

eunomie added 6 commits June 24, 2026 15:46
Proposal for demand-driven workspace module loading via a per-module
WorkspaceModule.typeDefs introspection: dagger call/functions reads module
names (currentWorkspace.moduleList, no load) then fetches only the targeted
module's typedefs, instead of serving every module via load-all
currentTypeDefs. currentTypeDefs stays untouched (kept for MCP and bare
listing). Includes the main-baseline call-flow reference doc.

Signed-off-by: Yves Brissaud <[email protected]>
Replace the one-shot ensureModulesLoaded with per-request, per-module
loading. Each request loads only the pending workspace modules it
demands and unselected modules stay pending, loading when a later
request demands them. The dagql schema is rebuilt from the served set
per request, so the session schema grows monotonically: narrowing is
deferral, not exclusion, and is therefore safe for open multi-request
sessions, generalizing the previous SingleQuery-only peek to every
client.

The demand is read from the request:

  - Root fields naming a pending module load just that module (the
    existing entrypoint fallback is preserved); full-schema fields
    (__schema, env, currentTypeDefs, ...) and anything unrecognized
    load everything.

  - An operation named "DaggerModuleScope_<module>" -- set by a targeted
    `dagger call`/`functions <module>` introspection, which otherwise
    names no module -- loads that module plus the workspace entrypoint.
    PeekRootFieldsAndOperation exposes the operation name (recovered from
    the document when the request envelope omits it) and a small codec
    encodes/decodes the scope. The operation name is otherwise ignored,
    so the same query works against engines that do not peek it.

Extra (-m) modules are explicitly requested, so they keep loading
eagerly on the first request with sticky errors. Ambient module failures
become per-module: a broken module only fails the requests that demand
it, and stays pending so later demands report its load error. Served
identities and names are tracked so cross-batch loads stay deduplicated
and demand filters keep recognizing already-loaded modules. Cancellation
and deadline errors are never recorded as module failures, so an
interrupted load stays retryable by later demands in the session.

Signed-off-by: Yves Brissaud <[email protected]>
The entire currentWorkspace selector API returns core types, so
currentWorkspace { generators|checks|services(include: [...]) } validates
against the core schema with no modules loaded -- only the resolver's
result needs them. Add a Query.Server.EnsureWorkspaceModules hook
(implemented by the engine, precedent: CurrentWorkspace) and call it at
the top of the checks/generators/services resolvers with their native
include argument.

So `dagger generate|check|up <module>` loads only the named module with
no CLI or API change -- the include is already the command's functional
argument -- and an unrelated broken or stale module can no longer block
the operation.

Signed-off-by: Yves Brissaud <[email protected]>
Per-module typedefs introspection that loads only the named workspace
module on demand (EnsureWorkspaceModules), leaving siblings pending, then
builds its typedefs through typeDefsFromServedDeps extracted from
Query.currentTypeDefs. Lets dagger call/functions narrow loading to the
targeted module instead of the load-all currentTypeDefs.

Signed-off-by: Yves Brissaud <[email protected]>
dagger call/functions resolve the leading positional token to an installed
workspace module via currentWorkspace.moduleList, and when it matches fetch
only that module's typedefs through currentWorkspace.moduleList.typeDefs
instead of the load-all currentTypeDefs. Unmatched tokens (entrypoint-proxied
functions, bare listings) fall back to currentTypeDefs. typedefs.graphql now
shares a TypeDefParts fragment across both operations.

Signed-off-by: Yves Brissaud <[email protected]>
Add a generators-broken workspace fixture -- a healthy module exposing a
generator, a check, and a service, alongside a module with intentionally
invalid source -- and lock in that `dagger generate`, `check`, `up`,
`call`, and `functions` targeting the healthy module never load the
broken one, while full listings still load every module and surface it.
The generate test runs with -y, exercising the multi-request path where
later requests must keep recognizing the already-loaded module.

A second fixture (call-narrowing) covers the demand shapes single-word
module names cannot: a module declared as "goodMod" is targeted through
its kebab-case command name (`dagger call good-mod ...`), and with a
workspace entrypoint configured, calling one of its root-proxied
functions loads the entrypoint module alone. In both cases the broken
sibling module stays unloaded.

Signed-off-by: Yves Brissaud <[email protected]>
@eunomie
eunomie force-pushed the per-module-typedefs branch from 5c6003e to ba13666 Compare June 24, 2026 13:57
Signed-off-by: Yves Brissaud <[email protected]>
eunomie added a commit to eunomie/dagger that referenced this pull request Jul 2, 2026
Design for extending the demand-driven workspace module loading (merged
for generate/check/up in dagger#13548) to dagger api call and api functions.

The introspection these commands build their command tree from
(currentTypeDefs) names no module, so the target must cross the wire:
the chosen design carries the CLI's leading command token in a new
ClientMetadata workspace_module_scope hint, resolved engine-side with
the same kebab/entrypoint rules as the merged demand filters and
consumed one-shot by the first request whose only full-schema demand is
currentTypeDefs. No GraphQL API change, no SDK regeneration, no version
gating; old engines ignore the unknown metadata key and old CLIs simply
do not send it.

Includes the investigation behind the choice: the merged foundation,
why call/functions are the hard case, a post-mortem of the prior
attempts (dagger#13380, dagger#13406, dagger#13539, dagger#13543), and the alternatives ranked.

Signed-off-by: Yves Brissaud <[email protected]>
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

eunomie added a commit to eunomie/dagger that referenced this pull request Jul 16, 2026
Design for extending the demand-driven workspace module loading (merged
for generate/check/up in dagger#13548) to dagger api call and api functions.

The introspection these commands build their command tree from
(currentTypeDefs) names no module, so the target must cross the wire:
the chosen design carries the CLI's leading command token in a new
ClientMetadata workspace_module_scope hint, resolved engine-side with
the same kebab/entrypoint rules as the merged demand filters and
consumed one-shot by the first request whose only full-schema demand is
currentTypeDefs. No GraphQL API change, no SDK regeneration, no version
gating; old engines ignore the unknown metadata key and old CLIs simply
do not send it.

Includes the investigation behind the choice: the merged foundation,
why call/functions are the hard case, a post-mortem of the prior
attempts (dagger#13380, dagger#13406, dagger#13539, dagger#13543), and the alternatives ranked.

Signed-off-by: Yves Brissaud <[email protected]>
eunomie added a commit to eunomie/dagger that referenced this pull request Jul 16, 2026
Design for extending the demand-driven workspace module loading (merged
for generate/check/up in dagger#13548) to dagger api call and api functions.

The introspection these commands build their command tree from
(currentTypeDefs) names no module, so the target must cross the wire:
the chosen design carries the CLI's leading command token in a new
ClientMetadata workspace_module_scope hint, resolved engine-side with
the same kebab/entrypoint rules as the merged demand filters and
consumed one-shot by the first request whose only full-schema demand is
currentTypeDefs. No GraphQL API change, no SDK regeneration, no version
gating; old engines ignore the unknown metadata key and old CLIs simply
do not send it.

Includes the investigation behind the choice: the merged foundation,
why call/functions are the hard case, a post-mortem of the prior
attempts (dagger#13380, dagger#13406, dagger#13539, dagger#13543), and the alternatives ranked.

Signed-off-by: Yves Brissaud <[email protected]>
eunomie added a commit to eunomie/dagger that referenced this pull request Jul 16, 2026
Design for extending the demand-driven workspace module loading (merged
for generate/check/up in dagger#13548) to dagger api call and api functions.

The introspection these commands build their command tree from
(currentTypeDefs) names no module, so the target must cross the wire:
the chosen design carries the CLI's leading command token in a new
ClientMetadata workspace_module_scope hint, resolved engine-side with
the same kebab/entrypoint rules as the merged demand filters and
consumed one-shot by the first request whose only full-schema demand is
currentTypeDefs. No GraphQL API change, no SDK regeneration, no version
gating; old engines ignore the unknown metadata key and old CLIs simply
do not send it.

Includes the investigation behind the choice: the merged foundation,
why call/functions are the hard case, a post-mortem of the prior
attempts (dagger#13380, dagger#13406, dagger#13539, dagger#13543), and the alternatives ranked.

Signed-off-by: Yves Brissaud <[email protected]>
eunomie added a commit to eunomie/dagger that referenced this pull request Jul 16, 2026
Document, in hack/designs/done, how dagger api call and api functions
narrow workspace module loading to their target: the CLI forwards its
leading command-line word as the workspace_module_scope client metadata
hint and the engine resolves it, completing the demand-driven loading
that generate/check/up already had. Covers the behavior table, the
one-shot-per-session rule, nested-client plumbing, why the target rides
connection metadata rather than a new API surface, and the prior
attempts (dagger#13380, dagger#13406, dagger#13539, dagger#13543).

Signed-off-by: Yves Brissaud <[email protected]>
eunomie added a commit to eunomie/dagger that referenced this pull request Jul 16, 2026
Document, in hack/designs/done, how dagger api call and api functions
narrow workspace module loading to their target: the CLI forwards its
leading command-line word as the workspace_module_scope client metadata
hint and the engine resolves it, completing the demand-driven loading
that generate/check/up already had. Covers the behavior table, the
one-shot-per-session rule, nested-client plumbing, why the target rides
connection metadata rather than a new API surface, and the prior
attempts (dagger#13380, dagger#13406, dagger#13539, dagger#13543).

Signed-off-by: Yves Brissaud <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Jul 17, 2026
tiborvass pushed a commit to eunomie/dagger that referenced this pull request Jul 20, 2026
Document, in hack/designs/done, how dagger api call and api functions
narrow workspace module loading to their target: the CLI forwards its
leading command-line word as the workspace_module_scope client metadata
hint and the engine resolves it, completing the demand-driven loading
that generate/check/up already had. Covers the behavior table, the
one-shot-per-session rule, nested-client plumbing, why the target rides
connection metadata rather than a new API surface, and the prior
attempts (dagger#13380, dagger#13406, dagger#13539, dagger#13543).

Signed-off-by: Yves Brissaud <[email protected]>
tiborvass pushed a commit to eunomie/dagger that referenced this pull request Jul 21, 2026
Document, in hack/designs/done, how dagger api call and api functions
narrow workspace module loading to their target: the CLI forwards its
leading command-line word as the workspace_module_scope client metadata
hint and the engine resolves it, completing the demand-driven loading
that generate/check/up already had. Covers the behavior table, the
one-shot-per-session rule, nested-client plumbing, why the target rides
connection metadata rather than a new API surface, and the prior
attempts (dagger#13380, dagger#13406, dagger#13539, dagger#13543).

Signed-off-by: Yves Brissaud <[email protected]>
tiborvass pushed a commit to eunomie/dagger that referenced this pull request Jul 21, 2026
Document, in hack/designs/done, how dagger api call and api functions
narrow workspace module loading to their target: the CLI forwards its
leading command-line word as the workspace_module_scope client metadata
hint and the engine resolves it, completing the demand-driven loading
that generate/check/up already had. Covers the behavior table, the
one-shot-per-session rule, nested-client plumbing, why the target rides
connection metadata rather than a new API surface, and the prior
attempts (dagger#13380, dagger#13406, dagger#13539, dagger#13543).

Signed-off-by: Yves Brissaud <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant