Skip to content

fix(coderd/x/agenthooks/dispatch): deflake TestDispatcherTimeoutNoRetry - #28050

Open
ibetitsmike wants to merge 2 commits into
mainfrom
mike/codagt-919-dispatcher-timeout-flake
Open

fix(coderd/x/agenthooks/dispatch): deflake TestDispatcherTimeoutNoRetry#28050
ibetitsmike wants to merge 2 commits into
mainfrom
mike/codagt-919-dispatcher-timeout-flake

Conversation

@ibetitsmike

Copy link
Copy Markdown
Collaborator

Fixes the TestDispatcherTimeoutNoRetry flake from CODAGT-919.

Problem

The test asserted requests.Load() == 1 where the counter was incremented inside an httptest handler, under a hard 50 ms dispatch timeout. On a loaded runner (observed on the test-go-pg (windows-2022) gauntlet) the deadline expired before the handler was scheduled, so timeout classification succeeded but the request count observed 0.

Fix

Replace the real server with a roundTripFunc transport stub (helper already in the file) that records the attempt synchronously, blocks on req.Context().Done(), and returns the context error. The dispatcher's own 50 ms deadline still genuinely expires and takes the timeout classification path in post(), and a retry regression would synchronously invoke the stub a second time, so both assertions keep guarding the same behavior without depending on scheduler timing.

Validation

  • go test ./coderd/x/agenthooks/dispatch -run '^TestDispatcherTimeoutNoRetry$' -count=100 and -race -count=40 pass; full package suite passes with -race.
  • Red toggle: disabling the timeout classification branch in dispatcher.go fails the test with expected: "timeout", actual: "protocol_error", confirming the test still guards that branch.

Mux acted on Mike's behalf to create this PR.

@linear-code

linear-code Bot commented Aug 12, 2026

Copy link
Copy Markdown

CODAGT-919

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: bdae156e22

ℹ️ 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/agenthooks/dispatch/dispatcher_internal_test.go Outdated
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: ecf0af5c7c

ℹ️ 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 August 12, 2026 07:50
t.Cleanup(server.Close)
return &http.Response{
StatusCode: http.StatusOK,
Body: contextBlockedBody{ctx: req.Context()},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would just waiting for req.Context() to expire in the roundTripFunc have the same effect here?

})}

_, _, err := newTestDispatcher(t, server.Client(), server.URL, 50*time.Millisecond).Dispatch(
_, _, err := newTestDispatcher(t, client, "https://hooks.example.com/coder", 50*time.Millisecond).Dispatch(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why change the server URL here?

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.

2 participants