diff --git a/docs/agent-workflow/tasks/M-LOG-01-05.md b/docs/agent-workflow/tasks/M-LOG-01-05.md new file mode 100644 index 0000000..0591ef5 --- /dev/null +++ b/docs/agent-workflow/tasks/M-LOG-01-05.md @@ -0,0 +1,28 @@ +# Log Hardening, Bounded Delivery, File Sync, and LogConfig Separation +Task ID: M-LOG-01..05 +Phase: P2 +Status: APPROVED +Contracts: C-01, C-02, C-03, C-04, C-05, C-11 + +## 1. Context and baseline +`Void::Log` (`Log.hpp` + `LogState/State.cpp`) holds `Sink` behind `State::mutex` during emission, and `Void::Logging::Logger` (`src/Log/Logger.cpp`) uses an unbounded batch drain without byte budgeting, contiguous ticket completion, exception quarantine, or file durability/reopen controls, while `Log` links `Configuration` via `FromConfig.hpp`. + +## 2. Deliverables +- Split `LogConfig` (`src/LogConfig/module.cmake`, `FromConfig.hpp`/`src/LogConfig/FromConfig.cpp`) out of `Log` (`src/Log/module.cmake`: `INTERNAL_DEPS Async Core Data Functional Memory Time LogState`, `OPTIONAL_DEPS Stacktrace`, `EXCLUDE_HEADERS Void/Log/Log.hpp Void/Log/FromConfig.hpp`). +- `include/Void/Log/Log.hpp` & `src/LogState/State.cpp`: immutable `SinkRegistration`, `register_sink`, `detach_and_drain` (`DrainResult` with `would_deadlock`), outer-of-lock callback invocation & owner destruction, reentrancy guard (depth <= 8) + emergency hook. +- `include/Void/Log/Entry.hpp`: `bool truncated{false};`. +- `include/Void/Log/Logger.hpp` & `src/Log/Logger.cpp`: `LogErrorCode`, `make_log_error` (`kLogErrorDomain = 11`), `DeliveryLimits`, `FailurePolicy`, `LoggerOptions`, `SubmitState`, `Ticket`, `SubmitReceipt`, `FlushDurability`, `FlushOptions`, `CloseOptions`, `FlushReport`, bounded deque with queued+in-flight entry and byte accounting, contiguous ticket watermark, `try_submit`, `flush_through`, `close`, quarantine & reset, admission-barrier `set_mode`, `sync_files()`. +- `include/Void/Log/Sinks.hpp`: `CallbackLogger(Callback, LoggerOptions)`, `MultiLogger::try_add` with max 8 children and cycle check. +- `include/Void/Log/Formatter.hpp` & `src/Log/Formatter.cpp`: field redaction in `FieldFilter`, `LogfmtFormatter` control-char escaping, `JsonLinesFormatter` int64 line numbers, `format_bounded`. +- `FileLogger` / `RotatingFileLogger` / `RollingFile`: explicit `create_directories`, `RotatingFileOptions::roadmap_defaults()`, stream write-error surfacing, `reopen()`, POSIX `::fsync` in `sync_files()`. +- `src/LogConfig/FromConfig.cpp` + moved `tests/standalone/LogConfig/FromConfig.cpp`: strict config value validation. +- `tests/standalone/Log/LogHardening.cpp` and `tests/package/LogOnly/{CMakeLists.txt,main.cpp}` registered in `tests/package/InstalledComponents.cmake`. + +## 3. Edge cases +- Legacy 3-argument `Logger` constructor preserves compatibility for existing `LogScopeSnapshot` immediate recursion and `AsyncLogger` 400k stress test (`owned_bytes >= max(8 MiB, entries * 1024)`, `suppress_reentrancy = false`). +- `DropOldest` never evicts already-dispatched in-flight batch entries; `Block` rejects self-blocking on worker (`would_deadlock`). + +## 4. Verification commands +```sh +dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-w5-log -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DVOID_ENABLED_MODULES="Log;Testing" -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-w5-log && /tmp/void-w5-log/tests/VoidTests && ctest --test-dir /tmp/void-w5-log --output-on-failure --timeout 120' +``` diff --git a/docs/agent-workflow/tasks/M-RESILIENCE-01-04.md b/docs/agent-workflow/tasks/M-RESILIENCE-01-04.md new file mode 100644 index 0000000..ee38041 --- /dev/null +++ b/docs/agent-workflow/tasks/M-RESILIENCE-01-04.md @@ -0,0 +1,28 @@ +# Resilience Hardening, Permits, Bounded Keyed Cleanup, and Async Policy +Task ID: M-RESILIENCE-01..04 +Phase: P2 +Status: APPROVED +Contracts: C-02, C-03, C-04, C-05, C-11, C-13 + +## 1. Context and baseline +`Void::Resilience` currently provides `TokenBucket`, `KeyedRateLimiter`, `CircuitBreaker`, and `ResourceMonitor` without config/input validation, overflow-safe `ResourceMonitor` subtraction, synchronized callback setters, single-probe HalfOpen leases, generation binding, bounded keyed cleanup cursors, or optional `Async` bulkhead/retry composition. + +## 2. Deliverables +- `src/Resilience/module.cmake` (`INTERNAL_DEPS Functional Time ObservabilityHooks`, `EXCLUDE_HEADERS Void/Resilience/AsyncPolicy.hpp`) +- `src/ResilienceAsync/module.cmake` (`INTERNAL_DEPS Resilience Async Functional Time ObservabilityHooks`, `EXTRA_HEADERS Void/Resilience/AsyncPolicy.hpp`) +- `include/Void/Resilience/Types.hpp`: `ResilienceErrorCode`, `make_resilience_error` (`kResilienceErrorDomain = 14`), `Outcome`, `Admission`, validated `BucketConfig`, `KeyedBucketConfig`, `BreakerConfig`, `MonitorConfig` +- Upgrades in `RateLimiter.hpp`, `KeyedRateLimiter.hpp`, `CircuitBreaker.hpp`, `ResourceMonitor.hpp`, `Resilience.hpp` (`TokenBucket::create`/`try_acquire_checked`/`try_acquire_all`, `BoundedKeyedRateLimiter`, `Breaker`/`BreakerPermit`, overflow-safe `ResourceMonitor`/`ResourcePermit`) +- `include/Void/Resilience/AsyncPolicy.hpp`: `BulkheadConfig`, `Bulkhead`, `BulkheadPermit`, `ResilientRetryConfig` (using `Void::Retry::ExponentialBackoff` + `JitterMode::Full`), `execute_resilient` +- `tests/standalone/Resilience/ResilienceHardening.cpp`, `tests/standalone/ResilienceAsync/AsyncPolicy.cpp` +- `tests/package/ResilienceOnly/{CMakeLists.txt,main.cpp}` registered in `tests/package/InstalledComponents.cmake` + +## 3. Edge cases +- Clock regression never moves `last_` backwards or adds tokens; NaN/Inf/negative/oversize costs consume nothing. +- `BreakerPermit` enforces single (or `half_open_max_probes`) concurrent HalfOpen probe, rejects stale-generation completions from closing newer Open state, and releases slot neutrally on abandonment. +- `ResourceMonitor` rejects overflow (`amount > limit - usage`), over-release (`release_checked`), and isolates observer callback exceptions outside locks. +- `execute_resilient` honors composition order, shares total deadline across retries, and never retries non-replay-safe operations. + +## 4. Verification commands +```sh +dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-w5-resilience -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DVOID_ENABLED_MODULES="Resilience;Testing" -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-w5-resilience && /tmp/void-w5-resilience/tests/VoidTests --filter "CircuitBreaker*|RateLimiter*|KeyedRateLimiter*|ResourceMonitor*|ResilienceHardening*" && ctest --test-dir /tmp/void-w5-resilience --output-on-failure --timeout 120' +``` diff --git a/docs/agent-workflow/tasks/M-STACKTRACE-01-04.md b/docs/agent-workflow/tasks/M-STACKTRACE-01-04.md new file mode 100644 index 0000000..e308e49 --- /dev/null +++ b/docs/agent-workflow/tasks/M-STACKTRACE-01-04.md @@ -0,0 +1,27 @@ +# Stacktrace Split Capture/Resolve, Bounded Cache, Safe Snippets, and Crash Marker +Task ID: M-STACKTRACE-01..04 +Phase: P2 +Status: APPROVED +Contracts: C-01, C-02, C-03, C-04, C-05 + +## 1. Context and baseline +`Void::Stacktrace` currently couples raw capture with demangling, source snippet file reads, and `Void::Log` diagnostics, has no explicit `Capabilities` query or async-signal-safe fatal marker helper, and has no standalone test directory under `tests/standalone/Stacktrace/`. + +## 2. Deliverables +- `src/Stacktrace/module.cmake`: add `Time` (`INTERNAL_DEPS Functional Time LogState`) +- `include/Void/Stacktrace/Stacktrace.hpp` & `src/Stacktrace/Stacktrace.cpp`: + - Legacy `StackFrame`, `capture_stacktrace`, `read_source_snippet`, `format_stacktrace`, `print_stacktrace` preserved. + - `kStacktraceErrorDomain = 12` `StacktraceErrorCode` + `make_stacktrace_error`. + - `Capabilities` (`raw_capture`, `symbols`, `line_info`, `async_signal_safe = false`, `backend_name`) + `capabilities() noexcept`. + - `CaptureOptions`, owned `RawFrame` (`address`, `module_offset`, `module_path`, `module_id`), `RawTrace`, `capture()` (validates `1 <= max_frames <= 256`, zero source IO, zero `Void::Log` calls). + - `FrameResolveStatus`, `ResolvedFrame`, `ResolvedTrace`, `ResolveOptions`, `Resolver` (bounded `1024` entries / `4 MiB` cache keyed by `(module_id, module_offset)`, `invalidate_module`, `clear_cache`), `read_source_snippet_checked` (allowed roots, symlink-escape rejection, overflow-safe line math, byte limits), `format_resolved_trace`, `write_fatal_signal_marker(int fd, int sig) noexcept`. +- `tests/standalone/Stacktrace/Stacktrace.cpp` + +## 3. Edge cases +- Pre-cancelled `stop_token` and expired `ManualClock` deadline return `incomplete == true` while preserving captured raw frames. +- Path traversal (`..`) and symlinks escaping `allowed_source_roots` fail with `unsafe_path`; `INT_MAX` line arithmetic never overflows. + +## 4. Verification commands +```sh +dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-w5-stacktrace -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DVOID_ENABLED_MODULES="Stacktrace;Testing" -DVOID_WARNINGS_AS_ERRORS=ON -DFETCHCONTENT_SOURCE_DIR_BOOST=/home/faumaray/Projects/VoidLibrary/build/_deps/boost-src && cmake --build /tmp/void-w5-stacktrace && /tmp/void-w5-stacktrace/tests/VoidTests --filter "Stacktrace*"' +``` diff --git a/docs/agent-workflow/tasks/S-OBSERVABILITY-01-04.md b/docs/agent-workflow/tasks/S-OBSERVABILITY-01-04.md new file mode 100644 index 0000000..33ae20f --- /dev/null +++ b/docs/agent-workflow/tasks/S-OBSERVABILITY-01-04.md @@ -0,0 +1,31 @@ +# Observability Hooks, Context, Metrics, and Tracing +Task ID: S-OBSERVABILITY-01..04 +Phase: P2 +Status: APPROVED +Contracts: C-01, C-02, C-03, C-04, C-05 + +## 1. Context and baseline +`ObservabilityHooks` and `Observability` do not yet exist in `src/` or `include/Void/Observability/`. Higher modules need zero-dependency instrumentation hooks, `HookLease` drain lifetimes, immutable `ContextSnapshot` propagation, bounded producer-sharded metrics, head-sampled bounded tracing, and a deterministic text snapshot exporter with zero dependency on `Async`, `IO`, `Runtime`, `Log`, `Net`, `Configuration`, or `System`. + +## 2. Deliverables +- `src/ObservabilityHooks/module.cmake` (header-only `Void/Observability/Hooks.hpp`, zero deps) +- `src/Observability/module.cmake` (`INTERNAL_DEPS ObservabilityHooks Core Functional Time Memory`, `EXCLUDE_HEADERS Void/Observability/Hooks.hpp`) +- `include/Void/Observability/Hooks.hpp`: `MetricKind`, `AttributeView`, `MetricPoint`, `DiagnosticEvent`, `ObservationHooks`, `kNullObservationHooks`, `DrainStatus`, `HookRegistrationId`, `HookLease`, `HookSlot` +- `include/Void/Observability/Context.hpp`: `ObservabilityErrorCode`, `make_observability_error` (`kObservabilityErrorDomain = 13`), `TraceId`, `SpanId`, `TraceContext`, `ContextLimits`, `ContextSnapshot`, `ScopedContext` +- `include/Void/Observability/AsyncContext.hpp`: `bind_context`, `ContextAwaitable` (no `#include `) +- `include/Void/Observability/Metrics.hpp` & `src/Observability/Metrics.cpp`: `MetricsLimits`, `InstrumentSpec`, `InstrumentHandle`, `HistogramSnapshot`, `SeriesSnapshot`, `MetricsSnapshot`, `MetricRegistry` +- `include/Void/Observability/Tracing.hpp` & `src/Observability/Tracing.cpp`: `TracingLimits`, `SpanStatus`, `SpanSpec`, `SpanEvent`, `CompletedSpan`, `ExportBatch`, `ExportReport`, `ExportOptions`, `Span`, `SpanExporter`, `CallbackSpanExporter`, `TextSnapshotExporter`, `Tracer` +- `include/Void/Observability/Observability.hpp` +- `tests/standalone/Observability/Observability.cpp` +- `tests/package/ObservabilityHooksOnly/{CMakeLists.txt,main.cpp}` & `tests/package/ObservabilityOnly/{CMakeLists.txt,main.cpp}` registered in `tests/package/InstalledComponents.cmake` + +## 3. Edge cases +- Null hooks allocate zero memory and initialize no backend. +- `HookSlot::detach_and_drain` detects self-drain from within an active callback (`would_deadlock`) and destroys owners strictly outside the lock. +- Exiting producer threads retain their metric shards via `std::shared_ptr` in `MetricRegistry` while `thread_local` caches hold `std::weak_ptr`, preventing leaks when `MetricRegistry` is destroyed. +- Cardinality overflow routes to `__overflow__` and increments overflow counters; exporting respects span/byte caps, retry limits, and deadline/stop without spawning hidden background threads. + +## 4. Verification commands +```sh +dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-w5-obs -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DVOID_ENABLED_MODULES="Observability;Testing" -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-w5-obs && /tmp/void-w5-obs/tests/VoidTests --filter "Observability*" && ctest --test-dir /tmp/void-w5-obs --output-on-failure --timeout 120' +``` diff --git a/include/Void/Functional/Error.hpp b/include/Void/Functional/Error.hpp index 016ef37..e0c78ce 100644 --- a/include/Void/Functional/Error.hpp +++ b/include/Void/Functional/Error.hpp @@ -60,6 +60,10 @@ namespace Void::Result inline constexpr std::uint32_t kIoErrorDomain = 8; inline constexpr std::uint32_t kStorageErrorDomain = 9; inline constexpr std::uint32_t kSystemErrorDomain = 10; + inline constexpr std::uint32_t kLogErrorDomain = 11; + inline constexpr std::uint32_t kStacktraceErrorDomain = 12; + inline constexpr std::uint32_t kObservabilityErrorDomain = 13; + inline constexpr std::uint32_t kResilienceErrorDomain = 14; struct ErrorCode { std::uint32_t domain{kGenericErrorDomain};