Skip to content

armgit / Piik

Public Imported from GitHub
0

Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

docs(route): record converged source runtime

AAAbb5a93112298
diff --git a/docs/adr/0005-automatic-hybrid-media-routing.md b/docs/adr/0005-automatic-hybrid-media-routing.md
index a7db8faf..c91b8459 100644
--- a/docs/adr/0005-automatic-hybrid-media-routing.md
+++ b/docs/adr/0005-automatic-hybrid-media-routing.md
@@ -1,6 +1,6 @@
# ADR-0005: Automatic Hybrid Media Routing
-- Status: Accepted route model; runtime migration pending
+- Status: Accepted; source runtime implemented, production release pending
- Date: 2026-08-20
- Last updated: 2026-08-23
@@ -309,15 +309,8 @@ deployment-wide.
## Current Production Divergence
-Production release `9461e20` predates this revision. Its exact behavior is owned
-by the deployment document. Generation guards, scoped authorization,
-first-decoded-frame transitions, and bounded recovery remain reusable only where they
-satisfy this ADR.
-
-That release remains a deployment fact and rollback reference. It must not be
-merged wholesale into a new route implementation. After this model is merged,
-retained code and tests are transplanted from current `main` by invariant;
-obsolete policy is replaced at its owner.
+Production release `9461e20` predates the implemented source runtime. Its exact
+behavior and rollback boundary are owned by the deployment document.
## Acceptance Boundary
@@ -383,7 +376,7 @@ Positive:
Negative:
-- the deployed controller intentionally diverges until this model is migrated;
+- production intentionally diverges until the implemented source is released;
- make-before-break consumes explicit endpoint and server reservations and may
require a bounded-gap cutover when no overlap slot exists; and
- real SFU/TURN and target-network evidence is still required.
diff --git a/docs/project-memory.md b/docs/project-memory.md
index ae937f2f..e79c0da8 100644
--- a/docs/project-memory.md
+++ b/docs/project-memory.md
@@ -25,7 +25,7 @@ Last updated: 2026-08-23
## Current Source And Production
- Canonical source is the clean `main` branch. New branches and worktrees start from its exact current commit after accepted truth is merged.
-- Current source admits up to `20` Viewers, implements the uniform `1/2/3` endpoint cap through one shared accounting guard, advances Web/server/Native to `screener-v6`, rejects v5 before room authority, and carries the exact deployment cap in every authenticated snapshot so ordinary Host authorization, Native admission, peer-assisted assignments, and sender slots use the same authority. Its SFU-fed-leaf and route-quality behavior still predates the accepted generic reconciliation model. SFU admission uses explicit no-default ingress/egress capacities, exact `reserved | committed | draining` lifecycle accounting, and a listener-fenced dedicated LiveKit owner. Selected TURN uses its own explicit no-default deployment capacity and exact logical-allocation ledger shared by independent peer edges and Host-SFU ingress.
+- Current source admits up to `20` Viewers and implements the uniform `1/2/3` endpoint cap, single Browser `screener-v7` wire, exact prepare candidate, first-decoded-frame commit, strict rollback revision, decoded-progress stall, and one event-driven room controller. Older Browser and executable-sender wires fail before room authority. SFU admission uses exact publication and Viewer-subscription handles with explicit no-default ingress/egress capacities and a listener-fenced dedicated LiveKit owner. Selected TURN uses its own explicit no-default deployment capacity and exact logical-allocation ledger shared by independent peer edges and Host-SFU ingress.
- Production runs exact `9461e207af62b4f38f6b7a8aa16f8beb49e0e4ee`, release `9461e20`, wire `screener-v5`; `21d5cd9f7139` is the rollback release.
- Production still enforces Host downstream `2`, ordinary Browser downstream `1`, deployment values `1/2`, a fixed SFU-root limit of `2`, and legacy publication/selected accounting. This is a dated implementation divergence, not current product policy.
- Production has automatic routing, bad-relay corroboration, peer-quality make-before-break with Viewer and Host provisional parents, selected-edge transport, stable route/connection details, 64/128/256 audio choices, access controls, self-check, diagnostic export, and signaling watchdog behavior.
@@ -35,7 +35,7 @@ Last updated: 2026-08-23
## Current Priority
1. Keep this truth set and [the TODO ledger](./todo.md) concise and internally consistent.
-2. Complete and release the remaining route-controller convergence first. Then release live audio and paused video-codec switching, follow with evidence-led H.264 diagnosis, the strict-NAT emulator gate, connection feedback, and the remaining functional roadmap. Distribution packaging starts only after those TODOs are complete. Parallel branches may finish earlier but do not change this merge/deployment order.
+2. Release the converged Browser route source first. Then release live audio and paused video-codec switching, follow with evidence-led H.264 diagnosis, the strict-NAT emulator gate, connection feedback, and the remaining functional roadmap. Distribution packaging starts only after those TODOs are complete. Parallel branches may finish earlier but do not change this merge/deployment order.
## Working Rules
diff --git a/docs/status.md b/docs/status.md
index e52b6519..436aca14 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -15,17 +15,17 @@ This is the current execution index. Git history owns completed timelines; [veri
- Canonical source is the clean `main` branch; auxiliary branches and worktrees do not own current truth.
- Current source implements one steady outbound media-copy cap for every non-server endpoint: default `2`, static `1/2/3`, a peer child or Host publication consumes one slot, upstream receive is free, a committed selected TURN transport replaces the same copy while hidden carry consumes another, and no Browser/UA/visibility tier exists. One shared guard owns the accounting and transition work is bounded by `min(C + 1, 3)`.
-- Current source and accepted room admission support one Host plus up to `20` Viewers. The route release still requires one 20-Viewer smoke without changing endpoint or server-resource accounting.
-- The v6 release boundary rejects v5 before room authority and carries the exact deployment cap in every authenticated snapshot so ordinary Host authorization, Native admission, peer-assisted child assignments, and sender slots share the server authority. Current `main` still carries the legacy childless-SFU-fed and route-quality slices that the pending generic reconciliation replaces.
+- Current source and accepted room admission support one Host plus up to `20` Viewers. Focused controller coverage includes `C=1/2/3` and a 20-Viewer graph; real Browser resource and media measurements remain release evidence.
+- The single Browser `screener-v7` boundary rejects stale Browser and executable-sender wires before room authority and carries the exact deployment cap plus exact prepare candidate in the authenticated route contract.
- Current source also implements explicit no-default SFU ingress/egress capacities and exact `reserved | committed | draining` accounting. The listener owner reconciles its dedicated non-auto-create LiveKit namespace before serving, creates each generation before token issuance, releases only after delete-plus-absence proof, and reclaims Host-offline generations through bounded exact-participant checks. Selected TURN has an independent explicit no-default deployment capacity; one process-local ledger charges every exact peer-selected edge and Host-SFU ingress through reserve, commit, drain, and release.
-- Automatic P2P-first routing, one active upstream, an acyclic source-reachable graph, exact Browser v7 prepare tuple, first-decoded-frame make-before-break, strict rollback revision, and bounded failure remain accepted.
-- The accepted controller has one event-driven reconciliation loop and at most one room-serial child operation. That object owns one deterministic tuple list/cursor, one current media candidate and reservations, fact version, and one total deadline. Join, exact-edge failure, relay disconnect, and effective-capacity reduction all enqueue that operation. Failed tuples are operation-local; exhaustion retires invalid/overflow edges but retains healthy bootstrap media. Bounded-gap preflights server resources, replans the remaining suffix, and restores a healthy retired edge through one final ordinary candidate. Admission commits synchronously before graph promotion; release uses the resource-set difference and room disposal returns all resources. One Host publication serves exact Viewer subscription handles under the same SFU generation, and actual global SFU/TURN usage release wakes only registered waiting rooms. Endpoint accounting, v6 capability fencing, aggregate generation lifecycle, and TURN admission are in current source; v7 Web wire, exact subscription admission, decoded-progress stall, and runtime controller convergence remain pending.
+- Current source implements automatic P2P-first routing with one active upstream, an acyclic source-reachable graph, exact Browser v7 prepare tuple, first-decoded-frame make-before-break, strict rollback revision, and bounded wait or failure.
+- One event-driven controller owns the committed graph and at most one room-serial child operation. The operation owns one deterministic tuple list/cursor, one current candidate and reservations, fact version, and one total deadline. Failed tuples are operation-local; exhaustion retires invalid/overflow edges but retains healthy bootstrap media. Bounded-gap preflights resources, replans the remaining suffix, and restores a healthy retired edge through one final ordinary candidate. Admission commits synchronously before graph promotion; release uses the resource-set difference and room disposal returns all resources. One Host publication serves exact Viewer subscription handles, selected TURN changes only transport, and actual global resource release wakes registered waiting rooms.
- Parent selection is deterministic rather than random or score-based: hard eligibility filters, then shallowest result, remaining sender capacity, stable join order, and peer identity. The exact candidate child's first new decoded frame is the only application media-ready event. Moderate bitrate, FPS, or visual degradation remains with stock WebRTC/LiveKit adaptation and diagnostics; only hard connection failure or a non-paused decoded-frame stall invalidates a route edge. Viewer connection feedback and the strict-NAT emulator gate are accepted follow-up work, not deployed behavior.
- Live 64/128/256 audio-ceiling mutation and paused-share video codec switching are accepted but not yet implemented on canonical `main`. H.264 startup blur/low-FPS reports remain an evidence-led diagnosis, not a presumed codec defect. Public-server and fully local distribution packages are later work after the functional, NAT, and real-network ledger is complete.
## Current Milestone
-1. Complete and release the audited generic route loop on the single Browser `screener-v7` wire with deterministic parent selection, one first-frame candidate transaction, event-driven SFU/TURN waiter wakeup, and efficient admission through 20 Viewers.
+1. Release the implemented generic route loop on the single Browser `screener-v7` wire after its remaining production acceptance boundary.
2. Release live audio-ceiling mutation and paused-share codec switching on the resulting generation/transition boundary.
3. Reproduce the H.264 startup report before any codec-specific repair, and build the strict-NAT emulator gate before any manually approved canary in an operator-owned test room.
4. Add first-frame-driven Viewer connection stages and finish the remaining accepted functional and real-network work.
@@ -40,7 +40,6 @@ This is the current execution index. Git history owns completed timelines; [veri
## Next Stop
-Implement the minimal controller-convergence wave from the accepted truth checkpoint. The route release
-still requires measured TURN and SFU capacities, a
-dedicated LiveKit instance with the documented private control-plane contract,
-and focused Browser `C=1/2/3` plus 20-Viewer acceptance.
+Complete the route production boundary without repeating the full local suite: one resource-limited
+20-Viewer Browser smoke, production preflight, deploy, postflight, and rollback verification. The
+dedicated LiveKit instance and measured SFU/TURN capacities remain required deployment inputs.
diff --git a/docs/todo.md b/docs/todo.md
index 79ad6e38..114f0d5e 100644
--- a/docs/todo.md
+++ b/docs/todo.md
@@ -6,15 +6,12 @@ Only items in **Now** are executable after their stated decision gate. A branch
## Now
-1. **Route Wave D: one reconciliation loop.** Make the room controller the only committed graph owner. Join, a hard-failed or non-paused decoded-progress-stalled edge, relay disconnect, and effective-capacity reduction enqueue the same room-serial child operation. It owns an operation-local deterministic tuple list/cursor, one current candidate and reservations, fact version, and one total deadline. Browser `screener-v7` prepare names exact child/transport/connection; first-frame ready synchronously commits admission before graph promotion. Failure releases resources and broadcasts `R>P` rollback without resetting the deadline. Exhaustion retires invalid/departed/overflow edges into waiting but keeps healthy bootstrap media. A bounded gap preflights server resources, replans the untried suffix, and adds one ordinary restore candidate for a healthy retired edge. Relay ingress reparent retains its subtree; confirmed departure/cap reduction drain children through the same operation. One Host publication serves exact Viewer subscriptions, TURN only changes transport, and actual global admission release wakes registered waiter rooms once. Pause aborts the candidate and suppresses decoded stall. Keep routing event-driven and edge-local; do not add compatibility paths, proactive scoring, probing, rebalancing, another graph/controller, or executable sender work.
+1. **Release the converged Browser route.** The one-controller `screener-v7` source is implemented, merged, typechecked, and focused-review clean. Do not repeat the full local suite. Run one resource-limited 20-Viewer Browser smoke that records route convergence, first-frame or bounded failure, endpoint sender counts, application CPU/memory, and SFU/TURN usage, then run production preflight, deploy, postflight, and rollback verification. Do not build or run Native, helper, shared-encode, Go test, or hardware executable artifacts.
2. **Switch screen-audio ceilings live.** Keep Opus fixed and serialize 64/128/256 kbps desired profile updates across every current Host, relay, and SFU audio sender. Each endpoint uses fresh `getParameters()`/`setParameters()` readback, ignores stale completions, retains media plus its prior applied value on failure, and applies the latest desired value to future edges. Do not add a remote applied-ack protocol or claim room-wide atomic convergence in this slice.
3. **Switch video codec while paused.** After the route/media-generation boundary is available, serialize the change with route mutation, freeze exact current route/media bindings, hold new joins, renegotiate P2P/relay and republish SFU while paused, then verify actual codec plus decoded frames on resume. A binding invalidated by leave or hard route failure exits this proof set and waits for routing to rebuild from the final committed preference after the bounded codec transaction settles. On failure pause again and perform bounded rollback; rollback proves the prior preference was reapplied plus a newly negotiated actual codec and decoded progress, not literal equality with the old actual codec. Zero targets update only the future-edge preference. Reset `automatic` with empty codec preferences. This is a paused bounded-gap transaction; unpaused make-before-break is a later extension.
4. **Diagnose the production H.264/blur report.** Reproduce exact release `769de201f7cc` against current `main` on the same Host/browser/driver/game and one wired direct Viewer, changing one variable at a time. Implement a codec-specific repair only if codec/encoder evidence identifies it; otherwise fix the proven capture, sender, BWE, or lifecycle cause.
5. **Gate the strict-NAT guessed-candidate experiment.** Build only the isolated endpoint-dependent NAT emulator and browser harness first. Standard ICE must fail in the owned fixture, the capped candidate set must pass the documented repeatability, deadline, privacy, and cleanup gates in stable Chrome and Firefox, and fallback must remain unchanged. Only then may one manually approved, operator-owned test room run a default-off, kill-switched canary with explicit consent from both endpoints and exact room/edge/generation/budget bounds; failure closes the candidate. Do not ship guessed candidates to ordinary rooms or infer NAT type from IP, UA, carrier, or two STUN observations.
6. **Make Viewer connection progress explicit.** Derive one stable stage from existing access, route, peer/SFU, media, autoplay, and bounded-failure state. Keep the overlay until a composited current-generation frame, show `Play` only for actual autoplay rejection, preserve a still-valid old frame during recovery, and expose retry only through the bounded controller. Measure the existing token-free SFU prewarm and route stages before adding another connection mechanism.
-7. **Validate and release in priority order.** Review, merge, and deploy each coherent slice from canonical `main`: route first, then audio/codec mutation, then H.264/NAT evidence and any proven repair, then connection feedback and remaining tools. Before the route release, exercise Browser `C=1/2/3`, effective capacity `0..C`, first-frame commit, `R>P` rollback, stale result, cursor/total deadline, failed-tuple fact reset, exhaustion-to-wait, bounded-gap restore, relay ingress reparent, disconnect/cap drain, SFU publication/subscription reuse, selected TURN, global-admission wake, decoded stall, and pause/resume through focused contract tests plus one resource-limited 20-Viewer browser smoke. Record route depth, first-frame time, endpoint sender counts, server CPU/memory and SFU/TURN usage; keep the one-operation controller event-driven and free of all-pairs probes. Do not build/run Native, helper, shared-encode, Go test, or hardware executable artifacts in this milestone. Run independent review, Web/server builds, production preflight, postflight, and rollback verification.
-
-The existing route implementation is an input, not an integration base. Reuse only scoped authorization, capacity, admission, deterministic-planning, and provisional-media primitives that fit the accepted single-loop model; rebuild the controller from the truth checkpoint rather than carrying role-specific state forward.
## Queued After Route
diff --git a/docs/verification-status.md b/docs/verification-status.md
index bdcb3944..fdd5e1a2 100644
--- a/docs/verification-status.md
+++ b/docs/verification-status.md
@@ -22,6 +22,7 @@ Capacity and routing entries below describe the exact tested source or release o
- Exact source `31e323e2754fcfde15f7b4d69e925ec71e2795cb` passed repository hygiene, TypeScript typecheck, client/server builds, all 660 Web tests, all Native Go packages, `go vet`, and two independent P0/P1 reviews. The tests cover strict v6 endpoint-cap authentication, ordinary active/waiting authorization and grace promotion, Native cap propagation and admission, and peer-assisted cap rejection. This is local state-machine/build evidence, not a complete Native physical-slot matrix or production, browser-quality, or heterogeneous-network acceptance.
- Exact Wave B implementation source `815c6174d411c55648daf5cd6ac4c42f64effff9`, based on `d1ba2e52919225e67ad0c8dd2b660f333fbc88fd`, passed its 372-test SFU-admission gate, all 690 Web tests, TypeScript typecheck, and client/server builds. Focused tests cover reserved/committed/draining accounting, reserve-before-token enforcement, explicit room lifecycle, listener-owner startup fencing, restart cleanup, stale-token replay boundaries, Host-offline reclamation, shutdown races, and two-room global admission. This is fake-control-plane and local state-machine evidence, not a real LiveKit process/JWT replay, packet-flow, multi-process, deployment-capacity, or production proof.
+- Exact route source `4e0a922` passed repository hygiene, TypeScript typecheck, and 84 focused controller, runtime, protocol, transition, decoded-stall, and SFU-admission tests. During the same convergence, the full 557-test Web suite and client/server builds passed before the final no-consumer cleanup. The two independent route audits' model and wire findings are incorporated, and final static review found no remaining P0/P1. No Browser, Native, Go, helper, hardware, or executable test ran in the final pass; this is source and state-machine evidence, not production or heterogeneous-network proof.
- Current source TURN-admission unit and signaling tests cover independent peer and Host-SFU logical edges, shared capacity exhaustion, exact reserve/commit/drain/release identity, current-share cleanup, and graceful shutdown. This is local authorization evidence, not real coturn, network-media, or production-capacity proof.
- Chrome 151 synthetic `1/3/5/8` and 720p30 runs preserved bounded fanout and decoding. A `9461e20`-era three-Viewer rerun kept Host2/Browser Viewer1, decoded every Viewer, and recovered a hard first-level relay departure in 5,380 ms; it did not exercise quality-triggered MBB. Sixteen-Viewer cap2/cap3 loopbacks decoded all Viewers and a ten-second follow-up recorded guarded sender and aggregate Chromium CPU evidence, but resolution/FPS remained low and the ordinary-PC data cannot rank caps, select product policy, or prove sustainable heterogeneous-network quality. See [peer-assisted media](./research/peer-assisted-media.md).
- Chrome 151 with local LiveKit 1.13.5/client 2.22.0 proved one SFU/UDP root after `q,f` -> `q,h`: decoded frames advanced 3 -> 23, rendered frames reached 26, Host used one edge, leaves were clean, and TURN was absent. This is functional evidence only. See [low-server media routes](./research/low-server-media-routes.md).
@@ -35,9 +36,9 @@ Capacity and routing entries below describe the exact tested source or release o
- Routing: verify current-release initial ingress, exact candidate first-frame commit and rollback, `peer-selected` expiry/failure, relay-ingress reparent with subtree retention, disconnect/effective-capacity drain, pause/resume, and bounded failure on real browser/media paths. Silent control partitions may wait 30 to 60 seconds for heartbeat detection before the default five-second grace; a non-paused decoded-frame stall may invalidate only that exact child edge.
- Quality: production startup blur remains unclassified. One same-`balanced` local A/B retained route/PC/SSRC/track while 720p rose to 1080p, but natural ramp prevents causal, production, or SFU conclusions. Correlate Host capture/encode/send with Viewer receive/decode before changing policy.
-- Relay resources: current source has the authenticated `1/2/3` endpoint-cap boundary, while production `9461e20` remains Host2/ordinary Browser Viewer1 and rejects Viewer child2 regardless of advertised capacity. Before release, explicitly exercise Native `C=1/2/3` admission, waiting promotion, peer-assisted assignment, and physical sender slots; CPU/GPU/upload and heterogeneous-network measurements remain evidence, not authority to change the contract.
-- Room scale: accepted admission is 20 Viewers plus one Host; current source and production stop at 16 and 8-by-default respectively. Before route release, update the source bound and run one 20-Viewer smoke for admission, route convergence, first-frame/bounded-failure, endpoint copies, application CPU/memory, and SFU/TURN accounting.
-- SFU: production `9461e20` deploys ordered `q,h`, roots <=2, and Dynacast off. Those are release facts; the accepted model has no fixed root-count or room-wide lease rule. Current source still needs real LiveKit lifecycle/JWT replay and shaped packet-flow, BWE downshift/recovery, resource, and SFU-fed first-child validation. Use Linux `tc` or an authorized public canary for per-leaf shaping, never CDP throttling.
+- Relay resources: current Browser source has the authenticated `1/2/3` endpoint-cap boundary and focused state coverage, while production `9461e20` remains Host2/ordinary Browser Viewer1 and rejects Viewer child2 regardless of advertised capacity. CPU/GPU/upload and heterogeneous-network measurements remain evidence, not authority to change the contract.
+- Room scale: accepted and current-source admission is 20 Viewers plus one Host; production remains eight by default. Focused controller coverage converges 20 Viewers under `C=1/2/3`, but the route release still needs one resource-limited Browser smoke for first-frame or bounded-failure behavior, endpoint copies, application CPU/memory, and SFU/TURN accounting.
+- SFU: production `9461e20` deploys ordered `q,h`, roots <=2, and Dynacast off. Those are release facts; current source uses one Host publication with exact Viewer subscriptions and no fixed root-count or room-wide lease rule. Real LiveKit lifecycle/JWT replay and shaped packet-flow, BWE downshift/recovery, resource, and SFU-fed first-child evidence remain open. Use Linux `tc` or an authorized public canary for per-leaf shaping, never CDP throttling.
- Audio: verify the 64/128/256 kbps Share settings, negotiated/observed bitrate, audible music quality, route changes, and game A/V synchronization. Bitrate settings are ceilings, not quality proof.
- Observability: the UI and local stats plumbing are deployed, including identity-bound relayed-detail retention and export freshness guards, but target-browser availability and actual values remain unverified for Host SFU sender evidence, codec/fmtp and encoder implementation/power efficiency, media-source and encoded FPS, A/V playout/jitter/concealment, selected candidate endpoints, and bounded same-pair STUN-response observation. These fields diagnose and have no recovery authority; they do not by themselves prove hardware encode, synchronization quality, or route quality.
- Mobile: Android/iOS remain Viewer-only. Autoplay, rotation, iOS lock-screen/page reclamation, background reconnection, and network changes need device evidence. AirPlay/system mirroring is Viewer-local output, not a portable in-app WebRTC output contract.