Skip to content

feat!: reject unrecognized model_config settings and bump coder/coder to latest main - #388

Merged
ethanndickson merged 11 commits into
mainfrom
agents-model-config-drop-validator
Jul 13, 2026
Merged

ethanndickson merged 11 commits into
mainfrom
agents-model-config-drop-validator

Conversation

@ethanndickson

@ethanndickson ethanndickson commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Closes CODAGT-797

Adds a plan-time validator for coderd_agents_model.model_config that fails loudly when the config contains settings the provider would silently drop when decoding into its pinned Coder SDK.

Why

Each provider release pins exactly one codersdk, and model_config is decoded into that SDK's ChatModelCallConfig before every create/update — so a release supports exactly one model_config schema. Standard encoding/json ignores object keys with no matching struct field, so anything outside that schema (a misspelled key, a field from a newer Coder, a field removed or renamed by an SDK bump) is silently dropped in the provider before the request is ever sent, with no plan diff, and the value in state compares semantically equal. A user can lose configured behavior with no signal.

What

  • New agentsModelConfigNoDroppedKeysValidator, wired into the model_config schema alongside the existing not-empty validator.
  • It reports every dropped setting by its full dotted path (e.g. provider_options.anthropic.bogus_setting), so a name that is valid in one place cannot mask a dropped occurrence of the same name elsewhere.
  • The error explains that the settings are not part of the schema this provider was built against, and tells the user to either upgrade the provider to a release built against their Coder version or fix/remove the field.

This is schema-change-agnostic: nothing in the implementation restates the SDK schema, so it cannot drift when ChatModelCallConfig evolves.

