Skip to content

feat(coderd/database): store agent definitions for users and organizations - #62

Merged
ibetitsmike merged 4 commits into
mainfrom
mike/custom-agent-types-5-stored-definitions
Nov 9, 2026
Merged

ibetitsmike merged 4 commits into
mainfrom
mike/custom-agent-types-5-stored-definitions

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

Part of #7

Adds storage for stored agent definitions (scope item 4, first of three PRs): a chatd.agent_definitions chatdmig node and authorized forkdb queries for the user and organization tiers. It has no routes, catalog resolution or UI. PR6 adds the user and organization routes behind fork-agent-definitions and resolves rows into the spawn catalog. PR7 adds organization ACL routes and the project tier.

Schema

  • The table mirrors public.skills: tier columns, a name format equal to workspacesdk.SkillNamePattern, size limits, ACL columns that are allowed only on organization-tier rows, per-owner unique names, and a 100-row per-owner limit trigger (enforce_agent_definitions_per_owner_limit).
  • Every row has organization_id NOT NULL. A row is in the organization tier when user_id and project_id are both NULL, the user tier when user_id is set, and the project tier when project_id is set.
  • Deviation from upstream: personal skills are deployment-wide, but a user-tier agent definition belongs to one user within one organization (AGENTS.md "New resources"). The user limit counts per (organization, user).

Authorization

  • Agent definitions reuse the skill RBAC objects. No new resources or API key scopes.
  • User tier: the object is ResourceUserSkill.WithOwner(user) without InOrg. policy.rego skips user-level permissions on objects that have an organization owner, and no org role grants ResourceUserSkill, so with InOrg set, members could not reach their own rows. dbauthz enforces the organization scope instead: every user-tier method, the list included, also authorizes ActionRead on ResourceOrganization.WithID(org).InOrg(org).
  • As with personal skills, a site owner keeps upstream's read and delete on personal rows.
  • Organization tier: ResourceOrganizationSkill.InOrg(org) with the row's group and user ACLs, following the upstream skill wrappers. The list uses fetchWithPostFilter, which is enough for at most 100 rows per organization. The insert takes group_acl and user_acl, like InsertOrganizationSkill, so the PR6 create route can seed the Everyone read grant.
  • No coderd/rbac files change.

Tests

  • TestForkQuerier: one case per method. Each asserts the exact objects and actions.
  • TestUserAgentDefinitionOrganizationMembership: uses the real authorizer. For create, read, list, update and delete, a member is allowed, a non-member is denied, and a member removed from the organization loses access to their row.
  • TestAgentDefinitions: a DB test of per-owner uniqueness, the check constraints, the per-owner limits, cascade on user delete, update, and organization filtering.
  • The test audit proved each new test fails when its behavior is broken. Polish and test-audit edits stayed inside the implementation diff.

Size

About 680 non-generated lines: 307 production (node, queries, dbauthz, dbmetrics, model methods, sqlc.yaml) and 370 tests. The rest is generated by sqlc and mockgen.

…d ACL objects

Adds a per-owner limit subtest, asserts that user-tier queries stay in their organization and organization-tier update and delete skip user-tier rows, and makes the organization-tier TestForkQuierer cases assert an explicit RBAC object with non-empty ACLs instead of the row's own RBACObject.
@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-09T19:11:56.024198Z ef9cd18 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 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: dbb2af51be

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

…tion ACLs on insert

Owner deletes cascade by user_id and organization_id, so the user unique index now leads with user_id and a plain organization_id index serves organization deletes. InsertOrganizationAgentDefinition takes group_acl and user_acl like InsertOrganizationSkill, so the route can seed the Everyone read grant.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

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

ℹ️ 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 closed this Nov 9, 2026
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

The head is unchanged (ef9cd18d82). This reopen only triggers a pull_request fork-ci run against current main (68fbdea615), because the last run (42680209462) started before main moved.

@ibetitsmike ibetitsmike reopened this Nov 9, 2026
@ibetitsmike
ibetitsmike merged commit f8c5493 into main Nov 9, 2026
19 checks passed
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

What I checked before merging head ef9cd18d82f27b65c34d95ae2f43952d02b02ba5:

  • fork-ci run 42685965405 passed. It ran as a pull_request run against current main (68fbdea615), after a close and reopen, because the earlier run predated the move of main.
  • I reviewed both Codex rounds. The findings were fixed or declined, and I confirmed each decline. There are 0 unresolved threads, and nothing new came in after the reopen.
  • None of this PR's files are touched by the commits that landed on main after its base (b457b3f1bf..68fbdea615), and git merge-tree is clean.
  • This PR adds chatd migration node 01a1c18d (agent_definitions). After the deploy, the daily server should report 8 nodes.

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