Skip to content

Conversation

@johnstcn
Copy link
Member

@johnstcn johnstcn commented Jan 26, 2026

Refactors existing usage of time.Sleep etc. to use github.com/coder/quartz.

🤖 Written by Claude Opus 4.5, reviewed by me.

@github-actions
Copy link

✅ Preview binaries are ready!

To test with modules: agentapi_version = "agentapi_175" or download from: https://github.com/coder/agentapi/releases/tag/agentapi_175

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 pull request integrates the coder/quartz library to provide a clock abstraction throughout the codebase, enabling better testability by allowing time-dependent code to use mock clocks in tests.

Changes:

  • Added github.com/coder/quartz dependency to replace direct time package usage
  • Replaced time.Now(), time.Sleep(), time.After(), and time.Since() calls with clock-based equivalents
  • Updated test files to use quartz.NewMock(t) for deterministic time-based testing

Reviewed changes

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

Show a summary per file
File Description
go.mod Added github.com/coder/quartz v0.1.2 dependency and removed unused go.uber.org/atomic
go.sum Updated dependency checksums including quartz and transitive dependencies
lib/util/util.go Added Clock field to WaitTimeout struct and replaced time operations with clock-based equivalents
lib/termexec/termexec.go Added clock field to Process struct and replaced time operations with clock methods
lib/screentracker/conversation.go Replaced GetTime function with Clock field and updated all time operations to use the clock
lib/screentracker/conversation_test.go Updated tests to use mock clocks for deterministic testing
lib/httpapi/server.go Added clock field to Server struct and updated ticker usage in snapshot loop

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@johnstcn johnstcn requested review from 35C4n0r and mafredri January 26, 2026 18:26
@johnstcn johnstcn marked this pull request as ready for review January 26, 2026 18:26
@johnstcn johnstcn requested a review from Copilot January 26, 2026 18:27
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 7 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

time.Sleep(1 * time.Second)
timer := c.cfg.Clock.NewTimer(1 * time.Second)
defer timer.Stop()
<-timer.C
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: Maybe this could be a little helper? Say, sleep(clock, time.Second)? Seems re-usable (at least below) and clarifies the code.

Might be a useful addition to quartz. Having <-clock.After(time.Second) would also be nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

interval := minInterval
if timeout.InitialWait {
time.Sleep(interval)
initialTimer := clock.NewTimer(interval)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
initialTimer := clock.NewTimer(interval)
initialTimer := clock.NewTimer(interval)
defer initialTimer.Stop()

return nil
}
time.Sleep(interval)
sleepTimer := clock.NewTimer(interval)
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: Consider wrapping in if err := func() error { ... } so you can defer stop to avoid stopping on each case.

Alternatively, perhaps a helper function that contains the select since at least 2 are identical.

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