Skip to content

fix(sdk): keep replay mode active after a virtual context#697

Merged
ParidelPooya merged 2 commits into
mainfrom
fix/replay-mode-virtual-context-child-check
Jul 7, 2026
Merged

fix(sdk): keep replay mode active after a virtual context#697
ParidelPooya merged 2 commits into
mainfrom
fix/replay-mode-virtual-context-child-check

Conversation

@ParidelPooya

Copy link
Copy Markdown
Contributor

checkAndUpdateReplayMode() decided replay was finished whenever the next step id had no checkpoint data. A virtual context (runInChildContext with virtualContext: true) is intentionally not checkpointed, so its id has no data even though its first child IS checkpointed under ${nextStepId}-1. This caused replay mode to switch to execution mode immediately after a virtual context, so operations like logging re-ran (e.g. duplicate logs) during replay.

Fix: when the next step id has no checkpoint data, also probe its first child id before concluding that replay has finished. Composes correctly for root (1 -> 1-1) and nested (2-1 -> 2-1-1) step prefixes.

Adds unit tests covering both the virtual-context case (stays in replay mode) and the genuine end-of-replay case (switches to execution mode).

Issue #, if available: #578

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

checkAndUpdateReplayMode() decided replay was finished whenever the next
step id had no checkpoint data. A virtual context (runInChildContext with
virtualContext: true) is intentionally not checkpointed, so its id has no
data even though its first child IS checkpointed under `${nextStepId}-1`.
This caused replay mode to switch to execution mode immediately after a
virtual context, so operations like logging re-ran (e.g. duplicate logs)
during replay.

Fix: when the next step id has no checkpoint data, also probe its first
child id before concluding that replay has finished. Composes correctly
for root (1 -> 1-1) and nested (2-1 -> 2-1-1) step prefixes.

Adds unit tests covering both the virtual-context case (stays in replay
mode) and the genuine end-of-replay case (switches to execution mode).

Closes #578
@ParidelPooya
ParidelPooya marked this pull request as ready for review July 7, 2026 22:45

@SilanHe SilanHe left a comment

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.

Does this change affect logging? I was under impression this is considered backwards incompatible for logging from our previous discussions as it will result in less logs than before. I can accept this as a bugfix.

@ParidelPooya

Copy link
Copy Markdown
Contributor Author

Does this change affect logging? I was under impression this is considered backwards incompatible for logging from our previous discussions as it will result in less logs than before. I can accept this as a bugfix.

It affects logging, and you're right that the direction is fewer logs. Before this change, replay mode was incorrectly switching to execution mode right after a virtual context, so
modeAware logging wasn't suppressing the replayed log lines — you'd get duplicate logs for statements after a virtual runInChildContext.

This PR restores the intended suppression, so those duplicate replay logs go away. Agreed it's reasonable to take this as a bugfix (it's the fix for #578).

@ParidelPooya
ParidelPooya merged commit 474c623 into main Jul 7, 2026
10 of 12 checks passed
@ParidelPooya
ParidelPooya deleted the fix/replay-mode-virtual-context-child-check branch July 7, 2026 23:26
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.

2 participants