Commit Graph
728 Commits
Author SHA1 Message Date
Michael Suchacz 5dde49dffb feat: add chat workspace file upload endpoint (#27079)
## What

Adds `POST /api/v2/chats/{chat}/workspace-files`, which streams the
request body to the chat's bound workspace agent and returns the final
path/name/size, plus the `workspace-file-reference` message part type
that carries the uploaded file's metadata through chat messages:

- `coderd/exp_chats.go`: owner-only middleware (chat RBAC update +
reject archived), workspace exec authorization (403/409 like the
existing chat exec paths), agent selection (prefer the chat's bound
agent, else deterministic `agentselect.FindChatAgent`, without
persisting a binding), 30s dial timeout, chat/ancestor tracking headers
on the agent connection, and agent error passthrough (agent HTTP status
preserved, 502 with a generic detail for transport failures; the real
error is logged). Deleted and non-running workspaces get a specific 409
("Workspace is stopped. Start the workspace before uploading files.")
before agent lookup. Each failed upload logs one structured warning, and
`coderd_chat_workspace_upload_total{status}` counts outcomes. The route
shares the files rate limit and documents its 429.
- Input validation: client-supplied `workspace-file-reference` parts
must point inside `/.coder/chats/<chat-id>/files/` with a matching
basename, non-negative size, and a `workspace_file_workspace_id` equal
to the chat's currently bound workspace (the upload response echoes it
as `workspace_id`). References uploaded before a workspace rebind are
rejected instead of silently sending the agent an unreadable path. The
file name must already be in sanitized form
(`SanitizeWorkspaceUploadName(name) == name`), and the cleaned path and
base media type are what gets persisted; message edits share the same
validation. Parts are rejected on chat creation (no chat ID exists yet).
- `coderd/x/chatd/chatprompt`: references render into the prompt as text
only, `[workspace file: <name> (<size>) at <path>]`; file bytes never
reach the LLM. Title derivation (`TitleText`) uses the bare file name,
so fallback titles carry no internal marker.
- `codersdk`: part-type constants/fields,
`ChatMessageWorkspaceFileReference` builder, and
`Client.UploadChatWorkspaceFile` (RFC 5987 filename in
`Content-Disposition`).

No DB migration: parts persist as JSON in `chat_messages.content`.

## Why

Bridges chat and the workspace filesystem for CODAGT-211: users drop a
file in chat, the bytes land where the agent's tools can operate on
them, and the model learns the path from the reference part.

## How tested

- `go test ./coderd -run 'WorkspaceFile|ChatInput|UploadChat'` including
an integration test that runs a real in-memory agent, uploads through
the coderd route, verifies bytes on disk, and exercises collision
suffixes.
- `go test ./codersdk ./coderd/x/chatd/...`, `make gen`
(swagger/types/docs), `make lint`.
- Rebased onto main 2026-09-21: the chat API moved from
`/api/experimental` to `/api/v2`, so the route is registered in
`coderd/chat_routes.go` and the SDK method lives on `codersdk.Client`.

## Follow-ups

