Skip to content

feat(schema): require declared Workspace! args on module functions - #13850

Merged
TomChv merged 2 commits into
mainfrom
feat/require-workspace-on-module-functions
Aug 18, 2026
Merged

TomChv merged 2 commits into
mainfrom
feat/require-workspace-on-module-functions

Conversation

@TomChv

@TomChv TomChv commented Aug 6, 2026

Copy link
Copy Markdown
Member

Follows #13845, which made currentModule.asSDK's workspace argument required. This does the same for module functions.

Problem

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 (core/typedef.go, plus two spots in core/schema/module.go). So a function declaring ws: Workspace! advertised an optional argument — the same lie asSDK told before #13845.

The modules already declare the truth. The Go SDK registers a plain ws *dagger.Workspace with no .WithOptional(true), unlike a // +optional arg next to it:

// .dagger/modules/engine-dev/dagger.gen.go
WithArg("ws", dag.TypeDef().WithObject("Workspace"), ...).
WithArg("clientDockerConfig", dag.TypeDef().WithObject("Secret").WithOptional(true), ...).

The engine was overriding that. This stops the override.

Why the callers had to change

The injection can't 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 everything that relied on injection for a required arg now puts it on the selector, resolving it the 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.

  • generators, checks, up — all funnel through ModTreeNode.DagqlValue, so they're covered in one place, for the root constructor as well as the leaf function.
  • scale-out — needs no query change. It selects Module.generator(name:), which binds no workspace, so it lands on the ambient fallback, which is what it relied on before.
  • LLM tools — buildObjectMethodSelector fills a required Workspace from the LLM's bound workspace.
  • dagger call — defaults it to currentWorkspace. --ws is still registered, via a new workspaceValue that resolves an address the way --dir does, so a caller can aim a function at a different workspace. It just never gets MarkFlagRequired, which would otherwise reject the call before the default could be filled in.

An argument declared optional is unaffected: it stays nullable and keeps its injection. That's why TestRuntimeDependencyDoesNotInheritWorkspace is untouched — its fixture declares // +optional, so the #13229 isolation behavior and error message are unchanged.

No codegen

Deliberately none. Both edited files are on the module-runtime path, not the core schema: FunctionSpec builds the dagql FieldSpec for a module's functions at load time, and the core/schema/module.go blocks were inside the functionArg/internalFunctionArg resolvers, mutating the value they return rather than the schema shape. schema.graphqls, the SDK clients, the reference docs and the vendored toolchain clients are all unchanged, and module dagger.gen.go files would regenerate byte-identical.

Draft: not yet run

Compiles and vets clean for linux, and the integration test typechecks — but nothing here has executed. core and core/integration can't build natively on darwin (engine/engineutil uses linux-only syscalls), so this needs a dev engine run before it's reviewable. The generators/checks/up threading and the dagger call default-fill are the paths to exercise first.

Changie entry still to add.

@TomChv
TomChv force-pushed the feat/require-workspace-on-module-functions branch 2 times, most recently from 2f1dcc6 to b15ab7d Compare August 10, 2026 13:40
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
TomChv force-pushed the feat/require-workspace-on-module-functions branch from b15ab7d to ee3a854 Compare August 11, 2026 10:56
@TomChv
TomChv marked this pull request as ready for review August 11, 2026 13:59
@TomChv
TomChv requested a review from vito August 11, 2026 16:04
@vito

vito commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Trying this to get a sense of the impact:

./hack/dev
./hack/with-dev ./bin/dagger generate dagger-go-sdk

I expect to see all the generated clients switch from a *Opts arg to a required Workspace arg, and for callers to break.

But instead the generate itself breaks: https://dagger.cloud/dagger/traces/e895ec6ca958ff77a46d2472f8ddd679?listen=d89b63a295a1236d&listen=02ff046daba969a1&listen=b47d5d637422afe4&listen=557a313e8d354846#8f1c5d8edd0e13a9

image

The TUI annoyingly doesn't surface the root cause - will have to chase that down, could have sworn we fixed that just recently already but maybe there's something unique about this case:

dagger-dev generate dagger-go-sdk
TRACE  ✘ FAILED
dagger generate dagger-go-sdk  2m3s
! failed to run codegen: failed to load dependencies as modules: failed to load module dependencies: failed to call module "engine-dev" to get functions: call constructor: exit code: 1

GENERATORS  ✘ 1 failed  ✔ 1 passed
✘ dagger-go-sdk:generate 1m59s ERROR
  GENERATORS  ✘ 1 failed
    ✘ dagger-dang-sdk:generate 16.5s ERROR
      ∅ DaggerDangSdk.generate(
        ┆ ws: Workspace.__withGeneratedLocalDependencies(
        ┆ ┆ module: ".dagger/modules/go-client-dev"
        ┆ ┆ changes: Directory.generateLocalDependencies(
        ┆ ┆ ┆ workspace: currentWorkspace: Workspace!
        ┆ ┆ ): Changeset!
        ┆ ): Workspace!
        ): Changeset! 16.5s
      ! context canceled
✔ dagger-go-sdk:generate-all-client 13.9s OK
Error: failed to run codegen: failed to load dependencies as modules: failed to load module dependencies: failed to call module "engine-dev" to get functions: call constructor: exit code: 1

I fixed the CodegenOpts case, which reveals another failure - but at least this one surfaced properly:

TRACE  ✘ FAILED
dagger generate dagger-go-sdk  1m55s
! failed to run codegen: failed to load dependencies as modules: failed to load module dependencies: failed to call module "python-client-dev" to get functions: call constructor: exit code: 1

