Skip to content

Stop the output schema recursing on a self-referential record - #26

Merged
tamnd merged 1 commit into
mainfrom
fix/schema-cycle
Jul 28, 2026
Merged

tamnd merged 1 commit into
mainfrom
fix/schema-cycle

Conversation

@tamnd

@tamnd tamnd commented Jul 28, 2026

Copy link
Copy Markdown
Owner

schemaForType expanded a struct field of its own type forever. Any domain with a self-referential record (a tweet that quotes a tweet, a comment with replies) took a stack overflow the moment something asked for the output schema, which is serve on startup and mcp on tools/list.

The walk now carries the set of structs open above it and answers the second occurrence with a plain object. The path is what matters rather than every type seen, so two sibling fields of the same type still both expand; there is a test for each.

Found while filling in x-cli's serve and mcp surfaces (tamnd/x-cli#18).

A record type that contains itself is normal: a tweet quotes a tweet, a
comment has replies, a directory entry has children. schemaForType walked
straight into it and the process died with a stack overflow the first time
anything asked for the schema, which is every serve startup and every MCP
tools/list.

The walk now carries the structs open above it and describes the second
occurrence as a plain object. The path is the set that matters, not every
type ever seen: two sibling fields of the same type are not a cycle and
both still expand.
@tamnd
tamnd merged commit 0b492f1 into main Jul 28, 2026
5 of 7 checks passed
@tamnd
tamnd deleted the fix/schema-cycle branch July 28, 2026 15:53
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.

1 participant