Skip to content

feat(coderd/database): add project-tier agent definition queries - #72

Merged
ibetitsmike merged 12 commits into
mainfrom
mike/custom-agent-types-9-project-queries
Nov 10, 2026
Merged

ibetitsmike merged 12 commits into
mainfrom
mike/custom-agent-types-9-project-queries

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

Part of #7

Based on main now that #71 has merged. First of three project-tier PRs: this one adds the schema guard and the queries. The next adds the fork routes under /api/v2/chats/fork/organizations/{organization}/projects/{project}/agent-definitions, and the last resolves project-tier rows into the spawn catalog behind the usable-project check. #69 has landed. Splitting keeps each under 500 lines.

Schema guard

A project-tier row stores both organization_id and project_id, unlike a project skill, whose organization_id is NULL. The new chatd node 01a1c246-…_agent_definition_project_organization adds a BEFORE INSERT OR UPDATE OF organization_id, project_id trigger on agent_definitions that raises agent_definitions_project_organization (check violation) when the project is not in the row's organization. Without it, a row could be read through an organization that does not own its project. chat_projects.organization_id never changes, so no trigger on chat_projects is needed.

Queries

InsertProjectAgentDefinition, GetProjectAgentDefinitionByName, ListProjectAgentDefinitionMetadata, UpdateProjectAgentDefinitionByName and DeleteProjectAgentDefinitionByName, keyed by project_id and name.

dbauthz authorizes them like upstream's project skill queries, through authorizeChatProjectConfig on the project: read for get and list, update for insert, update and delete. The row's own RBAC object stays unauthorizable, as before.

Tests

  • TestAgentDefinitions/ProjectTier: inserting into another organization and moving a row to another organization both fail with agent_definitions_project_organization. Names are unique per project. Update, get and list stay in the project, and an organization-tier row in the same organization is not listed. Delete removes the row.
  • TestForkQuerier: the five queries assert the project object with the right action.
  • Negative controls: removing the trigger from the node fails ProjectTier. Authorizing insert for read instead of update fails TestForkQuerier.
  • Ran in Colima: TestAgentDefinitions, TestSQLCSchemaOrder, TestForkQuerier, the chatdmig package with CHATDMIG_TEST_DATABASE_URL set (including TestForkNodesOnlyAddToChatd), chatdmig check, and golangci-lint (no findings in the changed files).

Size

221 non-generated lines added: 25 migration node, 32 queries, 60 dbauthz and dbmetrics, 103 tests and 1 sqlc config. The rest is sqlc and mock output.

…initions

Add CRUD routes for a member's stored agent definitions under
/api/v2/chats/fork/organizations/{organization}/members/{user}/agent-definitions,
the SDK types and client methods, and the generated API docs. Content is
parsed with workspacesdk.ParseAgentDefinition and the front-matter names the
definition. Writes are not audited.

Part of #7.
Add CRUD routes for organization-tier stored agent definitions under
/api/v2/chats/fork/organizations/{organization}/agent-definitions and the
SDK methods. A new definition grants read to the Everyone group, like a new
organization skill, and the list is filtered by each row's ACL.

Part of #7.
…erence

The routes are gated by an experiment, so mark them with @x-apidocgen skip like the fork chat todo routes.
… mike/custom-agent-types-6b-org-agent-definition-routes
Merged with PR6's head 4a2314c as the base, because #65's squash commit has the same content as PR6.
@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 9, 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-10T00:23:05.577675Z 99119de 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 48fe8d9beb

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

Base automatically changed from mike/custom-agent-types-8-org-acl-membership to main November 10, 2026 00:00
…es-9-project-queries

# Conflicts:
#	coderd/database/forkdb/agent_definitions.sql.go
#	coderd/database/forkdb/sqlc.yaml
#	coderd/database/migrations/chatdmig/nodes/01a1c242-decb-7db2-b52e-38c2843c434c_agent_definition_acl_org_member_delete.up.sql
#	coderd/fork_agent_definitions_test.go
#	coderd/fork_organization_agent_definitions_acl.go
@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. Delightful!

Reviewed commit: 99119de2e0

ℹ️ 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
ibetitsmike merged commit 8ddd673 into main Nov 10, 2026
10 checks passed
@ibetitsmike
ibetitsmike deleted the mike/custom-agent-types-9-project-queries branch November 10, 2026 00:31
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head 99119de2e02e6c816f4417aa15df9aa2826dea2c:

  • The head contains current main ec6cdd6f80 (deployed and healthy at 00:18Z). fork-ci pull_request run 42727493169 passed on this exact head. All checks green.
  • Codex review on this exact head: no major issues. 0 unresolved review threads. Merge state CLEAN.
  • UAT on this head (fresh DB): the server applies the new migration node at startup. Project rows whose organization does not match the project's organization are rejected on insert and update, names are unique per project, and personal and organization routes ignore project rows. Deleting a project cascades its rows. In an upgrade simulation, only this node applies, and the trigger comes back.

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