Skip to content

feat(coderd/database): add saved workflows storage - #335

Merged
ibetitsmike merged 5 commits into
mainfrom
mike/issue-322-saved-workflows-a
Nov 15, 2026
Merged

ibetitsmike merged 5 commits into
mainfrom
mike/issue-322-saved-workflows-a

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Coder Agents opened this PR on behalf of @ibetitsmike.

Part 1 of the stack for #322 (saved workflows). This PR adds only the storage. Routes and run_workflow by name come in the next PRs of the stack.

What changed

  • New chatdmig node 01a1db0e-..._saved_workflows creates saved_workflows. It follows agent_definitions:
    • User tier: user_id set, one row per user, organization and name.
    • Organization tier: user_id NULL, shared through group_acl and user_acl.
    • Columns: name, description, script, optional args_schema (a JSON object), phases text[] (stored now, used by chatd, site: workflow phases and the phase rail on the run card #325), created_by (who saved it, set NULL when that user is deleted).
    • Checks on name format and sizes, 32 phases at most, ACLs only on the organization tier.
    • A trigger caps rows at 100 per user per organization and 100 per organization.
    • A trigger drops a member's direct ACL grants when they leave the organization.
  • forkdb queries for both tiers: insert, get by name, list metadata (no script), partial update, ACL update and delete.
  • dbauthz authorizes like agent definitions of the same tier:
    • User tier: organization read plus user_skill owned by the user.
    • Organization tier: organization_skill with the row's ACLs. Members get read through the ACL. Create, update, share and delete need org admin rights.
  • dbmetrics wrappers and RBACObject methods.

Why

#322 needs a saved workflow resource with personal and organization tiers that mirror agent definitions.

Assumption to review

Mirroring agent definitions means a plain member cannot publish a workflow to the organization tier. Only org admins (and owners) create and share organization workflows. #327 talks about a member sharing their workflow, so this may need a follow-up decision.

Tests

  • flock ~/.fork-go.lock go test ./coderd/database/dbauthz/ -count=1: ok. Includes 12 new TestForkQuerier cases and TestSavedWorkflowRBAC, which runs the real authorizer: a member cannot read, list, edit or delete another member's workflow, cannot publish, edit, share or delete organization workflows, and reads shared rows through the Everyone grant or a direct grant.
  • flock ~/.fork-go.lock go test ./coderd/database/forkdb/ ./coderd/database/migrations/chatdmig/... -count=1: ok. TestSavedWorkflows covers defaults, unique names per tier, check constraints, both limits, user delete, partial updates and the ACL trigger.
  • flock ~/.fork-go.lock go run ./coderd/database/migrations/chatdmig/cmd/chatdmig check: ok.
  • flock ~/.fork-go.lock golangci-lint run ./coderd/database/forkdb/... ./coderd/database/dbauthz/... ./coderd/database/dbmetrics/...: 0 issues.

Size: about 350 lines of code and 485 lines of tests, generated code excluded.

Not covered here: HTTP routes, the experiment gate and the agent tool. They land in the next PRs.

Part of #322.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 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-15T15:31:20.569711Z 6016deb 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. Keep it up!

Reviewed commit: 4bdce68a2e

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

…workflows-a

# Conflicts:
#	coderd/database/forkdb/sqlc.yaml
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged main forward through the stack. @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 1194e8782b

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

Merged main (#334). @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 3b382682b1

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

…workflows-a

# Conflicts:
#	coderd/database/forkdb/sqlc.yaml
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged main (#339) into the branch. The sqlc.yaml conflict kept both nodes in graph order. chatdmig check passes, with saved_workflows before chat_wakeup_watches. The chatdmig tests with CHATDMIG_TEST_DATABASE_URL, the forkdb tests and the dbauthz tests pass.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 6b2d8c2645

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

Merged main (#340) into the branch with no conflicts. chatdmig check passes in the order saved_workflows, chat_wakeup_watches, chat_wakeup_watches_backfill. forkdb/generate.sh changes nothing. The chatdmig tests with CHATDMIG_TEST_DATABASE_URL, the forkdb tests and the dbauthz tests pass.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 6016deb64c

ℹ️ 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 6ae6741 into main Nov 15, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-322-saved-workflows-a branch November 15, 2026 16:17
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged as 6ae6741 (squash of 6016deb).

Gates on the merged head:

  1. Head 6016deb verified with --match-head-commit. main was cdf3579 and the branch was 0 behind.
  2. All 9 check runs passed, including fork-ci run 43730088592 on this exact head.
  3. Codex receipt "Didn't find any major issues" on 6016deb: feat(coderd/database): add saved workflows storage #335 (comment)
  4. 0 unresolved review threads.
  5. Independent Opus review at 3b38268: merge, no P1 or P2. The lines added and removed are identical on 6016deb; only the merges from main differ.
  6. Tests run (Opus reviewer and workstream, under the Go lock): forkdb and chatdmig tests with CHATDMIG_TEST_DATABASE_URL, including TestSavedWorkflows, TestForkNodesOnlyAddToChatd and TestUpgradeMatchesFresh; dbauthz TestSavedWorkflowRBAC, TestMethodTestSuite and the 13 saved workflow TestForkQuerier cases; generate.sh produced no diff; chatdmig check passed. All passed.

Not exercised: the node on a copy of production data, and any live server behavior. This PR adds storage only, with no routes or tools. The previous deploy (cdf3579) had landed before this merge.

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