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. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

fix(native): close one-viewer loopback gate

AAAddcf9622d316
diff --git a/docs/adr/0006-fixed-high-native-sender-canary.md b/docs/adr/0006-fixed-high-native-sender-canary.md
index 7d7c51d3..bd404b5f 100644
--- a/docs/adr/0006-fixed-high-native-sender-canary.md
+++ b/docs/adr/0006-fixed-high-native-sender-canary.md
@@ -138,8 +138,25 @@ only to report positive source gaps. Focused tests retain dropped-frame timing,
non-increasing rejection, and sub-sample progress; the real `/media` handler also
accepts two frames at 1,000,000 and 1,033,000 microseconds when the first reports
33,333 microseconds. This proves the source path no longer raises that fatal, not
-that it caused the retained browser failure. No post-fix Chrome smoke ran, so
-ADR-0006 remains product-gate no-go.
+that it caused the retained browser failure.
+
+## 2026-08-20 One-Viewer Loopback Revalidation
+
+A bounded Chrome 151 run with fixed VP8 1280x720@30 and peer assistance disabled
+closed the base sender-to-Viewer path once. Sender/Go recorded 30 written frames,
+85 source RTP packets, and zero fatal or encoder errors. The Viewer authenticated,
+completed offer/answer/ICE, received 877 packets, and advanced from 0 to 299
+decoded and rendered frames at 1280x720. The probe was corrected to tolerate
+pre-offer trickle candidates and a development-only pre-offer control-socket
+replacement while retaining fail-closed checks after an active offer/PC.
+
+The run still ended negative at the gate's Pion outbound assertion because the
+two-second Go diagnostics snapshot did not refresh during the media sample
+(`pionPacketDelta=0`). This is a residual observation-timing gap; inbound packet,
+decode, render, source-RTP, and no-fatal evidence are retained. The result is
+therefore a one-Viewer functional loopback proof, not a broad Native acceptance:
+two edges, FIFO, hardware, endurance, public-network, audio, and packaged-native
+boundaries remain no-go.
## Staged Revalidation
diff --git a/docs/project-memory.md b/docs/project-memory.md
index 38682173..aa46a4ea 100644
--- a/docs/project-memory.md
+++ b/docs/project-memory.md
@@ -23,7 +23,7 @@ Last updated: 2026-08-20
- Use direct host P2P for one or two viewers. Keep ADR-0004 off broadly; use an isolated exact-room candidate until resource, quality, recovery, SFU/UDP, bounded-failure, and browser/mobile gates pass.
- Browser relays resend remote `MediaStreamTrack` values and re-encode at each hop; WebRTC does not guarantee a shared encoder across peer connections, so measure the cost.
- Keep experiments bounded: the standard representation sequence is below; native RTP relay, encoded-object striping, and FEC remain separate.
-- ADR-0006 stays no-go: the clarification run retained VP8 output and one first-generation binary `send()` return, then no post-send diagnostics and a sanitized fatal marker; media zeros are initial, no Viewer was created, and cleanup passed 5/5. Source now removes one deterministic timestamp-overlap fatal by deriving RTP cadence from increasing capture timestamps rather than nullable WebCodecs duration. Focused/handler Go tests pass, but the retained fatal category and post-fix Chrome/Viewer proof are absent. The MF RTX H.264 fixture passed 360/360, but `42c01f` misses Pion's default fmtp. Native v2 remains memory-only and leaves SQLite/Web unchanged.
+- ADR-0006 remains no-go for expansion. A Chrome 151 loopback proves fixed VP8 WebCodecs -> Go RTP -> one 1280x720 Viewer: 30 sender frames/85 source RTP packets, 877 inbound packets, 299 decoded and rendered, no fatal. Pion outbound delta was not retained because its 2-second diagnostics snapshot did not refresh. Hardware, multi-viewer/FIFO, endurance, public-network, and packaged-native proof remain open. Source fixes timestamp overlap from nullable duration; the separate MF RTX fixture still misses Pion fmtp. Native v2 remains memory-only and leaves SQLite/Web unchanged.
- Mobile Web Host is unsupported; feature-detect and fail clearly. Mobile Viewer stays leaf-only. After Windows native, gate Android 14+; iOS waits for stable iOS 27 ScreenCaptureKit.
- ADR-0005 accepts direct/peer UDP, bounded SFU roots, then optional selected-edge TURN. Source has a default-off, undeployed one-shot rebuild after SFU; participant-wide TURN remains rejected and production stays STUN-only.
- Keep the controller exact-room only: room `1` is the STUN/SFU smoke. Preserve sticky progressing P2P, mobile leaves and break-before-make. Recovery spends one attempt per layer (ICE restart, same-parent rebuild, alternate peer, then SFU), never three identical retries; active SFU gets one fresh grant before Peer failback.
diff --git a/docs/research/native-shared-encode-sender.md b/docs/research/native-shared-encode-sender.md
index 2deb3021..0246c1b5 100644
--- a/docs/research/native-shared-encode-sender.md
+++ b/docs/research/native-shared-encode-sender.md
@@ -329,10 +329,28 @@ closed. Focused timeline tests cover shorter-than-duration jitter, dropped
source time, non-increasing input, and a positive delta below one 90 kHz sample.
A real `/media` handler test carries the two jittered frames through decode and
fanout with two frames written and positive source RTP. All Native Go packages
-pass. These checks prove that specific fatal path is removed; without a post-fix
-Chrome smoke they do not classify the retained run or prove Viewer delivery.
+pass. These checks prove that specific fatal path is removed; the later bounded
+loopback smoke below supplies one Viewer delivery proof but does not classify the
+retained fatal run or establish broader Native acceptance.
The WebCodecs and pinned Pion packetizer sources were rechecked 2026-08-20.
+A bounded follow-up smoke on 2026-08-20 then exercised the complete one-viewer
+loopback path with Chrome 151, fixed VP8 1280x720@30, and peer assistance off.
+The Sender reached 30 written frames and 85 source RTP packets with zero fatal or
+encoder errors. The Viewer authenticated, completed offer/answer/ICE, received
+877 packets (842,346 bytes), and advanced from 0 to 299 decoded and rendered
+frames at 1280x720. The gate stopped only because its Pion outbound check sampled
+the same two-second diagnostics snapshot before it refreshed (`pionPacketDelta=0`);
+that residual probe timing does not invalidate the independent inbound/decode/
+render counters, but it leaves a fresh Pion outbound delta unretained.
+
+The gate probe now treats trickled candidates before the first offer, and a
+development-only pre-offer control-socket replacement, as one logical generation;
+after an active offer/PeerConnection, socket or connection changes still fail
+closed. This is test-harness evidence, not a runtime protocol relaxation. No
+second Viewer, FIFO, hardware, endurance, public-network, or packaged-native run
+followed.
+
The frozen probe continues to bind the first actual local media WebSocket as
gate-local generation 1. A second bridge generation saturates at 2, stops
accumulating the first generation's counters, and fails the Viewer signal,
@@ -361,8 +379,8 @@ The earlier authorized 2026-08-19 local product gate is
| Viewer page | The page and probe loaded, but the 30-second combined decoded-and-rendered condition timed out. |
| Downstream lifecycle | Viewer auth, `peer-joined`, SDP/candidates, PC states, source RTP/edge packets, inbound RTP, video readiness, and console state were not retained. |
-The first missing evidence checkpoint is viewer authentication, not a proven
-authentication failure. The harness discarded each false sample; its reused
+For that retained run, the first missing evidence checkpoint was viewer
+authentication, not a proven authentication failure. The harness discarded each false sample; its reused
`progress()` path can omit a connection after a swallowed `getStats()` error;
and render evidence had no readiness/current-time/video-dimension fallback.
The timeout therefore cannot locate the runtime break or rule out a probe-only
diff --git a/docs/status.md b/docs/status.md
index 05b13a64..3bec77de 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -35,7 +35,7 @@ and is not part of production.
- Host A+B and authenticated P2P Viewer C are sanitized, generation-bound, read-only, and fail closed for stale, ambiguous, or SFU-fed evidence; no raw media metadata is retained.
- SVC is `no-go-web-svc-cross-path-hardware-contract`: no direct/peer selection, cross-PC shared encode, or portable hardware proof; pinned screen share is `L1T3`. No browser run was warranted.
- The `a11a73d` built-in TURN canary is rejected: local allocation passed, but direct Host/Pion Viewer failed before forced relay. Full rollback restored STUN-only client ICE and zero allocations.
-- Native remains no-go: the retained VP8 run reached one encoder and generation-1 binary send, then no diagnostics, a fatal marker and initial media zeros; no Viewer. Source removes a deterministic timestamp-overlap fatal and passes timeline/`/media` tests, but the retained category and post-fix Chrome/Viewer proof are absent.
+- Native VP8 loopback (Chrome 151) reached one Viewer: 30 sender frames, 85 source RTP packets, 877 inbound packets, 299 decoded/rendered at 1280x720, no fatal. Pion outbound delta missed a 2s refresh; hardware/multi-viewer/FIFO/endurance/public/native proof remains open.
- Access protocol/config/HTTP/storage/SQLite/signaling focused tests pass, including commit-first teardown and v1 rollback.
- Selected-edge typecheck and 131 focused control tests pass; no TURN allocation/media evidence exists.
@@ -46,7 +46,7 @@ and is not part of production.
- Silent partitions can wait 30 to 60 seconds for heartbeat detection before the default 5-second grace; this remains unverified.
- Real audio and heterogeneous clients remain unverified. Production reports poor film audio and voice-call self-echo under system capture; there is no app audio ceiling or Web process isolation. Diagnose A/B/C and sync, then gate Windows 11 game-process audio; Windows 10 stays unresolved without system fallback.
- The former release reportedly sustained bandwidth-limited blur on a capable LAN; Host refresh recovered while Viewer refresh did not. The new deployment has not yet reproduced or cleared it.
-- ADR-0006 still has no Viewer, two-edge, or FIFO proof.
+- ADR-0006 has one Viewer decode/render proof; two-edge/FIFO/hardware/endurance/public remain open.
- Browser fanout is host two/viewer one; any accepted endpoint relay stays capped at two downstream edges.
- PR #49/#50 BWE is unverified/default-off: test zero-child leaves, then root impact. No local per-leaf UDP shaper; resume with Linux `tc` or public canary, never CDP. Web P2P/SVC shortcuts remain no-go.
- The corrected standby smoke is localhost/headless/video-only; public DNS/TLS reuse, transport, audio, shaping, load, mobile, endurance, and sub-25 ms overlap remain open.
@@ -62,8 +62,8 @@ SFU; it never runs three identical retries or abandons progressing P2P early.
Next gate exactly-two/Dynacast-off BWE on a zero-child SFU leaf, then root
evacuation. Native source accepts increasing capture timestamps shorter than
-duration, but has no post-fix browser evidence. The next authorized run must
-prove stage-1 bridge ingress/source RTP before a Viewer.
+duration; one VP8 Viewer decode/render run is recorded. Next prove fresh Pion
+outbound diagnostics before viewer 2/FIFO/hardware/endurance/deploy.
Audio A/B/C may proceed without displacing P0.
Ordinary Peer ICE stays STUN-only; participant-wide TURN is removed. Selected-edge
is source-complete/default-off/undeployed. Next run one isolated forced-relay
diff --git a/scripts/native-one-viewer-gate.ts b/scripts/native-one-viewer-gate.ts
index 8f9183af..b24fb2b7 100644
--- a/scripts/native-one-viewer-gate.ts
+++ b/scripts/native-one-viewer-gate.ts
@@ -640,8 +640,11 @@ function viewerProbe(): string {
return `(() => {
const state = { signaling: { authenticateSent: 0, authenticatedReceived: 0,
offersReceived: 0, answersSent: 0, candidatesReceived: 0, candidatesSent: 0 },
- socketCount: 0, authenticateSocketOrdinal: 0, authSocketOrdinal: 0, authGeneration: 0,
- connectionIds: [], activeConnectionId: null, consistent: true, pendingOffer: null,
+ socketCount: 0, socketSequence: 0, logicalSocketCount: 0,
+ authenticateSocketOrdinal: 0, authSocketOrdinal: 0, logicalAuthSocketOrdinal: 0,
+ authGeneration: 0,
+ connectionIds: [], activeConnectionId: null, preOfferConnectionId: null,
+ consistent: true, pendingOffer: null,
pcs: [], boundPcOrdinal: 0, boundConnectionOrdinal: 0, boundSocketOrdinal: 0,
boundAuthGeneration: 0, trackCount: 0, trackOrdinal: 0, trackPcOrdinal: 0,
renderedFrames: 0, observedVideo: null };
@@ -657,7 +660,18 @@ function viewerProbe(): string {
state.signaling.authenticateSent += 1; state.authenticateSocketOrdinal = socketOrdinal; return;
}
if (direction === 'in' && message.type === 'authenticated') {
- state.signaling.authenticatedReceived += 1; state.authGeneration += 1;
+ state.signaling.authenticatedReceived += 1;
+ const activeMediaStarted = state.activeConnectionId !== null || state.boundPcOrdinal > 0;
+ if (state.authGeneration === 0) {
+ state.authGeneration = 1;
+ state.logicalSocketCount = 1;
+ state.logicalAuthSocketOrdinal = 1;
+ } else if (activeMediaStarted) {
+ state.authGeneration += 1;
+ state.logicalSocketCount += 1;
+ state.logicalAuthSocketOrdinal = state.logicalSocketCount;
+ state.consistent = false;
+ }
state.authSocketOrdinal = socketOrdinal;
if (state.authenticateSocketOrdinal !== socketOrdinal) state.consistent = false;
return;
@@ -668,12 +682,23 @@ function viewerProbe(): string {
state.consistent = false; return;
}
const ordinal = connectionOrdinal(rawConnectionId);
- if (state.activeConnectionId === null && direction === 'in' &&
- message.payload.kind === 'description' && message.payload.description?.type === 'offer') {
- state.activeConnectionId = rawConnectionId;
+ const inboundOffer = direction === 'in' && message.payload.kind === 'description' &&
+ message.payload.description?.type === 'offer';
+ if (state.activeConnectionId === null) {
+ if (inboundOffer) {
+ if (state.preOfferConnectionId !== null && state.preOfferConnectionId !== rawConnectionId) {
+ state.consistent = false;
+ }
+ state.activeConnectionId = rawConnectionId;
+ } else if (state.preOfferConnectionId === null) {
+ // Pion may trickle a candidate before the offer write reaches the Viewer.
+ state.preOfferConnectionId = rawConnectionId;
+ } else if (state.preOfferConnectionId !== rawConnectionId) {
+ state.consistent = false;
+ }
}
if (state.activeConnectionId !== rawConnectionId) state.consistent = false;
- if (direction === 'in' && message.payload.kind === 'description' && message.payload.description?.type === 'offer') {
+ if (inboundOffer) {
state.signaling.offersReceived += 1;
state.pendingOffer = { rawConnectionId, ordinal, socketOrdinal, authGeneration: state.authGeneration };
}
@@ -691,7 +716,7 @@ function viewerProbe(): string {
super(...args);
this.__gateSignal = new URL(String(args[0]), location.href).pathname === '/signal';
if (this.__gateSignal) {
- this.__gateSocketOrdinal = ++state.socketCount;
+ this.__gateSocketOrdinal = ++state.socketSequence;
this.addEventListener('message', (event) => inspect(event.data, 'in', this.__gateSocketOrdinal));
}
}
@@ -748,7 +773,8 @@ function viewerProbe(): string {
}
const activeOrdinal = state.activeConnectionId === null ? 0 :
state.connectionIds.indexOf(state.activeConnectionId) + 1;
- const identity = { socketCount: state.socketCount, socketOrdinal: state.authSocketOrdinal,
+ const identity = { socketCount: state.logicalSocketCount,
+ socketOrdinal: state.logicalAuthSocketOrdinal,
authGeneration: state.authGeneration, connectionCount: state.connectionIds.length,
connectionOrdinal: activeOrdinal, pcCount: state.pcs.length, pcOrdinal: state.boundPcOrdinal,
trackCount: state.trackCount, trackOrdinal: state.trackOrdinal,