fix(sim): bound the instance count the engine will act on - #58
Merged
Conversation
|
@kevin9327 is attempting to deploy a commit to the whoarrryou's projects Team on Vercel. A member of the Team first needs to authorize it. |
Owner
|
Reproduced all three on main, the 1e9 one really does take the process down. Good first contribution, thanks! |
This was referenced Sep 6, 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.
What
A design carrying a large
instancestakes the tab down on the first snapshot, and one carrying anon-numeric
instancesthrows.effectiveInstancespromises ">= 1" in its own doc comment, and cannot keep it:Math.floor(NaN)isNaNandMath.max(1, NaN)isNaN. The one caller that matters then doeswhich throws
RangeError: Invalid array lengthforNaNand forInfinity, and allocates that manyelements for a large finite number.
snapshot()runs at 10Hz, so it is the first frame that dies.Where it comes from
Not from the inspector: its slider stops at 512. It comes from every other way a design arrives.
isTopologychecks nine core config numbers are finite —capacity,serviceMs,serviceCv,queueLimit,hitRate,errorRate,timeoutMs,retries,rps— and says nothing aboutinstances, so a shared link, a.breakscalefile and a restored session all carry it straightthrough.
That makes it a link anyone can send.
decodeTopologysays of itself:It defends against a payload that inflates without bound, and then hands over a number that makes
the engine allocate without bound.
Measured, running the decoded topology through the engine:
The
1e9case is not a slow frame. Running the new test file againstmain, the vitest workerdoes not report a failure, it exits:
Fix
effectiveInstanceskeeps its promise. Anything that is not a finite number is one instance, andthe count is capped at
MAX_INSTANCES = 512, which is the ceiling the inspector already offers, sonothing a reader can build changes.
Bounding it in the engine rather than in
isTopologyputs the guard on the seam every path shares.A design reaches the engine from the editor, a link, a file and a restored session, and only one of
those goes through the validator.
Tests
src/sim/engine.instances.test.ts, new, on the publishedinstancescount:NaNandInfinityare one instance rather than a throw0and-4are one instance2.7is two, since a fractional machine is not a machine1e9is 512, and the snapshot returns in well under a secondAgainst
mainthe file cannot finish: the last of those kills the worker.How I tested
Windows 11, Bun 1.3.14.
bun run testis 916 passed, up from 911 by the five new tests, withnothing else moving.
bun run typecheckandbun run format:checkare clean, andbun run lintreports the same one pre-existing warning in
Metrics.tsxas it does onmain.I have not touched the inspector or the validator. If you would rather
isTopologyalso refuse adesign like this, that is a separate change and I am happy to write it; this one is the guard that
holds wherever the design came from.