Skip to content

Implement workflow.list and workflow.listByName - #189

Merged
ianmacartney merged 4 commits into
convex:mainfrom
dantman:feat-list
Jan 21, 2026
Merged

ianmacartney merged 4 commits into
convex:mainfrom
dantman:feat-list

Conversation

@dantman

@dantman dantman commented Jan 15, 2026 •

Copy link
Copy Markdown
Contributor

This implements two new methods of listing workflows. One for all workflows workflow.list which is ordered by creation. And one for workflows matching a specific name workflow.listByName.

These may be useful in user side attempts to cleanup workflows or create a dashboard listing the status of workflows.

I was not able to get npm link to work in my project so I have not been able to actually try out the new methods.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Summary by CodeRabbit

  • New Features

    • Added listing of workflows with pagination and ordering, name-based filtering, and paginated listing of workflow steps.
    • Improved workflow listing/filtering performance by indexing workflow names.
  • Documentation

    • Added "Listing workflows and steps" guide and updated examples with explicit handler annotations.
    • Added example showing storing an action result and clarified mutation examples to fetch by collection.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 15, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds paginated workflow listing endpoints and client APIs: list and listByName, a new PublicWorkflow type and validator, a workflows table index on name, documentation updates, and example/tsconfig adjustments. Client methods call component queries via ctx.runQuery.

Changes

Cohort / File(s) Summary
Documentation & Examples
README.md, example/convex/README.md
New "Listing workflows and steps" docs; examples updated with type-annotated handlers; example mutation now uses ctx.db.get("messages", id) (collection + id).
Client API
src/client/index.ts
Added list(ctx, opts?) and listByName(ctx, name, opts?) on WorkflowManager returning PaginationResult<PublicWorkflow> and delegating to component queries via ctx.runQuery. Note: methods appear duplicated in the diff.
Component Queries
src/component/workflow.ts
Added list and listByName query endpoints with ordering and pagination; introduced internal publicWorkflow() mapper to produce PublicWorkflow results.
Database Schema
src/component/schema.ts
Added .index("name", ["name"]) to the workflows table definition to support name-based queries.
Types & Validation
src/types.ts
Added PublicWorkflow, vPublicWorkflow, and VPublicWorkflow; added _publicWorkflow type assertion; renamed internal assertion _ → _workflowStep.
Example TS Config
example/convex/tsconfig.json
Reorganized/annotated tsconfig into required/not-required sections; adjusted lib, include, and exclude values and comments.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Server as WorkflowManager
  participant Component as workflow queries
  participant DB as Workflows Table
  Client->>Server: WorkflowManager.list(name?, opts?)
  Server->>Component: ctx.runQuery('list' / 'listByName', args)
  Component->>DB: query workflows (use .index("name") if filtering)
  DB-->>Component: paginated workflow docs
  Component->>Server: mapped PublicWorkflow pagination result
  Server-->>Client: PaginationResult<PublicWorkflow>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hopped through code with eager paws,

Added lists and indexed laws.
Names now found in nimble pace,
Clients call and fetch the trace.
A tiny hop, a tidy run—workflow joy, well done!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main objective of the pull request: implementing two new workflow listing methods (workflow.list and workflow.listByName).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1ddcd3 and 9c15b2b.

⛔ Files ignored due to path filters (1)
  • src/component/_generated/component.ts is excluded by !**/_generated/**
📒 Files selected for processing (1)
  • src/types.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/types.ts

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@example/convex/README.md`:
- Line 68: The example uses an invalid call ctx.db.get("messages", id); replace
it with the correct Convex signature ctx.db.get(id) so the function passes only
the document ID (variable id) to ctx.db.get, and update any surrounding code or
comments that implied a collection-name parameter to reflect that ctx.db.get
accepts a single ID argument.

In `@src/component/workflow.ts`:
- Around line 122-130: The vPublicWorkflow validator is missing the runResult
field so Convex will strip it from responses; update the vPublicWorkflow object
to include runResult (e.g., add runResult: v.optional(vResultValidator) or
runResult: vResultValidator depending on whether RunResult can be null/absent)
and ensure vResultValidator (from `@convex-dev/workpool`) is imported and used so
the validator matches the PublicWorkflow type returned by publicWorkflow.

In `@src/types.ts`:
- Around line 26-42: The vPublicWorkflow validator is missing the runResult
property even though publicWorkflow returns runResult: workflow.runResult;
update the vPublicWorkflow definition to include runResult (e.g., add runResult:
v.optional(v.any()) or an appropriate typed validator) so the runtime schema
matches the PublicWorkflow type; ensure the added validator uses the same
optional/required semantics as the PublicWorkflow field and keep VPublicWorkflow
and the _publicWorkflow assertion consistent.
🧹 Nitpick comments (1)
README.md (1)

541-560: Documentation for listing methods looks good.

The new section clearly documents the list, listByName, and listSteps methods with appropriate code examples. Consider varying the sentence structure to avoid three consecutive "Use" sentences (e.g., "Call listSteps with..." or "To get steps, use...").

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c227162 and e1ddcd3.

⛔ Files ignored due to path filters (3)
  • example/convex/_generated/dataModel.d.ts is excluded by !**/_generated/**
  • src/component/_generated/component.ts is excluded by !**/_generated/**
  • src/component/_generated/dataModel.ts is excluded by !**/_generated/**
📒 Files selected for processing (7)
  • README.md
  • example/convex/README.md
  • example/convex/tsconfig.json
  • src/client/index.ts
  • src/component/schema.ts
  • src/component/workflow.ts
  • src/types.ts
🧰 Additional context used
🧬 Code graph analysis (3)
src/types.ts (1)
src/client/index.ts (4)
  • WorkflowId (44-44)
  • vWorkflowId (41-41)
  • vWorkflowStep (42-42)
  • WorkflowStep (45-45)
src/component/workflow.ts (3)
src/component/_generated/dataModel.ts (1)
  • Doc (30-33)
src/types.ts (3)
  • PublicWorkflow (26-32)
  • vPaginationResult (119-135)
  • vPublicWorkflow (34-39)
src/client/index.ts (2)
  • list (232-247)
  • listByName (260-277)
src/client/index.ts (1)
src/types.ts (1)
  • PublicWorkflow (26-32)
🪛 LanguageTool
README.md

[style] ~554-~554: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...der:function", { order: "desc" }); ``` Use listSteps with a workflow's ID to get...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🔇 Additional comments (10)
example/convex/tsconfig.json (3)

2-13: LGTM! Good documentation and organization.

The added comments clearly explain the config's purpose and distinguish between optional and required settings. The option values are appropriate for a Convex project.


15-17: Verify the lib/target mismatch is intentional.

target is set to "ESNext" but lib is set to ["ES2021", "dom"]. This means type definitions for ES2022+ features (e.g., Array.prototype.at, Object.hasOwn, Error.cause) won't be available, even though the target allows their syntax. Also, DOM.Iterable was removed, which provides iterator types for DOM collections.

If newer APIs are needed, consider aligning:

-    "lib": ["ES2021", "dom"],
+    "lib": ["ESNext", "DOM", "DOM.Iterable"],

23-24: LGTM! Fixed glob patterns.

The include pattern is now explicit (["./**/*"] instead of [""]), and exclude uses a consistent relative path prefix. These are proper corrections.

src/component/schema.ts (1)

179-179: LGTM!

The new index on the name field correctly enables efficient lookups for the listByName query. Since name is optional (v.optional(v.string())), workflows without a name will still be indexed with undefined, which is appropriate behavior.

src/types.ts (1)

83-83: LGTM!

Good improvement renaming the type assertion variable to _workflowStep for clarity, consistent with the new _publicWorkflow pattern.

src/client/index.ts (2)

222-247: New list method implementation looks good.

The method follows the established pattern from listSteps, with sensible defaults (ascending order, 100 items per page). The JSDoc is comprehensive.


249-277: New listByName method implementation is correct.

Consistent with the list method, properly passes the name filter parameter to the component endpoint. Both methods use matching pagination defaults and type handling.

src/component/workflow.ts (3)

28-33: LGTM!

The new imports for PublicWorkflow, vPublicWorkflow, Doc, and Id are correctly added to support the new listing functionality.


162-178: LGTM!

The list query implementation is correct:

  • Uses paginator from convex-helpers for proper pagination support
  • Accepts order and pagination options as expected by the client
  • Maps results through publicWorkflow to transform internal documents to public representation

The type assertion on line 176 is necessary due to the map transformation changing the page item type.


180-198: LGTM!

The listByName query implementation correctly uses the name index on the workflows table for efficient filtering. The implementation is consistent with the list query pattern, and the index is properly defined in the schema.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread example/convex/README.md Resolved
Comment thread src/component/workflow.ts Resolved
Comment thread src/types.ts Resolved

@ianmacartney ianmacartney left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Can you try it out with the pkg-pr-new link (I'll generate it now)

@pkg-pr-new

pkg-pr-new Bot commented Jan 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/get-convex/workflow/@convex-dev/workflow@189

commit: 9c15b2b

@dantman

dantman commented Jan 15, 2026

Copy link
Copy Markdown
Contributor Author

Can confirm. With the pkg-pr-new version adding this mutation and running it worked to cleanup the workflows for my test email sending.

/**
 * Cleanup test email workflows.
 *
 * Cleans up the oldest 100 test email workflows.
 */
export const cleanupTestEmailWorkflows = internalMutation({
	args: {},
	handler: async (ctx) => {
		const workflows = await workflow.listByName(
			ctx,
			"email/test:sendTestEmailWorkflow",
			{ order: "asc", paginationOpts: { cursor: null, numItems: 100 } }
		);

		for (const wf of workflows.page) {
			await workflow.cleanup(ctx, wf.workflowId);
		}
	},
});

@ianmacartney
ianmacartney merged commit 2088b8a into convex:main Jan 21, 2026
2 checks passed
@ianmacartney

Copy link
Copy Markdown
Member

Thanks @dantman - just released it in @convex-dev/workflow@0.3.4

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.

2 participants