Skip to content

fix: mark incomplete run reports and refuse them in diff - #44

Merged
mickamy merged 8 commits into
mainfrom
fix/incomplete-reports
Nov 23, 2026
Merged

mickamy merged 8 commits into
mainfrom
fix/incomplete-reports

Conversation

@mickamy

@mickamy mickamy commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #43, addressing the Copilot review that arrived after it was merged. A run report that may have missed events is now written, marked incomplete, and refused by diff, so a partial measurement can no longer show up as a clean improvement.

Changes

fix: mark incomplete reports and reject them in diff

  • ci.Result.Incomplete / JSON incomplete (omitted when empty) holds why a measurement may have missed events. The text report shows an Incomplete: line.
  • run sets it when collection ends with ErrStreamEnded or ErrDrainLimit.
  • ci.Diff returns ErrIncompleteReport when either report is marked, and sql-tap diff exits 2. There is intentionally no override flag: incomplete numbers cannot serve as evidence. The report file is kept for diagnosis.
  • The JSON report has not been released yet (latest is v0.4.0), so the schema stays at version: 1.

fix(ci): do not report a stream end as early once stop is closed

  • When the command finished and the stream ended at the same moment, select could pick the end of stream first while stop was already closed, returning ErrStreamEnded and failing a complete measurement with exit 2.
  • The decision is extracted into streamEndErr, which checks whether stop is actually closed. It is unit-tested directly because the select ordering cannot be forced reliably from a test; the closed-stop case fails with the previous logic.

fix: write partial run reports marked incomplete on collection errors

  • A receive error such as gRPC Unavailable used to discard the captured events and return before writing any report, which could leave a stale -out file from an earlier run.
  • Watcher.Collect now returns the partial result with the error, and run writes the report marked incomplete for any collection error.
  • Exit code priority: the command's failure, then an incomplete measurement (2), then no statements (2), then problems (1).

Verification

  • go test -race ./... passes
  • golangci-lint run ./...: 0 issues
  • New regression tests fail against the previous implementation (streamEndErr closed-stop case, partial result on receive error)

Copilot AI balanced review requested due to automatic review settings November 23, 2026 00:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The stream termination logic can suppress cancellation or deadline errors when stop closes, causing interrupted measurements to be written unmarked and accepted by diff.

1 open issue
What changed in this PR

Follow-up to #43 that makes command measurements safer to compare: partial run reports are preserved for diagnosis, marked incomplete, and rejected by diff.

Changes:

  • Adds completeness metadata to results, JSON reports, and text output.
  • Preserves partial results on collection errors and rejects incomplete comparisons with exit code 2.
  • Adjusts simultaneous stop/stream-end handling and adds regression tests and documentation.
File Description
run.go Writes incomplete reports on collection errors and updates exit-code priority.
run_test.go Tests incomplete reports and replacement of stale output files.
README.md Documents incomplete measurements and comparison rejection.
diff.go Adds incomplete-report help and error guidance.
diff_test.go Tests CLI rejection of incomplete reports.
ci/​watcher.go Preserves partial results and adjusts stream-end handling.
ci/​watcher_internal_test.go Tests stop-state decisions and partial-result retention.
ci/​json.go Encodes and decodes completeness metadata.
ci/​json_test.go Includes completeness metadata in round-trip coverage.
ci/​diff.go Rejects comparisons when either report is incomplete.
ci/​diff_test.go Tests rejection of incomplete before and after reports.
ci/​ci.go Adds the incomplete reason and displays it in text reports.
ci/​ci_test.go Tests conditional display of the incomplete reason.

Review effort: Balanced

Comment thread ci/watcher.go Resolved
Copilot AI balanced review requested due to automatic review settings November 23, 2026 00:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical EOF/stop race in ci/watcher.go can silently allow diff to accept an incomplete report that omits the remaining SQL from the command.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread ci/watcher.go Resolved
Copilot AI balanced review requested due to automatic review settings November 23, 2026 00:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The test relies on a 50 ms sleep rather than explicit synchronization before closing stop, allowing goroutine scheduling to produce a nil endErr and intermittent failures.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread ci/watcher_internal_test.go Resolved
Copilot AI balanced review requested due to automatic review settings November 23, 2026 00:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because the documented report-writing guarantee conflicts with subscription-failure behavior and could lead users to trust a stale output file.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@mickamy

mickamy commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Re: the review summary note that a stale -out file could survive a subscription failure: fixed in 61ce961. run now removes the -out file right after parsing flags, before subscribing, so a run that fails before measuring (unreachable or old sql-tapd, command not found, usage error) never leaves an earlier report behind. The README states this.

Copilot AI balanced review requested due to automatic review settings November 23, 2026 01:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Deleting the existing report discards its permissions, potentially recreating a restricted 0600 file as 0644 and exposing SQL and command arguments to other users.

1 open issue

Review effort: Balanced

Comment thread run.go Resolved
Copilot AI balanced review requested due to automatic review settings November 23, 2026 01:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because flag-parsing failures can leave a stale report that a subsequent diff accepts, undermining the early-failure guarantee.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@mickamy

mickamy commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Re: the review summary note that a flag-parsing failure can leave a stale -out report: not addressing this one, intentionally.

  • A flag error exits 2 immediately with the usage text, so it is clear that nothing was measured. The guarantee in this PR targets measurements that may look complete while they are not; a wrong invocation is a different case.
  • flag stops at the first invalid flag, so an -out after it is never parsed and the target file is unknown. Truncating only when -out happened to be parsed would be a partial fix, and scanning the arguments ourselves risks diverging from flag's own parsing.

@mickamy
mickamy merged commit cb212e9 into main Nov 23, 2026
5 checks passed
@mickamy
mickamy deleted the fix/incomplete-reports branch November 23, 2026 01:12
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