- The files rate limit counts requests, not bytes or concurrency;
whether this route should use a per-user concurrency cap instead, and
whether the new-chat page should keep partial successes on a 429, is
still open
([CODAGT-1171](https://linear.app/codercom/issue/CODAGT-1171)).

Part of CODAGT-211. Stack: agent API -> coderd endpoint (this PR) -> UI.

> This PR was authored by Mux (AI) working on Mike's behalf.
2026-09-26 21:41:25 +02:00
david-fraley 282365b23a feat: report clicks on the workspace build debug action to telemetry (#29853) 2026-09-25 13:59:53 -05:00
Susana Ferreira 46ccaf3764 chore: mark organization AI spend users endpoint as experimental (#29842)
## Description

Move `GET /organizations/{organization}/ai/spend/users` under
`/api/experimental` so the per-user spend report is not part of the
stable API for this release. The endpoint behavior is unchanged.

Related to [internal Slack
thread](https://codercom.slack.com/archives/C04M9CNGHGF/p1790190171687059?thread_ts=1790190121.005749&cid=C04M9CNGHGF).

## Changes

- Register the route on the experimental handler and mark it
`@x-apidocgen {"skip": true}`, which removes it from the generated API
reference.
- Move the Go SDK method to `ExperimentalClient` and the frontend method
to `API.experimental`.
- Drop the docs link to the removed API reference section. The link is
commented out with a TODO so it can be restored later.

User-facing docs for the **User spend** page are updated upstack in
#29844.

> [!NOTE]
> Generated by Coder Agents on behalf of @ssncferreira.
2026-09-25 17:35:02 +01:00
david-fraley 702b13112d feat: add Debug with Coder Agents action for failed workspace builds (#29811) 2026-09-25 09:52:17 -05:00
Ethan f64ccfb836 feat: add experimental inline MCP servers (#29546)
Closes CODAGT-1131

Fifth PR in the inline MCP servers stack, on top of #29520. A chat owner
can now declare MCP servers by URL and headers on their own chat, and
chatd connects to them every turn alongside the org-configured ones.

They go in a new `inline_mcp_servers` field on `POST /api/v2/chats` and
`POST /api/v2/chats/{chat}/messages`, which replaces the whole set (omit
to keep, `[]` to remove). Root chats only. `GET /api/v2/chats/{chat}`
returns them, with the URL blanked for non-owners and header values
never returned. Subagents only get servers marked `allow_in_subagents`,
a root chat in explore mode gets none, and a root chat in plan mode gets
all of them.

URLs must be `https`, or `http` to an IP literal in
`CODER_MCP_ALLOWED_PRIVATE_CIDRS`. Header values have no minimum length,
so anything under the redactor's 8 byte floor from #29518 is accepted
but not redacted, which the docs call out. Every cap is exported from
`codersdk`.

It's behind the `chat-inline-mcp-servers` experiment, and the
`--disable-chat-caller-supplied-tools` kill switch from #29466 covers it
too. With either off, declaring servers gets a 403 and existing chats
stop connecting to theirs, but `[]` still works so a client can detach.

Load failures show up in the chat debug panel as failed connections, as
do org servers with an invalid config. Docs are hand-written in
`mcp-servers.md`.
2026-09-25 18:51:55 +10:00
Ethan c1af0793e5 feat: add caller-supplied tools kill switch for chats (#29466)
This is the first PR in a stack that adds experimental support for
attaching MCP servers to a chat when it's created, and then deprecates
`unsafe_dynamic_tools` in favour of them. Both are "caller-supplied
tools", i.e. tools the client hands to coderd at chat creation rather
than tools an admin has configured, so we want a single switch admins
can use to turn all of them off.

This PR adds that switch: `--disable-chat-caller-supplied-tools`
(`CODER_DISABLE_CHAT_CALLER_SUPPLIED_TOOLS`). It follows the existing
`disable-*` deployment flag pattern (`--disable-chat-sharing` etc.), so
there's no new API route and it's independent of any experiment. When
set, `POST /api/v2/chats` returns a `403` if the request includes
`unsafe_dynamic_tools`, and chats that already have dynamic tools run
without them; a call to one gets a tool error result and the model just
continues. Later in the stack, chat-attached MCP servers are gated
behind the same flag.

It's unset by default, so nothing changes unless you opt in.


Part of CODAGT-1131
2026-09-25 18:51:53 +10:00
Thomas Kosiewski 2de1f8b111 feat: link promoted chat messages to their queue entry (#29859)
Signed-off-by: Thomas Kosiewski <tk@coder.com>
2026-09-25 09:51:25 +02:00
Thomas Kosiewski 5393f9d5f4 feat: stream advisor reasoning in tool cards (#29742)
Show the advisor’s live reasoning under **Thinking**, separately from
**Advice**, in one tool card with the original question and title. Keep
nested reasoning out of the parent assistant’s reasoning and saved chat
history.

Clear both live channels on retry and remove transient reasoning when
the call finishes. Cover streaming, retry, error, and interrupted-output
behavior with regression tests, and regenerate the SDK and API schemas.

This also changes a shared seam for every tool, not only the advisor:
live output for a tool call that is already saved now completes that
call's card, and the separate live-row card for it is removed.

Remote UAT passed on `a39bbe4c21`: deterministic provider tests covered
streamed reasoning, retry, errors, and refresh; a real-provider run
confirmed advice streaming and card association. The real model did not
emit reasoning. The intermittent, unattributed React console warning is
tracked in #29741.

<details>
<summary>Remote UAT evidence (deterministic provider)</summary>

![One advisor card showing its question, Thinking, and
Advice](https://github.com/user-attachments/assets/edd05bf2-59b7-48c2-a608-2fd5a4fabcc8)

Streaming, completion, and refresh:


https://github.com/user-attachments/assets/dd1f3a24-a365-40c8-a1d9-b78cd17ef4c5

</details>

---

<details>
<summary>📋 Implementation Plan</summary>

# Plan: Stream advisor reasoning in Coder Agents

## Goal and delivery boundary

Show nested advisor reasoning as live **Thinking** in its advisor tool
card. Keep it separate from live **Advice**, normal parent-assistant
reasoning, and the final persisted advisor result.

Deliver one focused PR: optional SDK field, nested publisher, transient
frontend state, existing card rendering, generated API artifacts, and
regression tests. Do not add provider features, persistence, new stream
event types, UI redesigns, or unrelated cleanup.

The implementation already exists and has been reconciled with current
main. The implement-flow implementation phase is an acceptance audit,
not a rewrite. Preserve correct behavior and current architecture.
Change only demonstrated gaps. A no-op implementation result is valid;
do not manufacture an empty commit.

## Current integration points

1. `codersdk/chats.go`: add optional `ReasoningDelta string` with
`json:"reasoning_delta,omitempty" variants:"tool-result?"`. Preserve it
in `StripInternal` alongside other live fields. Register the same
NUL-encoding policy as `ResultDelta` in `chatprompt` so the SDK field
coverage and round-trip tests remain complete. Regenerate SDK types and
API documentation with `make gen`.
2. `coderd/x/chatd/chatadvisor/runner.go`: route assistant text and
reasoning through separate optional callbacks on `RunAdvisorOptions`.
Install the publisher if either callback exists. Preserve empty-delta
and role guards. Use current `GenerateAssistant` and `chatretry.Retry`.
Rename the reset callback to `OnLiveOutputReset` because it clears
advice and reasoning. Keep `extractAdvisorText` text-only and existing
budget/refund behavior.
3. `coderd/x/chatd/chatadvisor/tool.go`: use the current
context-injected `MessagePartPublisherFromContext`; do not reintroduce
the old ToolOptions publishing callbacks or chatd.go wiring. Preserve
the missing-publisher error and the nonempty tool-call-ID guard. Publish
reasoning as role `tool`, part type `tool-result`, tool name `advisor`,
matching `tool_call_id`, and `reasoning_delta`. Use existing
`result_reset` to reset both live channels on retry.
4.
`site/src/pages/AgentsPage/components/ChatConversation/streamState.ts`
and `types.ts`: retain a single transient reasoning string. Append
deltas exactly as plain text, never JSON-parse or trim them during
accumulation. Reasoning makes the tool streaming. An empty
`result_delta` must not swallow a nonempty `reasoning_delta`. Reset
removes the entry. A final result or `is_error` clears reasoning and
streaming state. Pass reasoning through `buildStreamTools` into
`MergedTool`.
5. `MessageBlocks.tsx` and `ChatElements/tools/Tool.tsx`: forward
reasoning at both current Tool instantiation paths and through
AdvisorRenderer. Do not restore the old ConversationTimeline rendering
implementation.
6. `AdvisorTool.tsx`: use current `ToolCall.Root`, `ScrollArea`,
`Response`, and semantic theme tokens. Display Thinking only when
running and trimmed reasoning is nonempty. Display live advice
separately when present. Keep completed advice, empty/loading, limit,
and error behavior unchanged. Reasoning-only running cards must not show
the empty-advice fallback. Do not restore removed MUI dependencies.
7. `messageParsing.ts`, `streamState.ts`, and `ChatPageContent.tsx`:
associate live tool results with matching durable tool calls. Preserve
the invocation's question, intent, and metadata. A durable final result
remains authoritative, including explicit null results. Remove only the
overlaid result and its block from the separate live row; keep unrelated
results and live call/result pairs unchanged. This closes the
durable-call/live-result split found during integration testing.

## Acceptance criteria

1. Nested reasoning reaches the dedicated runner callback and the client
as tool-scoped live output for the same advisor call as advice.
2. Advisor reasoning is not parent assistant reasoning, final advice,
input to the parent's continuation, or persisted chat history.
3. Retry clears stale reasoning and advice before fresh output. Final
success and bare error clear transient reasoning.
4. Raw whitespace and JSON-looking reasoning survive concatenation
unchanged. Empty advice deltas do not hide reasoning.
5. Reasoning-only and reasoning-plus-advice states render in exactly one
existing advisor card per invocation, retaining its question and intent
title when the call is already durable. Completed cards never display
transient thinking, even if handed a stale prop. Other tool and normal
assistant reasoning behavior is unchanged.
6. Generated artifacts match source. Final candidate passes relevant Go
tests, frontend tests, stories, typecheck, lint, and pre-commit checks,
or has explicit verified blockers. Old evidence is not final-candidate
evidence.

## Phases and quality gates

1. Reconcile existing work onto current main while retaining a recovery
snapshot. Remove obsolete workarounds, not current upstream behavior.
Gate: no conflicts, focused diff, preserved original work.
2. Audit regressions at the existing runner, tool publisher, parent-chat
stream, and frontend state boundaries. Add one missing behavior at a
time. Reproduce failures before fixes. Gate: failing tests demonstrate
the defect and pass after the smallest fix.
3. Simplify only within this feature. Use one reasoning string and
existing publishers/components. Gate: tests remain green, generated diff
is scoped, FE1 through FE10 pass.
4. Commit the candidate with repository hooks enabled, then run the
packaged implement-flow audit, validation, remote UAT, and polish
stages. Gate: readyForPr and verified remote evidence for the exact
final candidate. If polish changes HEAD, refresh the UAT evidence for
that SHA.
5. Create a reviewable PR and complete green CI plus bounded Codex
review on its exact head. Get one fresh independent readiness
recommendation. Gate: no unresolved review threads, required evidence
recorded, and a justified readiness decision. Do not merge.

## Regression coverage

- Runner: reasoning and advice callbacks remain separate; final advice
and usage count stay correct. Retain existing retry/refund tests.
- Tool: all reasoning/advice events carry role tool, type tool-result,
advisor name, and the invocation ID. Without an ID, emit no live output.
Retry emits stale reasoning/advice, reset, then fresh reasoning/advice.
- Chatd: extend `TestAdvisorHappyPath_RootChat` with deterministic
`openai-compat` reasoning chunks. Hold the nested response until the
live subscriber captures expected reasoning and advice. Observe the
complete relevant event set, assert no parent-assistant reasoning, and
check continuation and persisted content contain no advisor reasoning.
Extend only the test fixture needed to emit `reasoning_content`; do not
change production adapters.
- Frontend: extend streamState tests for exact accumulation, whitespace,
JSON-looking text, reasoning-only streaming, empty advice delta, reset,
final result, and bare error.
- Durable/live integration: replay a durable assistant tool call
followed by live reasoning and advice results. Assert the durable card
receives both channels and the live row no longer owns the same result
or block. Preserve unrelated IDs and live calls. Clear the overlay on
reset; prefer durable final results, including null. Cover the complete
display path with a real-store ChatPageContent story.
- Visual stories: running reasoning-only, running reasoning-plus-advice,
and completed with stale reasoning. Keep existing limit/error stories.
Stories set up visual states without assertions, following current FE1.

## Validation

Run targeted checks while iterating, then the broader gates:

```sh
umask 022
go test ./coderd/x/chatd/chatadvisor ./coderd/x/chatd ./codersdk -run 'Advisor|ChatMessagePart|ChatStream' -count=1
pnpm -C site exec vitest run --project=unit src/pages/AgentsPage/components/ChatConversation/streamState.test.ts
pnpm -C site exec vitest run --project=storybook src/pages/AgentsPage/components/ChatElements/tools/AdvisorTool.stories.tsx
make gen
make fmt
make test RUN='Advisor|ChatMessagePart|ChatStream'
pnpm -C site lint:types
pnpm -C site check
pnpm -C site lint
make lint
make pre-commit
```

Keep native exit codes and logs. Do not hide a failed check, bypass
hooks, or fix unrelated baseline problems in this PR. Stage intentional
generated/formatting changes before pre-commit's clean-diff checks.
Report exact blockers and risks.

## Remote dogfood UAT

Use the coder-agents-uat skill and an independent critical Coder Agent,
not a local-only substitute. Push only the named feature branch. Test
its exact SHA in an isolated workspace/deployment without changing
shared model credentials or configuration. Use an isolated user, chat,
and model config.

Setup:

1. Read the branch diff and UAT scope. Record the branch and SHA.
2. Start Coder with the repository-supported `./scripts/develop.sh
--port-offset` (or `CODER_DEV_PORT_OFFSET=true`). Do not replace it with
a manual server launch. Record effective API/UI URLs and wait for
readiness.
3. Prefer a deterministic mock OpenAI-compatible provider that emits
advisor reasoning and advice separately, and a retry after stale output.
Use only isolated configuration. Never print or capture secrets.
4. Start a named agent-browser session. Attempt `agent-browser skills
get core`; record the installed version/fallback if unavailable. Record
video before the scenario, then install any stream capture since
recording may recreate browser context.

Scenario:

1. Create a normal advisor-enabled root chat. Do not use Plan Mode:
current product behavior excludes the advisor there.
2. Capture the initial state. Prompt the parent to call advisor.
3. While the tool is running, capture reasoning-only and
reasoning-plus-advice states. Verify exactly one advisor card per
tool-call ID, with its original question and intent title. Verify
Thinking and Advice stay separate inside that card and the parent
thinking area does not receive nested reasoning.
4. Capture the relevant WebSocket event set. Verify role tool, type
tool-result, advisor name, matching tool-call ID, and reasoning_delta.
An advisor-filtered subset is insufficient to prove absence of parent
reasoning.
5. Let the advisor finish. Verify final advice remains, Thinking
disappears, and refresh does not restore transient reasoning.
6. Exercise retry with the deterministic provider if feasible. Verify
stale reasoning/advice clears before fresh output. If not exercised,
record the omission and remaining test evidence; do not claim it was
dogfooded.
7. Capture console errors before and after. Inspect the screenshots and
semantic video frames, not only successful media decoding.

Required evidence: exact tested SHA; remote chat URL; setup command and
effective URLs; non-secret provider/model names;
before/thinking/thinking-plus-advice/completed screenshots; a short
streaming video; complete relevant stream evidence; refresh and retry
observations; console results; explicit omissions; and owned-resource
cleanup receipts. Keep evidence under `.mux-uat/round-<n>/`, excluded
from source commits. When publishing evidence to GitHub, use native `gh
--attach`, not cookie-based uploads or gh-image.

Cleanup: stop only owned develop/provider processes and named browser
sessions. Do not use unscoped process sweeps, shared database resets, or
`agent-browser close --all`.

</details>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model:
`coder:openai/gpt-6-astra` • Thinking: `xhigh`_

---------

Signed-off-by: Thomas Kosiewski <tk@coder.com>
2026-09-25 07:58:22 +02:00
Bobby Ho b70702d50d docs: split OAuth2 provider page (#29778)
Split the OAuth2 provider documentation into seven focused pages.

- Update navigation and inbound links, preserving compatibility anchors for moved headings.
- Correct `DELETE /oauth2/tokens` documentation: it revokes only the calling user's tokens and codes, not every user's for the application.
- Clarify client authentication and app creation, mention PKCE, and update callback UI references.
- Remove contributor-only instructions and the feature-specific example from feature-stage docs; restore release and upgrade guidance in `security.md`.
- Standardize formatting and verify internal anchors. Markdown and em-dash linting pass.

Refs PLAT-659.
2026-09-24 13:42:59 -07:00
Nick Vigilante 3d30e201b5 docs: move contributor guides out of the published docs into the repo (#29751)
## Merge order

Merge first; then republish the docs; then coder/coder.com#1100 (the
redirects).

## Summary

The nine pages under `docs/about/contributing/` are for people working
in this repository, not for Coder users or administrators, so they leave
the published documentation.
The repository becomes their canonical home.
Until now the root `CONTRIBUTING.md` and `CODE_OF_CONDUCT.md` were
two-line stubs that only linked to the docs site, so contributors on
GitHub were bounced out to read them.

A companion PR in `coder/coder.com` adds redirects from every retired
`/docs/about/contributing/*` URL to the new GitHub location.
It must merge only after this PR has merged and the docs have
republished.

## Changes

| Old path | New path |
| -- | -- |
| `docs/about/contributing/CONTRIBUTING.md` | `CONTRIBUTING.md`
(replaces the stub) |
| `docs/about/contributing/CODE_OF_CONDUCT.md` | `CODE_OF_CONDUCT.md`
(replaces the stub) |
| `docs/about/contributing/SECURITY.md` | deleted; the root
`SECURITY.md` already holds the policy |
| `docs/about/contributing/AI_CONTRIBUTING.md` |
`contributing/AI_CONTRIBUTING.md` |
| `docs/about/contributing/backend.md` | `contributing/backend.md` |
| `docs/about/contributing/frontend.md` | `contributing/frontend.md` |
| `docs/about/contributing/modules.md` | `contributing/modules.md` |
| `docs/about/contributing/templates.md` | `contributing/templates.md` |
| `docs/about/contributing/documentation.md` |
`contributing/documentation.md` (see note below) |

For every moved file: the docs front matter is stripped and its `title`
becomes the H1, relative links are rewritten for the new depth
(`../../../foo` becomes `./foo` at the root and `../foo` under
`contributing/`; the two links into `docs/admin/` become
`../docs/admin/...`), and the docs-only `<div class="tabs">` wrapper in
`CONTRIBUTING.md` is removed.
`CONTRIBUTING.md` gains a short intro that links the code of conduct,
the security policy and the area guides, since GitHub only auto-surfaces
the root files.

`docs/manifest.json` loses the About → Contributing group and
`docs/images/icons/contributing.svg`, which only that group used.

Inbound references updated:

- `README.md`: contribution guide link now points at `CONTRIBUTING.md`
on GitHub.
- `docs/tutorials/example-guide.md` and
`docs/install/releases/feature-stages.md`: link to
`contributing/documentation.md` on GitHub, since a docs page cannot link
to a repo-only file.
- `docs/.style/style-guide/README.md`: the "Relationship to" section
names the new location.
- `scripts/docshtmlcheck/main.go`: both the package comment and the
user-facing error string name `contributing/documentation.md`.
- `scripts/docshtmlcheck/README.md`: relative link to the new location.
- `coderd/database/migrations/migrate_test.go`: `t.Log` link now points
at `contributing/backend.md#database-fixtures-for-testing-migrations`.
- `.github/pull_request_template.md`: AI contribution guidelines link.
- `.github/workflows/contrib.yaml`: commit-message guidelines link in
the PR title check.
- `.github/workflows/test-docs-preview-mapper.sh`: the mapper test case
that used `docs/about/contributing/CONTRIBUTING.md` now uses
`docs/admin/security/audit-logs.md`.
-
`.claude/docs/{ARCHITECTURE,PR_STYLE_GUIDE,WORKFLOWS,DOCS_STYLE_GUIDE}.md`:
links to `CONTRIBUTING.md`.

`git grep about/contributing` is empty after this change.
`CODEOWNERS` had no entry for the old paths.

Note on `documentation.md`: it is docs-authoring guidance and is parked
in `contributing/` for now.
Folding it into `docs/.style/` is tracked separately and is deliberately
not attempted here.

## Testing

- `go run ./scripts/docshtmlcheck` over `docs/`, and again over
`contributing/`, `CONTRIBUTING.md` and `CODE_OF_CONDUCT.md`: clean.
- `go vet ./scripts/docshtmlcheck/...` and `go test
./scripts/docshtmlcheck/...`: 47 tests pass.
- `go vet ./coderd/database/migrations/...`: clean. `go test` for that
package fails to link on this machine (`tailscale.com/tstime/mono:
invalid reference to runtime.nanotime1`) identically on unmodified
`main`, so it is a local toolchain issue and not exercised here; the
change is a string in a `t.Log`.
- `pnpm check-docs` (markdownlint-cli2 and markdown-table-formatter over
`docs/`, `.claude/docs/`, root `*.md`): 495 files, 0 errors. The same
two tools over `contributing/*.md`: 0 errors.
- Every relative link in the eight moved files resolves to an existing
path (scripted check).
- `bash .github/workflows/test-docs-preview-mapper.sh`: the changed
`assert_maps_to` case passes; the six `resolve_ref`/`pages_for_image`
failures it reports are identical on unmodified `main` on macOS.

Linear: [DOCS-975](https://linear.app/codercom/issue/DOCS-975)

---

🤖 Built with AI assistance.
2026-09-24 19:42:18 +00:00
Nick Vigilante 99a3425333 fix: advertise install.sh with curl -fsSL everywhere (#29801)
## Summary

The install one-liner is advertised as `curl -L` in most docs pages, the
README, and the CLI's default version-mismatch hint, while `install.sh`
itself and the deployment-local hint use `curl -fsSL`.
Without `-f`, curl writes an HTTP error body to stdout, and the
one-liner pipes that error page into `sh`.
This PR standardizes every `install.sh` invocation on `-fsSL` so a
failed download fails closed.

## Changes

- Docs: `install/cli.md`, `install/operate/upgrade.md` (twice),
`get-started/index.md`, `start/local-deploy.md`,
`install/operate/provisioners/index.md`,
`admin/templates/managing-templates/change-management.md` (twice),
`user-guides/workspace-access/zed.md`, and `README.md`.
- CLI: `defaultUpgradeMessage` in `cli/root.go` now prints `curl -fsSL`,
matching the deployment-local branch in the same function.
- `codersdk/deployment.go`: the `--cli-upgrade-message` description now
says `curl -fsSL`; the server help goldens, `server-config.yaml.golden`,
`docs/reference/cli/server.md`, and
`docs/admin/setup/configuration-reference.md` are regenerated to match.
- `install.sh`: the "To run" header comment now matches the script's own
usage text.
- Style guide: a new "Commands that pipe a download into a shell" rule
in `docs/.style/style-guide/formatting.md`, and the tabs example uses
`-fsSL`.

The coder.com download page already builds its command from `-fsSL` in
coder/coder.com#1093, and coder.com `main` has no other `install.sh`
one-liners outside test fixtures, so no coder.com change is needed.
DatoCMS content and a release verification page are not in this PR.

`main` since moved the upgrade and provisioner pages under
`docs/install/operate/` and removed the install one-liner from
`docs/install/index.md` in #29304, so that page no longer appears in
this diff.

## Testing

- `TZ=UTC go test ./cli
-run='Test(CommandHelp|ServerYAML|ErrorExamples|.*Golden)' -update` and
`go test ./enterprise/cli -run=TestEnterpriseCommandHelp -update` pass
and produce the committed golden diffs.
- `go test ./cli -run 'Test.*Version|TestWrapTransport'` passes,
including `Test_wrapTransportWithVersionCheck`.
- `go run ./scripts/configdocgen` output contains the new `curl -fsSL`
description.
- `markdownlint-cli2` on the edited style guide page reports 0 errors.
- `git grep` finds no remaining `curl -L …install.sh` outside the style
guide's **Don't** example.
- After merging `main`: `make pre-commit` passes, and `make test`, `make
test-js`, and `make site/out/index.html` pass.

Linear:
https://linear.app/codercom/issue/DOCS-964/standardize-installsh-curl-flags-on-fssl-across-docs-codercom-and-the

---
🤖 Built with AI assistance.
2026-09-24 18:23:54 +00:00
Nick Vigilante d5a6047879 docs: restructure Install into the five phase deployment spine (#29304)
Restructures the Install section into the five-phase deployment spine,
so the reading order matches the order a deployment actually happens:
**plan, prepare, install, validate, operate.** Today the first thing a
reader sees is a shell command, and architecture and sizing sit
downstream in Administration, after the point where they would have been
useful.

Resolves [DOCS-869](https://linear.app/codercom/issue/DOCS-869). Part of
[DOCS-685](https://linear.app/codercom/issue/DOCS-685) and
[DOCS-738](https://linear.app/codercom/issue/DOCS-738).

> [!IMPORTANT]
> **Stacked on [#28960](https://github.com/coder/coder/pull/28960)**
(DOCS-871, terminology). Base is that branch, not `main`. Retarget to
`main` after it merges.
>
> **Paired with coder/coder.com
[#1077](https://github.com/coder/coder.com/pull/1077)**, which must
merge **first**. Without it, every inbound link to a moved page 404s in
the gap.

## Deliberately mechanical

No prose changes. The only edits inside moved pages are relative link
and image path repairs, so the diff reads as renames. That is the point:
this is the highest link-breakage change in the project, and it should
be reviewable as such.

The prose work is [DOCS-868](https://linear.app/codercom/issue/DOCS-868)
(phase overview, architecture rewrite, sizing split, actor table) and
[DOCS-872](https://linear.app/codercom/issue/DOCS-872) (new pages).

## The new spine

```text
Install and deploy Coder            /install
├── Coder CLI                                   [unchanged, retired by DOCS-870]
├── 1. Plan your deployment
│   ├── Architecture and components             [from admin/infrastructure]
│   └── Coder Validated Architecture            [from admin/infrastructure]
│       └── 1k / 2k / 3k / 10k users
├── 2. Prepare prerequisites
│   ├── Licensing                               [from admin/licensing]
│   ├── Air-gapped deployments                  [from install/airgap]
│   └── Mirror images and registries            [from install/registry-mirror-artifactory]
├── 3. Install the control plane
│   ├── Docker / Kubernetes / Rancher / OpenShift
│   ├── Cloud marketplace and VM images
│   └── Unofficial install methods
├── 4. Validate your deployment
│   └── Scale testing                           [from admin/infrastructure]
│       ├── Scale test utility
│       └── Scaling best practices
└── 5. Operate and maintain
    ├── External provisioners                   [from admin/provisioners]
    ├── Upgrading (+ best practices, ESR guides)
    └── Uninstall
```

Leaving Install: release channels become `reference/releases`, feature
stages become `reference/feature-stages`.

`docs/admin/infrastructure/` is gone entirely, which is what DOCS-738
recommended.

## Numbers

- 31 pages moved, all as `git mv` renames.
- 1 page deleted: `admin/infrastructure/index.md`, whose content was a
one-line section blurb.
- 5 new placeholder index pages, one per phase, each a sentence of
orientation plus `<children></children>`. The nav schema requires a path
on every entry, so a phase cannot exist without one.
- 265 relative links and asset paths repaired across 57 files.
- `docs/manifest.json` restructured. Entry count goes 460 to 464: plus 5
stubs, minus the deleted Infrastructure entry.

## Reviewer attention, please

**The redirects PR repairs 19 existing redirects, not just adds new
ones.** This was the surprise. `redirects.json` already had entries
whose *destinations* pointed at pages this PR moves, so they would have
started redirecting to 404s. Examples:
`/docs/architecture/architecture`, `/docs/admin/architectures`,
`/docs/scaling/scale-testing`, `/docs/licensing`, `/docs/enterprise`,
`/docs/install/offline`, `/docs/platforms`, `/docs/install/1-click`,
`/docs/admin/upgrade`, `/docs/install/cloud/ec2`, and both
`feature-stages` aliases. All 19 are fixed in the paired PR.

**This PR touches `scripts/`, so it is not docs-only.** Two release
tools write to paths that moved and would have broken silently at
release time:

- `scripts/update-release-calendar.sh`: `DOCS_FILE` now points at
`docs/reference/releases.md`.
- `scripts/releaser/docs.go`: `releasesFile`, and also `kubernetesFile`
and `rancherFile`, which pointed at `docs/install/kubernetes.md` and
`docs/install/rancher.md`.

<details>
<summary>Deliberate scope decisions</summary>

- **Self-managed vs cloud grouping is flattened.** The reconciled IA
nested platform pages under a "Self-managed platforms" parent. That
would need two more placeholder index pages for groups with no content
yet, so the platform pages sit directly under Phase 3 and the grouping
lands with the DOCS-868 prose.
- **Release-notes URLs left alone.** `scripts/releaser/release.go` and
`scripts/release/generate_release_notes.sh` embed
`https://coder.com/docs/install/releases` and `/docs/install/upgrade` in
release-note templates. The redirects cover them, and changing the
strings would require updating Go test fixtures in
`scripts/release/main_internal_test.go`. Better as its own change.
- **In-product doc links left alone.** Several `site/src` pages link to
`coder.com/docs/admin/provisioners` and similar. Those are absolute
URLs, so the redirects cover them. Updating them is a frontend change
that would pull frontend review into a docs restructure.
- **`admin/security/audit-logs.md` line 237** is hand-written prose
below the generated table, and its `../licensing/index.md` link had to
move with the licensing page. Verified `make gen` does not revert it.
- **`reference/feature-stages.md`** has generated blocks whose relative
links changed depth with the move. The generator named in its own marker
comment (`scripts/release/docs_update_feature_stages.sh`) no longer
exists in the repo, so those links were repaired by hand and the file is
effectively hand-maintained. Worth its own issue.
- **`install/cli.md` keeps its nav slot** here. DOCS-870 retires it.

</details>

## Verification

| Check | Result |
|---|---|
| Broken relative link scan | 0 in `install/`, `admin/`, `reference/`.
21 remain, all pre-existing illustrative examples in
`docs/.style/style-guide/**` and one malformed URL in `docs/README.md` |
| `make gen` | clean, manifest not clobbered, phase structure intact |
| `make lint/markdown` | pass, 508 files, 0 errors |
| `make lint/emdash` | pass |
| `make lint/docs-html` | pass |
| `make lint/prose` | pass, 1 intentional demo error, no new findings |
| `make pre-commit` | pass, including `lint/go`, `lint/ts`,
`lint/shellcheck`, and a slim build |
| Manifest audit | every path resolves to a file on disk; entry-by-entry
diff shows only the expected moves |

Generated with Coder Agents on behalf of @nickvigilante.


<details>
<summary>CI note: doc-check failure is infrastructure, not this
PR</summary>

`Analyze PR for Documentation Updates Needed` fails before it reviews
anything: the Coder account behind `agents-chat-action` returns `User is
not active (status = "suspended")`. It isn't a required check.
`check-docs` (linkspector) and every other check pass on `58ed9e3e4b`.

_CI note added by Coder Agents on behalf of @nickvigilante._
</details>
2026-09-24 13:51:38 -04:00
Bobby Ho c95a87cea7 feat: warn before narrowing a self-registered OAuth2 app's scope allowlist (#29777)
- Warn rather than block when admins narrow a self-registered OAuth2 app's scope allowlist. Clients requesting all advertised scopes may receive `invalid_scope` on new authorizations; existing tokens retain their scopes.
- Expose `dynamically_registered` in API responses and display registration type on the app page.
- Show no warning for widening or clearing allowlists, or for admin-created apps.
- Update scope and `invalid_scope` troubleshooting docs and remove the outdated note that the UI cannot set allowlists.

Closes PLAT-664.
2026-09-24 08:03:32 -07:00
Ehab Younes bacb4fc6ed feat: expose per-app session counts (#29351)
Track individual applications across deployment statistics, Prometheus, telemetry, and the dashboard instead of exposing only fixed family totals. Preserve existing fields and gauges so current consumers can migrate without breaking.

- Add per-app counts with normalized identifiers and registry-backed display names, families, and bundled icons. Unrecognized apps retain their identifiers.
- Limit each statistics report to 64 distinct app names, combining excess names into an explicit overflow bucket.
- Group dashboard connections by family, including an Other category, with alphabetical per-app tooltips and distinct loading and empty states.
- Export app-keyed Prometheus counts separately from current family metadata, allowing queries to enrich historical counts without rewriting stored samples.
- Document family queries with unknown fallback, deployment isolation, and replica handling, alongside collection behavior and migration guidance.
- Include per-app counts in telemetry, update API schemas and documentation, and add regression coverage across collection, metrics, and dashboard behavior.

Closes #27411
2026-09-24 15:12:28 +03:00
McKayla はな 0c98308ca9 feat: default the CLI workspace search to the user filter (#29753) 2026-09-23 19:42:10 -06:00
Bobby Ho 528dd3cc44 feat: edit an OAuth2 app's redirect URIs as an ordered list (#29603)
Completes PLAT-619, following #29440 and #29502.

- Replace the OAuth2 app’s single callback field with an editable `redirect_uris` list supporting 1–32 entries, with the first labeled “Default callback.”
- Show a `+N` badge for additional redirect URIs in the applications table.
- Remove `omitempty` from request `redirect_uris` so explicit empty lists reach the server.
- Add tests and stories for adding, editing, removing, and requiring at least one URI.
2026-09-23 08:39:57 -07:00
Bobby Ho 395e8032dc fix: reject client_secret in the OAuth2 token and revocation URL (#29508)
Reject non-empty `client_secret` query parameters on token and revocation endpoints with `400 invalid_request`, enforcing OAuth 2.1 §2.4.1 (D6-04).

- **Breaking:** Send secrets in the request body or `Authorization` header, and rotate any previously sent in URLs. Rejections consume nothing, so clients can retry without reauthorization.
- Empty query secrets count as absent, but token requests also supplying a body secret still fail duplicate-parameter validation. Authorize ignores query secrets and logs a warning without the value.
- Sanitize and cap revocation parse errors, correctly report repeated token parameters, and update tests and API docs. Refusal logs include the app ID, never the secret.
- Other query parameters (`client_id`, `refresh_token`, `code`, and revocation tokens) remain accepted; body-only credential parsing is tracked in PLAT-660.

No migration or new error codes.

Refs PLAT-602.
2026-09-22 23:20:24 +00:00
Nick Vigilante 5e41baf73c docs: normalize control plane, coderd, and coder server terminology (#28960)
Normalizes the three overlapping names for the thing that serves the
Coder API and dashboard. This is step 1 of the Install/Deploy and
Administration refactor
([DOCS-685](https://linear.app/codercom/issue/DOCS-685),
[DOCS-738](https://linear.app/codercom/issue/DOCS-738)) and lands first
because every later page depends on settled terminology.

Resolves [DOCS-871](https://linear.app/codercom/issue/DOCS-871).

## The rule

| Term | Means | Use when |
|---|---|---|
| control plane | The component that serves the Coder API and dashboard,
brokers connections, and coordinates provisioners | Default in prose,
diagrams, planning, sizing, security |
| `coderd` | The process that implements it | Architecture internals,
metrics, logs, flags, troubleshooting |
| `coder server` | The literal CLI command | Only when the reader will
type it |

Retired: "the Coder server" as a name for the component, and "a service"
as a standalone description of it.

## What changed

- **`docs/.style/style-guide/word-choice.md`**: new "Naming Coder's
components" rule, with do/don't examples. Also fixes a "Do" example on
that page that itself used "the Coder server".
- **`docs/reference/glossary.md`**: rewrote `coderd` and Control plane,
added a `coder server` entry. The existing Control plane entry defined
it as "the collective term for `coderd`, its provisioners, and its
database", which made it indistinguishable from the Deployment entry two
sections later. Control plane is now the component; Deployment remains
the whole installation.
- **65 pages** across `docs/admin`, `docs/install`, `docs/get-started`,
`docs/tutorials`, `docs/user-guides`, `docs/ai-coder`, and `docs/about`:
roughly 154 component-sense "Coder server" usages, 21 bare "the server"
usages meaning the control plane, 3 "a service" descriptions, and 43
unbackticked `coderd` mentions in prose.
- One real bug caught in passing:
`docs/tutorials/best-practices/security-best-practices.md` documented
`coderd server --disable-path-apps`, which is not a command. Now `coder
server`.

Generated files were not touched: `configuration-reference.md`,
`prometheus.md`, `audit-logs.md`, `reference/cli/*`, `reference/api/*`,
and the generated blocks inside `feature-stages.md`. Those still contain
the retired term and need generator-side changes; see the deferred list
below.

## Reviewer attention, please

**Anchor changes.** 11 headings were renamed, so their fragments change.
No in-repo link targets any of them (the one internal link that did was
updated), but external deep links from tickets or blog posts would
break, and fragments cannot be fixed with a redirect. Happy to revert
any of these if you would rather they ride along with the page moves in
[DOCS-869](https://linear.app/codercom/issue/DOCS-869), which changes
those URLs anyway.

<details>
<summary>Renamed headings and their old fragments</summary>

| File | Old fragment | New heading |
|---|---|---|
| `admin/networking/index.md` | `#coder-server` | `## Control plane` |
| `install/index.md` | `#starting-the-coder-server` | `## Starting the
control plane` |
| `install/uninstall.md` | `#the-coder-server-binary-and-cli` | `## The
Coder binary and CLI` |
| `install/registry-mirror-artifactory.md` |
`#step-5-configure-coder-server-or-provisioners` | `## Step 5: Configure
the control plane or provisioners` |
| `install/cloud/compute-engine.md` | `#configuring-coder-server` | `##
Configuring the control plane` |
| `get-started/index.md` |
`#cant-start-coder-server-address-already-in-use` | ``### Can't start
`coder server`: Address already in use`` |
| `tutorials/external-database.md` |
`#coder-server-fails-startup-with-...` | ``### `coder server` fails
startup with ...`` |
| `tutorials/faqs.md` |
`#how-do-i-change-the-access-url-for-my-coder-server` | `## How do I
change the access URL for my control plane?` |
| `tutorials/best-practices/security-best-practices.md` |
`#coder-server` | `## Control plane` |
| `tutorials/best-practices/security-best-practices.md` |
`#server-logs-and-audit-logs` | `### Control plane logs and audit logs`
|
| `tutorials/best-practices/scale-coder.md` | `#coder-server`,
`#how-to-capture-coder-server-metrics-with-prometheus` | `## Control
plane`, `### How to capture control plane metrics with Prometheus` |

</details>

**One deliberate deviation from the issue.** DOCS-871 proposed reserving
"sub-agent" for the Coder Agents sense and using "devcontainer agent"
for the workspace sense. I did not make that change. The glossary
already disambiguates with "Sub-agent (Coder Agents)" and "Sub-agent
(dev containers)", and "devcontainer agent" would violate the existing
dev container spelling rule in the same style guide, which requires "dev
container" as two lowercase words. The current split reads correctly and
costs no churn. Happy to revisit if you disagree.

<details>
<summary>Deferred, with reasons</summary>

- **Generated content still says "Coder server".** `reference/cli/*`
comes from Go command help text, `configuration-reference.md` from
`configdocgen`, and `reference/api/*` from Swagger annotations. Fixing
those means changing Go source, which belongs in its own PR so a docs
review does not turn into a backend review.
- **`validated-architectures/index.md` "also known as `coderd`"** is
fixed here, but the page's larger problem is that it holds four
documents in one file. That split is
[DOCS-868](https://linear.app/codercom/issue/DOCS-868).
- **"server flag" phrasing** in `admin/users/idp-sync.md` and
`admin/users/oidc-auth/index.md` means `coder server` flags. Left alone;
rewording those sentences is a copy edit, not a substitution.
- **Metric and UI labels** such as "Dashboard-to-server latency" in
`admin/networking/index.md`. Renaming risks diverging from what the
dashboard shows.
- **Pre-existing `Coder.GerundHeading` warnings** on headings this PR
touches, and a "from from" typo in `scale-coder.md`. Out of scope for a
terminology pass.
- **Peer-sense "server"** in NAT traversal prose, where "client or
server" describes the connection roles rather than the control plane.
Needs restructuring, not substitution.

</details>

## Verification

| Check | Result |
|---|---|
| `make lint/emdash` | pass |
| `make lint/markdown` | pass, 504 files, 0 errors |
| `make lint/docs-html` | pass |
| `make lint/prose` | pass, findings identical to the `main` baseline (1
intentional demo error, 145 warnings, 1 suggestion; only Vale's file
ordering and one line-number shift in `glossary.md` differ) |
| `make gen` | clean, no drift |
| `make fmt/markdown` | applied |

No redirects needed: no page moved or was renamed in this PR.

<details>
<summary>Merged main, 2026-09-14</summary>

One conflict, in `docs/ai-coder/ai-gateway/providers.md`. Both hunks
were text this PR had edited and `main` had since deleted in #29053,
which removed env-based AI provider configuration:

- The deprecated provider seeding note, which held a `coderd` backtick
fix, is gone. Took `main`.
- The failure-mode table lost its env-drift row. Took `main`'s two rows
and reapplied the `coderd` logs wording.

`main` also landed new prose carrying the retired terms, so the pass was
extended to cover it:

- `docs/admin/integrations/oauth2-provider.md`: two "the server log(s)"
in the scope-enforcement sections added by #29144 are now "the `coderd`
log(s)"; "a `scope` the server will not grant" is now "the control
plane".
- `docs/reference/cli/index.md` gained "the server" from #29104, and
stays deferred as generated content.

The new `docs/ai-coder/agent-relay/claude-code.md` needed no change, and
no page `main` added links to a heading this PR renamed.

</details>

<details>
<summary>Decision log for the wider refactor</summary>

Agreed with @nickvigilante before implementation, recorded on DOCS-685
and in the Notion outline:

1. Feature stages and release channels move to Reference; ESR upgrade
guides move under Operate. No new top-level Releases section.
2. `data-retention.md` moves to Administration > Security;
`chat-lifecycle-hooks.md` moves into the Coder Agents docs.
`admin/setup/` therefore survives as "Deployment configuration" and
`configdocgen` is not touched.
3. Prepare is advisory, not a gate, framed as "don't know where to
start? Start here", with lead times and owners per item.
4. One actor table, on the Install overview, spanning all five phases,
noting that one person can be several actors and several people can be
one actor.
5. The quickstart stays independent and is mentioned once, on the
Install overview. The proposed `server/single-machine` page is dropped.
6. Coder Validated Architecture keeps its name in nav, defined in-page,
with a glossary entry.
7. PR 3 is split: moves only, then prose, so the riskiest change reads
as a pure rename diff.
8. For every PR that moves a page, the coder.com `redirects.json` change
merges first.
9. There is no Download section and no CLI page in docs. Per-OS CLI
steps live on coder.com/download and the Install overview links to it.

</details>

Generated with Coder Agents on behalf of @nickvigilante.
2026-09-22 15:18:40 -04:00
Bobby Ho 9fd0131d04 feat: accept redirect_uris on the OAuth2 app admin API and deprecate callback_url (#29502)
- Add `redirect_uris` to admin OAuth2 app responses and create/update requests.
- Deprecate `callback_url` while preserving compatibility; it maps to the first redirect URI.
- Reject empty `redirect_uris` lists instead of silently ignoring them.
- Update fixtures, tests, and docs.

Part of PLAT-619. Builds on #29440; admin UI support follows in #29603.
2026-09-22 19:12:27 +00:00
Nick Vigilante 6dd2e95692 docs: describe organization roles and correct the roles permission claims (#29303)
## Summary

The roles reference documented deployment-wide roles only.
Organization-scoped roles were named in passing on three other pages but
defined nowhere, and two statements on the page contradicted the RBAC
code.

Closes
[DOCS-891](https://linear.app/codercom/issue/DOCS-891/organization-scoped-roles-are-defined-only-in-code-not-in-the-docs)

## Problem

`coderd/rbac/roles.go` and `coderd/rbac/rolestore/rolestore.go` define
eight organization-scoped roles. `docs/` defined none of them. Searching
`docs/` for `organization-auditor`, `organization-user-admin`,
`organization-service-account`, and
`organization-workspace-creation-ban` returns nothing, and
`organization-admin` appears only inside an IdP sync JSON example.

That produced three concrete defects:

- **Dead-end cross-reference.** The AI Gateway group budget prerequisite
named the Organization Admin and Organization User Admin roles and
linked to a page that defines neither.
- **Incorrect Member claim.** The page said all users hold an implicit
Member role "that may use personal workspaces." The site `member` role
grants no workspace permissions, and `OrgMemberPermissions` grants none
either. Workspace access comes from `organization-workspace-access`,
which organizations attach through their default member roles.
- **Unqualified Owner row.** The table asserts Owner can execute and use
all workspaces. `CODER_DISABLE_OWNER_WORKSPACE_ACCESS` removes SSH and
application access from the role, and the flag was documented only in
the generated CLI and configuration references.

## Fix

Adds an Organization roles section to the roles page covering the six
assignable organization roles, where to assign them, and the implicit
membership role the dashboard doesn't display. It also records that
Organization Admin excludes SSH, application, and terminal access to
other members' workspaces, which is the least discoverable part of the
model.

Corrects the Member and Owner statements, retargets the group budget
prerequisite at the new section, notes that the Disabled workspace
sharing policy overrides the sharing permission of any role an
organization member holds, and fixes the built-in roles and custom roles
glossary entries.

The deployment roles table is deliberately untouched.
[ENG-873](https://linear.app/codercom/issue/ENG-873/autogenerate-roles-documentation)
replaces it with a generated table, so correcting the Auditor row or
adding an organization matrix by hand now would be churn. The new
section is prose a generator won't emit, so the two changes compose.

<details>
<summary>Verification and scope notes</summary>

**Claims verified against source, not assumed:**

| Claim | Source |
|---|---|
| Six assignable organization roles and their display names |
`builtInRoles` in `coderd/rbac/roles.go` |
| Organization Admin lacks `ssh` and `application_connect` | `orgAdmin`
role, `slice.Omit(ResourceWorkspace.AvailableActions(), ...)` |
| Member role grants no workspace permissions | `memberRole.User`
excludes `ResourceWorkspace` with no add-back |
| Workspace access comes from the default member roles |
`DefaultOrgMemberRoles()` and `orgWorkspaceAccessMemberPerms()` |
| `organization-member` and `organization-service-account` have no
display name, so the dashboard never shows them | `systemRoles` in
`rolestore.go`, `DisplayName: ""` |
| Disabled sharing overrides other roles | org-level negative
`workspace:share` permission in `OrgMemberPermissions` |
| Roles are assigned on the organization Members page | `Edit roles`
action in `OrganizationMembersTable.tsx` |
| Flag, environment variable, and YAML names | `codersdk/deployment.go`
|

**Scoped out deliberately:**

- The Disabled-sharing note says "any role held by a member of that
organization" rather than naming Owner. The negation rides on the
organization membership role, so it doesn't reach an Owner who isn't a
member of that organization.
- Pre-existing gerund headings on the touched pages (`Creating custom
roles`, `Getting Started`, `Sharing your Workspace`, `Using a shared
workspace`, `Accessing workspace apps in shared workspaces`) are left
alone to keep the diff scoped. Vale reports them as warnings on `main`
today.
- `## Custom Roles` is retitled to sentence case. The GitHub anchor slug
is unchanged, so inbound links still resolve.

**Checks run:** `make fmt/markdown`, `make lint/markdown`, `make
lint/emdash`, and `vale` on the four changed files. Vale reports zero
findings from the new text. Every link added or changed was resolved to
its file and heading anchor.

**Also worth knowing:** three en dashes in the workspace sharing policy
list are replaced with colons. `scripts/check_emdash.sh` only scans
changed files, so they survived on `main` and would have failed this
PR's CI once the surrounding lines were touched.

</details>

---

Opened by Coder Agents on behalf of @nickvigilante.
2026-09-22 14:17:00 -04:00
Michael Suchacz 80eee58d1d feat: add the organization AI spend client method and report fixture (#29627)
Adds `API.getOrganizationAISpendUsers(organizationId, params)` for `GET
/api/v2/organizations/{organization}/ai/spend/users` (period, provider,
model, client filters plus `limit`/`offset`), the
`MockOrganizationAISpendReport` fixture, and a shared
`codersdk.MaxAISpendPeriodDays` constant that the enterprise export
handler now reads and that `make gen` emits into `typesGenerated.ts`.

The model-list endpoint also accepts a literal `model` prefix. The
backend escapes SQL LIKE characters, while `q` keeps its existing search
syntax. Supplying both nonempty parameters returns 400. The filter menu
adopts this parameter in #29632.

## Why

The frontend caps custom ranges at the same 31-day limit the server
enforces; one SDK constant keeps the two from drifting. The fixture is
what every later test and story renders. Literal model identifiers
should not require search-language quoting or SQL escaping in the
frontend.

## What to scrutinize

- `enterprise/coderd/aibridge.go`: `maxAISpendExportPeriod` is now
derived from the SDK constant, same value as before.
- `MockOrganizationAISpendUser` is not exported yet; the table PR
exports it for its stories (knip fails on exports without a consumer).

## Generated files

`site/src/api/typesGenerated.ts`, `coderd/apidoc/docs.go`,
`coderd/apidoc/swagger.json`, and `docs/reference/api/aigateway.md` via
`make gen`.

## Validation

`pnpm test src/api/api.test.ts -t getOrganizationAISpendUsers` (new
case), `go test ./enterprise/coderd/ -run TestAIBridgeListModels
-count=1 -v`, repository pre-commit including `make gen` with no drift.
Model tests cover literal punctuation, prefix matching, existing `q`
behavior, and conflicting parameters.

## Delivery record

Published head `8d9a4faa0aa` passed per-layer integration checks and
commit hooks. The composed head `d899228f798` passed format, check, full
frontend lint, 125 unit tests, and 86 story tests. Pre-push hooks were
skipped as requested. See #28964 for audit findings, their disposition,
and historical UAT limits. No exact-head live UAT or new independent
re-review is claimed.

## Stack context

PR 3 of 9. The stack adds a **User spend** page under **Admin settings**
> **AI** > **User spend**: total and per-user AI Gateway spend for one
organization over a reporting period, read from `GET
/api/v2/organizations/{organization}/ai/spend/users` (#29129, merged).
It is #28964 split into one-concern PRs. Historical UAT covers earlier
heads only; live UAT has not been rerun after these review fixes. Bottom
to top: DateRangePicker limits, shared dimension badge, API client
method, spend table, page view, page container, reporting period,
dimension filters, route and navigation (#28964).

> Xum prepared this PR on behalf of @ibetitsmike.
2026-09-22 12:45:18 +00:00
Thomas Kosiewski 60cc826f2b feat: sign forwarded MCP identity headers (#29669) 2026-09-22 11:11:08 +02:00
Michael Suchacz af0ef00f91 feat: add owner_id to CreateChatRequest to create chats for another user (#29581)
Owners and owner-level service accounts can now start a Coder Agents
chat on behalf of another user by setting `owner_id` on `POST
/api/v2/chats`. The field is optional and defaults to the caller, so
existing clients are unaffected. A delegated owner must be an active,
non-system member of the requested organization; anything else returns
400 `Chat owner must be an active member of the organization.` once the
caller has passed the authorization gates below.

A chat runs entirely with its owner's credentials (synthetic API key,
workspace access, OIDC and provider tokens), so creating one for someone
else is acting as that user. On top of org-scoped `chat:create` for the
owner, the caller must hold the authority to create API keys for that
user, which is what the token endpoint demands to mint their session.
Org admins therefore cannot use it; site owners and owner-role service
accounts can. For the same reason the workspace binding, model config,
and MCP server IDs are validated as the owner rather than the caller,
and the owner must themselves hold `chat:create` (organization service
accounts do not). The initial user message is attributed to the caller
through `chatd.CreateOptions.CreatedBy`.

An earlier revision of this PR exposed the same behavior as `POST
/api/v2/users/{user}/chats`; that route and
`codersdk.Client.CreateUserChat` were removed in `62a8be3dd32` in favor
of the request field. An explicit zero `owner_id` is rejected with 400
rather than silently defaulting to the caller. Coverage lives in
`TestPostChats_OwnerID`.

<details>
<summary>Review record (path-based revision, gates unchanged)</summary>

- Two-axis code review (Standards, Spec) plus a simplicity audit ran as
Xum sub-agents on `1f3189898f0`. The Spec axis found the workspace
binding was authorized as the caller, fixed in `363d45281d8` with
red-green coverage in `WorkspaceNotAccessibleToOwner`. The additional
API-key gate and the `CreatedBy` attribution go beyond the workspaces
pattern and were kept deliberately for the reasons above.
- Codex review on `363d45281d8`: one P2, suspended, dormant, or system
users could be targeted and would get a chat that can never run because
AI Bridge refuses to authorize them. Fixed in `c065437e359` with
`OwnerSuspended` (red on the old head); thread replied to and resolved.
- Codex review on `c065437e359`: one P2, an explicit or
personal-override model config the caller can read but the owner cannot
was accepted and chatd would silently fall back to the default model at
run time. Fixed in `aa88b608182` by resolving the model config and MCP
server IDs under the owner's context, with
`ModelConfigNotAccessibleToOwner` (red on the old head); thread replied
to and resolved.
- Codex review on `aa88b608182`: one P2, an organization service account
(which deliberately holds no chat permissions) could be targeted because
the chat permission check ran as the caller. Fixed in `a6fe8075c30` by
also requiring the owner subject to hold `chat:create`, with
`OwnerWithoutChatPermission` (red on the old head); thread replied to
and resolved.
- Codex review on `a6fe8075c30`: one P2, the active/non-system check was
skipped when the caller could not read the owner's user object. Fixed in
`0dd8bb4dd44` by moving the check behind the authorization gates with a
system-restricted lookup; thread replied to and resolved. In
`62a8be3dd32` that lookup became a single `OrganizationMembers` query,
which also covers membership and excludes system and deleted users.
- Codex review on `62a8be3dd32` (the `owner_id` revision): two P2s. An
explicit zero `owner_id` was treated as omitted and created the chat for
the caller; fixed in `f54b4f33d36` with a 400 and `OwnerIDNil` (red on
the old head). Creation and the read-back still ran as the caller while
the preflight ran as the owner; fixed in the same commit by passing
`ownerCtx` to `CreateChat`, `GetChatByID`, title generation, and the
file-metadata fetch. That second scenario is unreachable today (only the
built-in `owner` role holds `api_key:create` for others, and site-wide
custom roles are refused by both the API and dbauthz), so it has no
dedicated red test. Both threads replied to and resolved.
</details>

<details>
<summary>Remote UAT record (path-based revision)</summary>

Remote UAT on dogfood (chat `d7442df3-693f-4403-805f-2de52f7bdbed`, Xum
sub-agent as critical runner) tested head `21ed6b389cc`, the last
path-based revision. Licensed dev server, real Haiku 4.5 model, 77
logged API requests, 23 inspected screenshots. Endorsed verdict:
**PASS**. Site owner creates a chat for member X: X sees it, gets real
answers to the admin prompt and to follow-ups, and state survives reload
and mid-response refresh. The creating admin gets `403 Only the chat
owner may send messages.` and a read-only view; an unrelated member gets
404. Org admin, member, user-admin, and template-admin callers get 403;
owner-role service account 201. Suspended, dormant, and service-account
targets 400; owner-inaccessible workspace, model config, or MCP server
400; 300 KiB body 413. The `owner_id` revision changes only how the
owner is supplied and the non-member response (400 instead of 404); the
authorization and eligibility gates it exercised are unchanged and
covered by `TestPostChats_OwnerID`.

Non-blocking findings for the author's judgment, none of them
regressions of this PR:
1. X's UI shows no author on the admin-written first message and offers
X "Edit" on it; `created_by` carries the admin but the frontend does not
surface it.
2. A site owner who is not a member of the organization can still create
a chat for its members (201), while a self-owned `POST /chats` returns
403 for the same organization; same asymmetry as `postUserWorkspaces`.
3. The creating admin can archive, rename, and interrupt X's chat
although it cannot message it (pre-existing chat authz).
4. Owner-inaccessible model config or MCP server is reported as "not
found or disabled" with no hint that the owner, not the caller, lacks
access.
5. Dormant (never logged in) targets are refused because AI Bridge
rejects non-active users; a new hire cannot be given a chat until first
login.
6. The endpoint docs list only 201 and 413.
</details>

> Xum (an AI agent) acted on behalf of @ibetitsmike for this PR.
2026-09-21 20:49:10 +02:00
Michael Suchacz 2bf0f567d8 feat: add OpenAI Pro reasoning mode to chat model configs (#29584)
Adds `provider_options.openai.reasoning_mode` (`pro`) to chat model
configs so admins can turn on OpenAI's Pro reasoning mode for a model,
alongside the other OpenAI request options on the model form such as
`service_tier`. The field is offered for any model on an OpenAI
provider; the field description says Pro is supported from the GPT-5.6
Sol generation and that requests fail when Pro is set on a model that
does not support it. There is deliberately no supported-model list
anywhere: a newly released model that supports Pro works with no code
change, and OpenAI rejects the request when the model does not.
Validation rejects only values other than `pro`, non-OpenAI providers,
and configs that explicitly force plain sampling
(`reasoning_model=false`) or Chat Completions
(`use_responses_api=false`), including partial updates that move a
configured model onto such a provider or transport.

A configured mode implies the Responses API and reasoning-model
treatment when `openai_config` leaves those unset
(`chatprovider.effectiveOpenAIConfig`), so an alias the pinned SDK has
never seen, such as `gpt-daybreak-blue-latest`, still gets `effort` and
`summary` and drops `temperature`. The same effective config feeds the
client options and the recorded transport, so the two cannot disagree.

The pinned fantasy OpenAI provider options do not carry
`reasoning.mode`, so the mode is applied as a client-scoped `openai-go`
request option when the model client is built rather than per call. The
SDK merges pre-serialization `WithJSONSet` overlays by top-level key, so
the key is escaped (`reasoning\.mode`) to add `mode` to the existing
`reasoning` object instead of replacing `effort` and `summary`.
`TestResolveModelCallReasoningModeWire` pins the resulting request body
for streaming and non-streaming calls and checks that the fixed
computer-use model does not inherit the mode; AI Gateway forwarding of
the `reasoning` object is covered in `aibridge`. Because the option is
bound to the model client, every call made through a Pro model config
carries it, including title generation and quick generation when those
fall back to the chat's model; deployments that want cheaper auxiliary
calls should point the title generation override at another model.

Frontend: the field renders through the existing schema-driven provider
options with no hand-written field logic. Two generic changes:
`visible_for_providers` is now honored for provider fields the way it
already was for general fields (render and payload), so the
OpenAI-scoped select does not appear or serialize for Azure, which
shares the OpenAI field group; and the add/update model save toasts now
carry the server's error detail, so a rejected combination such as Pro
with Use Responses API at Off tells the admin which field to change.

Docs: `docs/ai-coder/agents/models.md` gains a Reasoning Mode row in the
OpenAI provider-specific options table (from the documentation check
comment
https://github.com/coder/coder/pull/29584#issuecomment-5752457808), and
its Azure note now says Azure OpenAI lacks that one option.

Not changed: `coderd/x/chatd/ARCHITECTURE.md`. Its OpenAI transport
selection table needs a `reasoning_mode` row (client-applied, neither
transport) to match `TestProviderOptionsTransportParity`; left for the
human author.

<details>
<summary>Delivery record</summary>

- Local validation on every pushed head: targeted Go tests (chatopenai,
chatprovider, chatd wire test, aibridge integration test, coderd DB
tests for persistence, invalid input, and partial updates), red/green on
the wire test (injection removed, and unescaped key), Vitest
(`modelConfigFormLogic`, `ModelForm`), Storybook tests for
`ModelFormProviderConfig`, biome, tsc, oxlint, golangci-lint on touched
packages, pre-commit hook.
- Codex round 1 on `e7dbaefeafc`: 3 findings (Storybook assertions,
ARCHITECTURE.md TODO, `gpt-daybreak-blue-latest` alias). Disposition:
assertions moved to Vitest and alias accepted in `8fccf111111`;
ARCHITECTURE.md left untouched by author instruction. Threads replied to
and resolved.
- Codex round 2 on `8fccf111111`: 1 finding (fixture naming, FE9),
renamed in `23449e92317`. Round 3 on `23449e92317`: 1 finding (fixture
location, FE9), moved to `testHelpers/chatModels.ts` in `c3bd5aa370f`.
Round 4 on `c3bd5aa370f`: "Didn't find any major issues"
(https://github.com/coder/coder/pull/29584#issuecomment-5735119236). All
threads resolved.
- Remote UAT round 1 (chat
https://dogfood.cdr.dev/agents/f5ed1d16-be1d-4d39-952b-126a6a829ef1)
exercised `e7dbaefeafc`: endorsed PASS. Real `gpt-5.6-sol` turns showed
`"mode": "pro"` / `"standard"` / no key in the Debug tab with effort and
summary intact; 14 POST and 6 PATCH rejections captured; UI select
visibility, persistence, reload, and clearing verified. Low,
non-blocking notes: the `gpt-5.6` alias revert in the model identifier
field is pre-existing; Pro is dropped silently when a model or transport
change makes it unsupported; Pro applies to auxiliary calls (see above).
- Remote UAT round 2 on `c3bd5aa370f` (same chat, alias and core
re-verify): core PASS, alias FAIL. With `gpt-daybreak-blue-latest` the
request carried `{"mode": "pro"}` without the configured effort and
summary and kept sending `temperature` (provider 400 then retry on quick
generation and title calls), because the SDK does not classify the alias
as a reasoning model. Fixed in `d4c338de767`: a configured mode now
implies a reasoning model unless `openai_config.reasoning_model` is set,
and a mode on a config that forces plain sampling is rejected. Alias
UI/API behavior, rejections, and known-model Pro/Default turns all
passed on `c3bd5aa370f`.
- Codex round 5 on `d4c338de767`: "Didn't find any major issues"
(https://github.com/coder/coder/pull/29584#issuecomment-5736190356).
Zero unresolved threads. CI green on `d4c338de767`.
- Remote UAT round 3 on `d4c338de767` (same chat): endorsed PASS. Alias
runs are single-attempt 200s with `{"effort", "summary", "mode": "pro"}`
and no `temperature` (quick generation and title calls no longer retry);
`reasoning_model=false` plus a mode is rejected by POST and PATCH with
the stored config unchanged; the Reasoning Model override at Off hides
the select and drops the mode on save; `gpt-5.6-sol` Pro turn unchanged.
Remaining low notes, none introduced here: rejection detail for a
non-OpenAI provider names the model rather than the provider; Pro is
dropped silently when an override makes it unsupported; `PATCH
model_config` replaces the whole object (pre-existing on main).

- coder-frontend-review on `d4c338de767` (8 role reviewers, 3 passes):
13 failing checkpoints, chiefly a TS mirror of the Go model regex, the
`json_name === "reasoning_mode"` gate duplicated in the render filter
and payload builder, a defaulted `model` parameter, and comment and type
nits. Fixed in `554c90d5fd9`: the pattern and provider scope are
generated onto the field schema, one predicate is shared by both call
sites, `buildModelConfigFromForm(provider, model, form)` requires the
model, and the ModelForm test also asserts the select disappears for an
unsupported model. Red/green: stripping `supported_models` or
`visible_for_providers` from the generated schema fails 21 and 1 Vitest
cases respectively. Declined with rationale: RO4 (move the fixture to
`ModelsPage/testFixtures.ts`; FE9 in `FRONTEND_PATTERNS.md` names
`testHelpers/chatModels.ts`, and Codex round 3 required it) and a DF5
nit to gate on the committed identifier and warn when a saved mode is
dropped (behavior change, separate follow-up). Final pass: all
checkpoints PASS or N/A.
- Remote UAT round 4 on `554c90d5fd9` (same chat, focused regression
after the frontend-review refactor): endorsed PASS. All six claims held
(Pro round trip with effort and tier intact; unsupported identifiers
hide the select and a save drops the stale mode while keeping the other
options; Azure never shows or saves it; the alias shows it only with the
Responses override On; Reasoning Model Off hides it and drops it; three
real `gpt-5.6-sol` Pro turns were single-attempt 200s with
`{"effort","summary","mode":"pro"}` and no `temperature`). Probes aimed
at the refactor also passed: `gpt-5X6-sol` is rejected (dot escaping
survived the JSON round trip), whitespace-padded identifiers still
match, the other 11 OpenAI fields and the Anthropic section still
render. Remaining low notes are carried over from round 3 plus one
naming note ("Reasoning Mode" versus "Reasoning Model"). The final head
`abb58df77d8` differs from `554c90d5fd9` only in `ModelForm.test.tsx`,
so it ships the same production code.
- Codex round 6 on `554c90d5fd9`: 1 finding
(https://github.com/coder/coder/pull/29584#pullrequestreview-5260492465):
the two `toBeInTheDocument` assertions added in the frontend-review
round violate FE1. Confirmed against `site/AGENTS.md`; removed in
`abb58df77d8` (test-only, 7 deletions; the payload assertion keeps the
behavior coverage and the `ProviderConfigOpenAI` story captures the
hidden state). Thread replied to and resolved.
- Codex round 7 on `abb58df77d8`: "Didn't find any major issues"
(https://github.com/coder/coder/pull/29584#issuecomment-5749626071).
Zero unresolved threads. CI green on `abb58df77d8` (23 success, 8
skipped, `required` pass).

- Design change on `e99152e5c57` (owner direction: no model gating;
"none or pro" for any model; tooltip states the GPT-5.6 Sol constraint
and that requests fail on unsupported models). Removed
`codersdk.ChatModelReasoningModeModels`, the generated
`supported_models`, `isFieldApplicableToModel`, the
`gpt-daybreak-blue-latest` special case, and the `standard` enum value;
`ValidateReasoningMode(provider, config)` no longer takes the model;
`effectiveOpenAIConfig` makes a mode imply Responses and reasoning-model
treatment. PR footprint went from +1130/-22 to +769/-18. Local
validation: `go test` for chatopenai, chatprovider, chatd wire test, and
the coderd API tests (persistence now covers `gpt-5.6-sol`, `gpt-4o`,
`gpt-daybreak-blue-latest`, `gpt-7-nova`; invalid input now rejects
`standard`), golangci-lint on touched packages, Vitest (187 tests across
`modules/aiModels` and `ModelsPage`), biome, tsc, pre-commit hook.
- coder-frontend-review on `e99152e5c57` (8 roles, 1 pass plus a TS and
CD confirmation pass): 9 failing checkpoints (SD4, CD1, CD3, CD4, TS3,
TS7 x2, RO3, RO5, TN4, DF5). Fixed in `e06bfbe4299`: the ModelForm test
edits `mockGPT5` so its provider matches the selected provider state,
types the update mock like the sibling story, and drops an unused route;
the story spreads `mockGPT5` with a saved mode instead of a dedicated
shared fixture (`MockGPT56Pro` removed, `testHelpers/chatModels.ts` back
to base); a `ProviderConfigAzure` story captures the panel without
`reasoning_mode`; comment nits. Left as a nit with justification: RO3
(the one-line `!hidden && isFieldVisibleForProvider` predicate now
appears in both `getVisibleProviderFields` and
`getVisibleGeneralFields`; hoisting a helper for two call sites is not
worth it). Confirmation pass: TS all PASS; CD flagged one wording nit,
fixed before commit.
- CI green on `e06bfbe4299` (23 success, 8 skipped, `required` pass).
- Codex round 8 on `e06bfbe4299`: 1 P2 finding
(https://github.com/coder/coder/pull/29584#discussion_r4057659673): the
form still offers Pro with Use Responses API or Reasoning Model at Off,
a combination the server rejects, and the failure was not actionable.
Disposition: the select stays visible by owner direction (no client-side
gating of this field beyond the provider scope; an explicit rejection is
preferred over the earlier silent drop), and `e2b43c3aee7` makes the
add/update save toasts show the server detail so the admin sees which
field to change. Thread replied to and resolved; zero unresolved
threads.
- Remote UAT round 5 on `e06bfbe4299` (same chat): endorsed PASS with
two UI issues to land before release. All seven probes passed: the
select offers only Default and Pro for `gpt-5.6-sol` and `gpt-4o` with
the tooltip text verbatim; Pro saves on `gpt-4o` and the real turn fails
visibly with the provider's "reasoning.mode is not supported with this
model" after a single 400 attempt, and works again once Pro is cleared;
`gpt-daybreak-blue-latest` with Pro and no overrides is a single 200 to
`/v1/responses` with `{effort, summary, mode: "pro"}` and no
`temperature`; the `gpt-5.6-sol` Pro turn is unchanged; POST and PATCH
reject `standard`, `PRO`, empty, Responses Off, Reasoning Model Off, and
Azure, openai-compat, and Anthropic providers with the stored config
unchanged, while a model-only PATCH to `gpt-4o` now succeeds; the Azure
form shows no Reasoning Mode; the alias with an explicit Responses
override still works. Reservations: (1) medium, the UI conflict path
only showed "Invalid model config." without the detail (fixed in
`e2b43c3aee7`, not yet UAT-exercised); (2) low-medium, a dev-DB row
still holding `standard` from round 2 renders an empty red select whose
message is the whole field description plus "has an invalid value." and
blocks saving unrelated fields (pre-existing generic behavior of
`yupTestForField` using the description as the label; no released data
can hold `standard`, so no migration); (3) low, no hint next to older
identifiers (documented design); (4) low, a chat on such a stored row
fails with a generic headline (pre-existing).
- Final head `e2b43c3aee7` differs from `e06bfbe4299` only in the two
save-toast handlers (`AddModelPage.tsx`, `UpdateModelPage.tsx`, 8
insertions). CI is green on `e2b43c3aee7` (skipped=8, success=23,
`required` success). Codex has not run on `e2b43c3aee7`.
- Remote UAT round 6 on `e2b43c3aee7` (same chat,
https://dogfood.cdr.dev/agents/f5ed1d16-be1d-4d39-952b-126a6a829ef1,
settled 2026-09-20T19:02Z): endorsed PASS on the exact final head. Build
proven by `/api/v2/buildinfo` (`v2.37.2-devel+e2b43c3aee`,
`external_url` at the full SHA) and the UI badge. The round 5 toast
issue is resolved: Add and Update saves with Pro plus Use Responses API
Off or Reasoning Model Off show "Invalid model config." with the server
detail as the description, one 400 each, nothing stored. Compact
regression of every round 5 probe held (dropdown and tooltip; Pro on
`gpt-4o` fails visibly with the provider's `reasoning.mode is not
supported with this model` and works after clearing; alias with and
without the Responses override and `gpt-5.6-sol` all send `{effort,
summary, mode: "pro"}` with no `temperature` in a single 200; POST and
PATCH rejection matrices with stored config unchanged; Azure form
without the field). Legacy `standard` row: fails closed on chat, and
re-picking Pro or Default saves. Remaining notes, none blocking: the
malformed validation copy for an invalid stored enum (pre-existing
`yupTestForField` label choice, dev-DB rows only), Pro offered for
models that cannot accept it (documented design), and a pre-existing
`quickgen` status quirk on `gpt-4o` unrelated to this field. Secret scan
clean.
- Final head `4f3c6106dfe` adds one docs-only commit on top of
`e2b43c3aee7` (`docs/ai-coder/agents/models.md`, 9 insertions, 8
deletions, no code). Remote UAT round 6 exercised `e2b43c3aee7`; the
docs commit is not UAT-relevant. Validated with
`markdown-table-formatter`, `markdownlint-cli2`, and the pre-commit hook
(`fmt/markdown`, `lint/markdown`, `lint/emdash`, `lint/typos`). CI is
green on `4f3c6106dfe` (success=24, skipped=7, `required` success) and
the documentation check re-run marked its item addressed
(https://github.com/coder/coder/pull/29584#issuecomment-5752457808).
- Review tally for this PR: Codex 8 completed rounds;
coder-frontend-review 34 role passes (24 on `d4c338de767`, 10 on
`e99152e5c57`); remote UAT 5 rounds; no human review yet. This is far
past the six-review guardrail, so no further Codex or agent review has
been requested. Whether to spend another Codex pass on `e2b43c3aee7` is
an owner decision; human review is still required before merge.

</details>

> Xum acted on behalf of @ibetitsmike.
2026-09-21 15:58:18 +02:00
Spike Curtis 29ae50d9c9 feat: accept include_related query param on get workspace by ID (#29539)
Part of the lite `codersdk.Workspace` work
([GRU-82](https://linear.app/codercom/issue/GRU-82),
[RFC](https://app.notion.com/p/coderhq/Lite-Workspace-API-Requests-3aad579be5928060b5e7cc65c539717f)).
Follows #28639, which added the `wsrelated` package and parser.

Wires the `include_related` query parameter into `GET
/api/v2/workspaces/{workspace}`, the first endpoint to accept it. When
present, the value is parsed with `wsrelated.Parse` and the resulting
selection is threaded into `workspaceData`, so only the requested
related data is queried. Omitting the parameter is backward compatible
and returns everything (`wsrelated.All`). An invalid value returns
`400`.

Because related data can now be omitted, the handler no longer assumes
the build and template are present: it uses zero values when they are
absent, and only enforces the template read-authorization check (`403`)
when the template was actually requested.

### Partial-build conversion

`convertWorkspaceBuilds` now tolerates a build whose provisioner job or
template version was deliberately omitted from the selection, so
selections such as `latest_build` (build only) or
`latest_build.resources.*` (resources without the job) convert correctly
instead of erroring. The omitted fields are left zero (empty `Job`,
empty `TemplateVersionName`). Resources are keyed by the build's `JobID`
rather than the fetched job row, so they load independently of whether
the job is selected. The integrity error is preserved for full-data
callers: when a job or template version is requested but missing,
conversion still fails. The selection config (`wsrelated.LatestBuild`)
is threaded into `convertWorkspaceBuilds` to distinguish "not requested"
from "missing".

Only this endpoint is wired; the other endpoints that produce
`codersdk.Workspace` objects, and the codersdk client functions, come in
later PRs.

---

*Generated by Coder Agents on behalf of @spikecurtis.*
2026-09-21 10:50:01 +02:00
Ehab Younes 9974294ca9 feat: report arbitrary workspace agent session types (#28338)
Report session counts as a dynamic app-name map from the agent, the SSH CLI, and the workspace usage API, so a new IDE flows end to end without a schema, proto, or server change.

- Report through `Stats.session_counts` on Agent API v2.11. Older agents keep reporting through the deprecated count fields.
- Accept arbitrary names from `coder ssh --usage-app` and the workspace usage API. A name the registry does not recognize keeps its identity and is attributed to the `unknown` family.
- Add reconnecting PTY counts to the map without overwriting the counts SSH reported.
- Normalize and merge names before applying the deterministic 64-name cap, ordered by known apps, then count, then name. Overflow sums into `unknown`, and non-positive counts cannot cancel valid activity.
- Strip control characters, treat whitespace-only HTTP app names as absent, and require the exact environment variable prefix when you extract an SSH session type.
- Count overflow entries in `coderd_agentstats_session_counts_overflow_total` and keep raw payloads out of logs.
- Change the usage API's `app_name` to a string, and update the SDK types and API reference.

closes #27410
2026-09-19 00:32:51 +02:00
Bobby Ho 55da502938 feat: allow admins to configure an OAuth2 app's scope allowlist (#29313)
Add backend support for scope allowlists on admin-created OAuth2 apps, previously available only through DCR.

- Add optional, space-separated `scope` to create/update requests and return canonicalized, deduplicated scopes in app responses.
- On create, omitted or empty `scope` means unrestricted. On update, `scope` replaces the allowlist; omission preserves it, and an empty string clears it to unrestricted.
- Keep scope enforcement unchanged. Add tests for scope round-trips, DCR canonicalization parity, and authorization narrowing.
- Include generated SDK and docs updates. The UI scope picker follows in a separate PR.

Part of [PLAT-475](https://linear.app/codercom/issue/PLAT-475).
2026-09-18 11:58:49 -07:00
McKayla はな 8e159a8053 chore: remove stale TODO shims and dead code (#29252) 2026-09-18 10:27:26 -06:00
Paweł Banaszewski c47eb47393 feat: add stateless AI Gateway proxy mode (#29349)
Adds proxy mode to the AI Gateway. No AI provider is supported in this
mode yet.
2026-09-18 16:47:16 +02:00
Susana Ferreira c8b22a9d80 feat: add filters to the AI spend CSV endpoint (#29414)
## Description

Update the existing CSV export endpoint and SDK to accept user,
effective group, provider name, and model filters.

## Changes

- Pass the requested filters to the database query.
- Validate filters alongside the existing time window.
- Continue downloading all matching rows without pagination.

> [!NOTE]
> Generated by Coder Agents on behalf of @ssncferreira.
2026-09-18 15:26:24 +01:00
Cian Johnston 19076beb8d feat: attribute AI Gateway usage to workspaces (#29235)
- Adds nullable `workspace_id` to AI Gateway interceptions without a
foreign key or index.
- Derives direct attribution from strictly parsed server-minted workspace
session-token names, excluding user-created tokens and validating the
embedded owner.
- Derives delegated Coder Agents attribution from the persisted chat
workspace ID.
- Records `workspace_id` through the additive v1.3 gateway protocol and
structured interception logs.
- Exposes attribution in session details through
`interception_attributions`, including tool-less interceptions and null
values for unknown attribution.

Closes AIGOV-637

Generated by Coder Agents.
2026-09-18 15:22:02 +01:00
Spike Curtis aae145bdc9 feat: make NATS pubsub opt-out via no_nats_pubsub experiment (#29283)
Makes the embedded NATS pubsub an opt-out feature instead of opt-in. The
`nats_pubsub` experiment is removed and replaced with a `no_nats_pubsub`
experiment, so NATS pubsub is now the default and can be disabled to
fall back to PostgreSQL pubsub.

NATS clustering requires this replica's routable address, resolved into
`clusterHost` from either `--cluster-host` (`CODER_CLUSTER_HOST`) or the
DERP relay URL. When neither is set (allowed when DERP is disabled on
the primary), NATS cannot form a cluster, so startup logs a big error
and falls back to PostgreSQL pubsub. The NATS cluster CA is only
minted/rotated when NATS clustering is actually active (experiment not
set and a cluster host is present).

<details>
<summary>Implementation notes</summary>

- `codersdk/deployment.go`: removed `ExperimentNATSPubsub`
(`nats_pubsub`), added `ExperimentNoNATSPubsub` (`no_nats_pubsub`,
display name "No NATS Pubsub").
- `cli/server.go`: NATS is used by default unless `no_nats_pubsub` is
enabled; if `clusterHost` is empty, log an error and keep the PostgreSQL
pubsub.
- `coderd/coderd.go`: gate NATS CA minting/rotation on
`!ExperimentNoNATSPubsub && ClusterHost != ""` (i.e. only when NATS
clustering is active).
- `enterprise/coderd/licenses.go`: updated a stale comment.
- `enterprise/coderd/coderd_test.go`: `TestMultiReplica_NATSPubsubPeers`
no longer sets the removed experiment.
- Regenerated `coderd/apidoc/docs.go`, `coderd/apidoc/swagger.json`,
`docs/reference/api/schemas.md`, `site/src/api/typesGenerated.ts`.

</details>

---
*This PR was generated by Coder Agents on behalf of @spikecurtis.*
2026-09-18 12:58:06 +00:00
Ethan 77479408b4 feat: make the Coder Agents stream silence timeout configurable (#29394)
The `chatloop` stream silence guard cancels and retries a model attempt
after `10m` of silence, and it was hard-coded. It's armed before the
request opens, so it also bounds time to first token, and slow local
models (e.g. `llama-server` on a large prompt) can spend longer than
that on prompt processing alone, meaning every attempt just gets
cancelled and retried.

This PR adds `--chat-stream-silence-timeout` /
`CODER_CHAT_STREAM_SILENCE_TIMEOUT` (default `10m`) and passes it to
both the main loop and the advisor. Setting it to `0` disables the guard
entirely, and anything above `24h` is rejected, which also keeps the
watchdog arithmetic below from overflowing.

Whilst doing this I ran into the runner's `15m` task watchdog, which
kept counting during an open stream. That silently cancelled any healthy
stream longer than `15m`, and would've stopped a silence timeout above
`15m` from ever firing. To fix, the silence guard now kicks the watchdog
out to `max(15m, silence + 5m)` whenever it arms or sees a part. Silent
streams still fail through the guard, healthy streams can run for as
long as they like, and hang detection is unchanged everywhere else. With
the guard disabled there's nothing to kick against, so arming it just
stops the watchdog for the rest of the attempt. That does mean the DB
write after the stream isn't bounded either when `0` is set; I think
that's fine for an opt-in setting, and a user can still stop the chat
from the UI if it wedges there.

I did consider removing the guard entirely, but the provider HTTP
clients have no timeout, so a provider that holds the connection open
would only ever be caught as a generic task hang, which is what #25782
was fixing.
2026-09-18 15:24:15 +10:00
Steven Masley a90ad83af3 feat!: add a hidden flag to disable dynamic parameter closure evaluation (#29356)
**What changed**
Dynamic parameter rendering now evaluates only the coder parameter blocks and what they reference. Other root-module resources are skipped. Parameter, preset, and tag values are unchanged; optimizing rendering on large templates.

**How to revert**
Set `CODER_DYNAMIC_PARAMETERS_FULL_EVALUATION=true` (or `--dynamic-parameters-full-evaluation`) on `coder server` to restore full evaluation. The flag is hidden and needs no restart of workspaces. If you need it, please [open an issue](https://github.com/coder/coder/issues/new) with the template so we can fix the root cause.

**Troubleshooting**
Symptoms would be a parameter default, option list, preset value, or workspace tag that shows as unknown or empty after upgrading, when it was populated before. Confirm by setting the flag above; if the value comes back, report it. Templates written in `.tf.json` are not affected (they always use full evaluation).

**Why**
Rendering re-ran the entire template graph on every parameter change in the workspace form, which dominated latency on large templates. Resources a workspace would create cannot feed a parameter, so evaluating them is wasted work. The optimization lives in coder/preview#226 (coder/trivy#74); this PR adds the deployment-level escape hatch.

---

- `CODER_DYNAMIC_PARAMETERS_FULL_EVALUATION` / `--dynamic-parameters-full-evaluation` (hidden, default `false`) on `DeploymentValues`.
- `dynamicparameters.PreviewOptions(dv)` maps it to `preview.OptionFullEvaluation()`; `dynamicparameters.WithPreviewOptions` threads it through the loader to `preview.Preview`.
- Wired at the three render paths that hold deployment values: the template version tags extractor, the dynamic parameters websocket, and `wsbuilder` builds created from `coderd` (which call `.DeploymentValues(...)`).

Not covered: the autobuild lifecycle executor and the enterprise prebuilds reconciler construct `wsbuilder` without deployment values, so builds started from those paths use preview's default regardless of the flag. Those only re-render for builds, not the keystroke websocket path the optimization targets.

Prepared with Coder Agents assistance.
2026-09-17 14:33:37 -05:00
Jake Howell dd4f5ae48a fix: load AI Gateway session provider filter without AIProvider read (#28966)
> 🤖 This PR was modified by Coder Agents on behalf of Jake Howell.

The Provider filter on `/ai-gateway` called the owner-only
provider-config API (`GET /api/v2/ai/providers`). Site auditors can read
sessions but not that config, so the dropdown was empty, and typing
`provider_name:…` failed the whole sessions list because search looked
up the name with the same permission.

- Add `GET /api/v2/ai-gateway/providers`, returning display metadata
only (`name`, `type`, `display_name`, `icon`) from `ai_providers`,
including disabled and soft-deleted rows that past sessions still
reference. When a name was reused, the live row wins.
- Authorize it in `dbauthz` on `aibridge_interception` read rather than
`ai_provider` read, so owners and auditors get labels and icons without
access to configuration. Members get 404.
- Match `provider_name` as a plain string in session search instead of
looking up `ai_providers`. Unknown names return an empty page, not a
validation error.
- Point the Provider dropdown at the new endpoint; filter by name, show
`display_name`, and render the icon from `type`/`icon`.

The endpoint reads the small `ai_providers` table instead of grouping
`aibridge_interceptions`, so it needs no new index and does not inherit
the scan cost noted for the models/clients lists. It is registered only
under `/ai-gateway`, not the legacy `/aibridge` alias.
2026-09-17 15:29:21 +00:00
Paweł Banaszewski 263f2c207e feat: register AI Gateway proxy experiment and share provider helpers (#29347)
- Add `ai-gateway-reverse-proxy` experiment and update generated API
types and documentation. The experiment has no runtime effect yet.
- Extract shared (will be used by next PRs in stack) provider routing
and key-pool enumeration helpers.
- Log unsupported routes at Debug level.
2026-09-17 10:27:48 +02:00
Michael Suchacz 9d97337277 feat: list organization AI spend by user (#29129)
Third of a four-PR stack that reworks the AI spend page onto the
released organization spend export, `GET
/api/v2/organizations/{organization}/ai/spend/export`, and a sibling
per-user endpoint, `GET
/api/v2/organizations/{organization}/ai/spend/users`, instead of the
deployment-wide `/api/v2/ai-gateway/spend/*` endpoints this stack
previously proposed. Every PR in the stack was rewritten in place from
current main; the head branch name predates the rework. The export's
accounting rules are unchanged: token usage by `created_at` in
`[period_start, period_end)`, attributed to the organization through the
effective budget group, so the page reconciles with the CSV and with
daily budget accounting.

Adds `GET /api/v2/organizations/{organization}/ai/spend/users`, a
paginated per-user report beside the CSV export. It accepts the export's
period parameters and the optional `provider_name`, `model`, and
`client` filters (`client` matches after `COALESCE(client, 'Unknown')`,
as the AI Gateway sessions listing does), and it authorizes identically
through `ResourceGroupMember` in the organization. The response is
`OrganizationAISpendReport`: the applied period bounds,
`retention_start` when retention is enabled (so the page can bound its
date picker), the user count, a `totals` object over every matching
user, and one page of users (`limit` default 10, max 100; `offset` >=
0), each with cost, unpriced usage count, providers, and clients. Each
user row also lists the sorted distinct models they spent through
(e73049f, added on request after the review round).

The period rules (provided together, at most 31 days, within retention,
default narrowed to retention) are shared with the export through the
caller's query parser. As a result the export now rejects unknown query
parameters whether or not a period is given; previously the
excess-parameter check only ran in the explicit-period branch. The
export's parameters and output are otherwise unchanged; the CSV itself
is not filterable.

The JSON rows are per user while the CSV keeps its user x group x
provider x model grain. That is deliberate: the page is the only JSON
consumer, and an explicit `group_by` can be added later without changing
this contract. A page past the last user still carries the window
totals, read from the first page.

Query cost, measured on PostgreSQL 13 with 400k token usages and 200k
interceptions across 4 organizations (31-day window of about 52k usages
for the target organization): `ListOrganizationAISpendUsers` 128 ms
unfiltered and 68 ms filtered by provider. Token usage is read through
the existing partial index on `(effective_group_id, created_at)`; no new
index is needed. The provider and client aggregates were added after
this measurement.

Tests cover pagination validation (including the export rejecting page
parameters), report contents and filters against the CSV, retention
narrowing and rejection, retention disabled, and the role matrix (Owner,
User Admin, Auditor, Org Admin, Org User Admin OK; member 403; other
organization 404).

Previous revisions served this report from the export endpoint through
`Accept` negotiation and also added the dimension filters to the CSV
export (#29220, #29224); the separate endpoint replaces the former, and
the CSV filters were dropped because the page does not use them.

> Xum prepared this PR on behalf of @ibetitsmike.

Codex on e73049f: P2 on the moving `now - retention` lower bound for
clients that echo the default window while paging. Declined: it is the
released CSV export's contract, the report echoes `retention_start`, and
the page never echoes the default window; the handler and tests now use
`OrganizationAISpendPage` (8cdc127).
2026-09-17 04:32:16 +00:00
Michael Suchacz 6c7f6b855b feat: add openai_config.reasoning_model override and bump fantasy (#29230)
## Why

The coder/fantasy fork classifies OpenAI reasoning models by name. The
pinned version did not know `gpt-6-astra`, so the Responses client
omitted the `reasoning` parameter (the reasoning effort picker did
nothing) and forwarded `temperature` (quickgen title calls got HTTP 400
`Unsupported parameter: 'temperature'` and retried). Every new model
generation would need a fork release to fix this. Admins need a switch
in the model config instead.

## What

- Bump `charm.land/fantasy` to coder/fantasy `a511353f83eb`, the
`coder_2_33` commit that squash-merged coder/fantasy#57 (the pin also
carries coder/fantasy#58, Gemini media tool results): gpt-6 and later
generations are recognized as reasoning models, and the provider gains
`WithReasoningModelFunc` to override the classification.
- New tri-state `openai_config.reasoning_model` on
`ChatModelCallConfig`: unset keeps fantasy's name heuristics, `true`
forces reasoning-model handling (effort and summary sent,
temperature/top_p dropped), `false` forces plain sampling. It is applied
once at client construction next to `use_responses_api`. The generated
model editor shows it for `openai` and `bedrock` providers, since
Bedrock Mantle also serves OpenAI-format models; it is ignored for
Anthropic models on Bedrock.
- Remove the `IsGPT6Astra` transport fallback in
`chatopenai.UsesResponsesAPI`; the bumped SDK recognizes gpt-6 itself
(`IsGPT6Astra` stays for the effort clamp).
- Regenerated API docs, swagger, TypeScript types, and the model options
schema; ARCHITECTURE.md documents the flag.

## Validation

- New tests: `TestChatModelCallConfig_ReasoningModelRoundTrip`,
`TestModelFromConfig_OpenAIReasoningModelOverride` (request body has
`reasoning` and no `temperature` when forced on an unknown model; forced
off on gpt-5 drops `reasoning` and keeps `temperature`; unset
unchanged), `TestAIGatewayModelBedrockReasoningModelOverride` (Bedrock
provider path), `TestIsZeroChatModelCallConfigReasoningModel`, and
form-logic cases serializing the field for openai and bedrock.
Red-green: removing the constructor wiring fails the request-body
assertions.
- `go test ./coderd/x/chatd/... -count=1` (full), `go test
./codersdk/... -run ChatModel`, `go test ./coderd/ -run
'ChatModel|Chats'`, `golangci-lint run ./coderd/x/chatd/...
./codersdk/... ./coderd/` (0 issues), `make gen` (stable on rerun),
Vitest for `src/modules/aiModels` and `src/api/chatModelOptions` (174
tests), Biome, `tsc --noEmit`, `make pre-commit`.
- Remote dogfood UAT (Coder Agents) exercised the editor and chat on the
dev AI gateway: the switch shows for OpenAI and Bedrock providers only,
persists true/false/unset, and `gpt-daybreak-blue-latest` (an alias the
SDK does not recognize) sends `reasoning` without `temperature` when
forced on and gets OpenAI's temperature 400 when off or unset. UAT also
found the new switch colliding with `Use Responses API` at 375px;
tri-state switches now take the full row below `sm`. One open
observation for follow-up: in Coder chats on `gpt-6-astra` the upstream
stream carried no reasoning-summary events even though
`reasoning.summary=detailed` was sent, while the same model returns
summaries to a standalone fantasy client; not attributed to this change.
- Merged `origin/main` (`eceae296e8d`; the only conflict was the
ARCHITECTURE.md TODO block, resolved by keeping main's
transport-selection prose and adding a TODO for the GPT-6 Astra sentence
this PR makes stale) and moved the pin (`553bfb86bf5`). On that head:
`go build ./...`, `go vet ./coderd/x/chatd/... ./codersdk/`, `go test
./coderd/x/chatd/ -run
'ReasoningModel|TestAIGateway|Bedrock|ChatModelCallConfig|Quickgen|Transport'`,
`go test ./coderd/x/chatd/chatopenai/...
./coderd/x/chatd/chatprovider/... ./coderd/x/chatd/chatdebug/...`, `go
test ./codersdk/ -run 'ChatModel|Reasoning'`, and the pre-commit hook on
both commits. The `providers/openai` tree at `a511353f83eb` is
byte-identical to the previously pinned PR head `f5b3f253c112`.
- The local `pre-push` hook fails in this checkout only on unrelated
tests (umask-dependent `TestGetModulesArchive`, two untouched site
tests), so the push bypassed it; CI is the gate. For the pin-bump push
the hook ran once in full (31,276 tests passed; the only 2 failures were
`TestGetModulesArchive`, proven to be this checkout's 0600 file modes:
passes after normalizing modes and on an untouched `origin/main`
worktree) and was then opted out for this worktree per Mike's
instruction.

coder/fantasy#57 is merged (`a511353f83eb` on `coder_2_33`) and the pin
points at it. Related: #29229 (Bedrock `reasoning_summary` coercion).

> Xum acted on behalf of @ibetitsmike for this PR.
2026-09-16 20:09:34 +00:00
Bobby Ho feca38ec74 fix: bound OAuth2 request bodies and report the rejection per RFC (#28175)
- Enforce a 4 MiB body limit on `/oauth2/tokens` and `/oauth2/revoke` before parsing, replacing Go’s 10 MiB default. Oversized bodies now return `413 invalid_request` instead of misleading missing-`client_id` errors.
- Preserve `/oauth2/register`’s existing body limit while returning protocol-specific `413 invalid_request` errors rather than `codersdk.Response`.
- Include JSON decoder details in registration’s malformed-body `400` responses and add raw-body tests to verify the error shape.
2026-09-16 11:36:45 -07:00
Bobby Ho 86e43de5f6 fix!: authenticate confidential clients at OAuth2 token revocation (#29208)
- Require confidential-client authentication for OAuth2 token revocation, preventing revocation with only a token and public `client_id`.
- Accept `client_secret` via form fields or HTTP Basic; reject conflicting credentials.
- **Breaking:** Missing or invalid secrets now return 401 `invalid_client` without revoking tokens. `codersdk.RevokeOAuth2Token` requires a `clientSecret` argument (empty for public clients).
- Preserve public-client behavior and existing token ownership checks.
- Add revocation documentation and regression tests for authentication failures, HTTP Basic, and session preservation.

Completes SEC-348. Closes PLAT-507 (CDR-59).
2026-09-15 17:24:43 -07:00
Bobby Ho 070a91c1d9 feat: hide client secrets for public OAuth2 clients (#29312)
Fix the OAuth2 app edit page for public clients by replacing the secrets table and “Generate secret” button with an explanation and skipping secrets requests, including on initial load. Expose client_type in OAuth2 app API responses and regenerate TypeScript types and API docs. Confidential client behavior remains unchanged. Fixes PLAT-504.
2026-09-15 16:40:36 +00:00
Bobby Ho f5be7ae660 feat: remove the oauth2 experiment in favor of CODER_OAUTH2_PROVIDER_ENABLE (#29257)
Third of five for PLAT-492. Removes the oauth2 experiment entirely; CODER_EXPERIMENTS=oauth2 is now treated as an unknown experiment and nothing depends on it.

Stacked on #29251. No migration.
Removes ExperimentOAuth2 and its generated/API references.
Removed outright per review, consistent with experiments having no compatibility guarantee.
Migration guidance is covered by the startup logging in #29267 and docs/release notes in #29268, both pointing to CODER_OAUTH2_PROVIDER_ENABLE.
Existing unknown-experiment handling and tests already cover leftover oauth2 values.
After this merges, main is safe to cut a release from.
2026-09-14 14:10:05 -07:00
Michael Suchacz f46ff158c5 feat!: remove the Coder Tasks RBAC resource, scopes and permissions (#28750)
Removes the `task` RBAC resource, its five `task:*` API key scopes, and
every persisted reference to them. Custom role permission arrays drop
their `task` entries; API keys and OAuth2 codes and tokens lose task
scopes, and task-only ones are revoked; OAuth2 apps whose scope list
named only task scopes get a whitespace-only scope so they stay
restricted instead of reading as unconfigured; then `api_key_scope` is
recreated without the task values. Generated RBAC, SDK, site and API doc
artifacts are regenerated. The `resource_type` enum keeps `task` so
historical audit log rows remain queryable.

**Breaking change:** migration 000595 revokes task-only keys and grants.
The down migration restores the enum values only.

**Review changes:** the api_keys scope cleanup deletes any key left
without a non-task scope (redundant EXISTS dropped), the allow-list
comment states the real reason (`allow_list` cannot be empty), and the
migration test keeps each fixture next to its expected post-migration
value. Renumbered from 000594 to 000595.

**Stack context:** Coder Tasks removal stack (CODAGT-642): #28743
frontend → #28788 CLI → #28789 API → #28790 provisioner → #29084
notifications → #29085 build reasons → #29086 tables → **#28750
permissions**. The last four PRs replace the single data-drop migration
that used to live in #28750; each carries one concern and its own
migration number.

> Created by Xum (AI agent) on behalf of @ibetitsmike.


## Delivery record

**Status (2026-09-11 16:30Z): not merged; awaiting re-review.** Head
`80ee30141ee81287a03de3f46407f6a421387778` on `main`.

**Review history relevant to this diff:** 10 completed Codex code
reviews on the monolithic diff (2026-08-28 to 2026-09-01) plus
spikecurtis CHANGES_REQUESTED (2026-09-04, asked for the split),
spikecurtis COMMENTED 2026-09-08 (three findings on the migration and
test, all applied and resolved) and spikecurtis COMMENTED 2026-09-11
([r3990045458](https://github.com/coder/coder/pull/28750#discussion_r3990045458),
[r3990067224](https://github.com/coder/coder/pull/28750#discussion_r3990067224),
both applied in `80ee30141ee` and resolved). The review budget is
exhausted, so no further discretionary review or final advisory was
commissioned; a fresh independent final advisory for the final diff does
not exist and remains a documented gap. The reviewer's own re-review is
the remaining gate.

**Findings and dispositions on the current head:**
- OAuth-linked API key fixtures were confusing (deletion came from the
token trigger, not the migration): removed from `keys`; the grants loop
creates its backing api_keys row inline and asserts only code/token
rows.
- Missing cases: added `multi-task-scopes-key`, `multi-task-allows-key`,
and `task-only-key` (only task scopes and only task allows, deleted).
- Earlier round: redundant EXISTS on the api_keys scope DELETE dropped;
allow-list comment corrected (`allow_list` cannot be empty); test
restructured as before/after tables; renumbered to 000595.

**Test evidence for `80ee30141ee`:**
`TestMigration000595RemoveTaskPermissions` passes (up, down, re-up);
red-green: removing the token DELETE and UPDATE from the migration fails
the test at the grants/tokens assertion, file restored byte-identically.
Full repository pre-push hook passed before the push (`test` 97s,
`test-js` 45s, site build; `pre-push passed (143s)`). Note: this
workspace runs a service on loopback:3000, jsdom's default origin, which
made `test-js` fail on unmocked inbox requests for any commit; the hook
run used an `LD_PRELOAD` shim that only makes `connect()` to
loopback:3000 return `ECONNREFUSED`, matching CI, with no change to
sources, tests, config, or the host. Exact-head CI: run
[34622204759](https://github.com/coder/coder/actions/runs/34622204759)
in progress at the time of writing.

**Deferred:** `AI Documentation Check` failures on this stack come from
the dormant `doc-check-pr-*` workspace (CODAGT-1025), not code.
2026-09-14 20:15:13 +02:00
Bobby Ho 1cc73bc43f feat: add the CODER_OAUTH2_PROVIDER_ENABLE deployment flag (#29248)
First of five PRs for PLAT-492, adding the opt-in CODER_OAUTH2_PROVIDER_ENABLE flag for the OAuth 2.1 provider. It defaults to false and is not enforced yet, so there is no behavior change.

Adds the CLI/env/YAML flag and exposes oauth2_provider in build info.
Enables it by default in tests to prepare for route gating.
Updates tests, golden files, and frontend fixtures.
Follow-ups will gate routes/UI, retire the experiment, add startup logging, and update docs.
2026-09-14 08:31:26 -07:00
Cian Johnston 2cf819bfca feat: add break-glass user email update (#29256)
Adds an owner-only experimental API and hidden CLI command for
break-glass user email corrections.

The operation verifies the existing email, updates it transactionally,
clears outstanding password-reset state, revokes the target user's Coder
sessions and API tokens, and records successful and failed authenticated
attempts in the audit log. External-auth links remain unchanged.

Generated by Coder Agents.
2026-09-14 14:33:36 +01:00
Steven Masley 940f988cfb feat: add deployment-level option to disable Terraform module caching (#29187)
<!-- Generated by Coder Agents on behalf of @Emyrk. -->

<img width="762" height="239" alt="Screenshot From 2026-09-11 17-09-41"
src="https://github.com/user-attachments/assets/9f31fd1e-4cb2-47ab-8d37-4073df9f0a7c"
/>


Closes #22834.

Adds `CODER_PROVISIONER_DISABLE_MODULE_CACHE` so an admin can disable
Terraform module caching for every template at once instead of toggling
~100 templates by hand.

- The deployment setting wins. Templates cannot opt back in, and the
per-template toggle becomes read-only while the deployment setting is
on.
- Modules stay cached at template import, so dynamic parameter rendering
still resolves module-defined parameters. Only the workspace build is
denied the cached files.
- Templates report `module_cache_disabled_by_deployment`, and template
settings shows why the checkbox is locked.

<details><summary>Agent context</summary>

Decisions taken with @Emyrk before implementing:

1. **Precedence.** `deployment || template`, no per-template override,
so no migration and no nullable column. The rule lives in one place,
`codersdk.ModuleCacheDisabled`.
2. **Import-time caching untouched.** `dynamicparameters/render.go`
overlays `cached_module_files` at `.terraform/modules` to render
module-defined parameters. Skipping the cache there would reproduce the
`Module not loaded. Did you run terraform init?` failure reported by a
customer, so the deployment setting only affects what `AcquireJob` hands
the provisioner.
3. **Write path.** A PATCH carrying `disable_module_cache` is discarded
while the deployment setting is on, rather than persisted. Persisting it
would silently keep templates opted out after the deployment setting is
removed.
4. **API shape.** `disable_module_cache` keeps its meaning (this
template's stored value) and the new read-only
`module_cache_disabled_by_deployment` reports the deployment state.
Reading the effective value from `/deployment/config` was rejected
because template admins may lack deployment-config read permission.
5. **Naming.** `CODER_PROVISIONER_DISABLE_MODULE_CACHE` over the issue's
`CODER_DISABLE_TERRAFORM_MODULE_CACHE`, to match the provisioning option
group.

Note: `InsertTemplateParams` has no `disable_module_cache` binding, so
new templates always store `false`. With deployment precedence they
still behave as opted out, so the create path needed no change.

Out of scope and tracked elsewhere: the `coderd_template` Terraform
provider attribute (separate repo) and backporting the per-template
toggle to `release/2.30`.

</details>

---

<sub>Coder Agents on behalf of @Emyrk.</sub>
2026-09-11 18:13:16 -05:00
Michael Suchacz 9cd38b5373 feat!: remove the Tasks API from coderd and codersdk (#28789)
Removes the Tasks API and task orchestration from coderd and codersdk:
the `/api/v2/tasks` handlers, task middleware and search filters, task
name generation, autobuild pause/resume logic, task notification
enqueues, telemetry, and the codersdk task types. Regenerates apidoc,
the API reference docs, and `typesGenerated.ts`.

**Breaking change:** the Tasks API is removed; requests to
`/api/v2/tasks` fail. Tasks was deprecated in v2.34.

**Stack context:** Coder Tasks removal stack (CODAGT-642): #28743
frontend → #28788 CLI → #28789 API → #28790 provisioner → #29084
notifications → #29085 build reasons → #29086 tables → #28750
permissions. The last four PRs replace the single data-drop migration
that used to live in #28750; each carries one concern and its own
migration number.

**Why:** with the UI (#28743) and CLI (#28788) gone, this deletes the
server surface. Database tables, RBAC, and notification templates stay
until the top of the stack so every layer builds and migrates
independently.

**What to scrutinize:**
- The `enable-ai-tasks` option is removed outright (review feedback):
configs still carrying `enableAITasks` fail to parse until the key is
deleted.
- provisionerdserver now writes `HasAITask: false` on template/build
flags; the column and these lines are dropped in #29085.
- `codersdk.ResourceTypeTask` stays so audit logs recorded before the
removal keep rendering.

**Validation:** `go build ./...`, `go vet ./...`, `go test
./codersdk/...`, site biome and tsc, CLI goldens regenerated, pre-commit
hooks.

**Size:** +242/-10,792 over 76 files; additions are regenerated
docs/goldens and test fixture updates.

> Created by Xum (AI agent) on behalf of @ibetitsmike.
2026-09-11 01:48:56 +00:00
david-fraley fef0763820 feat: report template builder build failure reasons in telemetry (#28586) 2026-09-10 08:21:29 -04:00
Garrett Delfosse 65d01ef9b7 fix: error on CLI HTTP redirects instead of following them (#29104) 2026-09-09 07:34:51 -04:00
Paweł Banaszewski 8472a6884f chore!: remove env-based AI provider configuration (#29053)
> AI tools were used to create this PR

Removes deprecated AI provider configuration through environment
variables, CLI flags, and YAML.
Deletion includes indexed providers and legacy OpenAI, Anthropic, and
Bedrock options under both AI Gateway and AI Bridge branding, eg.
`CODER_AI_GATEWAY_PROVIDER_<N>_*` or `CODER_AI_GATEWAY_ANTHROPIC_KEY`.
Removes the associated startup-seeding code.
Updates tests and documentation.

**Breaking change:** Remove [obsolete AI provider CLI flags and YAML
keys](https://coder.com/docs/ai-coder/ai-gateway/providers#database-management-of-providers)
before upgrading, otherwise Coder will fail to start with an `unknown
flag` or `unknown option` error. Provider environment variables are
ignored and no longer seed the database. Existing database-stored
provider configuration is preserved.
2026-09-09 10:16:24 +02:00