Skip to content

fix(grug): the enforcement gauge reports the whole fleet, so the monitor cannot latch - #815

Merged
quadseven merged 2 commits into
mainfrom
fix/716-enforcement-monitor-latch
Aug 2, 2026
Merged

fix(grug): the enforcement gauge reports the whole fleet, so the monitor cannot latch#815
quadseven merged 2 commits into
mainfrom
fix/716-enforcement-monitor-latch

Conversation

@quadseven

Copy link
Copy Markdown
Owner

Why

The enforcement-gap monitor latched. On 2026-08-01 it read Alert for over three hours while zero repos were in the gap:

04:00:00Z  quadseven/yuzu-yard-sale emits its LAST datapoint (opted out)
07:18:15Z  monitor 308376323 status = Alert
           last_triggered_ts  = 2026-07-28T16:50:23Z   (3.5 days stale)
           repos in gap       = NONE

Datadog holds a silent multi-alert group in its last state for 24 hours, and group_retention_duration cannot shorten that - it is documented for APM/Audit/CI/Error-Tracking/Event/Logs/RUM monitors, not metric alert. So a repo that was red when it stopped reporting stayed red.

Full write-up, including which cause is observed and which is inferred: ADR-0022.

Summary

Every repo the installation can see reports a value on every poll cycle. Leaving the gauge is never how a repo stops alerting; reporting a healthy value is.

  • Opted-out repos emit opted_out (1.0) instead of being skipped, so their group resolves on the next evaluation.
  • Both opt-outs qualify. force_disable_enforcement is documented in CONTEXT.md as an enforcement opt-out, but the poller only ever checked tpm_enabled - so a repo using the documented escape hatch kept detecting none and pinned this monitor red permanently. That is a latent bug this PR also fixes.
  • The monitor thresholds on the value (< 0.5), never on the enforcement_type tag, so no state transition can make a series vanish.
  • observability.emit_enforcement_metric owns the value map; nothing else restates it.

Acceptance criteria

  • An opted-out repo reports instead of vanishing - test_enforcement_pass_emits_opted_out_instead_of_dropping_the_repo, which also asserts it costs no GitHub API call
  • force_disable_enforcement counts as an opt-out - test_enforcement_pass_treats_force_disable_as_an_opt_out
  • The query cannot latch on a state change - test_enforcement_gap_query_thresholds_on_value_not_the_state_tag
  • Verified against live data: 16 repos in scope, 14 at 0.5, 2 at 1.0, none breaching
  • Suites green: 1872 webhook, 288 api, 24 infra

Size

Size: M

Out of scope

  • Monitor state observability. pup monitors get returns state: null with overall_state_modified frozen at creation; live status only comes from pup monitors search. That is a vendor/tooling property, not fixable from grug's Pulumi. This is why the issue is Refs, not closes.
  • One residual case is inherent. A deleted repo, or a removed installation, cannot emit anything, so its group still ages out on Datadog's 24h default. Bounded: it needs a repo to leave the estate entirely while red.
  • The dangling docs/RUNBOOK.md#enforcement-gap anchor - that file has no enforcement section at all. Pre-existing; flagged rather than silently expanded.

Reviewer note

A first attempt (974e024) blamed only the tag filter and cited the yuzu measurement as proof. Review caught that yuzu left via tpm_enabled=false, which is a different latch - so the evidence did not support the claim. 7848a35 fixes the actual cause and ADR-0022 is explicit about which cause is observed and which is inferred.

Refs #716

The monitor filtered on the `enforcement_type:none` TAG. A repo that
gained enforcement stopped matching that tag, so instead of reporting a
healthy value into its multi-alert group, the group went SILENT -
and Datadog holds a silent metric group in its last state for 24h. The
alert stayed red long after the gap was gone.

Measured live 2026-08-01: yuzu-yard-sale emitted its last point at
04:00:00Z; at 07:18:15Z the monitor still read Alert with ZERO repos in
the gap, past 3x its own `last_1h` window. `last_triggered_ts` was
2026-07-28, 3.5 days stale.

`group_retention_duration` cannot shorten that: it is documented as
APM/Audit/CI/Error-Tracking/Event/Logs/RUM only, not `metric alert`.

