Context
The cache observability layer (#178) binds SemanticLoggerInterface (SafeSemanticLogger) as a process singleton with a stack-based session (open / event / close + depth). This matches the pre-existing 1.x logger binding (also a singleton).
Problem
Under concurrent long-running runtimes (Swoole / RoadRunner coroutines sharing one worker process), concurrent requests share the single logger instance. An interleaved open / close violates the LIFO stack, SafeSemanticLogger marks the session broken, and the current request's log is dropped (empty flush) — not merely interleaved.
- Cache behavior is unaffected — logging is a best-effort side-channel that never breaks cache reads/writes.
- The default PHP-FPM deployment (one request per process) is completely unaffected.
- Documented as a Known Limitation in
tests/CACHE_DEPENDENCY_TESTS.md.
Proposed fix
Make the logger request/coroutine-scoped instead of a process singleton:
- bind
SemanticLoggerInterface in a request/coroutine scope, or
- keep a singleton facade that delegates to a per-request session resolved from the host request context.
This is tied to the host flush-lifecycle (the package delegates request-end flush to the host transfer layer), so it should be designed together with the host integration.
Acceptance criteria
- Interleaved concurrent A/B logging test proving logs cannot cross-nest or be dropped.
- Per-request/coroutine session lifecycle integrated with the host flush boundary.
References
Context
The cache observability layer (#178) binds
SemanticLoggerInterface(SafeSemanticLogger) as a process singleton with a stack-based session (open/event/close+ depth). This matches the pre-existing 1.x logger binding (also a singleton).Problem
Under concurrent long-running runtimes (Swoole / RoadRunner coroutines sharing one worker process), concurrent requests share the single logger instance. An interleaved
open/closeviolates the LIFO stack,SafeSemanticLoggermarks the session broken, and the current request's log is dropped (empty flush) — not merely interleaved.tests/CACHE_DEPENDENCY_TESTS.md.Proposed fix
Make the logger request/coroutine-scoped instead of a process singleton:
SemanticLoggerInterfacein a request/coroutine scope, orThis is tied to the host flush-lifecycle (the package delegates request-end flush to the host transfer layer), so it should be designed together with the host integration.
Acceptance criteria
References
src/Log/SafeSemanticLogger.php,src/Log/SafeSemanticLoggerProvider.php,src/DonutCacheModule.php