Skip to content

feat(schema): require workspace arg on asSDK - #13845

Merged
TomChv merged 1 commit into
dagger:mainfrom
TomChv:feat/make-as-sdk-workspace-required
Aug 6, 2026
Merged

TomChv merged 1 commit into
dagger:mainfrom
TomChv:feat/make-as-sdk-workspace-required

Conversation

@TomChv

@TomChv TomChv commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

What

currentModule.asSDK(workspace:) is now required. The fallback to the ambient current workspace is gone.

Part of #13790 — the asSDK half only. The other half, module functions that declare ws: Workspace! but are still published as nullable (core/typedef.go:252-256, which is what produces dagger.FooOpts{Ws: ws} when calling another module), is not addressed here.

Why

#13727 landed the argument as optional to avoid updating every SDK in lockstep, leaving two FIXMEs naming the required argument as the end state. That rollout is finished — every official SDK module passes a workspace explicitly, as of 2026-07-27:

Repo Call site
dagger/go-sdk go-sdk.dang:32,116
dagger/typescript-sdk typescript-sdk.dang:59,641
dagger/python-sdk python-sdk.dang:26
dagger/php-sdk php-sdk.dang:32

Optional was also a lie in practice. Since #13229 a module driven as a dependency does not inherit its caller's workspace, so the fallback either failed with no current workspace: workspace not loaded (the failure #13727 was filed for) or, when the caller held a synthetic asWorkspace value or a staged overlay reached outside a generator group, silently read the wrong config. And because the argument was nullable, Go codegen rendered it as opts, so the only correct call was dag.CurrentModule().AsSDK(dagger.CurrentModuleAsSDKOpts{Workspace: ws}) — same shape in TypeScript, Python and Rust.

How

  • currentModuleAsSDK takes dagql.ID[*core.Workspace] and loads it directly; the currentWorkspace fallback and both FIXMEs are gone.
  • The three in-repo fixtures in core/integration/generators_test.go drop the opts wrapper (they already passed the workspace).
  • Regenerated: schema, all six SDK clients, PHP reference docs. CurrentModuleAsSDKOpts / CurrentModuleAsSdkOpts disappear from Go, TypeScript and Rust; Go is now AsSDK(workspace *Workspace).

Compatibility

The field is gated to AfterVersion("v1.0.0-0"), so this only touches pre-GA v1 surface. Breakage is limited to a workspace pinning an SDK module older than 2026-07-27 and running a newer engine; the error names the argument (missing required argument: "workspace") and dagger lock update moves the pin forward. No coordinated SDK release needed.

Not included

toolchains/{engine-dev,cli-dev,go}/internal/dagger/dagger.gen.go still carry the old optional signature — they only regenerate against a dev engine, and nothing in those toolchains calls AsSDK. toolchains/go is a separate matter: it pins engineVersion = "v0.21.7" yet its client already carries v1-only surface (Workspace.Cwd), which predates this change.

currentModule.asSDK took the workspace as an optional argument and fell
back to the ambient current workspace when omitted. That was a stopgap:
dagger#13727 landed the argument as optional to avoid updating every SDK in
lockstep, with FIXMEs marking the required argument as the end state.

The rollout is done — the go, typescript, python and php SDK modules all
call asSDK(workspace: ws) as of 2026-07-27 — so require it and drop the
fallback. Nullable was also a lie in practice: since dagger#13229 a module
driven as a dependency does not inherit its caller's workspace, so the
fallback either failed with "no current workspace" or, for a synthetic
or overlaid workspace, silently read the wrong config. It also forced
the clunky CurrentModuleAsSDKOpts{Workspace: ws} call shape in Go, and
the equivalent opts objects in TypeScript, Python and Rust.

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv requested review from a team as code owners August 5, 2026 16:14
@TomChv
TomChv marked this pull request as draft August 5, 2026 16:16
@TomChv
TomChv marked this pull request as ready for review August 6, 2026 12:30

@eunomie eunomie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@TomChv
TomChv merged commit 1bd7335 into dagger:main Aug 6, 2026
88 checks passed
TomChv added a commit that referenced this pull request Aug 6, 2026
Workspace arguments on module functions were published as nullable no
matter how they were declared, because the engine injects one when the
caller leaves it unset. That made every signature a lie in the same way
currentModule.asSDK's was before #13845: a function declaring
`ws: Workspace!` advertised an optional argument.

Drop the forcing, so a Workspace argument declared required is published
required and one declared optional stays nullable and keeps its
injection.

