Skip to content

feat: context aware replay status#488

Merged
wangyb-A merged 8 commits into
mainfrom
context_replay
Jun 30, 2026
Merged

feat: context aware replay status#488
wangyb-A merged 8 commits into
mainfrom
context_replay

Conversation

@wangyb-A

@wangyb-A wangyb-A commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available: first piece of #389

Summary

Track replay status per-context instead of as a single execution-wide flag.

Changes

  • context.py: DurableContext owns its replay status, seeded from its
    creator and refined per-operation via a _replay_aware() context manager.
    Added public context.is_replaying().
  • logger.py: Logger consults a per-context is_replaying callable
    instead of holding ExecutionState.
  • state.py: removed the global replay machinery (track_replay,
    is_replaying, _visited_operations); added has_prior_operations() for
    execution-level first-invocation detection.
  • execution.py: seeds the root context's status; uses
    has_prior_operations() for the plugin is_first_invocation flag.
  • concurrency/executor.py: branches track their own status; removed the
    per-branch track_replay call.

Replay boundary behavior

_replay_aware() flips REPLAY→NEW at three points:

  • before an op with no checkpoint (brand-new code),
  • after a non-terminal op (the resume point — its own logs stay deduped),
  • after a completed op when the next op doesn't exist yet (so bare logs
    immediately after a wait are treated as new, not suppressed).

The third case fixes a regression where a log right after a wait was
silently dropped on replay.

Testing

Logging from examples:

Invocation 1 (requestId 8b1e9590) — first run, suspends at parent wait

message is_replaying operationName
Workflow started (before wait) false
Preparing item prepare
Prepared, about to wait false

Invocation 2 (requestId a46ca6bd) — parent wait fired

message is_replaying / child_is_replaying
Resumed after wait false
Auditing in child context (before child wait) false (child)
(before-wait lines from invocation 1 are NOT repeated — de-duplicated)

Invocation 3 (requestId 22d99bc2) — child wait fired

message child_is_replaying operationName
Resumed in child context (after child wait) false
Finalizing item finalize
Workflow completed
(all parent + child before-wait lines NOT repeated — de-duplicated)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@wangyb-A wangyb-A marked this pull request as ready for review June 24, 2026 18:07
@zhongkechen

Copy link
Copy Markdown
Contributor

Tests failing

zhongkechen
zhongkechen previously approved these changes Jun 29, 2026
@wangyb-A

Copy link
Copy Markdown
Contributor Author

need to merge the change of #496

Alex Wang added 2 commits June 30, 2026 13:02
- Add replay status for map and parallel branches
- Use per-context replay for hooks
- Add logging assertion for examples
def run_in_child_handler() -> ResultType:
return self.execute_item(child_context, executable)

result: ResultType = child_handler(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need wrap this call with self._replay_aware() like the other operations in context?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the replay status is already checked and flipped above.
executor call child_handler directly (skip context) so we cannot directly reuse replay_aware annotation

@wangyb-A wangyb-A merged commit 8664294 into main Jun 30, 2026
130 of 131 checks passed
@wangyb-A wangyb-A deleted the context_replay branch June 30, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants