Skip to content

Commit 58aaec4

Browse files
hyperpolymathclaude
andcommitted
feat(schema): W8+W9 — cert decay (30-day window) + revocation detection
Closes design doc open questions #1 + #2. W8 (decay/sliding window) — mv_proven_certificates_recent: Computes PROVEN status over the last 30 days only (using started_at >= now64(3) - INTERVAL 30 DAY). A (class, prover) pair that was historically proven but has no recent activity shows status_30d='pending' — subject to revocation. W9 (revocation detection) — mv_cert_revocations: INNER JOIN all-time vs 30-day certs, surfaces rows where status_all_time='proven' AND status_30d='pending'. These are candidates for cert revocation notification. Current snapshot (2026-04-05): 0 revocations, 7 pairs proven in both windows (the entire historical data was generated today, so all activity falls inside the 30-day window). Downstream consumers can poll mv_cert_revocations via a new endpoint (follow-up) or directly via ClickHouse HTTP to emit audit events when a cert flips from proven → pending over the recent window. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 77446fe commit 58aaec4

2 files changed

Lines changed: 108 additions & 0 deletions

File tree

connectors/test-infra/seed/clickhouse-init.sql

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,57 @@ SELECT
394394
pa.obligation_class, pa.prover_used, pa.attempt_id, pa.obligation_id,
395395
pa.outcome, pa.duration_ms, pa.confidence, pa.started_at, pa.repo, pa.file
396396
FROM verisim.proof_attempts AS pa;
397+
-- SPDX-License-Identifier: PMPL-1.0-or-later
398+
-- W8: PROVEN cert with 30-day sliding window.
399+
-- W9: Revocation detection — compares all-time vs recent status.
400+
--
401+
-- mv_proven_certificates_recent: PROVEN status computed over the last
402+
-- 30 days only, not all-time. A cert's "recent status" can disagree
403+
-- with its all-time status when recent attempts have tanked the
404+
-- success rate — those are revocation candidates.
405+
406+
CREATE VIEW IF NOT EXISTS verisim.mv_proven_certificates_recent AS
407+
SELECT
408+
pa.obligation_class AS obligation_class,
409+
pa.prover_used AS prover_used,
410+
countIf(pa.outcome = 'success') AS success_count_30d,
411+
count() AS total_attempts_30d,
412+
sum(pa.duration_ms) AS total_duration_ms_30d,
413+
countIf(pa.outcome = 'success') / count() AS success_rate_30d,
414+
p.tau_proven AS tau_proven,
415+
p.n_proven AS n_proven,
416+
if(countIf(pa.outcome = 'success') / count() >= p.tau_proven
417+
AND count() >= p.n_proven,
418+
'proven', 'pending') AS status_30d,
419+
cityHash64(concat('proven|', toString(pa.obligation_class),
420+
'|', toString(pa.prover_used))) AS cert_id
421+
FROM verisim.proof_attempts AS pa
422+
CROSS JOIN (
423+
SELECT argMax(tau_proven, updated_at) AS tau_proven,
424+
argMax(n_proven, updated_at) AS n_proven
425+
FROM verisim.proof_attempts_cert_policy WHERE policy_id = 'default'
426+
) AS p
427+
WHERE pa.started_at >= now64(3) - INTERVAL 30 DAY
428+
GROUP BY pa.obligation_class, pa.prover_used, p.tau_proven, p.n_proven;
429+
430+
-- W9: Revocation signal — pairs where all-time says PROVEN but
431+
-- recent (30-day) window says PENDING. These are certs that may need
432+
-- revocation notification or cert-holder quarantine.
433+
CREATE VIEW IF NOT EXISTS verisim.mv_cert_revocations AS
434+
SELECT
435+
all_time.obligation_class AS obligation_class,
436+
all_time.prover_used AS prover_used,
437+
all_time.status AS status_all_time,
438+
recent.status_30d AS status_30d,
439+
all_time.success_rate AS rate_all_time,
440+
recent.success_rate_30d AS rate_30d,
441+
all_time.total_attempts AS n_all_time,
442+
recent.total_attempts_30d AS n_recent,
443+
all_time.cert_id AS cert_id,
444+
'revoked' AS revocation_status
445+
FROM verisim.mv_proven_certificates AS all_time
446+
INNER JOIN verisim.mv_proven_certificates_recent AS recent
447+
ON all_time.obligation_class = recent.obligation_class
448+
AND all_time.prover_used = recent.prover_used
449+
WHERE all_time.status = 'proven'
450+
AND recent.status_30d = 'pending';
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
-- SPDX-License-Identifier: PMPL-1.0-or-later
2+
-- W8: PROVEN cert with 30-day sliding window.
3+
-- W9: Revocation detection — compares all-time vs recent status.
4+
--
5+
-- mv_proven_certificates_recent: PROVEN status computed over the last
6+
-- 30 days only, not all-time. A cert's "recent status" can disagree
7+
-- with its all-time status when recent attempts have tanked the
8+
-- success rate — those are revocation candidates.
9+
10+
CREATE VIEW IF NOT EXISTS verisim.mv_proven_certificates_recent AS
11+
SELECT
12+
pa.obligation_class AS obligation_class,
13+
pa.prover_used AS prover_used,
14+
countIf(pa.outcome = 'success') AS success_count_30d,
15+
count() AS total_attempts_30d,
16+
sum(pa.duration_ms) AS total_duration_ms_30d,
17+
countIf(pa.outcome = 'success') / count() AS success_rate_30d,
18+
p.tau_proven AS tau_proven,
19+
p.n_proven AS n_proven,
20+
if(countIf(pa.outcome = 'success') / count() >= p.tau_proven
21+
AND count() >= p.n_proven,
22+
'proven', 'pending') AS status_30d,
23+
cityHash64(concat('proven|', toString(pa.obligation_class),
24+
'|', toString(pa.prover_used))) AS cert_id
25+
FROM verisim.proof_attempts AS pa
26+
CROSS JOIN (
27+
SELECT argMax(tau_proven, updated_at) AS tau_proven,
28+
argMax(n_proven, updated_at) AS n_proven
29+
FROM verisim.proof_attempts_cert_policy WHERE policy_id = 'default'
30+
) AS p
31+
WHERE pa.started_at >= now64(3) - INTERVAL 30 DAY
32+
GROUP BY pa.obligation_class, pa.prover_used, p.tau_proven, p.n_proven;
33+
34+
-- W9: Revocation signal — pairs where all-time says PROVEN but
35+
-- recent (30-day) window says PENDING. These are certs that may need
36+
-- revocation notification or cert-holder quarantine.
37+
CREATE VIEW IF NOT EXISTS verisim.mv_cert_revocations AS
38+
SELECT
39+
all_time.obligation_class AS obligation_class,
40+
all_time.prover_used AS prover_used,
41+
all_time.status AS status_all_time,
42+
recent.status_30d AS status_30d,
43+
all_time.success_rate AS rate_all_time,
44+
recent.success_rate_30d AS rate_30d,
45+
all_time.total_attempts AS n_all_time,
46+
recent.total_attempts_30d AS n_recent,
47+
all_time.cert_id AS cert_id,
48+
'revoked' AS revocation_status
49+
FROM verisim.mv_proven_certificates AS all_time
50+
INNER JOIN verisim.mv_proven_certificates_recent AS recent
51+
ON all_time.obligation_class = recent.obligation_class
52+
AND all_time.prover_used = recent.prover_used
53+
WHERE all_time.status = 'proven'
54+
AND recent.status_30d = 'pending';

0 commit comments

Comments
 (0)