The injection can no longer rescue a required argument: dagql rejects a
missing non-null argument in preselect (dagql/objects.go) before it runs
the GetDynamicInput hook that fills workspace args in. So the callers
that relied on it now pass the workspace explicitly, resolving it the
same way loadWorkspaceArg does — the workspace an enclosing group bound
into the context, else the session's ambient one, and never inherited
across a module function boundary:

- generator, check and up leaves resolve through ModTreeNode.DagqlValue,
  which now puts the workspace on the selector — for the constructor at
  the root as well as the leaf function. The ambient fallback is what
  keeps Module.generator(name:) working, since it binds no workspace;
  that is the shape the scale-out check query builds, so scale-out needs
  no query change.
- LLM tool dispatch fills a required Workspace from the LLM's bound
  workspace in buildObjectMethodSelector.
- `dagger call` defaults it to currentWorkspace. The flag is still
  registered, via a new workspaceValue that resolves an address the way
  --dir does, so a caller can point a function at a different workspace;
  it just never gets MarkFlagRequired, which would otherwise reject the
  call before the default could be filled in.

sdkInitArgIsWorkspace becomes modFunctionArg.IsWorkspace, now that more
than one CLI path needs it.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit that referenced this pull request Aug 10, 2026
Workspace arguments on module functions were published as nullable no
matter how they were declared, because the engine injects one when the
caller leaves it unset. That made every signature a lie in the same way
currentModule.asSDK's was before #13845: a function declaring
`ws: Workspace!` advertised an optional argument.

The modules already declared it required — the Go SDK registers a plain
`ws *dagger.Workspace` with no `.WithOptional(true)`, unlike a `+optional`
arg beside it — so this just stops the engine overriding them. A Workspace
declared optional stays nullable and keeps its injection.

Nothing regenerates: both edited files are on the module-runtime path, not
the core schema, so schema.graphqls, the SDK clients and the vendored
toolchain clients are unchanged.

Requiring the argument broke three things, none of which were the wire
type itself:

Discovery. ModTreeNode.Children skips any function with a required
argument, so generators, checks and services taking a workspace stopped
being *found* rather than failing to run — `dagger generate` reported no
generators and wrote nothing, and withScopedGeneration's empty-group
no-op meant `dagger module init` succeeded while leaving a module with no
generated code. The filter already carved out an @agent's required
`base: LLM!`; a Workspace! is the same category, so
functionRequiresArgsExceptAgentBase becomes functionRequiresCallerArgs.

Hand-built selectors. dagql rejects a missing non-null argument in
preselect, before the GetDynamicInput hook that fills workspace args in.
So anything assembling a selector itself has to supply it first: the
generator/check/up leaves in ModTreeNode.DagqlValue, the LLM tool
dispatcher, and the entrypoint proxies — which build their inner
constructor call from what `with` stored, and so failed `dagger call` on
an entrypoint module with `missing required argument: "ws"`.

Required of whom. The shell turns every required argument into a
mandatory positional, so `run <assignment>` became `run <assignment>
<ws>` with no way to name the current workspace. IsRequired stays the
schema truth; IsCallerRequired asks whether the caller must supply it,
which a Workspace never does. That drives both MarkFlagRequired and the
shell's positional split, so `dagger call` and `dagger shell` agree —
each defaulting an unset Workspace to currentWorkspace, and each letting
an explicit one win. `dagger call` still registers the flag, via a new
workspaceValue that resolves an address the way --dir does.

Raw GraphQL is deliberately left explicit: a document omitting the
argument fails validation before reaching the engine, so the dependency
test drives its explicit-workspace case through `dagger call` instead.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit that referenced this pull request Aug 11, 2026
Workspace arguments on module functions were published as nullable no
matter how they were declared, because the engine injects one when the
caller leaves it unset. That made every signature a lie in the same way
currentModule.asSDK's was before #13845: a function declaring
`ws: Workspace!` advertised an optional argument.

The modules already declared it required — the Go SDK registers a plain
`ws *dagger.Workspace` with no `.WithOptional(true)`, unlike a `+optional`
arg beside it — so this just stops the engine overriding them. A Workspace
declared optional stays nullable and keeps its injection.

Nothing regenerates: both edited files are on the module-runtime path, not
the core schema, so schema.graphqls, the SDK clients and the vendored
toolchain clients are unchanged.

What actually needed fixing was never the wire type, but four places that
treat "has required args" as a proxy for "needs something from the
caller".

argRequired already exempts contextual (defaultPath) args on the grounds
that the engine supplies them; a Workspace is the same case, so it joins
them there. That covers the @up and @generate contracts — both of which
document themselves as "callable with no caller-supplied arguments" —
plus @agent and no-arg enumeration, in one place.

