Skip to content

feat: members share personal saved workflows with the organization (fork-workflows) - #404

Merged
ibetitsmike merged 9 commits into
mainfrom
mike/issue-395-share-personal-workflows
Nov 21, 2026
Merged

ibetitsmike merged 9 commits into
mainfrom
mike/issue-395-share-personal-workflows

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Coder Agents opened this PR on behalf of @ibetitsmike.

Closes #395
Closes #327

What

Members can share a personal saved workflow with their organization.

  • Backend: POST /api/v2/chats/fork/organizations/{organization}/members/{user}/workflows/{workflow}/share, with an optional expect_id query parameter. It answers 201 with the new organization workflow. Behind fork-workflows.
  • Site: the member Workflows page (Agent settings) gets a "Share with organization..." row action on personal workflows, with a confirm dialog (ForkSavedWorkflowShareDialog) that shows the server error and stays open on failure. A 404 drops the row from the personal list, then closes the dialog with an info toast, because the workflow was shared or deleted elsewhere or the member left the organization. Dropping the row first sends focus to the table's fallback button. The request sends expect_id through savedWorkflowWriteSearchParams from feat(site): send expect_id with saved workflow saves and deletes #400, which rejects an empty id. In the organization table, the member can now edit and delete the rows they shared (created_by is them). Other organization rows stay read-only.

Design: move, not copy

Share moves the row from the personal tier to the organization tier in one SQL statement (ShareUserSavedWorkflowByName, a CTE that deletes the personal row and inserts the organization row with the same name, description, script, args schema and phases). The new row has:

  • created_by = the owner,
  • user_acl = owner: read, update, delete,
  • group_acl = Everyone group: read.

Why:

  • It reuses the organization tier ACL model, so the existing organization routes and dbauthz enforce the rules with no new authorization code: the owner edits and deletes, every other member reads and runs, and admins keep full control and can change grants with the existing sharing dialog.
  • A copy would leave a personal row of the same name, which run_workflow resolves first, so the member's chats would keep running the personal copy while others run the shared one. The move avoids that shadowing.
  • One statement is atomic. A taken organization name (unique index) or a full organization (100 per org trigger) answers 409 and the personal row stays. An earlier attempt with a privileged insert failed because the restricted system subject cannot create organization skills, and the single statement needs no privilege beyond the caller's.
  • Only the owner can share. Any other caller, a site owner or an admin who may delete the row included, gets 403 before any row is read, so the route does not reveal whether the workflow exists and nobody publishes a workflow under another member's name. The owner also needs delete and read on the personal row, the same check as a personal delete.

Caveats:

  • The admin ACL view lists the owner with role "read", because the ACL editor models only read grants. The owner's update and delete grants are still stored.
  • An admin who removes the owner from the ACL, or saves the owner as read, revokes the owner's edit rights. The sharing dialog sends only changed entries, so a plain re-save leaves the owner alone. A test covers the revoke path.
  • The site shows Edit and Delete on rows where created_by is the member. If an admin revoked the grant, the server answers 403 and the dialog shows it. Deriving row actions from effective permissions needs a per-row permission field in the API, which is a follow-up.
  • Shared workflows count against the 100 per organization cap, so members can fill it and claim names before admins. A per-member cap would be a follow-up.
  • Share gives the organization row a new id and new timestamps, because it is a new row in another tier.
  • The full organization 409 path has no dedicated share test. It is the same trigger that the organization create tests cover.
  • The share error uses the same Alert block as the delete confirmation in the same view, not ErrorAlert, so the two stay alike.
  • A committed share whose response is lost shows the transport error. The list refetch then shows the row in the organization list, and a retry gets the 404 toast.
  • A personal workflow deleted and recreated under the same name while the share dialog is open answers 409 on every retry from that dialog. Closing and reopening Share uses the new id.
  • A member who leaves the organization between the route lookup and the share gets the 404 toast, and only the picked row leaves the cache. The server refuses every action on the rows still cached.
  • Fork PRs document their routes in coderd/x/chatd/ARCHITECTURE.md directly, as feat(site): send expect_id with saved workflow saves and deletes #400 did, instead of leaving TODOs.

Tests

  • flock ~/.fork-go.lock go test ./coderd -run 'TestForkShareUserSavedWorkflow|TestForkUserSavedWorkflows|TestForkOrganizationSavedWorkflows|TestForkSavedWorkflowConditionalWrites' -count=1: pass. TestForkShareUserSavedWorkflow covers:
    • OwnerEditsOthersRead: another member's share gets 403 (also for a missing name). The owner's share moves the row (personal list empty, a second share 404). A second member lists and reads it, gets 403 on PATCH and DELETE and 404 on the ACL GET. The owner patches and deletes it.
    • RevokedGrantRemovesEdit: after an admin removes the owner's grant, the owner still reads it but gets 403 on PATCH and DELETE.
    • AdminCannotShareForMember: the site owner's share of a member's workflow gets 403, the personal row is unchanged and no organization row appears.
    • NameTakenKeepsPersonal: 409 with "The organization already has a workflow with this name." and the personal row is unchanged.
    • ExpectID: a mismatch gives 409 and keeps the row, a match succeeds.
    • ExperimentOff: 403.
  • flock ~/.fork-go.lock go test ./coderd/database/dbauthz -run Fork -count=1: pass, with the new ShareUserSavedWorkflowByName method entry.
  • pnpm exec vitest run --project unit src/api/forkSavedWorkflows.test.ts src/api/queries/forkSavedWorkflows.test.ts src/pages/AgentsPage/AgentSettingsPage/ForkSavedWorkflowsPage src/pages/AISettingsPage/ForkWorkflowsPage: 5 files, 64 passed. New page tests assert requests and callbacks: share success (the share request, the success toast, both lists refetch), retry after a 409 (the same dialog sends a second request that succeeds), and share after the workflow is gone (404 shows an info toast, refetches the personal list, and focus lands on the New workflow button while the refetch is still pending). Mutation tests cover the cache: a share moves the row from the personal list into the organization list and detail cache from the response, so it stays listed if the refetch fails, a 409 keeps the personal row, and a 404 drops only the picked row. An API test checks that share sends expect_id and rejects an empty one. Visual states (confirm, pending, error, row access, shared-by-me) are stories: ShareMenuOpen, RowAccess, ShareConfirm, SharePending, ShareError, SharedByMe.
  • tsc --noEmit, biome check, oxlint on the changed files: clean. golangci-lint on the changed Go packages: no findings in changed files.

