fix(cli): use quartz clock in waitForTaskIdle for immediate first poll#25648
Merged
Conversation
waitForTaskIdle used time.NewTicker(5s) which delays the first poll by 5 seconds. Debugger tracing proved the failure mechanism: on slow CI (Windows), the first poll at 5s sees "working" (idle patch has not landed due to goroutine scheduling), needs poll #2 at 10s, but the 25s context expires before it fires. Two changes: 1. Use r.clock.NewTicker (quartz) with time.Nanosecond initial interval and Reset(5s) for immediate first poll. Tests inject a mock clock via clitest.NewWithClock for deterministic control. 2. Rewrite WaitsForWorkingAppState test with quartz traps (NewTicker + TickerReset) for deterministic synchronization instead of racing goroutines. Fix PausedDuringWaitForReady sync point. Closes https://linear.app/codercom/issue/DEVEX-381
johnstcn
approved these changes
May 25, 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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
waitForTaskIdleusedtime.NewTicker(5s)which delays the first poll by 5 seconds. On slow CI (Windows), this causescontext deadline exceededbecause the polling budget is too tight.Two changes:
r.clock.NewTicker(quartz) withtime.Nanosecondinitial interval andReset(5s)for immediate first poll. Tests inject a mock clock viaclitest.NewWithClockfor deterministic control.WaitsForWorkingAppStatetest with quartz traps (NewTicker+TickerReset) for deterministic synchronization instead of racing goroutines. FixPausedDuringWaitForReadysync point.Root cause proof
Added
fmt.Fprintfinstrumentation towaitForTaskIdlelogging: function entry time, each ticker fire with elapsed time,task.Status,task.CurrentState(nil or not,.State,.Message), which switch branch was taken, and context cancellation with total poll count.Normal case (ran
go test -v -count=1 -run Test_TaskSend/WaitsForWorkingAppState ./cli/):Poll #1 fires at 5s, sees idle (the test patched to idle before the first tick), returns. Test passes in 5.92s.
Failure reproduction (modified test to use
testutil.WaitShort(10s) context and delayed the idle patch by 6s viatime.AfterFunc, then ran the same command):Poll #1 fires at 5s, sees "working" (idle patch delayed). Poll #2 would fire at 10s, but context expires at 9.96s. Only 1 poll occurred; the function never observed "idle".
This matches the CI failure: 26.14s runtime with a 25s context,
context deadline exceeded.dlv confirmation (ran
dlv test ./cli/ -- -test.v -test.run Test_TaskSend/WaitsForWorkingAppState, breakpoint attask_send.go:175): breakpoint hit once (hits goroutine(2758):1 total:1), confirming one poll per 5s tick.Closes https://linear.app/codercom/issue/DEVEX-381