Files
coder/coderd
Michael Suchacz 98104d10fe chore(coderd/database): drop the chat debug stale-sweep indexes (#31009)
Drops `idx_chat_debug_runs_stale` and `idx_chat_debug_steps_stale`, the
partial `updated_at` indexes that migration 000468 added for the
`FinalizeStaleChatDebugRows` query. #30995 deleted that query, so
nothing reads these indexes, but every debug run and step write still
updates them.

**Why it is safe:** no remaining query can use them. A partial index on
`updated_at WHERE finished_at IS NULL` only serves queries that filter
on `finished_at IS NULL`, and the one query that still does, the
`locked_run` CTE in `InsertChatDebugStep`, finds the run by primary key.
`DeleteOldChatDebugRuns` filters on `updated_at` alone and uses
`idx_chat_debug_runs_updated_at` from migration 000487, which stays. The
down migration recreates both indexes as 000468 defined them.

**Review focus:** the migration number. 000632 follows `main`'s newest
migration, 000631 from #31059. If `main` gains another migration first,
this one moves to the next free number.

Validation:
- `make gen` changes only `dump.sql`, which loses the two `CREATE INDEX`
lines. The renumber to 000632 leaves it unchanged.
- `go test -count=1 ./coderd/database/migrations/` passes on this
branch, where `main`'s 000631 and this 000632 both apply. The run
includes `TestMigrate/UpDownUp` (every migration up, down and up again)
and `TestMigrationChain`.
- 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. #30988 Delete the chat debug run and step heartbeats
2. #30989 Delete `FinalizeStale` and the stale threshold
3. #30995 Delete the `FinalizeStaleChatDebugRows` query
4. #30933 Pin the debug runs that turns, titles and status labels record
5. #30934 Create and finalize debug runs through one helper
6. #30980 Table the stream wrapper tests and cover their status rules
7. #30981 Share one finalize-once lifecycle between the stream wrappers
8. #31007 Number chat debug steps in the database
9. #31008 Delete the process-global step counters
10. This PR: Drop the chat debug stale-sweep indexes
11. #31010 Drop the unused `runnerCtx` from the runner debug turn

> Xum, an AI agent, opened this PR for @ibetitsmike and wrote this
description.
2026-10-22 07:42:22 +00:00
..