fix(acp): break self-referential $ref cycles before Code Mode schema - #10469
Merged
lifeizhou-ap merged 1 commit intoJul 15, 2026
Merged
Conversation
…codegen
pctx_code_mode eagerly converts every registered tool's JSON Schema into a
TypeScript type signature by following $refs through the schema's
$defs/definitions map. That walk (pctx_codegen::SchemaType::type_signature)
has no cycle detection or depth limit, so a self-referential schema -- e.g.
the generic "any JSON value" $defs entry some MCP servers (FastMCP/Pydantic)
emit via additionalProperties: {"$ref": "#/$defs/Any"} -- recurses forever
and aborts the whole goose serve process with a stack overflow the moment
such a tool is registered with the Code Mode extension enabled.
Sanitize tool input/output schemas before handing them to pctx: build the
$defs reference graph, detect cycles, and neutralize the specific $refs that
close a cycle with a permissive `{}` schema. This keeps pctx's recursion
finite regardless of what an external MCP server sends, at the cost of type
precision on the rare malformed/recursive branch only.
Fixes aaif-goose#10256
Abhijay007
requested review from
DOsinga,
The-Best-Codes,
alexhancock and
lifeizhou-ap
July 14, 2026 20:06
The-Best-Codes
approved these changes
Jul 14, 2026
lifeizhou-ap
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10256
Summary
pctx_code_mode eagerly converts every registered tool's JSON Schema into a TypeScript type signature by following $refs through the schema's $defs/definitions map. That walk (pctx_codegen::SchemaType::type_signature) has no cycle detection or depth limit, so a self-referential schema -- e.g. the generic "any JSON value" $defs entry some MCP servers (FastMCP/Pydantic) emit via additionalProperties: {"$ref": "#/$defs/Any"} -- recurses forever and aborts the whole goose serve process with a stack overflow the moment such a tool is registered with the Code Mode extension enabled.
Sanitize tool input/output schemas before handing them to pctx: build the $defs reference graph, detect cycles, and neutralize the specific $refs that close a cycle with a permissive
{}schema. This keeps pctx's recursion finite regardless of what an external MCP server sends, at the cost of type precision on the rare malformed/recursive branch only.Testing
manual and unit