Commit Graph
2 Commits
Author SHA1 Message Date
faumarayandClaude Fable 5 e941a48007 FSM v2 (A): CRTP typed access, States<> auto-registration, lifecycle, observers
Maintainability core, breaking the state API (all FSM tests migrated):
- Machine<Derived, ResultT> (CRTP). State::self() returns Derived& — drops
  the static_cast<Derived&>(machine()) boilerplate from every state.
- `using States = Fsm::States<...>` auto-registers every state in the base
  ctor (first entry = initial unless `using Initial = S`); no more manual
  add<S>()/initial<S>() for static machines. next<S>() static_asserts S is
  in the list (unregistered targets are now a COMPILE error, not a runtime
  fail); next_dynamic<S>() + add<S>()/add_if<S>() remain for dynamic
  machines.
- Per-state lifecycle: StateBase gains virtual on_enter()/on_exit()
  (Coro::Task<void>, default no-op) run around run(); the engine visit is
  enter -> run -> exit, so entry/exit actions split out of run(). run()
  now has a default (fails) so reactive states (Phase B) needn't define it.
- Observability: virtual on_transition(from,to) (default logs via Void::Log)
  + observe(fn) called on every transition (and the initial entry) with a
  Transition{from,to,step}. state_path()/state_names() added.

Migrated Basic/Events/Nesting/Serialize/Concurrency + the Orchestrator and
service-hot-reload tests to CRTP + self() + States<>; new Lifecycle suite
(enter/run/exit ordering, observer edges, default-run failure). 968 green,
ASan+UBSan clean, -Werror clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-14 01:03:43 +03:00
faumarayandClaude Fable 5 7b6cd7341a Plugins provide services: hot-reload + state-saving via the registry
Re-expresses the old FSM-plugin hot-plug through the service layer,
reusing the unchanged Plugin module (PluginManager, v2 serialize/
deserialize ABI, FileWatcher, atomic-rename install).

Service/PluginService.hpp: PluginServiceBinding<I> resolves a plugin's
exported service (extern "C" void_plugin_service(instance) -> IService*)
via PluginManager::raw_symbol and registers it under interface I. The
registry entry pins the plugin instance (and its mapped .so) so in-flight
callers never see a freed object. enable_hot_reload() re-binds on each
reload; the FSMs resolve I through their context, so a running FSM picks
up the new implementation on its next service<I>() call with no code
patched. I must derive IService (single inheritance) so the host recovers
it from IService* by static_cast — no dynamic_cast across RTLD_LOCAL.

Tests: ServicePluginV1/V2 (the plugin object is the service: IPlugin +
ICalc : IService; v2 migrates v1 state via Json::MigrationChain).
FsmServiceHotReload.cpp: an Orchestrator-launched FSM accumulates through
the plugin service while a reloader thread flips v1<->v2 under load —
state survives every migration, the FSM runs to completion, no crash; and
a deterministic reload test proving the implementation swaps (version
1->2) with the running total migrated.

Docs: CLAUDE.md/README updated for the new Fsm, Service, and Orchestrator
(StateMachine row removed). 965 tests green, ASan+UBSan clean, stable
across runs, -Werror clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-14 00:47:47 +03:00