GENERATORS  ✘ 1 failed  ✔ 1 passed
✘ dagger-go-sdk:generate 1m52s ERROR
  ✘ withExec go build -ldflags '-s -w' -o /runtime . 0.2s ERROR
  ┃ # dagger/python-client-dev
  ┃ ./main.go:59:34: cannot use dagger.DaggerEngineOpts{…} (value of struct type dagger.DaggerEngineOpts) as *dagger.Workspace value in argument to dag.DaggerE
  ┃ e
  ┃ ./main.go:61:4: unknown field Ws in struct literal of type dagger.DaggerEngineOpts
  ┃ ./main.go:197:52: cannot use dagger.DaggerEngineOpts{…} (value of struct type dagger.DaggerEngineOpts) as *dagger.Workspace value in argument to dag.Dagger
  ┃ ne
  ┃ ./main.go:197:76: unknown field Ws in struct literal of type dagger.DaggerEngineOpts
  ! exit code: 1
  GENERATORS  ✔ 1 passed
    ✔ dagger-dang-sdk:generate 8.0s OK
✔ dagger-go-sdk:generate-all-client 10.5s OK

The UX for this sort of change feels pretty rough atm - and afaict it's the same pain you'd feel with any API change within your module dependencies. Not really related to this PR, but maybe something to think about more. It would be nice if I could save what was able to re-generate instead of it being all-or-nothing. Right now I have to learn each failure one-by-one and write code that doesn't compile until all of the regens succeed.

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice - yeah this seems to strike the right balance:

  • CLI and shell still auto-supply Workspace - more responsibility but looks like it was trivial to support
  • GraphQL queries still require you to pass it, but entrypoint functions don't (their into auto-constructor-call passes it), which should cover all the ground we care about
  • SDKs have it required (the whole point)

Comment thread core/workspace_context.go Outdated
if err := srv.Select(ctx, srv.Root(), &ws, dagql.Selector{
Field: "currentWorkspace",
Args: []dagql.NamedInput{
{Name: "skipMigrationCheck", Value: dagql.Boolean(true)},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this exists anymore

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, I fixed it

Two follow-ups from review.

currentWorkspace takes no arguments — the skipMigrationCheck one this
copied from loadWorkspaceArg no longer exists. dagql ignores a selector
arg that isn't in the field spec rather than rejecting it, so it was
silently doing nothing. (core/modfunc.go still passes it too, left alone
here as it predates this change.)

bindWorkspaceModuleTools decided constructibility with
`arg.Type.Type().Name() == workspaceTypeName`, which never matches: a
module function's object args are published as ID scalars, so that reads
"ID". The branch was dead but harmless while workspace args were
nullable, because the !NonNull check above caught them first. Making them
required removed that cover, so a module whose constructor takes a
Workspace! was silently dropped from the LLM's toolset.

Extract inputSpecIsWorkspace, which checks the @expectedType directive —
the only place the object type survives on an input spec — and use it
for both that check and boundWorkspaceInput.

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv

TomChv commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

Thanks — both points addressed in c7106f6, plus a related bug your comment led me to.

skipMigrationCheck — you're right, currentWorkspace takes no arguments. dagql ignores a selector arg that isn't in the field spec rather than rejecting it, so it was silently a no-op, which is why nothing caught it. Removed. Worth noting core/modfunc.go:1281 passes the same dead argument — that predates this PR so I've left it, but it's where I copied from, so it'll get copied again.

Workspace modules were silently dropping out of the LLM toolset. Chasing the above, I found bindWorkspaceModuleTools deciding constructibility with:

if arg.Type.Type().Name() == workspaceTypeName { continue }

That never matches — a module function's object args are published as ID scalars, so it reads "ID". The branch was dead but harmless while workspace args were nullable, because the !NonNull check above it caught them first. Making them required removed that cover, so any module with a Workspace! constructor became "not constructible" and vanished from the agent's tools. Now uses the @expectedType directive, which is the only place the object type survives on an input spec.

That's the third variant of the same shape in this change — tree discovery in ModTreeNode.Children, the @up/@generate validators, and now this — all treating "has required args" as a proxy for "needs caller input". The engine now says it once in argRequired (alongside contextual args, for the same reason) and the CLI once in IsCallerRequired.

Re: the regen breakage you hit

Your ./hack/dev run is a preview of post-release, not a state CI reaches. The generate checks here regenerate module bindings with the released engine, which still publishes workspace args as nullable — so Ws stays inside the opts structs and the existing .dagger/modules/* sources compile unchanged. That's why dagger-go-sdk:generate and engine-dev:generate are green on this PR despite the change being in.

So there's a migration owed, but it's dated to the release rather than to this merge, and the two halves have to land together:

  • ~30 call sites across 11 modules (engine-dev, release, cli-dev, docs-dev, and the *-client-dev set) move the workspace out of the opts struct into a positional — dag.Go(dagger.GoOpts{Source: s, Ws: w}) becomes dag.Go(w, dagger.GoOpts{Source: s})
  • the regenerated internal/dagger/<dep>.gen.go bindings, in the same commit, since neither half compiles alone

Same shape as the AsSDK call-site migration in #13845 — except that one needed no coordination because the SDK modules had already been updated. This one hasn't been paid for yet. Happy to open a follow-up issue to track it if that's useful.

Agreed the all-or-nothing regen loop is the real pain and is orthogonal to this PR.

@TomChv
TomChv merged commit ea290ad into main Aug 18, 2026
88 checks passed
@TomChv
TomChv deleted the feat/require-workspace-on-module-functions branch August 18, 2026 12:34
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