Skip to content

Load workspace modules on demand for generate/check/up - #13548

Merged
eunomie merged 4 commits into
dagger:mainfrom
eunomie:demand-load-generate-check-up
Jun 29, 2026
Merged

eunomie merged 4 commits into
dagger:mainfrom
eunomie:demand-load-generate-check-up

Conversation

@eunomie

@eunomie eunomie commented Jun 25, 2026

Copy link
Copy Markdown
Member

Problem

Workspace module loading is one-shot: the first schema-needing request loads every configured module, so dagger generate|check|up <module> pays for all its siblings, and a single broken or stale module blocks operating on any other module — for generate, including the very module you were trying to fix. The existing narrowing (peek root fields → drop pending modules) is restricted to SingleQuery clients, because dropped modules can't come back in a later request, and generate/check/up are structurally multi-request.

Fix

Make loading additive and demand-driven: each request loads only the modules it can possibly touch; the rest stay pending and load when a later request demands them. The dagql schema is already rebuilt from the served set per request, so the session schema grows monotonically — narrowing becomes deferral rather than exclusion, safe for open multi-request sessions, and the root-field demand generalizes from SingleQuery to every client.

The demand source is the natural one for each query shape:

  • currentWorkspace { checks|generators|services(include: …) } validates against the core schema (all those fields return core types), so loading moves into the resolvers via a new Query.Server.EnsureWorkspaceModules hook — they receive include natively, no request peeking. Since the CLI already sends include as the command's functional argument, dagger generate|check|up <module> narrows with zero CLI and zero API change.
  • Root fields naming a pending module (raw dagger query, shell) load just that module (existing entrypoint fallback preserved); full-schema fields (__schema, currentTypeDefs, env, …) and anything unrecognized conservatively load everything.
sequenceDiagram
    autonumber
    participant CLI as dagger CLI
    participant H as serveQuery
    participant L as ensureModulesLoaded
    participant R as generators resolver

    Note over CLI: dagger generate good<br/>(workspace = {good, bad-broken})
    CLI->>H: query { currentWorkspace { generators(include:["good"]) { … } } }
    H->>H: ensureWorkspaceLoaded (pending = {good, bad})
    H->>L: peek root fields → currentWorkspace is core → demand = ∅
    H->>R: resolve generators(include:["good"])
    R->>L: EnsureWorkspaceModules(["good"])
    Note over L: include names "good" → load {good}<br/>bad stays pending, never loaded
    R-->>CLI: good's generators (bad cannot block this)
Loading

Other behavior:

  • Extra (-m) modules keep loading eagerly with sticky errors (explicitly requested).
  • Ambient module failures are per-module and non-sticky: a broken module only fails requests that demand it, and stays pending so later demands report its load error. Full listings (dagger generate -l, bare dagger functions) still load everything and surface it.
  • Cancellation/deadline is never recorded as a module failure, so an interrupted load stays retryable.
  • Entrypoint arbitration is split across batches: extras outrank ambient candidates; multiple ambient entrypoint declarations load together to preserve the existing conflict detection.

Design doc: hack/designs/demand-driven-module-loading.md.

Scope — dagger call / functions are intentionally out

This is the fourth PR on this topic. It deliberately covers only generate / check / up (and raw execution queries), which the engine narrows for free from the include they already send.

dagger call|functions <module> are not addressed here. They build their command tree from a currentTypeDefs(returnAllTypes: true) introspection that carries no module signal; narrowing it requires getting the target into the request (a new typedefs path/argument plus a CLI change) — a larger, separately reviewable change with its own trade-offs. This PR does not regress them: currentTypeDefs stays on the full-schema list, so call/functions load everything exactly as on main. The additive engine here is the foundation a later call-narrowing change builds on.

Relationship to the prior PRs (all same author):

This PR extracts the engine-only foundation + selector narrowing common to all three, with no SDK regen, no schema.graphqls change, and no cmd/dagger change.

Tests

TestGenerators/TestWorkspace{Generate,Check,Up}NarrowsToRequestedModule: a broken sibling no longer blocks a scoped generate/check/up of a healthy module, while full listings still load every module and surface the broken one. Verified against a from-source dev engine.

@shykes

shykes commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Did not read the code, but we discussed the design with @eunomie and we're in sync :)

eunomie added 4 commits June 29, 2026 09:50
Design for loading workspace modules on demand -- additively, so
narrowing is deferral rather than exclusion -- for dagger
generate/check/up and raw execution queries. dagger call/functions are
out of scope and keep loading everything, unchanged.

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's root fields: a field naming a
pending module loads just that module (the existing entrypoint fallback
is preserved), while full-schema fields (__schema, currentTypeDefs, env,
...) and anything unrecognized load everything. The currentWorkspace
selector resolvers load on demand from their own include argument
instead (the EnsureWorkspaceModules hook), so currentWorkspace itself
demands nothing here.

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]>
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`, and `up`
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.

Signed-off-by: Yves Brissaud <[email protected]>
@eunomie
eunomie force-pushed the demand-load-generate-check-up branch from 943107b to ac73461 Compare June 29, 2026 07:50
@eunomie
eunomie merged commit bc39a70 into dagger:main Jun 29, 2026
81 checks passed
@eunomie
eunomie deleted the demand-load-generate-check-up branch June 29, 2026 14:28
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]>
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