Skip to content

Commit 1612e33

Browse files
authored
refactor(daemon): move the runtime dependency construction to the process root (PR 6) (#3431)
* refactor(daemon): move the runtime dependency construction to the process root startDaemonRuntime now receives its composed dependencies instead of building them: provider runtimes, the platform gateway and inventory gateways, request platform providers, host diagnostics, credential fingerprinting, the platform lifecycle owners, the platform-services and claim-recovery compositions, and the command-surface factory all move to src/daemon-composition.ts, which src/daemon.ts composes and injects. The operational server keeps startup sequencing, listeners, shutdown, the metadata watch, idle reap, and request-handler creation, with the same order on both paths. DaemonProviderCredentials moves to @agent-device/daemon-contracts/provider-credentials, the #2559 shared home beside daemon-policy-file; the fingerprint implementation stays in the root. Tests boot the runtime through one shared fixture. No production file under src/daemon/ now reads a non-package src/ module except the direct-ios-selector edge owned by #2273/#2274. * refactor(daemon): let the server own assembly and take the root's deps as a factory startDaemonRuntime now takes a composeDeps factory and keeps the daemon paths, the ADR 0029 policy load (typed stderr and exit included), the SessionStore, the session callbacks, and the assertShutdownAllowed derivation in the server, so the process root and every runtime test share one assembly and the second resolveDaemonPaths and the policy round-trip go away. Skipped provider runtimes are data on the deps and the server emits provider_runtime_skipped through emitDaemonDiagnostic; the lease-lifecycle facts, the runtime gateway, the resource-cleanup surface, and the claim-recovery factory are declared once at the top level of DaemonRuntimeDeps. The fixture is a thin call through the real factory, and a new assembly test proves a dropped shutdown gate, a mis-wired store, or an unreadable policy cannot pass silently. * chore(gates): retire the daemon composition edges R76 carried The daemon-runtime rows of the R76 inventory no longer describe tree reality once the composition moved out of src/daemon/, so the stale entries go and the planted tests retarget the one surviving classified pair. daemon-composition is declared in the platform-runtime zone (a composition, not an executable), and ADRs 0019/0022/0033 record where the composition and the extracted credential type landed.
1 parent 7da2934 commit 1612e33

31 files changed

Lines changed: 776 additions & 580 deletions

‎docs/adr/0019-request-bound-platform-runtime.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -833,12 +833,15 @@ therefore structurally enforced rather than periodically measured.
833833
Some request-path work asks the host machine something without ever taking a device runtime:
834834
concrete local readiness, boot-time and runner-session observation, and open-target
835835
classification. Those asks now cross the daemon boundary as one required dependency,
836-
`DaemonPlatformServices` (`src/daemon/platform-services.ts`), composed by the root in
837-
`src/platform-runtime-daemon-services.ts` and threaded root → `RequestRouterDeps` → the request
838-
execution scope → the handlers and consumers. Stale-claim reconciliation gets the same treatment
839-
for the one act it may not perform itself: the root supplies a `ClaimRecoveryGatewayFactory`
840-
(`src/daemon/device/claim-recovery-gateway.ts`), and the daemon keeps the transaction — what to
841-
rebuild from (the dead owner's recorded state dir), in what order, and when to dispose it.
836+
`DaemonPlatformServices` (`src/daemon/platform-services.ts`), assembled by the daemon runtime's
837+
root-composition module in `src/daemon-composition.ts` — which reaches the concrete adapters
838+
through `src/platform-runtime-daemon-services.ts` behind a function-scoped `await import` — and
839+
threaded composition → `startDaemonRuntime` deps → `RequestRouterDeps` → the request execution
840+
scope → the handlers and consumers. Stale-claim reconciliation gets the same treatment
841+
for the one act it may not perform itself: the composition supplies the `ClaimRecoveryGatewayFactory`
842+
the daemon declares in `src/daemon/device/claim-recovery-gateway.ts`, built from
843+
`src/platform-runtime-claim-recovery.ts` (likewise deferred), and the daemon keeps the transaction —
844+
what to rebuild from (the dead owner's recorded state dir), in what order, and when to dispose it.
842845

843846
The port is not a raw escape hatch back into platform mechanics. Its observation members are the
844847
already-published neutral contract types from `@agent-device/contracts`, readiness is a boolean,

‎docs/adr/0022-daemon-platform-runtime-coupling.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ Accepted (2026-09-06). Implements the audit deliverables of issue #2278. The cla
66
inventory and the structural no-regrowth checks are gate-enforced; this ADR records the decisions
77
and points at the gates rather than restating the inventory.
88

9+
Amended 2026-10-11 by #3431: the daemon-runtime composition edges this
10+
ADR classified (the gateway/diagnostics/resource-cleanup/lifecycle edges, the provider-runtime
11+
hubs, and the platform-services and claim-recovery dynamic edges) moved out of `src/daemon/` into
12+
the process-root composition module `src/daemon-composition.ts`, which R76 does not see because it
13+
is no longer a daemon-zone importer. The R76 inventory now carries only the leaked
14+
selector-query edge (`src/daemon/direct-ios-selector.ts`); the section-2 outcomes below remain the
15+
record of how each was classified.
16+
917
## 1. Context
1018

1119
The platform-package migration removed direct production dependencies from `src/daemon/**` to

‎docs/adr/0033-collocation-decision-table.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ optimal.
150150
| `src/platform-runtime-daemon-lifecycle.ts` | retain for this batch | Same path-keyed R13/ADR 0022 seam: relocation is possible only with coordinated changes to those declarations. |
151151
| `src/platform-runtime-device-boot.ts` | retain for this batch | Same path-keyed R13/ADR 0022 seam. |
152152
| `src/platform-runtime-resource-cleanup.ts` | retain for this batch | Same path-keyed R13/ADR 0022 seam. |
153-
| `src/provider-credential-fingerprint.ts` | keep | Daemon ⇄ client shared contract from the same #2559 decision as `daemon-policy-file.ts`; #3288 declares its zone beside the provider composition that reads the credentials it fingerprints. |
153+
| `src/provider-credential-fingerprint.ts` | keep (type extracted) | Daemon ⇄ client shared contract from the same #2559 decision as `daemon-policy-file.ts`; #3288 declares its zone beside the provider composition that reads the credentials it fingerprints. PR 6 of the daemon extraction moved only the `DaemonProviderCredentials` declaration to `packages/daemon-contracts` (`./provider-credentials`), the same shared-below-both landing as the policy file; the fingerprinting implementation stays here because it reads the installed-plugin manifest. |
154154
| `src/provider-limrun-runtime.ts` | keep | Proposed → provider-limrun, but there is no seam: the class's constructor self-builds the root dependency factory (`src/sdk/limrun-runtime-dependencies.ts`), which is the ADR 0019 composition seam — it loads the root's adb-host binder, core Android interactor, and platform-runtime app-state helpers that the package must not import. Moving the class means moving that composition, which is design, not a move. |
155155
| `src/request-progress-protocol.ts` | moved → `packages/daemon-contracts/src/request-progress-protocol.ts` | Daemon ⇄ client shared contract from the same #2559 decision — the client reads it statically (`daemon-client-progress.ts`) and the server through `src/daemon/server/`, so only #2559's shared-placement boundary and the wire-compat ledgers pin it; declared `daemon-contracts` by #3288 and now physically placed by the extraction. Contracts was considered and R18 keeps contracts free of envelope validation mechanics. The wire-ledger keys moved with the file. |
156156
| `src/runtime-command-surface.ts` | moved → `src/command-runtime/runtime-command-surface.ts` ([#3299](https://github.com/callstack/agent-device/pull/3299)) | Physical move landed with `runtime-factory.ts` as one assembly group: the command-surface binding sits beside the factory it composes, under the folder that derives its `command-runtime` zone, so `topFolder` replaces the per-file `ROOT_MODULE_ZONES` row. |

‎packages/daemon-contracts/package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
"types": "./src/daemon-shutdown-report.ts",
4848
"default": "./src/daemon-shutdown-report.ts"
4949
},
50+
"./provider-credentials": {
51+
"types": "./src/provider-credentials.ts",
52+
"default": "./src/provider-credentials.ts"
53+
},
5054
"./request-progress-protocol": {
5155
"types": "./src/request-progress-protocol.ts",
5256
"default": "./src/request-progress-protocol.ts"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* The provider credentials a daemon started with, and the state dir that names that daemon.
3+
*
4+
* A `lease_allocate` request carries the caller's own fingerprint so a lease can be fenced to one
5+
* credential set (#2559): the daemon compares the request's value against the fingerprint it
6+
* computed from its own startup environment, and both sides read this one declaration — the
7+
* daemon's implementation stays in the process root (`src/provider-credential-fingerprint.ts`),
8+
* which the daemon client imports; the vocabulary lives here because that fingerprint module must
9+
* not carry a type edge into `src/daemon` (#2559).
10+
*/
11+
export type DaemonProviderCredentials = Readonly<{
12+
/** Undefined when the daemon's environment holds none of the credentials such a lease reads. */
13+
fingerprint(provider: string, leaseBackend?: string): string | undefined;
14+
stateDir: string;
15+
}>;

0 commit comments

Comments
 (0)