# 050 — Pro tebe from the server (A08)

Created: 2026-11-06
Updated: 2026-11-06

S13: signed in → the server computes, the TV downloads. S25: the server does not answer → the TV computes itself.
Signed out → `wcs/foryou/` exactly as today (no code path changes).

## Flow

1. `wcs/foryou/service.py` decides *when* as today (`due()`: no snapshot, day/slot changed, older than
   `REBUILD_AFTER`, signals changed + `SIGNAL_GAP`), and holds its locks as today.
2. In `build_now()`, before `engine.build(...)`: if `account.state.signed_in()` and not inside the onboarding guide →
   `account.foryou.fetch(etag)`:
   - `200` → validate (`version == engine.VERSION`, required keys, every row's items present in `items`) →
     `snapshot['signals'] = signals_stamp()` → `engine.save()` → the same `refresh.changed(...)` and
     `_show_appeared` as a local build;
   - `304` → keep the stored snapshot, refresh nothing, record "checked";
   - `503 building` → retry after `retry_after` (max 2×) else local;
   - timeout 20 s, network error, `409 version`, `426`, invalid JSON → local `engine.build()` (S25), one log line per
     streak.
3. The ETag is kept in `sync_state`; the snapshot in `meta foryou:snapshot` like today (it is switched with the account,
   030 §2).

## Why the server output equals the addon's

The web's engine is the port of `wcs/foryou/` proven by oracles (compose, features, score, rows). A08.1 adds an oracle
that feeds the same pool to the addon's `compose`/`widgets` and to the web's converter and requires identical rows.
The availability fields (`lang`, `quality`) come from the server's Webshare search with the account's Webshare
login — the same ranking code (ported with oracles).

## Result

2026-11-06 (WEB T26): the account keeps the newest snapshot built by a device; a signed-in device downloads a fresh
one or builds locally and uploads it; no server → local build (S25). Live: the Mac Kodi uploaded Standa's snapshot
(195 kB).
