Fix StateChangedAt mismatch during container recovery from storage#14482
Open
beena352 wants to merge 6 commits intomicrosoft:feature/wsl-for-appsfrom
Open
Conversation
…At mismatch during container recovery
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes intermittent ContainerRecoveryFromStorage failures by aligning StateChangedAt between live stop/event transitions and recovery by sourcing the timestamp from Docker’s FinishedAt when available.
Changes:
- Extended
WSLAContainerImpl::Transition()to accept an optionalstateChangedAtoverride. - Updated stop and stop-event paths to
InspectContainer()and pass Docker’sFinishedAtintoTransition(). - Preserved existing behavior by defaulting to
std::time(nullptr)when Docker’s timestamp is unavailable/unparseable.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/windows/wslasession/WSLAContainer.h |
Adds optional stateChangedAt parameter to Transition() to allow caller-provided timestamps. |
src/windows/wslasession/WSLAContainer.cpp |
Populates stateChangedAt from Docker FinishedAt in stop paths; updates Transition() to use the override. |
You can also share your feedback on Copilot code review. Take the survey.
OneBlue
reviewed
Mar 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to eliminate a flaky ContainerRecoveryFromStorage test failure by making StateChangedAt use a consistent time source between the “live” stop path and the recovery (Open()) path.
Changes:
- Extend
ContainerEventTrackercallbacks to include aneventTimeextracted from Docker events. - Add an optional
stateChangedAtparameter toWSLAContainerImpl::Transition()and introduceGetDockerFinishedAt()to source Docker’sFinishedAt. - Update container/process event handlers to accept the new callback signature and propagate timestamps into state transitions.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/windows/wslasession/WSLAProcessControl.h | Updates process control event handler signatures to accept event time. |
| src/windows/wslasession/WSLAProcessControl.cpp | Wires updated callbacks through std::bind and ignores unused eventTime. |
| src/windows/wslasession/WSLAContainer.h | Extends Transition() to accept an optional timestamp; adds helper declaration. |
| src/windows/wslasession/WSLAContainer.cpp | Uses Docker FinishedAt on explicit Stop(); uses event-provided time on stop notifications. |
| src/windows/wslasession/ContainerEventTracker.h | Extends callback type to include a timestamp. |
| src/windows/wslasession/ContainerEventTracker.cpp | Extracts time from Docker event JSON and forwards it to callbacks. |
OneBlue
reviewed
Mar 19, 2026
…hangedat-timestamp-consistency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
Fixed a flaky test failure in ContainerRecoveryFromStorage where StateChangedAt differed by 1 second between the live and recovery paths. The root cause was that Transition() used std::time(nullptr) (host clock) while Open() restored from Docker's FinishedAt (VM clock), producing different values.
PR Checklist
Detailed Description of the Pull Request / Additional comments
When a container is stopped, Transition() recorded m_stateChangedAt using std::time(nullptr) (the Windows host clock). When the container was later recovered via Open(), the timestamp was restored from Docker's FinishedAt field (the VM clock). These two clocks could differ by ~1 second, causing the ContainerRecoveryFromStorage test assertion AreEqual(containers[0].StateChangedAt, originalStateChangedAt) to fail intermittently.
Validation Steps Performed
Ran ContainerRecoveryFromStorage test repeatedly, no longer fails.