Console: see and change the daemon's settings, and restart it

Đang mở
#1,151 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@leonardoxr đang làm issue này rồi.

Từ ngày 31/10/2026.

  • #1152 của @leonardoxr — đang mở

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript

Hướng nghiên cứu

Start with ADR 0057 and the listed entry points src/contract/schemas.ts:930-1055 and src/core/config.ts:679-694; then trace the config and daemon restart paths named in the issue. The work spans daemon ownership, HTTP routes, CLI behavior, and the console Settings page, so check the referenced decisions and related issues before choosing a part. Done means the completion conditions hold for both worker and gateway consoles.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

feature:spec

Request: #1130

Problem

From #1130, item 5: an operator "has to leave the console for the CLI" to "change any setting. Warm-pool targets, idle timeouts, emulator flags, stream and agent-device options all live in config.json and change only through simlock config set or by editing the file. There is no settings page and no HTTP route to read or change config."

Every change also waits for a restart, and the only way to restart is a terminal (simlock daemon stop, then simlock daemon start). The one read there is, simlock config, prints the gateway token and alert secrets as written (#1097).

Who it is for

A developer running one worker for their own coding agents, and an operator running a gateway. Both keep the console open all day and want to change a timeout, an emulator flag or the HTTP port without a terminal.

Outcome

From the console of a worker or a gateway, an operator:

  • sees every setting the daemon takes: its value now, the value saved for the next start, its default, and whether a change applies at once or on restart;
  • changes any setting simlock config set can change, checked by the same rules, and gets the same refusal message for a bad value;
  • sets or replaces a gateway's alert destinations without ever seeing them on the page (a worker's gateway.token must change with gateway.url, so joining a fleet stays a CLI step);
  • is asked first before a change that can cut the console off, and is told where the console will be after the restart;
  • restarts the daemon from the page when a saved change waits for a restart.

simlock config set keeps working, and goes through the running daemon, so the console and the CLI never write the file behind each other's back.

How it works for the user

flowchart TD
  A[Operator opens Settings] --> B[Rows grouped by section: value, default, Live or On restart]
  B --> C{Edits a row}
  C -->|key that can cut the console off| D[Confirm naming the risk]
  D -->|Keep| B
  D -->|Save| E[Daemon checks it]
  C -->|other key| E
  E -->|refused| F[Error toast with the reason; the row keeps the typed value]
  E -->|live key| G[Saved and applied now]
  E -->|restart key| H[Saved; row reads Restart pending; Restart daemon offered]
  H --> I[Restart daemon, confirm]
  I --> J[Console shows Reconnecting, then the new values]

The CLI, before and after, with the daemon running:

$ simlock config set idle.shutdownAfterMs 300000
Updated idle.shutdownAfterMs in /Users/me/.simlock/config.json; takes effect on daemon restart.      (today)
Updated idle.shutdownAfterMs in /Users/me/.simlock/config.json; applied now.                          (after)

$ simlock config set lease.defaultTtlMs 10m
{"error":{"code":"USAGE","message":"Invalid config after setting lease.defaultTtlMs: ..."}}           (today, exit 2)
{"error":{"code":"USAGE","message":"Invalid config after setting lease.defaultTtlMs: ..."}}           (after, the same, now from the daemon)

$ simlock daemon restart
Usage: simlock daemon <start|stop|status|logs [--follow]|install|uninstall>                           (today, exit 2)
Daemon restarting                                                                                     (after)

With no daemon running, simlock config set writes the file itself and prints what it prints today.

Examples

What config.set does with a key, through the console or the CLI, while a worker runs:

Key and value Today (config set, file only) After
idle.shutdownAfterMs 300000 saved, applies on restart saved and applied now
diskPressure.freeBytesThreshold 5368709120 saved, applies on restart saved and applied now
lease.defaultTtlMs 600000 saved, applies on restart saved, applies on restart, row reads Restart pending
http.port 4800 saved confirm first; saved; "After restart, the console is at http://127.0.0.1:4800/"
http.enabled false saved confirm first; saved; "After restart, HTTP is off and this console stops"
gateway.token tok_abc alone refused: needs gateway.url refused the same way; a secret's value is never shown
warmPool.targets [...] saved CLI: saved, applies on restart. Console: read-only row linking to the Warm pool tab
idle.shutdownAfterMs "soon" refused, exit 2 refused, 400 or exit 2, file unchanged
foo.bar 1 refused: unknown key refused: unknown key
mode "gateway" refused refused; no row on the page

What could go wrong

  • A host or port change leaves the console on an address the operator must type; turning HTTP off ends the console until the CLI turns it on again. The confirm says so.
  • A restart that does not come back leaves the console on "Reconnecting"; the reason is in daemon.log. Likely only after a host or port another program holds.
  • A hand edit of config.json made in the same second as a console save can be lost.
  • A lease request still waiting when the daemon restarts fails and must be sent again, as with any restart.

Words used

  • setting: one key of config.json, e.g. idle.shutdownAfterMs.
  • live key: a setting the daemon applies the moment it is saved, e.g. idle.shutdownAfterMs.
  • restart key: a setting saved now and applied at the next start, e.g. http.port.
  • running value: what the daemon uses now. Saved value: what config.json gives at the next start.
  • pending: a setting whose saved value differs from its running value, e.g. http.port saved as 4800 while the daemon still listens on 4701.
  • secret setting: gateway.token or gateway.alerts.destinations; set or replaced, never shown.
  • lock-out key: a setting that can cut the console off: http.enabled, http.host, http.port, http.proxyAuth.
  • json row: a setting edited as one JSON value, e.g. warmPool.targets or capabilities.

Non-goals

  • Changing a worker's settings from the gateway's console. Deferred.
  • Removing a key (going back to the default by deleting it). config set cannot today; this does not add it.
  • Making more keys live than the three in ADR 0057 §3.
  • Changing what config.get and simlock config print (#1097 owns that).
  • Editing warm-pool targets or learn on the Settings page (the Warm pool tab does, #1137).
  • Restarting a worker through the gateway.

Completion conditions

  • On a worker's console, Settings lists every setting with its running value, saved value, default and Live or On restart; the gateway token and alert destinations read Set or Not set.
  • Saving idle.shutdownAfterMs from the console applies it with no restart: an idle device shuts down after the new time.
  • Saving http.port asks first, then shows the new console address and Restart pending; after Restart daemon the daemon listens on the new port, and the console opens at the new address.
  • A bad value is refused with the same message from the console and from simlock config set, and the file is unchanged.
  • simlock config set with a daemon running is written by the daemon and emits config.changed, naming the key and the caller and no value.
  • On a gateway's console, Settings lists only the gateway's own settings.

Open questions

none

Decisions

  • ADR 0057 — The daemon owns config.json while it runs, and the console edits every setting through it (PR #1152): one writer, config.list and config.set, three live keys, write-only secrets, daemon.restart through the updater, the Settings page and its lock-out confirms.
  • ADR 0042 — Simlock updates itself through a frozen call and a detached updater: the restart reuses its updater process.
  • ADR 0037 — The console acts through the HTTP routes: every Settings action is a route, a confirm and a toast.
  • ADR 0044 — The console reads what its page shows, and events mark it stale: config.changed marks the settings read.
  • ADR 0056 (Proposed, #1137) — runtime warm targets: the Settings page leaves warmPool.targets and learn to the Warm pool tab.

Shared values

Value or state Rule Written by Read by Source
A settings row { key, kind, values?, running?, saved?, default?, apply, secret, set?, pending }; kind is boolean, number, string, enum (with values) or json; apply is live or restart; a secret row has set and no running, saved or default: set follows the saved value, or the running one when the file does not load; pending is true when the saved value differs from the running value, on any row, a secret row included (a live key saved through config.set never is; one edited by hand in the file is, until the next start) #1153 #1154 (its answer), #1156 ADR 0057 §2
The rows of a role Walk configSchema: every object field recurses, at any depth, optional objects included (android.emulator.gpu, warmPool.quarantine.maxRetries, eventLog.retention); every other field is one row (json for an array, a record or a union: warmPool.targets, capabilities, gateway.alerts.destinations, lease.maxPerRequester); http.proxyAuth is one json row; plus a drivers json row; no mode row. A gateway: only the sections in GATEWAY_CONFIG_KEYS, without gateway.url, gateway.token, gateway.label #1153 #1154, #1156 src/contract/schemas.ts:930-1055, src/core/config.ts:679-694
fileProblem The loader's message when config.json does not load, at most 2000 characters; rows then have no saved #1153 #1156 ADR 0057 §2
Live keys idle.shutdownAfterMs, idle.deleteAfterMs, diskPressure.freeBytesThreshold; every other key is restart #1153 (list), #1154 (applies them) #1156 ADR 0057 §3
Secret keys gateway.token, gateway.alerts.destinations: the keys redactConfig masks, one list both read #1153 #1154, #1156 src/core/config.ts:482-500
Lock-out keys http.enabled, http.host, http.port, http.proxyAuth. Not gateway.url or gateway.token: the loader refuses either saved alone, and a worker with both set has its own HTTP off, so its console is never reached #1156 — ADR 0057 §6, src/core/config.ts:803-835
Read-only on the page warmPool.targets, warmPool.learn: shown, linked to the Warm pool tab, never edited on Settings #1156 — ADR 0057 §6
GET /v1/config admin; 200 { rows, fileProblem? } from config.list #1153 #1156 ADR 0057 §6
PUT /v1/config/{key} admin; body { value } (any JSON); 200 { rows, removed? } from config.set; 400 BAD_REQUEST on a refusal #1154 #1156 ADR 0057 §6
Keys config.set takes Every key simlock config set takes today: any dotted path, checked by the same validation. The touched rows are the rows whose key equals the key, starts with <key>. (a parent, idle), or is a prefix of it (a field inside a json row, http.proxyAuth.header). The answer's rows are the touched rows after the write; none for a key no row holds (on a gateway, idle.shutdownAfterMs, which it ignores). The live ones among them apply at once #1154 #1156 src/cli/commands/config.ts:89-100
Retired key config.set drops eventLog.rotateBytes from the file before it validates, as config set does, and lists it in removed; the CLI prints today's line Removed eventLog.rotateBytes from <path>: it is no longer used. on stderr #1154 — src/cli/commands/config.ts:47, :55-59, :72-79
{key} 1 to 200 characters, checked by the contract (400 BAD_REQUEST past it); a key with an empty segment is refused by the daemon, 400 Invalid config key: <key>, the CLI's words; any other key goes to the validation, which refuses an unknown one. One check, in the daemon, for the CLI and HTTP alike #1154 #1156 src/cli/commands/config.ts:90-93
Refusal message Invalid config after setting <key>: <loader message>; HTTP 400 BAD_REQUEST; the CLI prints it as USAGE, exit 2, with and without a daemon; never holds a secret's value #1154 #1156 src/cli/commands/config.ts:52
CLI success line restart key: Updated <key> in <path>; takes effect on daemon restart. (as today); live key through a daemon: Updated <key> in <path>; applied now. #1154 — src/cli/commands/config.ts:60-62
config.json Written only by the running daemon's config.set while one runs, one call at a time, read from disk each time, atomic, 0600; by the CLI only when no daemon of that role runs #1154 #1153 (saved values) ADR 0057 §1
config.changed { keys, applied, requesterId }, after the write: keys the touched rows' keys, or the given key when none; applied live when there are touched rows and all are live, else restart; never a value; none on a refusal or an offline CLI write #1154 #1156 (marks the settings read stale) ADR 0057 §8
POST /v1/restart admin; 202 { restarting: true } from daemon.restart; a second call while one runs 202 with nothing new launched; 503 DAEMON_UPDATING during an update; while a restart runs, a daemon.update that would start an update answers DAEMON_STOPPING and daemon.update {query} answers as today; a restart shows in no update field and emits no daemon.update-failed #1155 #1156 ADR 0057 §5
Updater restart mode --restart --pid <pid> [--gateway]: daemon.stop, wait until the socket is free and the pid has exited (10 min, then SIGKILL the pid), daemon start (running within 2 min, else exit 1); no install, no backup, no rollback #1155 — src/updater/index.ts:40-41, :96-140, :247-272
Protocol #1153, #1154 and #1155 each bump it by one; the PR that merges second bumps again. The bump alone sets no order; the chain comes from what the tasks share: #1154 uses #1153's settings handle and rows, and #1155 adds its case and handler entries beside #1154's in the same DaemonServer switch and handler tables each — src/contract/protocol.ts:13

Behaviours

Behaviour (invoker, action, what it sees) Seam Cases Task
An admin reads GET /v1/config on a worker and gets one row per setting with its kind, running, saved and default values and how it applies startDaemon (src/daemon/main.test.ts) through the admin client, the socket (src/daemon/server.test.ts) and createHttpApp (src/http/app.test.ts) a number key; an enum key with its values; a json key (warmPool.targets); drivers; http.proxyAuth as one row; an optional key unset (gateway.url); no mode row; a live key; a restart key #1153
A secret row says only whether it is set same gateway.token set and unset; gateway.token changed in the file after start (set, pending); two alert destinations with url and secret; the answer's text holds none of the three values #1153
A row says pending when the file differs from what runs same a restart key changed in the file after start (pending); a live key changed by hand in the file (pending too: only config.set applies it live); the file no longer loads (fileProblem, no saved); no file (saved is each default); the file unreadable (fileProblem the error's message); a fileProblem over 2000 characters (cut with …) #1153
A gateway lists only its own settings, and an agent is refused same gateway: http.port and gateway.disconnectedRetentionMs listed, idle.shutdownAfterMs and gateway.token not; an agent token gets 403; the call over the daemon socket (listConfig()) #1153
An admin saves a setting with PUT /v1/config/{key} and the daemon writes the file and answers the rows it touched same a restart key (file changed, running unchanged, pending); a live key (running changed, config.get shows it); a parent key idle (both rows answered, both live); a field inside a json row http.proxyAuth.header (the http.proxyAuth row answered); a key a gateway ignores (no rows, saved); eventLog.rotateBytes in the file (dropped, listed in removed); other keys and a hand edit kept; file mode 0600; two saves at once both kept #1154
A saved live key is used by the cleanup reaper and the warm pool on their next run startDaemon with a fake clock and a ready idle device idle.shutdownAfterMs lowered: a device idle since its lease ended shuts down at the new time with no restart (the reaper); a never-leased ready device no target keeps shuts down at the new time (the warm pool); idle.deleteAfterMs lowered; diskPressure.freeBytesThreshold raised over free disk: pressure is reported #1154
A bad value is refused with the CLI's message and the file is unchanged same as the save row a wrong type; an unknown key; lease.defaultTtlMs over lease.maxTtlMs; mode; a bad gateway.token refused with no value in the message; a key with an empty segment (Invalid config key: <key>); a body with no value; the file is not valid JSON #1154
A save emits config.changed with the key, how it applied and the caller same live key; restart key; no event on a refusal; the payload holds no value #1154
simlock config set goes through a running daemon and writes the file itself when none runs runCli (src/cli/index.test.ts) daemon running: written by the daemon, applied now. for a live key; none running: written by the CLI, no daemon started; --gateway with no gateway present: written by the CLI; daemon running and no admin token: refused, file unchanged; a refusal with a daemon running prints USAGE and the daemon's message, exit 2; the daemon dropped eventLog.rotateBytes: the CLI prints today's Removed line; a socket left by a crashed daemon (connection refused): written by the CLI; a daemon that does not answer the connect in time: the connect's error, exit 1, file unchanged #1154
An admin restarts the daemon with POST /v1/restart and the daemon launches the updater once in restart mode startDaemon with FakeUpdaterLauncher (src/daemon/main.test.ts), the socket (src/daemon/server.test.ts) and src/http/app.test.ts first call 202 and one launch in restart mode with the pid and the role; a second call 202, no second launch; the same call over the daemon socket; during an update 503 DAEMON_UPDATING; a new daemon.update during a restart DAEMON_STOPPING, while daemon.update {query} answers as today; the launch throws: 500 INTERNAL, the daemon keeps running and a later call launches again; the updater exits non-zero before stopping the daemon: a later call launches again, no daemon.update-failed; an agent 403 #1155
The updater in restart mode stops the daemon and starts it again, with no install runUpdater (src/updater/index.test.ts) and NodeUpdaterLauncher (src/ports/updater-launcher.test.ts) the launcher's arguments are --restart --pid <pid> plus --gateway for a gateway; starts (running at any version): exit 0, no npm call, no backup, no result file; does not start in 2 minutes: one stderr line, exit 1, no reinstall, nothing stopped; --gateway starts the gateway #1155
simlock daemon restart asks the running daemon to restart runCli (src/cli/index.test.ts) running: prints Daemon restarting, --json {"status":"restarting"}; none running: fails as daemon stop does #1155
An operator opens Settings and sees the rows grouped by section the settings model and screen markup (ui/src/model/settings.test.ts, ui/src/screens/settings/settings.test.tsx) and e2e/console/settings.spec.ts a value (the running one; a pending row adds the saved one); a secret (Set, Not set); Live, On restart, Restart pending; fileProblem shown above the rows; warmPool.targets read-only with its link; a gateway's rows #1156
An operator edits a row and saves it useActions().run (ui/src/state/actions.test.tsx) and e2e/console/settings.spec.ts boolean, number, string, enum, json; json that does not parse is refused on the page and nothing is sent; a refusal shows the daemon's message and keeps the typed value (gateway.token alone is refused this way); a secret's field starts empty; after a 200 the answer's rows replace those keys in ['config'] until the next read #1156
A lock-out key asks first and then shows where the console will be same http.port (new address); http.enabled false (console stops); http.proxyAuth (sign-in line); Keep sends nothing #1156
An operator restarts the daemon from Settings same Restart daemon shown only with a pending row; confirm, then one POST /v1/restart and the success toast; a 503 shows the daemon's message #1156
config.changed marks the settings read stale the console's event map (ui/src/state/queries.test.ts) config.changed marks ['config']; another event does not #1156

Tasks

flowchart LR
  A["#1153 read: GET /v1/config"] --> B["#1154 change: PUT /v1/config/key, CLI through the daemon"]
  B --> C["#1155 restart: POST /v1/restart"]
  C --> D["#1156 console Settings page"]
  X["#1135, #1145, #1146 (other features)"] --> D
  Y["#1143 (feature #1137)"] --> B
  • #1153 Settings: read every setting through GET /v1/config — an admin reads every setting with its running, saved and default values, secrets hidden. Risk: a secret shows on the wire.
  • #1154 Settings: change a setting through the daemon, live where it can — an admin or the CLI changes any setting through the running daemon; three keys apply at once. Risk: a change lost, or the CLI and the daemon both writing the file.
  • #1155 Settings: restart the daemon with POST /v1/restart and simlock daemon restart — an admin restarts the daemon without a terminal. Risk: a daemon that stops and does not come back.
  • #1156 Console: a Settings page that edits settings and restarts the daemon — an operator does all of it from the console. Risk: a save that cuts the console off without warning.

Completion conditions:

  • Settings lists every setting with its values and how it applies; secrets read Set or Not set: #1153 (data), #1156 (page).
  • Saving idle.shutdownAfterMs applies with no restart: #1154.
  • Saving http.port asks first, shows the new address and Restart pending; Restart daemon brings the console back: #1155 (restart), #1156 (confirm, address, button).
  • A bad value gets the same message from the console and the CLI, file unchanged: #1154.
  • simlock config set with a daemon running goes through it and emits config.changed: #1154.
  • A gateway's Settings lists only the gateway's settings: #1153 (rows), #1156 (page).

Open work in the same area:

  • #1143 (feature #1137, ADR 0056): wires WarmTargetsControl into the same new WarmPool({...}) call in src/core/create-core.ts:247-272 where #1154 turns idle into a live holder, and rewrites src/core/warm-pool/converger.ts, where #1154 changes the idle read: #1154 Depends on #1143.
  • #1144 (feature #1137): adds warm.* to src/contract/operations.ts, both dispatchers, the client and src/http/admin-declarations.ts in other places; no Depends on: the protocol bump alone sets no order. ADR 0057 narrows 0056 §1's "config.json is never written by the daemon" to warm.set.
  • #1145 (Warm pool tab edits): adds PUT to api.write and to ItemAction's method, which #1156's save uses: #1156 Depends on #1145. The Warm pool tab #1156 links to exists today read-only (ui/src/screens/fleet/worker-page.tsx:381-425).
  • #1133, #1134, #1135 (feature #1131, ADR 0055): #1135 adds an id to ItemAction's closed id list in ui/src/model/actions.ts, the same lines #1156 adds save-setting and restart-daemon to: #1156 Depends on #1135. If either feature is dropped, its Depends on goes with it.
  • #1097 (bug, simlock config prints secrets): this feature does not change config.get. #1153 moves redactConfig's fields into one list of secret keys; a fix for #1097 edits the same function, so whichever lands second takes the other's list. No Depends on: #1097 has no fix yet.
  • #1082 (open PR, android.emulator.hardwareKeyboard) and #1118 (ios.simulator.audio): a new key appears as a row with no change here, since the rows come from configSchema.
  • #1146 (feature #1137, Add device…): adds add-device to the same ItemAction id list, changes run in ui/src/state/actions.ts, and adds a select to the confirm dialog: #1156 Depends on #1146, and its Select is that one select, moved into ui/src/ds/field.tsx if #1146 kept it inside the dialog, so one control has one component.
  • Open PRs that change contract shapes (#1091, #1121, #1122, #1123, #1124, #1125, #1127): each bumps the protocol too; whichever merges second bumps again. No Depends on.

Written by an agent.

Ngôn ngữ chính
TypeScript
Star
730
Fork
44
Merge trung bình
16 giờ 13 phút
Pull request đã merge (30 ngày)
387

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của callstackincubator/simlock

Tất cả issue của callstackincubator/simlock

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.