Skip to content

refactor(coderd): delete the chat debug run and step heartbeats - #30988

Merged
ibetitsmike merged 3 commits into
mainfrom
mike/chatdebug-delete-heartbeats
Oct 20, 2026
Merged

ibetitsmike merged 3 commits into
mainfrom
mike/chatdebug-delete-heartbeats

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Deletes the chat debug heartbeats. Model calls and streams started a goroutine that touched the step and its run on a ticker, and runner debug turns started a second one that touched the run. Both existed so that FinalizeStale would not mark a live run as interrupted, but nothing in production calls FinalizeStale since #26270. Mike chose to delete the stale sweep as dead code. This PR is the first of three that do it.

  • chatdebug/model.go: Generate, GenerateObject and both stream wrappers no longer start launchHeartbeat.
  • active_turn_debug.go: the runner debug turn no longer starts LaunchRunHeartbeat.
  • chatdebug/service.go: deletes TouchStep, TouchRun, LaunchRunHeartbeat, heartbeatInterval, and the channel that SetStaleAfter closed to wake the heartbeats. The WithClock doc no longer names the heartbeat tickers.
  • Deletes the TouchChatDebugStepAndRun and TouchChatDebugRunUpdatedAt queries with their dbauthz wrappers and tests, and TestLaunchHeartbeat. TestFinalizeStaleChatDebugRows now backdates its run with UpdateChatDebugRun instead of the deleted test-only query.

Why it is safe: the heartbeats wrote only updated_at on chat_debug_runs and chat_debug_steps. These read it:

Reader Why it does not need the heartbeat
FinalizeStaleChatDebugRows and the partial indexes idx_chat_debug_runs_stale and idx_chat_debug_steps_stale No production caller. The next two PRs delete the query, and #31009 drops the indexes in a migration.
DeleteOldChatDebugRuns (dbpurge) See the next paragraph.
DebugPanel.tsx run sort Sorts by started_at || updated_at, and started_at is NOT NULL, so it never falls back to updated_at.
Debug run and step API responses Return updated_at as data. Nothing uses it to decide whether a run is alive.

dbpurge deletes runs whose updated_at is older than the debug retention window, whatever their status, and their steps cascade. The window is agents_chat_debug_retention_days: 30 days by default, and 0 turns the purge off, so dbpurge never deletes a run that was written in the last day. A run's updated_at still moves when the run is created, when each step is inserted (the InsertChatDebugStep CTE), and on every run update and finalize. So dbpurge could only delete a live run if one model call plus the tool calls after it ran for more than a day. The runner finalizes its debug run when the runner context ends, a requires_action wait times out after 5 minutes (the case TouchRun covered), and chatloop aborts a stream that is silent for --chat-stream-silence-timeout, 10 minutes by default (0 turns that guard off).

Mike accepted the cost: a run or step orphaned by a crashed replica stays in_progress until dbpurge deletes it. That is already true on main, because nothing runs the sweep.

This does not touch the chat worker's chat_heartbeats loop that ARCHITECTURE.md describes, and no ARCHITECTURE.md sentence about debug runs becomes false.

Review focus: nothing uses WithClock after this PR, but deleting it here would take this PR past 500 changed lines, so it goes with FinalizeStale in the next PR.

Validation: make gen/db, go build ./coderd/..., and golangci-lint run on the touched packages (0 issues). go test -count=1 passes for ./coderd/x/chatd/chatdebug/..., ./coderd/database/dbauthz/ -run TestMethodTestSuite, ./coderd/database/ -run ChatDebug, ./coderd/x/chatd/ -run Debug and ./coderd/database/dbpurge/. The pre-commit hook passed.

Stack

This stack deletes the stale debug-run sweep, then simplifies the chatdebug debug-run, stream wrapper and step numbering code, drops the indexes the sweep used, and last deletes a runner debug field that lost its only reader with the heartbeats. The debug-run and stream wrapper refactors each sit on a test-only layer that pins the behavior they keep.

  1. This PR: Delete the chat debug run and step heartbeats
  2. refactor: delete chatdebug FinalizeStale and the stale threshold #30989 Delete FinalizeStale and the stale threshold
  3. refactor: delete the FinalizeStaleChatDebugRows query #30995 Delete the FinalizeStaleChatDebugRows query
  4. 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
  5. refactor(coderd/x/chatd): create and finalize debug runs through one helper #30934 Create and finalize debug runs through one helper
  6. 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
  7. refactor(coderd/x/chatd/chatdebug): share one finalize-once lifecycle between the stream wrappers #30981 Share one finalize-once lifecycle between the stream wrappers
  8. refactor(coderd): number chat debug steps in the database #31007 Number chat debug steps in the database
  9. refactor(coderd/x/chatd/chatdebug): delete the process-global step counters #31008 Delete the process-global step counters
  10. chore(coderd/database): drop the chat debug stale-sweep indexes #31009 Drop the chat debug stale-sweep indexes
  11. refactor(coderd/x/chatd): drop the unused runnerCtx from the runner debug turn #31010 Drop the unused runnerCtx from the runner debug turn

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

The heartbeats only refreshed updated_at on in-progress debug runs and
steps so that FinalizeStale would not sweep them. FinalizeStale has no
production caller, so the heartbeats kept nothing alive. Delete both
launchers, Service.TouchStep, Service.TouchRun, the threshold-change
wake-up channel, and the TouchChatDebugStepAndRun and
TouchChatDebugRunUpdatedAt queries with their authz wrappers.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@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-19T12:19:14.176648Z f1cc3d9 Draft marked ready
ℹ️ 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. Nice work!

Reviewed commit: 45f9726f31

ℹ️ 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".

…he WithClock doc

This PR deletes the heartbeat tickers, so the WithClock doc no longer
names them.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: f1cc3d97e8

ℹ️ 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
ibetitsmike marked this pull request as ready for review October 19, 2026 12:13
@pr-queue-manager
pr-queue-manager Bot requested a review from ThomasK33 October 19, 2026 12:14
@ibetitsmike
ibetitsmike merged commit 2397f39 into main Oct 20, 2026
29 checks passed
@ibetitsmike
ibetitsmike deleted the mike/chatdebug-delete-heartbeats branch October 20, 2026 20:32
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 20, 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.

2 participants