Files
MrAlders0n 16fb706d17 Packet sites: a read model that serves region packet pages while trusted (#247)
* feat(db): packet_sites table and indexes

* feat(ingest): keep each packet's site row in the observation insert

* feat(db): packet_sites backfill, reconcile and audit

* feat(db): region packet pages from packet_sites when trusted, with an exact page cursor

* feat(db): packet_sites front sweeper with plan and liveness metrics

* feat: boot repair, reconcile, audit, sweep and first-time verification for packet_sites

* fix(db): read no site range when no packet was first heard in the window

* fix(db): read the window guard's maxima through indexes

* test(planguard): packet_sites statements active, data-derived cases, diff and storediff

* docs(api): pageCursor applies to region packet pages

* fix(db): drop packet_sites trust again after the unsited fallback write

* fix(db): the packet_sites audit refills a pair at its newest hearing

* fix(db): bounded region reads fill the page within the request, else today's statement answers

* fix(planguard): tie_cut needs both pages at the limit and members of other identities

* fix: packet_sites sweep without JIT, one verification VACUUM, read-only checks to the newest id

* docs(api): cursor and pageCursor on region pages served without nextPageCursor

* test: drop local baselines of entries the copy skips; plain race schedule names

* test(planguard): storediff walks of the bounded region shapes; local baselines after the overlay rebuild

* fix(db): drop message-site trust again after the unseeded insert

* fix(db): a region page cursor's fallback to today's statement continues from its exact position
2026-10-20 00:18:33 -04:00

139 lines
7.0 KiB
YAML

# Copyright 2026 Beacon Contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
# Planted regression: ListPacketsBySites as first proposed (rm: a per-site LIMIT before the cross-site re-check)
# loses rows; the end-state statement (end: the re-check inside each per-site range) does not.
#
# Needs the overlay overlay/packet_sites_walk.sql (schema t_s2b, the 12 sites below). Run it with walks:
# planguard diff --old-ref origin/dev --cases db/planguard/diff/planted_readmodels.yaml --walk 1,2,3,web --dsn ...
# then DROP SCHEMA t_s2b CASCADE. Without --walk, nl.walk compares the first page only, where rm is usually right.
#
# The legacy pairs compare today's ListPacketsByIATAs (millisecond cursor, a saturating per-site scan, the latest
# observer picked without a tie-break) with the packet_sites statements at the same cursor: the named classes cover
# exactly those differences, and nothing else may differ.
#
# The legacy judge pairs and nl.walk.judge use fixed times from a 2026-10-18 snapshot: they mean something only on
# a copy that holds data around those times (elsewhere they compare near-empty pages). nl.l1.pagecursor.tie derives
# its cursor from the data instead, and is skipped (which fails the run) on a snapshot without a microsecond tie.
batches:
- name: planted_readmodels
search_path: "t_s2b, public"
statements:
old: "old:ListPacketsByIATAs"
rm: "file:sql/planted/ListPacketsBySitesReadmodels.sql"
end: "new:ListPacketsBySites"
oracle: "file:sql/oracle/OracleBySites.sql"
pairs:
# Every page boundary from the first page: ref = the oracle (packet_observations, independent of
# packet_sites) fetched as one page, cands walked as the client walks them.
- id: nl.walk
ref: {stmt: oracle, params: [&nl "{AMS,EIN,ENS,GLZ,GRQ,LEY,LWR,MST,QAR,RTM,UDE,UTC}", infinity, '\x', 2]}
cands:
- {stmt: rm, params: [*nl, infinity, '\x', 2]}
- {stmt: end, params: [*nl, infinity, '\x', 2]}
key: [site_heard_at]
walk:
limit_param: 4
fetch_extra: 1
cursor: [{param: 2, column: site_heard_at}, {param: 3, column: packet_hash}]
first: [infinity, '\x']
web_limit: 50
oracle: true
expect: {rm: different, end: same}
# The same walk from just above the judge times below, so every cursor around them is a page boundary.
- id: nl.walk.judge
ref: {stmt: oracle, params: [*nl, "2026-10-18 15:41:00+00", '\x', 2]}
cands:
- {stmt: rm, params: [*nl, "2026-10-18 15:41:00+00", '\x', 2]}
- {stmt: end, params: [*nl, "2026-10-18 15:41:00+00", '\x', 2]}
key: [site_heard_at]
walk:
limit_param: 4
fetch_extra: 1
cursor: [{param: 2, column: site_heard_at}, {param: 3, column: packet_hash}]
first: ["2026-10-18 15:41:00+00", '\x']
web_limit: 50
oracle: true
expect: {rm: different, end: same}
# Today's statement at a millisecond cursor, with the server's parameters for limit 1 (scan depth
# (limit+1)*8, page limit+1). A cursor (t, '\x') is "below t", the same rows as the legacy cursor.
- id: nl.l1.legacy.judge1
ref: {stmt: old, params: [*nl, "2026-10-18 15:40:39.570+00", null, null, null, null, null, 16, 2]}
cands:
- {stmt: rm, params: [*nl, "2026-10-18 15:40:39.57+00", '\x', 2]}
- {stmt: end, params: [*nl, "2026-10-18 15:40:39.57+00", '\x', 2]}
key: [site_heard_at]
allowed: [tie_order, saturated_suffix, latest_observer_tie]
omit: &latest [latest_observer_id, latest_observer_name, latest_observer_iata, latest_observer_path_length_byte,
latest_observer_hash_size, latest_observer_hop_count, latest_observer_path_bytes]
saturated: {flag: scan_saturated, floor: scan_floor}
expect: {rm: different, end: same}
- id: nl.l1.legacy.judge2
ref: {stmt: old, params: [*nl, "2026-10-18 15:24:51.737+00", null, null, null, null, null, 16, 2]}
cands:
- {stmt: end, params: [*nl, "2026-10-18 15:24:51.737+00", '\x', 2]}
key: [site_heard_at]
allowed: [tie_order, saturated_suffix, latest_observer_tie]
omit: *latest
saturated: {flag: scan_saturated, floor: scan_floor}
expect: {end: same}
# The page cursor (exact microseconds and hash) against the legacy millisecond cursor at a real tie: the
# newest key two packets share to the microsecond. The cand's cursor is (that key, the larger hash), so its
# page leads with the other tied packet, which the legacy page (below the key's millisecond) leaves out. The
# three params are read from the overlay in the batch's snapshot; no tie, and the pair is skipped.
- id: nl.l1.pagecursor.tie
ref:
stmt: old
params:
- *nl
- sql: >-
WITH k AS (SELECT packet_hash, max(site_heard_at) AS k FROM packet_sites
WHERE iata = ANY('{AMS,EIN,ENS,GLZ,GRQ,LEY,LWR,MST,QAR,RTM,UDE,UTC}'::bpchar[])
GROUP BY packet_hash),
t AS (SELECT k FROM k GROUP BY k HAVING count(*) >= 2 ORDER BY k DESC LIMIT 1)
SELECT date_trunc('milliseconds', k) FROM t
- null
- null
- null
- null
- null
- 16
- 2
cands:
- stmt: end
params:
- *nl
- sql: >-
WITH k AS (SELECT packet_hash, max(site_heard_at) AS k FROM packet_sites
WHERE iata = ANY('{AMS,EIN,ENS,GLZ,GRQ,LEY,LWR,MST,QAR,RTM,UDE,UTC}'::bpchar[])
GROUP BY packet_hash),
t AS (SELECT k FROM k GROUP BY k HAVING count(*) >= 2 ORDER BY k DESC LIMIT 1)
SELECT k FROM t
- sql: >-
WITH k AS (SELECT packet_hash, max(site_heard_at) AS k FROM packet_sites
WHERE iata = ANY('{AMS,EIN,ENS,GLZ,GRQ,LEY,LWR,MST,QAR,RTM,UDE,UTC}'::bpchar[])
GROUP BY packet_hash),
t AS (SELECT k, (array_agg(packet_hash ORDER BY packet_hash DESC))[1] AS h FROM k
GROUP BY k HAVING count(*) >= 2 ORDER BY k DESC LIMIT 1)
SELECT h FROM t
- 2
key: [site_heard_at]
allowed: [pagecursor_tie_rows, tie_order, saturated_suffix, latest_observer_tie]
require: [pagecursor_tie_rows]
tie_boundary: 2
tie_cursor: {ts: 2, hash: 3, hash_column: packet_hash}
omit: *latest
saturated: {flag: scan_saturated, floor: scan_floor}
expect: {end: allowed}
# Control: a shape where rm is right, so a diff that flags everything would show here.
- id: nl.l50.first
ref: {stmt: oracle, params: [*nl, infinity, '\x', 51]}
cands:
- {stmt: rm, params: [*nl, infinity, '\x', 51]}
- {stmt: end, params: [*nl, infinity, '\x', 51]}
key: [site_heard_at]
expect: {rm: same, end: same}