Skip to content

Add replay-aware workflow logging to embedded PHP, the PHP SDK and Rust #227

Done

Description

@rmcdaniel

Problem

Workflow code is replayed every time a run wakes up. In embedded mode, the engine replays history on each wake-up, so a log line in workflow code is written again for every completed step. A workflow with 50 steps logs its opening line 50 times.

Python avoids this with ctx.logger, which is silent during replay (source). Embedded PHP, the PHP SDK and the Rust SDK offer no replay-aware logger and no way for workflow code to know it's replaying. The workflow constraints don't mention logging.

Users then either get duplicate, misleading log lines, or write workflow logs through a side effect or activity just to avoid them.

Source-verified, not reproduced.

Acceptance criteria

  • Embedded PHP, the PHP SDK and the Rust SDK provide a workflow logger that writes only when code runs for the first time, not during replay. It routes through the host's normal logger and adds run identity.
  • Tests show one log line per step across a multi-step run, including after a worker restart and a cold replay.
  • The workflow constraints page and each SDK guide explain logging from workflow code. They cover the replay-aware logger, why ordinary loggers duplicate lines, and keeping log handlers non-blocking so they don't stall the worker.

Activity

  1. added
    enhancement
    kind:feature
    kind:cross-repository
    priority:P3
    repo:workflow
    repo:sdk-php
    repo:sdk-rust
    on Oct 20, 2026
  2. rmcdaniel commented on Nov 4, 2026

    @rmcdaniel
    MemberAuthor

    General open-item pass, November 4. Owner: Workflow, sdk-php and sdk-rust; sdk-python as reference; General for coordination.

    Next action: Map replay-aware logging source and add controls proving no duplicate replay emission while preserving new execution/error observations.

    Action taken in this pass: Asked all relevant SDK/Core owners for implemented evidence or the next source slice; ordinary logging suppression must not be claimed as durable external-effect semantics.

    General retains the cross-repository follow-through. Existing operator stops and exact source/release/production gates remain binding; the item stays open until its actual acceptance is evidenced.

  3. rmcdaniel commented on Nov 4, 2026

    @rmcdaniel
    MemberAuthor

    Python reference audit (owner sdk-python): _ReplayLogger suppresses calls during committed replay; _ReplayLifetime and generator-lifecycle controls keep reconstruction/disposal quiet (tests). ctx.logger is the author-facing adapter over normal Python logging. These are shipped source boundaries, not a new published cold-restart run.

    Two limits must remain explicit in the portable reference: the internal replay flag is not currently a public WorkflowContext.is_replaying accessor, and this adapter forwards to the host logger without itself guaranteeing attached run identity. General owns the portable public-state/identity contract; sdk-python owns the corresponding additive accessor/logger-context slice if required. durable-workflow-github-io owns the guide/constraint wording; PHP/Rust/workflow retain their logger implementations. Next proof must cover multi-step live/cold replay and non-blocking host logging against published artifacts. Advanced today: mapped the precise guard/lifetime source and recorded the identity/public-state gaps, so the central issue cannot be closed from a Python-only reference or source test.

  4. rmcdaniel commented on Nov 4, 2026

    @rmcdaniel
    MemberAuthor

    Rust acceptance map / complete owner pass: Rust source owner sdk-rust; shared replay-boundary coordination General with sdk-python reference. Current4.12.0 uses host tracing for worker/client diagnostics but has no replay-aware workflow logger. I checked the public context and source surface; ordinary tracing is not a delivered replacement for this requirement.

    Next action is a workflow-scoped logger using the host logger and immutable run identity, emitting only across new execution boundaries and suppressing already-replayed steps. Coordinate its replay-state boundary with the clock/interceptor work; I requested Python's accepted reference rather than guessing from wall time or total history length. Source acceptance must show one log per step across multiple activations, restart and cold replay, with nonblocking handlers and no command/history mutation. SDK/constraints guides and qualified publication remain separate completion gates. No runtime or new implementation is claimed by this inventory.

  5. rmcdaniel commented on Nov 4, 2026

    @rmcdaniel
    MemberAuthor

    PHP owner sdk-php has confirmed that current WorkflowContext exposes neither a supported replay-aware logger nor public replay-state control. Host diagnostics/worker logging and the metrics recorder do not satisfy workflow-code log suppression.

    Next PHP source slice: a host/PSR logger adapter driven by the replayer's committed-prefix versus fresh-execution boundary, carrying original run identity and suppressing committed replay/query observations. Tests must include multi-step, fresh worker/cold replay, repeat task attempt, exception and logger-failure behavior; source handling must preserve commands and deadlines. This follows the current P2 client/identity work rather than being treated as an external runtime dependency.

    sdk-python owner: please return the exact current published logger boundary and its cold-replay controls. General: please confirm the portable claim remains suppression of replayed committed code, not durable exactly-once log delivery for an uncommitted/crashed attempt. Workflow owner owns embedded integration; Website owner owns the constraints/all-locale guidance, including non-blocking log handlers. These requests settle the shared semantics without claiming a PHP implementation, package or live acceptance.

  6. rmcdaniel commented on Nov 4, 2026

    @rmcdaniel
    MemberAuthor

    General's portable logger contract uses the same live replay-state boundary as226. Route observations to the host logger with exact namespace/workflow/run identity; suppress committed-history replay, including cold replay and completed-step worker replacement, without letting log callbacks alter durable commands. Keep handlers bounded/non-blocking and logging failures from manufacturing task success or new history.

    A log emitted in an uncommitted task region may repeat if the task crashes/retries; a replay-aware process logger is not an exactly-once durable outbox. Tests must separately prove one line for each committed step across restart/cold replay and expose the uncommitted crash window honestly. Do not close this accepted issue from a logger facade or source-only sample; the original cross-runtime tests, normally published behavior and guides remain required. Python is the current reference owner; Workflow/PHP/Rust prepare their owned source slices and automatic identity/replay-state controls. No new runtime cohort is admitted here.

  7. rmcdaniel commented on Nov 4, 2026

    @rmcdaniel
    MemberAuthor

    Workflow owns the embedded replay-aware logger source; PHP/Rust SDKs own their wrappers and Python is the reference. Next is the precise consumed/new-execution boundary and normal host logger/run identity adapter, with multi-step/cold-replay/error controls. Existing ordinary logger calls and tracing lifecycle events do not satisfy one authored log per first execution.

    Coordinate the replay flag with #226's worker context and #215's consumed-event clock; do not infer it from latest poll totals or an arbitrary history scan. Preserve original workflows and make delivery guarantees truthful: suppressing replay duplicates does not make logging exactly once across crashes or authorize durable external effects. I asked the SDK owners for their existing reference vectors; no producer, logger side-effect marker or runtime allocation is assigned here.

  8. rmcdaniel commented on Nov 4, 2026

    @rmcdaniel
    MemberAuthor

    PHP follow-through: General's contract at6642366435 is received. The previous portable-semantics question is answered: suppress committed replay using a live authoritative cursor; do not promise exactly-once logs in the uncommitted crash/retry region. I inspected PHP's normalized-step cursor and completed-history handling as the candidate shared foundation for #226/#227. A new-run/partial-prefix/completed-history/cold-replacement/query test set must distinguish those regions without changing captured commands.

    sdk-php owns the separate logger/accessor source after the current ready metrics slice. Automatic exact namespace/workflow/run identity must come from the bound worker context, and user log context must not override it. Bounded host-handler failures must not manufacture task success/history. Python owns the reference vectors and Workflow its embedded adapter. Published behavior, original cross-runtime tests and all-locale guidance remain before parent closure; no new runtime cohort is started.

  9. rmcdaniel commented on Nov 11, 2026

    @rmcdaniel
    MemberAuthor

    Workflow: not started. An embedded replay-aware logger (first run only, host logger, run identity), after the replay-cursor contract it shares with the PHP SDK. Owner: workflow.

  10. 24 remaining items

  11. rmcdaniel commented on Nov 25, 2026

    @rmcdaniel
    MemberAuthor

    Replay-aware workflow logging is merged in embedded PHP and the PHP SDK. Rust already shipped it in 4.17.0. The embedded and PHP SDK changes are not released yet.

    • workflow (embedded) #1296, merged as 52461f7. The code was reviewed at ae5b0d1, and main was then merged in without conflicts.
      • $this->logger(?string $channel) returns a PSR-3 logger that writes through the Laravel logger. Each line carries workflow_instance_id, workflow_run_id, workflow_type and namespace.
      • $this->replayState() returns Replaying, Executing or Unavailable, and isReplaying() is the boolean form.
      • The executor records the committed step boundary for each task. Lines are written after the task's transaction commits.
      • If the workflow parks on a pending select() handle without recording a step, those lines are written by the task that moves past the park.
      • A live-continuation fallback doesn't repeat lines. Queries and update validators never log.
    • sdk-php #490, merged as 4e645e6 (reviewed head 1ec3ddc).
      • WorkflowContext::logger(), replayState() and isReplaying().
      • The final replay's lines go through the Worker's PSR-3 logger, and only after the Server accepts the workflow-task completion.
      • Superseded, speculative and declined, or refused passes write nothing.
      • Code parked on a pending child or handle logs once, in the task that moves past it.

    Tests show one line per step:

    • Embedded: cold replays with a restart before every task, real worker processes, live fallback, one or two losing select() handles, rollback, and logger failure.
    • PHP SDK: replays by fresh Replayers, Worker restarts, a cold replay of the completed run, a two-child fan-out, and a failed task followed by an update task.

    Both PRs passed independent review after fixes: four rounds for embedded and three for the PHP SDK.

    Remaining:

    • Docs-site guides: durable-workflow.github.io#617, which covers the constraints page and the PHP guide in all 8 locales. Its version numbers need confirming at release.
    • Known gaps, non-blocking:
      • In the PHP SDK, cancel_selection_operation counts as progress, so a narrow select → cancel → await path can still repeat one line.
      • The embedded bridge runner never sets a boundary, so the logger is silent there.
      • Embedded workflows that already define logger(), replayState() or isReplaying() must rename them. The CHANGELOG says so.
  12. rmcdaniel commented on Nov 26, 2026

    @rmcdaniel
    MemberAuthor

    Released: the replay-aware workflow logger ships in Workflow 2.42.0 (embedded $this->logger() / replayState()) and PHP SDK 3.32.0 (WorkflowContext::logger()). Rust shipped it earlier in 4.17.0. The guides are merged in durable-workflow.github.io#617 (all 7 locales). The acceptance is met, so I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementkind:cross-repositorykind:featurepriority:P3repo:sdk-phprepo:workflowstatus:ready

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions