Skip to content

feat(agent-conversation): Show aggregate metrics and costs - #1458

Merged
vgrozdanic merged 1 commit into
mainfrom
feat/conversation-aggregate-metrics
Oct 9, 2026
Merged

vgrozdanic merged 1 commit into
mainfrom
feat/conversation-aggregate-metrics

Conversation

@vgrozdanic

Copy link
Copy Markdown
Member

Conversation details now preserve server aggregate stats across pagination and expose cost, call totals, errors, token totals, and deduplicated trace IDs in JSON and human output. Conversation list output also shows cost.

Port of getsentry/cli#1662 after CLI moved into Toolkit.

Refs TET-2959
Refs TET-2951

Preserve detail stats through pagination and expose costs, call totals, errors, token totals, and trace IDs in conversation output.

Refs TET-2959

Refs TET-2951

Co-Authored-By: GPT-5.6 Sol <agent@openai.com>
@linear-code

linear-code Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

TET-2951

TET-2959

@vgrozdanic
vgrozdanic marked this pull request as ready for review October 9, 2026 14:13
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 9, 2026
@vgrozdanic
vgrozdanic merged commit 62220b0 into main Oct 9, 2026
24 checks passed
@vgrozdanic
vgrozdanic deleted the feat/conversation-aggregate-metrics branch October 9, 2026 14:14
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
…ination (getsentry#1458)

## Root Cause

`listConversations` in `src/lib/api/conversations.ts` passed the user's
`limit` directly as `per_page` without capping at `API_MAX_PER_PAGE`
(100). The Sentry API silently caps `per_page` at 100, so users
requesting more than 100 conversations got silently truncated results.

Additionally, the function only fetched a single page — unlike all other
list APIs (`listTransactions`, `listSpans`, `listReplays`, etc.) which
use `autoPaginate()` for multi-page fetches.

## Reproduction

1. Run `sentry conversation list --limit 200`
2. The API receives `per_page=200`, silently caps at 100, and returns
only 100 results
3. No further pages are fetched, so the user sees at most 100
conversations instead of 200

## Fix

- Cap `per_page` at `Math.min(limit, API_MAX_PER_PAGE)` 
- Use the `autoPaginate()` helper for multi-page fetches, matching the
pattern used by `listTransactions`, `listSpans`, `listReplays`, and all
other list APIs in the codebase
- Extract the single-page fetch into a `fetchConversationsPage()` helper
(same pattern as other API modules)

<div><a
href="https://cursor.com/agents/bc-6e0fdaa7-73f7-4608-be3a-1498a6cc73bd?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/automations/95624600-485e-4461-829e-6b76f086c473"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/view-automation-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/view-automation-light.png"><img
alt="View Automation" width="141" height="28"
src="https://cursor.com/assets/images/view-automation-dark.png"></picture></a>&nbsp;</div>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
Co-authored-by: jared-outpost[bot] <jared-outpost[bot]@users.noreply.github.com>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
…ination (getsentry#1458)

## Root Cause

`listConversations` in `src/lib/api/conversations.ts` passed the user's
`limit` directly as `per_page` without capping at `API_MAX_PER_PAGE`
(100). The Sentry API silently caps `per_page` at 100, so users
requesting more than 100 conversations got silently truncated results.

Additionally, the function only fetched a single page — unlike all other
list APIs (`listTransactions`, `listSpans`, `listReplays`, etc.) which
use `autoPaginate()` for multi-page fetches.

## Reproduction

1. Run `sentry conversation list --limit 200`
2. The API receives `per_page=200`, silently caps at 100, and returns
only 100 results
3. No further pages are fetched, so the user sees at most 100
conversations instead of 200

## Fix

- Cap `per_page` at `Math.min(limit, API_MAX_PER_PAGE)` 
- Use the `autoPaginate()` helper for multi-page fetches, matching the
pattern used by `listTransactions`, `listSpans`, `listReplays`, and all
other list APIs in the codebase
- Extract the single-page fetch into a `fetchConversationsPage()` helper
(same pattern as other API modules)

<div><a
href="https://cursor.com/agents/bc-6e0fdaa7-73f7-4608-be3a-1498a6cc73bd?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/automations/95624600-485e-4461-829e-6b76f086c473"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/view-automation-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/view-automation-light.png"><img
alt="View Automation" width="141" height="28"
src="https://cursor.com/assets/images/view-automation-dark.png"></picture></a>&nbsp;</div>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
Co-authored-by: jared-outpost[bot] <jared-outpost[bot]@users.noreply.github.com>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
…ination (getsentry#1458)

## Root Cause

`listConversations` in `src/lib/api/conversations.ts` passed the user's
`limit` directly as `per_page` without capping at `API_MAX_PER_PAGE`
(100). The Sentry API silently caps `per_page` at 100, so users
requesting more than 100 conversations got silently truncated results.

Additionally, the function only fetched a single page — unlike all other
list APIs (`listTransactions`, `listSpans`, `listReplays`, etc.) which
use `autoPaginate()` for multi-page fetches.

## Reproduction

1. Run `sentry conversation list --limit 200`
2. The API receives `per_page=200`, silently caps at 100, and returns
only 100 results
3. No further pages are fetched, so the user sees at most 100
conversations instead of 200

## Fix

- Cap `per_page` at `Math.min(limit, API_MAX_PER_PAGE)` 
- Use the `autoPaginate()` helper for multi-page fetches, matching the
pattern used by `listTransactions`, `listSpans`, `listReplays`, and all
other list APIs in the codebase
- Extract the single-page fetch into a `fetchConversationsPage()` helper
(same pattern as other API modules)

<div><a
href="https://cursor.com/agents/bc-6e0fdaa7-73f7-4608-be3a-1498a6cc73bd?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/automations/95624600-485e-4461-829e-6b76f086c473"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/view-automation-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/view-automation-light.png"><img
alt="View Automation" width="141" height="28"
src="https://cursor.com/assets/images/view-automation-dark.png"></picture></a>&nbsp;</div>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
Co-authored-by: jared-outpost[bot] <jared-outpost[bot]@users.noreply.github.com>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
…#1486)

## What

Adds a small shared `paginate<T>()` helper in
`packages/cli/src/lib/api/infrastructure.ts` and migrates the divergent
list call sites onto it.

Every list endpoint was hand-wiring the same two things and occasionally
getting them wrong (see getsentry#1458, where `listConversations` passed raw
`limit` as `per_page` and did a single fetch):

```ts
const perPage = Math.min(limit ?? N, API_MAX_PER_PAGE);
return autoPaginate((cursor) => fetchFooPage(..., perPage, cursor), limit, options.cursor);
```

`paginate()` centralizes the `per_page` cap and the `limit` +
initial-cursor threading into `autoPaginate`, so call sites can't drift:

```ts
const regionUrl = await resolveOrgRegion(orgSlug);
return paginate(options, (perPage, cursor) =>
  fetchConversationsPage(regionUrl, orgSlug, { ...options, cursor }, perPage)
);
```

## Design note

I intentionally did **not** build the `createPaginatedList(endpoint,
schema)` factory from the issue. Each endpoint does bespoke query
building (sort mapping, field arrays, project resolution, response
unwrapping), so a generic endpoint/schema factory would fight those.
Extracting only the bug-prone cap + autoPaginate wiring keeps every
existing `fetch*Page` helper intact and avoids a `region.ts` ↔
`infrastructure.ts` import cycle (region resolution stays at the call
site).

## Changes

- `infrastructure.ts`: new exported `paginate<T>(options, fetchPage,
defaultLimit = 10)`.
- Migrated `listConversations` (default 10), `listReplays` (default 25),
`listTransactions` (default 10), `listSpans` (default 10).
- `fetch*Page` helpers unchanged — still usable for tests / one-off
calls, per the issue's scope.

## Tests

Added a focused `describe("paginate")` block in
`test/lib/api/infrastructure.test.ts`: per_page cap at
`API_MAX_PER_PAGE`, default-limit fallback, initial-cursor forwarding,
literal-limit passthrough below the cap, and multi-page accumulation up
to `limit`.

`vitest run` on the affected suites: **131 passed** (`infrastructure`,
`conversations`, `traces`, `replays`). Biome clean on the touched files.
Pre-existing `tsc` errors from missing generated SDK/docs files are
unrelated to this change.

Fixes getsentry#1473

---------

Co-authored-by: jared-outpost[bot] <jared-outpost[bot]@users.noreply.github.com>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
…#1486)

## What

Adds a small shared `paginate<T>()` helper in
`packages/cli/src/lib/api/infrastructure.ts` and migrates the divergent
list call sites onto it.

Every list endpoint was hand-wiring the same two things and occasionally
getting them wrong (see getsentry#1458, where `listConversations` passed raw
`limit` as `per_page` and did a single fetch):

```ts
const perPage = Math.min(limit ?? N, API_MAX_PER_PAGE);
return autoPaginate((cursor) => fetchFooPage(..., perPage, cursor), limit, options.cursor);
```

`paginate()` centralizes the `per_page` cap and the `limit` +
initial-cursor threading into `autoPaginate`, so call sites can't drift:

```ts
const regionUrl = await resolveOrgRegion(orgSlug);
return paginate(options, (perPage, cursor) =>
  fetchConversationsPage(regionUrl, orgSlug, { ...options, cursor }, perPage)
);
```

## Design note

I intentionally did **not** build the `createPaginatedList(endpoint,
schema)` factory from the issue. Each endpoint does bespoke query
building (sort mapping, field arrays, project resolution, response
unwrapping), so a generic endpoint/schema factory would fight those.
Extracting only the bug-prone cap + autoPaginate wiring keeps every
existing `fetch*Page` helper intact and avoids a `region.ts` ↔
`infrastructure.ts` import cycle (region resolution stays at the call
site).

## Changes

- `infrastructure.ts`: new exported `paginate<T>(options, fetchPage,
defaultLimit = 10)`.
- Migrated `listConversations` (default 10), `listReplays` (default 25),
`listTransactions` (default 10), `listSpans` (default 10).
- `fetch*Page` helpers unchanged — still usable for tests / one-off
calls, per the issue's scope.

## Tests

Added a focused `describe("paginate")` block in
`test/lib/api/infrastructure.test.ts`: per_page cap at
`API_MAX_PER_PAGE`, default-limit fallback, initial-cursor forwarding,
literal-limit passthrough below the cap, and multi-page accumulation up
to `limit`.

`vitest run` on the affected suites: **131 passed** (`infrastructure`,
`conversations`, `traces`, `replays`). Biome clean on the touched files.
Pre-existing `tsc` errors from missing generated SDK/docs files are
unrelated to this change.

Fixes getsentry#1473

---------

Co-authored-by: jared-outpost[bot] <jared-outpost[bot]@users.noreply.github.com>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
…#1486)

## What

Adds a small shared `paginate<T>()` helper in
`packages/cli/src/lib/api/infrastructure.ts` and migrates the divergent
list call sites onto it.

Every list endpoint was hand-wiring the same two things and occasionally
getting them wrong (see getsentry#1458, where `listConversations` passed raw
`limit` as `per_page` and did a single fetch):

```ts
const perPage = Math.min(limit ?? N, API_MAX_PER_PAGE);
return autoPaginate((cursor) => fetchFooPage(..., perPage, cursor), limit, options.cursor);
```

`paginate()` centralizes the `per_page` cap and the `limit` +
initial-cursor threading into `autoPaginate`, so call sites can't drift:

```ts
const regionUrl = await resolveOrgRegion(orgSlug);
return paginate(options, (perPage, cursor) =>
  fetchConversationsPage(regionUrl, orgSlug, { ...options, cursor }, perPage)
);
```

## Design note

I intentionally did **not** build the `createPaginatedList(endpoint,
schema)` factory from the issue. Each endpoint does bespoke query
building (sort mapping, field arrays, project resolution, response
unwrapping), so a generic endpoint/schema factory would fight those.
Extracting only the bug-prone cap + autoPaginate wiring keeps every
existing `fetch*Page` helper intact and avoids a `region.ts` ↔
`infrastructure.ts` import cycle (region resolution stays at the call
site).

## Changes

- `infrastructure.ts`: new exported `paginate<T>(options, fetchPage,
defaultLimit = 10)`.
- Migrated `listConversations` (default 10), `listReplays` (default 25),
`listTransactions` (default 10), `listSpans` (default 10).
- `fetch*Page` helpers unchanged — still usable for tests / one-off
calls, per the issue's scope.

## Tests

Added a focused `describe("paginate")` block in
`test/lib/api/infrastructure.test.ts`: per_page cap at
`API_MAX_PER_PAGE`, default-limit fallback, initial-cursor forwarding,
literal-limit passthrough below the cap, and multi-page accumulation up
to `limit`.

`vitest run` on the affected suites: **131 passed** (`infrastructure`,
`conversations`, `traces`, `replays`). Biome clean on the touched files.
Pre-existing `tsc` errors from missing generated SDK/docs files are
unrelated to this change.

Fixes getsentry#1473

---------

Co-authored-by: jared-outpost[bot] <jared-outpost[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant