@cotal-ai/manager 0.171.4 → 0.171.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/boot.d.ts +162 -0
- package/dist/boot.d.ts.map +1 -0
- package/dist/boot.js +627 -0
- package/dist/boot.js.map +1 -0
- package/dist/broker-transport.d.ts +6 -0
- package/dist/broker-transport.d.ts.map +1 -1
- package/dist/broker-transport.js +25 -6
- package/dist/broker-transport.js.map +1 -1
- package/dist/command-dispatch.d.ts +3 -0
- package/dist/command-dispatch.d.ts.map +1 -1
- package/dist/command-dispatch.js +67 -0
- package/dist/command-dispatch.js.map +1 -1
- package/dist/connector-inventory.d.ts +3 -0
- package/dist/connector-inventory.d.ts.map +1 -1
- package/dist/connector-inventory.js +17 -0
- package/dist/connector-inventory.js.map +1 -1
- package/dist/credential-renewal.d.ts +5 -1
- package/dist/credential-renewal.d.ts.map +1 -1
- package/dist/credential-renewal.js +65 -3
- package/dist/credential-renewal.js.map +1 -1
- package/dist/goal-writer.d.ts +3 -0
- package/dist/goal-writer.d.ts.map +1 -1
- package/dist/goal-writer.js +30 -0
- package/dist/goal-writer.js.map +1 -1
- package/dist/harness-resolution.d.ts +3 -0
- package/dist/harness-resolution.d.ts.map +1 -1
- package/dist/harness-resolution.js +14 -0
- package/dist/harness-resolution.js.map +1 -1
- package/dist/lease-keeper.d.ts +4 -0
- package/dist/lease-keeper.d.ts.map +1 -1
- package/dist/lease-keeper.js +10 -0
- package/dist/lease-keeper.js.map +1 -1
- package/dist/managed-static-lifecycle.d.ts +3 -0
- package/dist/managed-static-lifecycle.d.ts.map +1 -1
- package/dist/managed-static-lifecycle.js +42 -0
- package/dist/managed-static-lifecycle.js.map +1 -1
- package/dist/manager.d.ts +549 -354
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +86 -2222
- package/dist/manager.js.map +1 -1
- package/dist/names-capacity.d.ts +4 -0
- package/dist/names-capacity.d.ts.map +1 -1
- package/dist/names-capacity.js +29 -0
- package/dist/names-capacity.js.map +1 -1
- package/dist/persona-catalog.d.ts +3 -0
- package/dist/persona-catalog.d.ts.map +1 -1
- package/dist/persona-catalog.js +19 -0
- package/dist/persona-catalog.js.map +1 -1
- package/dist/preservation.d.ts +3 -0
- package/dist/preservation.d.ts.map +1 -1
- package/dist/preservation.js +48 -0
- package/dist/preservation.js.map +1 -1
- package/dist/preserved-resume.d.ts +220 -0
- package/dist/preserved-resume.d.ts.map +1 -0
- package/dist/preserved-resume.js +1222 -0
- package/dist/preserved-resume.js.map +1 -0
- package/dist/readiness-wait.d.ts +3 -0
- package/dist/readiness-wait.d.ts.map +1 -1
- package/dist/readiness-wait.js +11 -0
- package/dist/readiness-wait.js.map +1 -1
- package/dist/retirement.d.ts +4 -0
- package/dist/retirement.d.ts.map +1 -1
- package/dist/retirement.js +29 -0
- package/dist/retirement.js.map +1 -1
- package/dist/seat-custody.d.ts +4 -0
- package/dist/seat-custody.d.ts.map +1 -1
- package/dist/seat-custody.js +25 -0
- package/dist/seat-custody.js.map +1 -1
- package/dist/seat-launch.d.ts +3 -0
- package/dist/seat-launch.d.ts.map +1 -1
- package/dist/seat-launch.js +69 -0
- package/dist/seat-launch.js.map +1 -1
- package/dist/seat-stop.d.ts +3 -0
- package/dist/seat-stop.d.ts.map +1 -1
- package/dist/seat-stop.js +40 -0
- package/dist/seat-stop.js.map +1 -1
- package/dist/seat-types.d.ts +6 -6
- package/dist/seat-types.d.ts.map +1 -1
- package/dist/serve-plane.d.ts +4 -0
- package/dist/serve-plane.d.ts.map +1 -1
- package/dist/serve-plane.js +76 -0
- package/dist/serve-plane.js.map +1 -1
- package/dist/session-recovery.d.ts +4 -0
- package/dist/session-recovery.d.ts.map +1 -1
- package/dist/session-recovery.js +31 -0
- package/dist/session-recovery.js.map +1 -1
- package/dist/spawn-goal.d.ts +3 -0
- package/dist/spawn-goal.d.ts.map +1 -1
- package/dist/spawn-goal.js +23 -0
- package/dist/spawn-goal.js.map +1 -1
- package/dist/start-doors.d.ts +3 -0
- package/dist/start-doors.d.ts.map +1 -1
- package/dist/start-doors.js +14 -0
- package/dist/start-doors.js.map +1 -1
- package/dist/status-and-models.d.ts +3 -0
- package/dist/status-and-models.d.ts.map +1 -1
- package/dist/status-and-models.js +40 -0
- package/dist/status-and-models.js.map +1 -1
- package/dist/terminal-input.d.ts +3 -0
- package/dist/terminal-input.d.ts.map +1 -1
- package/dist/terminal-input.js +12 -0
- package/dist/terminal-input.js.map +1 -1
- package/dist/user-provision.d.ts +4 -0
- package/dist/user-provision.d.ts.map +1 -1
- package/dist/user-provision.js +17 -0
- package/dist/user-provision.js.map +1 -1
- package/package.json +12 -12
package/dist/boot.js
ADDED
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
import { CotalEndpoint, credsClaims, DEFAULT_SERVER, drainAndClose, ensureAuthorityStores, epgateKey, listGoalIndex, MANAGER_LEASE_RENEW_MS, mintCreds, mintLifecycleUid, newIdentity, parseEndpointGate, recordsBucket, rejectionText, standaloneConnectOpts, STANDING_RENEWABLE_TTL_SEC } from "@cotal-ai/core";
|
|
2
|
+
import { authDir, claimIdentityRecord, createManagerInstanceIdentity, getSpaceAuth, hasUserAuthState, loadManagerInstanceIdentity, loadMeshes, localTrustOfSpace, userAuthStateDir } from "@cotal-ai/workspace";
|
|
3
|
+
import { jetstreamManager } from "@nats-io/jetstream";
|
|
4
|
+
import { Kvm } from "@nats-io/kv";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { hostname } from "node:os";
|
|
7
|
+
import { resolve } from "node:path";
|
|
8
|
+
import { credRenewIntervalMs } from "./credential-renewal.js";
|
|
9
|
+
import { DELIVERY_ADMIN_BOOT_WAIT_MS, makeManagerEndpointHolderEvictor } from "./endpoint-evict.js";
|
|
10
|
+
import { makeManagerHolderLivenessProbe } from "./holder-liveness.js";
|
|
11
|
+
import { MANAGER_ENDPOINT } from "./manager-service-contract.js";
|
|
12
|
+
import { GateReconcileRefused, reconcileEndpointGate } from "./reconcile-gate.js";
|
|
13
|
+
import { RunHosting } from "./run-hosting.js";
|
|
14
|
+
import { TranscriptReceiver } from "./transcript-receive.js";
|
|
15
|
+
/** Startup reconciliation overlaps control-service registration. A spawn or attach for one of
|
|
16
|
+
* these aliases must wait until THAT alias's exact-op terminal attempt returns rather than racing
|
|
17
|
+
* a reuse. */
|
|
18
|
+
const STARTUP_RECONCILING = "startup static lifecycle reconciliation";
|
|
19
|
+
/** Builds the {@link ManagerBootDeps} for a Manager. It reads Manager members by name at each use, so a
|
|
20
|
+
* field the Manager assigns later is current and a member a test replaces on the instance is the one that runs. */
|
|
21
|
+
export function bootDeps(m) {
|
|
22
|
+
return {
|
|
23
|
+
admittedLocalIdentity: () => m["admittedLocalIdentity"],
|
|
24
|
+
setAdmittedLocalIdentity: (value) => { m["admittedLocalIdentity"] = value; },
|
|
25
|
+
attach: () => m["attach"],
|
|
26
|
+
auth: () => m["auth"],
|
|
27
|
+
setAuth: (value) => { m["auth"] = value; },
|
|
28
|
+
bootNotes: () => m["bootNotes"],
|
|
29
|
+
credRenewTimer: () => m["credRenewTimer"],
|
|
30
|
+
setCredRenewTimer: (value) => { m["credRenewTimer"] = value; },
|
|
31
|
+
daemonRenewalLeaseTimer: () => m["daemonRenewalLeaseTimer"],
|
|
32
|
+
setDaemonRenewalLeaseTimer: (value) => { m["daemonRenewalLeaseTimer"] = value; },
|
|
33
|
+
ep: () => m["ep"],
|
|
34
|
+
setEp: (value) => { m["ep"] = value; },
|
|
35
|
+
execution: () => m["execution"],
|
|
36
|
+
leaseInfo: () => m["leaseInfo"],
|
|
37
|
+
setLeaseInfo: (value) => { m["leaseInfo"] = value; },
|
|
38
|
+
leaseRevision: () => m["leaseRevision"],
|
|
39
|
+
setLeaseRevision: (value) => { m["leaseRevision"] = value; },
|
|
40
|
+
leaseStopping: () => m["leaseStopping"],
|
|
41
|
+
leaseTimer: () => m["leaseTimer"],
|
|
42
|
+
setLeaseTimer: (value) => { m["leaseTimer"] = value; },
|
|
43
|
+
managerInstanceId: () => m["managerInstanceId"],
|
|
44
|
+
setManagerInstanceId: (value) => { m["managerInstanceId"] = value; },
|
|
45
|
+
managerLifecycleUid: () => m["managerLifecycleUid"],
|
|
46
|
+
managerServeIdentity: () => m["managerServeIdentity"],
|
|
47
|
+
setManagerServeIdentity: (value) => { m["managerServeIdentity"] = value; },
|
|
48
|
+
name: () => m["name"],
|
|
49
|
+
onServiceIdentity: () => m["onServiceIdentity"],
|
|
50
|
+
remoteAuthority: () => m["remoteAuthority"],
|
|
51
|
+
remoteSupervisorCreds: () => m["remoteSupervisorCreds"],
|
|
52
|
+
resumeCredRenewal: () => m["resumeCredRenewal"],
|
|
53
|
+
setResumeCredRenewal: (value) => { m["resumeCredRenewal"] = value; },
|
|
54
|
+
runHosting: () => m["runHosting"],
|
|
55
|
+
setRunHosting: (value) => { m["runHosting"] = value; },
|
|
56
|
+
runtimeKind: () => m["runtimeKind"],
|
|
57
|
+
secrets: () => m["secrets"],
|
|
58
|
+
servers: () => m["servers"],
|
|
59
|
+
serviceServe: () => m["serviceServe"],
|
|
60
|
+
space: () => m["space"],
|
|
61
|
+
staticLifecycle: () => m["staticLifecycle"],
|
|
62
|
+
streamsTerminal: () => m["streamsTerminal"],
|
|
63
|
+
transcripts: () => m["transcripts"],
|
|
64
|
+
setTranscripts: (value) => { m["transcripts"] = value; },
|
|
65
|
+
transportDown: () => m["transportDown"],
|
|
66
|
+
userMode: () => m["userMode"],
|
|
67
|
+
setUserMode: (value) => { m["userMode"] = value; },
|
|
68
|
+
workspaceRoot: () => m["workspaceRoot"],
|
|
69
|
+
acquireInstanceLease: (...args) => m["acquireInstanceLease"](...args),
|
|
70
|
+
adoptReleasedSeats: (...args) => m["adoptReleasedSeats"](...args),
|
|
71
|
+
claimDaemonRenewalOwnership: (...args) => m["claimDaemonRenewalOwnership"](...args),
|
|
72
|
+
dial: (...args) => m["dial"](...args),
|
|
73
|
+
executionRecordPath: (...args) => m["executionRecordPath"](...args),
|
|
74
|
+
inspectConnectorsAtBoot: (...args) => m["inspectConnectorsAtBoot"](...args),
|
|
75
|
+
keepDaemonRenewalLease: (...args) => m["keepDaemonRenewalLease"](...args),
|
|
76
|
+
logSeatMeshTransitions: (...args) => m["logSeatMeshTransitions"](...args),
|
|
77
|
+
reconcileGoalIndex: (...args) => m["reconcileGoalIndex"](...args),
|
|
78
|
+
reconcileStaticLifecycles: (...args) => m["reconcileStaticLifecycles"](...args),
|
|
79
|
+
registerManagerService: (...args) => m["registerManagerService"](...args),
|
|
80
|
+
renewDaemonCreds: (...args) => m["renewDaemonCreds"](...args),
|
|
81
|
+
renewLease: (...args) => m["renewLease"](...args),
|
|
82
|
+
renewRemoteExecutor: (...args) => m["renewRemoteExecutor"](...args),
|
|
83
|
+
renewRemoteStandingBundle: (...args) => m["renewRemoteStandingBundle"](...args),
|
|
84
|
+
serviceIdentityObservation: (...args) => m["serviceIdentityObservation"](...args),
|
|
85
|
+
startGoalWriter: (...args) => m["startGoalWriter"](...args),
|
|
86
|
+
startSessionPlane: (...args) => m["startSessionPlane"](...args),
|
|
87
|
+
withTransferReader: (fn) => m["withTransferReader"](fn),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** Starting the manager: admitting its execution state, connecting and registering it, taking its instance lease, and healing a predecessor's frozen registration gate. */
|
|
91
|
+
export class ManagerBoot {
|
|
92
|
+
deps;
|
|
93
|
+
constructor(deps) {
|
|
94
|
+
this.deps = deps;
|
|
95
|
+
}
|
|
96
|
+
// The Manager members these bodies read, under their Manager names. Each reads through its dep at
|
|
97
|
+
// use, so a field the Manager assigns later is current and a method a test replaces on the Manager
|
|
98
|
+
// is the one that runs.
|
|
99
|
+
get admittedLocalIdentity() { return this.deps.admittedLocalIdentity(); }
|
|
100
|
+
set admittedLocalIdentity(value) { this.deps.setAdmittedLocalIdentity(value); }
|
|
101
|
+
get attach() { return this.deps.attach(); }
|
|
102
|
+
get auth() { return this.deps.auth(); }
|
|
103
|
+
set auth(value) { this.deps.setAuth(value); }
|
|
104
|
+
get bootNotes() { return this.deps.bootNotes(); }
|
|
105
|
+
get credRenewTimer() { return this.deps.credRenewTimer(); }
|
|
106
|
+
set credRenewTimer(value) { this.deps.setCredRenewTimer(value); }
|
|
107
|
+
get daemonRenewalLeaseTimer() { return this.deps.daemonRenewalLeaseTimer(); }
|
|
108
|
+
set daemonRenewalLeaseTimer(value) { this.deps.setDaemonRenewalLeaseTimer(value); }
|
|
109
|
+
get ep() { return this.deps.ep(); }
|
|
110
|
+
set ep(value) { this.deps.setEp(value); }
|
|
111
|
+
get execution() { return this.deps.execution(); }
|
|
112
|
+
get leaseInfo() { return this.deps.leaseInfo(); }
|
|
113
|
+
set leaseInfo(value) { this.deps.setLeaseInfo(value); }
|
|
114
|
+
get leaseRevision() { return this.deps.leaseRevision(); }
|
|
115
|
+
set leaseRevision(value) { this.deps.setLeaseRevision(value); }
|
|
116
|
+
get leaseStopping() { return this.deps.leaseStopping(); }
|
|
117
|
+
get leaseTimer() { return this.deps.leaseTimer(); }
|
|
118
|
+
set leaseTimer(value) { this.deps.setLeaseTimer(value); }
|
|
119
|
+
get managerInstanceId() { return this.deps.managerInstanceId(); }
|
|
120
|
+
set managerInstanceId(value) { this.deps.setManagerInstanceId(value); }
|
|
121
|
+
get managerLifecycleUid() { return this.deps.managerLifecycleUid(); }
|
|
122
|
+
get managerServeIdentity() { return this.deps.managerServeIdentity(); }
|
|
123
|
+
set managerServeIdentity(value) { this.deps.setManagerServeIdentity(value); }
|
|
124
|
+
get name() { return this.deps.name(); }
|
|
125
|
+
get onServiceIdentity() { return this.deps.onServiceIdentity(); }
|
|
126
|
+
get remoteAuthority() { return this.deps.remoteAuthority(); }
|
|
127
|
+
get remoteSupervisorCreds() { return this.deps.remoteSupervisorCreds(); }
|
|
128
|
+
get resumeCredRenewal() { return this.deps.resumeCredRenewal(); }
|
|
129
|
+
set resumeCredRenewal(value) { this.deps.setResumeCredRenewal(value); }
|
|
130
|
+
get runHosting() { return this.deps.runHosting(); }
|
|
131
|
+
set runHosting(value) { this.deps.setRunHosting(value); }
|
|
132
|
+
get runtimeKind() { return this.deps.runtimeKind(); }
|
|
133
|
+
get secrets() { return this.deps.secrets(); }
|
|
134
|
+
get servers() { return this.deps.servers(); }
|
|
135
|
+
get serviceServe() { return this.deps.serviceServe(); }
|
|
136
|
+
get space() { return this.deps.space(); }
|
|
137
|
+
get staticLifecycle() { return this.deps.staticLifecycle(); }
|
|
138
|
+
get streamsTerminal() { return this.deps.streamsTerminal(); }
|
|
139
|
+
get transcripts() { return this.deps.transcripts(); }
|
|
140
|
+
set transcripts(value) { this.deps.setTranscripts(value); }
|
|
141
|
+
get transportDown() { return this.deps.transportDown(); }
|
|
142
|
+
get userMode() { return this.deps.userMode(); }
|
|
143
|
+
set userMode(value) { this.deps.setUserMode(value); }
|
|
144
|
+
get workspaceRoot() { return this.deps.workspaceRoot(); }
|
|
145
|
+
acquireInstanceLease(...args) { return this.deps.acquireInstanceLease(...args); }
|
|
146
|
+
adoptReleasedSeats(...args) { return this.deps.adoptReleasedSeats(...args); }
|
|
147
|
+
claimDaemonRenewalOwnership(...args) { return this.deps.claimDaemonRenewalOwnership(...args); }
|
|
148
|
+
dial(...args) { return this.deps.dial(...args); }
|
|
149
|
+
executionRecordPath(...args) { return this.deps.executionRecordPath(...args); }
|
|
150
|
+
inspectConnectorsAtBoot(...args) { return this.deps.inspectConnectorsAtBoot(...args); }
|
|
151
|
+
keepDaemonRenewalLease(...args) { return this.deps.keepDaemonRenewalLease(...args); }
|
|
152
|
+
logSeatMeshTransitions(...args) { return this.deps.logSeatMeshTransitions(...args); }
|
|
153
|
+
reconcileGoalIndex(...args) { return this.deps.reconcileGoalIndex(...args); }
|
|
154
|
+
reconcileStaticLifecycles(...args) { return this.deps.reconcileStaticLifecycles(...args); }
|
|
155
|
+
registerManagerService(...args) { return this.deps.registerManagerService(...args); }
|
|
156
|
+
renewDaemonCreds(...args) { return this.deps.renewDaemonCreds(...args); }
|
|
157
|
+
renewLease(...args) { return this.deps.renewLease(...args); }
|
|
158
|
+
renewRemoteExecutor(...args) { return this.deps.renewRemoteExecutor(...args); }
|
|
159
|
+
renewRemoteStandingBundle(...args) { return this.deps.renewRemoteStandingBundle(...args); }
|
|
160
|
+
serviceIdentityObservation(...args) { return this.deps.serviceIdentityObservation(...args); }
|
|
161
|
+
startGoalWriter(...args) { return this.deps.startGoalWriter(...args); }
|
|
162
|
+
startSessionPlane(...args) { return this.deps.startSessionPlane(...args); }
|
|
163
|
+
withTransferReader(fn) { return this.deps.withTransferReader(fn); }
|
|
164
|
+
claimExecutionRecord(instanceId) {
|
|
165
|
+
const record = claimIdentityRecord(this.executionRecordPath(instanceId), "manager execution capability", (raw) => {
|
|
166
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
167
|
+
return undefined;
|
|
168
|
+
const r = raw;
|
|
169
|
+
return Object.keys(r).sort().join(",") === "execution,instanceId,space,v" && r.v === 1 && r.space === this.space &&
|
|
170
|
+
r.instanceId === instanceId && (r.execution === "none" || r.execution === "runtime") ? r : undefined;
|
|
171
|
+
}, () => ({ v: 1, space: this.space, instanceId, execution: this.execution }));
|
|
172
|
+
if (record.execution !== this.execution)
|
|
173
|
+
throw new Error("manager execution capability differs from its retained instance record; execution cannot change across restart");
|
|
174
|
+
}
|
|
175
|
+
async admitExecutionState() {
|
|
176
|
+
if (!this.remoteAuthority) {
|
|
177
|
+
let local = this.admittedLocalIdentity;
|
|
178
|
+
this.admittedLocalIdentity = undefined;
|
|
179
|
+
if (this.execution === "none") {
|
|
180
|
+
const recorded = loadMeshes().find((m) => m.space === this.space);
|
|
181
|
+
const auth = hasUserAuthState(this.workspaceRoot, this.space) && recorded?.mode === "user"
|
|
182
|
+
? await getSpaceAuth(this.secrets, this.space) : undefined;
|
|
183
|
+
if (!auth)
|
|
184
|
+
throw new Error("execution: none requires a genuine hosting user-auth root and its user-mode mesh record");
|
|
185
|
+
if (!local)
|
|
186
|
+
local = loadManagerInstanceIdentity(this.workspaceRoot, this.space);
|
|
187
|
+
if (local && !existsSync(this.executionRecordPath(local.instanceId)))
|
|
188
|
+
throw new Error("execution: none refuses an existing unclassified manager instance; keep its runtime and retained state, or register a fresh control instance");
|
|
189
|
+
if (!local) {
|
|
190
|
+
const proposed = { instanceId: mintLifecycleUid(), serveIdentity: newIdentity() };
|
|
191
|
+
local = createManagerInstanceIdentity(this.workspaceRoot, this.space, () => proposed);
|
|
192
|
+
if (local.instanceId !== proposed.instanceId)
|
|
193
|
+
throw new Error("execution: none refuses a concurrently claimed unclassified manager identity");
|
|
194
|
+
}
|
|
195
|
+
const localInstanceId = local.instanceId;
|
|
196
|
+
this.claimExecutionRecord(localInstanceId);
|
|
197
|
+
const nc = await this.dial({ ...standaloneConnectOpts({ creds: await mintCreds(auth, newIdentity(), "provisioner"), tls: false }), maxReconnectAttempts: 0 });
|
|
198
|
+
try {
|
|
199
|
+
const kvm = new Kvm(nc);
|
|
200
|
+
await ensureAuthorityStores(await jetstreamManager(nc), kvm, this.space);
|
|
201
|
+
const entries = await listGoalIndex(await kvm.open(recordsBucket(this.space)), MANAGER_ENDPOINT);
|
|
202
|
+
if (entries.some((entry) => entry.iid === localInstanceId && (entry.allocated !== undefined || entry.note !== undefined)))
|
|
203
|
+
throw new Error("execution: none refuses retained seat or turn inventory before recovery; keep the execution-owning Manager");
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
await drainAndClose(nc);
|
|
207
|
+
}
|
|
208
|
+
this.admittedLocalIdentity = local;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
local ??= createManagerInstanceIdentity(this.workspaceRoot, this.space, () => ({ instanceId: mintLifecycleUid(), serveIdentity: newIdentity() }));
|
|
212
|
+
this.claimExecutionRecord(local.instanceId);
|
|
213
|
+
this.admittedLocalIdentity = local;
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (this.remoteAuthority) {
|
|
218
|
+
if (this.execution === "none" && (await localTrustOfSpace(this.secrets, this.space)).present)
|
|
219
|
+
throw new Error("remote manager-service authority cannot be combined with local space signing trust - choose one authority path, never a fallback");
|
|
220
|
+
// Execution is fixed for a registered instance. An older instance with no capability
|
|
221
|
+
// record might own retained seats/runs, so it cannot be converted to none by omission.
|
|
222
|
+
const remote = this.remoteAuthority;
|
|
223
|
+
const path = this.executionRecordPath(remote.instanceId);
|
|
224
|
+
if (this.execution === "none" && !existsSync(path) && remote.serveGrant.epoch !== 0)
|
|
225
|
+
throw new Error("execution: none refuses an existing unclassified manager instance; keep its runtime and retained state, or register a fresh control instance");
|
|
226
|
+
if (this.execution === "none") {
|
|
227
|
+
const entries = await remote.scanGoalIndex();
|
|
228
|
+
if (entries.some((entry) => entry.iid === remote.instanceId && (entry.allocated !== undefined || entry.note !== undefined)))
|
|
229
|
+
throw new Error("execution: none refuses retained seat or turn inventory before recovery; keep the execution-owning Manager");
|
|
230
|
+
}
|
|
231
|
+
if (this.execution === "none" || existsSync(path))
|
|
232
|
+
this.claimExecutionRecord(remote.instanceId);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async runStart() {
|
|
236
|
+
await this.admitExecutionState();
|
|
237
|
+
this.staticLifecycle.start();
|
|
238
|
+
await this.inspectConnectorsAtBoot();
|
|
239
|
+
await this.attach.start();
|
|
240
|
+
// In auth mode the manager is just another user in the space's account — it mints
|
|
241
|
+
// itself creds from the same signing key it uses for the agents it spawns. The signer comes
|
|
242
|
+
// through the SecretStore seam (`this.secrets` — the injected `ManagerOptions.secretStore`, or
|
|
243
|
+
// the local `.cotal/auth/auth.json` FS default), so a HOSTED composition mints from its KMS/Vault
|
|
244
|
+
// and no signing seed is ever read from the hosted disk. `this.space` cross-checks the bundle.
|
|
245
|
+
//
|
|
246
|
+
// REMOTE AUTHORITY (#1944): a manager holding host-issued remote authority mints nothing from a
|
|
247
|
+
// local signer, so it never composes or validates local trust. It asks ONE question of the
|
|
248
|
+
// store — does THIS space's own local signing trust exist (`localTrustOfSpace`) — because that
|
|
249
|
+
// alone is the conflict of authorities a supervisor refuses. The stock behaviour this replaces
|
|
250
|
+
// read the whole root's trust chain (`getSpaceAuth`): with no records for this space it fell
|
|
251
|
+
// back to the legacy monolith of an UNRELATED static tenant and reported that bundle as
|
|
252
|
+
// "corrupt or mislabeled". Other tenants' records — split (their account + the shared
|
|
253
|
+
// per-root broker record) or monolith — are not this space's trust and never refuse; an
|
|
254
|
+
// unreadable record on a key that is read refuses loud with the store's own parse message.
|
|
255
|
+
//
|
|
256
|
+
// An OPEN mesh mints nothing, also in a root that still holds a static stack's accounts. A
|
|
257
|
+
// credential minted there joins this instance's family in the open account, and the next open
|
|
258
|
+
// boot could re-register only by verify-evicting it through a delivery daemon that an open mesh
|
|
259
|
+
// does not run.
|
|
260
|
+
const recorded = loadMeshes().find((m) => m.space === this.space);
|
|
261
|
+
if (this.remoteAuthority) {
|
|
262
|
+
if ((await localTrustOfSpace(this.secrets, this.space)).present)
|
|
263
|
+
throw new Error("remote manager-service authority cannot be combined with local space signing trust - choose one authority path, never a fallback");
|
|
264
|
+
this.auth = undefined;
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
this.auth = recorded?.mode === "open" ? undefined : await getSpaceAuth(this.secrets, this.space);
|
|
268
|
+
}
|
|
269
|
+
// USER-MODE detection is FAIL-CLOSED on the on-disk marker (the space-scoped state dir), never
|
|
270
|
+
// on the mutable mesh registry alone — registry drift/tamper must not let a user-auth space
|
|
271
|
+
// take the static self-mint branch. A marker/registry disagreement is a refused start with the
|
|
272
|
+
// repair, not a guess.
|
|
273
|
+
this.userMode = this.remoteAuthority !== undefined || hasUserAuthState(this.workspaceRoot, this.space);
|
|
274
|
+
if (!this.remoteAuthority && recorded && (recorded.mode === "user") !== this.userMode)
|
|
275
|
+
throw new Error(`mesh registry says space "${this.space}" is ${recorded.mode}-mode but the on-disk user-auth marker ${this.userMode ? "exists" : "is missing"} (${userAuthStateDir(this.workspaceRoot, this.space)}) - \`cotal down\` and re-\`cotal up\` this space to reconcile before running a manager`);
|
|
276
|
+
if (!this.remoteAuthority && this.userMode && !recorded)
|
|
277
|
+
throw new Error(`space "${this.space}" has user-auth state on disk but no mesh registry entry - a user-mode manager needs the authoritative record (\`cotal up\` writes it before the control plane); \`cotal up --user-auth\` this space, or remove the stale ${userAuthStateDir(this.workspaceRoot, this.space)}`);
|
|
278
|
+
if (!this.remoteAuthority && this.userMode && !this.auth)
|
|
279
|
+
throw new Error(`space "${this.space}" has user-auth state but no auth.json under ${authDir(this.workspaceRoot)} - the pre-flip manager still needs the space trust bundle; re-run \`cotal up --user-auth\` here`);
|
|
280
|
+
// SPEC 13.6 item 7: the LOGICAL instance id + serve identity PERSIST across restart
|
|
281
|
+
// (a space-scoped manager identity file under .cotal). A restart re-registers the SAME id with an
|
|
282
|
+
// ADVANCED epoch (the successor fences the predecessor); a fresh mint over a malformed file is
|
|
283
|
+
// refused loud (no-fallbacks - a restart never silently becomes a fresh instance). A second
|
|
284
|
+
// manager in a DIFFERENT workspace root is a DIFFERENT logical id by construction (its own state
|
|
285
|
+
// dir) - two managers in ONE space are two workspace roots.
|
|
286
|
+
//
|
|
287
|
+
// First mint on a fresh root is exclusive create (#1263). Two processes that both observe no
|
|
288
|
+
// file must not keep different in-memory ids: of N concurrent starts exactly one publishes the
|
|
289
|
+
// file by hard link and the others adopt that identity before taking a lease, or refuse with
|
|
290
|
+
// identity-record-create-lost. A filesystem without hard links refuses the first start with
|
|
291
|
+
// atomic-publish-unsupported. Atomic rename is not enough, because the loser
|
|
292
|
+
// of a replace would still serve under the id it minted.
|
|
293
|
+
{
|
|
294
|
+
if (this.remoteAuthority) {
|
|
295
|
+
this.managerInstanceId = this.remoteAuthority.instanceId;
|
|
296
|
+
this.managerServeIdentity = this.remoteAuthority.identities.serve;
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
// Admission already resolved this identity, including the first mint. A second claim here
|
|
300
|
+
// would stat the same record again.
|
|
301
|
+
const claimed = this.admittedLocalIdentity;
|
|
302
|
+
if (!claimed)
|
|
303
|
+
throw new Error("manager start has no admitted local identity");
|
|
304
|
+
this.admittedLocalIdentity = undefined;
|
|
305
|
+
this.managerInstanceId = claimed.instanceId;
|
|
306
|
+
this.managerServeIdentity = claimed.serveIdentity;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
await this.onServiceIdentity?.(this.serviceIdentityObservation());
|
|
310
|
+
let creds;
|
|
311
|
+
let id;
|
|
312
|
+
if (this.remoteAuthority) {
|
|
313
|
+
const remote = this.remoteAuthority;
|
|
314
|
+
id = remote.identities.supervisor.id;
|
|
315
|
+
creds = async () => this.remoteSupervisorCreds;
|
|
316
|
+
}
|
|
317
|
+
else if (this.auth) {
|
|
318
|
+
const identity = newIdentity();
|
|
319
|
+
const auth = this.auth;
|
|
320
|
+
id = identity.id;
|
|
321
|
+
// The long-lived SUPERVISOR cred (closure (ii), residual 2): serve the three control tiers, hold the
|
|
322
|
+
// singleton lease (open-only), publish + watch presence — and nothing else. Provisioning runs on an
|
|
323
|
+
// EPHEMERAL provisioner connection per spawn (withProvisioner); destructive purge mints a PURGER per
|
|
324
|
+
// call. So the always-on daemon holds no DM/DLV read, no consumer-create, no stream-admin tamper.
|
|
325
|
+
//
|
|
326
|
+
// STANDING RENEWAL (class 1): the manager holds the DATA signing seed, so it is its
|
|
327
|
+
// own renewal owner — the cred rides the endpoint's SOURCE seam and self-remints (same identity,
|
|
328
|
+
// pinned by the endpoint) ahead of each bounded supervisor JWT's expiry. A copied supervisor
|
|
329
|
+
// cred is broker-dead within the matrix TTL.
|
|
330
|
+
creds = () => mintCreds(auth, identity, "supervisor");
|
|
331
|
+
}
|
|
332
|
+
this.ep = new CotalEndpoint({
|
|
333
|
+
space: this.space,
|
|
334
|
+
servers: this.servers,
|
|
335
|
+
channels: [],
|
|
336
|
+
creds,
|
|
337
|
+
// The supervisor registers on the roster, and an authed presence-registering endpoint is
|
|
338
|
+
// lifecycle-keyed (SPEC 13.1, fail-before-presence). The manager process is the top of its
|
|
339
|
+
// own launch chain (the operator command IS its launcher): its incarnation uid is the
|
|
340
|
+
// per-process `managerLifecycleUid` field (also the `managerInstance` audit coordinate on
|
|
341
|
+
// every static activation).
|
|
342
|
+
lifecycleUid: this.remoteAuthority?.lifecycleUid ?? this.managerLifecycleUid,
|
|
343
|
+
// The supervisor serves control + watches presence; it never consumes chat/dm/task
|
|
344
|
+
// (no message handler). consume:false avoids binding consumers it doesn't use — and
|
|
345
|
+
// under auth avoids trying to bind its own DM/task durables that nothing pre-created.
|
|
346
|
+
// It still pre-creates OTHERS' durables via provisionDmInbox/provisionTaskQueue (lazy jsm).
|
|
347
|
+
consume: false,
|
|
348
|
+
// It also never reads the channel registry (it provisions + serves control, no channel
|
|
349
|
+
// pull/display), so skip the channel-registry watch — the supervisor cred (residual 2) then
|
|
350
|
+
// holds no channel-KV read grant. Presence (the roster) is still watched.
|
|
351
|
+
watchChannels: false,
|
|
352
|
+
// `host` says which machine runs this manager, as an agent's card does: an owner with several
|
|
353
|
+
// managers tells them apart by it. Advisory display metadata, never a routing input.
|
|
354
|
+
card: { id, ...(this.remoteAuthority ? { owner: this.remoteAuthority.owner, actor: this.remoteAuthority.actors.supervisor } : {}), name: this.name, role: "manager", kind: "endpoint", meta: { host: hostname(), terminal: this.streamsTerminal ? "stream" : "none" } },
|
|
355
|
+
});
|
|
356
|
+
// Raw failures ride error; conditions the endpoint is already surviving ride warning. Both
|
|
357
|
+
// matter to a supervisor operator, especially a failed standing-credential renewal.
|
|
358
|
+
const reportEndpoint = (e) => console.error(`! manager endpoint: ${e.message}`);
|
|
359
|
+
this.ep.on("error", reportEndpoint);
|
|
360
|
+
this.ep.on("warning", reportEndpoint);
|
|
361
|
+
// Every roster change and every view transition, so a seat that is offline in a fresh snapshot
|
|
362
|
+
// (recorded with no presence event) is logged the moment the view can support the verdict.
|
|
363
|
+
this.ep.on("roster", () => this.logSeatMeshTransitions());
|
|
364
|
+
this.ep.on("presence-view", () => this.logSeatMeshTransitions());
|
|
365
|
+
console.error("manager startup: connecting the supervisor endpoint");
|
|
366
|
+
await this.ep.start();
|
|
367
|
+
await this.ep.setActivity(`supervisor (${this.runtimeKind})`);
|
|
368
|
+
// Per-instance liveness lease (the old per-space singleton is DEMOTED). Acquire
|
|
369
|
+
// THIS logical instance's own key (atomic CAS create). A DIFFERENT instance (a second manager in a
|
|
370
|
+
// second workspace root) has a distinct id ⇒ a distinct key ⇒ it coexists; the create THROWS only
|
|
371
|
+
// when the SAME instance id is already live (a same-root double-start, or a restart racing the
|
|
372
|
+
// crashed predecessor's not-yet-expired key). A double-start REFUSES loud; a restart whose
|
|
373
|
+
// predecessor is provably dead on this host waits for that key's bucket TTL to remove it (#4092,
|
|
374
|
+
// {@link acquireInstanceLease}). Losing the key LATER ends this process only when another process holds it; otherwise
|
|
375
|
+
// the renew loop puts it back or keeps retrying ({@link renewLease}).
|
|
376
|
+
this.leaseInfo = { holder: this.ep.ref().id, instanceId: this.managerInstanceId, runtime: this.runtimeKind, root: resolve(this.workspaceRoot), pid: process.pid };
|
|
377
|
+
try {
|
|
378
|
+
console.error("manager startup: acquiring the instance liveness lease");
|
|
379
|
+
this.leaseRevision = await this.acquireInstanceLease(this.leaseInfo);
|
|
380
|
+
}
|
|
381
|
+
catch (e) {
|
|
382
|
+
await this.ep.stop();
|
|
383
|
+
await this.attach.stop();
|
|
384
|
+
throw e;
|
|
385
|
+
}
|
|
386
|
+
this.leaseTimer = setInterval(() => { void this.renewLease(); }, MANAGER_LEASE_RENEW_MS);
|
|
387
|
+
this.leaseTimer.unref?.();
|
|
388
|
+
// THE PEER-READABLE LIVENESS RESPONDER for the manager plane (#1577). Bound HERE — after the
|
|
389
|
+
// lease, before registration — precisely so it is up during the window in which the manager is
|
|
390
|
+
// NOT yet serving. A responder that only appeared once everything worked could never report the
|
|
391
|
+
// broken state it exists to report, which is the reported defect in a new place.
|
|
392
|
+
//
|
|
393
|
+
// WHAT IT GRADES is `serviceServe`, the v0.4 service endpoint's serve handle, which is assigned
|
|
394
|
+
// only after `serveEndpoint` has bound this instance's rails, AND that handle's connection. A
|
|
395
|
+
// closed serve connection holds no subscriptions, while `onServeConnectionClosed` keeps the
|
|
396
|
+
// handle through its re-dial waits, so the handle alone would answer `bound` with every rail
|
|
397
|
+
// gone. The re-dial swaps in the fresh connection and handle together, so `bound` returns only
|
|
398
|
+
// once the rails are served again. A DISCONNECTED serve connection is the same fault without the
|
|
399
|
+
// close: it reconnects without limit, so it stays open while the broker holds none of its rails,
|
|
400
|
+
// and this probe arrives on the separate supervisor connection that is still up. So the grade
|
|
401
|
+
// also requires the serve transport to be connected. That is a RESPONDER fact. It is
|
|
402
|
+
// deliberately NOT "this process is alive": this process is trivially alive whenever it answers
|
|
403
|
+
// at all, so grading on that would make the surface a `pgrep` that also lies in both directions
|
|
404
|
+
// — the exact instrument the reporter's evidence table indicts. Between lease acquisition and a
|
|
405
|
+
// successful registration the honest answer is `unbound`, and that is what a peer is told.
|
|
406
|
+
//
|
|
407
|
+
// The lease row is never consulted and never sent: presence is the whole ask, and the row
|
|
408
|
+
// carries the operator's workspace root and pid.
|
|
409
|
+
this.ep.serveLiveness("manager", () => {
|
|
410
|
+
const s = this.serviceServe;
|
|
411
|
+
return s?.handle && !s.nc.isClosed() && !this.transportDown.has(s.nc) ? "bound" : "unbound";
|
|
412
|
+
});
|
|
413
|
+
// Static §13.1: after this instance holds its lease, collect the durable static rows
|
|
414
|
+
// now, but do not let their exact-op terminals make the whole space unreachable. The service
|
|
415
|
+
// comes up below, then the sweep overlaps the remaining registration work. Two-window
|
|
416
|
+
// heal-then-register is slower than one executor, but the overlap is still the no-outage
|
|
417
|
+
// property: `reconcilingAliases` refuses spawn or attach of THAT alias until its terminal
|
|
418
|
+
// attempt returns.
|
|
419
|
+
const startupReconcile = this.auth && !this.userMode ? this.reconcileStaticLifecycles() : undefined;
|
|
420
|
+
if (startupReconcile)
|
|
421
|
+
void startupReconcile.catch((e) => console.error(`! ${STARTUP_RECONCILING}: ${rejectionText(e)} - no per-alias retry could be planned; a later manager start re-reads unfinished durable terminals`));
|
|
422
|
+
// A default stop records a user-mode seat it released while the seat was still running. This
|
|
423
|
+
// start adopts that seat, or retires it when the runtime proves it gone. Static seats stay on
|
|
424
|
+
// the sweep above.
|
|
425
|
+
if (this.userMode)
|
|
426
|
+
void this.adoptReleasedSeats().catch((e) => console.error(`! a released seat was not adopted: ${rejectionText(e)}`));
|
|
427
|
+
// The manager serves NO ctl tiers - its whole control surface is the v0.4
|
|
428
|
+
// service endpoint registered below. The old three-tier rail (self/manager/admin) is deleted;
|
|
429
|
+
// `ctl.delivery`/`ctl.delivery-admin` (the delivery daemon) and `ctl.auth-admin` (the auth
|
|
430
|
+
// plane) are separate services and keep their rails.
|
|
431
|
+
// Class 2: the manager is the CLASS-2 RENEWAL OWNER — the one control-plane process
|
|
432
|
+
// that is resident in EVERY mesh mode (foreground `up`, `up --detach`, same-root refresh) and
|
|
433
|
+
// holds the signer. Ordered initial pass NOW (ensureControlPlane starts delivery BEFORE the
|
|
434
|
+
// manager, so the daemon's launch-time creds write always precedes this — no write race), then
|
|
435
|
+
// every half-TTL: re-sign the daemon creds files for their EXISTING nkeys, request the explicit
|
|
436
|
+
// `reloadCreds` adoption on the delivery-admin rail, and persist the audit record doctor renders.
|
|
437
|
+
if (this.auth) {
|
|
438
|
+
// #1634: a space may be served by several managers, so ownership of the daemon's credential
|
|
439
|
+
// renewal is decided here rather than by being the only manager able to start. #871: a daemon
|
|
440
|
+
// that is still binding or re-acquiring its lease leaves this challenge unanswered for a few
|
|
441
|
+
// seconds, so boot waits that out instead of exiting over a daemon about to answer.
|
|
442
|
+
await this.claimDaemonRenewalOwnership(DELIVERY_ADMIN_BOOT_WAIT_MS);
|
|
443
|
+
// ARMED BEFORE the first remint, not after. That first `renewDaemonCreds()` re-signs through
|
|
444
|
+
// the SecretStore, and a slow or contended store makes the one pass outlast the lease's
|
|
445
|
+
// MANAGER_LEASE_TTL_MS. Arming afterwards leaves the whole first remint unprotected: the lease
|
|
446
|
+
// expires mid-pass, a second manager's CAS create succeeds, and both remint into one store.
|
|
447
|
+
this.daemonRenewalLeaseTimer = setInterval(() => { void this.keepDaemonRenewalLease(); }, MANAGER_LEASE_RENEW_MS);
|
|
448
|
+
this.daemonRenewalLeaseTimer.unref?.();
|
|
449
|
+
await this.renewDaemonCreds();
|
|
450
|
+
this.credRenewTimer = setInterval(() => { void this.renewDaemonCreds(); }, credRenewIntervalMs(STANDING_RENEWABLE_TTL_SEC));
|
|
451
|
+
this.credRenewTimer.unref?.();
|
|
452
|
+
}
|
|
453
|
+
else if (this.remoteAuthority) {
|
|
454
|
+
if (this.remoteAuthority.renewStandingBundle)
|
|
455
|
+
await this.renewRemoteStandingBundle();
|
|
456
|
+
else
|
|
457
|
+
await this.renewRemoteExecutor();
|
|
458
|
+
let standingTtl = STANDING_RENEWABLE_TTL_SEC;
|
|
459
|
+
if (this.remoteSupervisorCreds) {
|
|
460
|
+
try {
|
|
461
|
+
const claims = credsClaims(this.remoteSupervisorCreds);
|
|
462
|
+
if (typeof claims.exp === "number" && typeof claims.iat === "number" && claims.exp > claims.iat) {
|
|
463
|
+
standingTtl = claims.exp - claims.iat;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
catch { }
|
|
467
|
+
}
|
|
468
|
+
// A refused family needs another pass inside the final quarter of its lifetime.
|
|
469
|
+
const intervalMs = Math.min(credRenewIntervalMs(5 * 60), Math.max(1, Math.floor(standingTtl * 1000 / 8)));
|
|
470
|
+
this.resumeCredRenewal = () => {
|
|
471
|
+
if (this.credRenewTimer || this.leaseStopping)
|
|
472
|
+
return;
|
|
473
|
+
this.credRenewTimer = setInterval(async () => {
|
|
474
|
+
try {
|
|
475
|
+
if (this.remoteAuthority?.renewStandingBundle)
|
|
476
|
+
await this.renewRemoteStandingBundle();
|
|
477
|
+
else
|
|
478
|
+
await this.renewRemoteExecutor();
|
|
479
|
+
}
|
|
480
|
+
catch (e) {
|
|
481
|
+
console.error(`! remote manager renewal pass failed: ${rejectionText(e)}`);
|
|
482
|
+
}
|
|
483
|
+
try {
|
|
484
|
+
await this.runHosting?.renew();
|
|
485
|
+
}
|
|
486
|
+
catch (e) {
|
|
487
|
+
console.error(`! remote run-hosting renewal pass failed: ${rejectionText(e)}`);
|
|
488
|
+
}
|
|
489
|
+
}, intervalMs);
|
|
490
|
+
this.credRenewTimer.unref?.();
|
|
491
|
+
};
|
|
492
|
+
this.resumeCredRenewal();
|
|
493
|
+
}
|
|
494
|
+
// stop() fences before it waits for an accepted startup reconciliation terminal. Once that
|
|
495
|
+
// terminal drains, start() and stop() resume from the same await boundary; start must observe
|
|
496
|
+
// the fence before it can publish a fresh service registration after shutdown.
|
|
497
|
+
if (this.staticLifecycle.stopping)
|
|
498
|
+
return;
|
|
499
|
+
// Register the manager as an ordinary v0.4 `service` endpoint (SPEC §13.7/§13.9)
|
|
500
|
+
// and serve its typed command surface on the ep rails - the ONLY control door, in
|
|
501
|
+
// EVERY mesh mode. Static + user meshes mint the scoped executor + endpoint-serve credential;
|
|
502
|
+
// an open mesh runs the same gate/registration ceremony over bare connections and never mints
|
|
503
|
+
// (there is no credential system - the broker enforces nothing, matching the old open-mesh ctl
|
|
504
|
+
// trust). Fail-loud: a manager that cannot register does not start half-registered.
|
|
505
|
+
console.error("manager startup: binding the service endpoint");
|
|
506
|
+
await this.registerManagerService();
|
|
507
|
+
if (this.staticLifecycle.stopping)
|
|
508
|
+
return;
|
|
509
|
+
// Stand up the standing goal-writer connection for spawn-as-action — AFTER
|
|
510
|
+
// registration (it writes this endpoint's goal facts/records), disjoint from the serve cred.
|
|
511
|
+
await this.startGoalWriter();
|
|
512
|
+
// Stand up the ONE §13.6 session plane for `attach` — AFTER registration too (it
|
|
513
|
+
// rides the serve grant's epoch + the family-staged session-ledger cred), on its own standing
|
|
514
|
+
// connection disjoint from both the serve and goal-writer creds.
|
|
515
|
+
await this.startSessionPlane();
|
|
516
|
+
// Reconcile any accepted-but-unterminal goals inherited from a predecessor
|
|
517
|
+
// BEFORE spawn-as-action begins accepting (the goalReconcileDone gate) — a fresh incarnation
|
|
518
|
+
// never drops a goal a dead predecessor accepted. Never fatal; the gate opens either way.
|
|
519
|
+
console.error("manager startup: reconciling predecessor goals");
|
|
520
|
+
await this.reconcileGoalIndex();
|
|
521
|
+
// SPEC 14.3: the manager hosts workflow runs. Stood up AFTER registration (it names this
|
|
522
|
+
// instance's coordinates) and reconciled AFTER the goal index, for the same reason: a fresh
|
|
523
|
+
// incarnation takes back every run a dead predecessor was driving before it accepts new ones.
|
|
524
|
+
// The serve surface is already live by here, so the family itself holds the gate: `runHost()`
|
|
525
|
+
// refuses `run-start`/`run-resume` as `unavailable` until the host exists and `RunHosting`
|
|
526
|
+
// refuses them until its reconcile has returned. A remote user-auth manager uses its four
|
|
527
|
+
// registered issuer callbacks instead of holding a signer; a local user mesh stands none up.
|
|
528
|
+
const remoteRuns = this.remoteAuthority?.runHosting;
|
|
529
|
+
if (this.execution !== "none" && this.remoteAuthority && remoteRuns) {
|
|
530
|
+
this.runHosting = new RunHosting({
|
|
531
|
+
space: this.space,
|
|
532
|
+
servers: this.servers,
|
|
533
|
+
endpoint: MANAGER_ENDPOINT,
|
|
534
|
+
instanceId: this.managerInstanceId,
|
|
535
|
+
holder: { id: this.remoteAuthority.identities.supervisor.id, lifecycleUid: this.managerLifecycleUid },
|
|
536
|
+
auth: undefined,
|
|
537
|
+
log: (line) => console.error(line),
|
|
538
|
+
admitRun: remoteRuns.admitRun,
|
|
539
|
+
submitRun: remoteRuns.submitRun,
|
|
540
|
+
revokeRun: remoteRuns.revokeRun,
|
|
541
|
+
cancelRun: remoteRuns.cancelRun,
|
|
542
|
+
issueAttempt: remoteRuns.issueAttempt,
|
|
543
|
+
issueOperator: remoteRuns.issueOperator,
|
|
544
|
+
renewRun: remoteRuns.renewRun,
|
|
545
|
+
});
|
|
546
|
+
await this.runHosting.reconcile();
|
|
547
|
+
}
|
|
548
|
+
else if (!this.remoteAuthority && !this.userMode) {
|
|
549
|
+
this.runHosting = new RunHosting({
|
|
550
|
+
space: this.space,
|
|
551
|
+
servers: this.servers,
|
|
552
|
+
endpoint: MANAGER_ENDPOINT,
|
|
553
|
+
instanceId: this.managerInstanceId,
|
|
554
|
+
holder: { id: this.ep.ref().id, lifecycleUid: this.managerLifecycleUid },
|
|
555
|
+
auth: this.auth,
|
|
556
|
+
log: (line) => console.error(line),
|
|
557
|
+
});
|
|
558
|
+
await this.runHosting.reconcile();
|
|
559
|
+
}
|
|
560
|
+
// A carried resume (#1499) needs this instance's transfer reader: minted from the space's signing
|
|
561
|
+
// seed, issued by the host to a remote manager, or none on an open mesh.
|
|
562
|
+
if (this.execution !== "none" && (!this.remoteAuthority || this.remoteAuthority.mintTransferReader)) {
|
|
563
|
+
this.transcripts = new TranscriptReceiver({
|
|
564
|
+
space: this.space,
|
|
565
|
+
instanceId: this.managerInstanceId,
|
|
566
|
+
workspaceRoot: this.workspaceRoot,
|
|
567
|
+
withReader: (fn) => this.withTransferReader(fn),
|
|
568
|
+
log: (line) => console.error(line),
|
|
569
|
+
});
|
|
570
|
+
await this.transcripts.start();
|
|
571
|
+
}
|
|
572
|
+
for (const note of this.bootNotes.splice(0))
|
|
573
|
+
console.error(note);
|
|
574
|
+
// Plane-3 (durable backstop) is NOT the manager's job — the manager only manages agent lifecycle.
|
|
575
|
+
// The server-side delivery daemon hosts the fan-out writer + trusted reader, owns the durable
|
|
576
|
+
// membership registry, and serves the runtime durable join/leave/list ops (on `ctl.delivery`). The
|
|
577
|
+
// manager records each agent's read ACL at spawn (`commitAcl`, in provisionAgent) so the daemon can
|
|
578
|
+
// re-authorize it; that is the only Plane-3 state the manager touches, and it rides minting.
|
|
579
|
+
}
|
|
580
|
+
/** Complete a crashed predecessor's FROZEN registration gate before this incarnation starts a
|
|
581
|
+
* new one (#783 item 3 / #871). The CLI `cotal reconcile-gate` already does this; a successor
|
|
582
|
+
* that cannot register is exactly the state that command exists to repair, so boot must run
|
|
583
|
+
* the SAME composition rather than waiting for an operator.
|
|
584
|
+
*
|
|
585
|
+
* Admit only `gone` AND `sweepComplete=true` (the probe mapping already folds an incomplete
|
|
586
|
+
* `gone` into `unestablishable`). Live / unknown / unestablishable / wrong-op-kind stay loud
|
|
587
|
+
* refusals. No TTL: request-ingress has no process-epoch fence, so a clock would either let a
|
|
588
|
+
* superseded serve credential keep consuming ingress or just rename the freeze. An open gate
|
|
589
|
+
* is a no-op (the successor's own freeze comes next). A committed spec under that freeze is
|
|
590
|
+
* finished at the committed registrationRevision; only a definite no-commit abort-reopens. */
|
|
591
|
+
async healFrozenRegistrationGate(authKv, instanceId, auth, recordsKv) {
|
|
592
|
+
const key = epgateKey(MANAGER_ENDPOINT, instanceId);
|
|
593
|
+
const entry = await authKv.get(key);
|
|
594
|
+
if (!entry || entry.operation !== "PUT")
|
|
595
|
+
return;
|
|
596
|
+
const row = parseEndpointGate(entry.value, key);
|
|
597
|
+
if (row.state !== "frozen")
|
|
598
|
+
return;
|
|
599
|
+
const servers = this.servers ?? DEFAULT_SERVER;
|
|
600
|
+
const log = (line) => console.error(` ${line}`);
|
|
601
|
+
let report;
|
|
602
|
+
try {
|
|
603
|
+
report = await reconcileEndpointGate({
|
|
604
|
+
kv: authKv, space: this.space, endpoint: MANAGER_ENDPOINT, instanceId,
|
|
605
|
+
probeHolder: makeManagerHolderLivenessProbe({ space: this.space, servers, auth, log, unreachableWaitMs: DELIVERY_ADMIN_BOOT_WAIT_MS }),
|
|
606
|
+
evictHolders: makeManagerEndpointHolderEvictor({ space: this.space, servers, auth, log }),
|
|
607
|
+
log,
|
|
608
|
+
recordsKv,
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
catch (e) {
|
|
612
|
+
// We observed frozen, then a concurrent reconciler finished first. If the gate is now open,
|
|
613
|
+
// this incarnation continues the takeover. Every other refusal — including raced-but-still-
|
|
614
|
+
// frozen — stays loud.
|
|
615
|
+
if (e instanceof GateReconcileRefused && (e.condition === "not-frozen" || e.condition === "raced")) {
|
|
616
|
+
const latest = await authKv.get(key);
|
|
617
|
+
if (latest && latest.operation === "PUT" && parseEndpointGate(latest.value, key).state === "open") {
|
|
618
|
+
console.error(`boot self-heal: ${MANAGER_ENDPOINT}/${instanceId} is open after ${e.condition}; continuing the normal takeover`);
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
throw e;
|
|
623
|
+
}
|
|
624
|
+
console.error(`✓ boot self-heal: ${MANAGER_ENDPOINT}/${instanceId} registration gate reopened at generation ${report.reopenedAtGeneration} (processEpoch ${report.after.processEpoch}, registrationRevision ${report.after.registrationRevision}; freeze-holder gone, sweepComplete=true). Continuing the normal takeover.`);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
//# sourceMappingURL=boot.js.map
|