Skip to content

feat: let custom agent definitions name a model by alias - #100

Merged
ibetitsmike merged 6 commits into
mainfrom
mike/custom-agent-types-r12-2-model-aliases
Nov 10, 2026
Merged

ibetitsmike merged 6 commits into
mainfrom
mike/custom-agent-types-r12-2-model-aliases

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

Part of #7

With fork-agent-definitions on, a custom agent definition's model can now name an alias, such as fast, that an admin lists on a model config (brief item R12.2). Before this change, model had to match a model config ID, model or display name, so a definition written for one deployment broke on another that named its models differently.

Change

  • codersdk.ChatModelCallConfig gets aliases, stored in the existing options JSONB, so there is no migration. The admin model form shows it as a generated field.
  • validateChatModelAliases (coderd/fork_chat_model_aliases.go) runs on model config create and update, inside the existing transaction. Each alias must be 1 to 32 lowercase letters, digits or hyphens, must not be inherit, must be listed once, and must not belong to another model config of the same AI provider in the organization. Failures return 400 Invalid model aliases. with the reason.
  • resolveCustomAgentModel tries the model config ID, model and display name first, as before, then falls back to resolveCustomAgentModelAlias (coderd/x/chatd/fork_model_aliases.go). The alias match ignores case. One match wins. When models on several providers share the alias, the one on the parent chat's AI provider wins; otherwise the spawn fails and lists the matches.
  • With the experiment on, list_subagent_models shows each model's aliases, so the parent agent can see them. With it off, the tool output stays as upstream.
  • docs/fork/pstack-adapter.md maps model slugs to aliases and updates the line citations that moved.

With the experiment off, spawns and list_subagent_models behave as upstream. An admin can still store aliases, which only take effect with the experiment on.

Tests

  • TestForkChatModelAliases (coderd): create with aliases, a duplicate on the same provider, reuse on another provider, inherit, uppercase, a repeated alias, a config keeping its own alias on update, and an update that moves a config onto a provider where its alias is taken.
  • TestIsZeroChatModelCallConfigCoversEveryField now samples Aliases, so an aliases-only config is stored.
  • TestForkAgentDefinitionModelAlias (chatd): the parent's provider wins, a single match on another provider, an exact model name beating an alias, an alias on two other providers failing with both listed, and list_subagent_models showing aliases.
  • TestForkModelAliasesHiddenWithoutExperiment (chatd): with the experiment off, list_subagent_models lists the aliased model without aliases.
  • Negative controls, all restored clean: dropping aliases from the zero check, allowing uppercase, not reserving inherit, allowing a repeated alias, skipping the uniqueness check, ignoring the provider in it, not skipping the config being saved, skipping validation on update and on create, removing the alias fallback, removing the parent-provider tie-break, matching case-sensitively, sending a single match to the tie-break, not listing aliases, checking aliases before exact model names, and listing aliases with the experiment off. Each one turns its test red.
  • Ran in Colima: go test ./coderd/x/chatd/... ok, and go test ./coderd -run 'ChatModel|ForkChatModelAliases' ok. golangci-lint reports nothing in the touched files. Vitest unit tests for src/api and src/modules/aiModels pass.

UAT

Ran in Colima on a slim binary of 9c519f4abd with a mock provider and two AI providers. An admin's invalid aliases (duplicate on the same provider, inherit, uppercase, over 32 characters, repeated, and a provider change onto a taken alias) return 400 and store nothing. A member's personal agent definitions with model: fast, FAST, deep and an exact model name spawn on the expected models, the parent's provider wins for fast, and an unknown alias fails with no child. With the experiment off, the definitions don't exist and list_subagent_models shows no aliases.

Size

About 405 changed lines: about 170 implementation, about 170 tests, 18 doc lines, and about 47 generated lines (API docs, Swagger, TypeScript types and the model options schema).

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T09:45:48.857507Z 0037be2 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 9c519f4abd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum posted this on behalf of @ibetitsmike.

UAT: PASS on 9c519f4. It ran in Colima on a slim binary with a mock provider and two AI providers. P1 has mock-a (no aliases) and mock-b (fast). P2 has mock-c (fast, deep).

  • Admin validation returns 400 Invalid model aliases. for each of these and stores nothing: fast on another P1 model, inherit, Fast, a 33-character alias, [slow, slow], and moving mock-c onto P1. A PATCH that keeps mock-b's own fast returns 200. A member's PATCH returns 404.
  • With fork-agent-definitions on, the parent runs on mock-a. A member's personal definitions spawn as follows:
    • model: fast and model: FAST run on mock-b, because the parent's provider wins.
    • model: deep runs on mock-c, the single match.
    • model: mock-c runs on mock-c, an exact match.
    • model: nope fails with "not an available model" and creates no child.
  • With the parent on mock-c, fast runs on mock-c. list_subagent_models shows aliases on mock-b and mock-c.
  • With the experiment off, spawns return the upstream "type must be one of: general, explore", and list_subagent_models shows no aliases. The first UAT build, 7ccbe31, still listed them, and 9c519f4 fixes that.
  • The admin validation cases ran on 7ccbe31. 9c519f4 changes only the listing gate and its test.