Negative controls:

  • Owner user_acl changed to read only in the generated query: OwnerEditsOthersRead fails at the owner's PATCH (403).
  • canShare={false} on the page: all three share vitest tests fail.
  • Owner-only check disabled in the handler: AdminCannotShareForMember fails.
  • 404 branch of the share error handler disabled: the "already gone" test fails.
  • The share dialog closed on every error: the retry test and the "already gone" test fail.
  • Share response not written to the organization cache: the share mutation test fails.
  • Share URL built without savedWorkflowWriteSearchParams: the share URL test fails.
  • The 404 onError in the share mutation removed: the 404 mutation test fails, and the page test fails because focus does not reach the New workflow button.

Not verified: the #327 end-to-end flow on a dev build (share in the UI, then run_workflow from a second member's chat) was not exercised. The run path is unchanged and reads organization workflows the same way as before. The new stories were type checked but not rendered locally; Pixel renders them in CI. main was merged in after #400; that merge changed no Go code, so the Go tests were not rerun after it.

…ork-workflows)

Adds POST .../members/{user}/workflows/{workflow}/share, which moves a
personal workflow to the organization tier in one statement. The owner
keeps read, update and delete through user_acl, and the Everyone group
gets read. The member Workflows page gains a Share action and lets the
owner edit and delete the organization workflows they shared.

Closes #395
Closes #327
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 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-21T00:32:54.987551Z 1d91bc1 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

Coder Agents acted on behalf of @ibetitsmike.

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

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

Coder Agents acted on behalf of @ibetitsmike.

@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: 78bf53c20c

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

Coder Agents acted on behalf of @ibetitsmike.

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

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

Coder Agents acted on behalf of @ibetitsmike.

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

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

Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

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

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

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 1d91bc1027

ℹ️ 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 c7dfa9d into main Nov 21, 2026
10 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-395-share-personal-workflows branch November 21, 2026 00:57
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged at head 1d91bc1027db346a59cd77dec96df79e8179e164 as c7dfa9d, on main f874782e719f1a7d23419d9ae9688d6c3beda524, with the server running that main.

Gates on this exact head:

  1. The head matched the SHA I verified (--match-head-commit).
  2. Every check run passed. fork-ci run 44844139817 passed on this head.
  3. Codex receipt for this head: feat: members share personal saved workflows with the organization (fork-workflows) #404 (comment) ("Didn't find any major issues").
  4. No unresolved review thread.
  5. 0 commits behind main.
  6. I ran the tests below on this exact head.

Tests I ran on 1d91bc1027:

  • go test ./coderd/ -run 'TestForkShareUserSavedWorkflow|TestForkUserSavedWorkflow|TestForkOrganizationSavedWorkflow|TestForkSavedWorkflowConditionalWrites': 37 passed, 0 failed.
  • go test ./coderd/database/dbauthz/ -run 'TestForkQuerier|TestSavedWorkflowRBAC': 954 passed, 0 failed.
  • Go negative control: with the owner-only check in the share handler disabled, TestForkShareUserSavedWorkflow/AdminCannotShareForMember fails.
  • pnpm exec vitest run --project unit on the saved workflow API and query tests, AISettingsPage/ForkWorkflowsPage and AgentSettingsPage/ForkSavedWorkflowsPage: 5 files, 64 tests passed.
  • Site negative control: with a wrong share path in the API client, the share request test fails. Sources were restored after each control.

Review notes:

  • POST .../members/{user}/workflows/{workflow}/share moves a member's personal workflow to the organization tier in one SQL statement. Every member gets read through the Everyone group. The owner keeps read, update and delete, but not the share action.
  • Only the owner can share. An admin gets 403 for another member's workflow. dbauthz requires delete and read on the personal row.
  • A taken organization name or a full organization gives 409 and keeps the personal row. expect_id makes the move conditional, as in saved workflows: id-conditional PATCH and DELETE #392.
  • The member Workflows page has a Share action with a confirm dialog.
  • ARCHITECTURE.md gets final prose, per the lead decision for fork sections.

Not exercised: the share flow in a dev build, and a second member running the shared workflow by name from a chat. Coverage is coderd integration tests and mocked site tests.

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.

saved workflows: members share a personal workflow with the organization site: Workflows settings page for saved workflows

1 participant