Skip to content

feat(playground): a loop guard, a Stop that stops, and room for 20 heap objects - #223

Merged
mnaimfaizy merged 1 commit into
mainfrom
feat/playground-runs-and-limits
Oct 13, 2026
Merged

mnaimfaizy merged 1 commit into
mainfrom
feat/playground-runs-and-limits

Conversation

@mnaimfaizy

Copy link
Copy Markdown
Owner

What changes

Endless code no longer freezes the tab when Trace is off. Untraced code is rewritten only to count loop turns and function calls. Past 1,000,000 the run ends with: "Stopped after 1,000,000 loop turns and calls: a loop or recursion probably does not end. Turn Trace on to watch it step by step." The learner's own try/catch/finally cannot swallow the stop, lines keep their numbers, and callbacks and code after await are counted too. There is no setting for the limit.

Stop really stops. The sandbox iframe is discarded and replaced on Stop, on the host's timeout, and when a new run starts over an old one. Before, Stop changed nothing and a stuck sandbox stayed stuck.

Two dead settings are removed: Timeout and Animations were read by nothing. Stored settings that still hold them load as before. Font size and word wrap stay.

The heap draws up to 20 objects in 2D (it was 9), and 9 in 3D. A step that fits 2D but not 3D is shown in 2D with the line "This step is too large for 3D, so it is shown in 2D"; steps that fit go back to 3D and the choice of 3D is kept. On floors larger than 2×2, reference arrows run along the gutters between cards. Story layouts are unchanged.

Choosing 3D widens a narrow lens pane to the 3D minimum, once, at the moment of switching. It keeps 320px for the editor and 240px for the side pane, and does nothing when the window has no room.

A middle frame in 3D shows two slots and "+N more", with the slots in focus first. It used to show one line cut off.

docs/Playground-Developer-Guide.md is brought in line with the code.

Checks

npx tsc -b, npm run lint, npm run test:run (1,250 tests in 94 files) and npm run build pass; three.js is not in the entry graph. This branch was also merged locally with the content and visual polish PRs: no conflicts, and all checks pass on the combined tree.

Checked in the browser:

  • Trace off: while (true) {} stops with the message; a loop inside try/catch/finally prints nothing from either block; an endless await loop stops after the synchronous code finishes; a normal loop with a timer runs as before; an error still reports the learner's line.
  • A 15-node linked list draws in 2D. In 3D its last step falls back to 2D with the line, and an earlier step with two objects is drawn in 3D.
  • At 1440px, switching to 3D widens the lens pane to about 773px.
  • A recursion with three parameters shows "a: 3 b: 'x' +1 more" on its middle frame.
  • Settings lists only Font Size and Word Wrap.
  • Stop during a running interval, then a new run, works.

Limits that remain

  • The guard cannot stop one long built-in call ('x'.repeat(...), a regular expression that backtracks) or code built with eval or new Function.
  • Endless recursion is usually ended by the engine's own stack limit first.
  • Stop cannot interrupt a synchronous loop in a browser that runs the iframe on the page's thread; the guard is what covers that case.
  • A 15-node tree is dense with arrows. They are tested not to cross cards, but were not judged by eye for every shape.

🤖 Generated with Claude Code

…mits

- Trace off: a loop guard counts loop turns and function entries and stops
  a run after 1,000,000, with one plain message. The calls are spliced into
  the learner's text, so lines stay the learner's own, and catch/finally
  cannot swallow the stop.
- Stop and the host timeout backstop discard the sandbox iframe and mount a
  fresh one; the next run waits for it to be ready.
- Remove the Timeout and Animations settings, which nothing read. Stored
  settings that still hold them load.
- Heap limit: 20 objects in 2D (5x4), 9 in 3D. A step that fits 2D but not
  3D is drawn in 2D with one quiet line; the 3D choice is kept.
- 2D arrows on a floor larger than 2x2 run along gutters and bands, so they
  never pass behind an object.
- Choosing 3D widens a narrow lens pane once, if the window has room.
- 3D: a middle frame with more than two slots shows two and "+N more",
  focused slots first.
- Bring the Playground developer guide in line with the code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mnaimfaizy
mnaimfaizy merged commit 387ab2c into main Oct 13, 2026
9 checks passed
@mnaimfaizy
mnaimfaizy deleted the feat/playground-runs-and-limits branch October 13, 2026 06:06
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.

1 participant