Skip to content

fix(dang): correct namespaced type-name mangling; cross-dependency interface dispatch - #13377

Merged
vito merged 14 commits into
mainfrom
fix-dang-sdk-namespacing
Jun 10, 2026
Merged

vito merged 14 commits into
mainfrom
fix-dang-sdk-namespacing

Conversation

@vito

@vito vito commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes a Dang SDK namespacing bug and adds cross-dependency interface support.

strcase.ToCamel (gqlObjectName) is not idempotent: re-applying it to an already-final, module-namespaced type name lowercases word boundaries, so a namespaced interface that should be ModuleAOverlay came back as ModuleAoverlay. The corruption stayed hidden because the mangled names were ToCamel fixed-points, so the round-trips that rebuild a typedef from its name were accidentally idempotent — until a name that isn't a fixed point (a module whose camelCased name ends in a lone capital abutting a PascalCase subtype, e.g. moduleA + Overlay) flows through.

This keeps the existing collapsed naming convention (ModuleAOverlay) and fixes it at the layer where it breaks: every path that rebuilds a typedef from an already-final type name now preserves that name verbatim instead of running it back through ToCamel.

(An earlier revision of this branch standardized on an underscore separator — ModuleA_Overlay — for namespace hygiene, but that required fixing a long tail of ToCamel-on-namespaced-name sites across the engine, CLI, and interpreter, so it was dropped from this PR's scope. Some comments still use ModuleA_Overlay as an illustrative example.)

closes #13364

What's here

Preserve already-final type names (the core fix):

  • The internal __withName setters (object/interface/enum typedefs) store names verbatim; raw SDK names are still normalized once at creation (NewObjectTypeDef etc.).
  • InterfaceType.Install uses the name as-is, matching how objects install (ModuleObject.TypeDefinition).
  • Typedef-reconstruction paths go through a new SelectReferenceTypeDef helper: {Interface,ModuleObject,ModuleEnum}Type.TypeDef, the ModTypeFor lookups in interface.go, and — the best-hidden site — introspectionRefToTypeDef/resolveIDScalar in coremod.go, which rebuild the Query typedef from live schema introspection (a module's main-object functions promoted onto the Query root) and were re-collapsing enum/object/interface/scalar references. That surfaced as arguments resolving to empty-member stubs (e.g. a Dang module's enum flag showing no valid values).

Dang cross-dependency interface dispatch (self-calls run path):

  • The interpreted runtime resolves its own types by name against the runtime schema, so it needs self-calls to invoke a method on an interface value received across a dependency boundary. A single ModuleSource.SelfCallsEnabled() predicate covers both the SELF_CALLS flag and an always-on SDK capability that the Dang SDK opts into (persisted so cached module sources stay enabled). Routing both paths through one predicate keeps them consistent — an inconsistency would let a module's own types be both installed and rejected as duplicates.
  • The eager asModule in runCodegen stays gated on the explicit flag, since it type-checks the source purely to feed code generation and must not run for SDKs (like Dang) whose codegen is a no-op — otherwise dagger init/install fails on uninitialized or not-yet-installed-dependency source.
  • At runtime the interpreter maps module-local type names to their namespaced schema names when building node(id) queries, falling back to the local name for types already present (e.g. dependency types).

Tests

The full TestDang integration suite passes on the dev engine — enums, mismatch, core-type shadowing, and a new cross-dependency structural-interface run-path test (consume structural interface value across dependencies, asserting only that the run succeeds). Go SDK self-calls and the SDK-capability persistence are covered, and go test ./core ./core/schema is green.

🤖 Generated with Claude Code

@vito
vito requested review from a team as code owners June 9, 2026 13:29
@vito
vito force-pushed the fix-dang-sdk-namespacing branch 2 times, most recently from 3757a0a to 7220688 Compare June 9, 2026 18:48
@vito vito changed the title fix: namespace Dang module types with underscore separator fix(dang): correct namespaced type-name mangling; cross-dependency interface dispatch Jun 9, 2026
@vito vito added this to the v0.21.5 milestone Jun 9, 2026
vito and others added 12 commits June 10, 2026 12:10
The internal __withName setters and the typedef reconstruction paths
re-ran strcase.ToCamel on names that were already final and module-
namespaced. ToCamel is not idempotent: when a module name ends in a lone
capital (moduleA -> ModuleA) abutting a PascalCase subtype, a second
pass lowercased the boundary, turning "ModuleAOverlay" into
"ModuleAoverlay". The corruption stayed hidden because the mangled names
were ToCamel fixed-points, so the round-trips that rebuild a typedef
from a type's name were accidentally idempotent.

Store __withName names verbatim (raw SDK names are still normalized at
creation via withObject/withInterface), stop the interface install path
from re-normalizing, and route the reconstruction sites
(ModType.TypeDef and the ModTypeFor lookups in interface.go) through a
helper that keeps the already-final name.

Signed-off-by: Alex Suraci <[email protected]>
currentTypeDefs rebuilds the Query typedef from live schema
introspection, reconstructing each enum/object/interface/scalar reference
with a bare withEnum/withObject/withInterface/withScalar selector. Those
constructors run the name through strcase.ToCamel, which is not
idempotent: an already-final, module-namespaced name like
"TestEnum_Status" collapses to "TestEnumStatus". The collapsed reference
then diverges from the served definition, so consumers that resolve it by
name -- the CLI building arg flags, cross-module dispatch -- find an empty
stub instead of the real type. This is what broke Dang modules' enum,
object, and interface references once the namespace separator was kept.

Route these reconstructions through SelectReferenceTypeDef, which
preserves the final name verbatim, matching the fix already applied to the
other typedef-reconstruction sites. resolveIDScalar gets the same
treatment for the @expectedType directive's object/interface names. A new
SelectReferenceTypeDefWithServer variant lets these run against the
module's dependency schema rather than the current call's server.

Signed-off-by: Alex Suraci <[email protected]>
Self-calls could only be turned on via the SELF_CALLS experimental flag,
but the interpreted Dang SDK always needs them: it resolves its own types
by name against the runtime schema, so a module's own types must be
present in the schema it queries (e.g. to call a method on an interface
value received across a dependency).

Add a single ModuleSource.SelfCallsEnabled predicate that is true when the
flag is set or the SDK reports the new AlwaysEnablesSelfCalls capability,
and route every call site through it; the Dang SDK opts in. Routing both
paths through one predicate keeps them consistent -- an inconsistency
would let a module's own types be both installed and rejected as
duplicates. The eager asModule in runCodegen stays gated on the explicit
flag, since it type-checks the source purely to feed code generation and
must not run for SDKs (like Dang) whose codegen is a no-op.

Signed-off-by: Alex Suraci <[email protected]>
A Dang module's own types are local in its source (e.g. an interface
"Overlay") but module-namespaced in the schema it queries against
("ModuleA_Overlay"). When marshaling a received interface value into a
runtime node query, the interpreter referenced the local name, so the
query and its inline fragment named a type that does not exist in the
schema and the cross-dependency call failed.

