Skip to content

Make the SemanticLogger session request/coroutine-scoped for concurrent runtimes #179

Description

@koriym

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions