Repository navigation
Conversation
verifyFiniteCalls proves the call graph acyclic, but a DAG can still be a diamond: N levels of two calls each expand 2^N times. - collectBindings re-walked a definition at every call site; binding collection is now memoized per (definition, locals scope) so one definition contributes once per scope it is reached under. - renderExpression expanded every call and each item with no ceiling; renders now charge produced output against an 8 MiB budget and refuse past it. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
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.
Closes #454
Summary
verifyFiniteCallsalready proves the TextTemplate call graph is a DAG — but a DAG can still be a diamond: N levels of two calls each expand 2^N times, and two consumers paid that cost:collectBindingsre-walked a definition's subtree at everycallsite — a 30-level diamond is ~2³⁰ walks. What a definition contributes to the binding set is a pure function of (definition, locals scope), so collection is now memoized on that pair: each(definition, scope)is walked once and its contribution unioned. Semantics preserved, including the lexical-eachshadowing test where the same definition contributes different bindings under different scopes.renderExpressionexpanded everycallandeachitem with no ceiling — diamond call graphs double output per level, andreplace/eachamplify further. Render now charges every produced string against an 8 MiB budget (textRenderOutputLimit, exported likewindowsLockerPasswordLimit) and throwsText render exceeds the …-character output budgetpast it. The charge counts each returned expression once per nesting level, which bounds total string work, not just final size — that is the resource the attack burns.Behavior relative to main
textTemplateBindingNames["leaf"]output budgetRed / green
packages/text/test/text.test.ts:diamondTemplatebuilds an N-level two-calls-per-level graph — the 30-level binding-collection test returns instantly here (hangs on main), and the 24-level render test hits the budget (on main it produced the full 16 MB). The lexical-eachscope test still passes, confirming per-scope memoization is correct.Verification
node --import tsx --test packages/text/test/text.test.ts— 9 pass.pnpm check— clean.renderText; all binding collection throughtextTemplateBindingNames— both are covered.Merge Danger
Checklist
Generated with Devin