Skip to content

fix(cli): Use the issues endpoint's filtered counts for release: queries - #1590

Merged
BYK merged 1 commit into
mainfrom
fix/issue-list-filtered-counts
Oct 22, 2026
Merged

BYK merged 1 commit into
mainfrom
fix/issue-list-filtered-counts

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #1512 and #1583.

#1512 fixed the counts sentry issue list --query 'release:"X"' displays: after building the listing, it refetches each issue's counts from the events endpoint. But in multi-project listings (DSN auto-detect, project search across orgs), the CLI merges the per-project results and trims them to --limit before that refetch runs. So --sort freq / --sort user picked the rows using period-wide counts. That could drop the issues with the most events in the release and keep ones that barely appear in it. The re-ranking afterwards only reorders rows that already survived the trim.

Root cause. The issues endpoint already returns release-scoped counts. StreamGroupSerializerSnuba builds conditions from the query's event-level search filters, and release isn't in skip_snuba_fields. When filtered isn't collapsed, it returns filtered.count / filtered.userCount computed with those conditions. The search executor's freq/user sort aggregates over the same filtered events. So each server page is already ordered by release-scoped counts. The CLI just never read those numbers, because buildIssueListCollapse always collapsed filtered.

Sentry sources checked: src/sentry/api/serializers/models/group_stream.py, group.py (GroupSerializerSnuba.__init__, SKIP_SNUBA_FIELDS), and src/sentry/search/snuba/executors.py (sort_strategies, aggregation_defs).

Change

  • buildIssueListCollapse gains shouldCollapseFiltered. It defaults to true, so other callers like feedback are unchanged.
  • When shouldScopeCounts is true (a release: filter, and the counts are shown or drive the sort), issue list stops collapsing filtered. It also keeps stats, because the server only returns filtered when stats aren't collapsed.
  • applyQueryScopedCounts copies filtered.count/filtered.userCount into count/userCount right after each fetch: per target, org-wide, and cursor resume. That happens before any merge, sort, or trim. It then drops filtered, so the --json output shape doesn't change.
  • Removes the per-issue events fan-out (issue-scoped-counts.ts, applyScopedCounts, and the project option on ExploreQueryOptions that only it used). That's one fewer request per listed issue.

Tests

  • test/commands/issue/list.test.ts:
    • collapse params with and without release:
    • filtered counts promoted into count/userCount, and filtered: null falling back to the top-level counts
    • --sort freq --fields id,title keeping stats
    • a multi-project --sort freq --limit 2 merge/trim regression test
  • The new tests fail on main (4 of 5; the no-release case passes either way) and pass with this change.
  • test/lib/issue-collapse.property.test.ts: a property test for shouldCollapseFiltered.

Verification

  • tsc --noEmit and pnpm run lint (oxlint + oxfmt): clean.
  • pnpm run test:unit: 11188 passed and 6 failed. All 6 failures are permission tests (EACCES/EPERM, read-only DB, unreadable files) in completions, telemetry, upgrade, code-scanner, and file-changes. The same 6 fail on unmodified main in this sandbox.
  • Not run: e2e tests and a live API check against a real org.

via BYK.

--

View Junior Session [Sentry]

`issue list --query 'release:"X"'` fixed its displayed counts in #1512 by
refetching each listed issue's counts from the events endpoint after the
listing was built. Multi-project listings merge and trim to `--limit`
before that step, so `--sort freq`/`--sort user` picked rows using
period-wide counts and could drop the issues that matter for the release.

The issues endpoint already computes counts scoped to the query's
event-level filters in its `filtered` block. The CLI always collapsed it.
Request `filtered` (and keep `stats`, which the server nests it under)
when the query has a `release:` filter. Promote those counts into
`count`/`userCount` right after each fetch, before any merge, sort, or
trim. This also removes the per-issue events fan-out
(`issue-scoped-counts.ts`).

Refs #1583

Co-Authored-By: Burak Yigit Kaya <burak.kaya@sentry.io>
@vercel

vercel Bot commented Oct 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Oct 22, 2026 10:57am UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 22, 2026
@BYK
BYK merged commit e983cc0 into main Oct 22, 2026
26 checks passed
@BYK
BYK deleted the fix/issue-list-filtered-counts branch October 22, 2026 11:20
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
…etsentry#1591)

Running a DSN-dependent command (e.g. `sentry issue list`) from `$HOME`,
or any directory without a project marker, made `findProjectRoot` fall
back to `$HOME` as the project root and then scan **downward** up to 3
levels with `hidden: true`. That walk reached OS app-data and credential
directories (`~/Library/Group Containers/…`, `~/.ssh`, `~/.aws`, …),
tripping security-monitoring alerts and opening sensitive files for the
8 KB content sniff.

This skips the downward code/env scan entirely when project root
resolves via `reason: "fallback"` to `$HOME` or an ancestor of it — only
the `SENTRY_DSN` env var is consulted in that case. As defence in depth,
OS app-data and common credential directories are also added to
`DSN_ADDITIONAL_SKIP_DIRS`.

## Testing
- `vitest run test/lib/dsn` (new `home-fallback.test.ts` + updated
project-root/scan-options tests pass; 2 pre-existing failures are
environmental — chmod-based tests that don't restrict `root`)
- `biome check` clean on changed files

Closes getsentry#1590

<!--
## Plan
Root cause:
- `getStopBoundary()` in project-root.ts is `homedir()`. From `$HOME`
with no VCS/language/build markers, `findProjectRoot` returns `{
projectRoot: $HOME, reason: "fallback" }`.
- `detectDsn`/`detectAllDsns` then run downward scans from `$HOME` with
`dsnScanOptions()` (`maxDepth: 3`, `hidden: true`). The skip list had no
OS/credential dirs, so the walk reached `~/Library/...` and
extensionless files under `~/.ssh`/`~/.aws` fell through to
`readHeadAndSniff`.

Changes:
1. project-root.ts — add exported `isHomeOrAncestor(dir)`: true when
`dir` resolves to home or an ancestor of home.
2. detector.ts — in both `detectDsn` and `detectAllDsns`, when `reason
=== "fallback" && isHomeOrAncestor(projectRoot)`, skip the filesystem
scan and return only `detectFromEnv()`. `detectAllDsns` reads `reason`
from both the cached root and the fresh walk.
3. scan/constants.ts — extend `DSN_ADDITIONAL_SKIP_DIRS` with Library,
AppData, .ssh, .gnupg, .aws, .azure, .kube, .docker, .password-store,
.gpg, .config, .local.

Tests: isHomeOrAncestor cases; skip-set assertions; new
home-fallback.test.ts mocking homedir to a temp dir.
-->

---------

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
…etsentry#1591)

Running a DSN-dependent command (e.g. `sentry issue list`) from `$HOME`,
or any directory without a project marker, made `findProjectRoot` fall
back to `$HOME` as the project root and then scan **downward** up to 3
levels with `hidden: true`. That walk reached OS app-data and credential
directories (`~/Library/Group Containers/…`, `~/.ssh`, `~/.aws`, …),
tripping security-monitoring alerts and opening sensitive files for the
8 KB content sniff.

This skips the downward code/env scan entirely when project root
resolves via `reason: "fallback"` to `$HOME` or an ancestor of it — only
the `SENTRY_DSN` env var is consulted in that case. As defence in depth,
OS app-data and common credential directories are also added to
`DSN_ADDITIONAL_SKIP_DIRS`.

## Testing
- `vitest run test/lib/dsn` (new `home-fallback.test.ts` + updated
project-root/scan-options tests pass; 2 pre-existing failures are
environmental — chmod-based tests that don't restrict `root`)
- `biome check` clean on changed files

Closes getsentry#1590

<!--
## Plan
Root cause:
- `getStopBoundary()` in project-root.ts is `homedir()`. From `$HOME`
with no VCS/language/build markers, `findProjectRoot` returns `{
projectRoot: $HOME, reason: "fallback" }`.
- `detectDsn`/`detectAllDsns` then run downward scans from `$HOME` with
`dsnScanOptions()` (`maxDepth: 3`, `hidden: true`). The skip list had no
OS/credential dirs, so the walk reached `~/Library/...` and
extensionless files under `~/.ssh`/`~/.aws` fell through to
`readHeadAndSniff`.

Changes:
1. project-root.ts — add exported `isHomeOrAncestor(dir)`: true when
`dir` resolves to home or an ancestor of home.
2. detector.ts — in both `detectDsn` and `detectAllDsns`, when `reason
=== "fallback" && isHomeOrAncestor(projectRoot)`, skip the filesystem
scan and return only `detectFromEnv()`. `detectAllDsns` reads `reason`
from both the cached root and the fresh walk.
3. scan/constants.ts — extend `DSN_ADDITIONAL_SKIP_DIRS` with Library,
AppData, .ssh, .gnupg, .aws, .azure, .kube, .docker, .password-store,
.gpg, .config, .local.

Tests: isHomeOrAncestor cases; skip-set assertions; new
home-fallback.test.ts mocking homedir to a temp dir.
-->

---------

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
…etsentry#1591)

Running a DSN-dependent command (e.g. `sentry issue list`) from `$HOME`,
or any directory without a project marker, made `findProjectRoot` fall
back to `$HOME` as the project root and then scan **downward** up to 3
levels with `hidden: true`. That walk reached OS app-data and credential
directories (`~/Library/Group Containers/…`, `~/.ssh`, `~/.aws`, …),
tripping security-monitoring alerts and opening sensitive files for the
8 KB content sniff.

This skips the downward code/env scan entirely when project root
resolves via `reason: "fallback"` to `$HOME` or an ancestor of it — only
the `SENTRY_DSN` env var is consulted in that case. As defence in depth,
OS app-data and common credential directories are also added to
`DSN_ADDITIONAL_SKIP_DIRS`.

## Testing
- `vitest run test/lib/dsn` (new `home-fallback.test.ts` + updated
project-root/scan-options tests pass; 2 pre-existing failures are
environmental — chmod-based tests that don't restrict `root`)
- `biome check` clean on changed files

Closes getsentry#1590

<!--
## Plan
Root cause:
- `getStopBoundary()` in project-root.ts is `homedir()`. From `$HOME`
with no VCS/language/build markers, `findProjectRoot` returns `{
projectRoot: $HOME, reason: "fallback" }`.
- `detectDsn`/`detectAllDsns` then run downward scans from `$HOME` with
`dsnScanOptions()` (`maxDepth: 3`, `hidden: true`). The skip list had no
OS/credential dirs, so the walk reached `~/Library/...` and
extensionless files under `~/.ssh`/`~/.aws` fell through to
`readHeadAndSniff`.

Changes:
1. project-root.ts — add exported `isHomeOrAncestor(dir)`: true when
`dir` resolves to home or an ancestor of home.
2. detector.ts — in both `detectDsn` and `detectAllDsns`, when `reason
=== "fallback" && isHomeOrAncestor(projectRoot)`, skip the filesystem
scan and return only `detectFromEnv()`. `detectAllDsns` reads `reason`
from both the cached root and the fresh walk.
3. scan/constants.ts — extend `DSN_ADDITIONAL_SKIP_DIRS` with Library,
AppData, .ssh, .gnupg, .aws, .azure, .kube, .docker, .password-store,
.gpg, .config, .local.

Tests: isHomeOrAncestor cases; skip-set assertions; new
home-fallback.test.ts mocking homedir to a temp dir.
-->

---------

Co-authored-by: jared-outpost[bot] <jared-outpost[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
Preview — 251fec4c Deployed Oct 22, 2026 by vercel[bot]
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