Repository navigation
fix(metrics): report a corrupt hooks.json once, not every export - #23101
KiroCrewCaptain merged 1 commit into
Conversation
The webhook-registration gauge reads hooks.json through webhooks.registered_context_count once per export interval. That read went through _read_json, which logs "webhook store unreadable" at WARNING on every failed parse, so a file that stayed corrupt logged once a minute and went around the probe's own warn-once note. registered_context_count now parses the file itself and returns (0, False) on a parse or read error without logging. The probe still counts every failure and warns once. Closes kirodotdev#23098 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The rewritten read sorts every input into the same outcome Notes
[DESIGN-REVIEWED] c8c7e90 Description read[DESCRIPTION-READ] 88828d5db300df7732c207a5a979226683437353dbb383a5030e84cc6a8c3fa6 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix is at the cause: the periodic caller stops borrowing a reader that logs, and What this change shipsInventory (3 items) — 3 justifiedIntent: an operator whose
[FIRST-PRINCIPLES-REVIEWED] c8c7e90 Description read[DESCRIPTION-READ] 92aaf2e3fb4d420cd75b497a238f400fd76a943ed53407c3dccc8db4fd351129 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (3 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: the webhook registration count reads hooks.json without the store reader's per-read warning, so a corrupt file is reported once by the metrics probe instead of on every export interval; a new test pins the single warning. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/metrics.md.
Problem / Motivation
Goal: A
hooks.jsonthat does not parse is reported in the gateway log once, not once per metrics export interval.The
kirocrew.inventory.webhooks.registeredgauge callswebhooks.registered_context_count()every export interval (60 s by default). That function readhooks.jsonthroughwebhooks._read_json, which logswebhook store unreadable (<path>): <error>at WARNING on every failed parse. A file that stays corrupt therefore adds a WARNING togateway.logevery minute. That goes around the probe's own_note_probe_failure, which exists to warn once and drop repeats to DEBUG. The message also calls the file the "webhook store", thoughhooks.jsonis shared with the script-hook store. The Opus review on #22223 named this.Why it matters
An operator with metrics on and one bad byte in
hooks.jsongets 1,440 identical warnings a day, which bury everything else in the log. The probe's warn-once rule was written to prevent exactly that.Not a goal
_read_json. Its warning stays for the webhook store's own readers and writers, where a failed read refuses an operation.hooks.json.What changed (motivation → approach → change)
webhook store unreadableWARNING per export interval whilehooks.jsonis corrupt.registered_context_count, whose only caller is the gauge, read through_read_json, which logs every failure. The function's contract is to answer(0, False)for an unreadable file and leave the reporting to its caller.registered_context_countparses the file itself with the sameread_bytes_with_retry+json.loadsthat_read_jsonuses. A missing file is still(0, True), and a parse or read error is(0, False), now without a log line. The probe still counts every failure and warns once (_note_probe_failure).metrics.mdrow for the gauge now says the read does not log and the probe reports a corrupt file once.Backwards compatibility
Compatible: the function returns the same pair for every input, and its only caller is the gauge. The one difference is a log line that is no longer written.
Removes nothing: no path, field, key or validator is removed; the probe's warning and failure count still report the fault.
Tests
test_registered_webhooks_corrupt_file_warns_once_across_export_intervals(new,test/metrics/test_inventory_gauges.py) reads a corrupthooks.jsonthrough the probe three times. It asserts exactly one WARNING is logged (the probe's, naming'webhooks') and the failure count is 3.origin/main'swebhooks.pythe new test fails: the warnings includewebhook store unreadable (...hooks.json): Expecting property name enclosed in double quotes ...on every read.test/metrics/test_inventory_gauges.pyand everytest/test_webhook*.pyfile (335 passed, 1 skipped). black (my hunk;webhooks.pyis on the black baseline and black's diff does not touch it), isort, flake8,mypyon the changed module,check_black_formatting.py,check_comment_history.py,check_brand_name.pyanddocs-lint.share clean.Manual verification
N/A — unit coverage sufficient: the test drives the real probe and reader against a real corrupt file and reads the log records, which is the whole behaviour.
Related Issues
Closes #23098
Follows the Opus review finding on #22223.
Pattern harvest
Not generalizable: a reader that logs on failure is right for the store it serves. The defect was one caller, a periodic probe, borrowing it while it already reports failures itself.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
🤖 Generated with Claude Code