Skip to content

Compare observers against a pinned reference - #2492

Merged
efiten merged 12 commits into
Kpa-clawbot:masterfrom
n30nex:codex/reference-fleet-20261126
Dec 1, 2026
Merged

efiten merged 12 commits into
Kpa-clawbot:masterfrom
n30nex:codex/reference-fleet-20261126

Conversation

@n30nex

@n30nex n30nex commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #671. Compare pins one observer and reports distinct receptions, bidirectional overlap percentages and paired SNR for each peer over 24 hours. Regions filter peers while preserving the reference denominator. Results are cached per pin for 30 seconds.

Reach and reference comparisons now share two of the four SQLite readers. Eight distinct cold requests can queue for up to three seconds. A full or expired queue returns 429 with a two-second retry interval; the page offers a retry for the same selection. A failed or panicking worker releases its reservation. The comparison SQL deadline starts after admission and allows 45 seconds within the server’s 60-second write timeout.

Paired real-handler measurements on 6 million synthetic observations, 800,000 in the window, with 60 observers. Two Reach reports and two comparisons succeeded in all three runs per revision.

Median Previous Shared limit
Two ordinary indexed reads during the burst 345 ms 0.51 ms
Completion of all four reports 1.22 s 1.42 s
Fresh-pool comparison 1.00 s 1.04 s

OS file caching was uncontrolled. One first scan hit its deadline during a separate CPU-saturated run. The maintainer measured 15–19 s cold on their machine.

Chromium retried into the actual server. The independent SQLite calculation matched all 1,190 peer rows. Shared-budget regression

@n30nex

n30nex commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Review feedback addressed (commit d3cad1efb).

  1. Clearing a pending pair now shows the selection prompt and updates its bookmark. Late responses leave that state intact.
  2. Region changes and mode switches preserve shared theme and embed settings. Tests cover an empty region and zero versus missing SNR.
  3. Matching observer names show distinct receiver IDs in the reference picker and table.

Kent Beck Gate: PASS (test quality) on d3cad1efb. All 15 focused browser checks passed locally. Workflow for this revision

@efiten

efiten commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Thanks, the feature works and the deep link (ref, mode, region) round-trips.

One blocker on the new endpoint (AGENTS.md rule 0): cmd/server/observer_comparison.go:60-81 runs the full 24-hour aggregate over observations on every request, with no cache or singleflight, on the 4-connection pool (cmd/server/db.go:166). region only filters the final observer rows, so it does not shrink the scan, and every region toggle in the UI sends a new request (public/compare.js:193, :346).

Measured on a local DB with the production indexes and ANALYZE:

