feat: add organization-aware chat model discovery#27337
Closed
mafredri wants to merge 1 commit into
Closed
Conversation
Expose organization-qualified read paths while keeping the existing global contract intact. Explicit membership checks prevent site-wide roles from granting access to an unrelated organization.
Docs preview📖 View docs preview for |
This was referenced Jul 20, 2026
Member
Author
|
$Closing this stack because its merge-safe compatibility direction was incorrect. CODAGT-709 will be rebuilt as review-only dependent diffs whose combined head is merged atomically.\n\n> 🤖 This review was automatically generated with Coder Agents. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Organization-owned chat model configs need an organization-qualified read contract before the destructive clone-and-remap migration can land safely. This expansion PR adds that contract while preserving every existing global route and caller.
The requested organization is an eligibility boundary during the expansion phase. Members receive the existing global catalog behavior, and deployment configuration readers retain visibility of disabled configs. Later stacked PRs can migrate consumers before organization ownership is activated.
Verification
make fmtmake gencoderdandcodersdktestsmake lintmake buildThe mandatory pre-push Storybook phase has inherited failures that reproduce on
origin/main. They are being investigated independently onmathias/fix-chat-storybook-tests; this PR does not change the failing stories or components.Approved implementation plan
CODAGT-709: reviewable expansion-first stack for organization-scoped chat model configs
Direction for approval
Replace the previous hard-cut implementation with an expansion-first stack. The existing global
chat_model_configsrows remain authoritative until every supported consumer can supply a concrete organization. New organization-qualified read contracts are additive and preserve the legacy global behavior while source data is still global. The clone, remap, ACL activation, cache cutover, and removal of global routes occur only in the final cutover PR after all supported callers use organization-qualified contracts.This sequencing is required for correctness. The final migration creates a distinct model-config ID for every legacy-config and organization pair. After that point, an unscoped request has no correct answer for both an existing chat in a non-default organization and a new chat created in a selected non-default organization. A default-organization legacy adapter would return the wrong cloned rows for one of those flows.
The current staged diff is discarded and rebuilt as the stack below. CODAGT-714 remains separate. It owns selected-organization settings and model-management UI work. CODAGT-709 includes only contract migrations in the existing Agents creation and chat-detail flows where the organization is already an existing resource property or the existing form selector state.
Observable end state
chat_model_configsis organization-owned, with one non-deleted default per organization.readonly. The organization Everyone group hasreadon migrated configs.Settled decisions
chat.organization_id, never a deployment default.Ruled out
Constraints and risks
Reviewable PR stack
PR 1: additive organization-qualified discovery contract
Title:
feat(coderd): add organization-aware chat model discoveryPurpose: Establish a merge-safe contract that can be consumed before model rows become organization-owned.
Include:
GET /api/experimental/organizations/{organization}/chats/models.GET /api/experimental/organizations/{organization}/chat-model-configs.httpmw.ExtractOrganizationParamand requirehttpmw.UserAuthorization(ctx).HasOrganizationMembership(organization.ID).GET /api/experimental/chats/modelsandGET /api/experimental/chats/model-configsunchanged.ListChatModelsForOrganizationandListChatModelConfigsForOrganization; retain the existing methods and signatures.Exclude:
Invariants:
Verification:
coderdendpoint tests for both legacy and additive endpoints;codersdkURL and response tests;make gen,make fmt,make lint, relevant Go package tests, andgit diff --check.PR 2: existing chat detail consumes its resource organization
Title:
feat(site/AgentsPage): scope chat model reads to the chat organizationPurpose: Migrate the existing-chat flow to the additive read contract without adding UI state.
Include:
AgentChatPagerequests catalog, model configs, and user compaction thresholds usingchat.organization_id.Exclude:
Invariants:
Verification:
pnpm lint:types, relevant site tests, andgit diff --check.PR 3: existing new-chat form consumes its selected organization
Title:
feat(site/AgentsPage): scope new chat model reads to selected organizationPurpose: Migrate the existing form's model-dependent reads to the organization selector it already owns.
Include:
AgentCreatePageintoAgentCreateForm, which already ownsselectedOrgand sendsorganization_idwith the create request.Exclude:
Invariants:
Verification:
git diff --check.PR 4: CODAGT-714 consumer migration, owned separately
Purpose: Migrate selected-organization settings and model-management callers to the additive contract.
Owner and scope: CODAGT-714, not CODAGT-709. This is a dependency record only. CODAGT-709 does not create this PR or change its files without a separate assignment and approved plan.
Required result before final cutover:
PR 5: atomic data, authorization, runtime, and API cutover
Title:
feat(coderd): scope chat model configs to organizationsPurpose: Activate organization ownership only after the contract consumers are ready.
Include as one coherent review boundary:
organization_id,user_acl, andgroup_acltochat_model_configs;readACL;ResourceChatModelConfigwith create, read, update, delete, and share. NoActionUse. Direct user and group ACL roles map only toread.Invariants:
read, not mutation or share authority.Verification:
make gen,make fmt,make lint, relevant package tests, and build entry points;Dependencies and implementation order
Evidence
AgentChatPagehaschat.organization_id; the resource organization is already available without UI work.AgentCreateFormownsselectedOrgand sendsorganization_id; the required source already exists without adding a picker.httpmw.ExtractOrganizationParamis the established route resolver for organization-qualified APIs.