Repository navigation
fix(coderd/x/chatd): keep the waker loop free of full slots and poke new wake-ups - #377
Conversation
…new wake-ups A pass that finds every delivery slot taken now skips the wake-up and records its chat, and the next delivery to end pokes it, so slow deliveries no longer stall pokes, the timer and the sweep. schedule_wakeup and wait_for_events poke the waker after the commit of a new wake-up. The waker can run again after its run returned. Tests cover full slots, each path that makes a watched child done, the two tool pokes and a second run, each with a control without pokes or with a free slot. Refs #347
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d44c6957e
ℹ️ 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".
A freed slot pokes every skipped chat. Each poked chat ran its own due query, so one freed slot cost one query per waiting chat. A pass over a poked chat now records the chat as skipped, with no query, while every slot is taken. A full pass still runs. The end of a delivery takes the skipped set only when it holds chats, so it never ranges the map that dispatch writes after the unlock. Refs #347
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b7c29874d2
ℹ️ 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".
The end of a delivery poked every skipped chat, and the loop then put all but one of them back, so a large backlog cost quadratic map writes and pokes. The skipped chats now wait in a queue. The end of a delivery only signals the loop, and the loop gives each free slot to the chat that waited longest. The ChildWakeupExpires control now waits until the child's wake-up completes before it checks that the parent got nothing. Refs #347
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
# Conflicts: # coderd/x/chatd/ARCHITECTURE.md # coderd/x/chatd/fork_waker_internal_test.go
Restacked on |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ef8a530111
ℹ️ 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".
Fixed the P2 on queue order in |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2a2371e9de
ℹ️ 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".
Fixed the full-pass queue order P2 in |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Merged at head Gates on this exact head:
Tests I ran on
Review notes:
Not exercised:
|
Closes #347
Follow-ups to the waker of fork-chat-wakeups (
coderd/x/chatd/fork_waker.go). No new experiment, no migration.Changes per item
wakeupReadFitsandwithWakeupDeadline, so this item no longer applies. Onmaina delivery no longer reads pull requests, since the pull request poller does that off the delivery path. feat: the workspace agent reports chat process events #376 merged asada0207617, and this branch is restacked on it by a merge ofmain.dispatchno longer waits for a slot. When all 8 slots are taken, it skips the due wake-up and queues its chat. While every slot is taken, a pass over a poked chat queues the chat too, with no query. The end of a delivery signals the loop, and the loop gives each free slot to the queued chat that waited longest. The slot and the queue change under the same lock, so a skipped wake-up is never lost. A freed slot costs about one pass and one query, however many chats wait. A full pass still runs while the slots are taken, so the timer stays right.TestWakerDeliversWhenChildFinishes),SetChatWakeupStatuspokes),SendMessagestarts a turn, and the end of that turn publishes),archive_agentarchiving the child (the publish buffer ofsetSubtreeArchived).schedule_wakeupandwait_for_eventspoke the chat after the create commit./loopcreates its wake-up inside the message send, and that commit publishes. No API route creates wake-ups.withWakeupDeadlineandwakeupReadFits, so this nit no longer applies.run: now safe to run again. When a run returns, it resetsstarted, the timer, the pending pokes and the skipped chats. A second call while a run is active still returns at once. The doc comment says so.ARCHITECTURE.md("Wake-up delivery") now describes the tool pokes, the skip of a full slot and the poke after it, the child-done paths, and the second run.Tests
New tests in
coderd/x/chatd/fork_waker_internal_test.go:TestWakerFullSlotsDoNotStallTheLoop/SlotsFull: 8 slow deliveries hold every slot. The first pass still ends and arms the timer for a later wake-up. The skipped wake-up is delivered once a slow delivery ends./SlotLeft: 7 slow deliveries, so the plain wake-up is delivered at once.TestWakerFreedSlotCostsOneList: 8 deliveries hold every slot and 20 chats wait. When one slot frees, the chat skipped first is delivered. The other 19 stay queued in order, no chat is poked, and the run costs 2 lists in total.TestWakerChildDonePathsDeliver/{ChildWakeupExpires,ChildWakeupCanceled,QuestionAnswered,ChildArchived}/Pokes: the idle parent's wake-up is delivered right after the change./NoPokes: with pokes cut off, nothing is delivered until the next full pass of the clock.TestWakerScheduleWakeupArmsTimer/Pokes: the tool call arms the timer for 120 s at once.TestWakerWaitForEventsDeliversDoneChild/Pokes: a wait on a child that is already done delivers with no clock advance./NoPokes: the timer is armed, or the wake-up delivered, only at the sweep.TestWakerQueueBeforeOtherChats/{FreshPoke,FullPass}: one slot is free and chat A waits in the queue. Chat B is poked in the same drain, or a full pass lists B first. A gets the slot and B waits behind it.FreshPokefails with thedrainofef8a530111(B gets the slot);FullPassfails without the queue check indispatch.TestWakerRunsAgain: a second run while one is active returns. A new run after the first returned delivers a new wake-up.startWakernow gives the server a mock clock of its own, set to the waker's time, so the tools create wake-ups at the test's time. The server's tickers stay off the waker's clock.Commands run on head
7f9bf6c7df(restacked onada0207617, plus the queue order fixes) (all underflock ~/.fork-go.lock, cold build):go test ./coderd/x/chatd/ -run 'TestWakerFullSlots|TestWakerFreedSlot|TestWakerChildDonePaths|TestWakerScheduleWakeupArmsTimer|TestWakerWaitForEventsDeliversDoneChild|TestWakerRunsAgain' -count=20 -race -v(withTestWakerQueueBeforeOtherChatsadded to the pattern): PASS: 540 PASS lines (tests and subtests), 0 FAIL.go test ./coderd/x/chatd/ -run 'TestWaker|TestScheduleWakeup|TestWaitForEvents|TestProcess|TestPullRequest|TestWakeup|TestArchiveAgent|TestSecret|TestDescendantQuestion' -count=1 -race: PASS, 219 PASS lines, 0 FAIL.go test ./coderd/x/chatd/... -count=1: PASS, 21 packages ok.golangci-lint run --config=.golangci.new-code.yaml --new-from-merge-base=origin/main ./coderd/x/chatd/...: 0 issues.paralleltestctxandintxcheckon the package: clean.Fail-before checks (each fix reverted alone, then restored):
TestWakerScheduleWakeupArmsTimer/PokesandTestWakerWaitForEventsDeliversDoneChild/PokesFAIL (timeout). The NoPokes controls pass.TestWakerFullSlotsDoNotStallTheLoop/SlotsFullFAILS (the pass never arms the timer)./SlotLeftpasses.started:TestWakerRunsAgainFAILS.drainoff:TestWakerFreedSlotCostsOneListFAILS (21 lists, expected 2).drainofef8a530111, which passed poked chats before the queue: the fresh poke case FAILS (the poked chat gets the slot).dispatch:TestWakerQueueBeforeOtherChats/FullPassFAILS (the chat the full pass lists first gets the slot).An earlier Codex finding, the shared empty skipped map, no longer applies: the end of a delivery does not read the skipped chats any more. The queue order and the no-poke assertions have no fail-before run, because the older code has no queue to inspect.
ChildWakeupExpires/NoPokesnow waits until the child's wake-up completes before it checks the parent.Not exercised: a real multi-replica deployment, and a real slow delivery holding the slots. The tests use a stub delivery that blocks. The old shared-map race was not reproduced under
-race.