Repository navigation
Conversation
normalizeGenuiSpec, the file-tree directory pass, and unknown-field diagnostics all walk the freshly parsed fence before validateNode and repairNodeFields apply GENUI_LIMITS.maxDepth / maxTreeDepth. A deeply nested fence overflowed the stack before the guard could reject it. Thread the walk depth through those three functions and stop at the same limits the validator and repair already use: the root item is depth 0, depth 9 is the first rejected level, and a file-tree keeps maxTreeDepth + 1 levels. The over-deep subtree is returned untouched; validation rejects the fence and repair drops that tail either way, so readers never see it. Reproduced on the base commit with "RangeError: Maximum call stack size exceeded" for a ~1.1k-level / ~27 KB col chain (normalizeGenuiSpec), a ~2.5k-level file-tree (defaultFileTreeDirectories) and a ~2k-level tree (diagnoseUnknownGenuiFields). 4k-level inputs now process in <10 ms, and specs within the documented depth limit are byte-identical to before.
This branch has not been deployed
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.
Problem
Three walks run on a freshly parsed fence before validation/repair:
normalizeGenuiSpec(src/client/genui-runtime/normalize.ts)defaultFileTreeDirectories, thefile-treetype pass (same file)diagnoseUnknownGenuiFields(src/client/genui-runtime/diagnostics.ts)All three recurse over the component tree with no depth bound.
validateNode,repairNodeFieldsandwalkTreedo enforceGENUI_LIMITS.maxDepth = 8/maxTreeDepth = 6, but they run after these walks, so a deeply nested fence overflows the stack before the spec can be rejected:{"type":"col","items":[…]}chainnormalizeGenuiSpecfile-treechildrendefaultFileTreeDirectoriesdiagnoseUnknownGenuiFieldsAll three fail with
RangeError: Maximum call stack size exceeded. Fence bodies are model output, so the input is untrusted and ~27 KB is not a large fence.Fix
Thread the node depth through the three walks and stop at the same limits the rest of the pipeline already uses:
exceeds max depth 8diagnostic);file-treekeepsmaxTreeDepth + 1 = 7levels, matchingwalkTreeand the renderer's owndepth > maxTreeDepthcheck (blocks/advanced.tsx);No renderer, schema or limit changes.
Tests
Four new tests in
tests/genui-schema.spec.ts:normalizenormalizes exactly the rendered levels (alias at depth 8 works) and leaves depth 9 untouched; 4k-level input does not throw.maxDepth(reported at depth 8, not at depth 9).maxTreeDepth; the deepest kept directory keeps its inferreddirmarker.On the base commit all four fail with
RangeError; with the patchnpx vitest runis 2110 passed / 152 files andnpx tsc -p tsconfig.json --noEmitis clean. Specs within the documented depth limit are byte-identical before/after (26-spec equivalence set covering empty/single roots, every container, aliases, unknown fields and file-trees of 6/7/8 levels).