Skip to content

refactor(coderd/x/chatd): create and finalize debug runs through one helper - #30934

Draft
ibetitsmike wants to merge 5 commits into
mike/chatdebug-debug-run-testsfrom
mike/chatdebug-begin-run
Draft

ibetitsmike wants to merge 5 commits into
mike/chatdebug-debug-run-testsfrom
mike/chatdebug-begin-run

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Chat turns, manual titles, automatic titles and turn status labels each created a debug run on a detached, time-bounded context, rebuilt the run context from the row, and finalized the run by hand. This PR adds chatdebug.Service.BeginRun and StartRun and routes all four through them. It deletes prepareQuickgenDebugCandidate, shortTextCandidate, chatdebugRunContext, debugCreateRunTimeout and a literal 5 second insert timeout.

  • BeginRun inserts the run on a context that ignores the caller's cancellation, with a 5 second limit, and builds the RunContext from its parameters. Chat turns call it and still finalize in runnerDebugTurn.
  • StartRun wraps BeginRun for one model call and returns a context that carries the run plus a function that finalizes it from the call's error. Titles and status labels use it.
  • New TestService_StartRun covers a finalized run, a failed insert and a failed finalize with a mock store, including the warning each failure logs.

Why it is safe: #30933 pins the insert parameters, the run context, the finalize status and summary, and the failed insert for all four call sites. Those tests and the other debug-run, title and quickgen tests pass before and after. CreateRun stores its parameters unchanged, so a RunContext built from the parameters equals one built from the row. A repo-wide search finds no reference to the deleted symbols. Of 13 mutants of BeginRun and StartRun, 12 fail TestService_StartRun; the survivor shortens the insert limit from 5 seconds to 1.

Review focus: log output. Create and finalize failures now log through the chatdebug logger as failed to create debug run and failed to finalize debug run. Before, each call site used its own logger and message. Compaction still creates its debug run by hand, because #30766 changes that code; it can move to StartRun after that PR merges.

Validation:

  • go test -race -count=1 -p 4 -parallel 4 ./coderd/x/chatd/ -run '^(TestActiveServer_ChatTurnDebugRun.*|TestRunnerDebugTurn.*|TestProposeChatTitle_DebugRun|TestArchiveChatDeletesDebugRuns|TestEditMessageDebugCleanup.*|TestQuickgen.*|TestMaybeGenerateChatTitle.*|TestPrepareManualTitleDebugRunCreateFailure)$': the same 25 tests pass before and after.
  • go test -race -count=1 -p 4 -parallel 4 ./coderd/x/chatd/chatdebug/... passes.
  • 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.

…helper

Chat turns, manual titles, automatic titles and turn status labels each
created a debug run on a detached, time-bounded context, rebuilt its run
context from the returned row and finalized it by hand. Add
chatdebug.Service.BeginRun and StartRun and route those call sites through
them. This deletes prepareQuickgenDebugCandidate, shortTextCandidate,
chatdebugRunContext, debugCreateRunTimeout and a literal 5 second insert
timeout.

Create and finalize failures now log through the chatdebug logger with one
message each. The compaction copy is unchanged.
@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:45.176676Z 13fb6e7 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. Chef's kiss.

Reviewed commit: 582be0e9df

ℹ️ 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. Chef's kiss.

Reviewed commit: 13fb6e7154

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

This branch has not been deployed

No deployments
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.

1 participant