Skip to content

feat: share organization agent definitions behind fork-agent-definitions - #71

Merged
ibetitsmike merged 12 commits into
mainfrom
mike/custom-agent-types-8-org-acl-membership
Nov 10, 2026
Merged

ibetitsmike merged 12 commits into
mainfrom
mike/custom-agent-types-8-org-acl-membership

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

Part of #7

Stacked on #66 (organization-tier routes). Adds the ACL routes for organization agent definitions behind fork-agent-definitions, and a regression test for read-time organization membership. PR9 adds the project tier.

Routes

GET and PATCH on /api/v2/chats/fork/organizations/{organization}/agent-definitions/{agentDefinition}/acl, in the same registerForkChatRoutes mount as #66.

  • They reuse the organization skill ACL types (codersdk.OrganizationSkillACL, UpdateOrganizationSkillACLRequest) and helpers (validateOrganizationACLUpdate, applyACLReadRoles, resolveACLUsers, resolveACLGroups), so the request shape and validation match /organizations/{organization}/skills/{skillName}/acl.
  • Like ExtractOrganizationSkillParam(..., policy.ActionShare), both routes admit only callers who can share the definition. Readers and everyone else get 404, so readers cannot list the grants. A share-only API key scope works.
  • PATCH locks the row (GetOrganizationAgentDefinitionByNameForUpdate), validates the grants against the organization in the same transaction, and writes through UpdateOrganizationAgentDefinitionACLByName, which dbauthz authorizes for ActionShare.
  • Writes are not audited, as in feat: serve user-tier agent definitions behind fork-agent-definitions #65 and feat: serve organization agent definitions behind fork-agent-definitions #66.

Read-time membership

acl_allow in policy.rego already requires is_org_member, so RBAC drops a direct grant as soon as its user leaves the organization. No extra dbauthz check is needed. TestOrganizationAgentDefinitionOrganizationMembership runs the get and list queries against the real authorizer and locks this in: before removal the grantee reads the row, after removal get is not authorized and the list is empty.

Leaving the organization also drops the user's direct grants, so rejoining does not restore them, the same as skills (000621) and chat projects (000629). A new chatd node, 01a1c242-…_agent_definition_acl_org_member_delete, mirrors 000629: a BEFORE DELETE ON organization_members trigger that removes the user from the user_acl of the definitions in that organization, and a one-time cleanup for users who already left. Nodes have no down migrations.

The trigger sits on a core table but runs a chatd function, like upstream's skill trigger after the adopt node. TestForkNodesOnlyAddToChatd now admits that one shape (CREATE TRIGGER ... EXECUTE FUNCTION chatd.), and the chatdmig README says so.

Tests

  • TestForkOrganizationAgentDefinitions/ACL: an org admin replaces the Everyone grant with a direct read grant. The ACL lists only the grantee. The grantee reads the definition, another member gets 404 and an empty list. The grantee gets 404 on GET and PATCH of the ACL. An invalid user ID gives 400. After the grantee leaves the organization, reading gives 404 and the stored user_acl no longer has the grantee. After the grantee rejoins, reading still gives 404.
  • TestForkOrganizationAgentDefinitions/ScopedAPIKeys: a key scoped to organization_skill:share reads the ACL.
  • TestForkQuerier: the new queries, with ActionShare for the ACL update.
  • Negative controls: removing the trigger from the node fails the ACL subtest. Reverting the chatdObject change fails TestForkNodesOnlyAddToChatd on the new trigger. Authorizing the ACL routes for read instead of share, dropping the user grant from the PATCH, and authorizing the dbauthz ACL update for update instead of share each make a test fail.
  • Ran in Colima: the chatdmig package with CHATDMIG_TEST_DATABASE_URL set (including TestForkNodesOnlyAddToChatd), chatdmig check, TestSQLCSchemaOrder, TestForkOrganizationAgentDefinitions, TestForkUserAgentDefinitions, TestForkQuerier, TestOrganizationAgentDefinitionOrganizationMembership, TestForkChatRoutes, TestEndpointsDocumented, TestEnterpriseEndpointsDocumented, TestSwaggerParametersValid, TestSDKFieldsFormatted, and golangci-lint (no findings in the changed files).

Size

395 non-generated lines added: 146 handlers, 76 dbauthz tests, 72 API tests, 36 migration node, 39 queries and wrappers, 12 SDK, 11 chatdmig test and README, 1 sqlc config and 2 routes. The rest is sqlc, mock and Swagger output. The routes are skipped from the published API reference with @x-apidocgen {"skip": true}.

…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-09T23:26:08.927014Z 48e21c7 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. More of your lovely PRs please.

Reviewed commit: 13acc8151d

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

@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: 6c95de77bc

ℹ️ 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-6b-org-agent-definition-routes to main November 9, 2026 22:57
@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: 2eef33ad7b

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

…write

Lock the granted users' organization memberships before the definition row,
like the organization skill ACL route, so a concurrent member removal cannot
miss the new grant. Limit the member-removal cleanup to organization-tier
rows, the only ones with ACLs.
@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. Hooray!

Reviewed commit: 48e21c75fb

ℹ️ 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 (e6cd44a997) and run fork-ci on it. The head is unchanged.

@ibetitsmike ibetitsmike closed this Nov 9, 2026
@ibetitsmike ibetitsmike reopened this Nov 9, 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 (e6cd44a997), 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 closed this Nov 9, 2026
@ibetitsmike ibetitsmike reopened this Nov 9, 2026
@ibetitsmike
ibetitsmike merged commit d73dac3 into main Nov 10, 2026
20 of 27 checks passed
@ibetitsmike
ibetitsmike deleted the mike/custom-agent-types-8-org-acl-membership branch November 10, 2026 00:00
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head 48e21c75fb27f8e0ee32838d4f904c4f572eeab6:

  • fork-ci pull_request run 42723449345 passed; its build job checked out Merge 48e21c75fb into e6cd44a997 (current main, deployed and healthy at 23:55Z). All checks green.
  • Codex review on this exact head: no major issues. 0 unresolved review threads. Merge state CLEAN.
  • UAT on a server-only build of this head merged with e6cd44a (fresh DB, mock OpenAI provider): a fresh DB has 9 migration nodes and the new organization member delete trigger; an upgrade from main state applies the node and drops a stale grant. An organization admin shares an organization definition with one member, who can then spawn it while other members cannot. Members cannot grant themselves or others access (404). Removing a member clears their grants, and re-adding them does not restore the grant.

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