Skip to content

fix: suppress baseline comparisons across statistics resets - #64

Merged
alexshapalov merged 3 commits into
pgrundev:mainfrom
DivyamTalwar:fix/reset-safe-baseline-comparisons
Oct 12, 2026
Merged

alexshapalov merged 3 commits into
pgrundev:mainfrom
DivyamTalwar:fix/reset-safe-baseline-comparisons

Conversation

@DivyamTalwar

Copy link
Copy Markdown
Contributor

What and why

Closes #61.

A detected statistics reset or server restart makes the two snapshots incomparable. The standalone diff path nevertheless calculated deltas, and the text renderer could print either those deltas or "nothing material changed" after its reset warning.

Reuse the existing StatsResetBetween contract in diff.Compute and stop rendering after the reset explanation. JSON retains its reset caveat and changes: []; ordinary comparisons and the independent eviction warning are preserved.

Verification

Verified commit: 0e9cecb8cafe087cdc5efc661c91ee067804dccb.

  • The new regression tests fail on base a1e6561e366455756c45a16a46647f882b3b6a1c for the reported behavior.
  • go test -race ./internal/diff ./internal/render ./cmd/pgbot -run 'TestCompute_|TestDiffReport_|TestResolveDiff_Reset' -count=20: passed.
  • Coverage includes the real SQLite snapshot store, offline resolver and CLI/MCP-shared JSON, first/later resets, restarts, comparable snapshots and text rendering.
  • bash scripts/gate.sh: passed on the committed HEAD, including build, vet, pinned lint, unit tests and six release-target builds.
  • go test -race ./...: passed; formatting and git diff --check are clean.
  • Additional identical-source-tree validation and dependency scanning: fork run. This commit changes author/message metadata only relative to that source tree.

Risk and rollback

The behavior changes only when the existing reset detector says comparison is unavailable. No PostgreSQL queries, dependencies, migrations or JSON field shapes change. Revert this commit to restore the previous behavior. The new store/JSON regression is database-independent; PostgreSQL-specific integration tests self-skip in the local suite.

Checklist

  • Committed-HEAD gate, full race tests and formatting pass.
  • Read-only and privacy invariants are unchanged.
  • JSON schema and finding catalog are unchanged.

Offline comparisons could expose cumulative deltas or report no material change after detecting a statistics reset or server restart. Apply the existing reset-suppression contract in Compute and terminate rendering after the unavailable-comparison explanation.

Regression coverage includes the real SQLite baseline store, CLI/MCP-shared JSON, first and later resets, restarts, normal comparisons and eviction notices. Existing JSON field shapes remain unchanged.

Closes pgrundev#61
alexshapalov pushed a commit that referenced this pull request Oct 12, 2026
The diff and advisor text renderers ignored their final write result, so a
broken destination could produce a successful command with missing output.
Return the original error, reject silent short writes, and propagate the
result through the actual Cobra handlers.

Tests exercise both command paths, real SQLite-backed diff history, large
and empty reports, reset-only output and successful output preservation.
The advisor collection seam supplies only the backend result. The original
diff command and a swallowed-error advisor control fail; focused tests
pass 20 race repetitions and full render/CLI race suites pass.

No SQL, dependencies or JSON contract changes. The separate reset branch in
PR #64 must propagate this same writer error when the changes are combined.
alexshapalov and others added 2 commits October 12, 2026 15:09
pgrundev#93 made DiffReport return the writer's error; the early return added here
for the reset case predates that and no longer compiled once both landed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@alexshapalov
alexshapalov merged commit b38f5e9 into pgrundev:main Oct 12, 2026
21 checks passed
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.

Offline diff presents reset-crossing snapshots as valid comparisons

2 participants