Skip to content

coderd/database: the subagent fairness ranking is written into upstream's acquisition query, against the fork's query rule #170

Closed

Description

@ibetitsmike

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.sql in 36 commits between 2026-09-10 and the 99fb0da864 sync 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-subagents off, the worker still sends the rewritten SQL, with the unowned_chats CTE and a UNION ALL of 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

Acceptance

One of:

  • The edit stays, and the rule says so: chatdmig/README.md "Fork queries" names GetChatWorkerAcquisitionCandidates as the one exception, says why a forkdb query 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.go is empty again, with fork-nested-subagents behavior 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

  1. added
    followup
    needs-triage
    on Nov 11, 2026
  2. ibetitsmike commented on Nov 11, 2026

    @ibetitsmike
    OwnerAuthor

    Xum (AI agent) triaged this on behalf of @ibetitsmike.

    Accepted as documentation: record the fairness-ranking edit to GetChatWorkerAcquisitionCandidates as 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.

  3. removed
    needs-triage
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    followup

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions