Repository navigation
feat(schema): require declared Workspace! args on module functions - #13850
Conversation
2f1dcc6 to
b15ab7d
Compare
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]>
b15ab7d to
ee3a854
Compare
|
Trying this to get a sense of the impact: ./hack/dev
./hack/with-dev ./bin/dagger generate dagger-go-sdkI expect to see all the generated clients switch from a But instead the
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: I fixed the 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
left a comment
There was a problem hiding this comment.
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)
| if err := srv.Select(ctx, srv.Root(), &ws, dagql.Selector{ | ||
| Field: "currentWorkspace", | ||
| Args: []dagql.NamedInput{ | ||
| {Name: "skipMigrationCheck", Value: dagql.Boolean(true)}, |
There was a problem hiding this comment.
I don't think this exists anymore
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]>
|
Thanks — both points addressed in c7106f6, plus a related bug your comment led me to.
Workspace modules were silently dropping out of the LLM toolset. Chasing the above, I found if arg.Type.Type().Name() == workspaceTypeName { continue }That never matches — a module function's object args are published as ID scalars, so it reads That's the third variant of the same shape in this change — tree discovery in Re: the regen breakage you hitYour 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:
Same shape as the Agreed the all-or-nothing regen loop is the real pain and is orthogonal to this PR. |

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 incore/schema/module.go). So a function declaringws: Workspace!advertised an optional argument — the same lieasSDKtold before #13845.The modules already declare the truth. The Go SDK registers a plain
ws *dagger.Workspacewith no.WithOptional(true), unlike a// +optionalarg next to it: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 theGetDynamicInputhook that fills workspace args in. So everything that relied on injection for a required arg now puts it on the selector, resolving it the wayloadWorkspaceArgdoes — the workspace an enclosing group bound into the context, else the session's ambient one, and never inherited across a module function boundary.ModTreeNode.DagqlValue, so they're covered in one place, for the root constructor as well as the leaf function.Module.generator(name:), which binds no workspace, so it lands on the ambient fallback, which is what it relied on before.buildObjectMethodSelectorfills a required Workspace from the LLM's bound workspace.dagger call— defaults it tocurrentWorkspace.--wsis still registered, via a newworkspaceValuethat resolves an address the way--dirdoes, so a caller can aim a function at a different workspace. It just never getsMarkFlagRequired, 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
TestRuntimeDependencyDoesNotInheritWorkspaceis 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:
FunctionSpecbuilds the dagqlFieldSpecfor a module's functions at load time, and thecore/schema/module.goblocks were inside thefunctionArg/internalFunctionArgresolvers, 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 moduledagger.gen.gofiles would regenerate byte-identical.Draft: not yet run
Compiles and vets clean for linux, and the integration test typechecks — but nothing here has executed.
coreandcore/integrationcan't build natively on darwin (engine/engineutiluses linux-only syscalls), so this needs a dev engine run before it's reviewable. The generators/checks/up threading and thedagger calldefault-fill are the paths to exercise first.Changie entry still to add.