rhai limits #8
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_lib_rhai#8
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
see RHAI_LIMITS_INVESTIGATION.md
Root Cause Analysis
Smoking gun found:
crates/os_rhai/src/profiling.rs:182setsengine.set_max_operations(10000)on the shared hero_do engine.Call chain:
hero_do/src/main.rs→create_engine_with_base_path()→Engine::new()(default: unlimited operations)herolib_os_rhai::register_os_system_module(&mut engine)(os_rhai/src/lib.rs:63)register_profiling_module(engine)(os_rhai/src/profiling.rs:7)configure_engine_security(engine)(os_rhai/src/profiling.rs:82)engine.set_max_operations(10000)(os_rhai/src/profiling.rs:182) ← THE BUGThis 10,000 operation limit is extremely restrictive. Any non-trivial script hits it quickly.
Additionally,
configure_engine_securitydisables symbols (File,Dir,Env,Process,Command,Http,Tcp,Udp,debug,inspect) on the shared engine — these should NOT be disabled globally.Why the investigation found
set_max_operations(0)did not help:The hero_do engine creation does NOT call
set_max_operations(0). So even if you set it to 0 in hero_do, the profiling module registration (called AFTER) overrides it back to 10,000.Fix Strategy
Remove security overrides from profiling module registration — Module registration functions should ONLY register types and functions, never modify global engine settings (limits, disabled symbols). The
configure_engine_security()andconfigure_engine_security_strict()calls will be removed from theregister_functions.Add centralized
configure_engine_limits()in hero_do — Bothmain.rsandlib.rswill get a shared limits function called AFTER all module registrations:set_max_expr_depths(0, 0)— unlimitedset_max_call_levels(0)— unlimitedset_max_operations(0)— unlimitedset_max_modules(0)— unlimitedset_max_string_size(0)— unlimitedset_max_array_size(0)— unlimitedset_max_map_size(0)— unlimitedKeep security functions available for standalone profiling use — Export them as public functions so callers who want sandboxed execution can opt in, but they will not be called during normal module registration.
Apply the same fix pattern to foundry engine — Ensure the foundry engine limits are set AFTER all registrations.
Fix Pushed —
development_8branchCommit:
fdb8a22— Fix Rhai engine operation limits causing script failures (#8)Changes:
crates/os_rhai/src/profiling.rsconfigure_engine_security()call fromregister_profiling_module(this was the bug — it setmax_operations(10000)on the shared engine)configure_engine_security_strict()call fromregister_profiling_module_strictcrates/hero_do/src/main.rsconfigure_engine_limits()function that sets all Rhai limits to 0 (unlimited)crates/hero_do/src/lib.rsconfigure_engine_limits()function added, called AFTER all module registrationsNote:
The workspace has a pre-existing build issue (herolib_crypt missing rhai feature flag) that prevents cargo check from completing. The fix itself is syntactically correct and follows the established patterns.
Merged and closing
Branch
development_8merged intodevelopment(fast-forward).Verification
hero_do: a 50,000-iteration loop fails withToo many operationsos_rhai/profiling.rswas callingconfigure_engine_security()during module registration, settingmax_operations(10000)on the shared engineset_max_operations(0)after the override correctly removes the limitFix summary (3 files)
os_rhai/src/profiling.rs- Removedconfigure_engine_security()/configure_engine_security_strict()calls from module registration functions. Module registration should only register types and functions, never modify engine limits.hero_do/src/main.rs- Addedconfigure_engine_limits()(all limits = 0/unlimited), called AFTER all module registrations.hero_do/src/lib.rs- Sameconfigure_engine_limits()added for the library engine path.Note: Workspace cannot currently build due to pre-existing dependency issues (herolib_crypt missing
rhaifeature, sqlite3 version conflict). Those are separate from this fix.Fully fixed and verified
Build now passes, hero_do installed and tested
Test result:
Previously this failed with
Too many operationsat ~10,000 ops.Commits on
development:fdb8a22- Fix Rhai engine operation limits (the core #8 fix)configure_engine_security()from profiling module registrationconfigure_engine_limits()in hero_do, called after all module registrationsa0e955e- Fix build: update bindings for hero_lib API changesrhaifeature)Also pushed to hero_lib (
910b43d2): made rusqlite optional behindusagefeature, bumped webserver rusqlite to 0.32.