Skip to content

Lifecycle, three-tier rebuild, correction, perf contracts, networks - #9

Merged
ewowi merged 16 commits into
mainfrom
next-iteration
Jun 3, 2026
Merged

ewowi merged 16 commits into
mainfrom
next-iteration

Conversation

@ewowi

@ewowi ewowi commented May 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

15-commit branch covering child-lifecycle propagation, the long-overdue closure of the coarse-rebuild debt, per-driver output correction, a real performance-contracts gate, NetworkModule polish, and the developer-environment Improv test loop.

Module lifecycle + module tree:

  • MoonModule loop / loop20ms / loop1s base defaults now propagate to children via a shared tickChildren helper; the previously asymmetric "setup chains, loops don't" was historical, not principled. Override-and-chain convention codified in architecture.md § Lifecycle propagation to children.
  • ImprovProvisioningModule moves to a child of NetworkModule (a four-line follow-up enabled by the propagation fix).
  • markWiredByCode() flag on MoonModule preserves code-wired children across an applyNode load whose saved JSON predates the addition — fixes Improv vanishing on every reboot before this branch.

Control-change + rebuild:

  • Three-tier handleSetControl: cheap onUpdate always, buildState() only when controlChangeTriggersBuildState(name) returns true (default false; overridden true on LayoutBase / ModifierBase). Slider drag no longer triggers a tree-wide realloc sweep. Mirrors MoonLight's onUpdate / requestMappings / onSizeChanged split.
  • Renamed onAllocateMemory → onBuildState (idempotent, history-agnostic — boot and later changes are the same call).

Output correction:

  • Per-driver stage shared via the Drivers container — Correction (256-entry brightness LUT + channel-order table + derive-white flag) handed to each physical driver via const Correction*. ArtNet was previously sending raw bytes; gap now closed. Preview exempt.

Performance contracts + telemetry:

  • Per-target tick + heap + max_alloc_block contracts captured in every scenario JSON, with an observed.<target> widen-only sibling block tracking the rolling [min, max] across runs. run_scenario.py writes back observed values automatically.
  • docs/performance.md now generated from the contracts — no hand-edited table to drift.
  • ArtNet alloc moved off the hot path; platform clock seam kills the previously-flaky animation tests.

NetworkModule polish:

  • New mode / rssi / txPower read-only metrics — required adding ControlType::ReadOnlyInt (int8 + unit suffix). Static-IP fields gain ControlType::IPv4 (4-byte storage instead of 16-char dotted-quad).
  • Idle recovery: failed STA/Eth init now lands cleanly on Idle instead of crashing.

ControlType dispatcher:

  • src/core/Control.cpp extracts the per-ControlType switch that had drifted across HttpServerModule::writeControls, FilesystemModule::writeValue, and scenario_runner.cpp. ApplyPolicy::Strict (HTTP) vs Clamp (FS load) preserves the tolerant-load semantics. JsonSink gains a fixed-buffer mode (third backend alongside socket + heap-grow) so the FS serializer shares the codepath without growing a per-value allocation. Codified as coding-standards.md § Per-type behaviour lives with the type.

MoonDeck:

  • New "Networks" concept — bundles WiFi credentials + scanned devices + last-used serial port per network; auto-detects which network the laptop is currently on. Replaces the previous flat device list and per-config WiFi credentials file.
  • Per-network state mutated under mutate_state(mutator) with RLock + atomic temp-file write.

Board → firmware rename:

  • "Board" was overloaded between physical hardware and firmware variant. The firmware variant (esp32-eth-wifi etc.) is now firmware; board is reserved for physical hardware (a separate concept, see docs/plan.md § Board injection).

Test reorganization:

  • test/unit/ split into core/ and light/ subdirectories with CamelCase naming matching the source module.
  • Generated docs/tests/unit-tests.md + docs/tests/scenario-tests.md indices from source — no hand-edited test catalog to drift.
  • scenario_runner and run_live_scenario now share contract semantics; min_pct bounds are runner-WARN, hardware-fail.

Developer-environment Improv test loop:

  • scripts/run/preview_installer.py flash-ready mode stages every local build/esp32-*/projectMM.bin under releases/latest/ in the preview server's tree, generates Pages-relative manifests via the same script production uses, and overlays the GitHub latest tag — http://localhost:8000/ flashes the local build with full ESP Web Tools + Improv WiFi. Web Serial works on localhost without the secure-origin requirement.
  • scripts/build/improv_smoke_test.py: three-step probe + WiFi provision + LAN reachability as a single CLI, exit codes for CI, wired into MoonDeck. Closes the gap that made every Improv-touching commit a high-friction "tag, wait for CI, deploy" cycle.

KPI (head of branch)

PC:356KB | tick:70/58/126/107us(FPS:14285/17241/7936/9345)
ESP32:1178KB | tick:83521us(FPS:11) | heap:154KB
src:60(9232) | test:33(4279) | lizard:33w

PC tick squarely in the historical 46–85us / 48–59us / 121–196us / 107–158us band. ESP32 tick from a live Olimex board.

Test plan

  • Desktop build clean (zero warnings)
  • ctest — all unit + scenario tests pass on every commit
  • mm_scenarios (in-process) — all pass
  • Live scenarios on Olimex ESP32-Gateway — run_live_scenario.py for the touched scenarios; observed bands within contract
  • Platform boundary check — PASS
  • Spec check — 25/25
  • ESP32 build (esp32-eth-wifi) — clean
  • Hardware verification on Olimex ESP32-Gateway:
    • Improv renders as a child of Network, survives reboot without erase_flash (the markWiredByCode fix)
    • Network mode / rssi / txPower metrics update live; mode lands Idle cleanly when init fails
    • Slider drag no longer triggers a tree-wide realloc sweep (three-tier control-change)
    • Output correction visible end-to-end via ArtNet (brightness scaling + channel reorder applied at the driver edge)
    • MoonDeck networks: laptop switches between two LANs, devices/wifi/port follow the active network
    • Local installer flash-ready mode: preview_installer.py → browser → flash → Improv WiFi → device reachable on LAN

Reviewer trail

  • CodeRabbit findings processed across the branch — fixed in additional commits or skipped with a one-line reason on the PR thread.
  • Opus Reviewer agent run at pre-merge over the full branch diff (git diff main...HEAD) — findings either fixed in commit 158d727 or accepted with reason.

🤖 Generated with Claude Code

MoonModule loop/loop20ms/loop1s base defaults now propagate to children
via a shared tickChildren helper that gates each child by the same rule
the Scheduler applies to top-level modules (respectsEnabled() || enabled())
and accumulates per-child timing. Leaf modules pay one predicted-not-taken
branch per call. Layers / Drivers shed the per-child block they each
carried; Layer keeps its custom Effect-only dispatch.

With propagation in place, ImprovProvisioningModule moves from a top-level
Scheduler module to a child of NetworkModule — the relationship matches
the data flow (Improv polls credentials, pushes them into Network).
NetworkModule's overrides chain to base so Improv participates in setup,
control binding, loop1s, and teardown.

To stop the persistence-apply step from trimming the code-wired Improv on
devices whose saved Network.json predates the addition, MoonModule grows
a markWiredByCode() flag. main.cpp marks Improv, FilesystemModule's
applyNode skips wired-by-code children in both the position-replace and
trim paths. Verified on real hardware: the same Network.json that caused
Improv to vanish on every boot now loads cleanly without erase-flash.

The UI rendered code-wired children invisibly because acceptsChildren()
gated on a light-pipeline allowlist. Split into hasNestedChildren()
(controls whether nested cards render) and acceptsNewChildren() (controls
whether "+ add child" appears). Parent control collapse-by-default ties
to acceptsNewChildren — Network keeps its controls expanded since the
parent's settings are the focus there.

CLAUDE.md drops the docs/history/plan-NN.md flow; plans live in the
agent's own workspace, only their distilled lessons (decisions.md) land
in the repo. Brings the process back to vanilla Claude Code planning.

KPI: 16384lights | PC:356KB | tick:70/58/126/107us(FPS:14285/17241/7936/9345) | ESP32:1178KB | tick:83521us(FPS:11) | heap:154KB | src:60(9232) | test:33(4279) | lizard:33w

- Core:
  - MoonModule: loop/loop20ms/loop1s defaults propagate via tickChildren; markWiredByCode/isWiredByCode added
  - NetworkModule: setup / loop1s / teardown / onBuildControls chain to base so the Improv child participates
  - FilesystemModule: applyNode preserves code-wired children in both position-replace and trim paths
  - Scheduler: unchanged (top-level walk still correct; recursion now happens inside each root's loop)
- Light domain:
  - Layers: loop() override deleted (was pure propagation; base default does it)
  - Drivers: loop() shrinks to blendMap + MoonModule::loop()
  - Layer: unchanged (custom Effect-only dispatch with extrude logic)
- UI:
  - app.js: acceptsChildren split into hasNestedChildren + acceptsNewChildren; collapse-by-default ties to acceptsNewChildren so Network's controls stay expanded
- Scripts / MoonDeck: none
- Tests:
  - test_lifecycle_propagation: 6 new cases pinning propagation gating + timing + leaf no-op
  - test_filesystem_persistence: 2 new cases pinning wiredByCode preservation in trim and position-replace
- Docs / CI:
  - CLAUDE.md: removes the docs/history/plan-NN.md process; plans live in agent's workspace
  - architecture.md: new "Lifecycle propagation to children" subsection + Persistence bullet for code-wired children
  - testing.md: lifecycle-propagation test section
  - decisions.md: two new entries (asymmetric lifecycle was historical; override-and-chain conventions)
  - ImprovProvisioningModule.md: notes Improv-as-Network-child relationship + wiredByCode

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@coderabbitai

coderabbitai Bot commented May 27, 2026 •

Copy link