Skip to content

fix(client-js): send page/perPage in logs queries when they are 0#18632

Open
abhay-codes07 wants to merge 1 commit into
mastra-ai:mainfrom
abhay-codes07:fix/client-js-logs-pagination-zero
Open

fix(client-js): send page/perPage in logs queries when they are 0#18632
abhay-codes07 wants to merge 1 commit into
mastra-ai:mainfrom
abhay-codes07:fix/client-js-logs-pagination-zero

Conversation

@abhay-codes07

@abhay-codes07 abhay-codes07 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What

client.listLogs and client.getLogForRun drop the page and perPage query parameters when they are 0, because they guard with a truthy check:

if (page) {
  searchParams.set('page', String(page));
}
if (perPage) {
  searchParams.set('perPage', String(perPage));
}

page/perPage are optional numbers, so if (page) is falsy for 0. Requesting the first page with page: 0 (or perPage: 0) never sends those values and the server falls back to its own defaults, returning the wrong page.

Every other paginated method in the client guards with !== undefined (listMemoryThreads, getMcpServers, listScoresByRunId, the resources/ methods, etc.). These two log methods are the only sites using a truthy check.

Change

Change the four guards in listLogs and getLogForRun to !== undefined.

Tests

Added unit tests asserting listLogs and getLogForRun include page=0 and perPage=0 in the request URL. Both fail on the current code and pass after the fix. The existing client.test.ts suite still passes.

Closes #18631


cc @abhiaiyer91 who last touched this file. One-line-per-site change, no behavior change for non-zero values.

ELI5

This change fixes a bug where asking for the first page of logs could accidentally be ignored. Now, when page or perPage is set to 0, the client still sends it properly instead of skipping it and using the server’s default.

What changed

  • Fixed client.listLogs and client.getLogForRun to keep page=0 and perPage=0 in query strings by checking for !== undefined instead of truthy values.
  • Added unit tests to confirm both methods include zero-valued pagination parameters in the request URL.
  • Added a changeset for @mastra/client-js.

Notes

  • This resolves the pagination bug for zero values and closes the referenced issue.

listLogs and getLogForRun guarded page/perPage with a truthy check, so page: 0
(the first page) and perPage: 0 were dropped from the query string and the
server fell back to its own defaults. Every other paginated method in the client
guards with !== undefined; these two were the only sites using a truthy check.

Change the four guards to !== undefined. Adds unit tests.

Closes mastra-ai#18631
Copilot AI review requested due to automatic review settings June 29, 2026 17:53
@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 919580f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@mastra/client-js Patch
@internal/playground Patch
@mastra/react Patch
mastra Patch
@mastra/playground-ui Patch
create-mastra Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@abhay-codes07 is attempting to deploy a commit to the Mastra Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e7465702-e93d-480c-9046-a5578d4c6e61

📥 Commits

Reviewing files that changed from the base of the PR and between 56ea17e and 919580f.

📒 Files selected for processing (3)
  • .changeset/fix-client-js-logs-pagination-zero.md
  • client-sdks/client-js/src/client-logs-pagination.test.ts
  • client-sdks/client-js/src/client.ts

Walkthrough

In client.ts, the listLogs and getLogForRun methods change their page/perPage guards from truthy checks to !== undefined, so zero values are included in query parameters. A new test file verifies this behavior, and a changeset documents the patch.

Fix zero pagination params in client-js log methods

Layer / File(s) Summary
Fix undefined checks and add pagination tests
client-sdks/client-js/src/client.ts, client-sdks/client-js/src/client-logs-pagination.test.ts, .changeset/fix-client-js-logs-pagination-zero.md
Four truthy guards (if (page), if (perPage)) in listLogs and getLogForRun are replaced with !== undefined checks. New tests assert that page=0 and perPage=0 appear in request URLs. Changeset marks a patch release.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the logs pagination zero-value fix.
Linked Issues check ✅ Passed The code and tests match issue #18631 by preserving page/perPage when they are 0.
Out of Scope Changes check ✅ Passed The PR only adds the targeted fix, test coverage, and a changeset.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@dane-ai-mastra dane-ai-mastra Bot added the complexity: low Low-complexity PR label Jun 29, 2026
@dane-ai-mastra

Copy link
Copy Markdown
Contributor

PR triage

Linked issue check passed (#18631).

Mastra uses CodeRabbit for automated code reviews. Please address all feedback from CodeRabbit by either making changes to your PR or leaving a comment explaining why you disagree with the feedback. Since CodeRabbit is an AI, it may occasionally provide incorrect feedback.


PR complexity score

Factor Value Score impact
Files changed 3 +6
Lines changed 57 +3
Author merged PRs 2 -2
Test files changed Yes -10
Final score -3

Applied label: complexity: low


Changed test gate

Changed Test Gate is pending. The Changed Test Gate / changed-tests check will update the test label when it completes.

@abhay-codes07

Copy link
Copy Markdown
Contributor Author

@abhiaiyer91 kindly approve it since I found few good quality issues and because of limit reset I can't proceed with the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

complexity: low Low-complexity PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] client-js listLogs/getLogForRun drop page and perPage when they are 0

2 participants