From f08bb652b4931ce009f153e0f4484385ec46274b Mon Sep 17 00:00:00 2001 From: Hugo Dutka Date: Tue, 16 Jun 2026 14:01:14 +0200 Subject: [PATCH] chore(coderd/x/chatd/chatdebug): clean up after the chatd refactor (#26345) Addresses https://github.com/coder/coder/pull/26109#discussion_r3379164243 and https://github.com/coder/coder/pull/26109#discussion_r3379151284 --- coderd/x/chatd/chatdebug/service.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/coderd/x/chatd/chatdebug/service.go b/coderd/x/chatd/chatdebug/service.go index 89a5667cda..541e8c3b9b 100644 --- a/coderd/x/chatd/chatdebug/service.go +++ b/coderd/x/chatd/chatdebug/service.go @@ -524,7 +524,9 @@ func (s *Service) TouchStep( // TouchRun bumps the run's updated_at timestamp without changing any // other fields. Runner-owned debug turns use this while no model step is -// active, such as requires-action waits. +// active, such as requires-action waits. It is a no-op when the service +// is nil or either ID is uuid.Nil, since debug tracking is optional and +// callers may not have an open run. func (s *Service) TouchRun(ctx context.Context, runID uuid.UUID, chatID uuid.UUID) error { if s == nil || runID == uuid.Nil || chatID == uuid.Nil { return nil @@ -538,7 +540,9 @@ func (s *Service) TouchRun(ctx context.Context, runID uuid.UUID, chatID uuid.UUI } // LaunchRunHeartbeat starts a goroutine that periodically touches an -// open run until done is closed or ctx is canceled. +// open run until done is closed or ctx is canceled. It is a no-op when +// the service is nil, either ID is uuid.Nil, or done is nil, since debug +// tracking is optional and callers may not have an open run. func (s *Service) LaunchRunHeartbeat(ctx context.Context, runID uuid.UUID, chatID uuid.UUID, done <-chan struct{}) { if s == nil || runID == uuid.Nil || chatID == uuid.Nil || done == nil { return @@ -548,7 +552,7 @@ func (s *Service) LaunchRunHeartbeat(ctx context.Context, runID uuid.UUID, chatI interval := s.heartbeatInterval() ticker := s.clock.NewTicker(interval, "chatdebug", "run-heartbeat") defer ticker.Stop() - resetTicker := func() { + maybeResetTicker := func() { if newInterval := s.heartbeatInterval(); newInterval != interval { interval = newInterval ticker.Reset(interval, "chatdebug", "run-heartbeat") @@ -562,7 +566,7 @@ func (s *Service) LaunchRunHeartbeat(ctx context.Context, runID uuid.UUID, chatI return case <-thresholdCh: thresholdCh = s.thresholdChan() - resetTicker() + maybeResetTicker() case <-ticker.C: if err := s.TouchRun(ctx, runID, chatID); err != nil { s.log.Debug(ctx, "run heartbeat touch failed", @@ -570,7 +574,7 @@ func (s *Service) LaunchRunHeartbeat(ctx context.Context, runID uuid.UUID, chatI slog.F("run_id", runID), ) } - resetTicker() + maybeResetTicker() } } }()