observations total / in window first call warm median
400k / 50k (the PR's scale) 111 ms 108 ms
6M / 800k 5.68 s 1.67 s

With 8 concurrent comparison calls, an unrelated query on the same pool waited 2.12 s for a connection.

Suggested fix, following #1910 (statsSF and observersCacheV2 in routes.go): a short-TTL, bounded cache plus singleflight keyed on ref only, computed for all observers, with the region filter applied in Go on the cached rows. Please add a timing at a realistic in-window size to the PR body.

Smaller notes, optional here: the peer table has no cap or paging (public/compare.js:354); the new frontend helpers have only E2E coverage, all of it with a mocked endpoint; and the #671 E2E steps went into the #1640 test file.

@n30nex
n30nex marked this pull request as draft November 27, 2026 21:54
@n30nex

n30nex commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Review feedback addressed (commit dcfa2a4d2).

  1. Regions share a 30-second snapshot keyed by reference. The cache retains 16 references and reserves pool capacity by admitting two distinct cold scans. Additional cold pins receive 429 with Retry-After.
  2. On 6M observations with 800k in the window, nine region toggles fell from 873 ms median to under 1 ms. Eight callers sharing a cold pin ran one scan, and all eight succeeded. An unrelated indexed read went from 1,185 ms to 1.13 ms. The PR body includes fresh-pool timings and sample counts.

@n30nex

n30nex commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Review feedback addressed (commit 1e9074ba8).

  1. When both scan slots are busy, Compare shows a retry control for the current pin and region. It becomes available after the advertised wait. Changing selection or leaving the page clears it.
  2. A browser control returned 429 once, then passed the retry to the real server. The table recovered with the same bookmark and two requests in total.

Kent Beck Gate: PASS (test quality) on 1e9074ba8. Tests before the retry fix

@n30nex
n30nex marked this pull request as ready for review November 27, 2026 23:13
@efiten

efiten commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks, this fixes the blocker. I re-measured at 6M observations with 800k in the window: a cache hit and a region toggle take under 1 ms, 8 cold calls on the same pin run one scan, and an unrelated read stays under 1 ms while 8 distinct pins are cold. The cache is bounded, -race -count=20 is clean, and no slot leaks on error or cancel.

One design point (cmd/server/observer_comparison.go:31, :117-120): comparisonScanLimit = 2 is a second "half the pool" budget next to reach's reachColdBuildLimit = 2 (node_reach_cold_limit.go:38). Together they can hold all 4 connections (db.go:166). This one also sheds with 429 immediately, where reach queues for 3 s first. I read that from the code and did not measure it. Could both share one limiter (generalise reachColdLimiter), or at least give the comparison the same short queue before it sheds?

Smaller notes: the scan goroutine has no recover (:123-137). The 30 s scan timeout (:32) is close to what a first scan took here in a fresh process: 15 to 19 s, against the 929 ms in the PR body. And the retry E2E mocks both attempts (test-issue-1640-compare-discovery-e2e.js:301-311), so it does not reach the real server.

@n30nex
n30nex marked this pull request as draft November 29, 2026 17:13
@n30nex

n30nex commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Review feedback addressed (commit fc98bf1b4).

  1. Reach and pinned comparisons now share two of the four SQLite readers. Eight distinct requests can wait up to three seconds. Failed workers release their reservations. Concurrent callers for one pin share the same scan.
  2. On six million observations, two ordinary indexed reads took 0.51 ms during a mixed burst, down from 345 ms. All four reports completed in 1.42 s, up from 1.22 s. A separate CPU-saturated run hit the 45-second deadline. The browser preserved the selection across a busy response and retry.

@n30nex

n30nex commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Kent Beck Gate: PASS (test quality) at fc98bf1b4. Two blocked Reach reports left two SQLite connections for ordinary reads. An independent caller still got its comparison after the first caller cancelled. The timeout and panic cases both allowed the next request to complete. Chromium also retried a real 429 successfully.

@n30nex
n30nex marked this pull request as ready for review November 29, 2026 18:06

@zfouts zfouts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at fc98bf1b. Approving: efiten's earlier points are all addressed at this head.

  • One cache entry and one in-flight scan per reference; region filtering happens on the cached rows.
  • Node Reach and the comparison share coldScans, including the 3 s queue before a 429.
  • The scan goroutine recovers from a panic, and the panic test shows the queue place, slot and in-flight entry are all released.
  • The 45 s timer starts only once a slot is free, so the worst case (3 s + 45 s) stays under the 60 s WriteTimeout.

I traced the limiter on every path (fast slot, queued, cancelled, timed out, panic); each token is handed on or released exactly once. go test -race -count=3 -run 'ObserverComparison|Reach|ColdScan|ReadOnly' and tests/unit/test-compare-overlap.js pass locally.

Non-blocking, for a follow-up if you agree:

  1. A failed scan isn't cached (cmd/server/observer_comparison.go:145-149). On a slow host, a scan that hits the 45 s deadline returns a 500 with "context deadline exceeded" to every waiter, and the next click starts another 45 s scan holding one of the two shared slots, so Reach gets 429s in the meantime. Caching the failure for ~10 s, or answering 503 with Retry-After, would stop that.
  2. The 3 s queue belongs to the loader, not the caller (observer_comparison.go:156). A request that joins an in-flight load at 2.9 s can get a 429 almost at once. Harmless with the retry button; just worth knowing when the docs say "3 s".
  3. Wording: writeReachColdBusy429 (analytics_cold_limit.go:170-176) still says "reach is busy computing other reports", but the busy scan may now be a comparison.
  4. A screenshot of the Reference comparison mode in the PR would help the next reviewer, and indexFleetNames/observerLabel in compare.js have only mocked E2E coverage, no unit test.

@efiten
efiten merged commit 84eb4ac into Kpa-clawbot:master Dec 1, 2026
17 checks passed
zfouts added a commit to zfouts/CoreScope that referenced this pull request Dec 1, 2026
Conflict resolutions:
- cmd/server/store.go ingestNewFromDB: keep both. Each transmission is
  still redacted once (redactLocatedAdvert); master's per-observation
  observedFrameEvidence (Kpa-clawbot#2497) runs on the observation's own frame
  before it is dropped, so it reads exact bytes but keeps only the hop
  width and reception kind.
- cmd/server/store.go nodeZeroHopRegionCounts: take master's version,
  which moved the frame checks into StoreObs.receivedDirectAdvert. Its
  legacy-singleton fallback read packetpath.AdvertRouteEvidence(tx.RawHex),
  which is empty for a located advert under privacy, and the evidence
  needs the payload length, so frameHead cannot supply it. hiddenFrame now
  keeps routeEvidence (computed from the whole frame at redaction) and
  receivedDirectAdvert reads tx.frameRouteEvidence(). Test:
  TestRedactZeroHopLegacySingletonParity.

Follow-ups for master's changes:
- TestLocationLeakRoutes: classify GET /api/analytics/observer-comparison
  (Kpa-clawbot#2492). It returns observer IDs, names, reception counts and SNR
  deltas, no position.
- packet_redact_frames_test.go: ingestNewFromDB takes a clientCount (Kpa-clawbot#2511).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zfouts added a commit to zfouts/CoreScope that referenced this pull request Dec 2, 2026
… and the advert reception changes to Postgres

Brings in 10 master commits: Kpa-clawbot#2366 (catalogue key tier), Kpa-clawbot#2497 (regions
count only received adverts), Kpa-clawbot#2498 (archived foreign-advert flags), Kpa-clawbot#2492
(observer comparison), Kpa-clawbot#2511, Kpa-clawbot#2513, Kpa-clawbot#2514, Kpa-clawbot#2517, Kpa-clawbot#2518, Kpa-clawbot#2519.

Conflicts:
- cmd/ingestor/approved_channels.go: both sides added a mutex to
  channelKeySet. One mu now serialises refresh, master's setCatalog and the
  branch's Close, and guards the users.db/Postgres accounts readers as well
  as master's approvedNames and catalogue tier.
- cmd/ingestor/db.go, nodes upsert: master's foreign_advert carry-over on
  top of the branch's qualified columns and lastSeenClampSQL. Master looked
  up the archived flag with ?1, which dbx.Rebind turns into $11 on Postgres;
  it is now a plain ? bound to the public key again, and the EXISTS is
  wrapped in CASE so Postgres stores 0/1 in the BIGINT column.
- cmd/ingestor/db.go, MoveStaleNodes: master's UPDATE that restores an
  archived foreign flag runs before the branch's portable moveStaleNodesSQL
  (not master's INSERT OR REPLACE ... SELECT *), with IS DISTINCT FROM 1
  instead of the SQLite-only IS NOT 1.

Ported to Postgres:
- catalog_keys (Kpa-clawbot#2366): pgschema migration 0004_catalog_keys.sql (same
  columns, CHECKs, defaults and key; LatestVersion 4), the table in
  sqlite_endstate.sql, and the worker's upsert sets updated_at from
  excluded.updated_at instead of strftime('%s','now').
- corescope-migrate copies catalog_keys and verify never prints
  catalog_keys.key_hex (channel secrets), for any store.
- GetNodes region filter (Kpa-clawbot#2497) and the observer comparison (Kpa-clawbot#2492) used
  IS NOT 'tx'; both use IS DISTINCT FROM 'tx'. The comparison's
  ORDER BY label COLLATE NOCASE is lower(<label expression>) on Postgres,
  which folds ASCII only under COLLATE "C", as NOCASE does.
- docs/catalogue-keys.md: the revert SQL on PostgreSQL.

Tests on both backends:
- The catalogue key tests that use a store and the Kpa-clawbot#2498 foreign-advert
  tests run on SQLite and Postgres (onBothStores; insertTx uses RETURNING).
- New dual tests for the observer comparison and the GetNodes region filter.
- pgschema: an upgrade from version 3 with data; the control migration tests
  no longer assume 3 is the latest version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zfouts added a commit to zfouts/CoreScope that referenced this pull request Dec 2, 2026
The SQLite-only forms master brought in this round (Kpa-clawbot#2492, Kpa-clawbot#2497, Kpa-clawbot#2498,
Kpa-clawbot#2366) and in the last one (Kpa-clawbot#2486) were only caught by Postgres test runs.
The ingestor's portable-SQL guard now also rejects IS NOT with a number,
numbered placeholders (dbx.Rebind turns ?1 into $11) and strftime; the
server gets a guard for IS NOT with a literal and numbered placeholders.
Both scanners have self-tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: reference observer comparison — compare packet overlap with a known-good observer

3 participants