Persist resolution_reason on resolve_error so the audit log is useful

The UPDATE in `_resolve_error_impl` only touched `resolved_at` — the
`reason` argument every caller passes was silently dropped, and the
`resolution_reason` / `resolution_type` columns stayed NULL for every
auto-resolved error. The columns were added back in a previous sprint
for exactly this audit-log purpose, but the writer was never updated
to populate them.

Fix the SQL to write `resolution_reason = ?` and tag
`resolution_type = COALESCE(existing, 'auto')` so admin-cleared
errors (whose type is set elsewhere) keep their value while the
default auto path correctly labels itself.

Verified end-to-end on the lab host: re-injected the `disk_nvme2n1`
warning, waited one scan cycle, the row now reads
`resolution_type='auto'` and
`resolution_reason='Transient I/O cleared, SMART now reports healthy'`
— previously these columns stayed NULL even though the resolve_error
call passed a descriptive reason.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
MacRimi
2026-06-01 23:02:52 +02:00
parent 9677c5cb19
commit 3c5beb0286
3 changed files with 13 additions and 3 deletions
+12 -2
View File
@@ -673,11 +673,21 @@ class HealthPersistence:
cursor = conn.cursor()
now = datetime.now().isoformat()
# Persist `reason` into the dedicated resolution_reason column
# (and tag resolution_type='auto' so the audit log can tell
# auto-resolves apart from explicit admin clears). Previously
# this UPDATE only touched resolved_at, so the `reason` arg
# every caller passes — including the new
# `_reconcile_stale_disk_warnings` pass — was silently dropped
# and the resolution_reason column stayed NULL for every
# auto-resolved error.
cursor.execute('''
UPDATE errors
SET resolved_at = ?
SET resolved_at = ?,
resolution_type = COALESCE(resolution_type, 'auto'),
resolution_reason = ?
WHERE error_key = ? AND resolved_at IS NULL
''', (now, error_key))
''', (now, reason, error_key))
if cursor.rowcount > 0:
self._record_event(cursor, 'resolved', error_key, {'reason': reason})