← Back to Pull requests

feat(r76): broadcaster memory telemetry, a telemetry audit and PoP telemetry (R77) #563

Merged
tuhokuutio[bot] merged 77 files (4843 lines) on Oct 24, 2026 14:01 UTC
View on GitHub
tuhokuutio[bot] tuhokuutio[bot] commented on Oct 24, 2026 12:41 UTC
Author

What and why

Started from a report: the Windows broadcaster went from about 250 MB to almost 750 MB after switching Delivery to Reliable mid-stream, and telemetry could show neither the step nor the baseline. Three milestones followed.

R76 — broadcaster memory, measured ([docs/77](docs/77-broadcaster-memory.md))

  • A lab run ruled out the Reliable send path: the engine's real sender and transport stay flat at 7–10 MB in both modes, clean, lossy and over-capacity (docs/77 M1). So this PR measures; it does not reduce.

  • The native broadcasters (Windows, macOS, Linux, iOS) report the footprint in the OS task manager's own figure, the Rust heap (counting allocator), GPU memory (DXGI on Windows, the graphics ledger on Apple) and five component gauges, on every sample and in Copy diagnostics.

  • Owner decisions: a 100 MB budget while live, and a full per-component breakdown. memory-over-budget and memory-growth warn (never bad).

  • A native session's samples stopped after about 90 minutes, when the 4 MiB per-session budget ran out. The budget is now 16 MiB in both clients, and a minute memory event outlives it.
  • Telemetry audit (docs/77 D12–D16)

  • The stored row now carries the Delivery setting, uplink mode and congestion controller (they were raw-window only), and the counters today's engine sends in lowerCamelCase (sentFrames, keyframeIntervalMs, the carrier counters, … were never rolled up). Parity is typed for broadcasters.

  • New events: delivery-changed, uplink-warning, uplink-loss, network.

  • Fix: a web viewer following an offer to a PoP kept posting the PoP connection's stats under home's telemetry session (test written first, watched fail).

  • Fix: home counted a PoP uplink leg's loss as the broadcaster's uplink, in totals, metrics and leg-a-broadcaster-uplink. The publisher is now marked publisherKind: "pop-leg", its loss has its own pop_leg_ingress_* family, and pop-uplink-leg names the venue's line.
  • R77 — PoP telemetry ([docs/78](docs/78-pop-telemetry.md))

  • Home mints a PoP's tokens over its link, scoped to what the PoP serves and rate-limited; the fleet key never reaches a PoP, and gawk-relay refuses -telemetry-key.

  • The PoP's issuer key rides inside the token's nonce, under the existing tag: no token format or client change.

  • The PoP's relay-side view reaches the telemetry service through home's ops listener (/internal/telemetry/pops, not /statusz, which is also public).

  • Every relay join filters by issuer, so a party broadcast's home and PoP observations never cross.
  • Commits are split per component for release-please: gawk-broadcast-desktop, gawk-ios (shared engine), gawk-server, gawk-telemetry, gawk-app, docs.

    Verification

  • gawk-server: go vet ./..., go test ./... green. New: wire issuer tests (golden token unchanged), hub TestAPopLegsIngressIsItsOwnLeg, metrics TestLossAttributionByLeg, fleet tests TestPopSessionsGetHomeMintedTelemetry, TestHomeMintsOnlyWithinScopeAndRate, TestAPopOfAHomeWithoutTelemetrySendsNoHello, config relay refusal. The pop-leg assertion was checked to fail without the change.

  • gawk-telemetry: go vet ./..., go test ./... green; stored-shape golden extended (additive only). TestSessionsJoinOnlyTheRelayThatServedThem fails without the issuer filter.

  • gawk-app: vitest run 1838 passed; oxlint, tsc -b clean.

  • gawk-broadcast-desktop: cargo test --workspace, cargo clippy --workspace --all-targets -D warnings, cargo fmt --check on Linux; cargo xwin clippy --workspace --target x86_64-pc-windows-msvc -D warnings.

  • gawk-admin, gawk-sampler: build and vet against the changed gawk-server.

  • Not run here: macOS and iOS builds (no Apple SDK on this host; the Apple FFI type-checks with rustc --target aarch64-apple-ios) — the macos and ios.yml jobs are the first compile. No hardware pass: the numbers against Task Manager / Activity Monitor (docs/77 MM5) and a real party end to end (docs/78) are open.
  • Checklist

  • Title is a Conventional Commit, with the right type and scope

  • Commits are signed off (git commit -s)

  • Tests for anything behavioral; for a bug fix, the test was written first and watched to fail

  • Docs updated where the change makes them wrong — docs/77, docs/78, docs/76, docs/33, docs/13, ROADMAP.md, docs/gotchas.md

  • THIRD-PARTY-NOTICES.md regenerated if dependencies changed — no dependency changes
  • 🤖 Generated with Claude Code

    Diff: 4843 lines (+4724 / -119) across 77 files Reviewer: claude[bot] Review duration: 80m
    All Vouch review confidence checks passed
    Residual risk 0.31 = Change Risk (0.72) × (1 − Review Confidence (0.56)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.72 · 4843 lines diff across 77 files
    0.72
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.25 · 3 substantive comment(s)
    0.25
    Model 3 · Review Timing & Attention
    Session adequacy: 66% · Reviewer familiarity: 50%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Shallow Review Depth shallow_review_depth
    0.264
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    4 items
    claude[bot] claude[bot] commented on code on Oct 24, 2026 12:46 UTC
    Code Review
    gawk-server/internal/popclient/telemetry.go:1
    @@ -0,0 +1,217 @@
    +package popclient
    +
    +// The PoP's side of R77 (docs/78): telemetry identities minted by home
    +// (D1, D5), and the PoP's relay-side view sent home (D7).
    +
    +import (
    +	"context"
    +	"encoding/hex"
    +	"encoding/json"
    +	"errors"
    +	"sync"
    +	"time"
    +
    +	"github.com/Tuhis/gawk/gawk-server/internal/poplink"
    +	"github.com/Tuhis/gawk/gawk-server/wire"
    +)
    +
    +const (
    +	// telemetryPoolSize is how many tokens a pool asks for at a time, and
    +	// telemetryPoolLow the level below which it asks again (D5): a session
    +	// takes one from the pool without a round trip home.
    +	telemetryPoolSize = 4
    +	telemetryPoolLow  = 2
    +	// telemetryRetry is how soon a refused pool asks again: a new party
    +	// broadcast's reservation, or a downlink viewer's leg slot, reaches the
    +	// link-home pod a moment after the session starts, and a scope refusal
    +	// in that moment is not the answer (docs/78 D5).
    +	telemetryRetry = 500 * time.Millisecond
    +	// telemetryPoolIdle drops a pool nobody has drawn from in this long.
    +	telemetryPoolIdle = 10 * time.Minute
    +	// telemetryObsBudget keeps a TelemetryObs record well under
    +	// poplink.MaxRecordBytes.
    +	telemetryObsBudget = 48 << 10
    +)
    +
    +type telemetryPool struct {
    +	broadcastKey []byte
    +	tokens       [][]byte
    +	asked        bool // a TelemetryMint is outstanding
    +	refused      bool // home refused the last one
    +	refusedAt    time.Time
    +	used         time.Time
    +	ready        chan struct{} // closed and replaced when tokens or a refusal arrive
    +}
    +
    +type telemetry struct {
    +	c     *Client
    +	mu    sync.Mutex
    +	pools map[string]*telemetryPool
    +}
    +
    +func newTelemetry(c *Client) *telemetry {
    +	t := &telemetry{c: c, pools: map[string]*telemetryPool{}}
    +	c.OnRecord(poplink.TTelemetryTokens, func(rec any) {
    +		if r, ok := rec.(*poplink.TelemetryTokens); ok {
    +			t.tokens(r)
    +		}
    +	})
    +	c.OnRecord(poplink.TTelemetryRefused, func(rec any) {
    +		if r, ok := rec.(*poplink.TelemetryRefused); ok {
    +			t.refused(r)
    +		}
    +	})
    +	return t
    +}
    +
    +func poolKey(id string, role wire.TelemetryRole) string { return id + "/" + string(role) }
    +
    +// TelemetryHello implements transport.PopTelemetry (docs/78 D5).
    +func (c *Client) TelemetryHello(ctx context.Context, id string, role wire.TelemetryRole) (wire.TelemetryHello, string, bool) {
    +	cfg := c.State().Config
    +	if cfg == nil || cfg.Telemetry == nil {
    +		return wire.TelemetryHello{}, "", false
    +	}
    +	tc := *cfg.Telemetry
    +	tok, bk, ok := c.tel.take(ctx, id, role)
    +	if !ok {
    +		return wire.TelemetryHello{}, "", false
    +	}
    +	return wire.TelemetryHello{
    +		Enabled:          true,
    +		ReportIntervalMs: max(tc.ReportIntervalMs, 250),
    +		Token:            tok,
    +		BroadcastKey:     bk,
    +	}, tc.AdvertiseURL, true
    +}
    +
    +// take hands out one token for (id, role), asking home for more when the
    +// pool runs low, and waits for them until ctx is done when it is empty.
    +func (t *telemetry) take(ctx context.Context, id string, role wire.TelemetryRole) ([]byte, []byte, bool) {
    +	key := poolKey(id, role)
    +	for {
    +		t.mu.Lock()
    +		t.sweepLocked()
    +		p := t.pools[key]
    +		if p == nil {
    +			p = &telemetryPool{ready: make(chan struct{})}
    +			t.pools[key] = p
    +		}
    +		p.used = time.Now()
    +		if len(p.tokens) < telemetryPoolLow && !p.asked && (!p.refused || time.Since(p.refusedAt) >= telemetryRetry) {
    +			p.asked = true
    +			p.refused = false
    +			if err := t.c.Send(poplink.TelemetryMint{ID: id, Role: string(role), N: telemetryPoolSize}); err != nil {
    +				p.asked = false
    +				if errors.Is(err, ErrNotLinked) && len(p.tokens) == 0 {
    +					t.mu.Unlock()
    +					return nil, nil, false
    +				}
    +			}

    Bug: once a mint request goes unanswered, its pool stops asking for tokens.

    p.asked is set here after a TelemetryMint is sent successfully. Only a TelemetryTokens or TelemetryRefused reply for this pool clears it again. There is no timeout, the 500 ms retry timer only re-runs this loop, and the pools live on c.tel, which outlives relinks.

    Home doesn't always answer:

  • The link can drop after the request is written, for example on a home rolling update or a 4002 drain. The old pod's mint then finds local(pop) == nil and returns without replying, or its SendToLink fails.

  • mint also returns silently when the hex decode or MintTelemetrySessionTokenForIssuer fails.

  • On the PoP side, tokens() returns early on a malformed BroadcastKey, before it clears asked.
  • https://github.com/Tuhis/gawk/blob/b4e5e30326bc3c66d2ef5bee7bc367d24ade01d0/gawk-server/internal/popsrv/telemetry.go#L121-L125

    In any of these cases the pool keeps asked = true and never sends another request. Once its remaining tokens are used up, every new session on that broadcast and role waits the full popTelemetryWait and sends no telemetry hello. The idle sweep never removes the pool either, because take() refreshes p.used on every call. A busy broadcast loses PoP telemetry for as long as sessions keep arriving.

    Suggested fix: store an askedAt time and treat asked as expired after a few telemetryRetry intervals, or reset asked on every pool when the link comes back up. Also have home's silent error paths send a TelemetryRefused reply.

    tuhokuutio[bot] tuhokuutio[bot] commented on code on Oct 24, 2026 12:50 UTC
    Code Review
    gawk-server/internal/popclient/telemetry.go:1
    @@ -0,0 +1,217 @@
    +package popclient
    +
    +// The PoP's side of R77 (docs/78): telemetry identities minted by home
    +// (D1, D5), and the PoP's relay-side view sent home (D7).
    +
    +import (
    +	"context"
    +	"encoding/hex"
    +	"encoding/json"
    +	"errors"
    +	"sync"
    +	"time"
    +
    +	"github.com/Tuhis/gawk/gawk-server/internal/poplink"
    +	"github.com/Tuhis/gawk/gawk-server/wire"
    +)
    +
    +const (
    +	// telemetryPoolSize is how many tokens a pool asks for at a time, and
    +	// telemetryPoolLow the level below which it asks again (D5): a session
    +	// takes one from the pool without a round trip home.
    +	telemetryPoolSize = 4
    +	telemetryPoolLow  = 2
    +	// telemetryRetry is how soon a refused pool asks again: a new party
    +	// broadcast's reservation, or a downlink viewer's leg slot, reaches the
    +	// link-home pod a moment after the session starts, and a scope refusal
    +	// in that moment is not the answer (docs/78 D5).
    +	telemetryRetry = 500 * time.Millisecond
    +	// telemetryPoolIdle drops a pool nobody has drawn from in this long.
    +	telemetryPoolIdle = 10 * time.Minute
    +	// telemetryObsBudget keeps a TelemetryObs record well under
    +	// poplink.MaxRecordBytes.
    +	telemetryObsBudget = 48 << 10
    +)
    +
    +type telemetryPool struct {
    +	broadcastKey []byte
    +	tokens       [][]byte
    +	asked        bool // a TelemetryMint is outstanding
    +	refused      bool // home refused the last one
    +	refusedAt    time.Time
    +	used         time.Time
    +	ready        chan struct{} // closed and replaced when tokens or a refusal arrive
    +}
    +
    +type telemetry struct {
    +	c     *Client
    +	mu    sync.Mutex
    +	pools map[string]*telemetryPool
    +}
    +
    +func newTelemetry(c *Client) *telemetry {
    +	t := &telemetry{c: c, pools: map[string]*telemetryPool{}}
    +	c.OnRecord(poplink.TTelemetryTokens, func(rec any) {
    +		if r, ok := rec.(*poplink.TelemetryTokens); ok {
    +			t.tokens(r)
    +		}
    +	})
    +	c.OnRecord(poplink.TTelemetryRefused, func(rec any) {
    +		if r, ok := rec.(*poplink.TelemetryRefused); ok {
    +			t.refused(r)
    +		}
    +	})
    +	return t
    +}
    +
    +func poolKey(id string, role wire.TelemetryRole) string { return id + "/" + string(role) }
    +
    +// TelemetryHello implements transport.PopTelemetry (docs/78 D5).
    +func (c *Client) TelemetryHello(ctx context.Context, id string, role wire.TelemetryRole) (wire.TelemetryHello, string, bool) {
    +	cfg := c.State().Config
    +	if cfg == nil || cfg.Telemetry == nil {
    +		return wire.TelemetryHello{}, "", false
    +	}
    +	tc := *cfg.Telemetry
    +	tok, bk, ok := c.tel.take(ctx, id, role)
    +	if !ok {
    +		return wire.TelemetryHello{}, "", false
    +	}
    +	return wire.TelemetryHello{
    +		Enabled:          true,
    +		ReportIntervalMs: max(tc.ReportIntervalMs, 250),
    +		Token:            tok,
    +		BroadcastKey:     bk,
    +	}, tc.AdvertiseURL, true
    +}
    +
    +// take hands out one token for (id, role), asking home for more when the
    +// pool runs low, and waits for them until ctx is done when it is empty.
    +func (t *telemetry) take(ctx context.Context, id string, role wire.TelemetryRole) ([]byte, []byte, bool) {
    +	key := poolKey(id, role)
    +	for {
    +		t.mu.Lock()
    +		t.sweepLocked()
    +		p := t.pools[key]
    +		if p == nil {
    +			p = &telemetryPool{ready: make(chan struct{})}
    +			t.pools[key] = p
    +		}
    +		p.used = time.Now()
    +		if len(p.tokens) < telemetryPoolLow && !p.asked && (!p.refused || time.Since(p.refusedAt) >= telemetryRetry) {
    +			p.asked = true
    +			p.refused = false
    +			if err := t.c.Send(poplink.TelemetryMint{ID: id, Role: string(role), N: telemetryPoolSize}); err != nil {
    +				p.asked = false
    +				if errors.Is(err, ErrNotLinked) && len(p.tokens) == 0 {
    +					t.mu.Unlock()
    +					return nil, nil, false
    +				}
    +			}

    Confirmed and fixed in 87cb38ad, test first: both new tests failed on the old code (one mint request in 3 s; a malformed answer left the request outstanding).

  • An outstanding request now expires after telemetryAskExpiry (4 × telemetryRetry, 2 s), and the next draw asks again. That covers a request written just before the link dropped, including a 4002 drain or a rolling update. In that case the old pod's local(pop) == nil path has nothing to answer on, which is now commented.

  • tokens() settles the request on any answer, malformed included, before it validates the contents.

  • Home answers its own failures (the hex decode, the mint) with TelemetryRefused{reason: "error"}.
  • Tests: popclient TestAnUnansweredMintIsAskedAgain, TestAMalformedAnswerSettlesTheRequest. The PoP fleet tests still pass. docs/78 D5 records the expiry.

    claude[bot] claude[bot] commented on Oct 24, 2026 12:58 UTC
    Bot

    Code review

    No issues found. Checked for bugs and CLAUDE.md compliance.

    Reviewers
    Assignees
    tuhokuutio[bot] tuhokuutio[bot]
    Labels
    risk: low confidence: 56.4% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.5% (HIGH) · Higher = larger blast radius
    71.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.4% · Lower = rushed or shallow review
    56.4%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 31.1% · Safe to merge
    31.1%
    Repository