Thread the executing module's name through the eval context and resolve
local type names to their namespaced schema names when building node
queries, falling back to the local name for types already present (e.g.
dependency types). NamespaceObject is exported from core so the runtime
can reuse the engine's namespacing rule rather than duplicating it.

Signed-off-by: Alex Suraci <[email protected]>
Add a subtest that calls a Dang module which receives a structural
interface value across a dependency boundary and invokes a method on it,
asserting only that the run succeeds. The test-interface module now
implements Dep_Greeter, the namespaced name of the dependency's Greeter
interface under the underscore convention.

Signed-off-by: Alex Suraci <[email protected]>
Record whether an SDK always enables self calls in ModuleSource persistence and
replay that capability through the lazy SDK wrapper. This keeps Dang module
sources self-call enabled after they are reloaded from cache.

Signed-off-by: Alex Suraci <[email protected]>
Keep the Dang integration test independent of shared module test helpers by
using local Dang-specific module init helpers. This avoids compile failures in
runs that do not include the generic helper definitions.

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
withFinalTypeName preserved already-final names for object, interface,
and enum typedefs but fell through to a silent no-op for scalars, even
though SelectReferenceTypeDef is used with withScalar (e.g. in
coremod.go's Query rebuild). A reconstructed scalar reference therefore
kept the strcase.ToCamel'd name, diverging from the served scalar when
the namespaced name is not a ToCamel fixed-point — a module whose
camelCased name ends in a lone capital, e.g. module-a's "ModuleAToken"
collapsing to "ModuleAtoken".

Add a verbatim ScalarTypeDef.WithName plus its __withName field and a
scalar case in withFinalTypeName. The divergence was harmless in
practice — custom scalars are opaque, so unlike enums and objects they
carry no members or fields to resolve by name — but the helper was
dishonest and a footgun for future callers. A Dang integration test
covers a namespaced custom scalar argument.

Signed-off-by: Alex Suraci <[email protected]>
An earlier revision of this branch standardized type namespacing on an
underscore separator (ModuleA_Overlay), but that was dropped; the
collapsed form (ModuleAOverlay) is what the engine serves. Update the
lingering underscore examples in the runtime type-name mapping comments
to match.

Signed-off-by: Alex Suraci <[email protected]>
withFinalTypeName's scalar case (added so SelectReferenceTypeDef stays
correct for every kind, including coremod.go's withScalar reconstruction)
cannot be exercised yet: Dagger modules don't expose custom scalars as
distinct module-namespaced types. A Dang `scalar Foo` resolves to String,
and the only scalars in a schema are core ones whose names are already
strcase.ToCamel fixed-points, so there is no manglable namespaced scalar
to preserve.

Drop the integration test and fixture that appeared to cover this but in
fact passed regardless of the fix, and document the branch as speculative
so the plumbing is kept for when module-defined custom scalars land.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the fix-dang-sdk-namespacing branch from 4890938 to 3433f96 Compare June 10, 2026 12:22
vito added 2 commits June 10, 2026 12:34
The runtime needs the executing module's name to map the module's own local
type names to the namespaced names its schema exposes, but that name was being
smuggled through context.Context, which read as a smell. Move the
value-marshaling helpers onto a dangConverter that carries the resolution scope
and the module identity, so the name is passed explicitly and context.Context
is back to carrying only cancellation and telemetry.

The conversion helpers were a cohesive cluster that all threaded the same
(ctx, env) pair, so making them methods also sheds the repeated env argument.
Behavior is unchanged and the change is confined to Dang v2; v1 stays frozen.

Signed-off-by: Alex Suraci <[email protected]>
The converter only ever marshals values for a live function call, whose
moduleContext is a populated ObjectResult, so Self() is never nil and the
module always has a name. The nil check in eval and the known() fallback in
schemaTypeName could therefore never fire; remove them so the module identity
is built and namespaced unconditionally. Confined to Dang v2.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito merged commit a3adf05 into main Jun 10, 2026
79 checks passed
@vito
vito deleted the fix-dang-sdk-namespacing branch June 10, 2026 13:02
marcosnils pushed a commit that referenced this pull request Jun 10, 2026
…terface dispatch (#13377)

* fix(core): preserve final type names when rebuilding typedefs

The internal __withName setters and the typedef reconstruction paths
re-ran strcase.ToCamel on names that were already final and module-
namespaced. ToCamel is not idempotent: when a module name ends in a lone
capital (moduleA -> ModuleA) abutting a PascalCase subtype, a second
pass lowercased the boundary, turning "ModuleAOverlay" into
"ModuleAoverlay". The corruption stayed hidden because the mangled names
were ToCamel fixed-points, so the round-trips that rebuild a typedef
from a type's name were accidentally idempotent.

Store __withName names verbatim (raw SDK names are still normalized at
creation via withObject/withInterface), stop the interface install path
from re-normalizing, and route the reconstruction sites
(ModType.TypeDef and the ModTypeFor lookups in interface.go) through a
helper that keeps the already-final name.

Signed-off-by: Alex Suraci <[email protected]>

* fix(core): keep final type names in Query rebuild

currentTypeDefs rebuilds the Query typedef from live schema
introspection, reconstructing each enum/object/interface/scalar reference
with a bare withEnum/withObject/withInterface/withScalar selector. Those
constructors run the name through strcase.ToCamel, which is not
idempotent: an already-final, module-namespaced name like
"TestEnum_Status" collapses to "TestEnumStatus". The collapsed reference
then diverges from the served definition, so consumers that resolve it by
name -- the CLI building arg flags, cross-module dispatch -- find an empty
stub instead of the real type. This is what broke Dang modules' enum,
object, and interface references once the namespace separator was kept.

Route these reconstructions through SelectReferenceTypeDef, which
preserves the final name verbatim, matching the fix already applied to the
other typedef-reconstruction sites. resolveIDScalar gets the same
treatment for the @expectedType directive's object/interface names. A new
SelectReferenceTypeDefWithServer variant lets these run against the
module's dependency schema rather than the current call's server.

Signed-off-by: Alex Suraci <[email protected]>

* feat(core): unify self-calls enablement check

Self-calls could only be turned on via the SELF_CALLS experimental flag,
but the interpreted Dang SDK always needs them: it resolves its own types
by name against the runtime schema, so a module's own types must be
present in the schema it queries (e.g. to call a method on an interface
value received across a dependency).

Add a single ModuleSource.SelfCallsEnabled predicate that is true when the
flag is set or the SDK reports the new AlwaysEnablesSelfCalls capability,
and route every call site through it; the Dang SDK opts in. Routing both
paths through one predicate keeps them consistent -- an inconsistency
would let a module's own types be both installed and rejected as
duplicates. The eager asModule in runCodegen stays gated on the explicit
flag, since it type-checks the source purely to feed code generation and
must not run for SDKs (like Dang) whose codegen is a no-op.

Signed-off-by: Alex Suraci <[email protected]>

* fix(dang): map local type names to schema names

A Dang module's own types are local in its source (e.g. an interface
"Overlay") but module-namespaced in the schema it queries against
("ModuleA_Overlay"). When marshaling a received interface value into a
runtime node query, the interpreter referenced the local name, so the
query and its inline fragment named a type that does not exist in the
schema and the cross-dependency call failed.

Thread the executing module's name through the eval context and resolve
local type names to their namespaced schema names when building node
queries, falling back to the local name for types already present (e.g.
dependency types). NamespaceObject is exported from core so the runtime
can reuse the engine's namespacing rule rather than duplicating it.

Signed-off-by: Alex Suraci <[email protected]>

* test(dang): cover cross-dep interface dispatch

Add a subtest that calls a Dang module which receives a structural
interface value across a dependency boundary and invokes a method on it,
asserting only that the run succeeds. The test-interface module now
implements Dep_Greeter, the namespaced name of the dependency's Greeter
interface under the underscore convention.

Signed-off-by: Alex Suraci <[email protected]>

* fix(core): persist SDK self-call capability

Record whether an SDK always enables self calls in ModuleSource persistence and
replay that capability through the lazy SDK wrapper. This keeps Dang module
sources self-call enabled after they are reloaded from cache.

Signed-off-by: Alex Suraci <[email protected]>

* test(dang): use local init helpers

Keep the Dang integration test independent of shared module test helpers by
using local Dang-specific module init helpers. This avoids compile failures in
runs that do not include the generic helper definitions.

Signed-off-by: Alex Suraci <[email protected]>

* ununderscore

Signed-off-by: Alex Suraci <[email protected]>

* test(dang): switch to fixture for cross-dep test

Signed-off-by: Alex Suraci <[email protected]>

* fix(core): preserve final type names for scalars too

withFinalTypeName preserved already-final names for object, interface,
and enum typedefs but fell through to a silent no-op for scalars, even
though SelectReferenceTypeDef is used with withScalar (e.g. in
coremod.go's Query rebuild). A reconstructed scalar reference therefore
kept the strcase.ToCamel'd name, diverging from the served scalar when
the namespaced name is not a ToCamel fixed-point — a module whose
camelCased name ends in a lone capital, e.g. module-a's "ModuleAToken"
collapsing to "ModuleAtoken".

Add a verbatim ScalarTypeDef.WithName plus its __withName field and a
scalar case in withFinalTypeName. The divergence was harmless in
practice — custom scalars are opaque, so unlike enums and objects they
carry no members or fields to resolve by name — but the helper was
dishonest and a footgun for future callers. A Dang integration test
covers a namespaced custom scalar argument.

Signed-off-by: Alex Suraci <[email protected]>

* docs(dang): fix namespaced-name examples in comments

An earlier revision of this branch standardized type namespacing on an
underscore separator (ModuleA_Overlay), but that was dropped; the
collapsed form (ModuleAOverlay) is what the engine serves. Update the
lingering underscore examples in the runtime type-name mapping comments
to match.

Signed-off-by: Alex Suraci <[email protected]>

* core: mark scalar typedef rename as speculative

withFinalTypeName's scalar case (added so SelectReferenceTypeDef stays
correct for every kind, including coremod.go's withScalar reconstruction)
cannot be exercised yet: Dagger modules don't expose custom scalars as
distinct module-namespaced types. A Dang `scalar Foo` resolves to String,
and the only scalars in a schema are core ones whose names are already
strcase.ToCamel fixed-points, so there is no manglable namespaced scalar
to preserve.

Drop the integration test and fixture that appeared to cover this but in
fact passed regardless of the fix, and document the branch as speculative
so the plumbing is kept for when module-defined custom scalars land.

Signed-off-by: Alex Suraci <[email protected]>

* dang: marshal call values via a converter struct

The runtime needs the executing module's name to map the module's own local
type names to the namespaced names its schema exposes, but that name was being
smuggled through context.Context, which read as a smell. Move the
value-marshaling helpers onto a dangConverter that carries the resolution scope
and the module identity, so the name is passed explicitly and context.Context
is back to carrying only cancellation and telemetry.

The conversion helpers were a cohesive cluster that all threaded the same
(ctx, env) pair, so making them methods also sheds the repeated env argument.
Behavior is unchanged and the change is confined to Dang v2; v1 stays frozen.

Signed-off-by: Alex Suraci <[email protected]>

* dang: drop unreachable module-identity guard

The converter only ever marshals values for a live function call, whose
moduleContext is a populated ObjectResult, so Self() is never nil and the
module always has a name. The nil check in eval and the known() fallback in
schemaTypeName could therefore never fire; remove them so the module identity
is built and namespaced unconditionally. Confined to Dang v2.

Signed-off-by: Alex Suraci <[email protected]>

---------

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
dagger 0.21.5

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## v0.21.5 - 2026-06-10

### Added

- Added expand option to container.exists by @alexcb in dagger/dagger#13310
- Support both Dang v1 and v2, routed by module engineVersion by @vito in dagger/dagger#13388

### Changed

- Prune local cache during disk pressure by @sipsma in dagger/dagger#13375
- Persist trivial core objects by @sipsma in dagger/dagger#13387

### Fixed

- Correct namespaced type-name mangling and cross-dependency interface dispatch in Dang by @vito in dagger/dagger#13377
- Surface exec errors correctly on the Bun runtime in the TypeScript SDK by @marcosnils in dagger/dagger#13395
- Ignore host xattrs for local filesync import identity by @sipsma in dagger/dagger#13389
- Don't shallow-clone the user's repo for git telemetry labels by @marcosnils in dagger/dagger#13363
- Preserve pending lazy container parents by @sipsma in dagger/dagger#13365
- Preserve withChanges parent layers by @dagger-codex[bot] + @shykes in dagger/dagger#13342
- Treat incomplete image metadata as cache miss by @sipsma in dagger/dagger#13346
- Cache registry image metadata by @dagger-codex[bot] + @shykes in dagger/dagger#13341
- Don't require id field for interface conformance in Dang by @vito in dagger/dagger#13318
- Use module-local check names for scale-out by @dagger-codex[bot] + @tiborvass in dagger/dagger#13329
- Fix snapshot owner lease attach/remove race by @sipsma in dagger/dagger#13321
- Follow source symlinks when copying directory contents in layercopy by @marcosnils in dagger/dagger#13326

### What to do next?

- Read the [documentation](https://docs.dagger.io)
- Join our [Discord server](https://discord.gg/dagger-io)
- Follow us on [Twitter](https://twitter.com/dagger_io)

</pre>
  <p>View the full release notes at <a href="https://github.com/dagger/dagger/releases/tag/v0.21.5">https://github.com/dagger/dagger/releases/tag/v0.21.5</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!11205
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