Commit Graph
4 Commits
Author SHA1 Message Date
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 b343bce396 Add Plugin hot-plug: PluginManager, versioned state ABI, file watching
Backward-compatible C ABI v2 (Plugin.hpp; ABI_VERSION unchanged, IPlugin
vtable frozen): optional void_plugin_state_version / serialize_state /
free_string / deserialize_state(inst, json, from_version). State transfer
prefers serialize->deserialize (survives layout changes; migrations live
in the new .so via Json::MigrationChain), falling back to the existing
transfer_state, then no-op. PluginLoader::reload gains this chain; the
shared transfer_plugin_state helper drives it. Existing ABI-v1 plugins
(TestPlugin) load and reload unchanged.

PluginManager (Manager.hpp/.cpp): multi-plugin registry with RCU-style
pinned handles. acquire(name) is one atomic<shared_ptr> load returning a
PluginHandle that keeps its instance alive for the whole call. reload()
is transactional: build new instance, transfer state from old, then
atomic-exchange it in; on any failure the old instance stays. In-flight
handles keep the old instance and its mapped .so alive (dlclose_on_swap=
false) until they drop, so work never stops and callers never see a torn
or freed object. watch(name) auto-reloads via FileSystem::FileWatcher
(debounced); on_reloaded fires after each swap.

Reload-safety: dlopen of a fresh-inode hotswap copy is required to load
new bytes; deployments must install the new .so by atomic rename, never
in-place overwrite of the mapped file (corrupts the running mapping ->
SIGBUS). Documented; tests install via copy-to-.incoming + rename.

Tests: StatefulPluginV1/V2 (shared IStateful interface, atomic counter;
v2 adds a field and migrates v1 JSON). Manager.cpp covers load/acquire,
v1->v2 migration, pinned-handle-survives-reload, legacy transfer_state
fallback, and watch auto-reload. HotReloadUnderLoad.cpp: 6 reader threads
calling through acquire() while 24 v1<->v2 reloads run concurrently --
zero crashes, state survives every migration, ASan+UBSan clean, stable
across 10+ runs.

965 tests green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-13 18:08:06 +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 Sonnet 4.6 58ff7b38a0 Add 20+ new modules with tests: Pipeline, Matrix, Tokenizer, ScopeGuard, Bitset, Optional, Counted, Curry, TypeMap, Bench, DisjointSet, Histogram, StopWatch, and more
Also fixes Diff/Memo/PriorityQueue from previous session: LineDiff is now
an alias for Edit<string> so count_op/apply work on line diffs; Memoized
uses std::apply instead of type-based get to handle duplicate arg types.

874/877 tests pass (3 are platform-gated plugin tests).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 23:49:09 +03:00