fix: 3 bug fixes — test env isolation, event pagination, pagination crash guard#947
Closed
cursor[bot] wants to merge 3 commits into
Closed
fix: 3 bug fixes — test env isolation, event pagination, pagination crash guard#947cursor[bot] wants to merge 3 commits into
cursor[bot] wants to merge 3 commits into
Conversation
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>
Contributor
Codecov Results 📊✅ 6856 passed | Total: 6856 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 35.29%. Project has 14050 uncovered lines. Files with missing lines (2)
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 |
Member
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
withTTYhelper incolors.test.tsonly saved/restoredSENTRY_PLAIN_OUTPUTandprocess.stdout.isTTY, but did not clearNO_COLORorFORCE_COLOR. In CI environments (or any shell withNO_COLORset),isPlainOutput()returnstrueat theNO_COLORcheck before reaching the TTY fallback, causingterminalLinkto return plain text.Reproduction: Run
NO_COLOR=1 bun test ./test/lib/formatters/colors.test.ts— twoterminalLinkTTY tests fail.Fix: Save/restore
NO_COLORandFORCE_COLORalongsideSENTRY_PLAIN_OUTPUTin thewithTTYhelper.2. fix(events): drop nextCursor when trimming listIssueEvents results
Root cause:
listIssueEvents()auto-paginates through the API and trims results tolimit. When trimming, it preservednextCursor— 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
listIssueEventswith alimitsmaller than the API page size for an issue with many events — subsequent-c nextnavigation skips events between the trim point and the next API page boundary.Fix: Drop
nextCursorwhen trimming, matching the existing correct behavior oflistIssuesAllPagesinissues.ts(lines 253-257).3. fix(pagination): guard JSON.parse of cursor_stack against corrupt data
Root cause:
getPaginationState()callsJSON.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 unhandledSyntaxError.Reproduction: Manually corrupt the
cursor_stackcolumn in thepagination_cursorstable, then run any command with--cursor next.Fix: Wrap
JSON.parsein try/catch. On failure, log a debug message, delete the corrupt row, and returnundefined— the user continues from a fresh first page instead of a hard crash.