"""Job #2744 (pursue route 114, rev 4). QUESTION (#1361's next step): across the WHOLE accepted lane, does any accepted patch or revision show as a repository write in the mirror's provenance manifest, or is patch_status unconditionally a queue state? POPULATION: returns-index.json (every return id walked in-band by enum2744.py), filtered to status == accepted with a non-null patch or a revision (revision_path/revision_sha). TESTS, per (return, target path), pre-registered before the run: T1 manifest[target].source.modified_at >= effects_applied_at (a write at or after acceptance) -> FALSIFIER of the queue-state reading if true for any accepted patch; also record last_commit and the delta in hours. T5 the patch's added lines present in the SERVED file (GET docs/), removed lines still served; for a revision return: served sha256 (store's appended newline stripped) == revision_sha. H the store's own history endpoint (GET history/): number of versions and whether one is attributed to this return (the overlay layer the 2026-09-16 cut reverted, review #154). CONTROLS: C1 the four audits #101/#151/#152/#153 must reproduce #1361's T1 deltas (-60.07/-80.58/-191.38/-80.64 h); C2 the manifest's newest modified_at is after every acceptance (live clock); C3 the four documents' manifest sha256 equal the served bytes (T2 of #1361). Output: fresh2744.json + a table on stdout. Progress to stderr.""" import json, sys, subprocess, hashlib, re, datetime as dt from pathlib import Path HERE = Path(__file__).resolve().parent idx = json.load(open(HERE / 'returns-index.json', encoding='utf-8')) man = json.load(open(HERE / 'PUBLICATION.json', encoding='utf-8')); files = man['files'] log = sys.stderr def api(path): r = subprocess.run(['bash', str(HERE.parent / 'api.sh'), 'GET', path], capture_output=True) return r.stdout def ts(s): if not s: return None s = s.replace('Z', '+00:00') return dt.datetime.fromisoformat(s) served_cache = {} def served(path): if path not in served_cache: b = api('docs/' + path) if b.startswith(b'{"error"'): served_cache[path] = None else: if b.endswith(b'\n'): b = b[:-1] served_cache[path] = b return served_cache[path] hist_cache = {} def history(path): if path not in hist_cache: try: hist_cache[path] = json.loads(api('history/' + path).decode('utf-8')) except Exception: hist_cache[path] = None return hist_cache[path] pop = [r for r in idx.values() if r.get('status') == 'accepted' and (r.get('has_patch') or (r.get('revision') or {}).get('sha'))] pop.sort(key=lambda r: r['id']) # enum2744.py only parsed '+++ b/' headers; re-read the patch of every accepted return whose targets came out empty for r in pop: if r.get('has_patch') and not r.get('patch_targets'): d = json.loads(api('return/' + str(r['id'])).decode('utf-8')) patch = d.get('patch') or '' paths = re.findall(r'^\+\+\+ (?:b/)?(\S+)', patch, re.M) or re.findall(r'^diff --git a/(\S+) b/', patch, re.M) or re.findall(r'^--- (?:a/)?(\S+)', patch, re.M) r['patch_targets'] = [p for p in paths if p != '/dev/null'] r['patch_added'] = [l[1:] for l in patch.splitlines() if l.startswith('+') and not l.startswith('+++')][:400] r['patch_header_form'] = 'reparsed' print(f"#{r['id']}: reparsed patch targets {r['patch_targets']} (first lines: {patch[:120]!r})", file=log) print(f'accepted returns total: {sum(1 for r in idx.values() if r.get("status") == "accepted")}; with patch or revision: {len(pop)}', file=log) rows = []; falsifier = [] for r in pop: rid = r['id']; applied = ts(r.get('effects_applied_at')) targets = [(p, 'patch') for p in r.get('patch_targets') or []] rv = r.get('revision') or {} if rv.get('path'): targets.append((rv['path'], 'revision')) for fx in r.get('also_fix') or []: if isinstance(fx, dict) and fx.get('path'): targets.append((fx['path'], 'also_fix')) seen = set() for path, via in targets: path = path.lstrip('/') if path in seen: continue seen.add(path) ent = files.get(path) or {}; src = ent.get('source') or {} mod = ts(src.get('modified_at')) delta = None if not (mod and applied) else round((mod - applied).total_seconds() / 3600, 2) row = {'return': rid, 'type': r.get('type'), 'handle': r.get('handle'), 'via': via, 'path': path, 'in_manifest': bool(ent), 'effects_applied_at': r.get('effects_applied_at'), 'patch_status': r.get('patch_status'), 'commit': r.get('commit'), 'manifest_modified_at': src.get('modified_at'), 'last_commit': (src.get('last_commit') or '')[:12], 'delta_hours': delta, 'T1_write_after_acceptance': bool(mod and applied and mod >= applied)} sv = served(path) row['served'] = sv is not None if sv is not None: row['served_sha256'] = hashlib.sha256(sv).hexdigest() row['manifest_sha_matches_served'] = (ent.get('sha256') == row['served_sha256']) if ent else None text = sv.decode('utf-8', 'replace') if via == 'patch': added = r.get('patch_added') or [] added_sig = [l for l in added if len(l.strip()) >= 12] row['T5_added_tested'] = len(added_sig) row['T5_added_present'] = sum(1 for l in added_sig if l in text) if via == 'revision': row['T5_revision_sha_served'] = (rv.get('sha') == row['served_sha256']) h = history(path) if isinstance(h, dict) and isinstance(h.get('versions'), list): vs = h['versions'] row['H_versions'] = len(vs) mine = [v for v in vs if str(v.get('return_id')) == str(rid)] row['H_version_by_this_return'] = [v.get('version') for v in mine] if vs: last = vs[-1] row['H_current_version'] = last.get('version'); row['H_current_return_id'] = last.get('return_id'); row['H_current_summary'] = (last.get('summary') or '')[:80] row['H_current_is_this_return'] = str(last.get('return_id')) == str(rid) row['H_overlay_superseded_by_cut'] = bool(mine) and not row['H_current_is_this_return'] and any((v.get('version') or 0) > mine[-1].get('version', 0) and v.get('return_id') is None for v in vs) row['H_current_sha_equals_served'] = (vs[-1].get('content_sha') == row.get('served_sha256')) if vs and row.get('served_sha256') else None if row['T1_write_after_acceptance'] or row.get('T5_added_present', 0) > 0 or row.get('T5_revision_sha_served'): falsifier.append(row) rows.append(row) print(f"#{rid:<5} {via:<9} {path:<60} delta={delta} T1={row['T1_write_after_acceptance']} T5add={row.get('T5_added_present')}/{row.get('T5_added_tested')} revsha={row.get('T5_revision_sha_served')} H={row.get('H_versions')}/{row.get('H_version_by_this_return')}", file=log, flush=True) # controls c1 = {rid: [x['delta_hours'] for x in rows if x['return'] == rid] for rid in (101, 151, 152, 153)} newest = max(ts(e['source']['modified_at']) for e in files.values() if e.get('source', {}).get('modified_at')) last_accept = max((ts(r['effects_applied_at']) for r in pop if r.get('effects_applied_at')), default=None) c2 = {'manifest_generated_at': man.get('generated_at'), 'newest_modified_at': newest.isoformat(), 'last_acceptance_in_population': last_accept.isoformat() if last_accept else None, 'files_modified_after_last_acceptance': sorted(p for p, e in files.items() if ts(e.get('source', {}).get('modified_at')) and last_accept and ts(e['source']['modified_at']) >= last_accept)} out = {'instrument': 'fresh2744.py', 'job': 2744, 'population': [r['id'] for r in pop], 'n_accepted_total': sum(1 for r in idx.values() if r.get('status') == 'accepted'), 'n_ids_walked': len(idx), 'n_http_found': sum(1 for r in idx.values() if r.get('http') == 200), 'rows': rows, 'falsifier_rows': falsifier, 'C1_four_audit_deltas': c1, 'C2_live_clock': c2, 'verdict': {'any_write_after_acceptance': any(x['T1_write_after_acceptance'] for x in rows), 'any_added_line_served': any((x.get('T5_added_present') or 0) > 0 for x in rows), 'any_revision_sha_served': any(x.get('T5_revision_sha_served') for x in rows), 'n_rows': len(rows), 'n_returns': len(pop)}} json.dump(out, open(HERE / 'fresh2744.json', 'w', encoding='utf-8'), indent=1) print(json.dumps(out['verdict'])); print('C1', c1); print('C2', json.dumps(c2)[:600])