Skip to content

Targeted module loading for dagger api call / api functions - #13574

Merged
tiborvass merged 5 commits into
dagger:mainfrom
eunomie:api-call-module-scope-design
Jul 22, 2026
Merged

tiborvass merged 5 commits into
dagger:mainfrom
eunomie:api-call-module-scope-design

Conversation

@eunomie

@eunomie eunomie commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

dagger api call <module> / api functions <module> build their command tree from a currentTypeDefs introspection that names no module — so they load every workspace module, and one broken sibling blocks calling any module. This completes #13548, which narrowed generate/check/up and left call/functions out of scope.

Fix

The CLI forwards its leading argv token (already extracted by functionName) as a new workspace_module_scope ClientMetadata hint. The engine resolves it in ensureRequestModulesLoaded (kebab-normalized; a known module → that module's target + entrypoint; unknown → entrypoint, else all) and consumes it one-shot after the first successful load whose only full-schema demand is currentTypeDefs. Pre-request loading leaves currentTypeDefs and its cache key untouched.

  • No API / SDK / version-gate change — no GraphQL schema change, no SDK regen, no version gate. Old engines ignore the unknown metadata key; old CLIs simply don't send it.
  • Nested clients never inherit the parent's scope; they forward their own headers' scope (including getOrInitClient's late-arriving fill-in, since the nested client is created by a headerless session-attachables pre-request).
sequenceDiagram
    autonumber
    participant CLI as dagger CLI
    participant H as serveQuery
    participant L as module loader
    participant R as currentTypeDefs resolver

    Note over CLI: dagger api call good fn<br/>(workspace = {good, bad-broken, entry*})
    Note over CLI: connect: workspace_module_scope: "good"
    CLI->>H: query { currentTypeDefs(...) }  — unchanged document
    H->>H: peek root fields → [currentTypeDefs]<br/>scope set → resolve + consume (one-shot)
    H->>L: demand = {good, entry} — bad stays pending
    L-->>H: good + entry served
    H->>R: resolve currentTypeDefs (unchanged resolver)
    R-->>CLI: typedefs (Query + good + entry closure)
    CLI->>H: query { goodMod { fn } }
    H-->>CLI: result — bad never loaded, cannot block
Loading

Design doc

hack/designs/targeted-module-loading-api-call-functions.md (in-tree) — includes a post-mortem of #13380 / #13406 / #13539 / #13543 and the alternatives considered.

Tests

Unit (demand-filter matrix, one-shot consumption, metadata plumbing incl. nested inherit/forward, CLI sites incl. shell guard) + integration TestWorkspaceCall* — targeting a module (exact + kebab), entrypoint-proxied function, scoped --help, one-shot within a session, bare listings still load all — all passing against a dev engine (27 passed), plus the merged generate/check/up narrowing tests as regression.

@eunomie
eunomie force-pushed the api-call-module-scope-design branch from e5164e1 to 7697688 Compare July 2, 2026 12:07
@eunomie
eunomie force-pushed the api-call-module-scope-design branch 2 times, most recently from 8d3d02d to f9e3023 Compare July 16, 2026 08:18
@eunomie eunomie changed the title Design: targeted module loading for dagger api call / api functions Targeted module loading for dagger api call / api functions Jul 16, 2026
@eunomie eunomie added this to the v1.0.0 milestone Jul 16, 2026
@eunomie
eunomie force-pushed the api-call-module-scope-design branch 2 times, most recently from 0a97a16 to b1331a0 Compare July 16, 2026 10:01
@eunomie
eunomie force-pushed the api-call-module-scope-design branch from b1331a0 to ad8452e Compare July 16, 2026 13:02
@eunomie
eunomie marked this pull request as ready for review July 16, 2026 13:49
@eunomie
eunomie force-pushed the api-call-module-scope-design branch 2 times, most recently from 192c252 to c57b53f Compare July 16, 2026 14:18
@tiborvass tiborvass self-assigned this Jul 16, 2026
@tiborvass
tiborvass force-pushed the api-call-module-scope-design branch 2 times, most recently from 99b7d4e to 76c577f Compare July 20, 2026 16:00
@tiborvass
tiborvass force-pushed the api-call-module-scope-design branch 2 times, most recently from 69b9d75 to af16986 Compare July 21, 2026 08:29
eunomie added 5 commits July 21, 2026 17:23
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]>
Add a WorkspaceModuleScope hint to ClientMetadata: the leading CLI
command token, forwarded unresolved (it may name a workspace module, an
entrypoint-proxied function, or a typo). The engine may use it to defer
loading unrelated workspace modules for the first request whose only
full-schema demand is currentTypeDefs; consumption and resolution are
engine-side and follow in the next patch.

The client only forwards the scope when it also asks for workspace
module loading, mirroring the LoadWorkspaceModules guard: with -m or
core mode there are no pending workspace modules to narrow. Nested
request metadata treats the scope like the other load-shaping fields:
never inherited from the parent's struct copy, re-read from the nested
request's own headers -- a dagger CLI running inside a container is a
nested client and its scoped call must narrow like on the host. Since
the nested client is created by a headerless session-attachables
pre-request before the CLI's metadata arrives, the scope also joins
getOrInitClient's late-arriving fill-in set, beside
LoadWorkspaceModules and SingleQuery.

Old engines json.Unmarshal client metadata and ignore the unknown key,
degrading to loading everything; old CLIs simply do not send it.

Signed-off-by: Yves Brissaud <[email protected]>
Consume the workspace_module_scope hint in ensureRequestModulesLoaded:
when a request's only full-schema demand is currentTypeDefs, the scope
replaces its load-everything contribution with the resolved module set
-- the named module plus the pending entrypoint module(s), whose
functions are proxied onto the Query root and belong in the command
tree either way. A token naming nothing known demands the entrypoint
alone when one is pending (it is probably one of its proxied
functions), else everything loads. Matching kebab-normalizes both
sides like the selector and root-field filters, and served modules are
recognized without reloading. Any other full-schema root field (env,
__schema, ...) keeps loading everything, scope untouched.

The scope is consumed exactly when it is applied. One-shot consumption
is load-bearing: dagger api call handing off to the interactive
prompt-mode shell reuses the session, and the shell's own typedefs
introspections must see every remaining module, not the narrowed view.
Consuming early is monotonically safe -- loading stays additive, so a
consumed scope only ever means more loads later, never less served.

Scoped loads stay strict (no best-effort): a call whose demanded
module fails to load must fail with that module's error.

Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Tibor Vass <[email protected]>
dagger api call and api functions forward their leading positional
token -- extracted with the existing functionName flag-skipping logic
-- as the workspace_module_scope client metadata hint, so the engine
narrows the currentTypeDefs introspection to the targeted module
instead of loading every workspace module. The queries the CLI sends
are unchanged, there is no engine-version branch (old engines ignore
the unknown metadata key and load everything, as before), and all
resolution stays engine-side.

The scope is set at the two command sites, deliberately not in
initModuleParams: dagger shell shares that helper and must keep the
full workspace view for its command table.

Signed-off-by: Yves Brissaud <[email protected]>
Lock in that dagger api call/functions targeting one module never load
an unrelated broken sibling: the CLI's workspace_module_scope hint
narrows the currentTypeDefs introspection to the targeted module, so
building the command tree (including --help) no longer pays for -- or
fails on -- every workspace module. Full listings still load
everything and surface the broken module.

The call-narrowing fixture covers the demand shapes single-word module
names cannot: a module declared goodMod targeted through its kebab-case
command name, and a workspace entrypoint whose root-proxied function is
the first argument, loading the entrypoint module alone. The fixture
also extends kebab-case coverage to the generate/check/up selector
path, which the merged generators-broken fixture only exercises with
single-word names.

Signed-off-by: Yves Brissaud <[email protected]>
@tiborvass
tiborvass force-pushed the api-call-module-scope-design branch from 8e586e2 to a9d4c30 Compare July 21, 2026 16:12
@tiborvass
tiborvass merged commit 1862b24 into dagger:main Jul 22, 2026
87 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.

2 participants