Console: edit the warm pool's targets on a worker's Warm pool tab

未关闭
#1,145 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
frontend

调研方向

Start with ui/src/screens/fleet/worker-page.tsx, ui/src/model/actions.ts, and the existing Warm pool tests in ui/src/screens/fleet/fleet.test.tsx; read ui/AGENTS.md for the Actions and Reads guidance. Then trace the warm-pool query and write handling in ui/src/state/queries.ts and ui/src/state/actions.ts. Done when the worker-only panels safely update targets and learned kinds, refresh state correctly, and the browser test in e2e/console/workers.spec.ts covers the flow.

由索引模型根据 Issue 内容生成。

描述

task:draft

Part of #1137.

Scope

After this PR an operator on a worker's console warms the pool up and down from the worker page's Warm pool tab. They step a kind's count, drop a runtime row, choose whether the pool learns, and forget a learned kind. Everything goes through #1144's routes. On a gateway, or while the console does not know the daemon's mode, the tab stays as it is today: read-only.

In short

The Warm pool tab gains two panels above the figures, in worker mode only. Targets lists the effective list from GET /v1/warm-pool: each kind with a − and + stepper, its origin, and on a runtime row Use config (it replaced configured targets) or Remove (it did not). Below the rows is a Learn kinds from leases choice. Learned kinds lists each kind the pool learned with its peak and Forget. Every step, Use config, Remove or Learn choice sends one PUT /v1/warm-pool/targets with the stored runtime list changed by that one thing and runtime.learn kept. Forget asks first, then sends one DELETE /v1/warm-pool/learned. The figures table stays read-only; its Origin column can now read runtime.

flowchart LR
  T[Warm pool tab, worker mode] --> R["GET /v1/warm-pool (new read)"]
  R --> P[Targets and Learned kinds panels, new]
  P -->|− + / Use config / Remove / Learn| U[PUT /v1/warm-pool/targets]
  P -->|Forget, after a confirm| D[DELETE /v1/warm-pool/learned]
  U --> S[Toast]
  D --> S
  E[warm-pool.targets-changed] --> K["marks ['warm-pool'] and the workers stale"]
  style P stroke-width:3px
  style U stroke-width:3px
  style D stroke-width:3px
  style K stroke-width:3px

Words, exactly (<kind> is the Kind spelling in #1137's Shared values; <n>, <m> are counts):

Where Text
Targets panel title Targets
its columns Kind, Count, Origin
stepper buttons − and +, labelled Keep one fewer <kind> and Keep one more <kind>
Origin cell configured, runtime, or runtime; config says <m>
row buttons Use config on a runtime row with configuredCount, Remove on one without
Learn choice legend Learn kinds from leases, shown; choices Config (<on|off>) from the answer's learn.configured, On, Off; Config chosen when learn.origin is configured, else the runtime value
empty No targets.
Learned kinds panel title Learned kinds, columns Kind, Peak; empty None learned.
row button Forget
success toast, a count of 1 or more Keeping <n> <kind> warm
success toast, a count of 0 Keeping no <kind> warm, description Its idle devices shut down now.
success toast, Use config <kind> follows config.json again
success toast, Remove Stopped keeping <kind> warm
success toast, Learn Learning: on, Learning: off, or Learning follows config.json: <on|off>
error toast title, any PUT Couldn't change the warm pool, with the daemon's message below
Forget confirm title Forget <kind>?
its body The pool stops keeping it warm, and the idle rules shut its idle devices down and delete them. Its next lease teaches it again., then, when the match also covers other learned kinds, It also forgets <kind>, <kind>.
its buttons Keep, Forget (busy: Forgetting…)
its success toast Forgot <kind>; Forgot <kind> and <n> more when forgotten lists more; <kind> was already forgotten when it is empty
its error toast title Couldn't forget <kind>

The count a step sends is #1137's "Count a client raises from": max(count, learnedCount) ± 1, between 0 and 256; learnedCount is 0 on a runtime row. − is disabled when that base is 0, and + when it is 256 or more; a merged configured row may sum above 256, and − on it then sends 256. Every control of both panels shares one in-flight key, warm-pool, so all are disabled while any warm-pool write is out. A PUT's answer is the whole warm.list answer: it cancels any ['warm-pool'] read in flight and replaces the data at once, so the next click builds on it and a late poll cannot bring the old list back. Forget's answer does not, so after it the console marks ['warm-pool'] stale and reads it again.

Forget sends platform, model, osVersion, mode, and imageTag when the kind has one. With no image tag warm.forget also forgets the kind's tagged kinds (src/core/warm-pool/learned.ts:186-198), so the confirm names each learned kind the match covers, read from the Learned kinds rows.

Row count, learnedCount + sends − sends
configured ios iPhone 17 26.0 2, 0 runtime row 3 runtime row 1
configured ios iPhone 16 18.5 1, 3 4 2
runtime android Pixel 8 0, 0 (a runtime row) 1 disabled
runtime android Pixel 8 256, 0 disabled 255

If this goes wrong, an operator sees a step that sends a stale or reordered list (another change undone), or a control on a gateway's tab.

Technical spec

Facts

Commit ce8fea85.

# Fact Source
F1 The Warm pool tab is a "Warm pool" panel with Pool and Reserved running slots facts and a read-only figures table (Model, Runtime, Mode, Origin, Wanted, Ready, Booting, Short), then "Installs in progress" ui/src/screens/fleet/worker-page.tsx:381-425
F2 The tab's data is each worker's warmPool from GET /v1/workers, shaped by warmTabOf and warmRow ui/src/state/workers.ts:139, ui/src/model/worker-page.ts:575-610
F3 The figures row's origin is a string shown as given ui/src/model/worker-page.ts:551, :581
F4 ItemAction ids are a closed union; method is "DELETE" | "POST"; an action may carry a confirm, a body, an outcome toast from the answer, and a failure title ui/src/model/actions.ts:26-50
F5 workerActions offers nothing unless the mode is gateway; the mode is "gateway" | "worker", anything else unknown ui/src/model/actions.ts:234-240, ui/src/data/mode.ts:4, :43
F6 useActions().run skips an item key in flight, sends api.write(method, path, {body, timeoutMs}), shows the success or outcome toast, and on an error shows the daemon's message under the failure title with Retry ui/src/state/actions.ts:72-108
F7 api.write and send take only DELETE and POST; the body is sent as JSON; the default limit is 10 s ui/src/data/api.ts:1, :29, :106, :190-196
F8 routeKey('/v1/warm-pool') is ['warm-pool']; a key polls only if TIMES names it (workers every 15 s) ui/src/state/queries.ts:41-50, :66-68, :88-90
F9 staleKeys maps an event name to the keys it marks; an unlisted name marks nothing; warm-pool.target-missed is unlisted ui/src/model/stale-keys.ts:17-44
F10 ChoiceChips is a radio group with a legend and one chosen value ui/src/ds/choice.tsx:11-36
F11 The confirm host takes a title, a body, a confirm and a busy label ui/src/ds/confirm-dialog.tsx:8-17
F12 The tab's tests render the page's markup from a view ui/src/screens/fleet/fleet.test.tsx:282, :324-389
F13 The browser lane opens the Warm pool tab e2e/console/workers.spec.ts:954
F14 The console's worker page is described on the website website/src/content/docs/docs/worker/console.mdx:115
F15 warm.forget treats a field left out as matching every kind, and an image tag left out also matches tagged kinds; it emits no event src/core/warm-pool/learned.ts:186-198, src/core/warm-pool/converger.ts:190-199
F16 ChoiceChips hides its legend and has no disabled prop ui/src/ds/choice.tsx:12-22
F17 The in-flight flag clears when the answer arrives; an event's re-read lands at least 300 ms later ui/src/state/actions.ts:100-101, ui/src/state/queries.ts:29-31
Modules touched

Searches: WarmTab, warmTabOf, warmPoolRows, ItemAction, "DELETE" | "POST", staleKeys, TIMES, Warm pool in ui/src/, e2e/console/ and website/.

  • ui/src/model/actions.ts: ids set-warm-targets and forget-warm-kind; method gains "PUT"; warmTargetActions(list, mode) (new) builds each row's −, +, Use config or Remove, and the Learn choices; learnedKindActions(kind, mode) (new) builds Forget. Both answer [] unless the mode is worker.
  • ui/src/model/worker-page.ts: warmTargetsOf(answer) (new) shapes the Targets and Learned kinds rows.
  • ui/src/data/api.ts: write and send take "PUT".
  • ui/src/state/workers.ts (or a new ui/src/state/warm.ts): reads GET /v1/warm-pool only in worker mode.
  • ui/src/state/queries.ts: 'warm-pool' in TIMES, 15 s like workers.
  • ui/src/model/stale-keys.ts: warm-pool.targets-changed marks ['warm-pool'] and the workers (['workers'], ['inbox'], as every workers mark does).
  • ui/src/state/actions.ts: a PUT's answer sets the ['warm-pool'] data; a Forget marks it stale after its answer.
  • ui/src/ds/choice.tsx: a shown legend and a disabled prop (F16).
  • e2e/console/workers.spec.ts: the Done when test.
  • ui/src/screens/fleet/worker-page.tsx: the two panels.
  • ui/AGENTS.md (Actions, Reads), website/src/content/docs/docs/worker/console.mdx.
flowchart LR
  SC[screens/fleet/worker-page *] --> ST[state: warm read *]
  SC --> AC[state/actions run]
  ST --> Q[state/queries *]
  SC --> MA[model/actions *]
  SC --> MW[model/worker-page *]
  AC --> API[data/api *]
  LV[live stream] --> SK[model/stale-keys *]
sequenceDiagram
  participant O as Operator
  participant C as Console
  participant D as Daemon (worker)
  O->>C: + on ios iPhone 17 26.0
  C->>D: PUT /v1/warm-pool/targets {targets: runtime + changed row, learn: runtime.learn}
  alt 200
    D-->>C: warm.list answer
    C-->>O: toast Keeping 3 ios iPhone 17 26.0 warm
    D--)C: event warm-pool.targets-changed
    C->>D: GET /v1/warm-pool, GET /v1/workers (stale)
  else 400, 501 or no answer
    D-->>C: error
    C-->>O: error toast Couldn't change the warm pool, the message, Retry
  end