So threshold on the VALUE instead, which already encodes the state
(grug_managed 1.0, external 0.5, none 0.0, error -1.0). Every repo keeps
reporting into its own group, and a repo that gains enforcement flips
0.0 -> 0.5/1.0 and RESOLVES rather than going quiet.

This also closes a blind spot that was worse than the latch. Under the
tag filter, an auth or rate-limit outage emitted `enforcement_type:error`
for every repo and `none` for none of them - so the gap monitor went
QUIET during exactly the incident that made enforcement unknowable.
`error` is -1.0, so it now trips the threshold. The monitor is renamed
"not provably gated" because that is what it now means.

Verified against live data: the new query puts 16 repos in scope (14 at
0.5, 2 at 1.0) and NONE breach - so this also clears the current red.

Residual and inherent to Datadog: a repo leaving the fleet entirely
(tpm_enabled=false, archive, uninstall) stops emitting and its group
still ages out on the 24h default. Stated in the monitor message so the
next operator does not chase it.

Refs #716
Follow-up to 974e024 on the same issue, after review found that commit's
central claim did not survive its own evidence.

974e024 blamed the tag filter and cited yuzu-yard-sale's 04:00Z->07:18Z
red-with-no-gap window as proof. But yuzu left via `tpm_enabled=false`,
which `poller_handler` handled with a bare `continue` - so it stopped
emitting ENTIRELY. That is a different latch from the one the commit
fixed, and it is the one the measurement actually proves. The tag-filter
latch is real by inspection but has never been observed.

Both are the same shape: a repo that stops reporting keeps its last
verdict, because Datadog holds a silent multi-alert group for 24h and
`group_retention_duration` is not available for `metric alert`.

So fix the cause rather than the symptom: EVERY visible repo reports
every cycle. An opted-out repo emits `opted_out` (1.0) instead of being
skipped, which resolves its group on the next evaluation. It is still not
detected - opting out should not spend a GitHub API call.

`force_disable_enforcement` now counts as an opt-out too. CONTEXT.md
documents it as one, but the poller only checked `tpm_enabled`, so a repo
using the documented escape hatch kept detecting `none` and pinned this
monitor red permanently.

Review also caught real drift, all fixed here:
- DESIGN.md asserted -1.0 in one row while the row above said the values
  were 1.0/0.5/0.0 only.
- CONTEXT.md never learned `error`, `opted_out` or "provably gated",
  though the monitor name and query now depend on all three.
- The postmortem narrative was restated in four places and the value map
  in five. Both now live once: ADR-0022 and `emit_enforcement_metric`.
- The monitor message had grown into a mini-runbook and told operators to
  use `tpm_enabled=false` while CONTEXT.md documents
  `force_disable_enforcement`. Trimmed to the sibling shape.

Suites: 1872 webhook, 288 api, 24 infra.

Refs #716
@quadseven
quadseven force-pushed the fix/716-enforcement-monitor-latch branch from 474d9ab to 7848a35 Compare August 2, 2026 14:47
@quadseven

Copy link
Copy Markdown
Owner Author

Force-pushed to drop 474d9ab from this branch. The split was incomplete on my side: I cherry-picked the intent-edit fix onto its own branch (#814) but never removed it here, so the first CI run on this PR was reviewing both workstreams at once (1878 webhook tests instead of 1872).

This branch is now the enforcement-gauge work only - 8 files, no rerun.py or dispatch.py. Suite re-verified locally at 1872 passed after the rebase.

@grug-tribe

grug-tribe Bot commented Aug 2, 2026

Copy link
Copy Markdown

Grug walk most of trail. Some ground not walked.

fix(grug): the enforcement gauge reports the whole fleet, so the monitor cannot latch

Grug Elder - Partial coverage - no markings on the ground Grug walked - check `neutral`
  • Fast look only - deep look may add more.
  • Grug swallow 1 weak thought(s).

Some ground not walked this pass - part of the diff did not fit one look. What Grug did walk is above. Grug not say trail safe for ground Grug not walk.

@quadseven
quadseven merged commit fcda737 into main Aug 2, 2026
20 checks passed
@quadseven
quadseven deleted the fix/716-enforcement-monitor-latch branch August 2, 2026 14:57
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.

1 participant