Lua timeout only fires inside host callbacks, so a tight loop is never interrupted #99

Open
opened 2026-10-13 02:28:38 +00:00 by ImBenji · 0 comments
Owner

From the engineering review on 2026-10-13.

checkDeadline in lib/scripting/lua_engine.dart:100 is only called from host functions (CanvasObject.new, __newindex, declareParams and so on). A script such as while true do end never calls the host, so it never returns, and there is no isolate, so it runs on the UI isolate and freezes the editor. Regeneration runs on move, paste and param edits, so a bad script saved into a file would hang again on reopen, and the agent can write and run scripts.

Evidence: test/review_probes/engine_lua_budget_probe.dart (local, untracked): timeout=20ms elapsed=602ms result=LuaRunSuccess for a bounded 3M iteration loop. string.rep("x", 20000000) also succeeds, so memory is unbounded. A truly infinite loop was not run.

Side find: #s on a string throws attempt to get length of a string value, which looks like a lua_dardo_plus bug.

Fix sketch: add an instruction count hook if the VM exposes one, otherwise run scripts in an isolate with a kill timeout. Cap or remove string.rep. Related: #38.

From the engineering review on 2026-10-13. `checkDeadline` in `lib/scripting/lua_engine.dart:100` is only called from host functions (`CanvasObject.new`, `__newindex`, `declareParams` and so on). A script such as `while true do end` never calls the host, so it never returns, and there is no isolate, so it runs on the UI isolate and freezes the editor. Regeneration runs on move, paste and param edits, so a bad script saved into a file would hang again on reopen, and the agent can write and run scripts. **Evidence:** `test/review_probes/engine_lua_budget_probe.dart` (local, untracked): `timeout=20ms elapsed=602ms result=LuaRunSuccess` for a bounded 3M iteration loop. `string.rep("x", 20000000)` also succeeds, so memory is unbounded. A truly infinite loop was not run. Side find: `#s` on a string throws `attempt to get length of a string value`, which looks like a `lua_dardo_plus` bug. **Fix sketch:** add an instruction count hook if the VM exposes one, otherwise run scripts in an isolate with a kill timeout. Cap or remove `string.rep`. Related: #38.
ImBenji added the bug label 2026-10-13 02:28:38 +00:00
ImBenji added this to the Arcs & Angles project 2026-10-13 02:28:38 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: IMBENJI.NET/Metro-Map-Maker#99