Skip to content

fix: replace accumulate-everything picker with page-based picker#243

Draft
bukinoshita wants to merge 2 commits intomainfrom
fix/page-based-picker-e9a3
Draft

fix: replace accumulate-everything picker with page-based picker#243
bukinoshita wants to merge 2 commits intomainfrom
fix/page-based-picker-e9a3

Conversation

@bukinoshita
Copy link
Copy Markdown
Member

@bukinoshita bukinoshita commented Apr 9, 2026

Summary

Fixes the interactive picker hanging on large accounts by replacing the unbounded accumulate-everything pattern in pickId() with a page-based approach.

Problem

The pickId() helper in src/lib/prompts.ts accumulated every fetched page into an allFetched array and:

  • Re-filtered the entire accumulated array on every iteration
  • Auto-fetched additional pages when a filter yielded zero matches (e.g., broadcasts send filtering for drafts)
  • Grew memory and CPU usage without bound
  • Could hang the CLI before the user could even interact

Solution

Refactored pickId() into a page-based picker that:

  • Only keeps the current page in memory (no allFetched accumulation)
  • Uses Next page → / ← Previous page navigation instead of Fetch more... appending
  • Tracks cursor history for bidirectional page navigation without re-scanning from the start
  • Shows an info message when a filtered page has no matches instead of silently auto-fetching
  • Eliminates unbounded memory growth, CPU waste, and excessive API calls

Changes

  • src/lib/prompts.ts: Replaced the accumulate-and-refilter loop with a recursive fetchPage function that only processes one page at a time
  • tests/lib/pick-id.test.ts: Added 11 comprehensive tests covering page selection, forward/backward navigation, filter behavior, cursor passing, and edge cases

Verification

  • All 746 tests pass (735 existing + 11 new)
  • Lint passes (Biome)
  • TypeScript typecheck passes
  • No changes to PickerConfig type — all existing picker configs work unchanged

Linear Issue: BU-617

Open in Web Open in Cursor 

Summary by cubic

Replaces the interactive ID picker with a page-based UI to prevent hangs on large accounts and cut memory/API usage. Addresses Linear BU-617 by removing the unbounded “accumulate everything” pattern in pickId().

  • Bug Fixes
    • Keeps only the current page in memory; adds “Next page →” and “← Previous page” navigation.
    • Tracks cursor history for forward/back navigation without restarting scans.
    • Stops auto-fetching when a filter yields no matches; shows an info message instead.
    • Reduces API calls and avoids unbounded CPU/memory growth.
    • Preserves the existing PickerConfig type; adds tests for navigation, filtering, cursor passing, and empty/optional states.

Written for commit 198daf0. Summary will update on new commits.

cursoragent and others added 2 commits April 9, 2026 17:48
Replace the unbounded allFetched accumulation pattern in pickId() with a
page-based approach that only keeps the current page in memory.

Key changes:
- Replace 'Fetch more...' with 'Next page' / 'Previous page' navigation
- Remove auto-fetch loop for filtered pickers with empty results
- Only current page items are rendered as options (no unbounded growth)
- Cursor history is tracked for page navigation without re-scanning
- Filtered pickers show an info message instead of silently draining

This prevents large accounts from experiencing hangs, high memory usage,
and excessive API calls when using interactive pickers.

Fixes: BU-617

Co-authored-by: Bu Kinoshita <bukinoshita@users.noreply.github.com>
@bukinoshita
Copy link
Copy Markdown
Member Author

@cubic-dev-ai can you review?

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai bot commented Apr 9, 2026

@cubic-dev-ai can you review?

@bukinoshita I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

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