Design notes
  • The SDK is the sole oracle. To decide whether a key is dropped, the validator removes it from the decoded document, re-canonicalizes through ChatModelCallConfig, and compares against the canonical output of the full document: a key whose removal leaves the output unchanged contributed nothing, so it was dropped. Nothing hardcodes recognized fields, legacy aliases, or folding rules.
  • Relocations and legacy aliases fall out for free. A legacy top-level pricing key on its own (folded under cost) probes as kept, because removing it changes the output. The same key shadowed by a differing cost.<key> (whose nested value wins) probes as dropped, because removing the ignored legacy value changes nothing — so silent overrides are still caught.
  • Content-free values are skipped. null, [], and {} hit omitempty whether or not the key is recognized, so removing one never changes the output; the probe cannot judge them and does not try.
  • json.DisallowUnknownFields does not work here: ChatModelCallConfig has a custom UnmarshalJSON that calls plain json.Unmarshal internally, discarding the decoder's strict setting for the whole subtree.
  • This branch is independent of the coder/coder bump (PR chore!: bump coder/coder go module to latest main #386): tests assert on synthetic unknown keys that drop on any SDK version.

Compatibility model

The supported way to consume this (experimental) resource is to run the provider release that matches your Coder version; cross-version compatibility is delivered by the release stream (see #386's release plan), not by any single provider binary.

We considered making model_config an opaque passthrough blob (raw JSON both ways, bypassing the typed SDK client) so one provider release could span Coder versions, and rejected it as counter to that compatibility story. Passthrough would let this one attribute float across versions while everything else about the resource stays typed to the pinned SDK — a false sense of cross-version support — and it silently accepts typos and unsupported settings, which match no Coder version, get dropped by the server on write, and never come back: a perpetual diff with no error. This validator enforces the contract loudly instead: any setting outside the schema the provider was built against fails at plan time, with the remedy in the diagnostic (fix the field name, or upgrade the provider if the setting is valid on your Coder). Combining passthrough with this validation wouldn't help either — the error rejects exactly the newer-server fields passthrough exists to forward, and softening it to a warning just re-introduces quiet drift while adding the raw-HTTP machinery passthrough requires.

The validator checks against the pinned SDK, not the live server, so the reverse mismatch — a provider newer than your Coder — can still send fields the server drops; that too is solved by matching versions.

Opened by Coder Agents on behalf of @ethanndickson.

…ently drop

Add a plan-time validator for coderd_agents_model.model_config that
canonicalizes the user's JSON through codersdk.ChatModelCallConfig and
compares object key names before and after. Any key present in the input
but gone after the round-trip is a setting Coder does not recognize and
would silently discard, so the validator raises a plan-time error naming
those keys instead of losing configuration with no diff.

json.DisallowUnknownFields cannot be used here because the SDK's custom
UnmarshalJSON calls json.Unmarshal internally, which defeats strict
decoding for the whole subtree.

@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: c6602821b2

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

Compare model_config key paths instead of bare names so a valid key can't
mask a dropped occurrence of the same name elsewhere, with an exception for
the SDK's legacy top-level pricing keys folded under cost. Also drops the
unused sliceContains helper that failed lint.
@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: 7934eebbec

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

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: 986c469266

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

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: 4bc9c6aca5

ℹ️ 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 self-assigned this Jul 13, 2026
@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: 9ff5a42293

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

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 5ef88fb59b

ℹ️ 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 changed the title feat(internal/provider): reject model_config settings Coder would silently drop feat: reject model_config settings Coder would silently drop Jul 13, 2026
@ethanndickson ethanndickson changed the title feat: reject model_config settings Coder would silently drop feat: reject model_config settings the provider would silently drop Jul 13, 2026
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: af7bae0108

ℹ️ 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 johnstcn July 13, 2026 10:28

@johnstcn johnstcn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel like this adds a lot of complexity for not much gain.

Do we plan eventually to promote the model config into a top-level Terraform type? Would it be simpler to just promote once it stabilizes?

}
// Invalid or non-object JSON is left for the custom type and the not-empty
// validator to report.
dropped, err := agentsModelConfigDroppedKeys(req.ConfigValue.ValueString())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be simpler to just marshal to the SDK config type and back, and assert JSON equivalence? (leaving out the problems of ordering and whitespace)

@ethanndickson

ethanndickson commented Jul 13, 2026 •

Copy link
Copy Markdown
Member Author

I feel like this adds a lot of complexity for not much gain.

Yeah I think that's a reasonable criticism. The reason I'm doing this is because Mike and his agent had no idea his coder/dogfood PR to adapt the thinking levels wasn't going to do anything until the codex review bot flagged the codersdk on this repo needed bumping, but I think this applies to customers too. People pin their Terraform providers, and without this they might upgrade coder, but forgot to update the provider, and be left wondering why their config didn't apply. The provider wouldn't tell them without this.

Do we plan eventually to promote the model config into a top-level Terraform type? Would it be simpler to just promote once it stabilizes?

No plans to promote it unfortunately, when I looked at doing model_config as a top-level Terraform time it was hack after hack and hugely complex, thanks to things like fields typed with map[string]any. Also, I don't think it'll ever truly be stabilized? These AI providers seem to add and remove fields at the drop of a hat.

@johnstcn

Copy link
Copy Markdown
Member

People pin their Terraform providers, and without this they might upgrade coder, but forgot to update the provider, and be left wondering why their config didn't apply. The provider wouldn't tell them without this.

Fair point. In that case, I wonder if it would make sense to move the validation into codersdk?

@ethanndickson

Copy link
Copy Markdown
Member Author

People pin their Terraform providers, and without this they might upgrade coder, but forgot to update the provider, and be left wondering why their config didn't apply. The provider wouldn't tell them without this.

Fair point. In that case, I wonder if it would make sense to move the validation into codersdk?

Ah good shout. Yeah we could just add an UnmarshalStrict to ChatModelCallConfig that sets json.Decoder.DisallowUnknownFields, and that would let us catch this with very little code.

…ropped model_config settings

Replaces the removal-probe drop detection with
codersdk.ChatModelCallConfig.UnmarshalStrict (coder/coder#27187), pinning
the SDK to that PR's commit. The strict decoder shares the lenient path's
aux struct, so the SDK stays the sole oracle with no schema knowledge in
the provider.
Comment on lines +271 to +272
"model_config contains a setting that is not part of the Coder chat model config schema this provider was built against, so it would be silently dropped before reaching Coder: %s. "+
"If the setting is valid for your Coder deployment, upgrade the provider to a version built against your Coder release; otherwise remove it or fix the field name. "+

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

non-blocking: As an end-user, how do you determine this? Something to think about in future, I suppose.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ask an agent

Yeah, not sure... Bit of an experimental-API only paper cut... We haven't had to ask users to pay attention to the provider versions like this in the past.

…xtures to top-level reasoning_effort

Folds the non-go.mod changes from #386 into this branch, since it already pins an SDK with the reasoning_effort restructure.
@ethanndickson ethanndickson changed the title feat: reject model_config settings the provider would silently drop feat!: reject unrecognized model_config settings and bump coder/coder to latest main Jul 13, 2026
@linear-code

linear-code Bot commented Jul 13, 2026

Copy link
Copy Markdown

CODAGT-797

Copy link
Copy Markdown
Collaborator

coder/dogfood#397 is now green and waiting on a provider release containing this SDK bump. Its current provider pin silently drops top-level reasoning_effort, which leaves one valid Codex finding unresolved. Once this PR lands and releases, I will bump dogfood, validate the rendered plan, and resume its Codex review loop.

Mux posted this dependency note on behalf of Mike.

@ethanndickson
ethanndickson merged commit 6c4d21e into main Jul 13, 2026
13 checks passed
@ethanndickson
ethanndickson deleted the agents-model-config-drop-validator branch July 13, 2026 14:26
@ibetitsmike

Copy link
Copy Markdown
Collaborator

The v0.0.22 GitHub release completed successfully, but Terraform Registry has not indexed v0.0.21 or v0.0.22. The Registry provider metadata is still coder/coderd/0.0.20 with last-modified: Wed, 01 Jul 2026, and terraform init fails with no available releases match the given constraints 0.0.22. Release assets and signatures are present, and v0.0.20 through v0.0.22 use the same signing key.

Could a maintainer check or resync the Terraform Registry publication? coder/dogfood#397 is ready to consume v0.0.22 once the Registry serves it.

Mux diagnosed and reported this release blocker on behalf of Mike.

@ethanndickson

Copy link
Copy Markdown
Member Author

The v0.0.22 GitHub release completed successfully, but Terraform Registry has not indexed v0.0.21 or v0.0.22. The Registry provider metadata is still coder/coderd/0.0.20 with last-modified: Wed, 01 Jul 2026, and terraform init fails with no available releases match the given constraints 0.0.22. Release assets and signatures are present, and v0.0.20 through v0.0.22 use the same signing key.

Could a maintainer check or resync the Terraform Registry publication? coder/dogfood#397 is ready to consume v0.0.22 once the Registry serves it.

Mux diagnosed and reported this release blocker on behalf of Mike.

Yeah I'm resyncing now

ethanndickson added a commit to coder/coder that referenced this pull request Jul 14, 2026
)

Adds `ChatModelCallConfig.UnmarshalStrict`: `UnmarshalJSON` except
unknown fields and trailing data are errors instead of being silently
dropped.

`model_config` is free-form JSON at its edges (Terraform config, API
bodies), so a typo'd setting is dropped with no signal;
coder/terraform-provider-coderd#388 uses this for plan-time validation.
It has to live in codersdk because the custom `UnmarshalJSON` and its
unexported aux struct (which defines the accepted key set, including
legacy pricing aliases) make strict decoding impossible from outside the
package. `UnmarshalJSON` stays lenient since it is on the read path for
stored configs and older clients, where unknown keys mean version skew
rather than user error.

_Opened by Coder Agents on behalf of @ethanndickson._

Relates to CODAGT-797
wyattfry pushed a commit to wyattfry/terraform-provider-coderd that referenced this pull request Jul 27, 2026
… to latest main (coder#388)

Closes CODAGT-797

Adds a plan-time validator for `coderd_agents_model.model_config` that
fails loudly when the config contains settings the provider would
silently drop when decoding into its pinned Coder SDK.

## Why

Each provider release pins exactly one `codersdk`, and `model_config` is
decoded into that SDK's `ChatModelCallConfig` before every create/update
— so a release supports exactly one `model_config` schema. Standard
`encoding/json` ignores object keys with no matching struct field, so
anything outside that schema (a misspelled key, a field from a newer
Coder, a field removed or renamed by an SDK bump) is silently dropped in
the provider before the request is ever sent, with no plan diff, and the
value in state compares semantically equal. A user can lose configured
behavior with no signal.

## What

- New `agentsModelConfigNoDroppedKeysValidator`, wired into the
`model_config` schema alongside the existing not-empty validator.
- It reports every dropped setting by its full dotted path (e.g.
`provider_options.anthropic.bogus_setting`), so a name that is valid in
one place cannot mask a dropped occurrence of the same name elsewhere.
- The error explains that the settings are not part of the schema this
provider was built against, and tells the user to either upgrade the
provider to a release built against their Coder version or fix/remove
the field.

This is schema-change-agnostic: nothing in the implementation restates
the SDK schema, so it cannot drift when `ChatModelCallConfig` evolves.

<details>
<summary>Design notes</summary>

- **The SDK is the sole oracle.** To decide whether a key is dropped,
the validator removes it from the decoded document, re-canonicalizes
through `ChatModelCallConfig`, and compares against the canonical output
of the full document: a key whose removal leaves the output unchanged
contributed nothing, so it was dropped. Nothing hardcodes recognized
fields, legacy aliases, or folding rules.
- **Relocations and legacy aliases fall out for free.** A legacy
top-level pricing key on its own (folded under `cost`) probes as *kept*,
because removing it changes the output. The same key shadowed by a
differing `cost.<key>` (whose nested value wins) probes as *dropped*,
because removing the ignored legacy value changes nothing — so silent
overrides are still caught.
- **Content-free values are skipped.** `null`, `[]`, and `{}` hit
`omitempty` whether or not the key is recognized, so removing one never
changes the output; the probe cannot judge them and does not try.
- `json.DisallowUnknownFields` does **not** work here:
`ChatModelCallConfig` has a custom `UnmarshalJSON` that calls plain
`json.Unmarshal` internally, discarding the decoder's strict setting for
the whole subtree.
- This branch is independent of the coder/coder bump (PR coder#386): tests
assert on synthetic unknown keys that drop on any SDK version.
</details>

## Compatibility model

The supported way to consume this (experimental) resource is to run the
provider release that matches your Coder version; cross-version
compatibility is delivered by the release stream (see coder#386's release
plan), not by any single provider binary.

We considered making `model_config` an opaque passthrough blob (raw JSON
both ways, bypassing the typed SDK client) so one provider release could
span Coder versions, and rejected it as counter to that compatibility
story. Passthrough would let this one attribute float across versions
while everything else about the resource stays typed to the pinned SDK —
a false sense of cross-version support — and it silently accepts typos
and unsupported settings, which match no Coder version, get dropped by
the server on write, and never come back: a perpetual diff with no
error. This validator enforces the contract loudly instead: any setting
outside the schema the provider was built against fails at plan time,
with the remedy in the diagnostic (fix the field name, or upgrade the
provider if the setting is valid on your Coder). Combining passthrough
with this validation wouldn't help either — the error rejects exactly
the newer-server fields passthrough exists to forward, and softening it
to a warning just re-introduces quiet drift while adding the raw-HTTP
machinery passthrough requires.

The validator checks against the pinned SDK, not the live server, so the
reverse mismatch — a provider newer than your Coder — can still send
fields the server drops; that too is solved by matching versions.

_Opened by Coder Agents on behalf of @ethanndickson._
BobbyHo added a commit that referenced this pull request Jul 30, 2026
…399)

> [!NOTE]
> **Unblocked —
[coder/coder#27316](coder/coder#27316) has
merged** as
[`fbac6024`](coder/coder@fbac602).
`go.mod` now pins that squash commit on `main` instead of the PR's
branch head (`569a0eb3`, branch `coder-eng-3056-dcr-flag`), so nothing
here depends on unreviewed code any more. No *released* `coder/coder`
contains `codersdk.OAuth2ProviderSettings` yet, so this stays a `main`
pseudo-version pin — the same approach #388 took. Ready for review.
>
> Upstream landed as `feat!`, but the break is server-side behavior (DCR
now defaults to disabled); the SDK contract this PR consumes is
unchanged from the previously pinned branch head —
`DynamicClientRegistrationEnabled *bool`, and `GET`/`PUT` on
`/api/v2/oauth2-provider/settings`.

`coder/coder#27316` adds a deployment-level toggle for OAuth2 Dynamic
Client Registration (RFC 7591), giving admins two ways to flip it: the
`coder oauth2-provider dcr enable|disable` CLI command, or a raw `PUT
/api/v2/oauth2-provider/settings`. Neither is declarative. A team
already managing their deployment through this provider — alongside
`coderd_organization`, `coderd_license`,
`coderd_organization_sync_settings` — has no way to express "DCR is
enabled on this deployment" as Terraform-managed state. The only
Terraform-shaped option is a `local-exec` provisioner shelling out to
the CLI, which participates in neither plan/diff, drift detection, nor
`terraform destroy`.

Add a `coderd_oauth2_provider_settings` **resource** wrapping the same
`codersdk` contract. It is modelled on
`coderd_organization_sync_settings`, the closest existing precedent: a
singleton wrapping a GET-for-read / PUT-for-write API with no delete
endpoint. The resource has one `Required` boolean; `Create` and `Update`
share a single idempotent `PUT`; `Delete` resets to the documented
default (`false`) because no `DELETE` verb exists; `ImportState` lets an
admin adopt an already-configured deployment without overwriting it; and
`ModifyPlan` raises a plan-time warning when a first apply would disable
DCR on a deployment where it is currently enabled.

> [!NOTE]
> **An earlier revision of this PR also added a read-only data source of
the same name. It has been removed**
([review](#399 (comment))),
so the net diff no longer contains it.
>
> Declaring it alongside the resource produced a deterministic stale
read: a data source with a fully-known config and no `depends_on`
resolves in the **plan** phase, while the resource's `PUT` happens
during **apply**, so any plan-time consumer saw the pre-apply value and
lagged one apply behind. The example fed that value to a `count`, the
worst case — `count` is structural, so it must be settled at plan time
and is never re-evaluated during apply. Without `depends_on` it is
known-but-stale and the run silently ends in a self-contradictory state;
with `depends_on` it becomes unknown and the configuration will not plan
at all (`Invalid count argument`). There is no correct spelling of that
example.
>
> The data source's stated safety invariant — that it only ever issues a
`GET` — forecloses write/write conflicts but is silent on read/write
*ordering*, which is why its tests all passed: every one exercised it in
isolation. It can return later behind an enforced "never declare
alongside the resource" rule rather than advisory prose.

Closes #395. Addresses
[ENG-3083](https://linear.app/codercom/issue/ENG-3083/support-oauth2-dynamic-client-registration-setting-dynamic-client).
Requires coder/coder#27316, which has merged.

## Where this sits in the request path

```mermaid
sequenceDiagram
    autonumber
    participant U as Admin (Terraform user)
    participant TF as terraform
    participant P as terraform-provider-coderd<br/>(NEW)
    participant SDK as codersdk.Client
    participant API as coderd
    participant DB as site_configs<br/>(oauth2_dcr_enabled)

    Note over U,DB: Adoption path — import first, never overwrites
    U->>TF: terraform import ...dcr oauth2_provider_settings
    TF->>P: ImportState(req)
    Note over P: NEW: placeholder state. req.ID carries<br/>no meaning for a singleton
    TF->>P: Read(state) (core issues this next)
    P->>SDK: OAuth2ProviderSettings(ctx)
    SDK->>API: GET /api/v2/oauth2-provider/settings
    API->>DB: SELECT oauth2_dcr_enabled
    DB-->>API: true (live value, never overwritten)
    API-->>P: 200 OK
    P->>TF: state.Set — matches reality, no PUT issued

    Note over U,DB: Apply
    U->>TF: dynamic_client_registration_enabled = true
    TF->>P: ModifyPlan(plan)
    Note over P: NEW: on a create that would disable a<br/>live-enabled deployment, warn at plan time
    TF->>P: Create/Update(plan)
    P->>SDK: PutOAuth2ProviderSettings(ctx, {true})
    SDK->>API: PUT /api/v2/oauth2-provider/settings
    API->>API: authorize(ActionUpdate, ResourceDeploymentConfig)
    API->>DB: UPSERT oauth2_dcr_enabled = true
    API-->>P: 200 OK (audited)
    P->>TF: state.Set(data)

    Note over U,DB: Destroy — no DELETE endpoint exists
    TF->>P: Delete(state)
    Note over P: NEW: reset to the default via the same PUT
    P->>SDK: PutOAuth2ProviderSettings(ctx, {false})
    SDK->>API: PUT /api/v2/oauth2-provider/settings
    API->>DB: UPSERT oauth2_dcr_enabled = false
    P->>TF: state removed
```

## Files changed: manual vs. generated

Reviewers should focus on the **manual** files. The **generated** ones
are `make gen` output that follows mechanically from the schema and
examples, and don't need direct review.

<details>
<summary><b>Manual files (8)</b> — click to expand, grouped the same way
as "Suggested review order" below</summary>

**1. Dependency** (isolated in commits `e6283ba` and `07735ed`)

| File | What changed |
|---|---|
| `go.mod`, `go.sum` | Bump `github.com/coder/coder/v2` to expose
`codersdk.OAuth2ProviderSettings`, pinned to the merged squash commit
`fbac6024` on `main` — see the note at the top. Transitively bumps the
`go` directive to 1.26.5 and 19 indirect dependencies. |

**2. The resource**

| File | What changed |
|---|---|
| `internal/provider/oauth2_provider_settings_resource.go` | The
feature. One `Required` bool; `Read`; `Create`/`Update` via a shared
`patch()`; `Delete` resets to `false`; `ImportState`; `ModifyPlan`;
`dcrEnabledOrDefault`, the nil-safe read of the SDK's `*bool`; and
`oauth2ProviderSettingsDiag`, the shared 404 → minimum-version error
every CRUD path routes through. |
| `internal/provider/provider.go` | Registers the resource. One line. |

**3. Tests**

| File | What changed |
|---|---|
| `internal/provider/oauth2_provider_settings_fake_test.go` |
`fakeCoderd`: an `httptest` stand-in serving the two `Configure()`
endpoints plus `GET`/`PUT` on the settings endpoint. Records every
request in order (method, path, PUT body) and can inject
`403`/`404`/`5xx` per verb, with pre-`GET`/pre-`PUT` hooks for
simulating mid-apply mutation. |
| `internal/provider/oauth2_provider_settings_resource_test.go` |
`TestOAuth2ProviderSettingsModifyPlan` (8 table cases, plain unit test,
no Terraform binary) plus `TestAccOAuth2ProviderSettingsResource` (15
subtests) and `TestAccOAuth2ProviderSettingsNotDeclared` (2 subtests). |

**4. Examples** (`docs/` is generated from these)

| File | What changed |
|---|---|
| `examples/resources/coderd_oauth2_provider_settings/resource.tf` |
Singleton warning, import-before-first-apply warning, and a
readiness-gate pattern for the case where the same configuration also
upgrades Coder. |
| `examples/resources/coderd_oauth2_provider_settings/import.sh` |
Placeholder-ID import, both CLI and `import {}` block forms. |

</details>

<details>
<summary><b>Generated files (1)</b> — from <code>make gen</code>, no
need to review directly</summary>

`docs/resources/oauth2_provider_settings.md`.

</details>

## Suggested review order

### 1. The SDK contract (in coder/coder#27316, not this PR)

`OAuth2ProviderSettings` is a single boolean, and both client methods
are a bare `GET`/`PUT` with no identifying parameter. Everything below
is shaped by how small that contract is — in particular, a parameterless
`Read()` is what makes `ImportState` cheap to support correctly.

### 2. The resource

Read in this order; `oauth2ProviderSettingsDiag` is a leaf the others
call, so it comes last.

1. `Schema` — why `dynamic_client_registration_enabled` is `Required`.
Opting out of managing DCR means *not declaring the resource*, not
declaring it with the field blank. A plain `Optional` attribute is not
viable here: `Read()` writes a concrete bool while an omitted config
plans as null, producing a permanent `false -> null` diff on every plan.
2. `Delete` — the one semantic decision that isn't "copy the existing
pattern". The API has no `DELETE` verb, so this resets to the documented
default via the same `PUT`, mirroring
`OrganizationSyncSettingsResource.Delete`. A failed reset leaves the
resource in state so `terraform destroy` can retry.
3. `ImportState` — the import ID is an unused placeholder, since this is
a deployment-wide singleton and `Read()` takes no parameters. The
framework requires the handler to write *something*, so it writes a
placeholder that the framework's follow-up `Read()` immediately
overwrites with the live value.
3. `patch()` and `dcrEnabledOrDefault` — the SDK field is a `*bool` so
that a PUT can omit it to mean "leave this alone". Both write paths
deliberately send an explicit **non-nil** pointer: this resource owns
the value outright, and omitting it would make `Create`/`Update` no-ops
and silently turn `Delete`'s reset-to-default into a no-op. The fake
records whether the field was *present* on each PUT, not just its value,
so that regression fails a test rather than passing quietly. On the read
side a GET is documented to always return non-nil, so
`dcrEnabledOrDefault`'s nil branch is defensive against a contract
violation, not an expected response.
4. `ModifyPlan` — warns when a first apply would disable DCR on a
deployment where it is currently enabled. Deliberately asymmetric: a
live `false` is indistinguishable from never-configured, because the
server coalesces both, so warning in that direction would fire on every
greenfield apply. A failed lookup here is intentionally silent rather
than a plan error — `Create()` makes the identical call moments later
and reports it with wording matching the operation that actually failed.
5. `oauth2ProviderSettingsDiag` — maps a 404 to an actionable
minimum-version error. Deliberately **not** `isNotFound()`: that helper
also maps a 400 `"must be an existing uuid or username"` to not-found,
which is meaningless for a parameterless endpoint. Note this resource
must *not* treat 404 as "resource deleted" the way most resources here
do — the singleton always exists on a supported deployment, so 404 can
only mean the endpoint is missing, and removing state would hide a
version problem behind a phantom diff.

### 3. Tests

1. `oauth2_provider_settings_fake_test.go` first — the assertions below
only make sense once you know the fake records every request.
2. `TestOAuth2ProviderSettingsModifyPlan` — fastest, and the clearest
statement of the plan-time hook's contract.
3. The acceptance tests. Each subtest is named for a case in the design
proposal, so they can be read in any order.

On **why a fake rather than `integration.StartCoder`**: that helper
pulls a *published* `ghcr.io/coder/coder` image, and although #27316 has
merged, no published image contains it yet, so a real-server test cannot
exist until it ships in a release. Independently, a fake is the only way
to assert the requests that must *not* happen — import never issues a
`PUT`, an undeclared resource issues no settings calls at all — and to
produce responses a real deployment won't give on demand (404 from an
old version, 403 from a role that would otherwise need provisioning, a
transient 500). Adding one `integration.StartCoder` happy-path test to
catch fake-vs-real divergence is the obvious follow-up once #27316 ships
in a release.

### 4. Examples

Read last; `docs/` follows mechanically.

## Explicitly out of scope

- **Any coderd-side change.** That is entirely coder/coder#27316's
scope; this only consumes its contract.
- **The deployment settings UI toggle**
([ENG-3082](https://linear.app/codercom/issue/ENG-3082)). Separate
surface, separate repo, no code overlap beyond both reading and writing
the same setting.
- **A future Initial Access Token setting.** ENG-3083 is scoped to
`dynamic_client_registration_enabled` only.
- **Enabling the `oauth2` experiment.** That is a coderd *server
startup* flag (`--experiments` / `CODER_EXPERIMENTS`) with no runtime
API, so it belongs to whichever provider manages the deployment's
infrastructure — a `helm_release`, a `docker_container`, cloud-init —
not to this one.
ethanndickson pushed a commit that referenced this pull request Sep 22, 2026
…s_model model_config (#444)

Coder now supports OpenAI's Pro reasoning mode for chat models
(coder/coder#29584): `provider_options.openai.reasoning_mode = "pro"` in
the model config, for models from the GPT-5.6 Sol generation onward,
including GPT-6 Astra.

## Problem

`coderd_agents_model.model_config` is validated against the provider's
pinned `codersdk.ChatModelCallConfig` at plan time (#388), so with the
current `github.com/coder/coder/v2 v2.37.1` pin any config that sets the
new field fails before it is ever sent to Coder:

```
Error: Unrecognized model_config settings

model_config contains a setting that is not part of the Coder chat model config schema this provider was built against, so it would be silently dropped before reaching Coder: provider_options.openai.reasoning_mode. If the setting is valid for your Coder deployment, upgrade the provider to a version built against your Coder release; otherwise remove it or fix the field name.
```

## Fix

- Bump `github.com/coder/coder/v2` to `main` commit `a970c6c92e46`
(`v2.34.0-rc.0.0.20260921160322-a970c6c92e46`), the same pseudo-version
pattern as #388 and #413. Diffing the `ChatModelCallConfig` JSON tags
between v2.37.1 and the new pin shows the `model_config` schema change
is purely additive (`provider_options.openai.reasoning_mode` and
`openai_config.reasoning_model`); no existing key is removed, so there
is no migration and this is not a breaking release.
- Adapt test helpers to the renamed `codersdk.CreateUserRequest`
(`OrganizationIDs` replaces `OrganizationID`, `DisableLogin` is gone).
Provider code is unaffected.

No field-specific tests or examples are added for `reasoning_mode`; the
existing validator and canonicalization tests cover the mechanism,
matching how earlier dependency-bump fields were handled (review
feedback, 0293fa2).

## Compatibility

Using `reasoning_mode` requires a Coder release that includes
coder/coder#29584 (newer than 2.37); Coder validates the value
server-side and OpenAI rejects it for models without Pro.
`integration/agents-model-test` is intentionally left unchanged because
the integration harness pulls `ghcr.io/coder/coder:latest`, which does
not yet echo the field back.

> Xum opened this PR on behalf of @ibetitsmike.
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.

3 participants