Contract and event changes

none: the console reads #1143's warm.list answer and sends its warm.set input through #1144's routes; it adds no contract shape.

Other code on the same state

Searches: writers of the runtime list (warm.set: #1144's CLI and this tab), readers of ['warm-pool'] (this tab only), the workers' warmPool figures (warmTabOf).

Component Both act Wins
A CLI warm set or another console between this tab's read and its PUT this tab sends the list it last read with its one change the later PUT; the event marks this tab stale and it reads the list again
Two clicks before the first answer the second is disabled while the write is in flight (F6) the first
The figures table (['workers']) changes after the pool's pass, read again on the event —
Failure modes
Call Outcome What happens Limit, counted from
GET /v1/warm-pool ok the panels show 10 s, from the read
GET /v1/warm-pool error or no answer the panels show the page's refusal text in place of the rows; the figures still show 10 s, from the read
PUT /v1/warm-pool/targets 200 success toast 10 s, from the click
PUT 400, 501 error toast with the daemon's message and Retry 10 s
PUT no answer error toast The daemon did not answer. (F6) 10 s
DELETE /v1/warm-pool/learned 200 Forgot <kind>, or … was already forgotten 10 s
DELETE error Couldn't forget <kind> with the message 10 s

The console writes no state of its own.

The read failure has no Tests line of its own: it is the page's refusal, as every read on the page (useRouteQuery).

Rules in play
  • ADR 0037 §3, "One list of actions per kind of item": the target row's controls come from warmTargetActions, Forget from learnedKindActions.
  • ADR 0037 §4, the console reads the daemon's mode and "never guesses": nothing is offered and GET /v1/warm-pool is not read unless the mode is worker.
  • ADR 0037 §5: success toasts leave, error toasts carry the daemon's message.
  • ADR 0044, "the console reads what its page shows, and events mark it stale": ['warm-pool'] is read only on this tab and marked by warm-pool.targets-changed.
  • ADR 0056 §5–6: the raise base, the stored runtime order, worker only.
  • Documentation rule 9: worker/console.mdx describes the panels.
Tests

Seam: the tab's model and markup (ui/src/screens/fleet/fleet.test.tsx, ui/src/model/actions.test.ts), useActions().run (ui/src/state/actions.test.tsx), staleKeys through the query client (ui/src/state/queries.test.ts).

  • An operator opens the Warm pool tab on a worker and sees the targets with a count stepper, Use config or Remove on runtime rows, a Learn choice and Forget on learned kinds: mode worker / gateway / unknown; a configured, a runtime and a replaced row; count 0 disables −, 256 disables +; a learned kind.
  • An operator steps a count, uses config, removes a row or picks Learn, and sees one PUT /v1/warm-pool/targets with the whole runtime list changed by that one thing, then a toast: + on a configured row adds a runtime row; + on a row whose learned peak is above its count raises from the peak; − on a runtime row; − to 0 (Keeping no …, Its idle devices shut down now.); Use config drops the row; Remove drops a runtime-only row (Stopped keeping …); Learn off, On, and Config (drops learn; toast from the answer); a runtime learn kept on a count change; three + in a row send 3, 4, 5, each from the last answer; + on a second row keeps the first row's change; every control disabled while a PUT is out; 400 and 501 show the daemon's message.
  • An operator runs Forget on a learned kind and sees a confirm naming it, then one DELETE /v1/warm-pool/learned and a toast: confirmed, then ['warm-pool'] read again; cancelled sends nothing; an Android kind with an image tag passes it; an untagged kind whose match covers a tagged one names both in the confirm and the toast; nothing forgotten.
  • warm-pool.targets-changed marks the warm-pool list and the workers stale: the event; warm-pool.target-missed marks nothing, as today.

Done when

  • pnpm exec vitest run --project unit ui/src/model ui/src/state ui/src/screens/fleet passes, each Tests line a test there.
  • pnpm test:console --project=chromium e2e/console/workers.spec.ts passes with one more test: on a worker, + on a target sends one PUT /v1/warm-pool/targets and a toast shows.
  • website/src/content/docs/docs/worker/console.mdx describes the Targets and Learned kinds panels and says they show only on a worker.

Out of scope

  • Add device… (#1146).
  • A stepper on a learned kind.
  • Any warm control on a gateway's console.

Depends on

  • #1144
  • #1133
  • #1135

Written by an agent.

主要语言
TypeScript
星标
705
派生
40
平均合并
12 小时 9 分钟
30 天内合并 PR
376

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

callstackincubator/simlock 的其他 Issue

查看 callstackincubator/simlock 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。