Commit Graph
11 Commits
Author SHA1 Message Date
faumarayandClaude Opus 4.8 80293ee56f Add async/resilience/reflection primitives + FSM v2 rewrite
A round of new universal capabilities (all generic — templated/reflection
based, no app coupling), verified by the test suite (1103 passing):

Data reflection:
- Reflect.hpp now (de)serializes chrono::duration, chrono::time_point,
  std::variant (tagged), std::array, and non-string-keyed std::map;
  Meta.hpp gains is_time_point_v et al.

Async:
- EventBus gains Mode::Async (worker-thread dispatch + flush()).
- ThreadPool gains a bounded queue, try_submit(), and rejection stats.

New modules / containers:
- Resilience: TokenBucket, KeyedRateLimiter<Key>, CircuitBreaker,
  ResourceMonitor.
- Containers: BufferPool<T> (size-class buffer reuse) and Cache<K,V>
  (per-entry TTL, LRU/LFU/FIFO eviction, hit/miss stats).
- System: process/CPU/memory metrics (Metrics.hpp) and a streaming
  Process API.

Plus FSM v2 (typed Success/Failure, sub-machines, parallel regions,
history states, deferred events), Configuration/Logging reflection
helpers, and the accompanying test suites.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 15:45:16 +03:00
faumarayandClaude Fable 5 ec9e466d7a FSM (4): one signature-inferred State (drops Reactive/Continue bases)
There is now a single state base, `State`. The engine infers each state's
role purely from member signatures via P2996 — no `override`, no
framework-mandated names:

  struct Work : State {                          // entry
    Coro::Task<Step> run() { ... }
    Coro::Task<Step> run(Cfg c) { ... }          // startup-entry (launch data)
  };
  struct Idle : State {                          // reactive
    void transitions(TransitionBuilder& on) { on.event<Go>().to<Run>(); }
  };
  struct After : State {                         // continuation
    Coro::Task<Step> ok(ChildSuccess auto s) { use s.value; }
    Coro::Task<Step> no(ChildFailure auto f) { use f.value; }
  };

- Detail/Roles.hpp: ChildSuccess/ChildFailure concepts over boxes, plus the
  reflection selectors (invoke_entry / invoke_startup / invoke_handler /
  dispatch_result / has_transitions / make_driver). At add<S>() a per-state
  driver thunk is stored (reactive table vs entry, by whether S has a
  TransitionBuilder& member); drive() calls it. startMachine<Sub, Next>(data)
  builds a Launch step carrying a launcher (injects data into Sub's initial
  startup-entry) + a dispatcher (dispatch_result<Next, Sub>) that builds the
  ChildSuccess/Failure box and calls Next's matching handler.
- Removed Reactive/Continue<R> bases, StateKind/kind(), StateBase::run/resume
  (only on_enter/on_exit remain virtual). Reactive states keep the same DSL.
- Toolchain note: template-for + member splicing fails inside a coroutine
  body in this GCC build, so the selectors are non-coroutines returning a
  Task<Step> (plain Step wrapped via ready_task). Discovery is
  invocability-based — no parameter-type reflection (P3096). Probe-verified.

All FSM tests migrated to the nameless style (SubMachine: Continue ->
ChildSuccess/Failure handlers + startup-entry seeding; reactive states drop
the Reactive base/override). 995 tests (992 green, 3 skipped), ASan clean,
-Werror clean; lone intermittent failure remains the pre-existing racy
plugin hot-reload-under-load test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-15 01:20:56 +03:00
faumarayandClaude Fable 5 9e9eb838ea FSM: typed Success/Failure result model (reflected nested types)
A machine is now Machine<Derived> (dropping the ResultT template param) and
declares its result types as nested types reflected *by name* — Success and
Failure (a struct or a using-alias), each defaulting to void:

    class Login : public Machine<Login> {
      using Success = Token;     // or a nested struct; default void
      struct Failure { int code; };
    };

- Outcome = std::expected<Success, Failure> (void failure -> std::monostate
  error arm). succeed(Success{...}) / fail(Failure{...}) carry the typed
  values (nullary when void). Resolved by plain dependent-name lookup
  (Detail/Result.hpp), no P2996.
- Engine/system faults (no initial state, unregistered target, no entry)
  travel a SEPARATE FsmError channel: status()==Faulted + system_error(),
  never the typed Failure. New Step::Kind::Fault carries it.
- CRTP wrinkle: Derived is incomplete at base instantiation, so the engine
  stores the result type-erased (std::any) and rebuilds the typed Outcome in
  wait()/run_blocking()/take_outcome() — function templates defaulted on
  Derived. run_child/run_region/start_machine reconstruct OutcomeOf<Sub> at
  the boundary (Sub is complete).
- Step carries Success/Failure payloads as std::any; the reactive DSL
  (finish/fail) and Continue<Sub> are reparameterised off the nested types.

Interim: Continue<Sub> keeps the named on_success/on_failure form (Phase 2
replaces it with signature-inferred ChildSuccess/ChildFailure). All FSM
tests migrated to the nested-type form. 995 tests (992 green, 3 skipped),
ASan clean, -Werror clean; the lone intermittent failure is the
pre-existing racy plugin hot-reload-under-load test (flaky on HEAD too).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-14 21:14:43 +03:00
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
faumarayandClaude Fable 5 04cf1998bd Remove the two old FSMs ahead of the inheritance-based rewrite
Deletes the compile-time Void::StateMachine and the builder-based runtime
Void::Fsm (Definition/Machine/Event/PluginBehavior + their standalone
tests, the FSM behaviour plugins, and the FSM x Plugin integration test
and its CMake wiring). The general-purpose Plugin module and its stateful
hot-reload tests are untouched.

Both are being replaced by a single inheritance + coroutine workflow FSM
(next phase). 936 tests green (51 old FSM/StateMachine tests removed).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-14 00:26:30 +03:00
faumarayandClaude Fable 5 c988f635e9 Integrate FSM with Plugin: states/actions from plugins, hot reload
Fsm/PluginBehavior.hpp: IFsmBehaviorPack::register_into(Builder&) lets a
plugin contribute states/events/guards/actions; plugins export it via
extern "C" void_plugin_fsm_behaviors(). build_machine_def(pack) runs the
pack through a Builder and validates.

PluginManager::raw_symbol(name, symbol) resolves an optional extra entry
point from a plugin's current .so (returns nullptr if absent), so the
host can fetch the behaviour factory without widening the frozen IPlugin
vtable.

Integration flow (tests/internal/FsmPluginHotReload.cpp): build a machine
def from the plugin pack, run it; on reload, rebuild from the reloaded
pack and swap_definition between RTC steps. Same state names across
versions ⇒ the live configuration is adopted seamlessly (machine keeps
running, queue intact); v2's new "skip" transition goes live. Safety:
plugin actions are std::functions whose code lives in the .so, so a
PluginHandle is pinned for the machine's lifetime and dlclose_on_swap=
false keeps the code pages mapped under in-flight frames.

Tests: FsmPluginV1/V2 (same idle/busy/done states; v2 adds skip).
Definition-swap test proves configuration survival + new behaviour; the
stress test runs 4 producer threads posting while 5 v1<->v2 rebuild+swaps
happen concurrently, then asserts exactly one active leaf. 967 tests
green, stable across runs, ASan+UBSan clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-13 18:13:03 +03:00
faumarayandClaude Fable 5 c74a02a5a5 Overhaul Logging and Configuration; integrate the log facade library-wide
Void::Log facade (header-only, macro-free):
- Leveled function templates trace/debug/info/warn/error/fatal(module,
  fmt, args...) with lazy formatting - a disabled call is one relaxed
  atomic load, no allocation, no formatting.
- Global min level + per-module overrides (can raise or lower); empty
  sink/Disabled level = logging fully off; set_sink remains the splice
  point for external logging libraries.

Void::Logging::Logger - async by default, one class for both modes:
- Mode::Async (default): lock-free MPSC queue + logger-owned worker
  delivering batches via on_flush outside any lock; Immediate/Buffered
  give synchronous behavior via constructor arg or set_mode at runtime.
- Bounded queue with OverflowPolicy{Block, DropNewest, DropOldest};
  flush() (now virtual) blocks until everything submitted is delivered;
  base destructor only stops/joins the worker, never touches virtuals.
- Fixed a wakeup race: stale park token + fresh release overflowed the
  binary semaphore; wakeup is a counting semaphore (spurious wakes are
  absorbed by the worker loop).

