Skip to content

test(coderd/x/chatd): fail partitioned admissions that straddle the partition - #234

Closed
ibetitsmike wants to merge 2 commits into
mainfrom
mike/issue-61-heartbeat-flake
Closed

ibetitsmike wants to merge 2 commits into
mainfrom
mike/issue-61-heartbeat-flake

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

Fixes #61

TestRunnerManager_HeartbeatDoesNotReviveStaleLease failed intermittently in fork-ci chat-tests with timed out waiting for task call kind="generation" for chat B at line 296.

Cause

The fake partition let replica one admit B. The failing run's cleanup log (run 43171336736 attempt 1) shows that replica one's worker owned generation tasks for both A and B, so replica two never got B.

partitionableLimiter.Admit read the partitioned flag before the real admission counted capacity. An acquisition pass on replica one, woken by the message queued on A, could pass that check just before the test set the flag. If it then counted capacity after makeHeartbeatStale made A's lease stale, it found the slot free and admitted B. Replica two then saw B with a fresh lease and A refused, and waited for a B generation that never came.

Fix

partitionableLimiter.Admit checks the flag again after the inner admission and fails the candidate if the partition began meanwhile. The error rolls back the acquisition transaction, so a partitioned replica admits nothing. The test sets the flag before it makes the lease stale, so any count that sees the stale lease also sees the flag. Only the test changes; production admission is not involved.

This edits a test file synced from upstream (7dee434315), so a later upstream sync that changes partitionableLimiter may conflict.

Validation

In Colima (postgres:17), -run TestRunnerManager_HeartbeatDoesNotReviveStaleLease$:

Run Result
Unfixed test with a 500 ms sleep between the flag check and the capacity count (forces the race), -count=5 5/5 FAIL, timed out waiting for task call kind="generation", the CI symptom
Fixed test with the same sleep, -count=5 5/5 PASS
Unfixed test (main's file), -count=50 50/50 PASS (the natural flake is rare)
Fixed test, -count=50 50/50 PASS
Fixed test, -race -count=10 10/10 PASS
TestAdmission_, TestRunnerManager_, TestRenewChatHeartbeats ok

The sleep exists only in the validation overlay; it is not committed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T08:01:00.824269Z 9ea17d3 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.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike. New head 9ea17d3 only merges main (fcd3d20) into the branch.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 9ea17d3f9f

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

Xum posted this on behalf of @ibetitsmike.

Superseded by #236. This PR edits coderd/x/chatd/agentcapacity_regression_internal_test.go, which is synced from upstream, and the fork does not patch upstream code. #236 skips the test in fork-ci instead.

Root cause, kept here for reference: partitionableLimiter.Admit checks its partitioned flag before the real admission counts capacity. A replica-one acquisition pass, woken by the message queued on A, can pass that check just before the test sets the flag, then count capacity after makeHeartbeatStale and admit B itself. Replica two then sees B with a fresh lease, refuses A, and never starts B, so waitCall times out at line 296. The failing log (run 43171336736 attempt 1) shows replica one owning generation tasks for both A and B at cleanup. A 500 ms sleep between the check and the count reproduced it 5/5; rechecking the flag after the inner Admit (this PR) passed 5/5 under the same sleep. A fix belongs upstream in that helper.

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.

test(coderd/x/chatd): fix flaky TestRunnerManager_HeartbeatDoesNotReviveStaleLease

1 participant