Skip to content

refactor(coderd/x/chatd): set the chatdebug stale threshold at construction - #30932

Closed
ibetitsmike wants to merge 3 commits into
mike/chatdebug-heartbeat-testsfrom
mike/chatdebug-stale-after-option
Closed

ibetitsmike wants to merge 3 commits into
mike/chatdebug-heartbeat-testsfrom
mike/chatdebug-stale-after-option

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

chatd sets the debug stale threshold once, in debugSvcFactory, before any caller can reach the service. This PR replaces Service.SetStaleAfter with a WithStaleAfter option and deletes the code that let a running heartbeat pick up a later change: the atomic threshold, the mutex, the wake-up channel, and the resets_ticker_on_threshold_change subtest that tested them. The step and run heartbeat launchers now share one loop, and the test-only WithClock option is gone.

It also deletes a chatd.go comment that said debug runs do not heartbeat during model streams. Both launchers do.

Why it is safe: SetStaleAfter had one production caller, in debugSvcFactory, which ran before the factory returned the service. A repo-wide search finds no reference to SetStaleAfter, thresholdChan, staleThreshold, staleAfterNanos or the chatdebug WithClock. TestLaunchHeartbeat (#30931) and TestService_FinalizeStale_UsesConfiguredThreshold cover the new code. The second is now a table that also checks that a zero or negative WithStaleAfter keeps DefaultStaleThreshold. All 13 mutants of the option, the shared loop, both launchers and FinalizeStale fail these tests, including ones that make WithStaleAfter accept zero or negative values.

Review focus: the shared heartbeat loop in service.go. The one visible change is a log message: run heartbeat failures now log heartbeat touch failed, the message step heartbeats already used, instead of run heartbeat touch failed.

Validation:

  • go test -race -count=1 -p 4 -parallel 4 ./coderd/x/chatd/chatdebug/... passes before and after.
  • go test -race -count=1 -p 4 -parallel 4 ./coderd/x/chatd/ -run '^(TestActiveServer_ChatTurnDebugRun.*|TestRunnerDebugTurn.*|TestProposeChatTitle_DebugRun|TestArchiveChatDeletesDebugRuns|TestEditMessageDebugCleanup.*)$': the same 16 tests pass before and after.
  • golangci-lint run --fix=false ./coderd/x/chatd/chatdebug/... ./coderd/x/chatd/ reports 0 issues, and the pre-commit hook passed.

Stack

This stack simplifies the chatdebug heartbeat, debug-run and stream wrapper code. Each refactor sits on a test-only layer that pins the behavior it keeps.

  1. test(coderd/x/chatd/chatdebug): cover both debug heartbeat launchers #30931 Cover both debug heartbeat launchers
  2. refactor(coderd/x/chatd): set the chatdebug stale threshold at construction #30932 Set the chatdebug stale threshold at construction
  3. test(coderd/x/chatd): pin the debug runs that turns, titles and status labels record #30933 Pin the debug runs that turns, titles and status labels record
  4. refactor(coderd/x/chatd): create and finalize debug runs through one helper #30934 Create and finalize debug runs through one helper
  5. test(coderd/x/chatd/chatdebug): table the stream wrapper tests and cover their status rules #30980 Table the stream wrapper tests and cover their status rules
  6. refactor(coderd/x/chatd/chatdebug): share one finalize-once lifecycle between the stream wrappers #30981 Share one finalize-once lifecycle between the stream wrappers

Xum, an AI agent, opened this PR for @ibetitsmike and wrote this description.

…uction

chatd sets the debug stale threshold once, inside debugSvcFactory, before
any caller can see the service. Replace Service.SetStaleAfter with a
WithStaleAfter option and delete the atomic, mutex and wakeup channel
that let running heartbeats pick up a runtime change, along with the
subtest that exercised that path. The step and run heartbeat launchers
now share one loop, and the test-only WithClock option is gone.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T16:47:22.104243Z dec2ff8 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: bc1cc67b9f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: dec2ff883b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

ibetitsmike added a commit that referenced this pull request Oct 18, 2026
…-tests

Moves this layer off #30932 and onto the stale-sweep deletion stack
(#30995) without rewriting history. The tree is the new parent plus this
layer's own diff, which is unchanged.
@ibetitsmike
ibetitsmike removed this pull request from stack #30935 October 18, 2026 18:34
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Closing this PR. Mike chose to delete the stale debug-run sweep as dead code instead of reworking it. This PR set the stale threshold at construction, and #30989 deletes that threshold. The replacement stack:

The rest of the old stack now sits on #30995. The branch stays in place.

Xum, an AI agent, closed this PR for @ibetitsmike.

@github-actions github-actions Bot locked and limited conversation to collaborators Oct 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant