Skip to content

chore: implement phase 7 - #2785

Merged
Tofel merged 4 commits into
dx-5122-alerts-assertion-p6from
dx-5122-alerts-assertion-p7
Sep 9, 2026
Merged

chore: implement phase 7#2785
Tofel merged 4 commits into
dx-5122-alerts-assertion-p6from
dx-5122-alerts-assertion-p7

Conversation

@Tofel

@Tofel Tofel commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Implements proveCoverage (invariant H3) — the pure coverage function: nine checks over one rule's polls (sentinel, from-bounds, heartbeat continuity, health error/nodata, liveness, pause, absence, KeepLast). Liveness is absolute, never a delta; cross-domain comparisons translate by each poll's own skew.

Review focus: coverage.go — the nine checks and the fail-closed skew translation.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

⚠️ API Diff Results - github.com/smartcontractkit/chainlink-testing-framework/grafana-alertcheck

⚠️ Breaking Changes (1)

package github (1)
  • com/smartcontractkit/chainlink-testing-framework/grafana-alertcheck/cmd/grafana-alertcheck — 🗑️ Removed

✅ Compatible Changes (1)

package github (1)
  • com/smartcontractkit/chainlink-testing-framework/grafana-alertcheck/cmd — ➕ Added

📄 View full apidiff report

@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p6 branch from c1f0275 to a68bc90 Compare September 1, 2026 11:25
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p7 branch 2 times, most recently from 3335384 to ea5360b Compare September 1, 2026 14:18
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p6 branch from a68bc90 to 2bbb84b Compare September 1, 2026 14:18
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p7 branch from ea5360b to 4b763aa Compare September 1, 2026 14:46
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p6 branch from 2bbb84b to 4161182 Compare September 1, 2026 14:46
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p7 branch from 4b763aa to ac47c19 Compare September 1, 2026 15:25
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p6 branch from 4161182 to 2b64acf Compare September 1, 2026 15:25
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p7 branch from ac47c19 to 71d8038 Compare September 2, 2026 09:45
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p6 branch 2 times, most recently from 07d2fb9 to c7a6144 Compare September 4, 2026 15:03
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p7 branch from f1b13d6 to b37a4b9 Compare September 4, 2026 15:03
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p6 branch from c7a6144 to eabba1c Compare September 4, 2026 15:15
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p7 branch from b37a4b9 to 2853a5d Compare September 4, 2026 15:15
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p6 branch from eabba1c to 2f15034 Compare September 7, 2026 09:35
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p7 branch from 2853a5d to b022005 Compare September 7, 2026 09:35
@Tofel
Tofel marked this pull request as ready for review September 7, 2026 09:36
@Tofel
Tofel requested a review from a team as a code owner September 7, 2026 09:36
Copilot AI lite review requested due to automatic review settings September 7, 2026 09:36

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 new coverage logic has confirmed fail-open edge cases under corrupted log data (e.g., negative skew bounds and future lastEvaluation) that should be handled explicitly before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adds the “pure coverage” evaluation layer (proveCoverage) for Grafana alert rule polling, implementing invariant H3 via nine ordered checks over a single rule’s poll stream. It’s designed to be deterministic and side-effect-free, enabling tight unit testing and keeping I/O (HTTP/log reads) out of the coverage decision path.

Changes:

  • Introduces proveCoverage and helper functions to compute window membership, heartbeat gaps, health runs, liveness (absolute staleness), pause/absence detection, and KeepLast notes.
  • Defines CoverageResult + UnobservableReason vocabulary to produce machine-readable coverage outcomes with human diagnostics.
  • Adds a comprehensive unit test suite covering all nine checks, skew translation behavior, multi-failure ordering, and timing derivation round-trip behavior.
File summaries
File Description
grafana-alertcheck/internal/gate/coverage.go Implements the pure per-rule coverage proof function and its helper routines.
grafana-alertcheck/internal/gate/coverage_test.go Adds extensive tests pinning expected behavior for each coverage check and key edge cases.
Review details

Suppressed comments (1)

grafana-alertcheck/internal/gate/coverage.go:302

  • ruleHeartbeatGap widens boundary segments by p.SkewBound(), but SkewBoundMS is read from logs without validation (ReadLog is deliberately “crudest possible”). If a corrupted/hand-edited log contains a negative skew_bound_ms, adding it here would shrink the boundary gap (fail-open) instead of widening it. Consider normalizing the bound to a non-negative value before using it in the boundary-gap math.
	runnerOf := func(p Poll) time.Time { return p.GrafanaNow.Add(-p.Skew()) }

	first := in[0]
	if gap := runnerOf(first).Sub(from) + first.SkewBound(); gap > largestGap {
		largestGap, largestGapAt = gap, from
	}
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread grafana-alertcheck/internal/gate/coverage.go
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p7 branch from b022005 to 9d3c68c Compare September 7, 2026 09:46
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p6 branch from 2f15034 to 91e12a3 Compare September 7, 2026 09:46
Invariant defended: H3. The one question: can a rule be called alive
because it looked alive one poll ago?

proveCoverage (grafana-alertcheck/internal/gate/coverage.go) is the pure
coverage function: nine checks over one rule's polls — sentinel,
from-bounds, heartbeat continuity, health error/nodata, liveness,
in-window pause, rule absence, KeepLast. Liveness is absolute, never a
delta. Cross-domain comparisons translate by each poll's own skew and
widen boundary segments by its skew bound, fail-closed.
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p7 branch from 9d3c68c to 82dc549 Compare September 7, 2026 15:02
@Tofel
Tofel force-pushed the dx-5122-alerts-assertion-p6 branch from 91e12a3 to 155f65e Compare September 7, 2026 15:02
@Tofel
Tofel removed this pull request from stack #2791 September 9, 2026 09:52
@Tofel Tofel closed this Sep 9, 2026
* chore: implement phase 8

Invariant defended: H6/H7. The one question: can a violation ever
outrank an unobservable rule, or can a pass happen without
Violations empty and err nil?

Adds classify.go: the pure per-instance classifier (outcome table,
preexisting policy, BadFor) and decide(), the seam combining
proveCoverage with those timelines under one Policy. Consolidates
rule-poll filtering and skew translation onto pollsForRule/runnerTime,
shared with coverage.go.

* chore: rename some vars + add unit tests

* chore: address code review comments

* chore: implement phase 9 (#2787)

* chore: implement phase 9

Invariant defended: H5/H7. The one question: can check report a pass
over a window it did not prove?

Check() is the I/O shell around the pure decide(). Single-step
synthesizes the header and its own sentinel, so no mode flag reaches
the pure layer. Log mode stops the recorder before the one full read.

The header, not a definition re-resolved after the window closed, is
the authority for what was paused when the window opened — it decides
`skipped`, the drain set, and the transitionGrace max. The flock, not
the pidfile, is the authority for whether a writer still exists.

* chore: remove unix build tag

* chore: implement phase 10 (#2788)

* Wire watch/check subcommands to the gate library, with a table+JSON
renderer and H6/H7 exit-code mapping. Extend Result with per-rule/global
thresholds and a real skew bound; export SkewHardLimit; reject --states
normal.

* chore: fix goreleaser.yaml and add version command

* chore: implement phase 11 (#2789)

* chore: implement phase 11

Add coverage.go's declared-KeepLast check (no_data_state/exec_err_state,
not just an observed reason) and close the remaining §22 gaps: newly_bad's
no-early-exit clock assertion, a recorder-mode gap right after the deploy,
a rule's own coverage gap overriding its own recovery, a genuinely
skew-discriminating staleness test, exit-2 consequences on two
Reason-only coverage tests, and end-to-end checks for log-name
collapse, a truncated log, and the real watch-written state histogram.

* chore: address code review comments

* chore: more concise comments (#2790)

* chore: more concise comments

* fix: merge conflict

* chore: shorten comments

* fix: resolve conflict

* chore: use testify's require in tests (#2792)

* chore: use testify's require in tests

* chore: move remaining assumptions to testify

* chore: address code review comments

* chore: fix logging and std out printing (#2798)

* chore: fix logging and std out printing

* chore: truncate to seconds when comparing from time

* chore: add centralized docs (#2802)

* chore: add centralized docs

* chore: further update docs

* chore: address code review comments (#2807)

* chore: address code review comments

* chore: get rid of goreleaser
@Tofel Tofel reopened this Sep 9, 2026
@Tofel
Tofel merged commit 90b21f3 into dx-5122-alerts-assertion-p6 Sep 9, 2026
42 of 57 checks passed
@Tofel
Tofel deleted the dx-5122-alerts-assertion-p7 branch September 9, 2026 09:59
Tofel added a commit that referenced this pull request Sep 9, 2026
* chore: implement phase 6

Invariant defended: H2. The one question: can watch return success over a
window that nothing is recording?

Watch() records the first observation of each non-skipped rule, then detaches
a child that polls at the cadence in the header. The parent returns only after
the child reports ready on an inherited pipe, and writes the pidfile after
that. A clean stop writes the sentinel; a hard error does not.

* chore: add a unit test, remove build tags

* chore: address code review comments

* chore: implement phase 7 (#2785)

* chore: implement phase 7

Invariant defended: H3. The one question: can a rule be called alive
because it looked alive one poll ago?

proveCoverage (grafana-alertcheck/internal/gate/coverage.go) is the pure
coverage function: nine checks over one rule's polls — sentinel,
from-bounds, heartbeat continuity, health error/nodata, liveness,
in-window pause, rule absence, KeepLast. Liveness is absolute, never a
delta. Cross-domain comparisons translate by each poll's own skew and
widen boundary segments by its skew bound, fail-closed.

* chore: enhance unit tests

* chore: address code review comments

* chore: implement phase 8 (#2786)

* chore: implement phase 8

Invariant defended: H6/H7. The one question: can a violation ever
outrank an unobservable rule, or can a pass happen without
Violations empty and err nil?

Adds classify.go: the pure per-instance classifier (outcome table,
preexisting policy, BadFor) and decide(), the seam combining
proveCoverage with those timelines under one Policy. Consolidates
rule-poll filtering and skew translation onto pollsForRule/runnerTime,
shared with coverage.go.

* chore: rename some vars + add unit tests

* chore: address code review comments

* chore: implement phase 9 (#2787)

* chore: implement phase 9

Invariant defended: H5/H7. The one question: can check report a pass
over a window it did not prove?

Check() is the I/O shell around the pure decide(). Single-step
synthesizes the header and its own sentinel, so no mode flag reaches
the pure layer. Log mode stops the recorder before the one full read.

The header, not a definition re-resolved after the window closed, is
the authority for what was paused when the window opened — it decides
`skipped`, the drain set, and the transitionGrace max. The flock, not
the pidfile, is the authority for whether a writer still exists.

* chore: remove unix build tag

* chore: implement phase 10 (#2788)

* Wire watch/check subcommands to the gate library, with a table+JSON
renderer and H6/H7 exit-code mapping. Extend Result with per-rule/global
thresholds and a real skew bound; export SkewHardLimit; reject --states
normal.

* chore: fix goreleaser.yaml and add version command

* chore: implement phase 11 (#2789)

* chore: implement phase 11

Add coverage.go's declared-KeepLast check (no_data_state/exec_err_state,
not just an observed reason) and close the remaining §22 gaps: newly_bad's
no-early-exit clock assertion, a recorder-mode gap right after the deploy,
a rule's own coverage gap overriding its own recovery, a genuinely
skew-discriminating staleness test, exit-2 consequences on two
Reason-only coverage tests, and end-to-end checks for log-name
collapse, a truncated log, and the real watch-written state histogram.

* chore: address code review comments

* chore: more concise comments (#2790)

* chore: more concise comments

* fix: merge conflict

* chore: shorten comments

* fix: resolve conflict

* chore: use testify's require in tests (#2792)

* chore: use testify's require in tests

* chore: move remaining assumptions to testify

* chore: address code review comments

* chore: fix logging and std out printing (#2798)

* chore: fix logging and std out printing

* chore: truncate to seconds when comparing from time

* chore: add centralized docs (#2802)

* chore: add centralized docs

* chore: further update docs

* chore: address code review comments (#2807)

* chore: address code review comments

* chore: get rid of goreleaser
Tofel added a commit that referenced this pull request Sep 9, 2026
* chore: implement phase 5

Add the JSONL evidence log (P5).

- log.go: Header/Poll records, reduction, H2 transition markers,
  §3.2 verification, append-only Writer with flock, ReadLog
- flock_unix.go: non-blocking exclusive lock, unix only
- schedule.go: DeriveTimingsFromLog — log-mode cadence comes from the
  header, never from the definitions

* chore: remove unix build tags

* chore: address code review comments

* chore: implement phase 6 (#2784)

* chore: implement phase 6

Invariant defended: H2. The one question: can watch return success over a
window that nothing is recording?

Watch() records the first observation of each non-skipped rule, then detaches
a child that polls at the cadence in the header. The parent returns only after
the child reports ready on an inherited pipe, and writes the pidfile after
that. A clean stop writes the sentinel; a hard error does not.

* chore: add a unit test, remove build tags

* chore: address code review comments

* chore: implement phase 7 (#2785)

* chore: implement phase 7

Invariant defended: H3. The one question: can a rule be called alive
because it looked alive one poll ago?

proveCoverage (grafana-alertcheck/internal/gate/coverage.go) is the pure
coverage function: nine checks over one rule's polls — sentinel,
from-bounds, heartbeat continuity, health error/nodata, liveness,
in-window pause, rule absence, KeepLast. Liveness is absolute, never a
delta. Cross-domain comparisons translate by each poll's own skew and
widen boundary segments by its skew bound, fail-closed.

* chore: enhance unit tests

* chore: address code review comments

* chore: implement phase 8 (#2786)

* chore: implement phase 8

Invariant defended: H6/H7. The one question: can a violation ever
outrank an unobservable rule, or can a pass happen without
Violations empty and err nil?

Adds classify.go: the pure per-instance classifier (outcome table,
preexisting policy, BadFor) and decide(), the seam combining
proveCoverage with those timelines under one Policy. Consolidates
rule-poll filtering and skew translation onto pollsForRule/runnerTime,
shared with coverage.go.

* chore: rename some vars + add unit tests

* chore: address code review comments

* chore: implement phase 9 (#2787)

* chore: implement phase 9

Invariant defended: H5/H7. The one question: can check report a pass
over a window it did not prove?

Check() is the I/O shell around the pure decide(). Single-step
synthesizes the header and its own sentinel, so no mode flag reaches
the pure layer. Log mode stops the recorder before the one full read.

The header, not a definition re-resolved after the window closed, is
the authority for what was paused when the window opened — it decides
`skipped`, the drain set, and the transitionGrace max. The flock, not
the pidfile, is the authority for whether a writer still exists.

* chore: remove unix build tag

* chore: implement phase 10 (#2788)

* Wire watch/check subcommands to the gate library, with a table+JSON
renderer and H6/H7 exit-code mapping. Extend Result with per-rule/global
thresholds and a real skew bound; export SkewHardLimit; reject --states
normal.

* chore: fix goreleaser.yaml and add version command

* chore: implement phase 11 (#2789)

* chore: implement phase 11

Add coverage.go's declared-KeepLast check (no_data_state/exec_err_state,
not just an observed reason) and close the remaining §22 gaps: newly_bad's
no-early-exit clock assertion, a recorder-mode gap right after the deploy,
a rule's own coverage gap overriding its own recovery, a genuinely
skew-discriminating staleness test, exit-2 consequences on two
Reason-only coverage tests, and end-to-end checks for log-name
collapse, a truncated log, and the real watch-written state histogram.

* chore: address code review comments

* chore: more concise comments (#2790)

* chore: more concise comments

* fix: merge conflict

* chore: shorten comments

* fix: resolve conflict

* chore: use testify's require in tests (#2792)

* chore: use testify's require in tests

* chore: move remaining assumptions to testify

* chore: address code review comments

* chore: fix logging and std out printing (#2798)

* chore: fix logging and std out printing

* chore: truncate to seconds when comparing from time

* chore: add centralized docs (#2802)

* chore: add centralized docs

* chore: further update docs

* chore: address code review comments (#2807)

* chore: address code review comments

* chore: get rid of goreleaser
Tofel added a commit that referenced this pull request Sep 9, 2026
* chore: implement phase 4

Add per-rule poll timings, scheduler, and budget check (P4).

- schedule.go: DeriveTimings, Scheduler, CheckBudget (§5)
- Address review: add Folder/Title resolve test, rename
  CheckBudget's minPollEvery to tightestUID

* chore: enhance unit tests

* chore: address code review comments

* chore: implement phase 5 (#2783)

* chore: implement phase 5

Add the JSONL evidence log (P5).

- log.go: Header/Poll records, reduction, H2 transition markers,
  §3.2 verification, append-only Writer with flock, ReadLog
- flock_unix.go: non-blocking exclusive lock, unix only
- schedule.go: DeriveTimingsFromLog — log-mode cadence comes from the
  header, never from the definitions

* chore: remove unix build tags

* chore: address code review comments

* chore: implement phase 6 (#2784)

* chore: implement phase 6

Invariant defended: H2. The one question: can watch return success over a
window that nothing is recording?

Watch() records the first observation of each non-skipped rule, then detaches
a child that polls at the cadence in the header. The parent returns only after
the child reports ready on an inherited pipe, and writes the pidfile after
that. A clean stop writes the sentinel; a hard error does not.

* chore: add a unit test, remove build tags

* chore: address code review comments

* chore: implement phase 7 (#2785)

* chore: implement phase 7

Invariant defended: H3. The one question: can a rule be called alive
because it looked alive one poll ago?

proveCoverage (grafana-alertcheck/internal/gate/coverage.go) is the pure
coverage function: nine checks over one rule's polls — sentinel,
from-bounds, heartbeat continuity, health error/nodata, liveness,
in-window pause, rule absence, KeepLast. Liveness is absolute, never a
delta. Cross-domain comparisons translate by each poll's own skew and
widen boundary segments by its skew bound, fail-closed.

* chore: enhance unit tests

* chore: address code review comments

* chore: implement phase 8 (#2786)

* chore: implement phase 8

Invariant defended: H6/H7. The one question: can a violation ever
outrank an unobservable rule, or can a pass happen without
Violations empty and err nil?

Adds classify.go: the pure per-instance classifier (outcome table,
preexisting policy, BadFor) and decide(), the seam combining
proveCoverage with those timelines under one Policy. Consolidates
rule-poll filtering and skew translation onto pollsForRule/runnerTime,
shared with coverage.go.

* chore: rename some vars + add unit tests

* chore: address code review comments

* chore: implement phase 9 (#2787)

* chore: implement phase 9

Invariant defended: H5/H7. The one question: can check report a pass
over a window it did not prove?

Check() is the I/O shell around the pure decide(). Single-step
synthesizes the header and its own sentinel, so no mode flag reaches
the pure layer. Log mode stops the recorder before the one full read.

The header, not a definition re-resolved after the window closed, is
the authority for what was paused when the window opened — it decides
`skipped`, the drain set, and the transitionGrace max. The flock, not
the pidfile, is the authority for whether a writer still exists.

* chore: remove unix build tag

* chore: implement phase 10 (#2788)

* Wire watch/check subcommands to the gate library, with a table+JSON
renderer and H6/H7 exit-code mapping. Extend Result with per-rule/global
thresholds and a real skew bound; export SkewHardLimit; reject --states
normal.

* chore: fix goreleaser.yaml and add version command

* chore: implement phase 11 (#2789)

* chore: implement phase 11

Add coverage.go's declared-KeepLast check (no_data_state/exec_err_state,
not just an observed reason) and close the remaining §22 gaps: newly_bad's
no-early-exit clock assertion, a recorder-mode gap right after the deploy,
a rule's own coverage gap overriding its own recovery, a genuinely
skew-discriminating staleness test, exit-2 consequences on two
Reason-only coverage tests, and end-to-end checks for log-name
collapse, a truncated log, and the real watch-written state histogram.

* chore: address code review comments

* chore: more concise comments (#2790)

* chore: more concise comments

* fix: merge conflict

* chore: shorten comments

* fix: resolve conflict

* chore: use testify's require in tests (#2792)

* chore: use testify's require in tests

* chore: move remaining assumptions to testify

* chore: address code review comments

* chore: fix logging and std out printing (#2798)

* chore: fix logging and std out printing

* chore: truncate to seconds when comparing from time

* chore: add centralized docs (#2802)

* chore: add centralized docs

* chore: further update docs

* chore: address code review comments (#2807)

* chore: address code review comments

* chore: get rid of goreleaser
Tofel added a commit that referenced this pull request Sep 9, 2026
* chore: implement phase 3

Add Resolve() for alert name resolution (uid:/Title/Folder/Title/
Folder/Group/Title forms, UID collapse, no-match suggestions) and the
grafana-alertcheck CLI's list subcommand, the first runnable piece of
the gate.

Incorporates review fixes: reject empty path segments in classifyForm,
guard uid: against an empty suffix, scope the no-match rule count and
suggestions to supported rule kinds only, and exit 0 on -h/--help.

* chore: enhance unit tests

* chore: implement phase 4 (#2782)

* chore: implement phase 4

Add per-rule poll timings, scheduler, and budget check (P4).

- schedule.go: DeriveTimings, Scheduler, CheckBudget (§5)
- Address review: add Folder/Title resolve test, rename
  CheckBudget's minPollEvery to tightestUID

* chore: enhance unit tests

* chore: address code review comments

* chore: implement phase 5 (#2783)

* chore: implement phase 5

Add the JSONL evidence log (P5).

- log.go: Header/Poll records, reduction, H2 transition markers,
  §3.2 verification, append-only Writer with flock, ReadLog
- flock_unix.go: non-blocking exclusive lock, unix only
- schedule.go: DeriveTimingsFromLog — log-mode cadence comes from the
  header, never from the definitions

* chore: remove unix build tags

* chore: address code review comments

* chore: implement phase 6 (#2784)

* chore: implement phase 6

Invariant defended: H2. The one question: can watch return success over a
window that nothing is recording?

Watch() records the first observation of each non-skipped rule, then detaches
a child that polls at the cadence in the header. The parent returns only after
the child reports ready on an inherited pipe, and writes the pidfile after
that. A clean stop writes the sentinel; a hard error does not.

* chore: add a unit test, remove build tags

* chore: address code review comments

* chore: implement phase 7 (#2785)

* chore: implement phase 7

Invariant defended: H3. The one question: can a rule be called alive
because it looked alive one poll ago?

proveCoverage (grafana-alertcheck/internal/gate/coverage.go) is the pure
coverage function: nine checks over one rule's polls — sentinel,
from-bounds, heartbeat continuity, health error/nodata, liveness,
in-window pause, rule absence, KeepLast. Liveness is absolute, never a
delta. Cross-domain comparisons translate by each poll's own skew and
widen boundary segments by its skew bound, fail-closed.

* chore: enhance unit tests

* chore: address code review comments

* chore: implement phase 8 (#2786)

* chore: implement phase 8

Invariant defended: H6/H7. The one question: can a violation ever
outrank an unobservable rule, or can a pass happen without
Violations empty and err nil?

Adds classify.go: the pure per-instance classifier (outcome table,
preexisting policy, BadFor) and decide(), the seam combining
proveCoverage with those timelines under one Policy. Consolidates
rule-poll filtering and skew translation onto pollsForRule/runnerTime,
shared with coverage.go.

* chore: rename some vars + add unit tests

* chore: address code review comments

* chore: implement phase 9 (#2787)

* chore: implement phase 9

Invariant defended: H5/H7. The one question: can check report a pass
over a window it did not prove?

Check() is the I/O shell around the pure decide(). Single-step
synthesizes the header and its own sentinel, so no mode flag reaches
the pure layer. Log mode stops the recorder before the one full read.

The header, not a definition re-resolved after the window closed, is
the authority for what was paused when the window opened — it decides
`skipped`, the drain set, and the transitionGrace max. The flock, not
the pidfile, is the authority for whether a writer still exists.

* chore: remove unix build tag

* chore: implement phase 10 (#2788)

* Wire watch/check subcommands to the gate library, with a table+JSON
renderer and H6/H7 exit-code mapping. Extend Result with per-rule/global
thresholds and a real skew bound; export SkewHardLimit; reject --states
normal.

* chore: fix goreleaser.yaml and add version command

* chore: implement phase 11 (#2789)

* chore: implement phase 11

Add coverage.go's declared-KeepLast check (no_data_state/exec_err_state,
not just an observed reason) and close the remaining §22 gaps: newly_bad's
no-early-exit clock assertion, a recorder-mode gap right after the deploy,
a rule's own coverage gap overriding its own recovery, a genuinely
skew-discriminating staleness test, exit-2 consequences on two
Reason-only coverage tests, and end-to-end checks for log-name
collapse, a truncated log, and the real watch-written state histogram.

* chore: address code review comments

* chore: more concise comments (#2790)

* chore: more concise comments

* fix: merge conflict

* chore: shorten comments

* fix: resolve conflict

* chore: use testify's require in tests (#2792)

* chore: use testify's require in tests

* chore: move remaining assumptions to testify

* chore: address code review comments

* chore: fix logging and std out printing (#2798)

* chore: fix logging and std out printing

* chore: truncate to seconds when comparing from time

* chore: add centralized docs (#2802)

* chore: add centralized docs

* chore: further update docs

* chore: address code review comments (#2807)

* chore: address code review comments

* chore: get rid of goreleaser
Tofel added a commit that referenced this pull request Sep 9, 2026
* chore: implement phase 2

Fix retry-error conflation, measure full poll latency, and harden Source test doubles for concurrency.

* chore: enhance unit tests

* chore: address code review comments

* chore: implement phase 3 (#2781)

* chore: implement phase 3

Add Resolve() for alert name resolution (uid:/Title/Folder/Title/
Folder/Group/Title forms, UID collapse, no-match suggestions) and the
grafana-alertcheck CLI's list subcommand, the first runnable piece of
the gate.

Incorporates review fixes: reject empty path segments in classifyForm,
guard uid: against an empty suffix, scope the no-match rule count and
suggestions to supported rule kinds only, and exit 0 on -h/--help.

* chore: enhance unit tests

* chore: implement phase 4 (#2782)

* chore: implement phase 4

Add per-rule poll timings, scheduler, and budget check (P4).

- schedule.go: DeriveTimings, Scheduler, CheckBudget (§5)
- Address review: add Folder/Title resolve test, rename
  CheckBudget's minPollEvery to tightestUID

* chore: enhance unit tests

* chore: address code review comments

* chore: implement phase 5 (#2783)

* chore: implement phase 5

Add the JSONL evidence log (P5).

- log.go: Header/Poll records, reduction, H2 transition markers,
  §3.2 verification, append-only Writer with flock, ReadLog
- flock_unix.go: non-blocking exclusive lock, unix only
- schedule.go: DeriveTimingsFromLog — log-mode cadence comes from the
  header, never from the definitions

* chore: remove unix build tags

* chore: address code review comments

* chore: implement phase 6 (#2784)

* chore: implement phase 6

Invariant defended: H2. The one question: can watch return success over a
window that nothing is recording?

Watch() records the first observation of each non-skipped rule, then detaches
a child that polls at the cadence in the header. The parent returns only after
the child reports ready on an inherited pipe, and writes the pidfile after
that. A clean stop writes the sentinel; a hard error does not.

* chore: add a unit test, remove build tags

* chore: address code review comments

* chore: implement phase 7 (#2785)

* chore: implement phase 7

Invariant defended: H3. The one question: can a rule be called alive
because it looked alive one poll ago?

proveCoverage (grafana-alertcheck/internal/gate/coverage.go) is the pure
coverage function: nine checks over one rule's polls — sentinel,
from-bounds, heartbeat continuity, health error/nodata, liveness,
in-window pause, rule absence, KeepLast. Liveness is absolute, never a
delta. Cross-domain comparisons translate by each poll's own skew and
widen boundary segments by its skew bound, fail-closed.

* chore: enhance unit tests

* chore: address code review comments

* chore: implement phase 8 (#2786)

* chore: implement phase 8

Invariant defended: H6/H7. The one question: can a violation ever
outrank an unobservable rule, or can a pass happen without
Violations empty and err nil?

Adds classify.go: the pure per-instance classifier (outcome table,
preexisting policy, BadFor) and decide(), the seam combining
proveCoverage with those timelines under one Policy. Consolidates
rule-poll filtering and skew translation onto pollsForRule/runnerTime,
shared with coverage.go.

* chore: rename some vars + add unit tests

* chore: address code review comments

* chore: implement phase 9 (#2787)

* chore: implement phase 9

Invariant defended: H5/H7. The one question: can check report a pass
over a window it did not prove?

Check() is the I/O shell around the pure decide(). Single-step
synthesizes the header and its own sentinel, so no mode flag reaches
the pure layer. Log mode stops the recorder before the one full read.

The header, not a definition re-resolved after the window closed, is
the authority for what was paused when the window opened — it decides
`skipped`, the drain set, and the transitionGrace max. The flock, not
the pidfile, is the authority for whether a writer still exists.

* chore: remove unix build tag

* chore: implement phase 10 (#2788)

* Wire watch/check subcommands to the gate library, with a table+JSON
renderer and H6/H7 exit-code mapping. Extend Result with per-rule/global
thresholds and a real skew bound; export SkewHardLimit; reject --states
normal.

* chore: fix goreleaser.yaml and add version command

* chore: implement phase 11 (#2789)

* chore: implement phase 11

Add coverage.go's declared-KeepLast check (no_data_state/exec_err_state,
not just an observed reason) and close the remaining §22 gaps: newly_bad's
no-early-exit clock assertion, a recorder-mode gap right after the deploy,
a rule's own coverage gap overriding its own recovery, a genuinely
skew-discriminating staleness test, exit-2 consequences on two
Reason-only coverage tests, and end-to-end checks for log-name
collapse, a truncated log, and the real watch-written state histogram.

* chore: address code review comments

* chore: more concise comments (#2790)

* chore: more concise comments

* fix: merge conflict

* chore: shorten comments

* fix: resolve conflict

* chore: use testify's require in tests (#2792)

* chore: use testify's require in tests

* chore: move remaining assumptions to testify

* chore: address code review comments

* chore: fix logging and std out printing (#2798)

* chore: fix logging and std out printing

* chore: truncate to seconds when comparing from time

* chore: add centralized docs (#2802)

* chore: add centralized docs

* chore: further update docs

* chore: address code review comments (#2807)

* chore: address code review comments

* chore: get rid of goreleaser
Tofel added a commit that referenced this pull request Sep 9, 2026
* chore: implement phase 1

Strict parsers for the state and ruler endpoints (H1), a Prometheus-style
duration parser, and fixtures sliced from real Grafana 13.1.0 payloads
covering every required/optional-field and must-error case, including the
"Normal (NoData)"/"Normal (Error)" composite reason states found live in the
current fleet capture (not in the original plan's vocabulary).

* chore: apply code review comments

* chore: implement phase 2 (#2780)

* chore: implement phase 2

Fix retry-error conflation, measure full poll latency, and harden Source test doubles for concurrency.

* chore: enhance unit tests

* chore: address code review comments

* chore: implement phase 3 (#2781)

* chore: implement phase 3

Add Resolve() for alert name resolution (uid:/Title/Folder/Title/
Folder/Group/Title forms, UID collapse, no-match suggestions) and the
grafana-alertcheck CLI's list subcommand, the first runnable piece of
the gate.

Incorporates review fixes: reject empty path segments in classifyForm,
guard uid: against an empty suffix, scope the no-match rule count and
suggestions to supported rule kinds only, and exit 0 on -h/--help.

* chore: enhance unit tests

* chore: implement phase 4 (#2782)

* chore: implement phase 4

Add per-rule poll timings, scheduler, and budget check (P4).

- schedule.go: DeriveTimings, Scheduler, CheckBudget (§5)
- Address review: add Folder/Title resolve test, rename
  CheckBudget's minPollEvery to tightestUID

* chore: enhance unit tests

* chore: address code review comments

* chore: implement phase 5 (#2783)

* chore: implement phase 5

Add the JSONL evidence log (P5).

- log.go: Header/Poll records, reduction, H2 transition markers,
  §3.2 verification, append-only Writer with flock, ReadLog
- flock_unix.go: non-blocking exclusive lock, unix only
- schedule.go: DeriveTimingsFromLog — log-mode cadence comes from the
  header, never from the definitions

* chore: remove unix build tags

* chore: address code review comments

* chore: implement phase 6 (#2784)

* chore: implement phase 6

Invariant defended: H2. The one question: can watch return success over a
window that nothing is recording?

Watch() records the first observation of each non-skipped rule, then detaches
a child that polls at the cadence in the header. The parent returns only after
the child reports ready on an inherited pipe, and writes the pidfile after
that. A clean stop writes the sentinel; a hard error does not.

* chore: add a unit test, remove build tags

* chore: address code review comments

* chore: implement phase 7 (#2785)

* chore: implement phase 7

Invariant defended: H3. The one question: can a rule be called alive
because it looked alive one poll ago?

proveCoverage (grafana-alertcheck/internal/gate/coverage.go) is the pure
coverage function: nine checks over one rule's polls — sentinel,
from-bounds, heartbeat continuity, health error/nodata, liveness,
in-window pause, rule absence, KeepLast. Liveness is absolute, never a
delta. Cross-domain comparisons translate by each poll's own skew and
widen boundary segments by its skew bound, fail-closed.

* chore: enhance unit tests

* chore: address code review comments

* chore: implement phase 8 (#2786)

* chore: implement phase 8

Invariant defended: H6/H7. The one question: can a violation ever
outrank an unobservable rule, or can a pass happen without
Violations empty and err nil?

Adds classify.go: the pure per-instance classifier (outcome table,
preexisting policy, BadFor) and decide(), the seam combining
proveCoverage with those timelines under one Policy. Consolidates
rule-poll filtering and skew translation onto pollsForRule/runnerTime,
shared with coverage.go.

* chore: rename some vars + add unit tests

* chore: address code review comments

* chore: implement phase 9 (#2787)

* chore: implement phase 9

Invariant defended: H5/H7. The one question: can check report a pass
over a window it did not prove?

Check() is the I/O shell around the pure decide(). Single-step
synthesizes the header and its own sentinel, so no mode flag reaches
the pure layer. Log mode stops the recorder before the one full read.

The header, not a definition re-resolved after the window closed, is
the authority for what was paused when the window opened — it decides
`skipped`, the drain set, and the transitionGrace max. The flock, not
the pidfile, is the authority for whether a writer still exists.

* chore: remove unix build tag

* chore: implement phase 10 (#2788)

* Wire watch/check subcommands to the gate library, with a table+JSON
renderer and H6/H7 exit-code mapping. Extend Result with per-rule/global
thresholds and a real skew bound; export SkewHardLimit; reject --states
normal.

* chore: fix goreleaser.yaml and add version command

* chore: implement phase 11 (#2789)

* chore: implement phase 11

Add coverage.go's declared-KeepLast check (no_data_state/exec_err_state,
not just an observed reason) and close the remaining §22 gaps: newly_bad's
no-early-exit clock assertion, a recorder-mode gap right after the deploy,
a rule's own coverage gap overriding its own recovery, a genuinely
skew-discriminating staleness test, exit-2 consequences on two
Reason-only coverage tests, and end-to-end checks for log-name
collapse, a truncated log, and the real watch-written state histogram.

* chore: address code review comments

* chore: more concise comments (#2790)

* chore: more concise comments

* fix: merge conflict

* chore: shorten comments

* fix: resolve conflict

* chore: use testify's require in tests (#2792)

* chore: use testify's require in tests

* chore: move remaining assumptions to testify

* chore: address code review comments

* chore: fix logging and std out printing (#2798)

* chore: fix logging and std out printing

* chore: truncate to seconds when comparing from time

* chore: add centralized docs (#2802)

* chore: add centralized docs

* chore: further update docs

* chore: address code review comments (#2807)

* chore: address code review comments

* chore: get rid of goreleaser
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