Repository navigation
Description
Xum (AI agent) opened this on behalf of @ibetitsmike.
Problem
The Rules table in #8 says fork queries belong in coderd/database/forkdb only (row "Queries") and forbids edits to queries.sql.go and querier.go (row "Schema"). coderd/database/migrations/chatdmig/README.md ("Fork queries") gives the reason: fork queries go to forkdb "so that upstream's queries.sql.go never conflicts".
#47 is the one fork feature PR that does not follow this. It rewrote upstream's GetChatWorkerAcquisitionCandidates in coderd/database/queries/chats.sql to add the interleave_subagents ranking, and regenerated queries.sql.go and querier.go. The exception is not written down anywhere.
Two consequences:
- The fork carries a hand-written change inside an upstream query and inside its sqlc output. A later upstream change that overlaps it needs a manual conflict resolution and a regeneration during the sync. Upstream changed
chats.sqlin 36 commits between 2026-09-10 and the99fb0da864sync point; that shows how active the file is, not that a conflict will happen. - The rewrite is not behind the flag at the SQL level. With
fork-nested-subagentsoff, the worker still sends the rewritten SQL, with theunowned_chatsCTE and aUNION ALLof two subqueries where upstream has one lateral subquery. The flag only turns the ranking branch off. This review shows a difference in the SQL text. It did not compare query plans or measure anything.
It has not caused a sync conflict so far. The conflict in these three files during the first sync (#110, resolved in #124) was in GetChatQueuedMessageHead, from the queue stack (#23).
Evidence
On main at ce90b5bb74, against the last upstream sync point 99fb0da864:
$ git diff --numstat 99fb0da864 ce90b5bb74 -- coderd/database/queries/chats.sql coderd/database/queries.sql.go coderd/database/querier.go
9 0 coderd/database/querier.go
76 22 coderd/database/queries.sql.go
72 19 coderd/database/queries/chats.sql
- Both hunks in
chats.sqlare insideGetChatWorkerAcquisitionCandidatesand come from277d423787(feat: enforce subagent concurrency limits behind fork-nested-subagents #47). The only production caller passes the flag atcoderd/x/chatd/worker.go:174(InterleaveSubagents: w.server.nestedSubagentsEnabled()). git diff --numstat 99fb0da864 ce90b5bb74 -- coderd/database/queries/listschats.sqlonly, and the same diff fordump.sql,dbmockandmodels.gois empty. So this is the only place where a fork feature changes an upstream query.- The rule was known in feat: enforce subagent concurrency limits behind fork-nested-subagents #47's own review. A reply there declines a finding because "Rotating candidates would need a change to upstream's acquisition query, which the fork does not edit" (feat: enforce subagent concurrency limits behind fork-nested-subagents #47 (comment)). A later commit in the same PR edited that query.
Acceptance
One of:
- The edit stays, and the rule says so:
chatdmig/README.md"Fork queries" namesGetChatWorkerAcquisitionCandidatesas the one exception, says why aforkdbquery could not do this, and says how the exception is kept through an upstream sync. - Or the ranking moves out of the upstream query, so that
git diff <upstream> -- coderd/database/queries coderd/database/queries.sql.go coderd/database/querier.gois empty again, withfork-nested-subagentsbehavior unchanged and covered by the existing capacity tests.
Related to #8.
Found by a read-only review of fork main that listed every fork change to the files the plan says are never edited.
Activity
ibetitsmike commentedon Nov 11, 2026
Accepted as documentation: record the fairness-ranking edit to
GetChatWorkerAcquisitionCandidatesas a known exception in the fork rules docs, and say what to do when upstream changes that query. Moving it into a forkdb query isn't worth the risk while it causes no sync conflicts.