Skip to content

docs(r11): embedded Lua policy engine — example 42 + chapter 42 (Deep Dives) - #11

Merged
patterncatalyst merged 1 commit into
mainfrom
docs/r11-embedded-lua
Jul 26, 2026
Merged

patterncatalyst merged 1 commit into
mainfrom
docs/r11-embedded-lua

Conversation

@patterncatalyst

Copy link
Copy Markdown
Owner

Part 12 (Deep Dives) opens. pmon lifts its restart/backoff decision out of the compiled host and into a single shared policy.lua, embedded three structurally different ways — C++23 via sol2 (Lua 5.4), Go via gopher-lua (Lua 5.1), Rust via mlua (Lua 5.4) — and hot-reloaded live on a real SIGHUP with no process restart.

Example 42-embedded-lua-scripting (mode: local)

  • One Lua-5.1-safe policy.lua drives all three hosts to byte-identical decisions (diff-confirmed). policy-v2.lua is the SIGHUP edit: 500ms→100ms base backoff, max_restarts 8→2, flipping a would-be restart into an escalate.
  • Sandbox opens only base/string/table/math, nils the loader globals, never loads os/io/package/debug. policy-evil.lua (os.execute) and policy-broken.lua (missing end) prove runtime + load-time rejection — with genuinely different diagnostics per binding (sol2/mlua name the nil global via PUC-Lua; gopher-lua's guard table names the blocked field).
  • verify.lua asserts behaviour (PASS 19 / FAIL 0 per language), not exit codes.

Chapter 42

To the spine (Part "Deep Dives"): Tools-used box, 3 verbatim tri-language codetab sets, Figures 42.1 (host↔script boundary) + 42.2 (SIGHUP reload lifecycle), verified footer.

Tooling

validate.py now skips .lua fixtures declaring validate: expect-syntax-error (policy-broken.lua is invalid by design).

Gate

  • test-all-examples.py --only 42-embedded-lua-scripting → 3 passed / 0 failed
  • full --mode local → 96 passed / 0 failed / 3 skipped (skips are 38-otel, lgtm down)
  • validate.py: OK

Libraries: sol2/3.5.0+lua/5.4.6 (Conan), gopher-lua v1.1.2, mlua 0.12 (lua54+vendored).

… Dives)

Part 12 opens: pmon lifts its restart/backoff decision out of the compiled
host and into a single shared policy.lua, embedded three structurally
different ways — C++23 via sol2 (Lua 5.4), Go via gopher-lua (Lua 5.1),
Rust via mlua (Lua 5.4) — and hot-reloaded live on a real SIGHUP with no
process restart.

Example 42-embedded-lua-scripting (mode: local):
- one Lua-5.1-safe policy.lua drives all three hosts to byte-identical
  decisions (diff-confirmed); policy-v2 is the SIGHUP edit (500ms→100ms
  backoff, max_restarts 8→2 flipping a restart into an escalate).
- sandbox opens only base/string/table/math, nils the loader globals, and
  never loads os/io/package/debug; policy-evil.lua (os.execute) and
  policy-broken.lua (missing end) prove runtime + load-time rejection, with
  genuinely different diagnostics per binding.
- verify.lua asserts behaviour (PASS 19/FAIL 0 per language), not exit codes.

Chapter 42 to the spine: Tools-used box, 3 verbatim tri-language codetab
sets, Figures 42.1 (host↔script boundary) + 42.2 (SIGHUP reload lifecycle),
verified footer.

validate.py: teach check_lua to skip fixtures declaring
"validate: expect-syntax-error" (policy-broken.lua is invalid by design).

Gate: test-all-examples.py --only 42 → 3 passed/0 failed; full --mode local
→ 96 passed/0 failed/3 skipped (skips are 38-otel, lgtm down). validate: OK.
@patterncatalyst
patterncatalyst merged commit 649d436 into main Jul 26, 2026
6 checks passed
@patterncatalyst
patterncatalyst deleted the docs/r11-embedded-lua branch July 26, 2026 05:53
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