From 9c7adc4438109d233b64fdd52ccb3c503ecd1b15 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 09:02:34 +0100 Subject: [PATCH 1/5] docs(adr): 0086 on Windows the daemon service is a logon task that runs a Simlock supervisor --- ...gon-task-that-runs-a-simlock-supervisor.md | 120 ++++++++++++++++++ docs/internal/adr/README.md | 1 + 2 files changed, 121 insertions(+) create mode 100644 docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md diff --git a/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md b/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md new file mode 100644 index 000000000..27152dba2 --- /dev/null +++ b/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md @@ -0,0 +1,120 @@ +# 0086. On Windows the daemon service is a logon task that runs a Simlock supervisor + +- **Status:** Proposed +- **Date:** 2026-11-18 +- **Issue:** [#1691](https://github.com/callstackincubator/simlock/issues/1691) (request [#1069](https://github.com/callstackincubator/simlock/issues/1069)) +- **Narrows:** [ADR 0041](0041-the-daemon-can-run-under-the-users-service-manager.md) + §1 (Windows is no longer a usage error), §3 (how the saved + environment reaches the daemon), §4 (who restarts it), §5 (no SIGTERM + on Windows) and §8 (the reboot hint). + +## Context + +On Windows `simlock daemon install` is a usage error. A daemon a command +starts lives in that command's logon session: over ssh it dies when the +ssh session ends, and after a crash or a reboot nothing starts it again. + +Windows offers two per-user ways to start a program: a Windows service +and a Task Scheduler task. Measured on Windows 11 23H2 (2026-11-18): + +- A service runs as a system account or needs the user's password, and + must speak the service control protocol, which Node does not. +- A task runs as the user with no password saved. An **interactive** + task with a logon trigger runs in the user's desktop session; a + standard account can register and run it. A "logged on or not" (S4U) + task runs in session 0 at boot, but a standard account cannot run one + (it lacks the batch logon right). +- A task that runs `node.exe` opens a terminal window on the desktop, and + closing that window ends the daemon. `conhost.exe --headless` runs the + same program with no window. +- A task's "restart on failure" setting does not restart a program that + exits non-zero: it covers only a task that fails to start. +- A task runs at below-normal priority unless its XML says otherwise, is + stopped after 72 hours, and does not start on battery. +- Starting an interactive task while its user has no desktop session + succeeds and runs nothing. +- Ending a task kills only the process it started (here `conhost.exe`); + the programs below it keep running. + +```mermaid +flowchart LR + subgraph Today + C1[a simlock command] --> S1[CLI spawns daemon in the caller's session] + S1 -->|ssh ends, crash, reboot| N1[daemon gone] + end + subgraph After + L[user logs in] --> T[logon task] + C2[a simlock command] -->|service installed and user has a desktop session| T + T --> V[supervisor, no window] + V --> D[daemon] + D -->|exits non-zero| V + end +``` + +## Decision + +1. **The service is a per-user Task Scheduler task.** It has a logon + trigger for the installing user only, runs with that user's + interactive token at the user's normal (not elevated) level, and has + the same name as on macOS (ADR 0041 §2), in the root task folder. It + runs at normal priority, never times out, ignores battery state, and + ignores a second start while it runs. Install needs no administrator + rights and stores no password. +2. **The task runs a Simlock supervisor, with no window.** The task runs + `conhost.exe --headless` with the Node path and the supervisor entry + that ships beside `dist/daemon/main.js`. The supervisor starts the + daemon as auto-start does (the role's flag, stdout and stderr appended + to `daemon.log`, no window), with the variables install saved (ADR + 0041 §3) carried in the task's own arguments. The supervisor holds no + daemon state. +3. **The supervisor restarts after a failure only.** A daemon that exits + 0 (a clean stop, or `Daemon already running`) ends the supervisor and + the task. A daemon that exits non-zero or is killed is started again + 10 s later, forever, as launchd and systemd do. Each restart writes one + line to `daemon.log`. +4. **A stop is `daemon.stop`.** Windows has no SIGTERM. `daemon stop`, + install and uninstall stop the daemon through the daemon contract, as + on every platform. Ending the task in Task Scheduler stops nothing + that matters: the daemon and its devices keep running, as launchd's + `AbandonProcessGroup` and systemd's `KillMode=process` leave them. +5. **Not loaded means no desktop session.** The service is *not loaded* + while the installing user has no desktop session (no process of the + user in a session other than 0). A start then spawns the daemon as + today with the notice ADR 0041 §6 prints, since running the task would + do nothing. A disabled task is not loaded too. +6. **Start at login, not at boot.** As on macOS, install prints one line: + turn on automatic login for this user to start after a reboot. + +## Consequences + +- A Windows worker comes back after a crash, and at every login; a + daemon started over ssh while the user is logged in at the screen runs + in the desktop session and outlives the ssh session. +- Emulators boot in the desktop session, with its GPU and at normal + priority, and show their windows there unless `headless` is set. +- Over ssh with nobody logged in at the screen, commands still spawn the + daemon, which dies with the ssh session, as today. +- Two Node processes run per role: the supervisor and the daemon. +- The doctor `service-broken` finding and `daemon status` gain the + manager name `task-scheduler`, a contract shape change that bumps the + protocol by one. +- `conhost.exe --headless` is undocumented. If a Windows release drops + it, install still succeeds but the task fails to start and `daemon + status` and the startup deadline show it. + +## Alternatives considered + +- **A boot task that runs whether the user is logged on or not (S4U).** + Starts at boot with nobody logged in, but a standard account cannot + run it and emulators would run in session 0 with no desktop. Rejected + for parity with macOS and for standard accounts. +- **A Windows service.** Needs a system account or a saved password, and + a service wrapper binary Simlock would have to ship. Rejected. +- **Task Scheduler's own restart, or a repeating trigger.** The first + does not restart after a non-zero exit; the second also restarts after + `daemon stop`. Rejected for the supervisor. +- **A Run key or the Startup folder.** Starts at login, but nothing + restarts the daemon and nothing can start it on demand. Rejected. +- **The daemon entry as its own supervisor (`main.js --service`).** + Loads the whole daemon into the supervisor process. Rejected for a + small entry. diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index a0820ea5b..623db69ef 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -118,3 +118,4 @@ the status is stale. | [0083](0083-a-worker-may-turn-single-slim-services-on-or-off-beside-its-categories.md) | A worker may turn single slim services on or off beside its categories | Accepted; narrows 0060 §1, §2 and 0066 §2 | | [0084](0084-a-worker-may-serve-a-platforms-enrolled-phones-only.md) | A worker may serve a platform's enrolled phones only | Accepted; narrows 0022 and 0009 §4 | | [0085](0085-an-ios-simulator-takes-keys-on-every-runtime-and-the-app-switcher-and-lock.md) | An iOS simulator takes keys on every runtime, and the app switcher and Lock | Accepted; narrows 0049 §4 | +| [0086](0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md) | On Windows the daemon service is a logon task that runs a Simlock supervisor | Proposed; narrows 0041 §1, §3, §4, §5 and §8 | From 8d9933a4bba324907239a1180aaf782ac3bc8d41 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 09:14:53 +0100 Subject: [PATCH 2/5] docs(adr): 0086 a supervisor stops when its task is gone or replaced --- ...rvice-is-a-logon-task-that-runs-a-simlock-supervisor.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md b/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md index 27152dba2..682191099 100644 --- a/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md +++ b/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md @@ -70,8 +70,11 @@ flowchart LR 3. **The supervisor restarts after a failure only.** A daemon that exits 0 (a clean stop, or `Daemon already running`) ends the supervisor and the task. A daemon that exits non-zero or is killed is started again - 10 s later, forever, as launchd and systemd do. Each restart writes one - line to `daemon.log`. + 10 s later, as launchd and systemd do. Each restart writes one line to + `daemon.log`. Before each restart the supervisor reads its task: when + the task is gone (uninstall) or names another install (a new install), + it stops instead, so a restart loop ends with the service, as launchd's + `bootout` and systemd's `disable --now` end theirs. 4. **A stop is `daemon.stop`.** Windows has no SIGTERM. `daemon stop`, install and uninstall stop the daemon through the daemon contract, as on every platform. Ending the task in Task Scheduler stops nothing From 6c20a4cac77a5f3131b374f79f86f4b17500b67b Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 09:17:24 +0100 Subject: [PATCH 3/5] docs(adr): 0086 the supervisor waits on its child; install ends the old instance --- ...is-a-logon-task-that-runs-a-simlock-supervisor.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md b/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md index 682191099..b2fb386e0 100644 --- a/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md +++ b/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md @@ -63,10 +63,10 @@ flowchart LR 2. **The task runs a Simlock supervisor, with no window.** The task runs `conhost.exe --headless` with the Node path and the supervisor entry that ships beside `dist/daemon/main.js`. The supervisor starts the - daemon as auto-start does (the role's flag, stdout and stderr appended - to `daemon.log`, no window), with the variables install saved (ADR - 0041 §3) carried in the task's own arguments. The supervisor holds no - daemon state. + daemon with the role's flag, its stdout and stderr appended to + `daemon.log` and no window, as a child it waits on (not detached), with + the variables install saved (ADR 0041 §3) carried in the task's own + arguments. The supervisor holds no daemon state. 3. **The supervisor restarts after a failure only.** A daemon that exits 0 (a clean stop, or `Daemon already running`) ends the supervisor and the task. A daemon that exits non-zero or is killed is started again @@ -74,7 +74,9 @@ flowchart LR `daemon.log`. Before each restart the supervisor reads its task: when the task is gone (uninstall) or names another install (a new install), it stops instead, so a restart loop ends with the service, as launchd's - `bootout` and systemd's `disable --now` end theirs. + `bootout` and systemd's `disable --now` end theirs. Install ends the + running task instance before it replaces the task, so its start is not + ignored while an old supervisor waits. 4. **A stop is `daemon.stop`.** Windows has no SIGTERM. `daemon stop`, install and uninstall stop the daemon through the daemon contract, as on every platform. Ending the task in Task Scheduler stops nothing From 7207c7f687fe830c86499bbf3dcde48cbc53a199 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 09:23:35 +0100 Subject: [PATCH 4/5] docs(adr): accept 0086 --- ...on-service-is-a-logon-task-that-runs-a-simlock-supervisor.md | 2 +- docs/internal/adr/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md b/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md index b2fb386e0..74c4142a4 100644 --- a/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md +++ b/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md @@ -1,6 +1,6 @@ # 0086. On Windows the daemon service is a logon task that runs a Simlock supervisor -- **Status:** Proposed +- **Status:** Accepted — not yet implemented - **Date:** 2026-11-18 - **Issue:** [#1691](https://github.com/callstackincubator/simlock/issues/1691) (request [#1069](https://github.com/callstackincubator/simlock/issues/1069)) - **Narrows:** [ADR 0041](0041-the-daemon-can-run-under-the-users-service-manager.md) diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index 623db69ef..3b583fde6 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -118,4 +118,4 @@ the status is stale. | [0083](0083-a-worker-may-turn-single-slim-services-on-or-off-beside-its-categories.md) | A worker may turn single slim services on or off beside its categories | Accepted; narrows 0060 §1, §2 and 0066 §2 | | [0084](0084-a-worker-may-serve-a-platforms-enrolled-phones-only.md) | A worker may serve a platform's enrolled phones only | Accepted; narrows 0022 and 0009 §4 | | [0085](0085-an-ios-simulator-takes-keys-on-every-runtime-and-the-app-switcher-and-lock.md) | An iOS simulator takes keys on every runtime, and the app switcher and Lock | Accepted; narrows 0049 §4 | -| [0086](0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md) | On Windows the daemon service is a logon task that runs a Simlock supervisor | Proposed; narrows 0041 §1, §3, §4, §5 and §8 | +| [0086](0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md) | On Windows the daemon service is a logon task that runs a Simlock supervisor | Accepted — not yet implemented; narrows 0041 §1, §3, §4, §5 and §8 | From 7fe20838da634b7db3e8b05e4f8aec37a0f72c45 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 14:06:48 +0100 Subject: [PATCH 5/5] =?UTF-8?q?docs(adr):=200086=20narrows=200041=20=C2=A7?= =?UTF-8?q?6=20and=20=C2=A79,=20and=20a=20dropped=20conhost=20--headless?= =?UTF-8?q?=20fails=20install=20at=20the=20deadline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...is-a-logon-task-that-runs-a-simlock-supervisor.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md b/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md index 74c4142a4..babd982fb 100644 --- a/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md +++ b/docs/internal/adr/0086-on-windows-the-daemon-service-is-a-logon-task-that-runs-a-simlock-supervisor.md @@ -6,7 +6,11 @@ - **Narrows:** [ADR 0041](0041-the-daemon-can-run-under-the-users-service-manager.md) §1 (Windows is no longer a usage error), §3 (how the saved environment reaches the daemon), §4 (who restarts it), §5 (no SIGTERM - on Windows) and §8 (the reboot hint). + on Windows), §6 (what "not loaded" means, and the 10 s limit on + launchctl and systemctl calls, which Windows does not use), §8 (the + reboot hint) and §9 (on Windows "broken" checks the Node path and the + supervisor entry, because the service runs a supervisor, not + `main.js`). ## Context @@ -104,8 +108,10 @@ flowchart LR manager name `task-scheduler`, a contract shape change that bumps the protocol by one. - `conhost.exe --headless` is undocumented. If a Windows release drops - it, install still succeeds but the task fails to start and `daemon - status` and the startup deadline show it. + it, install registers the task but the task fails to start, so + `daemon install` waits out the startup deadline and fails with + `DAEMON_STARTUP_FAILED` after 20 s; `daemon status` shows the broken + start. ## Alternatives considered