Discovery. ModTreeNode.Children skips any function with a required
argument, so generators, checks and services taking a workspace stopped
being *found* rather than failing to run: `dagger generate` reported no
generators and wrote nothing, and withScopedGeneration's empty-group
no-op meant `dagger module init` succeeded while leaving a module with no
generated code. The filter already carved out an @agent's required
`base: LLM!`, so functionRequiresArgsExceptAgentBase becomes
functionRequiresCallerArgs.

Hand-built selectors. dagql rejects a missing non-null argument in
preselect, before the GetDynamicInput hook that fills workspace args in.
So anything assembling a selector itself has to supply it first: the
generator/check/up leaves in ModTreeNode.DagqlValue, the LLM tool
dispatcher, and the entrypoint proxies — which build their inner
constructor call from what `with` stored, and so failed `dagger call` on
an entrypoint module with `missing required argument: "ws"`.

Required of whom. The shell turns every required argument into a
mandatory positional, so `run <assignment>` became `run <assignment>
<ws>` with no way to name the current workspace. IsRequired stays the
schema truth; IsCallerRequired — the CLI-side twin of argRequired — asks
whether the caller must supply it, which a Workspace never does. That
drives both MarkFlagRequired and the shell's positional split, so
`dagger call` and `dagger shell` agree: each defaults an unset Workspace
to currentWorkspace, and each lets an explicit one win. `dagger call`
still registers the flag, via a new workspaceValue that resolves an
address the way --dir does.

Raw GraphQL is deliberately left explicit: a document omitting the
argument fails validation before reaching the engine, so the dependency
test drives its explicit-workspace case through `dagger call` instead.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit that referenced this pull request Aug 18, 2026
…13850)

Workspace arguments on module functions were published as nullable no
matter how they were declared, because the engine injects one when the
caller leaves it unset. That made every signature a lie in the same way
currentModule.asSDK's was before #13845: a function declaring
`ws: Workspace!` advertised an optional argument.

The modules already declared it required — the Go SDK registers a plain
`ws *dagger.Workspace` with no `.WithOptional(true)`, unlike a `+optional`
arg beside it — so this just stops the engine overriding them. A Workspace
declared optional stays nullable and keeps its injection.

Nothing regenerates: both edited files are on the module-runtime path, not
the core schema, so schema.graphqls, the SDK clients and the vendored
toolchain clients are unchanged.

What actually needed fixing was never the wire type, but four places that
treat "has required args" as a proxy for "needs something from the
caller".

argRequired already exempts contextual (defaultPath) args on the grounds
that the engine supplies them; a Workspace is the same case, so it joins
them there. That covers the @up and @generate contracts — both of which
document themselves as "callable with no caller-supplied arguments" —
plus @agent and no-arg enumeration, in one place.

Discovery. ModTreeNode.Children skips any function with a required
argument, so generators, checks and services taking a workspace stopped
being *found* rather than failing to run: `dagger generate` reported no
generators and wrote nothing, and withScopedGeneration's empty-group
no-op meant `dagger module init` succeeded while leaving a module with no
generated code. The filter already carved out an @agent's required
`base: LLM!`, so functionRequiresArgsExceptAgentBase becomes
functionRequiresCallerArgs.

Hand-built selectors. dagql rejects a missing non-null argument in
preselect, before the GetDynamicInput hook that fills workspace args in.
So anything assembling a selector itself has to supply it first: the
generator/check/up leaves in ModTreeNode.DagqlValue, the LLM tool
dispatcher, and the entrypoint proxies — which build their inner
constructor call from what `with` stored, and so failed `dagger call` on
an entrypoint module with `missing required argument: "ws"`.

Required of whom. The shell turns every required argument into a
mandatory positional, so `run <assignment>` became `run <assignment>
<ws>` with no way to name the current workspace. IsRequired stays the
schema truth; IsCallerRequired — the CLI-side twin of argRequired — asks
whether the caller must supply it, which a Workspace never does. That
drives both MarkFlagRequired and the shell's positional split, so
`dagger call` and `dagger shell` agree: each defaults an unset Workspace
to currentWorkspace, and each lets an explicit one win. `dagger call`
still registers the flag, via a new workspaceValue that resolves an
address the way --dir does.

Raw GraphQL is deliberately left explicit: a document omitting the
argument fails validation before reaching the engine, so the dependency
test drives its explicit-workspace case through `dagger call` instead.


Signed-off-by: Tom Chauveau <[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