…es-r12-2-model-aliases

# Conflicts:
#	docs/fork/pstack-adapter.md
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum posted this on behalf of @ibetitsmike.

Merged origin/main at 2d635ea9a6 (#95) into this branch as 72ae96c124. The only conflict was in docs/fork/pstack-adapter.md. Git merged the code and generated files without conflicts, and the merge changes no behavior on either side.

How the doc resolution works: it keeps main's citation lines, including #95's computer_use line, and this PR's two alias lines. Where each side's code moved the other's cited lines, I renumbered the citations and checked each against the merged files:

  • fork_agent_definitions.go: model match :389-412 and subagentContextResource :414-431, because this PR shortens resolveCustomAgentModel by 3 lines.
  • subagent.go: the computer_use check :626-628, because this PR adds 3 lines in list_subagent_models.
  • codersdk/chats.go: Aliases at :1945, because main added lines above it.

Validation on 72ae96c124:

  • go build of ./coderd/, ./codersdk/ and ./coderd/x/chatd/ passes.
  • go test ./coderd/x/chatd/ -count=1 passes (54s), including TestForkAgentDefinitionModelAlias, TestForkModelAliasesHiddenWithoutExperiment, TestListSubagentModels and TestForkComputerUseSpawnOverrides*.
  • go test ./coderd/ -run TestForkChatModelAliases passes.
  • Regenerating coderd/apidoc and typesGenerated.ts gave only the known local enum-order noise, so the auto-merged generated files are correct.
  • golangci-lint reports no findings in any file this PR changes.

Because the merge changes no behavior, the earlier UAT verdict still holds.

@codex review

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 72ae96c124

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…es-r12-2-model-aliases

# Conflicts:
#	docs/fork/pstack-adapter.md
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum posted this on behalf of @ibetitsmike.

Merged origin/main at a9438bd7af (#118, #128) into this branch as 0037be28a6. The only conflict was in docs/fork/pstack-adapter.md. It keeps #128's three new citation lines, and the list_agents line keeps this PR's subagent.go:573-592 and :482-490, because this PR adds 3 lines above them in subagent.go. Since 72ae96c124, main changed only site/ files this PR doesn't touch, plus this doc, so the Go code is byte-identical to the 72ae96c124 validation in the comment above. No behavior change.

The one Codex finding on 72ae96c124 (an architecture TODO) was declined and resolved: #100 (comment)

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 0037be28a6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) closed and reopened this on behalf of @ibetitsmike.

Closing and reopening only to make GitHub recompute the merge ref against current main (32bbba5265) and run fork-ci on it. The head is unchanged.

@ibetitsmike ibetitsmike reopened this Nov 10, 2026
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) closed and reopened this again on behalf of @ibetitsmike.

The merge ref now points at current main (32bbba5265), but the run started by the first reopen was queued against the old merge ref. This second reopen starts fork-ci on the recomputed merge. The head is unchanged.

@ibetitsmike ibetitsmike reopened this Nov 10, 2026
@ibetitsmike
ibetitsmike merged commit 17ef343 into main Nov 10, 2026
20 of 27 checks passed
@ibetitsmike
ibetitsmike deleted the mike/custom-agent-types-r12-2-model-aliases branch November 10, 2026 11:32
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head 0037be28a683d74a944d666afb18bbd9e31a14ae:

  • fork-ci pull_request run 42805403813 passed; its build job checked out Merge 0037be28a6 into 32bbba5265 (current main). All checks green. Run 42792970819 had also passed on this head.
  • Codex on this exact head: no major issues (comment 6764148394). 0 unresolved review threads.
  • UAT PASS on a slim binary of 9c519f4abd in Colima (PR body, UAT): invalid admin aliases return 400 and store nothing; member definitions with model: fast, FAST, deep and an exact model name spawn on the expected models, the parent's provider wins for fast, and an unknown alias fails with no child; with the experiment off the definitions don't exist and list_subagent_models shows no aliases. Accepted as covering this head: the only later commits are two merges of main, and the PR's own diff against main is identical to the UAT'd diff in every file except docs/fork/pstack-adapter.md citations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant