Skip to content

fix: 3 bug fixes — test env isolation, event pagination, pagination crash guard#947

Closed
cursor[bot] wants to merge 3 commits into
mainfrom
cursor/sentry-cli-bug-fixes-7969
Closed

fix: 3 bug fixes — test env isolation, event pagination, pagination crash guard#947
cursor[bot] wants to merge 3 commits into
mainfrom
cursor/sentry-cli-bug-fixes-7969

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 11, 2026

Summary

Three independent bug fixes discovered through codebase analysis and test failure investigation.


1. fix(test): complete env isolation in terminalLink tests

Root cause: The withTTY helper in colors.test.ts only saved/restored SENTRY_PLAIN_OUTPUT and process.stdout.isTTY, but did not clear NO_COLOR or FORCE_COLOR. In CI environments (or any shell with NO_COLOR set), isPlainOutput() returns true at the NO_COLOR check before reaching the TTY fallback, causing terminalLink to return plain text.

Reproduction: Run NO_COLOR=1 bun test ./test/lib/formatters/colors.test.ts — two terminalLink TTY tests fail.

Fix: Save/restore NO_COLOR and FORCE_COLOR alongside SENTRY_PLAIN_OUTPUT in the withTTY helper.


2. fix(events): drop nextCursor when trimming listIssueEvents results

Root cause: listIssueEvents() auto-paginates through the API and trims results to limit. When trimming, it preserved nextCursor — but that cursor points to the next API page, skipping the un-trimmed tail of the current batch. This causes events to be lost during cursor-based pagination.

Reproduction: Call listIssueEvents with a limit smaller than the API page size for an issue with many events — subsequent -c next navigation skips events between the trim point and the next API page boundary.

Fix: Drop nextCursor when trimming, matching the existing correct behavior of listIssuesAllPages in issues.ts (lines 253-257).


3. fix(pagination): guard JSON.parse of cursor_stack against corrupt data

Root cause: getPaginationState() calls JSON.parse(row.cursor_stack) on data read from SQLite without a try/catch. If the stored JSON is corrupt (partial write, manual edit, incompatible migration), the CLI crashes with an unhandled SyntaxError.

Reproduction: Manually corrupt the cursor_stack column in the pagination_cursors table, then run any command with --cursor next.

Fix: Wrap JSON.parse in try/catch. On failure, log a debug message, delete the corrupt row, and return undefined — the user continues from a fresh first page instead of a hard crash.

Open in Web View Automation 

cursoragent and others added 3 commits May 11, 2026 12:13
The withTTY helper only saved/restored SENTRY_PLAIN_OUTPUT and isTTY,
but did not clear NO_COLOR or FORCE_COLOR. In environments where
NO_COLOR is set (e.g., CI), isPlainOutput() returns true before
reaching the TTY check, causing terminalLink to return plain text
and two tests to fail.

Save/restore NO_COLOR and FORCE_COLOR alongside SENTRY_PLAIN_OUTPUT
so the tests exercise the actual OSC 8 code path regardless of
the outer environment.

Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
When auto-paginating issue events and the accumulated results exceed
the requested limit, the function trimmed the array but preserved
nextCursor. That cursor points to the next API page, skipping the
untrimmed tail of the current batch — causing events to be lost
during cursor-based pagination.

Drop nextCursor when trimming, matching the existing behavior of
listIssuesAllPages in issues.ts which correctly returns no cursor
when results are trimmed.

Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
getPaginationState() calls JSON.parse on cursor_stack from SQLite
without a try/catch. If the stored JSON is corrupt (partial write,
manual edit, incompatible migration), the CLI crashes with an
unhandled SyntaxError instead of degrading gracefully.

Wrap JSON.parse in try/catch. On parse failure, log a debug message,
delete the corrupt row, and return undefined (treating it as no
saved state). This lets the user continue navigating from a fresh
first page rather than being stuck with a hard crash.

Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

Codecov Results 📊

6856 passed | Total: 6856 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 35.29%. Project has 14050 uncovered lines.
✅ Project coverage is 76.97%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
src/lib/db/pagination.ts 50.00% ⚠️ 6 Missing
src/lib/api/events.ts 0.00% ⚠️ 5 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    76.97%    76.97%        —%
==========================================
  Files          319       319         —
  Lines        60994     61003        +9
  Branches         0         0         —
==========================================
+ Hits         46947     46953        +6
- Misses       14047     14050        +3
- Partials         0         0         —

Generated by Codecov Action

@BYK
Copy link
Copy Markdown
Member

BYK commented Jun 3, 2026

Superseded by #1051, which consolidates the genuinely-needed, de-duplicated fixes from this PR (rebased onto current main) along with the others. Closing in favor of #1051.

