Skip to content

Load workspace modules on demand (dumb client, peeked operation name) - #13539

Closed
eunomie wants to merge 5 commits into
dagger:mainfrom
eunomie:dumb-cli-single-query-peak
Closed

eunomie wants to merge 5 commits into
dagger:mainfrom
eunomie:dumb-cli-single-query-peak

Conversation

@eunomie

@eunomie eunomie commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Alternative to #13406. Same goal — load workspace modules on demand instead of all-at-once, so an unrelated broken or stale module can't block operating on another one — but with no API change.

The CLI stays dumb. The intelligence is in the engine; the client just renames its introspection query so the engine can peek the target.

  • generate / check / up already narrow through their include argument — engine-only, zero CLI change.
  • dagger call / functions are the only hard case: their currentTypeDefs introspection names no module. Instead of adding a public currentTypeDefs(include:) argument (the Load workspace modules on demand #13406 approach, which needs a version gate, a cache-key fix, an SDK regen, and a CLI fallback for old engines), the CLI names the operation DaggerModuleScope_<module> and the engine peeks the operation name. Same query, same arguments — only the operation name changes.

Why this is nice

  • No API change — currentTypeDefs is untouched: no new argument, no SDK regeneration, no version gate, no PerClientInput.
  • Backward compatible — an operation name is free-form GraphQL. The same query works against any engine: an old engine that doesn't peek it simply ignores the name and loads everything (today's behavior). No fallback branch, no engine-version detection.
  • Loading happens before the request runs, so the schema already contains the module at currentTypeDefs time and its cache key stays workspace-unique for free (the property main has and Load workspace modules on demand #13406 had to restore with PerClientInput).

The whole client delta is two call sites plus naming the operation.

Reuses #13406's integration tests as the spec.

How it works — dagger call MODULE fn with { MODULE, sibling-A, sibling-BROKEN }

main — one-shot, load everything (a broken sibling blocks the call)

sequenceDiagram
    autonumber
    participant CLI
    participant H as Engine HTTP handler<br/>(session.go)
    participant L as Module loader
    participant S as dagql schema
    participant R as currentTypeDefs resolver
    participant C as dagql result cache

    Note over CLI: dagger call MODULE fn --arg ...
    CLI->>H: query { currentTypeDefs { ... } }<br/>PLAIN doc, no include
    Note right of CLI: multi-request session →<br/>SingleQuery peek/narrowing does NOT apply

    H->>H: ensureWorkspaceLoaded() (discover)
    H->>L: ensureModulesLoaded() — ALL pending
    L-->>H: MODULE ok, sibling-A ok, sibling-BROKEN FAILS
    Note over H,L: one broken sibling fails the whole request

    H->>S: build schema = core + MODULE + sibling-A + sibling-BROKEN
    H->>R: resolve currentTypeDefs
    R->>C: key = CurrentSchemaInput = digest(served schema)
    Note over C: served schema already contains workspace modules<br/>→ key differs per workspace for free (no client ID needed)
    R-->>CLI: typedefs (everything served)
    Note over CLI: build command tree → send actual call (2nd request)
Loading

#13406 — narrow via a new public include argument

sequenceDiagram
    autonumber
    participant CLI
    participant H as Engine HTTP handler<br/>(session.go)
    participant S as dagql schema
    participant R as currentTypeDefs resolver
    participant C as dagql result cache
    participant L as Module loader

    Note over CLI: dagger call MODULE fn --arg ...<br/>extract leading positional token → "MODULE"
    CLI->>H: query { currentTypeDefs(include: ["MODULE"]) { ... } }<br/>old engine rejects arg → fall back to PLAIN doc (load-all)

    H->>H: ensureWorkspaceLoaded() (discover)
    Note over H: ambient modules NOT loaded here (only -m extras)
    H->>S: build schema = core only
    Note over S: currentTypeDefs is a core field →<br/>query validates with no modules loaded

    H->>R: resolve currentTypeDefs(include: ["MODULE"])
    R->>C: key = CurrentSchemaInput(core only) + PerClientInput(client ID)
    Note over C: schema digest is core-only → identical across workspaces<br/>PerClientInput (client ID) is what prevents an A/B collision
    R->>L: EnsureWorkspaceModulesForTypeDefs(["MODULE"])
    L-->>R: MODULE ok (+ entrypoint module if configured)
    Note over L: sibling-A, sibling-BROKEN stay PENDING (never evaluated)
    R-->>CLI: typedefs for MODULE
    Note over CLI: build command tree → send actual call (2nd request)
Loading

This PR — narrow via the peeked operation name (no API change)

sequenceDiagram
    autonumber
    participant CLI
    participant H as Engine HTTP handler<br/>(session.go)
    participant L as Module loader
    participant S as dagql schema
    participant R as currentTypeDefs resolver
    participant C as dagql result cache

    Note over CLI: dagger call MODULE fn --arg ...<br/>extract leading positional token → "MODULE"
    CLI->>H: query DaggerModuleScope_MODULE { currentTypeDefs { ... } }<br/>SAME doc for every engine (no include arg, no fallback)

    H->>H: ensureWorkspaceLoaded() (discover)
    H->>H: ensureRequestModulesLoaded() — peek operation name → scope "MODULE"
    H->>L: load only MODULE (+ entrypoint module if configured), pre-request
    L-->>H: MODULE ok
    Note over L: sibling-A, sibling-BROKEN stay PENDING (never evaluated)
    Note over H,L: a broken sibling can't fail this request

    H->>S: build schema = core + MODULE
    Note over S: MODULE served before the request runs

    H->>R: resolve currentTypeDefs (UNCHANGED — no include arg)
    R->>C: key = CurrentSchemaInput = digest(served schema)
    Note over C: served schema already contains MODULE<br/>→ key differs per workspace for free (no PerClientInput needed)
    R-->>CLI: typedefs for MODULE
    Note over CLI: build command tree → send actual call (2nd request)
Loading

Design doc

hack/designs/dumb-cli-single-query-peek-module-loading.md

@eunomie
eunomie force-pushed the dumb-cli-single-query-peak branch 5 times, most recently from 4b6e61d to 9618bf4 Compare June 23, 2026 14:44
eunomie added 5 commits June 23, 2026 16:51
Document an alternative to dagger#13406 (demand-driven workspace module
loading) that keeps the same engine foundation but moves the
`dagger call`/`functions` narrowing signal out of the client. Instead of
a new public `currentTypeDefs(include:)` argument and the client-side
document building, version gating and SDK regeneration it implies, the
CLI names its typedefs introspection operation after the target module
and the engine peeks the operation name. The same query works against
every engine, so the CLI carries no engine-version fallback.

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]>
`dagger call`/`functions <module>` build their command tree from a
currentTypeDefs introspection that previously loaded every workspace
module. That request names no module, so the target must enter it
somehow. Rather than add a public currentTypeDefs(include:) argument and
the client-side document building, version gating and SDK regeneration
it implies, carry the target in the GraphQL operation name -- free-form
text every request already sends.

When targeting a module, name the introspection operation
"DaggerModuleScope_<module>" (leading positional token, the only token
that can name a workspace module) so the engine peeks it and loads just
that module plus the workspace entrypoint. Kebab-case command names are
sanitized to identifier-safe operation names; the engine kebab-normalizes
the decoded token, so `good-mod` still matches module `goodMod`.

The query is otherwise unchanged: an engine that does not peek the
operation name ignores it and loads every module, the pre-narrowing
behavior, so the CLI needs no engine-version fallback. currentTypeDefs
and every generated SDK client are untouched.

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 dumb-cli-single-query-peak branch from 9618bf4 to cde8c12 Compare June 23, 2026 14:51
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 8, 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.

@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 16, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant