Skip to content

fix: auto-paginate workflow list#12

Merged
Hinne1 merged 2 commits intomainfrom
hs_fix-workflow-list-auto-pagination
Mar 24, 2026
Merged

fix: auto-paginate workflow list#12
Hinne1 merged 2 commits intomainfrom
hs_fix-workflow-list-auto-pagination

Conversation

@Hinne1
Copy link
Contributor

@Hinne1 Hinne1 commented Mar 23, 2026

Summary

  • wf list now auto-paginates through all pages (250/page) instead of silently truncating at 100
  • With 310 workflows on prod, the old default hid 210 workflows from every list operation
  • Manual pagination via --cursor still works for single-page fetches
  • --limit default changed from 100 to 0 (= fetch all)

What changed

  • ListWorkflows in the API client now loops through pages automatically
  • Original single-page logic extracted to listWorkflowsPage (unexported)
  • Removed "More results available" CLI hint (no longer needed)

Test plan

  • n8nctl wf list --json returns 310 workflows (was 100)
  • n8nctl wf list --active returns 81 (was truncated to whatever fit in page 1)
  • --cursor flag still works for manual single-page fetch
  • go build ./... passes

ListWorkflows now fetches all pages automatically (250/page) instead of
silently truncating at the first 100 results. With 300+ workflows on
prod, the old behavior hid workflows from all list operations.

Manual pagination still works via --cursor for single-page fetches.
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue where the wf list command silently truncated workflow results, displaying only the first 100 workflows. By implementing automatic pagination in the API client and adjusting the CLI behavior, users can now reliably retrieve all workflows without manual intervention, significantly improving the usability and accuracy of workflow listings.

Highlights

  • Auto-pagination for wf list: The wf list command now automatically paginates through all available workflow pages, resolving previous truncation issues where only the first 100 workflows were displayed.
  • API Client Refactoring: The ListWorkflows function in the API client was refactored to handle automatic pagination, with the original single-page logic extracted into an unexported listWorkflowsPage function.
  • CLI --limit default: The default value for the --limit flag in wf list has been changed from 100 to 0, signifying that all workflows should be fetched by default.
  • Manual Pagination Support: Manual pagination using the --cursor flag is still supported, allowing users to fetch specific pages when needed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces automatic pagination for the wf list command. The review focuses on a breaking change in the behavior of the --limit flag, a magic number that could be a constant, and a suggestion for clarifying a command-line flag's help text.

Comment on lines +218 to +247
func (c *Client) ListWorkflows(opts ListWorkflowsOptions) (*ListResult[Workflow], error) {
// Manual pagination: caller provided a cursor, return single page
if opts.Cursor != "" {
return c.listWorkflowsPage(opts)
}

pageSize := opts.Limit
if pageSize <= 0 {
pageSize = 250
}

var all []Workflow
pageOpts := opts
pageOpts.Limit = pageSize

for {
page, err := c.listWorkflowsPage(pageOpts)
if err != nil {
return nil, err
}
all = append(all, page.Data...)

if page.NextCursor == "" || len(page.Data) == 0 {
break
}
pageOpts.Cursor = page.NextCursor
}

return &ListResult[Workflow]{Data: all}, nil
}

Choose a reason for hiding this comment

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

high

This new implementation of ListWorkflows changes the behavior of the --limit flag in a breaking way. Previously, it limited the total number of results. Now, it controls the page size for auto-pagination, and there is no longer a way to limit the total number of returned workflows. This can be surprising to users and may cause performance issues if they unintentionally fetch a very large number of workflows.

Consider re-introducing a way to limit the total number of results, perhaps by making --limit a total limit again and adding a new --page-size flag for when pagination is desired.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the intentional behavior change — the whole point of this PR. The old --limit 100 default silently hid 210 of 310 workflows on prod. Nobody was using --limit to deliberately cap results; it was just a page size that happened to truncate output.

This is an internal CLI (n8nctl), so there's no external compatibility concern. Adding a separate --page-size flag would be YAGNI.


pageSize := opts.Limit
if pageSize <= 0 {
pageSize = 250

Choose a reason for hiding this comment

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

medium

The default page size 250 is used here as a magic number. It's better to define this as a constant at the package level, for example const defaultListPageSize = 250. This improves code clarity and maintainability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed — extracted to defaultListPageSize constant.

cmd.Flags().StringSliceVar(&tags, "tag", nil, "Filter by tag (can be repeated)")
cmd.Flags().IntVar(&limit, "limit", 100, "Maximum number of workflows to return")
cmd.Flags().StringVar(&cursor, "cursor", "", "Pagination cursor for next page")
cmd.Flags().IntVar(&limit, "limit", 0, "Maximum number of workflows per page (0 = auto-paginate all)")

Choose a reason for hiding this comment

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

medium

The help text (0 = auto-paginate all) is a bit misleading. With the new implementation, auto-pagination of all results happens for any value of --limit, with the value determining the page size. The special case for 0 is that it uses a default page size (250). A clearer description would improve user understanding.

Suggested change
cmd.Flags().IntVar(&limit, "limit", 0, "Maximum number of workflows per page (0 = auto-paginate all)")
cmd.Flags().IntVar(&limit, "limit", 0, "Maximum number of workflows per page; all pages are fetched (0 = default size)")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed — updated to Page size per API request (0 = default).

Address Gemini review feedback:
- Extract magic number 250 to defaultListPageSize constant
- Clarify --limit flag description (all values auto-paginate)
@Hinne1 Hinne1 marked this pull request as ready for review March 24, 2026 04:56
@Hinne1 Hinne1 merged commit 34b5dc5 into main Mar 24, 2026
5 checks passed
@gemini-code-assist
Copy link

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@Hinne1 Hinne1 deleted the hs_fix-workflow-list-auto-pagination branch March 24, 2026 04:56
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