Skip to content

feat(schema): add optional workspace arg to asSDK - #13727

Merged
vito merged 8 commits into
dagger:mainfrom
vito:as-sdk-explicit-workspace
Jul 24, 2026
Merged

vito merged 8 commits into
dagger:mainfrom
vito:as-sdk-explicit-workspace

Conversation

@vito

@vito vito commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

What

currentModule.asSDK now takes an optional workspace: Workspace argument and resolves the module's SDK-role data (the modules and clients it manages) against that workspace, instead of reading the ambient current workspace. When the argument is omitted it falls back to the current workspace, so existing callers keep working unchanged.

Why

#13229 disabled workspace inheritance for dependency modules: a module invoked as a dependency no longer inherits its caller's current workspace. But currentModule.asSDK resolved its config by calling CurrentWorkspace(ctx), so the moment an SDK module was driven as a dependency and tried to enumerate its managed modules, it failed with no current workspace: workspace not loaded.

a3679718e1 fixed the same class of failure for the Workspace.generators().run() path by restoring the workspace owner's client context before running codegen. This does the equivalent for the direct/explicit path: rather than reaching for an ambient workspace that dependency modules intentionally can't see, asSDK takes the workspace explicitly. Both callers that reach it already hold one — a dependency is handed it, and a generator run by the framework has it injected.

Making the argument required is the ideal end state, but requiring it up front makes the rollout painful — every SDK that reaches asSDK would have to be updated in lockstep before anything works. So the argument is optional for now, defaulting to the current workspace, with FIXMEs marking the intended end state: make it required and drop the fallback once every caller passes a workspace explicitly.

How

  • asSDK(workspace:) loads the passed workspace (or resolves currentWorkspace when omitted) and reads its config. Reads route through the workspace's own rootfs / owner client, so there is no sandbox concern, and a synthetic (value) workspace that carries config is honored like a detected one.
  • Each asSDK client carries the workspace it was resolved on as a BoundWorkspace, so a client's module source resolves against that workspace rather than the ambient one.
  • Updated the TestSDKGeneratorOwnsClients fixture so its +generate function receives the injected workspace and threads it into AsSDK (now via CurrentModuleAsSDKOpts).
  • Regenerated the SDK and docs goldens. Because the argument is optional, the Go SDK surfaces it as AsSDK(opts ...CurrentModuleAsSDKOpts) and the schema exposes workspace: ID (nullable).

@TomChv TomChv 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.

I'm giving an early approval so we can merge it whenever it's possible.

Next step after:

  • Bump the engine version in CI (optional but it always feel good to see green checks 😸)
  • Merge dagger/go-sdk#14 and replicate the changes on other SDK's.

@vito vito changed the title feat(schema): require workspace arg on asSDK feat(schema): add optional workspace arg to asSDK Jul 24, 2026
@vito
vito force-pushed the as-sdk-explicit-workspace branch from bc7ff8b to 0d52b63 Compare July 24, 2026 16:55
vito added 8 commits July 24, 2026 14:18
currentModule.asSDK read the ambient current workspace to resolve the
module's SDK-role config. Disabling workspace inheritance for dependency
modules makes that ambient workspace unavailable: a module driven as a
dependency no longer inherits its caller's workspace, so asSDK failed
with "no current workspace" the moment such a module tried to enumerate
its managed modules.

Take the workspace as an explicit, required argument and resolve
SDK-role data against it. Config reads route through that workspace's
own rootfs or owner client, so there is no sandbox concern, and a
synthetic workspace that carries config is honored like a detected one.
Both callers that reach asSDK already hold the workspace to pass: a
dependency receives it explicitly, and a generator run by the framework
has it injected.

Thread the injected workspace through the TestSDKGeneratorOwnsClients
fixture's generate function into AsSDK so it keeps resolving its clients.

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
currentModuleAsSDKClientModuleSource resolved a client's module against
the session's ambient current workspace. A module driven as a dependency
no longer has one, and a workspace carrying overlay edits would resolve
against stale content.

Carry the workspace asSDK was called on as a BoundWorkspace on each
CurrentModuleAsSDKClient — a full object result, so it represents overlay
and synthetic workspaces, not just client-bound ones — and resolve the
client's module source against it. The workspace is persisted by result
id and re-attached on decode, so a reloaded client still resolves against
the right workspace, matching how generator and check groups carry theirs.

Extend TestSDKGeneratorOwnsClients to bind a client to a local module and
resolve its source, exercising the resolver end to end.

Signed-off-by: Alex Suraci <[email protected]>
Making Workspace a required argument on currentModule.asSDK is the ideal
end state, but requiring it up front makes the rollout painful: every SDK
that reaches asSDK has to be updated in lockstep before anything works.

Accept the workspace as an optional argument for now. When it is omitted,
fall back to resolving the ambient current workspace, exactly as asSDK did
before the argument existed, so existing callers keep working untouched.
The fallback selects currentWorkspace to get an ObjectResult, so the bound
workspace carried on each client is still populated for module-source
resolution. FIXMEs mark the intended end state: make the argument required
and drop the fallback once every caller passes a workspace explicitly.

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the as-sdk-explicit-workspace branch from 0d52b63 to 57046f0 Compare July 24, 2026 18:51
@vito
vito merged commit 611626b into dagger:main Jul 24, 2026
87 checks passed
TomChv added a commit to dagger/typescript-sdk that referenced this pull request Jul 27, 2026
Mirrors dagger/go-sdk#14, pairs with dagger/dagger#13727.

`currentModule.asSDK` now takes an explicit workspace argument instead of implicitly resolving against the current workspace, so modules(ws) resolves its SDK-managed module list against the workspace it was actually handed.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit to dagger/python-sdk that referenced this pull request Jul 27, 2026
dagger/dagger#13727 added an optional `workspace` argument to
`currentModule.asSDK`, so the SDK-role data resolves against an explicitly
passed workspace instead of the ambient current workspace — which dependency
modules cannot see since workspace inheritance was disabled.

Use it instead of the `ws.sdk(name: currentModule.name)` workaround: looking the
SDK up by module entry name only worked by coincidence of the entry being named
after the module, and it read the workspace's SDK list rather than the current
module's own as-sdk role.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit that referenced this pull request Aug 6, 2026
currentModule.asSDK took the workspace as an optional argument and fell
back to the ambient current workspace when omitted. That was a stopgap:
#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 #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]>
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