Skip to content

Viewers through a gateway share one relayed stream per worker and target #1603

Closed

Description

@V3RON

Part of #602.

Scope

After this PR, viewers of one device (or one lease) through a gateway share one relayed stream to the worker, once that worker promises a key frame every 5 seconds. Many viewers no longer crowd a worker link's channels. A worker that hasn't been updated yet is relayed per viewer, as today.

If it goes wrong: every gateway viewer of a device breaks at once, or a relay stays open with no viewer.

Technical spec

Commit 5e639b4.

Rows

  • Behaviours: B11, B12, B13
  • Stored state: S2
  • Interfaces: I6; uses I1, I2
  • Existing code: X5, X6, X14 (the stream manual's Gateway rule), X17

Facts

# Fact Source
F1 The gateway link's tests drive createGatewayStreamLink with a fake FleetPort whose relay returns a Response. src/stream/gateway-link.test.ts:63-94
F2 The OpenAPI test pins the stream's 200 response to exactly four headers today. src/http/openapi.test.ts:405-410

Modules touched

src/stream (gateway-link.ts, service.ts, create.ts, definition.ts, their tests, AGENTS.md), src/http/openapi.test.ts, website/src/content/docs/docs/using-devices/watching-the-screen.mdx. Searches: fleet.relay, streamResponse, STREAM_HEADERS, simlock-stream-.

Rules in play

  • ADR 0079 §2 and §3: one relay per worker and target, shared only on the worker's promise; the gateway reads lengths, tags and meta frames, never a picture.
  • src/stream/AGENTS.md (Gateway): a non-operator on a device path and an unknown worker are refused before any relay; a worker's refusal is a claim, forwarded only when shaped like ours.
  • ADR 0033 §6: a viewer's expiresAt ends only that viewer.
  • Documentation rule 9: the new header is declared for OpenAPI and on the website's stream page.

Retired words

  • relays the body unread: the gateway splits a shared relay's body into frames and reads meta frames, never a picture.

Tests

The seam is the gateway's stream link through src/stream/gateway-link.test.ts, with a fake FleetPort, as its existing cases do; the cases that need the gateway's HTTP answer (its headers, a viewer's expiresAt) go through createGatewayStream in src/stream/create.test.ts, as its gateway expiresAt cases do (create.test.ts:379-457).

  • B11: viewers through a gateway share one relay per worker and target: three device-path viewers; the owner and an operator on one lease; a device-path and a lease-path viewer; refusals before joining; a worker answer without I6 (one after the other, and both waiting on the first head); one with it; the gateway's own answer carries no I6.
  • B12: a joiner, a slow viewer and the last viewer leaving behave as on a worker: a joiner after the first key frame; after a later meta frame; a stalled viewer; the first viewer leaving; the last leaving; every viewer leaving while the head is awaited; the last viewer's expiresAt.
  • B13: a refused or failed shared relay refuses or ends every viewer the same way: a 409 refusal to two viewers; WORKER_UNREACHABLE to two; a frame over the bound; a frame of length 0; a first frame that is not meta; a later meta frame that fails the check; the relay body ending.

Done when

  • pnpm test:changed passes, with the B11 to B13 cases and src/http/openapi.test.ts.
  • The OpenAPI document declares simlock-stream-keyframe-ms on the stream routes' 200 response.
  • src/stream/AGENTS.md's Gateway rule says the gateway reads frame lengths, tags and meta frames, never a picture, and shares a relay only on the worker's promise.
  • The website's "Watching the screen" page describes simlock-stream-keyframe-ms.

Out of scope

  • Sharing one relay between a device path and a lease path: ADR 0079 §2.

Depends on

Written by an agent.

Metadata

Metadata

Assignees

Labels

task:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions