Skip to content

Narrow workspace module loading for dagger generate/check/up/call - #13380

Closed
eunomie wants to merge 9 commits into
dagger:mainfrom
eunomie:workspace-load-single-module
Closed

eunomie wants to merge 9 commits into
dagger:mainfrom
eunomie:workspace-load-single-module

Conversation

@eunomie

@eunomie eunomie commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

Problem

dagger generate <module>, dagger check <module>, dagger up <module>, and dagger call <module> … (plus dagger functions <module>) each load every workspace module — to enumerate generators/checks/services, or to build the command tree from a typedefs introspection. A single stale or broken workspace module then blocks operating on any other module — and for generate this includes the very module you were trying to fix by running dagger generate.

The single-query lazy-load mechanism (peek root fields → narrow pending workspace modules) does not help here: these commands root their query at currentWorkspace/currentTypeDefs (treated as needing the full workspace schema) and keep the session open rather than declaring SingleQuery.

Fix

Reuse and extend the existing peek/narrow mechanism rather than adding any new client→server contract:

  • dagql.PeekWorkspaceSelectorInclude recognizes { currentWorkspace { <generators|checks|services>(include: [...]) … } } — backing generate/check/up.
  • dagql.PeekWorkspaceTypeDefsInclude recognizes { currentTypeDefs(… include: [...]) … } — backing call/functions, which build their command tree from a typedefs introspection. The include argument may be a literal list or a query variable, so the shared request peek now also resolves variables.
  • currentTypeDefs gains an optional include argument: a workspace module-loading hint the engine consumes before the resolver runs (the resolver itself ignores it).
  • serveQuery narrows the pending workspace modules to the named modules (module:item, or a bare module matching a known workspace module) plus their transitive deps, via one shared filter. A bare token that is not a module name (an entrypoint-proxied item), or patterns matching no module, fall back to loading everything.
  • CLI: generate/check/up pass their include patterns; call/functions pass their leading positional token as the typedefs include hint.

Net effect: dagger generate/check/up/call/functions <module> loads only that module (+ its dependencies), so an unrelated broken/stale module can no longer block the operation.

Tests

  • Unit: dagql peek matching for generators/checks/services and currentTypeDefs (literal + variable include, plus negative shapes), and the engine/server pending-module filter.
  • Integration: TestWorkspaceGenerate/Check/Up/CallNarrowsToRequestedModule against a generators-broken fixture — a healthy dang module exposing a generator, a check, and a service, alongside a module with intentionally invalid source. Each asserts that targeting only the healthy module succeeds despite the broken module, while a full listing still loads every module and surfaces the broken one.

@eunomie
eunomie force-pushed the workspace-load-single-module branch from 5dba7c0 to dc25ea9 Compare June 9, 2026 10:50
@eunomie eunomie changed the title Narrow workspace module loading for dagger generate Narrow workspace module loading for dagger generate/check/up Jun 9, 2026
@TomChv

TomChv commented Jun 9, 2026

Copy link
Copy Markdown
Member

Net effect: dagger generate/check/up loads only that module (+ its dependencies), so an unrelated broken/stale module can no longer block the operation.

Do we have a way to verify a module is broken or not then? Or we have to call it to ensure it work? I remember we had a similar discussion when I did the lazy runtime loading.

@eunomie

eunomie commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

Do we have a way to verify a module is broken or not then? Or we have to call it to ensure it work?

Yes there's multiple ways. The basic one is probably just to call asModule on it and see what happen. That would be interesting if we want for instance to not block because of failed modules and at the same time loading all (valid) modules. For instance on a full dagger generate.

In this case it's slightly different, and very related to the suppression of codegen at runtime for modules.
For instance if you remove a function of a module, add code from a dependency, enable self calls, etc, you'll need to run dagger generate (or dagger generate SDK) to refresh the generated code, bindings, entry point. And currently this can't work because if the module (the one you want to fix) is not buildable then the full process stop even if you already specified dagger generate SDK.

This PR will not solve the dagger generate when there's a failing module, that's quite orthogonal, but something we might want.

eunomie added 9 commits June 10, 2026 09:32
Add PeekWorkspaceSelectorInclude, which recognizes a GraphQL request of the
shape `{ currentWorkspace { <generators|checks|services>(include: [...]) ... } }`
and returns the literal include patterns while preserving the request body. It
is deliberately conservative: any other shape (extra root fields, a non-selector
selection, fragments, a missing or non-literal include argument) returns false.

These three currentWorkspace fields back `dagger generate`, `dagger check`, and
`dagger up` respectively. Each roots its query at currentWorkspace -- otherwise
treated as needing the full workspace schema -- so recognizing this shape lets
the engine narrow workspace module loading to only the requested items' modules.

Signed-off-by: Yves Brissaud <[email protected]>
`dagger generate <module>`, `dagger check <module>`, and `dagger up <module>`
each root their query at currentWorkspace and keep the session open rather than
declaring SingleQuery, so the existing single-query peek treats them as needing
the full workspace schema and loads every workspace module just to enumerate
generators/checks/services. One stale/broken module then blocks the operation on
any other -- including, for generate, the very module you wanted to fix.

When such a client requests specific items via an include argument, peek those
patterns (PeekWorkspaceSelectorInclude) and narrow the pending workspace modules
to the named modules ("module:item" or a bare "module" matching a known
workspace module) plus their transitive dependencies. A bare token that is not a
module name (an entrypoint item) or patterns matching no module disable the
narrowing, so loading falls back to every module.

Signed-off-by: Yves Brissaud <[email protected]>
Add TestWorkspaceGenerate/Check/UpNarrowsToRequestedModule and a
generators-broken workspace fixture: a healthy dang module exposing a generator,
a check, and a service, plus a module with intentionally invalid source. They
lock in that `dagger generate`/`check`/`up <module>` (and their -l list forms)
load only the named module -- succeeding despite the unrelated broken module --
while the full `-l` forms still load every module and surface the broken one.

Signed-off-by: Yves Brissaud <[email protected]>
Add PeekWorkspaceTypeDefsInclude, which recognizes a GraphQL request of the
shape `{ currentTypeDefs(... include: [...]) ... }` and returns the include
patterns while preserving the request body. `dagger call` and `dagger functions`
build their command tree from currentTypeDefs, which otherwise needs the full
workspace schema; recognizing this shape lets the engine narrow module loading
to the targeted module.

The include argument may be a literal list or a query variable, so extend the
shared request peek to also parse the request variables and resolve a variable
reference. The existing literal-list peeks (generators/checks/services) are
unaffected.

Signed-off-by: Yves Brissaud <[email protected]>
Add an optional `include` argument to currentTypeDefs. It is a workspace
module-loading hint consumed by the engine before the resolver runs (it narrows
which modules are served); the typedef computation reflects whatever ended up
served, so the resolver ignores it. This lets `dagger call <module>` and
`dagger functions <module>` introspect only the targeted module.

Regenerate the SDK clients for the new argument.

Signed-off-by: Yves Brissaud <[email protected]>
`dagger call <module> <function>` and `dagger functions <module>` build their
command tree from a currentTypeDefs introspection. That query roots at
currentTypeDefs (treated as needing the full workspace schema) and keeps the
session open rather than declaring SingleQuery, so it loads every workspace
module just to introspect and one stale/broken module blocks the call.

When such a client scopes the introspection via an include argument, peek those
patterns (PeekWorkspaceTypeDefsInclude) and narrow the pending workspace modules
to the named modules (plus their transitive dependencies), reusing the same
filter as the generate/check/up narrowing. A token that does not name a
workspace module disables narrowing, so loading falls back to every module.

Signed-off-by: Yves Brissaud <[email protected]>
When `dagger call <module> ...` or `dagger functions <module>` has a leading
positional token, pass it as the currentTypeDefs `include` hint. Only the first
token can name a workspace module (later tokens are functions/arguments within
it), so an unrelated broken/stale module is not loaded just to introspect the
targeted one. The engine ignores the hint when it does not name a workspace
module (e.g. an entrypoint-proxied function or no args), loading every module as
before.

Signed-off-by: Yves Brissaud <[email protected]>
Add TestWorkspaceCallNarrowsToRequestedModule, asserting `dagger call good
verify` and `dagger functions good` succeed despite the unrelated broken module,
while a full `dagger functions` still loads every module and surfaces it.

Restructure the generators-broken healthy module so its workspace directory is a
parameter of the generator rather than an object field: a `@defaultPath` field
becomes a constructor argument, which collides with `dagger call`'s command-tree
construction. This keeps the existing generate/check/up narrowing tests passing.

Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
@eunomie
eunomie force-pushed the workspace-load-single-module branch from dc25ea9 to b98ddf4 Compare June 10, 2026 07:33
@eunomie
eunomie requested review from a team as code owners June 10, 2026 07:33
@eunomie eunomie changed the title Narrow workspace module loading for dagger generate/check/up Narrow workspace module loading for dagger generate/check/up/call Jun 10, 2026
@eunomie
eunomie marked this pull request as draft June 12, 2026 16:23
@eunomie eunomie closed this Jun 23, 2026
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]>
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]>
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants