Skip to content

test(coderd): make the chatd idle wait fail on timeout - #30967

Draft
ibetitsmike wants to merge 3 commits into
mainfrom
mike/chatd-idle-wait-timeout
Draft

ibetitsmike wants to merge 3 commits into
mainfrom
mike/chatd-idle-wait-timeout

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

chatd.WaitUntilIdleForTest waited up to 10 seconds for the chat worker to go idle, dropped the timeout error, and then drained tracked work, so a test whose worker never went idle passed after a silent 10-second stall. The hook now takes the caller's ctx and returns an error when ctx ends before the worker is idle or the tracked work finishes. Its 26 callers wrap it in require.NoError. The poll loop moves from chatWorker.WaitIdle, whose only caller was the hook, into testhooks.go. It polls on a real 10 ms ticker instead of the server clock, which a mock clock never advances.

Why it is safe

  • The idle check is unchanged: the hook reads the runner manager under the worker's lock and returns at once when the worker or manager is nil. The drain still calls drainInflight, now in a goroutine so that ctx bounds it; that goroutine exits once Close cancels the tracked work.
  • Red-green for the idle wait: with runnerManager.idle forced to return false, TestCreateChatImmediatelyProcessesNewChat passes on main after 10.2 s and fails on this branch at its 25 s context with wait for the chat worker to go idle: context deadline exceeded.
  • Red-green for the drain: a probe that holds one tracked task open stayed blocked in the hook 2 s past a 100 ms context on this PR's first head, then returned nil. It now returns wait for tracked chat work to finish: context deadline exceeded at 100 ms.
  • Hidden timeouts: on main, with the hook instrumented to report errors and idle waits over 1 s, all 119 hook calls in the packages below returned in under 1 s without an error. The runs below pass with the bounded drain, so no test needed a fix.
  • git grep WaitIdle finds no other caller.

Review focus

Callers now pass their own test context instead of getting a fresh 10 s one. Every direct caller, and every caller of coderdtest.WaitForChatSettled and waitForChatProcessed, passes a context of testutil.WaitLong or longer, so the budget grows, but the rest of the test shares it.

The goroutine around the drain adds 9 lines, so this PR adds 7 more lines than it removes. Without it, a stalled title or summary call holds the hook past its deadline.

Validation

  • go test ./coderd/x/chatd/ -count=3: pass.
  • go test ./coderd/ -count=3 -run '<every test in exp_chats_test.go, exp_chats_workspace_file_test.go, and exp_chats_hooks_test.go>': pass.
  • go test ./codersdk/toolsdk/ -count=3 -run '^(TestChatTools|TestCreateChatOrganizationDefaultModel)$': pass.
  • The mutant and the probe use go test -overlay; a copy with a syntax error fails to build, so the overlay applies.
  • The pre-commit hook (make pre-commit) passed.

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

WaitUntilIdleForTest waited up to 10 seconds for the chat worker to go
idle, dropped the timeout error, and then drained tracked work, so a
test whose worker never went idle passed after a silent stall. It now
takes the caller's context and returns an error when the context ends
first. Its 26 callers wrap it in require.NoError.

Move the poll loop from chatWorker.WaitIdle, whose only caller was the
hook, into testhooks.go. It polls on a real ticker instead of the
server clock, which a mock clock never advances.
@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-18T17:06:30.108561Z 03bc5af 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e894c22a1

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

Comment thread coderd/x/chatd/testhooks.go
WaitUntilIdleForTest returned an error when ctx ended before the chat
worker went idle, but it then drained tracked work with no bound, so a
stalled title or summary call held it past the caller's deadline. Run
the drain in a goroutine and return ctx's error if ctx ends first.
@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. Keep it up!

Reviewed commit: 03bc5af92a

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