Skip to content

fix(prisma-cloud): bound the last three Management API listing loops - #204

Merged
wmadden-electric merged 2 commits into
mainfrom
fix/bound-remaining-pagination
Aug 5, 2026
Merged

fix(prisma-cloud): bound the last three Management API listing loops#204
wmadden-electric merged 2 commits into
mainfrom
fix/bound-remaining-pagination

Conversation

@wmadden-electric

Copy link
Copy Markdown
Contributor

Converts the three remaining hand-rolled cursor-pagination loops to the bounded page driver introduced in #195, so a misbehaving Management API (a non-advancing cursor, or endless pages) fails a deploy loudly instead of hanging it — in the listAllConnections case, hanging while holding the deploy lock.

Changes

  • listAllProjects (lowering/src/container.ts) and listAllConnections (lowering/src/state/bootstrap.ts): shape-only conversion to collectPages — same accumulate-everything semantics on a healthy API.
  • Preflight's env-var visibility search (target/src/preflight.ts): converted to a new drivePagesAsync — a Promise twin of drivePages sharing the page cap and error builder. It is deliberately a sibling loop rather than an Effect wrapper: routing the fetch through Effect.runPromise would re-wrap preflight's own listFailedError as a FiberFailure, changing the error identity its callers see (the doc comment records this). The short-circuit on the first visible row is preserved.
  • pagination.ts joins the lowering barrel (export *, matching the file's idiom) so target can import it.
  • Test fakes in both packages gained real cursor paging plus stuck-cursor and runaway-cursor modes; new tests pin found-beyond-page-one, the stuck-empty-page rejection (chosen so the short-circuit cannot mask it), and the page-cap rejection.

With this, no hand-rolled Management API cursor loop remains in the package (swept during review).

Why

#195's review found this loop shape can spin forever on a stuck cursor; it bounded the three loops that PR touched and deferred these three, which run on every deploy. Same trade-off as accepted there: a broken listing fails the deploy with a named error instead of hanging or acting on incomplete data.

Verification: lowering 145 / target 342 tests pass (both failure paths pinned per package), lint clean, cast-ratchet delta 0, typecheck 74/74.

🤖 Generated with Claude Code

PR #195 introduced the bounded page driver and converted the loops it
touched; three hand-rolled, unbounded loops stayed on the deploy path.
listAllProjects (container.ts) and listAllConnections (state/bootstrap.ts)
now use collectPages. The env-var visibility search in target's preflight
speaks the SDK's Promise {data, error} shape directly, so pagination.ts
gains drivePagesAsync — a Promise twin of drivePages sharing the page cap
and non-advancing-cursor failure, kept as a sibling loop so the caller's
own thrown errors (listFailedError) propagate unwrapped — and preflight's
short-circuiting search runs through it. pagination.ts is exported from the
lowering barrel so target can import it like every other lowering helper.

Fakes for /v1/projects and the env-var listing gained real cursor paging
plus stuck- and runaway-cursor modes; both failure paths are pinned per
package.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@wmadden-electric, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 564c59b6-40e6-4fb5-89c6-9d21a591f281

📥 Commits

Reviewing files that changed from the base of the PR and between 8308108 and 335ca0b.

📒 Files selected for processing (4)
  • .drive/deferred.md
  • packages/1-prisma-cloud/0-lowering/lowering/src/__tests__/container.test.ts
  • packages/1-prisma-cloud/0-lowering/lowering/src/pagination.ts
  • packages/1-prisma-cloud/1-extensions/target/src/__tests__/preflight.test.ts

Summary by CodeRabbit

  • Bug Fixes

    • Improved retrieval of projects, connections, and environment variables across multiple API pages.
    • Prevented endless pagination loops caused by stalled or runaway cursors.
    • Added safeguards that stop pagination after a defined maximum.
    • Checks can now stop early when a matching result is found.
  • Tests

    • Added coverage for later-page results and invalid or unbounded pagination scenarios.

Walkthrough

The change replaces manual cursor loops for projects, connections, and environment variables with shared bounded pagination helpers. It adds the Promise-based drivePagesAsync helper and exports the pagination module. Tests now simulate later-page results, stuck cursors, and pagination exceeding the 1,000-page limit. A deferred follow-up records workflow cleanup and confirms the pagination conversion.

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and specifically summarizes the main change: converting the remaining Management API listing loops to use bounded pagination.
Description check ✅ Passed The description comprehensively explains the changeset, including the problem, solution, affected functions, and verification results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bound-remaining-pagination
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/bound-remaining-pagination

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.

@pkg-pr-new

pkg-pr-new Bot commented Aug 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@prisma/composer@204
npm i https://pkg.pr.new/@prisma/composer-prisma-cloud@204

commit: 335ca0b

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.drive/deferred.md:
- Around line 179-183: Insert one blank line after each of the headings “Remove
the composer-demo CI USER workaround (after TML-3157 ships)” and “Convert the
remaining Management API listing loops to drivePages” in the deferred
documentation.

In `@packages/1-prisma-cloud/0-lowering/lowering/src/pagination.ts`:
- Around line 87-90: Update the pagination logic in collectPages and drivePages
to return only when hasMore is false; when hasMore is true with a null
nextCursor, throw brokenPaginationError instead of treating the listing as
complete. Preserve the non-advancing cursor check and add regression coverage
for both drivers.

In `@packages/1-prisma-cloud/0-lowering/lowering/src/state/bootstrap.ts`:
- Around line 78-84: Update cleanupAgedConnections so PrismaApiError failures
from listAllConnections, including stuck or MAX_PAGES-exceeded pagination,
propagate out of bootstrap instead of being swallowed by the outer
Effect.ignore; retain best-effort ignoring only for individual deleteConnection
failures. Add a bootstrap test covering a non-advancing connection cursor or
capped connection pages and assert the cleanup/bootstrap operation fails.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: efca5cdd-5b20-4f2b-a344-776eb5f9747f

📥 Commits

Reviewing files that changed from the base of the PR and between d30d751 and 8308108.

📒 Files selected for processing (8)
  • .drive/deferred.md
  • packages/1-prisma-cloud/0-lowering/lowering/src/__tests__/container.test.ts
  • packages/1-prisma-cloud/0-lowering/lowering/src/container.ts
  • packages/1-prisma-cloud/0-lowering/lowering/src/exports/index.ts
  • packages/1-prisma-cloud/0-lowering/lowering/src/pagination.ts
  • packages/1-prisma-cloud/0-lowering/lowering/src/state/bootstrap.ts
  • packages/1-prisma-cloud/1-extensions/target/src/__tests__/preflight.test.ts
  • packages/1-prisma-cloud/1-extensions/target/src/preflight.ts

Comment thread .drive/deferred.md Outdated
Comment thread packages/1-prisma-cloud/0-lowering/lowering/src/pagination.ts
Comment thread packages/1-prisma-cloud/0-lowering/lowering/src/state/bootstrap.ts
Both page drivers treated `hasMore: true` with `nextCursor: null` as a
clean end, so a listing the API itself says is incomplete came back as if
it were complete — the exact outcome the drivers exist to prevent. Both
now return only when `hasMore` is false, and raise the shared broken-
pagination error when more pages are reported without a cursor to fetch
them with. The non-advancing-cursor check, the 1000-page cap, and the
early stop when `onPage` returns true are unchanged.

The lowering and target fakes gained a matching mode, and each driver has
a test pinning the new failure. Without the fix, the target test shows the
old behaviour concretely: preflight reported a provisioned secret as
missing because it stopped reading after the first page.

Also rewraps the two newest `.drive/deferred.md` entries to the file's
style — blank line after the heading (markdownlint MD022), prose wrapped
at 80 columns.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@wmadden-electric
wmadden-electric enabled auto-merge (squash) August 5, 2026 06:21
@wmadden-electric
wmadden-electric merged commit ba074ca into main Aug 5, 2026
18 checks passed
@wmadden-electric
wmadden-electric deleted the fix/bound-remaining-pagination branch August 5, 2026 06:24
wmadden-electric added a commit that referenced this pull request Aug 5, 2026
Reconciles the preflight env-var listing: main bounded the loop with
drivePagesAsync (#204); this branch made the same loop track the newest
updatedAt for the deploy fingerprint. The merged version walks every page
through the bounded driver and keeps both sides' tests.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
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