@BYK BYK closed this Jun 3, 2026
BYK added a commit that referenced this pull request Jun 3, 2026
Address Cursor BugBot (high severity): the previous fix dropped nextCursor on
overshoot, which stranded every event past the first page — 'sentry issue
events' could only ever show the first --limit events.

Cap page size with per_page = min(limit, API_MAX_PER_PAGE) (Sentry accepts
per_page on this route at runtime though it's absent from the OpenAPI spec) so
the server cursor is page-aligned and never overshoots. Trim defensively to
limit but PRESERVE nextCursor: the events cursor is offset-based, so resuming
re-includes any trimmed tail instead of skipping it, and -c next can advance.

This resolves both the original skip bug (#947) and the stall regression.
Update tests to assert per_page is sent (capped at 100) and the cursor is
preserved on overshoot.
BYK added a commit that referenced this pull request Jun 3, 2026
…1051)

## Summary

Consolidates the five open Cursor BugBot PRs (#908, #947, #973, #1023,
#1044)
into a single, de-duplicated, rebased PR. Each genuinely-needed fix is
verified
against current `main`; overlapping fixes use the best variant; stale
and
subjective changes are dropped.

## Why consolidate

The five BugBot PRs heavily overlapped and had gone stale (7–113 commits
behind
`main`): the cache `JSON.parse` guard appeared 3×, the `withTTY` test
fix 2×, the
pagination guard 3×. Several also failed CI only on unrelated base
drift. This PR
lands the real fixes once and adds guardrails so the
duplication/staleness
doesn't recur.

## Fixes included

**Cache hardening** (`fix(db)`) — from #908/#947/#1044
- New `safeParseJson()` db helper; used in `getPaginationState()` (with
`Array.isArray` validation) and `getCachedDetection()` so corrupt cached
JSON
  is a cache miss, not a crash.
- `log.debug()` added to three silent catch blocks in
`sentry-client.ts`.

**Event pagination** (`fix(events)`) — from #947
- `listIssueEvents` now uses the shared `autoPaginate()` helper and
drops
`nextCursor` when a page overshoots `limit`, so `-c next` never skips
events.
Adds a property test for the `autoPaginate` trim-drops-cursor invariant
plus a
  focused overshoot regression test.

**Relative time** (`fix(formatters)`) — from #1044
- `formatRelativeTime` clamps `diffMs` to `>= 0` ("0m ago" instead of
"-5m ago").

**Seer** (`fix(seer)`) — from #973/#1023, relates to #958
- `normalizeAgentStatus` maps `canceled`/`cancelled` → `CANCELLED`
(fixes a
polling-timeout bug) and `need_more_information` →
`NEED_MORE_INFORMATION`.
- `searchContainersForRootCauses` requires `causes.length > 0` so an
empty
  legacy array no longer blocks the agent-artifact fallthrough.
- `extractNoSolutionReason` reads the step-level `description` (current
API)
  before the artifact-level `reason` (legacy).

**Release set-commits** (`fix(release)`) — from #1023
- Narrow the default-mode 400 fallback to the exact
`NO_REPO_INTEGRATIONS_MESSAGE`
so unrelated 400s (invalid refs, bad release state) propagate instead of
being
  masked as "no integration".

**Test isolation** (`test`) — from #1044/#947
- `withTTY` now saves/restores `NO_COLOR` and `FORCE_COLOR` (CI sets
`NO_COLOR=1`).

## Systemic guardrails

- `script/check-error-patterns.ts` gains an advisory silent-catch scan
  (`SENTRY_STRICT_SILENT_CATCH=1` to enforce).
- `AGENTS.md` documents automated-fix-PR rules: check existing
PRs/issues first,
rebase before review, separate correctness from opinion, prefer shared
helpers.
- Removed a stale, now-unused `biome-ignore` in `formatters/local.ts`
that broke
  repo-wide lint under biome 2.3.8.

## Dropped (intentionally)

- **`issue list` "lifetime" collapse removal** (#973) — superseded on
`main` by
  the `shouldCollapseLifetime` param; issue #969 is already closed.
- **Issue selector hint `is:resolved` → bare list** (#1023) — subjective
UX;
  `main`'s current behavior is deliberate.

## Follow-up

- A scheduled stale-bot to auto-close inactive bot PRs (out of scope
here).

## Testing

- `pnpm run typecheck` ✓
- `pnpm run lint` ✓ (766 files)
- `pnpm run check:errors` ✓ · `pnpm run check:deps` ✓
- `pnpm run test:unit` ✓ (325 files, 7419 passed, 13 skipped)

Closes #908, #947, #973, #1023, #1044.
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