fix(sfm): an audit row can be finished once, from pending -- anything else raises

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-23 16:24:46 -04:00
1 parent fb9b48f259
commit ff0cce1cb2
3 files changed
+34 -3

No files matched your search

+10 -2
View File
@@ -131,6 +131,7 @@ CREATE INDEX IF NOT EXISTS idx_monitor_log_session ON monitor_log(session_id);
CREATE TABLE IF NOT EXISTS device_commands (
id TEXT PRIMARY KEY,
ts TEXT NOT NULL, -- when the attempt began (UTC ISO)
-- ts/finished_ts: tz-aware UTC ISO (+00:00), unlike the naive UTC of older tables
finished_ts TEXT,
serial TEXT NOT NULL,
series INTEGER NOT NULL,
@@ -432,13 +433,20 @@ class SeismoDb:
"""Record the result of a command begun with begin_device_command()."""
ts = datetime.datetime.now(datetime.timezone.utc).isoformat()
with self._connect() as conn:
conn.execute(
cur = conn.execute(
"UPDATE device_commands SET finished_ts=?, outcome=?, verified=?, "
"ack=?, error=? WHERE id=?",
"ack=?, error=? WHERE id=? AND outcome='pending'",
(ts, outcome, verified,
json.dumps(ack) if ack is not None else None,
error, command_id),
)
if cur.rowcount == 0:
known = conn.execute(
"SELECT 1 FROM device_commands WHERE id=?",
(command_id,)).fetchone()
raise ValueError(
f"device command {command_id} "
+ ("is already finished" if known else "is unknown"))
def query_device_commands(
self,