Repository navigation
feat(coderd): record a capacity_wait stage on chat acquisition - #29805
jscottmiller wants to merge 5 commits into
Conversation
|
/coder-agents-review |
|
Chat: Review posted | View chat Review history
deep-review v0.13.0 | Round 1 | Last posted: Round 1, 18 findings (4 P2, 4 P3, 7 P4, 3 Nit), COMMENT. Review Finding inventoryFinding inventory: PR #29805Findings
Contested and acknowledgedLaw analysisNot run. Effective additions 386 (threshold 1000). Round logRound 1Full panel (round 1). Netero first pass: 1 P2 (CRF-1), no P0, panel proceeded. Specialists by trigger: Ging-Go (.go), Knuckle (query change), Killua (acquisition loop, cache), Takumi (lock-free map, sync.Map), Kurapika (dbauthz.AsChatd read), Ryosuke (Go package layering), Luffy (new stage feature). Core: Pariston, Mafuuu. Pool: Bisky (tests), Gon and Leorio (once-per-PR floor). 12 panel reviewers at the multi-domain target, plus wildcard Kite (random draw from distilled set). Kurapika: no findings. Cross-check: CRF-2 convergent (Pariston reproduced 20 of 25 refused chats remembered after one pass); Leorio's proposed 30s-bound doc text contradicts it and was merged (CRF-11). CRF-4 convergent across four reviewers, two reproductions (Takumi, Mafuuu); Kite's P2 wins the tiebreak (tail inflation on the metric used to size the limit). CRF-5 convergent across five reviewers at P3 to Note; P3 wins. CRF-3 structural alternative verified against stacked commit 5ffb40e ARCHITECTURE.md (acquisition anchored at prompt created_at). CRF-6: Killua's proposed expiry assumes a waiting chat stays in the window; interrupting, requires-action, and other-pool rows can displace it (chats.sql:2502-2507), noted in the comment. Gon rated eight comment-restatement items P2; seven dropped (CRF-20 to CRF-26) because the comments describe behavior and meet the repo comment rule, and the eighth (field ownership rule) merged with Leorio at P3 (CRF-13). Ging-Go Nit and Gon P4 on the untyped sync.Map merged at P4 (CRF-17). Kurapika's nolint wording Nit dropped (CRF-27). Leorio's PR-description Note raised to P4 (CRF-16) because it asks for a change. No out-of-scope items. Reviewed against 3809e82..5be82a7. About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
There was a problem hiding this comment.
This PR records a capacity_wait stage from a worker's first capacity refusal of a chat to its acquisition, and adds an organization name cache and a chat kind helper. Findings: 4 P2, 4 P3, 7 P4, 3 Nit.
coderd/x/chatd/chatloop/metrics.go:173
P3 [CRF-10] The stage_duration_seconds help text lists capacity_wait as observed but does not say when it is observed or what it measures, and this PR adds its only producer. (Leorio)
Operators read the generated docs/admin/integrations/prometheus.md:244, not ARCHITECTURE.md, and will assume one observation per turn covering the whole wait. The stage is observed only for chats the acquiring replica refused at least once and starts at that replica's first refusal, so dividing its count by the chat_turn count does not give the fraction of turns that waited. Add that to the help string and run make gen.
🤖
🤖 This review was automatically generated with Coder Agents.
The acquisition loop remembers when each chat was first refused a concurrent-agent capacity slot, with the chat's history version at that refusal, and records a capacity_wait stage from that refusal when it later acquires the chat at the same version. Waits are dropped on non-capacity skips and pruned when the candidate batch is complete. The acquisition candidates query selects history_version. Adds Server.organizationName, a cached organization name lookup for stage span attributes, and chatKindAttr.
Remove the per-worker capacity wait bookkeeping, the acquisition candidate columns it read, and its stage, docs, and tests. Keep the organization name cache and chatKind, and add withStageIdentity, which puts a stage's scope, chat kind, and organization on a context.
5be82a7 to
b02f956
Compare
3809e82 to
adeadee
Compare
|
Folded into #29771: capacity_wait was dropped in the architecture cleanup, and the remaining helpers (organization name cache, chatKind, withStageIdentity) now land as part of #29771.
|
The acquisition loop remembers when each chat was first refused a concurrent-agent capacity slot, together with the chat's history version at that refusal (candidates skipped because their pool already refused one this pass are remembered too). When the same worker later acquires the chat at the same history version, it records a
capacity_waitstage from that first refusal to the acquisition, as a span and as an observation oncoderd_chatd_stage_duration_seconds.GetChatWorkerAcquisitionCandidatesnow selectshistory_versionfor this.Chats admitted on their first attempt record nothing. A remembered refusal for an earlier history version is discarded, so a chat refused here, acquired elsewhere, and later re-prompted while every batch stayed full is not charged the old wait. The wait start is dropped when a candidate is skipped for a non-capacity reason (owned by a live runner, archived, not runnable, or gone) and pruned when the candidate batch is shorter than its limit, since a chat missing from a truncated batch may still be waiting. The map is touched only by the acquisition goroutine.
The refusal history is per worker and in memory while the limit is deployment-wide, so the value is a lower bound: a chat refused on one replica and acquired by another is measured from the acquiring replica's first refusal, and a restart discards history. All replicas wake together on the
chat:ownershiphint, so the undercount is bounded by about one 30s acquisition interval rather than growing with replica count.Also adds
Server.organizationName, a cached organization ID to name lookup used as a span attribute (an organization label is not added to any metric), andchatKindAttr. Both are used by the turn span in the next PR.ARCHITECTURE.md gains a "Capacity wait" section.
🤖 This PR was generated by Coder Agents on behalf of @jscottmiller.