From 9643188e2f40bbd295cfc4b07cccacdd2bbccb85 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 23 Oct 2026 10:59:21 +0200 Subject: [PATCH 1/6] docs(adr): reserve ADR 0044 for the console's reads (#905) Co-Authored-By: Claude --- ...its-page-shows-and-events-mark-it-stale.md | 24 +++++++++++++++++++ docs/internal/adr/README.md | 1 + 2 files changed, 25 insertions(+) create mode 100644 docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md diff --git a/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md b/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md new file mode 100644 index 000000000..aba63cf4c --- /dev/null +++ b/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md @@ -0,0 +1,24 @@ +# 0044. The console reads what its page shows, and events mark it stale + +- **Status:** Proposed +- **Date:** 2026-10-23 +- **Issue:** [#905](https://github.com/callstackincubator/simlock/issues/905) +- **Supersedes:** [ADR 0013](0013-the-console-reads-routes-and-follows-the-event-stream.md) + §3 (refetch every second, and refetch the screen on every event). + +## Context + +_Draft: the spec session for #905 is still deciding. This file reserves the +number._ + +## Decision + +_To come._ + +## Consequences + +_To come._ + +## Alternatives considered + +_To come._ diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index 8822c4c99..b877c5347 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -82,3 +82,4 @@ the status is stale. | [0041](0041-the-daemon-can-run-under-the-users-service-manager.md) | The daemon can run under the user's service manager | Accepted — not yet implemented | | [0042](0042-simlock-updates-itself-through-a-frozen-call-and-a-detached-updater.md) | Simlock updates itself through a frozen call and a detached updater | Accepted — not yet implemented; narrows 0009's `takes-requests` stage | | [0043](0043-physical-devices-reach-agent-device-through-a-second-daemon.md) | Physical devices reach agent-device through a second daemon on the worker | Accepted — not yet implemented; supersedes 0023 §3–4 in part | +| [0044](0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md) | The console reads what its page shows, and events mark it stale | Proposed; supersedes 0013 §3 | From 5dd1ab0bf5d24f948ee6d8c550bd5f70afa6b122 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 23 Oct 2026 11:11:00 +0200 Subject: [PATCH 2/6] docs(adr): draft ADR 0044 (#905) Co-Authored-By: Claude --- ...its-page-shows-and-events-mark-it-stale.md | 134 +++++++++++++++++- 1 file changed, 128 insertions(+), 6 deletions(-) diff --git a/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md b/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md index aba63cf4c..c71b1173f 100644 --- a/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md +++ b/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md @@ -4,21 +4,143 @@ - **Date:** 2026-10-23 - **Issue:** [#905](https://github.com/callstackincubator/simlock/issues/905) - **Supersedes:** [ADR 0013](0013-the-console-reads-routes-and-follows-the-event-stream.md) - §3 (refetch every second, and refetch the screen on every event). + §3 (refetch every second, and refetch the screen on every event). §1, §2, + §4 and §5 stand. ## Context -_Draft: the spec session for #905 is still deciding. This file reserves the -number._ +ADR 0013 made the console re-read every route the screen uses once a second, +and again at once after any event. That was cheap for one host. On a gateway +it is not: + +- The sidebar's Inbox count reads `/v1/workers`, `/v1/leases`, `/v1/tokens` + and `/v1/lease-requests` on every page (`ui/src/state/shell.ts:12`), so + every page polls the whole fleet every second. +- The only throttle on event reads is "one in flight, one queued" + (`ui/src/data/live/connection.ts:181`). On a busy fleet the reads run back + to back, as fast as the gateway answers. `lease.renewed` alone fires once + per lease every TTL/3. +- A gateway's worker views change only after a worker event or on the 30 s + tick (`src/gateway/service.ts:277`), so most 1 s reads return the same + answer, in full: no route has an ETag. +- `GET /v1/leases/{id}` scans the whole lease list (`src/http/app.ts:797`). +- The read cache never drops a route, while each screen's event list is + fetched again every time it opens. + +The target is a gateway with 50 workers of 5–10 devices each, several tabs +open. ## Decision -_To come._ +### 1. One query cache, in the state layer + +The console keeps server data in TanStack Query (`@tanstack/react-query`), in +`ui/src/state/`. `ui/src/data/` keeps the API client, the stream and the +connection status; the layer rules forbid `@tanstack/*` there. + +One key per route. A key is read when a page that uses it mounts and polls +only while such a page is on screen, never in a hidden tab, never while the +console is disconnected: + +| Key | Poll | Fresh for | Dropped after unused | +|---|---|---|---| +| `['lease-requests']` | 5 s | 2 s | 60 s | +| `['leases']`, `['lease', id]` | 10 s | 2 s | 60 s | +| `['inbox']` | 10 s | 2 s | 60 s | +| `['workers']` | 15 s | 2 s | 60 s | +| `['stats', range]` | 60 s | 30 s | 60 s | +| `['tokens']` | none | 5 min | 60 s | +| `['events', 'recent']` | none (the stream fills it) | always | 60 s | +| `['events', 'history', filter]` | none, 10 pages at most | always | 30 s | + +```mermaid +flowchart LR + S[Screens] --> H[state hooks] + H --> Q[(Query cache)] + Q --> A[data: API client] + L[data: live connection] -- events --> M[event map] + M -- mark stale --> Q + L -- connected / lost --> Q +``` + +### 2. Events mark keys stale; they do not read + +An event name maps to the keys it changes (the table in #905). An unknown +name maps to none. The console collects the keys of a burst and acts 300 ms +after the last event: a key a page on screen uses is read, any other key is +only marked stale and read when a page next needs it. The same keys are read +once more 1.5 s later, because a gateway passes a worker's event on before it +has refreshed that worker's view. + +`lease.renewed` reads nothing. Its `newDeadline` is written into the cached +lease, matched by `workerId` and `workerLeaseId` on a gateway, by `id` on a +worker. + +```mermaid +sequenceDiagram + participant G as Gateway + participant C as Console + G--)C: lease.granted, device.ready, ... (burst) + Note over C: 300 ms with no event + C->>G: GET each stale key on screen + G-->>C: 200, or 304 when unchanged + Note over C: 1.5 s later + C->>G: same reads once more +``` + +A change with an event shows within about a second. A change with none +(host load, a worker connecting as incompatible) shows within the slowest +poll of its page, 15 s. + +### 3. The server helps + +- **ETag.** Every `GET` under `/v1` that answers 200 with JSON carries a + strong ETag, the SHA-1 of its body. A matching `If-None-Match` gets 304 + with no body. Streams and mounts carry none. The console sends back the + last ETag per key and keeps its data on a 304. +- **`lease.get`.** `GET /v1/leases/{id}` and its `/events` read one lease + through a new `lease.get` operation instead of filtering `lease.list`. An + unknown or not-owned id still answers 404. +- **`workerLeaseId`.** On a gateway, a lease record carries the worker's own + lease id, so a relayed event can be matched to it. +- **`GET /v1/inbox`.** The Inbox rules move from the console + (`ui/src/model/inbox.ts`) to `src/contract/inbox.ts`, and a new + `inbox.get` operation answers them in both modes. Items carry ids, labels + and the timestamps their times count from; the browser ticks the times. The + sidebar count, the Inbox page and the Overview's Needs you read it instead + of the four fleet lists. A drawer reads its worker, device or lease when it + opens. + +### 4. The clock ticks in leaves + +The per-second tick re-renders the labels that show a time, not the hooks +that build a page's view model. ## Consequences -_To come._ +- An idle tab on any page makes at most 30 requests a minute against a + 50-worker gateway, most of them 304s. A browser-lane test holds that line. +- The public console page changes "within about a second" to say which + changes take up to 15 s. +- A new event that should refresh a page needs a row in the event map; until + then it waits for the poll. +- The console gains one dependency, `@tanstack/react-query`. +- Two contract changes (`lease.get` with `workerLeaseId`, `inbox.get`) each + bump the protocol. ## Alternatives considered -_To come._ +- **Keep the 1 s poll, add only ETags.** Rejected: still four full-fleet + reads a second per tab on the gateway's side, and no fix for read storms. +- **A revision counter per worker view instead of a body hash.** Rejected: + a missed bump shows stale data, and it covers two routes only. A hash + covers every route and cannot go stale. +- **The gateway relays a worker's event only after refreshing its view.** + Rejected for now: it changes the relay for every client and delays every + event; a second read is nearly free with 304s. +- **Any unknown event marks every key stale.** Rejected: on a busy fleet it + brings back a read of every list per burst. +- **A count-only `GET /v1/inbox/summary`.** Rejected: the Inbox page would + still read the four lists, and the rules would live on both sides. +- **An event for a worker that connects as incompatible, so every change + shows within a second.** Rejected: 15 s is enough for a fact that rare. From c180be2feb41ef2a5d9988dd8c4bec6358db3f34 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 23 Oct 2026 11:22:02 +0200 Subject: [PATCH 3/6] docs(adr): 0044 after the feature check (#905) Co-Authored-By: Claude --- ...its-page-shows-and-events-mark-it-stale.md | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md b/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md index c71b1173f..cff53fe8f 100644 --- a/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md +++ b/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md @@ -67,14 +67,15 @@ flowchart LR An event name maps to the keys it changes (the table in #905). An unknown name maps to none. The console collects the keys of a burst and acts 300 ms -after the last event: a key a page on screen uses is read, any other key is +after the last event, or 1 s after the first, whichever comes first: a key a page on screen uses is read, any other key is only marked stale and read when a page next needs it. The same keys are read once more 1.5 s later, because a gateway passes a worker's event on before it has refreshed that worker's view. `lease.renewed` reads nothing. Its `newDeadline` is written into the cached lease, matched by `workerId` and `workerLeaseId` on a gateway, by `id` on a -worker. +worker. When the cached Inbox shows that lease as ending, the Inbox is +marked stale too. ```mermaid sequenceDiagram @@ -105,11 +106,12 @@ poll of its page, 15 s. lease id, so a relayed event can be matched to it. - **`GET /v1/inbox`.** The Inbox rules move from the console (`ui/src/model/inbox.ts`) to `src/contract/inbox.ts`, and a new - `inbox.get` operation answers them in both modes. Items carry ids, labels - and the timestamps their times count from; the browser ticks the times. The - sidebar count, the Inbox page and the Overview's Needs you read it instead - of the four fleet lists. A drawer reads its worker, device or lease when it - opens. + `inbox.get` operation answers them in both modes. Each item embeds a small + copy of its subject: the worker's own fields (no devices, catalog, leases or + downloads), or the device, the lease with its holder, or the request. Its + times are the subject's timestamps; the browser ticks them. The sidebar + count, the Inbox page and the Overview's Needs you read it instead of the + four fleet lists. ### 4. The clock ticks in leaves @@ -118,7 +120,7 @@ that build a page's view model. ## Consequences -- An idle tab on any page makes at most 30 requests a minute against a +- An idle tab on any page makes at most 40 requests a minute against a 50-worker gateway, most of them 304s. A browser-lane test holds that line. - The public console page changes "within about a second" to say which changes take up to 15 s. @@ -140,6 +142,9 @@ that build a page's view model. event; a second read is nearly free with 304s. - **Any unknown event marks every key stale.** Rejected: on a busy fleet it brings back a read of every list per burst. +- **Inbox items with ids only, the drawer reading its subject on open.** + Rejected: a row's buttons need the subject's facts before any drawer + opens, so the Inbox page would read the fleet lists again. - **A count-only `GET /v1/inbox/summary`.** Rejected: the Inbox page would still read the four lists, and the rules would live on both sides. - **An event for a worker that connects as incompatible, so every change From aeb482158328f7dc07944b486a383e6e34042231 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 23 Oct 2026 11:39:18 +0200 Subject: [PATCH 4/6] docs(adr): 0044 after the task checks (#905) Co-Authored-By: Claude --- ...its-page-shows-and-events-mark-it-stale.md | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md b/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md index cff53fe8f..0f9eff635 100644 --- a/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md +++ b/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md @@ -50,8 +50,13 @@ console is disconnected: | `['workers']` | 15 s | 2 s | 60 s | | `['stats', range]` | 60 s | 30 s | 60 s | | `['tokens']` | none | 5 min | 60 s | -| `['events', 'recent']` | none (the stream fills it) | always | 60 s | -| `['events', 'history', filter]` | none, 10 pages at most | always | 30 s | + +The recent events the Inbox and lease drawers show come from one feed per +tab, filled by the stream and kept 60 s after its last user. Activity keeps +its own feed and scroll-back, dropped when the operator leaves it. + +A read lost to the network leaves the key as it was; the sidebar says +Reconnecting, as today. ```mermaid flowchart LR @@ -96,7 +101,7 @@ poll of its page, 15 s. ### 3. The server helps - **ETag.** Every `GET` under `/v1` that answers 200 with JSON carries a - strong ETag, the SHA-1 of its body. A matching `If-None-Match` gets 304 + strong ETag, Hono's digest of its body (SHA-1, chained per 256 KiB). A matching `If-None-Match` gets 304 with no body. Streams and mounts carry none. The console sends back the last ETag per key and keeps its data on a 304. - **`lease.get`.** `GET /v1/leases/{id}` and its `/events` read one lease @@ -110,13 +115,9 @@ poll of its page, 15 s. copy of its subject: the worker's own fields (no devices, catalog, leases or downloads), or the device, the lease with its holder, or the request. Its times are the subject's timestamps; the browser ticks them. The sidebar - count, the Inbox page and the Overview's Needs you read it instead of the - four fleet lists. - -### 4. The clock ticks in leaves - -The per-second tick re-renders the labels that show a time, not the hooks -that build a page's view model. + count reads only this route. The Inbox page and the Overview's Needs you + read it and `/v1/workers` (for names, links and lease counts), and no + longer read leases, tokens or waiting requests. ## Consequences @@ -126,6 +127,8 @@ that build a page's view model. changes take up to 15 s. - A new event that should refresh a page needs a row in the event map; until then it waits for the poll. +- The per-second clock still rebuilds views that show a time; making it + cheaper is left to later work. - The console gains one dependency, `@tanstack/react-query`. - Two contract changes (`lease.get` with `workerLeaseId`, `inbox.get`) each bump the protocol. From 81a333a2accf34d619eb7b4fa2ef5b83faf64373 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 23 Oct 2026 12:13:42 +0200 Subject: [PATCH 5/6] =?UTF-8?q?docs(adr):=20accept=200044,=20supersede=200?= =?UTF-8?q?013=20=C2=A73=20(#905)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- ...3-the-console-reads-routes-and-follows-the-event-stream.md | 2 +- ...sole-reads-what-its-page-shows-and-events-mark-it-stale.md | 2 +- docs/internal/adr/README.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/internal/adr/0013-the-console-reads-routes-and-follows-the-event-stream.md b/docs/internal/adr/0013-the-console-reads-routes-and-follows-the-event-stream.md index 2b738abe6..01de8fad3 100644 --- a/docs/internal/adr/0013-the-console-reads-routes-and-follows-the-event-stream.md +++ b/docs/internal/adr/0013-the-console-reads-routes-and-follows-the-event-stream.md @@ -1,6 +1,6 @@ # 0013. The console reads the routes and follows the event stream -- **Status:** Accepted +- **Status:** Accepted; §3 superseded by [0044](0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md) - **Date:** 2026-10-02 - **Issue:** [#88](https://github.com/callstackincubator/simlock/issues/88) - **Supersedes:** nothing. diff --git a/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md b/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md index 0f9eff635..56c776231 100644 --- a/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md +++ b/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md @@ -1,6 +1,6 @@ # 0044. The console reads what its page shows, and events mark it stale -- **Status:** Proposed +- **Status:** Accepted — not yet implemented - **Date:** 2026-10-23 - **Issue:** [#905](https://github.com/callstackincubator/simlock/issues/905) - **Supersedes:** [ADR 0013](0013-the-console-reads-routes-and-follows-the-event-stream.md) diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index b877c5347..db96963bf 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -51,7 +51,7 @@ the status is stale. | [0010](0010-components-have-one-owner-in-the-core.md) | Components are installed, recorded and removed through one owner in the core | Accepted | | [0011](0011-the-console-is-a-built-app-the-daemon-serves.md) | The console is a built app the daemon serves at `/` | Accepted | | [0012](0012-a-worker-answers-the-fleet-operations-as-a-fleet-of-one.md) | A worker answers the fleet operations as a fleet of one | Accepted | -| [0013](0013-the-console-reads-routes-and-follows-the-event-stream.md) | The console reads the routes and follows the event stream | Accepted | +| [0013](0013-the-console-reads-routes-and-follows-the-event-stream.md) | The console reads the routes and follows the event stream | Accepted; §3 superseded by 0044 | | [0014](0014-an-event-has-one-id-minted-where-the-fact-happened.md) | An event has one id, minted where the fact happened | Accepted; §6 narrowed by 0021 | | [0015](0015-a-lease-request-is-a-set-of-constraints.md) | A lease request is a set of constraints, and the catalog says which class each model is | Accepted; §3 narrowed by 0022 for physical devices; §3–5 narrowed by 0025 on Android | | [0016](0016-usage-figures-are-derived-on-read-from-the-event-history.md) | Usage figures are derived on read from the event history | Accepted — partly implemented: the event and retention parts are built, the reader (§1, §5–§8) is not; §6's fleet join and a Consequence superseded by 0021; §1 and §4 superseded by 0032 | @@ -82,4 +82,4 @@ the status is stale. | [0041](0041-the-daemon-can-run-under-the-users-service-manager.md) | The daemon can run under the user's service manager | Accepted — not yet implemented | | [0042](0042-simlock-updates-itself-through-a-frozen-call-and-a-detached-updater.md) | Simlock updates itself through a frozen call and a detached updater | Accepted — not yet implemented; narrows 0009's `takes-requests` stage | | [0043](0043-physical-devices-reach-agent-device-through-a-second-daemon.md) | Physical devices reach agent-device through a second daemon on the worker | Accepted — not yet implemented; supersedes 0023 §3–4 in part | -| [0044](0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md) | The console reads what its page shows, and events mark it stale | Proposed; supersedes 0013 §3 | +| [0044](0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md) | The console reads what its page shows, and events mark it stale | Accepted — not yet implemented; supersedes 0013 §3 | From e13cdd97ee757431310498d03e8ff77e21159443 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 23 Oct 2026 12:24:03 +0200 Subject: [PATCH 6/6] docs(adr): host load shows within 15 s of the daemon, about 45 s on a gateway (#905) --- ...-reads-what-its-page-shows-and-events-mark-it-stale.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md b/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md index 56c776231..5e06c460a 100644 --- a/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md +++ b/docs/internal/adr/0044-the-console-reads-what-its-page-shows-and-events-mark-it-stale.md @@ -96,7 +96,9 @@ sequenceDiagram A change with an event shows within about a second. A change with none (host load, a worker connecting as incompatible) shows within the slowest -poll of its page, 15 s. +poll of its page, 15 s, after the daemon serves it. On a gateway the view +changes only on the gateway's own 30 s refresh, so it shows within about +45 s. ### 3. The server helps @@ -124,7 +126,7 @@ poll of its page, 15 s. - An idle tab on any page makes at most 40 requests a minute against a 50-worker gateway, most of them 304s. A browser-lane test holds that line. - The public console page changes "within about a second" to say which - changes take up to 15 s. + changes take up to 15 s, and up to about 45 s on a gateway. - A new event that should refresh a page needs a row in the event map; until then it waits for the poll. - The per-second clock still rebuilds views that show a time; making it @@ -151,4 +153,4 @@ poll of its page, 15 s. - **A count-only `GET /v1/inbox/summary`.** Rejected: the Inbox page would still read the four lists, and the rules would live on both sides. - **An event for a worker that connects as incompatible, so every change - shows within a second.** Rejected: 15 s is enough for a fact that rare. + shows within a second.** Rejected: a delay of 15 s, about 45 s on a gateway, is enough for a fact that rare.