Skip to content

DNM: feat!: add organization-scoped coderd_agents_default_model - #423

Open
ethanndickson wants to merge 8 commits into
org-chat-models/agents-modelfrom
org-chat-models/default-model
Open

DNM: feat!: add organization-scoped coderd_agents_default_model#423
ethanndickson wants to merge 8 commits into
org-chat-models/agents-modelfrom
org-chat-models/default-model

Conversation

@ethanndickson

@ethanndickson ethanndickson commented Aug 25, 2026

Copy link
Copy Markdown
Member

Caution

DNM: Coder will likely drop the /experimental/ prefix from these API routes in 2.37 and replace it with /v2/. That hasn't happened upstream yet — hold this PR until it's settled so the pinned SDK targets the final routes.

Stacked on #422.

Coder 2.37 makes the default chat model per-organization rather than deployment-global (coder/coder#27957, coder/coder#28442): each organization now has its own default, the first model created in an organization is auto-promoted, and existing configs were migrated to the default organization. The experimental coderd_default_agents_model resource modeled a single global default — a constant "default" id, a global list lookup, and import by model UUID — which no longer matches the server.

This PR replaces it with the organization-scoped coderd_agents_default_model resource:

  • The resource is renamed from coderd_default_agents_model to coderd_agents_default_model, grouping it with coderd_agents_model and treating the organization-scoped behavior as a new experimental resource.
  • New required organization_id attribute: the target organization must be stated explicitly (deliberately stricter than the optional-with-default pattern used by coderd_agents_mcp_server/coderd_agents_model, since promoting a default silently demotes the previous one); changing it forces replacement.
  • The resource id is the organization UUID, since each organization has exactly one default.
  • Create/Update PATCH the org-scoped endpoint with is_default: true; a 404 is surfaced as an actionable diagnostic naming the endpoint and the minimum Coder version. Setting a model from another organization as the default fails with the server's 400.
  • Read lists the organization's models and resolves the default; if the organization or default is gone, the resource is removed from state.
  • Delete remains an intentional no-op: Coder requires a default once models exist and has no unset-default API.

Breaking changes and migration:

  • coderd_default_agents_model is removed and replaced by coderd_agents_default_model.
  • No cross-type MoveState migration is provided. The old resource was experimental, and its Terraform state represented a default selection rather than an independently deletable server object.
  • Existing users can remove the old resource from configuration and apply with the previous provider before upgrading, or run terraform state rm coderd_default_agents_model.<name>, then declare coderd_agents_default_model. Forgetting the old state does not clear or otherwise change Coder's server-side default.
  • The resource requires Coder v2.37.0 or later.
  • The import ID is the organization UUID (previously the model config UUID); model_id is resolved on read.
  • organization_id is required.

Disclosure: Xum (AI agent) authored this PR on @ethanndickson's behalf.

Closes CODAGT-973

@ethanndickson
ethanndickson force-pushed the org-chat-models/default-model branch from 6638443 to 98d5bc3 Compare August 25, 2026 10:08
@ethanndickson
ethanndickson force-pushed the org-chat-models/default-model branch from 98d5bc3 to c5fbf17 Compare August 25, 2026 10:16
@ethanndickson ethanndickson changed the title feat!: make coderd_default_agents_model per-organization DNM: feat!: make coderd_default_agents_model per-organization Aug 25, 2026
@ethanndickson
ethanndickson marked this pull request as ready for review August 25, 2026 10:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c5fbf17cc5

ℹ️ 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".

Comment thread internal/provider/agents_default_model_resource.go Outdated
Comment thread internal/provider/agents_default_model_resource.go Outdated
@ethanndickson
ethanndickson force-pushed the org-chat-models/default-model branch 2 times, most recently from 92f104e to a0e3b26 Compare August 25, 2026 12:38
@linear-code

linear-code Bot commented Aug 25, 2026

Copy link
Copy Markdown

CODAGT-973

@ethanndickson ethanndickson changed the title DNM: feat!: make coderd_default_agents_model per-organization DNM: feat!: add organization-scoped coderd_agents_default_model Aug 25, 2026
@ethanndickson
ethanndickson force-pushed the org-chat-models/default-model branch from ab939e9 to c918c14 Compare August 25, 2026 14:47
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c918c1495d

ℹ️ 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".

Comment thread internal/provider/agents_default_model_resource.go Outdated
Comment thread integration/agents-model-test/main.tf
@ethanndickson
ethanndickson force-pushed the org-chat-models/default-model branch 2 times, most recently from 2d02b85 to f152fdd Compare August 25, 2026 15:59

Copy link
Copy Markdown
Member Author

@codex review

matifali added a commit that referenced this pull request Aug 25, 2026
Add per-resource tfplugindocs templates (templates/resources/<name>.md.tmpl,
templates/data-sources/<name>.md.tmpl) that set a subcategory
front-matter field per resource/data source, so the Terraform Registry
sidebar groups coderd_* pages into Agents, AI Governance, Deployment,
Identity & Access Management, and Templates instead of listing them flat.

The templates are copies of tfplugindocs' default resource template,
minus the HasImportIDConfig/HasImportIdentityConfig branches: no
resource ships import-by-string-id.tf or import-by-identity.tf example
files, so those branches were always-false dead code. Data-source
templates drop the import section entirely.

Stacked on org-chat-models/default-model (#423): templates cover the
renamed coderd_agents_default_model and this base's
coderd_chat_system_prompt; when the stack rebases past #425, rename
templates/resources/chat_system_prompt.md.tmpl to
agents_system_prompt.md.tmpl.

Regenerated docs/ with make gen; only the subcategory line changed per
file.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f152fdd55d

ℹ️ 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".

Comment thread internal/provider/agents_default_model_resource.go Outdated

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f3b9705ae

ℹ️ 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".

Comment thread internal/provider/agents_default_model_resource.go Outdated
@ethanndickson
ethanndickson force-pushed the org-chat-models/default-model branch from 1f3b970 to 78daa14 Compare August 25, 2026 16:44
@ethanndickson
ethanndickson force-pushed the org-chat-models/default-model branch from 78daa14 to efee9c8 Compare August 25, 2026 17:13

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19eaf12e25

ℹ️ 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".

organizationID := state.OrganizationID.ValueUUID()
configs, err := r.experimentalClient().ChatModels(ctx, organizationID)
if err != nil {
if isHTTPNotFound(err) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat Coder's 400 not-found response as deletion

When the collection lookup for an externally deleted or inaccessible organization returns Coder's known 400 "must be an existing uuid or username" response, isHTTPNotFound rejects it because it recognizes only status 404. Refresh then emits an error and retains the resource in state instead of allowing Terraform to recreate it. Use the shared isNotFound helper here so both server not-found representations follow the deletion path.

AGENTS.md reference: AGENTS.md:L73-L73

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 49d64a31ed

ℹ️ 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".


func (r *AgentsDefaultModelResource) agentsDefaultModelDiag(ctx context.Context, action string, organizationID, modelID uuid.UUID, err error) diag.Diagnostics {
var diags diag.Diagnostics
if !isHTTPNotFound(err) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle alternate not-found responses during apply

When Create or Update targets an organization that Coder reports with its known 400 "must be an existing uuid or username" response, this check bypasses all model/organization probing and emits only a generic client error; the same problem occurs if a 404 PATCH is followed by that 400 from the collection or organization probe. Fresh evidence beyond the previously fixed Read path is that agentsDefaultModelDiag still uses the narrower isHTTPNotFound in all three checks, so use the shared isNotFound helper here as well to preserve the actionable missing-resource diagnosis.

AGENTS.md reference: AGENTS.md:L73-L73

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

@codex review

re: Handle alternate not-found responses during apply

Rejecting this finding. In the pinned Coder source, the exact 400 "user" must be an existing uuid or username response is emitted only by httpmw.ExtractUserContext for {user} routes. The organization-scoped chat-model PATCH and collection routes use ExtractOrganizationParam and ExtractChatModelConfigParam; those middleware paths return 404 for missing organizations/models and 500 for other lookup failures. Pre-2.37 deployments also signal the absent endpoint with a literal 404. The strict isHTTPNotFound checks are therefore intentional capability signals. Replacing all three checks with isNotFound could misclassify a hypothetical non-404 probe response as an unsupported Coder version.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 49d64a31ed

ℹ️ 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".

@ethanndickson
ethanndickson requested a review from matifali August 26, 2026 08:50
ethanndickson pushed a commit that referenced this pull request Aug 26, 2026
Add per-resource tfplugindocs templates (templates/resources/<name>.md.tmpl,
templates/data-sources/<name>.md.tmpl) that set a subcategory
front-matter field per resource/data source, so the Terraform Registry
sidebar groups coderd_* pages into Agents, AI Governance, Deployment,
Identity & Access Management, and Templates instead of listing them flat.

The templates are copies of tfplugindocs' default resource template,
minus the HasImportIDConfig/HasImportIdentityConfig branches: no
resource ships import-by-string-id.tf or import-by-identity.tf example
files, so those branches were always-false dead code. Data-source
templates drop the import section entirely.

Stacked on org-chat-models/default-model (#423): templates cover the
renamed coderd_agents_default_model and this base's
coderd_chat_system_prompt; when the stack rebases past #425, rename
templates/resources/chat_system_prompt.md.tmpl to
agents_system_prompt.md.tmpl.

Regenerated docs/ with make gen; only the subcategory line changed per
file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant