Skip to content

Fix StateChangedAt mismatch during container recovery from storage#14482

Open
beena352 wants to merge 6 commits intomicrosoft:feature/wsl-for-appsfrom
beena352:user/beenachauhan/fix/statechangedat-timestamp-consistency
Open

Fix StateChangedAt mismatch during container recovery from storage#14482
beena352 wants to merge 6 commits intomicrosoft:feature/wsl-for-appsfrom
beena352:user/beenachauhan/fix/statechangedat-timestamp-consistency

Conversation

@beena352
Copy link

@beena352 beena352 commented Mar 19, 2026

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

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • [x ] Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

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.

  • Added an optional stateChangedAt parameter to Transition() with a default of std::nullopt (falls back to std::time(nullptr), preserving existing behavior for all other callers).
  • In Stop() and OnEvent(Stop), call InspectContainer() to retrieve Docker's FinishedAt timestamp and pass it to Transition(), so the live path and recovery path both use the same time source.

Validation Steps Performed

Ran ContainerRecoveryFromStorage test repeatedly, no longer fails.

@beena352 beena352 requested a review from a team as a code owner March 19, 2026 18:00
Copilot AI review requested due to automatic review settings March 19, 2026 18:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 optional stateChangedAt override.
  • Updated stop and stop-event paths to InspectContainer() and pass Docker’s FinishedAt into Transition().
  • 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.

Copilot AI review requested due to automatic review settings March 19, 2026 19:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 ContainerEventTracker callbacks to include an eventTime extracted from Docker events.
  • Add an optional stateChangedAt parameter to WSLAContainerImpl::Transition() and introduce GetDockerFinishedAt() to source Docker’s FinishedAt.
  • 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.

Copilot AI review requested due to automatic review settings March 20, 2026 18:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

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