Skip to content

feat(scope-audit): transport view of every repeater seen forwarding (#2142, API) - #8

Closed
A13xB0 wants to merge 4 commits into
masterfrom
feat/2142-scope-transport-api
Closed

A13xB0 wants to merge 4 commits into
masterfrom
feat/2142-scope-transport-api

Conversation

@A13xB0

@A13xB0 A13xB0 commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

Backend half of upstream issue Kpa-clawbot#2142 (the page is a separate, stacked PR).

GET /api/scope-audit lists only repeaters that have answered a declared-regions request: 17 of almost 200 nodes on the instance the request came from. This adds a transport view, GET /api/scope-audit?mode=transport&window=…[&scope=X], with one row per repeater seen forwarding in the window:

  • transported: the named region scopes it was seen carrying, each with packets and first/last seen (most packets first), plus unscoped, unmatched and ambiguous-hop counts;
  • asked, declaredRegions, notObserved, configState, declaredAt where a declared answer exists; asked: false with null declared fields where it does not ("not asked" is not "declares nothing");
  • with scope=X (spelled sco, #sco or SCO): carriesScope on every row and carrying / notCarrying counts, which is the rollout report the issue asks for.

mode=declared (or no mode) is unchanged. An unknown mode is a 400.

Partial fix for Kpa-clawbot#2142: this PR provides the API; the page is the stacked PR. The issue should only be considered done once both are in.

How it follows the issue's notes

  • The scan does not change. It is the same single ScopeAuditForwarding pass, with every repeater and room in nodes (plus any declared target) as a target instead of only the declared ones. Same attribution rules: FLOOD-family route types only, minForwarderHopHexLen (no 1-byte hops), and a hop whose prefix matches more than one repeater is credited to none of them.
  • Identity lookup with 1,000+ pubkeys: scopeAuditNodeIdentities runs one IN query; exercised at 1,200 keys in the benchmark below.
  • Row count and response size: measured below.
  • Cache: the transport view is cached per window with the declared view's TTLs (30 s; 5 min for 7d), under the same singleflight group with a transport| key. The scope filter is applied to a copy of the cached result, so one scan serves every scope. (scope=, not region=: across the API region= is the observer IATA filter.)
  • Wording: "transported" is documented as seen carrying, not configured for; the declared side stays separate.

Performance

BenchmarkComputeScopeTransport: 1,200 repeaters (Kpa-clawbot#1975 quotes an instance with 1,179), 30k flood transmissions in the last 24h on 4-hop paths of 3-byte prefixes, a third region-scoped:

BenchmarkComputeScopeTransport-12   5   219253727 ns/op   425.4 response-KB   1200 rows

219 ms per compute, served from cache for 30 s (24h) or 5 min (7d); a 425 KB uncompressed response for 1,200 rows. This is new code with no "before"; the declared view's numbers are untouched (same scan, same cache).

On real data (pre-prod: a copy of the production database and the live feed)

request rows result time
declared view, 24h 16 (unchanged)
mode=transport, 24h 385 repeaters seen forwarding, 16 of them with a declared answer 1.5 s cold
mode=transport&scope=eng-ne, 7d 664 51 carrying eng-ne, 613 not 14.4 s cold
mode=transport&scope=%23SCO, 7d (same window, now cached) 664 sco: 237 carrying, 427 not 0.35 s

The 7d cold compute is the same full-window hop scan the declared view already pays for 7d (its own TTL comment measures 16.7 s on a live-shaped database); like the declared view it is then cached for 5 minutes, and every scope filter is served from that one scan.

  • Commit c08c5026 renamed the filter from region= to scope= after opening (see the comment below); the real-data figures above were taken before the rename and are otherwise the same code.

Tests

  • Red commit b2e10dba: response types and a mode=transport stub that returns no rows, plus tests. Four fail on the stub:
    • repeaters that never answered are listed with asked: false and null declared fields (and the answered one with its declared list and notObserved);
    • scope=fr / %23fr / FR marks carriers and non-carriers and counts them; no scope means no carriesScope or counts;
    • an unknown mode is a 400;
    • the transport and declared views are cached separately (requesting one does not serve the other).
  • Also added, passing on the stub by construction: a repeater with no traffic in the window is not listed; the node blacklist applies.
  • Green commit 4133ae40: the implementation, docs/api-spec.md (new mode and scope parameters, a Transport view section with the response shape), and the benchmark.
  • make test: 16 of 16 modules pass, including every existing scope-audit test.

Review notes

  • Hidden-name and blacklist filtering use the same rules as the declared view.
  • newTestStoreWithDB now takes testing.TB so the benchmark can use it (callers unchanged).
  • No new map[string]interface{}; the response is a named struct.
  • No config added.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KaR4xu8gVykQBkH8yG8m6H

@A13xB0

A13xB0 commented Oct 10, 2026

Copy link
Copy Markdown
Owner Author

Change after opening (commit c08c5026):

  1. The transport view's filter is now ?scope= (response field scope, per-row carriesScope), not ?region=. Across the API region= is the observer IATA filter, and the Scope Audit is about to get that filter too, so the two must not share a name. docs/api-spec.md and the tests are updated; behaviour is otherwise unchanged.

@A13xB0

A13xB0 commented Oct 10, 2026

Copy link
Copy Markdown
Owner Author

This branch has been updated before going upstream:

  • rebased onto master (673442c);
  • test examples made generic (SJC/SFO/LAX, #be scopes);
  • SonarLint fixes added.

It's submitted upstream as Kpa-clawbot#2167. The description here predates those changes; the upstream one is current.

A13xB0 and others added 4 commits October 10, 2026 18:20
…rding (Kpa-clawbot#2142)

The scope audit only lists repeaters that have answered a declared-regions
request. Kpa-clawbot#2142 asks for a transport view: every repeater seen forwarding in
the window, the region scopes it carried, its declared regions where known
("not asked" otherwise), and a region filter for tracking a rollout.

Adds ScopeTransportRow / ScopeTransportResponse, a ?mode=transport stub that
returns no rows, and tests: repeaters that never answered are listed with
asked=false and null declared fields, repeaters with no traffic are left out,
region=X (spelled fr, #fr or FR) marks carriers and non-carriers and counts
them, the blacklist applies, an unknown mode is a 400, and the two views are
cached separately. Four fail on the stub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaR4xu8gVykQBkH8yG8m6H
…pa-clawbot#2142)

GET /api/scope-audit?mode=transport lists one row per repeater the
forwarding scan attributed traffic to in the window, whether or not it ever
answered a declared-regions request:

- transported: the named region scopes it was seen carrying, with packet
  counts and first/last seen (most packets first), plus unscoped, unmatched
  and ambiguous-hop counts;
- asked / declaredRegions / notObserved / configState / declaredAt where a
  declared answer exists, null where it does not ("not asked");
- region=X (with or without '#', any case) adds carriesRegion per row and
  carrying / notCarrying counts: the rollout report.

Same single ScopeAuditForwarding scan and attribution rules as the declared
view (FLOOD-family routes, no 1-byte hops, ambiguous hops credited to nobody),
with every repeater and room in nodes as a target. Cached per window with the
declared view's TTLs, under the same singleflight group; the region filter is
applied to a copy of the cached result. An unknown mode is a 400. Documented
in docs/api-spec.md.

BenchmarkComputeScopeTransport (1,200 repeaters, 30k flood transmissions in
24h, 4-hop paths): 219 ms per compute, 1,200 rows, 425 KB response.

newTestStoreWithDB now takes testing.TB so benchmarks can use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaR4xu8gVykQBkH8yG8m6H
…egion=

Across the API, region= is the observer IATA filter (/api/nodes,
/api/packets, ...). The transport view used region= for a region SCOPE
(be, be-van), which would collide with adding the observer filter to the
scope audit. It is now ?scope=, echoed as "scope", with carriesScope on each
row; carrying / notCarrying are unchanged. Tests and docs/api-spec.md
updated to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaR4xu8gVykQBkH8yG8m6H
…r, row and sort helpers

SonarLint S3776 (cognitive complexity 41 > 15). Same response; the
transport tests are unchanged and pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaR4xu8gVykQBkH8yG8m6H
@A13xB0
A13xB0 force-pushed the feat/2142-scope-transport-api branch from 060668b to bb056a1 Compare October 10, 2026 17:22
@A13xB0 A13xB0 added live: pre-prod In the image running on CoreScope pre-production upstream: merged Merged into Kpa-clawbot/CoreScope master labels Oct 10, 2026
@A13xB0

A13xB0 commented Oct 10, 2026

Copy link
Copy Markdown
Owner Author

Merged upstream as Kpa-clawbot#2167 (2026-10-10T19:22:20Z). Closing; master will be synced from upstream.

@A13xB0 A13xB0 closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

live: pre-prod In the image running on CoreScope pre-production upstream: merged Merged into Kpa-clawbot/CoreScope master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant