Schedule the action from a monotonic clock, not the wall clock [patch] - #69
Merged
Merged
Conversation
TryRun compared DateTimeOffset.Now against the wall-clock time of the last run. Setting the system clock back (an NTP step, a manual change, a VM resume) put that last run in the future, so the action silently stopped for as long as the clock moved. Scheduling now measures elapsed Stopwatch time since the last run. LastRunTime is still recorded as wall-clock time, for reporting only. Fixes #54 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TRHs5nFW38XRh3KGTHYjE6
|
This was referenced Sep 29, 2026
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.



Fixes #54
Setting the system clock backwards made the action stop silently, for as long as the clock had moved.
Cause
TryRundecided whether to run withDateTimeOffset.Now - LastRunTime > ActionInterval, andLastRunTimewas wall-clock time. When the clock is set back, for example by an NTP step, a manual change, or a VM resume, the last run appears to be in the future. The difference then stays negative until the clock catches up.Fix
HasIntervalElapsed) now measures elapsed time betweenStopwatch.GetTimestamp()readings. It no longer readsDateTimeOffset.Now.RecordRun():LastRunTimestamp(new, internal) drives scheduling.LastRunTimestays as wall-clock time, for reporting only.Stopwatch.GetElapsedTimeonly exists from .NET 7, so a small privateGetElapsedTimedoes the tick conversion for the older targets.Why not
TimeProviderThe triage suggested
TimeProvider, which would needMicrosoft.Bcl.TimeProvideron the older targets. That would add a dependency and a public injection point, which is a minor-version change. The acceptance criterion needs neither. A clock change moves only the wall-clock value the instance holds, and the test can set that value directly, sinceLastRunTimeis internal andInternalsVisibleTothe tests.Test
SettingTheWallClockBackDoesNotDelayTheNextRun:TryRunitself.LastRunTimean hour into the future. That is exactly where a clock set back an hour leaves it.TryRun()to start the action.Results:
main: the test fails, becauseTryRun()returnsfalse.CLAUDE.md's implementation notes now describe the two fields.🤖 Generated with Claude Code
https://claude.ai/code/session_01TRHs5nFW38XRh3KGTHYjE6
Generated by Claude Code