Skip to content

fix(acp): break self-referential $ref cycles before Code Mode schema - #10469

Merged
lifeizhou-ap merged 1 commit into
aaif-goose:mainfrom
Abhijay007:fix/acp-code-mode-schema-ref-cycle
Jul 15, 2026
Merged

fix(acp): break self-referential $ref cycles before Code Mode schema#10469
lifeizhou-ap merged 1 commit into
aaif-goose:mainfrom
Abhijay007:fix/acp-code-mode-schema-ref-cycle

Conversation

@Abhijay007

@Abhijay007 Abhijay007 commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

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

…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
@lifeizhou-ap
lifeizhou-ap added this pull request to the merge queue Jul 15, 2026
Merged via the queue into aaif-goose:main with commit 0564b8c Jul 15, 2026
24 checks passed
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.

goose serve crashes with SIGABRT — unbounded recursion in pctx_codegen schema processing when MCP server returns outputSchema

3 participants