Repository navigation
Description
Part of #806.
Scope
Refuse a joined worker's own HTTP API/console at config validation, with the agreed error. Cover merged config and real CLI validation/startup; document manual migration. Adapt existing agent-device and console fixtures to supported standalone/gateway topologies and remove the obsolete direct-versus-gateway timing comparison.
One task keeps the validation and the fixtures it invalidates together. It changes core config plus tests/docs, not production agent-device or listener lifecycle.
In short
A joined worker is a worker with gateway.url and its required join token, for example wss://fleet.example plus gateway.token. It must have HTTP off; a standalone worker can still enable HTTP. The role comes from how the daemon is started, not a config key (F1).
flowchart LR
A[File and overrides] --> V[Config loader: NEW joined-worker HTTP refusal]
V -- valid --> D[Worker startup]
V -- conflict --> E[Error naming http.enabled]
For an otherwise valid joined config, run:
simlock --local config set http.enabled trueToday (F4): Updated http.enabled in <configPath>; takes effect on daemon restart. After: exit 2, JSON error code USAGE, message exactly:
Invalid config after setting http.enabled: Invalid config value for "http.enabled": expected false when gateway.url is set (joined workers are reached through the gateway)
<configPath> is the selected worker config file path (F4). The refused edit leaves that file untouched. Repair an existing conflict with simlock --local config set http.enabled false, then stop/start the worker to apply it. With no worker daemon listening, simlock --local daemon start refuses the conflicting file before invoking the launcher. A running daemon is not reconfigured by this change (F5).
Today's results are from the loader evaluated at the Facts commit with fake filesystem/system stats; see F2/F3 for the implementation and existing tests.
| Effective config | Today | After |
|---|---|---|
| Worker, valid URL/token, HTTP true | accepted | refused with exact inner error below |
| Worker, valid URL/token, HTTP false/omitted | accepted, HTTP off | same |
| Standalone worker, HTTP true/false/omitted | accepted, true/false/false | same |
| Gateway, HTTP true/omitted | accepted, HTTP on | same |
| Gateway, HTTP false | refused naming http.enabled | same |
| Gateway with worker URL/token keys | ignored with warnings | same |
| Worker URL empty/malformed/http/https | refused naming gateway.url | same, before new check |
| Worker URL-only/token-only | refused naming missing token/URL | same, before new check |
| File or overrides with mode | refused with removed-key message | same |
If this goes wrong, a valid standalone worker/gateway could fail to start, or a joined worker's second network entrance could remain open.
Technical spec
Facts
Sources below are at d8404072da2ef7ac823c0269d1b987d20a040c62; ADR 0039 is Accepted — not yet implemented in PR #809 after maintainer spec approval.
| # | Fact | Source |
|---|---|---|
| F1 | loadConfig receives role (default worker), rejects a mode key in file or overrides, merges defaults then file then overrides, and performs worker membership checks only in the worker branch. |
src/core/config.ts:535-597; surface src/core/index.ts:13 |
| F2 | Membership validation accepts ws/wss URLs (including paths), rejects other/empty/malformed URLs, then requires URL/token together; token presence is checked against undefined, not truthiness. It does not inspect HTTP. URL/token are strings; HTTP enabled is boolean. | src/core/config.ts:772-791,1028-1031,1086-1089; src/core/validation.ts:84-103 |
| F3 | Worker HTTP defaults false; gateway HTTP defaults true and is required. Existing config cases cover removed mode, defaults, gateway HTTP refusal, gateway ignoring worker keys, URL/token pairing and URL schemes. | src/core/config.ts:750-755,920-926; src/core/config.test.ts:1708-1779,1840-1907 |
| F4 | CLI config set reads a file, sets the value, validates the result, then writes; validation failure is wrapped as UsageError. It prints the restart notice after a successful write. The real CLI environment validates through loadConfig using overrides and the selected role, then writes atomically. |
src/cli/commands/config.ts:40-63; src/cli/environment.ts:202,262-298; src/cli/errors.ts:24-32; real-loader test pattern src/cli/index.test.ts:2581-2641 |
| F5 | Auto-launch checks config only after the existing connection fails as unavailable and before launcher.launch. checkConfig uses the selected role. Daemon composition itself loads config before composing services. | src/cli/environment.ts:36-43,206-218; src/daemon/main.ts:185-215; src/cli/commands/daemon.ts:24-34 |
| F6 | Worker uplink construction is separate from HTTP startup, which checks enabled. | src/daemon/main.ts:462-476,496-500,656 |
| F7 | The gateway-front fixture gives direct workers membership AND HTTP; its setup waits for every member to appear at the gateway. Direct allocation checks absence of requires; another case requires direct-plus-gateway access to the same worker. | src/agent-device/gateway-front.test.ts:93-98,238-271,324-339,821-831,1175-1196 |
| F8 | The real-device gateway suite starts a joined worker with HTTP enabled; the app install test uploads through the gateway. The timing comparison uses worker HTTP as a direct baseline; its upload generation/timing helpers support that comparison. | e2e/slow-agent-device-gateway.test.ts:55-80,169-181,209-234,308-389 |
| F10 | The console fixture enables HTTP for every daemon and waits for the HTTP log, console URL and health endpoint; startFleet joins workers through that fixture. | e2e/console/fixtures.ts:85-103,119-133,150-188,207-223 |
| F12 | The joined-worker quarantine/stall setup polls worker views through HTTP; the redaction test opens both worker and gateway consoles. The local worker-list CLI returns the same workers envelope over the socket. | e2e/console/attention.spec.ts:50-70,92-133,276-308; e2e/console/events.spec.ts:263-290; src/cli/commands/worker.ts:36-57; src/daemon/dispatcher.ts:326,842-868 |
| F11 | withSharedDaemon requires a numeric configOverrides.http.port even if HTTP is disabled. | e2e/helpers/env.ts:384-388 |
| F9 | Non-test TS calls to loadConfig are the daemon, CLI startup and config-set validation, and module test helpers. The console URL helper only reads whether HTTP is enabled. | Search rg -n 'loadConfig\(' src --glob '*.ts' --glob '!*.test.ts': 6 lines (definition plus calls); src/modules/testing.ts:135,186; src/contract/console-url.ts:22 |
Modules touched
Searches: rg -n 'loadConfig\(' src --glob '*.ts' --glob '!*.test.ts' and rg -n 'http\.enabled|gateway\.url' src --glob '*.ts' --glob '!*.test.ts' (6 and 25 matching lines at the Facts commit), plus rg -n 'direct|http:|gateway:' src/agent-device/gateway-front.test.ts e2e/slow-agent-device-gateway.test.ts e2e/console/fixtures.ts and a repository search for 1 GiB upload|1.5 times|straight to the worker.
- Core:
src/core/config.ts,config.test.ts, and its manual if needed. Add the single rule after existing membership validation, on the effective config. - CLI: regression cases in
src/cli/index.test.tsusing the real loader; no duplicate production rule in CLI. - Agent-device: fixture and affected tests in
src/agent-device/gateway-front.test.ts(F7). - E2E:
e2e/slow-agent-device-gateway.test.tsfixture, timing-test removal and unused helpers (F8). Keep its numeric port for the helper (F11). - Console:
e2e/console/fixtures.tsstartup readiness and joined-worker HTTP settings (F10); preserve gateway and standalone HTTP readiness/failure checks. After dependencies Console: Queue and Activity in the shared frame, Activity scrolls back through history #767/Console: Overview home and Inbox #768 land, adapt the moved redaction test ine2e/console/activity.spec.ts(currentlyevents.spec.ts) and readiness helper ine2e/console/inbox.spec.ts(currentlyattention.spec.ts), as specified below (F12). - Docs: joining/modes/HTTP entries and migration in
docs/CONFIGURATION.md; reconcile other claims made false under always-in-scope. ADR 0039/0005 status links are in the feature's ADR PR docs(adr): joined workers refuse their own HTTP listener #809.
flowchart TD
CLI[CLI: new regression tests] --> Core[Core: changed loadConfig validation]
Daemon[Daemon composition] --> Core
AD[Agent-device fixture: changed] --> Daemon
Slow[Slow gateway fixture: changed] --> Daemon
CLI --> Launch[Daemon launcher: not reached on invalid config]
sequenceDiagram
participant O as Operator
participant C as CLI
participant V as Core config loader
participant L as Launcher
O->>C: --local daemon start, no daemon listening
C->>V: Load worker file
alt joined and HTTP true
V-->>C: ConfigError
C-->>O: Nonzero error naming http.enabled
Note over L: No launch
else valid
V-->>C: Config
C->>L: Existing launch path
end
Contract and event changes
None. This narrows accepted combinations of existing config fields (F1/F2), not their wire shapes. No new field, event or protocol bump. Keep boolean HTTP validation and URL/token string/pair/scheme validation; do not tighten token content or URL path handling in this task.
After existing membership validation, if role is worker, gateway.url !== undefined and http.enabled is true, use the existing invalidValue error style (F2/F3) to emit exactly:
Invalid config value for "http.enabled": expected false when gateway.url is set (joined workers are reached through the gateway)
Other code on the same state
The searches in Modules touched cover the membership/HTTP config readers (F1, F5, F6, F9). loadConfig owns the rule; callers inherit it without their own guard.
| Reader/writer | Interaction and which wins |
|---|---|
| Defaults, file and overrides | Last override wins before checking. Valid override false repairs file true; split membership/HTTP layers still conflict when effective HTTP is true. B1. |
| CLI config set | Validate the proposed resulting file before writing; rejected edit does not persist. Disabling HTTP repairs an existing conflicting file. B2/B3. |
| Daemon startup and CLI auto-launch | Invalid config throws before service composition/launch. Connecting to a running daemon is not a reload (F5); no live closure. B4 covers the new refusal. |
| Running worker HTTP/uplink | No live mutable config is added. Existing process keeps its current config until restarted (F5/F6). No new timing, lock or concurrency mechanism. |
| Module test helpers and console URL derivation | Helpers call the same loader; console URL consumes the effective enabled value (F9). No second writer or validation policy. |
This change adds no config write, startup side effect or shared state. Two independent loads validate their own merged snapshots; concurrent CLI-edit arbitration and atomic-write behavior remain outside this change.
Failure modes
| Call | Outcome | What happens | Limit, counted from |
|---|---|---|---|
| loadConfig membership validation | Valid combination | Return config through existing path. | Synchronous check after merge; no new wait. B1. |
| loadConfig membership validation | HTTP conflict | Throw exact ConfigError; no gateway dial to decide. | Synchronous check after existing membership errors. B1/B4. |
| loadConfig membership validation | Malformed URL or missing pair | Existing specific membership error wins before HTTP check (F2). | Same synchronous path. B1. |
| CLI proposed edit through real validation | Conflict / repaired config | Refuse before persistence / accept write with restart notice (F4). | No new wait or retry; B2/B3. |
No new external call or timeout. Filesystem errors, absent files, daemon-connection retries and their existing bounds are not changed. No new state is written by the validator, so interruption leaves no new partial state; the CLI refusal is checked against persisted file bytes in B2.
Fixture adaptation
The maintainer chose these changes after the feature's round-0 check exposed the incompatible topologies (F7/F8):
- The direct-allocation test uses a standalone worker with HTTP on and no membership keys. Extend/reuse the existing fixture so it does not wait for a standalone worker to appear at the gateway (F7). Keep its assertion that the lease request contains no
requires. Do not disable production validation for tests. - Delete the test titled
an agent on a worker token with the same principal name as a gateway agent, connected to the worker directly, does not see the gateway agent's agent-device session, and the gateway agent's commands still work: its HTTP topology is forbidden. Retain the existing gateway isolation tests and production tenant-prefix behavior; no replacement lower-level topology test was requested. - In the slow gateway suite, keep the existing HTTP host and numeric free port, changing only
enabledto false:http: { enabled: false, host: "127.0.0.1", port: await freeLoopbackPort() }. The port remains required by the shared helper (F11), though no worker HTTP listener uses it. Remove thea 1 GiB upload takes at most 1.5 times as long through the gateway as straight to the workertest and helpers/imports used only by it. Keep the existing gateway app install/upload correctness test and the rest of the gateway suite. No direct endpoint or temporary standalone benchmark is introduced. - In the console fixture, default HTTP off for workers with gateway membership; keep HTTP on for standalone workers and gateways. For an HTTP-off worker, use socket/CLI readiness, assert that status has no consoleUrl, skip the HTTP-listening log wait and HTTP health fetch, and return the fixture's existing empty-string URL representation (F10). Keep listener-bind failure detection and HTTP URL/health checks for HTTP-enabled daemons. Preserve explicit test config overrides so an invalid joined-worker HTTP override is not silently changed. Keep the general startup repair in shared fixture startup (
startDaemon/startFleet), not repeated across callers. The two named spec adaptations below are also required after Console: Queue and Activity in the shared frame, Activity scrolls back through history #767/Console: Overview home and Inbox #768; do not change navigation. This changes test readiness only, not production readiness or the console UI. - Keep only the gateway half of the existing join-token browser redaction test (F12): open the gateway console, wait for worker.connected, inspect event details and page content, and assert neither contains the join token. Drop the joined-worker console half and rename the title to state the gateway claim. The maintainer chose this narrower coverage; do not delete the gateway assertions.
- Replace the local view polling in the quarantine/stall readiness helper (F12) with
daemon.cli(["worker", "list", "--json"]), assert success, and read its JSON workers envelope. This works for joined workers without HTTP and preserves the existing view predicate and wait bounds. Keep the browser test's final assertions against the gateway; do not remove quarantine/stall coverage or change production view routing.
Rules in play
- ADR 0039 (PR docs(adr): joined workers refuse their own HTTP listener #809, Accepted — not yet implemented): the joined-worker HTTP restriction and chosen coverage removals; ADR 0034: role supplied by caller, no mode key.
- Architecture rule 10: “A rule is enforced in exactly one place” — core loader only.
- Testing rules 6/7: “through its surface” and “Prove each claim once” — loader through core, real CLI seam; extend neighboring tests and migrate supported fixture coverage.
- Delivery rule 16: “slow lane runs one at a time, through its script” — real-device gateway regression is a hardware stage.
- Documentation rules 2/3: end-user migration text states the action directly without internal ADR links or repo paths in errors.
Tests
New behavior seams: core loadConfig and real CLI runCli. Model core cases on loadConfig modes (ADR 0005) and CLI cases on CLI: config set validates with the real config loader (ADR 0003 §11, B9) (F3/F4). Reuse existing invalid-input cases for precedence, rather than duplicating them. Start refusal cases from a valid accepted control and change the conflicting setting.
- B1: A caller loads config and sees the joined-worker HTTP conflict refused with the exact error, with valid surrounding configurations accepted and existing invalid inputs keeping their errors. Cases: file only, overrides only, split membership/HTTP across layers both ways, override false repairs file true; valid ws/wss URL plus token and HTTP true/false/omitted; worker without membership; gateway default/on/off and ignored membership; empty/malformed/http/https URL, URL-only/token-only, removed mode key.
- B2: An operator attempts a CLI config edit that creates the conflict and sees exit 2/USAGE, the validation error and an untouched persisted file. Cases: enable HTTP on joined worker; set the gateway object on standalone HTTP-enabled worker.
- B3: An operator repairs a conflicting file by setting HTTP false and sees a successful validated write with the existing restart notice. Case: joined config with HTTP true;
--local config set http.enabled false. - B4: An operator starts a worker with the conflict and sees a nonzero failure with the validation error before any daemon launch. Case:
--local daemon start, no daemon listening, valid URL/token and HTTP true, gateway at unreachable loopback address.
Existing regression coverage: preserve the gateway join-token redaction assertions and quarantine/stall setup/final assertions in the post-dependency console specs (F12). Migrate the direct-allocation/no-requires assertion (F7) to standalone; keep gateway isolation tests in that file. Preserve and run the existing real gateway install/upload test (F8); this is fixture regression coverage, not a new production behavior or performance promise.
Done when
- Core config cases prove B1, including exact error and effective merge semantics:
pnpm exec vitest run --project unit src/core/config.test.ts. - Real CLI cases prove B2/B3/B4, including persisted bytes unchanged on refusal, successful repair, and no launcher call for invalid fresh startup:
pnpm exec vitest run --project unit src/cli/index.test.ts. - Supported agent-device topologies pass, with standalone direct allocation/no-requires assertion retained and only the named impossible topology case removed:
pnpm exec vitest run --project unit src/agent-device/gateway-front.test.ts. - Existing console/fleet specs pass through
pnpm test:console --project=chromium; joined-worker fixture startup uses the local socket without waiting for HTTP or advertising a console URL, while standalone/gateway listener readiness and bind-failure coverage remain. The join-token test checks the gateway only; quarantine/stall readiness uses local CLI views and retains its gateway browser assertions. - On a machine with the pinned agent-device setup and real iOS simulator/Android emulator prerequisites from toolchain.md,
scripts/slow-e2e.sh e2e/slow-agent-device-gateway.test.tspasses for the platforms available, including its existing gateway app install/upload correctness test; the joined worker has HTTP off and the removed timing comparison/helpers are absent. Missing platform coverage is recorded by the hardware stage, not represented as a pass. - Configuration docs name the immediate breaking change, local repair command, and stop/start requirement. Diff review verifies no live enforcement, automatic rewrite or production agent-device change was added.
Out of scope
Live reload/listener shutdown, auto migration, standalone HTTP removal, auth or token-prefix changes, new wire shapes/events, and replacement performance comparisons. The removed comparison no longer proves a direct-versus-gateway speed ratio.
Depends on
- Console: Queue and Activity in the shared frame, Activity scrolls back through history #767 — moves/rewrites the join-token browser test from events.spec.ts to activity.spec.ts; adapt that test after it lands.
- Console: Overview home and Inbox #768 — moves/rewrites the quarantine/stall console spec from attention.spec.ts to inbox.spec.ts and its readiness helper; adapt the resulting helper after it lands.
The implementation PR stacks above ADR PR #809 for feature #806 after these external dependencies close. #767 also depends on #765/#766/#764; #768 depends on #765/#766/#767, ordering the earlier console changes transitively. Other open work #620/#777 and PRs #804/#805 touch separate functions/sections, so no further dependency. Do not edit another feature's task bodies.
Written by an agent.
Activity
test: agent-device gateway-front uses a standalone worker for direct …
test: slow gateway suite joins a worker with HTTP off and drops the d…
test: console fixtures start joined workers with HTTP off and read th…
docs: a joined worker must keep HTTP off, with the repair command (#811)
refactor(core): split joined-worker membership checks (#811)
test: daemon start refusal fails on its launches assertion, docs: con…
test: URL-error cases assert the URL message, not a substring the ref…
fix(agent-device): a heartbeat that meets a lease the gateway's list …
test: gateway worker-list e2e allows the stream segment after agent-d…
docs(adr): joined workers refuse their own HTTP listener (#809)
feat(config): refuse HTTP on joined workers and migrate fixtures (#842)