Skip to content

Fix/nested types reflection - #93

Merged
mjheilmann merged 13 commits into
mainfrom
fix/nested-types-reflection
Nov 14, 2026
Merged

mjheilmann merged 13 commits into
mainfrom
fix/nested-types-reflection

Conversation

@mjheilmann

Copy link
Copy Markdown
Collaborator

fixes #92

Do a wider review of nested message handling, take a TDD approach to fail corner cases and then improve their behaviors.

We are relying on the assumption that the Elixir modules that we are reflecting have been validated and compiled through protoc, so we are not handling invalid states and cases that should have been caught during that process.

mjheilmann and others added 13 commits November 10, 2026 12:28
The grpcurl graph walk matched symbols with regexes that excluded `_`, so in
a snake_case package such as `edge_cases` it listed the service and calls but
never described a single type. Allow `_` in both regexes.

Types can refer back to each other (Request <-> Reply), and the walk had no
stop condition, so it now remembers what it has described. Before, it only
ended because it never followed those references.

Six exact-list assertions encoded the blind spot and now include the types
grpcurl resolves.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Protos for shapes the existing fixtures never exercised, generated with and
without descriptors:

- nested_cross_reference: nested types referenced from a different message,
  used directly as an rpc request, a map value, and never referenced at all
- nested_cycle: a cycle that runs through a nested type
- nested_deep_dependency: a type used only by a message nested three deep
- short_names: single letter and lowercase type names

Also stop skipping nested_self_reference.proto in the descriptor-less pass.
The fixtures are not used by any test yet.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A file's dependencies came from the fields of its message and of the messages
nested one level inside it. A type used only by a message nested two or more
levels down was left out, so a client could not resolve it after loading the
file. Collect fields at every level of nesting.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A nested message or enum is declared in the file of the message that encloses
it, but the builder only knew that when the type was referenced by its own
parent, and not at all without descriptors. Anything else got a standalone
file that declared the wrong symbol, so clients failed with "cannot resolve
type" (grpcurl) or never loaded the file.

Every reference now resolves to the outermost enclosing message, found from
the module name and its `full_name` (new Builder.Nesting). The file registers
every nested symbol it declares, and traces the types nested messages refer to.
This also covers nested types used as an rpc request or response.

Without descriptors nothing records what is nested, so a nesting index built
once over all services tells the synthesizer which nested messages and enums
to embed, and map entries get `options.map_entry` like protoc emits.

Related fixes in the same code:

- resolve dependencies before merging cycles, so a cycle through a nested
  type (First -> Second.Inner -> First) is seen and merged
- derive a file's package by dropping the last segment of its top-level
  symbol, not by guessing which segments are capitalized type names, so `A`
  and `lower` no longer end up in the package
- take an extension file's package from the file it extends

Adds GraphCheck, which link-checks the tree built for every fixture service
the way a client would: dependencies exist, no cycles, every type resolves
through the file or its direct dependencies, every symbol is defined by the
file it maps to.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Finding a nested type's module relies on how protoc-gen-elixir names modules.
When that does not hold, a nested type's fields are not traced and a client
later fails to load the file with an error that points nowhere near the
cause.

- warn when the module for a nested type cannot be found, naming the module
  looked for
- log an error for every file that depends on a file that was never built
  (the symptom, however it came about)

The rest of the tree is still served.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
When a field refers to a nested type we are handed its real module, but only
the outermost message was traced from it. The nested type's own fields were
followed by looking its module up by name, which depends on how
protoc-gen-elixir names modules.

Trace the module we were handed (once per symbol), so every nested type
something reachable refers to is followed whatever its module is called. The
by-name lookup is left for nested types nothing refers to.

The "module not found" warning goes with it: it fired for types that are
traced after all. Test it with hand-built modules that break the convention.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
If a nested type has no findable module and nothing reachable refers to it,
its own references are never followed. The file that declares it then imports
files we never built, and a client cannot load that file at all.

Nothing reachable uses such a type, so drop it from its file instead: remove
it (and what is nested in it) from the descriptor and the symbol index, and
recompute the file's dependencies. A nested type with nothing unresolvable
in it stays. Log a warning naming what was left out and what it refers to.

The error for a file that still depends on a file nobody built stays as the
net for anything else. Its test now builds that case from a descriptor that
mentions a type the message's fields do not.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Modules generated before protoc-gen-elixir recorded `full_name` were never
seen as nested, so a nested type referenced before its enclosing message was
filed on its own, and then registered a second time with the enclosing
message. That raised `Symbols Conflict detected` and failed every
reflection request.

Without a `full_name`, take the parent's descriptor as the record of what it
declares. Module names must agree with it as well, so a module that only
looks nested is not mistaken for one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A group field's type is the atom `:group`, not a module, so following it
raised while building the tree and failed every reflection request. The
group's message is declared inside the enclosing message and is traced with
that message's other nested types.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The package of a nested message's extension file comes from the file that
declares it, not from the name of its enclosing message. Nothing exercised
that: reverting it left the suite green.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A client rejects a symbol that two files define, but GraphCheck only
checked that each symbol's own file defines it, so a nested type served both
inside its enclosing message and as a file of its own passed. GraphCheck now
has tests of its own.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@mjheilmann
mjheilmann merged commit 72e9d38 into main Nov 14, 2026
11 checks passed
@mjheilmann
mjheilmann deleted the fix/nested-types-reflection branch November 14, 2026 15:18
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.

Descriptor-less reflection: nested messages/enums can't be resolved by clients (grpcurl fails)

1 participant