New sinks and formatters:
- RotatingFileLogger (size-based rotation, max-files cap), NullLogger,
  CallbackLogger, MultiLogger (tee via new Logger::relay), SyslogLogger.
- Formatter interface: PatternFormatter ({time}/{level}/{scopes}/...),
  JsonLinesFormatter, LogfmtFormatter; installable on Console/File/
  Rotating sinks. Console/File sinks now default to Async.
- Logging::from_config builds the whole sink tree from Config keys;
  apply_facade_config drives facade levels.

Configuration:
- Typed get_as<T>/get_or_as<T> (numbers, bool spellings, enums by name,
  chrono durations), dotted keys, subtree(), sorted keys().
- New sources: from_env_prefix (APP_LOG__LEVEL -> log.level), from_ini
  (sections as prefixes), from_json (objects/arrays flattened),
  from_args (--key=value / --key value / --flag).
- Bind.hpp: reflection bind<T>(cfg, prefix) fills aggregates; defaults
  in the struct are the schema; nested aggregates, optional, vector.
- Watch.hpp: ConfigWatch reloads on change with per-key diff; parse
  failures keep the previous config.

System: new FileSystem::FileWatcher - debounced polling watcher (stable
mtime+size across N polls), callbacks off-thread, deletion events;
shared groundwork for plugin hot-reload.

Sweep: all internal Void::Log::log call sites migrated to the leveled
API ("Umbrella.Feature" labels); Plugin loader now logs load/reload.

918 tests green (28 new), stable across 30 consecutive runs, ASan+UBSan
clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-13 00:11:13 +03:00
faumarayandClaude Fable 5 28b94883fd Restructure into umbrella modules (~55 -> 16 targets)
Headers move, CMake targets merge, C++ namespaces stay unchanged:
- Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant
- Functional: Pipeline, Either, Result, Retry
- Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval
- Math: +Matrix, Numeric, Random, Histogram
- Text: Str, Format, Tokenizer, Diff, Encoding, Semver
- Data: Json, Csv, Ini
- Async: Coro, Concurrency, EventBus, Observable
- Time: +Bench
- Log: Log facade + Logging framework (facade now header-only, breaking
  the Stacktrace<->Log link cycle the merge would have created)
- System: FileSystem + Process
- Configuration: +Argparse
- Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail

Module system fixes:
- OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no
  longer depends on the alphabetical discovery order of src/ subdirs
  (Testing -> Text would have been silently dropped).
- Every header-only module now has a tracked module.cmake; previously the
  empty src/<Name> marker dirs were untracked, so a fresh clone would have
  silently skipped those modules.
- VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT.

Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files
prefixed: ResultBasic etc.). Test count verified identical (831) before and
after. README/CLAUDE.md module tables updated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 18:50:02 +03:00
faumarayandClaude Sonnet 4.6 a09e000f0f Add Hash, Random, Uuid, Encoding, Bits, Math modules + make Testing deps optional
New header-only modules:
- Void::Hash — FNV-1a 32/64, CRC-32, DJB2, MurmurHash3-32, UDL literals
- Void::Random — Xoshiro256** PRNG, uniform_int/real, coin_flip, shuffle, random_string
- Void::Uuid — v4 (random), v5_lite (name-based), parse, RFC 4122 namespaces
- Void::Encoding — Base64 (standard + URL-safe), Hex encode/decode
- Void::Bits — popcount, bit extract/deposit, rotation, align, byteswap, masks
- Void::Math — Vec2/Vec3/Vec4, Mat4 (identity, translation, scale, rotation)

Testing module: move Stacktrace from INTERNAL_DEPS to OPTIONAL_DEPS. Added
Detail/Color.hpp shim that delegates to Stacktrace::Color when present or
provides inline ANSI fallback otherwise. All Stacktrace calls in SignalHandler,
ConsoleReporter, and Runner are gated on VOID_HAS_STACKTRACE.

Fix Repr.hpp reflect_struct to handle template specializations that lack
std::meta::identifier_of (now guarded by has_identifier check).

33/33 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 21:52:22 +03:00
faumaray 42268c6c35 Reflection and filesystem
Signed-off-by: faumaray <faumaray@gmail.com>
2026-05-03 18:09:46 +03:00