carlos / platform Public

scripts: ppv2-step S3 guard reads every saved poll, verdict or not

Re-review round 3 (Astra item 6): an interrupted convergence keeps
its polls but writes no verdict, so a reverify could pass over an S3
signal seen in it. Each trust poll now records its S3 signal against
its own run's baseline as it is logged, and reverify scans the whole
poll log (every apply, resume and reverify, interrupted or not) as
well as the verdict and its history; it refuses without
--incident-cleared.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev a4883d2125224fe251d7a1c4d7a385aabf89a04c parent 2b69706
2 files changed, +97 −6
  • scripts/ppv2-step.py +50 −6
  • scripts/ppv2_step_test.py +47 −0
diff --git a/scripts/ppv2-step.py b/scripts/ppv2-step.py
index 83ad1bfc2..6cb6d47e0 100755
--- a/scripts/ppv2-step.py
+++ b/scripts/ppv2-step.py
@@ -696,12 +696,17 @@ def cmd_reverify(args, cloud):
if sorted(targets) != sorted(made_with):
raise Refused(f"--targets must be the step's targets ({', '.join(made_with)}); a target cannot leave "
'a step before it converges')
- # A trust-violation signal in this step's evidence is S3 on some node (spec 6.4).
+ # A trust-violation signal anywhere in this step's evidence is S3 on some
+ # node (spec 6.4): in a verdict, its history, or any saved poll of any
+ # run of the step, including an interrupted one that wrote no verdict.
prior = load_record(record_dir / f'{args.step}.json') or {}
- signals = [h for h in [prior] + list(prior.get('history') or []) if h.get('s3_signal')]
+ signals = [f'{args.step}.json' for h in [prior] + list(prior.get('history') or []) if h.get('s3_signal')]
+ signals += [f"{args.step}-polls.jsonl at {e.get('at')}: {'; '.join(e.get('s3_reasons') or [])}"
+ for e in logged_s3_signals(record_dir / f'{args.step}-polls.jsonl')]
if signals and not args.incident_cleared:
- raise Refused(f'{args.step}.json records an S3 signal (marker_trusted or no_client_refused moved); '
- 'run the S3 incident procedure (runbook) first, then reverify with --incident-cleared')
+ raise Refused(f'{args.step} has an S3 signal (marker_trusted or no_client_refused moved): '
+ f'{signals[0]}; run the S3 incident procedure (runbook) first, then reverify with '
+ '--incident-cleared')
applied = basis.get('applied')
try:
doc = json.loads((root / TFVARS_FILE).read_bytes())
@@ -977,6 +982,13 @@ def converge(cloud, record_dir, applied, paths, timeout):
poll_health()
schedule['health'] = now + HEALTH_EVERY
+ def log_trust(job):
+ """Logs a trust poll with any S3 signal it shows against this run's
+ baseline, as it is observed, so no later run can miss it."""
+ entry = job.entry()
+ found = s3_reasons(entry['status'], applied.get('baseline') or {})
+ return log.add(dict(entry, s3_signal=bool(found), s3_reasons=found))
+
next_trust = clock.time()
job = None
try:
@@ -985,7 +997,7 @@ def converge(cloud, record_dir, applied, paths, timeout):
if job is None and clock.time() >= next_trust:
job = TrustJob(cloud, targets)
if job is not None and job.check():
- log.add(job.entry())
+ log_trust(job)
next_trust, job = job.started + TRUST_EVERY, None
if probes_ready(paths, clock) or clock.time() >= deadline:
break
@@ -998,7 +1010,7 @@ def converge(cloud, record_dir, applied, paths, timeout):
while not job.check():
health_due()
clock.sleep(TICK)
- entry = log.add(job.entry())
+ entry = log_trust(job)
if not any(isinstance(s, str) for s in entry['status'].values()):
break
health_due()
@@ -1112,6 +1124,38 @@ def coverage_reasons(times, window, gap, what):
return reasons
+S3_COUNTERS = ('marker_trusted', 'no_client_refused')
+
+
+def s3_reasons(status, baseline):
+ """The S3 signals (spec 6.4) in one poll's statuses against a run's baseline."""
+ found = []
+ for iid, s in status.items():
+ base = baseline.get(iid)
+ if is_status(s) and is_status(base):
+ for counter in S3_COUNTERS:
+ if s['counters'][counter] > base['counters'][counter]:
+ found.append(f"{iid}: {counter} moved from {base['counters'][counter]} to {s['counters'][counter]}")
+ return found
+
+
+def logged_s3_signals(path):
+ """Every saved trust poll with an S3 signal, for any anchor, verdict written or not."""
+ try:
+ lines = path.read_text().splitlines()
+ except FileNotFoundError:
+ return []
+ out = []
+ for line in lines:
+ try:
+ entry = json.loads(line)
+ except ValueError:
+ continue
+ if entry.get('kind') == 'trust' and entry.get('s3_signal'):
+ out.append(entry)
+ return out
+
+
def continuous_reasons(times, start, end, gap, what, start_label):
"""Observations (this host's clock) from start to end, never more than gap apart."""
points = sorted(t for t in times if start <= t <= end)
diff --git a/scripts/ppv2_step_test.py b/scripts/ppv2_step_test.py
index 4c66ad7c6..7c5305323 100644
--- a/scripts/ppv2_step_test.py
+++ b/scripts/ppv2_step_test.py
@@ -1091,6 +1091,53 @@ class ReverifyTests(Harness):
# The signal stays in history, so a later reverify needs the flag again.
self.assert_refused(self.reverify('A80'), 'run the S3 incident procedure')
+ def interrupted_window(self, sample):
+ """A80 applied (TG now in S1); its convergence is interrupted at 45 s,
+ after trust polls at 1 s and 31 s, the second answering `sample` on
+ TARGETS[1]. No verdict is written; only the poll log keeps what was seen."""
+ self.ready_for('A80')
+ self.live({'80': 'S1'})
+ applied = {'nlb_arn': NLB, 'port': '80', 'step': 'A80', 'applied_at': APPLIED_AT, 'tg_arn': TG['80'],
+ 'tg_address': ADDR['80'], 'targets': list(TARGETS),
+ 'baseline': {t: trust('baseline') for t in TARGETS}, 'baseline_at': gate.iso(T0 - 5)}
+ self.record('A80-applied', **applied)
+ clock = FakeClock(T0 + 1)
+ cloud = FakeCloud(clock, 'A80')
+ cloud.samples[TARGETS[1]] = [(0, 'after_a'), (20, sample)]
+
+ def interrupt():
+ raise gate.Interrupted('SIGTERM')
+ clock.at(T0 + 45, interrupt)
+ paths = [str(self.probes / 'a.json'), str(self.probes / 'b.json')]
+ with contextlib.redirect_stdout(io.StringIO()), self.assertRaises(gate.Interrupted):
+ gate.converge(cloud, self.records, applied, paths, 600)
+ self.assertFalse((self.records / 'A80.json').exists())
+ # The fake aws now answers the reverify with steady counters.
+ self.world['trust'] = {TARGETS[0]: [trust('after_a')], TARGETS[1]: [trust(sample)]}
+
+ def test_interrupted_s3_signal_blocks_reverify(self):
+ # marker_trusted rose in a run that was interrupted before any verdict.
+ self.interrupted_window('marker_trusted_moved')
+ result = self.reverify('A80')
+ self.assert_refused(result, 'run the S3 incident procedure (runbook) first')
+ self.assertIn('A80-polls.jsonl', result.stderr)
+ self.assertIn('marker_trusted moved from 0 to 2', result.stderr)
+ self.assertFalse((self.records / 'A80-verified.json').exists())
+ # With the incident procedure run, the operator says so and it proceeds.
+ self.apply_converging('A80', command='reverify', incident_cleared=True)
+ self.assertTrue(self.record_of('A80')['passed'])
+ self.assertTrue(self.record_of('A80-verified')['incident_cleared'])
+ # The same for no_client_refused.
+ self.setUp()
+ self.interrupted_window('no_client_refused_moved')
+ self.assert_refused(self.reverify('A80'), 'no_client_refused moved')
+ # A clean interrupted run does not block.
+ self.setUp()
+ self.interrupted_window('after_a')
+ self.apply_converging('A80', command='reverify')
+ self.assertTrue(self.record_of('A80')['passed'])
+ self.assertFalse(self.record_of('A80-verified')['incident_cleared'])
+
class FakeClock:
def __init__(self, t):