@cotal-ai/manager 0.166.2 → 0.167.0
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/console/session-bundle.js +2 -0
- package/dist/manager-timeout.d.ts +5 -0
- package/dist/manager-timeout.d.ts.map +1 -0
- package/dist/manager-timeout.js +11 -0
- package/dist/manager-timeout.js.map +1 -0
- package/dist/manager.d.ts +162 -243
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +213 -1732
- package/dist/manager.js.map +1 -1
- package/dist/retirement.d.ts +221 -0
- package/dist/retirement.d.ts.map +1 -0
- package/dist/retirement.js +480 -0
- package/dist/retirement.js.map +1 -0
- package/dist/seat-custody.d.ts +100 -0
- package/dist/seat-custody.d.ts.map +1 -0
- package/dist/seat-custody.js +320 -0
- package/dist/seat-custody.js.map +1 -0
- package/dist/serve-plane.d.ts +228 -0
- package/dist/serve-plane.d.ts.map +1 -0
- package/dist/serve-plane.js +664 -0
- package/dist/serve-plane.js.map +1 -0
- package/dist/session-recovery.d.ts +115 -0
- package/dist/session-recovery.d.ts.map +1 -0
- package/dist/session-recovery.js +350 -0
- package/dist/session-recovery.js.map +1 -0
- package/package.json +12 -12
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
import { rmSync } from "node:fs";
|
|
2
|
+
import { credsAuthenticator } from "@nats-io/transport-node";
|
|
3
|
+
import { DEFAULT_SERVER, DEV_OWNER, DeprovisionError, deprovisionAgent, isConcreteChannel, managedRetirementOpId, mintCreds, newIdentity, parsePrincipalKey, principalKey, resolveAuthProvider, AUTH_ENDPOINT, EP_CMD_RETIRE_LIFECYCLE, resolveService, invokeCommand, rejectionText, attemptCleanup, describeCleanupFailures, } from "@cotal-ai/core";
|
|
4
|
+
import { agentLifecycleSecretFilePaths, agentSecretKeyForFile, userAuthStateDir } from "@cotal-ai/workspace";
|
|
5
|
+
import { MANAGER_ENDPOINT } from "./manager-service-contract.js";
|
|
6
|
+
/** Retirement holds, exact-lifecycle teardown flights and confirmed predecessor coordinates. */
|
|
7
|
+
export class Retirement {
|
|
8
|
+
deps;
|
|
9
|
+
/** Names RESERVED PENDING RETIREMENT: a despawned agent's name stays held until
|
|
10
|
+
* the auth plane confirms its lifecycle's retirement TERMINAL over the auth-admin rail - the
|
|
11
|
+
* alias-reuse gate that closes the same-name despawn→respawn race at its root. An UNCERTAIN
|
|
12
|
+
* outcome (rail down, timeout) keeps the hold with the last attempt's copy; a same-name spawn
|
|
13
|
+
* refuses legibly AND re-fires the request. In-memory: across a manager restart the durable
|
|
14
|
+
* truth is the auth-side lifecycle head itself (an unretired head refuses issuance - the
|
|
15
|
+
* named residual this belt narrows, not replaces). */
|
|
16
|
+
retiring = new Map();
|
|
17
|
+
/** SINGLE-FLIGHT guard for {@link requestRetirement} (audit #1): one in-flight rail round-trip per
|
|
18
|
+
* (name, lifecycleUid). The detached `deprovision` call and every same-name-spawn nudge for THAT
|
|
19
|
+
* lifecycle JOIN the same promise instead of stacking independent requests that dual-enter the
|
|
20
|
+
* barrier; a fresh trigger after it settles re-drives. Keyed by (name, uid) - NOT name alone - so a
|
|
21
|
+
* same-name SUCCESSOR (which can spawn after the hold clears but before this flight's `nc.close`
|
|
22
|
+
* yield settles) never joins the predecessor's rail request and skips its own retirement. */
|
|
23
|
+
retiringFlight = new Map();
|
|
24
|
+
/** Wire principals of RETIRED static incarnations: populated at every completed
|
|
25
|
+
* static terminal and from the boot sweep's retired slot rows, so a copied credential of a
|
|
26
|
+
* retired incarnation is refused at the control surface even across a manager restart. The
|
|
27
|
+
* durable truth is the slot row + principal-keyed head; this set is the in-memory index of it
|
|
28
|
+
* (one string per retired incarnation - bounded by lifecycle count, never pruned in-process). */
|
|
29
|
+
retiredPrincipals = new Set();
|
|
30
|
+
/** Exact predecessor incarnations whose full hosted retirement reached a terminal answer. Presence
|
|
31
|
+
* is advisory and can retain that old lifecycle briefly after its process exits. Resume may ignore
|
|
32
|
+
* only this exact (alias, principal, lifecycleUid) row when adopting a different lifecycle; every
|
|
33
|
+
* unknown, current, or differently identified live row still refuses. A later retirement of the
|
|
34
|
+
* same alias replaces its prior predecessor coordinate. */
|
|
35
|
+
confirmedRetiredPredecessors = new Map();
|
|
36
|
+
/** SINGLE-FLIGHT guard for {@link deprovision} (INT-2/C): one in-flight teardown per
|
|
37
|
+
* (name, lifecycleUid). The detached freeSlot teardown and every same-name-spawn nudge that
|
|
38
|
+
* re-drives it JOIN one promise instead of launching a SECOND, concurrent teardown. Without it,
|
|
39
|
+
* two teardowns race the NAME-KEYED ledger revoke: once the first frees the alias and a successor
|
|
40
|
+
* mints its own row, the second's delayed revoke (which carries no lifecycle coordinate) would
|
|
41
|
+
* delete the SUCCESSOR's standing authority. Keyed by (name, uid) so a later same-name lifecycle
|
|
42
|
+
* gets its own flight; a fresh trigger after settle re-drives only if the hold still stands. */
|
|
43
|
+
deprovisioningFlight = new Map();
|
|
44
|
+
constructor(deps) {
|
|
45
|
+
this.deps = deps;
|
|
46
|
+
}
|
|
47
|
+
get auth() { return this.deps.auth(); }
|
|
48
|
+
get remoteAuthority() { return this.deps.remoteAuthority(); }
|
|
49
|
+
get userMode() { return this.deps.userMode(); }
|
|
50
|
+
get workspaceRoot() { return this.deps.workspaceRoot(); }
|
|
51
|
+
get space() { return this.deps.space(); }
|
|
52
|
+
get servers() { return this.deps.servers(); }
|
|
53
|
+
get secrets() { return this.deps.secrets(); }
|
|
54
|
+
get managerServeIdentity() { return this.deps.serveIdentity(); }
|
|
55
|
+
get managerLifecycleUid() { return this.deps.lifecycleUid(); }
|
|
56
|
+
get managerInstanceId() { return this.deps.instanceId(); }
|
|
57
|
+
dial(opts) { return this.deps.dial(opts); }
|
|
58
|
+
withRetirementSlot(run) { return this.deps.withRetirementSlot(run); }
|
|
59
|
+
driveStaticRetirement(a) { return this.deps.driveStaticRetirement(a); }
|
|
60
|
+
awaitHandleExit(handle) { return this.deps.awaitHandleExit(handle); }
|
|
61
|
+
shredUserSecrets(failures, family) { return this.deps.shredUserSecrets(failures, family); }
|
|
62
|
+
dropSeatRecord(a) { return this.deps.dropSeatRecord(a); }
|
|
63
|
+
fenceRetiringAcl(a) { return this.deps.fenceRetiringAcl(a); }
|
|
64
|
+
lifecycleMembershipInventory(a) { return this.deps.lifecycleMembershipInventory(a); }
|
|
65
|
+
hold(name, hold) { this.retiring.set(name, hold); }
|
|
66
|
+
held(name) { return this.retiring.get(name); }
|
|
67
|
+
hasHold(name) { return this.retiring.has(name); }
|
|
68
|
+
predecessor(name) { return this.confirmedRetiredPredecessors.get(name); }
|
|
69
|
+
get pendingCount() { return this.retiring.size; }
|
|
70
|
+
get inFlightCount() { return this.deprovisioningFlight.size; }
|
|
71
|
+
rememberRetired(principal) { this.retiredPrincipals.add(principal); }
|
|
72
|
+
recordStaticRetirement(a) {
|
|
73
|
+
const principal = principalKey(DEV_OWNER, a.id).key;
|
|
74
|
+
this.retiredPrincipals.add(principal);
|
|
75
|
+
const cur = this.retiring.get(a.name);
|
|
76
|
+
if (cur && cur.target.lifecycleUid === a.lifecycleUid) {
|
|
77
|
+
this.retiring.delete(a.name); // ABA-guarded hold clear
|
|
78
|
+
this.confirmedRetiredPredecessors.set(a.name, { principal, lifecycleUid: a.lifecycleUid });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
membershipRefusal(caller) {
|
|
82
|
+
for (const [name, hold] of this.retiring) {
|
|
83
|
+
const held = hold.target.userOwner ? hold.target.id : principalKey(DEV_OWNER, hold.target.id).key;
|
|
84
|
+
if (held === caller)
|
|
85
|
+
return `the caller's lifecycle ${hold.target.lifecycleUid} (name "${name}") is retiring; a retiring incarnation's credential holds no control authority`;
|
|
86
|
+
}
|
|
87
|
+
if (this.retiredPrincipals.has(caller))
|
|
88
|
+
return "the caller's lifecycle is retired; a retired incarnation's credential holds no control authority";
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
/** Tear down a departed agent's minted footprint (#159 B2, auth mode): its local-principal durables
|
|
92
|
+
* (`dm_local-<id>`, `dlv_local-<id>`), its read-ACL row, and its creds file - everything the spawn's
|
|
93
|
+
* `provisionAgent` + creds-write left behind. Mints an EPHEMERAL, TARGET-PINNED `deprovisioner` cred
|
|
94
|
+
* (mirrors the ephemeral `provisioner`/`purger`): it can delete only THIS agent's local-principal footprint,
|
|
95
|
+
* never a peer's and never the role-shared `svc_<role>` (which its siblings still bind). Open mesh →
|
|
96
|
+
* no-op (nothing was minted). Idempotent at the broker (missing consumer / ACL row = no-op) and on
|
|
97
|
+
* disk (`force` tolerates an absent creds file, e.g. a ledgered deploy that wrote none).
|
|
98
|
+
*
|
|
99
|
+
* Removing the creds file is footprint REDUCTION, not revocation: a JWT copied off disk before exit
|
|
100
|
+
* keeps its inline publish/live-sub/control grants until key rotation or JWT expiry - cred revocation
|
|
101
|
+
* is the separate per-user-auth work, not this. Tearing down the durables + ACL row still shrinks the
|
|
102
|
+
* delivery surface a stale copy could use. */
|
|
103
|
+
async deprovision(a) {
|
|
104
|
+
if (!this.auth && !this.remoteAuthority)
|
|
105
|
+
return; // open mesh mints no creds/durables - nothing to tear down
|
|
106
|
+
// SINGLE-FLIGHT per (name, lifecycleUid) (INT-2/C): join an in-flight teardown for this exact
|
|
107
|
+
// lifecycle rather than launching a second concurrent one whose delayed name-keyed revoke could
|
|
108
|
+
// outlive the hold-clear and delete a successor's row. A fresh trigger after settle re-drives.
|
|
109
|
+
const key = JSON.stringify([a.name, a.lifecycleUid]); // ASCII-safe, delimiter-collision-free
|
|
110
|
+
const inflight = this.deprovisioningFlight.get(key);
|
|
111
|
+
if (inflight)
|
|
112
|
+
return inflight;
|
|
113
|
+
const flight = this.withRetirementSlot(() => this.driveDeprovision(a)).finally(() => {
|
|
114
|
+
if (this.deprovisioningFlight.get(key) === flight)
|
|
115
|
+
this.deprovisioningFlight.delete(key);
|
|
116
|
+
});
|
|
117
|
+
this.deprovisioningFlight.set(key, flight);
|
|
118
|
+
return flight;
|
|
119
|
+
}
|
|
120
|
+
/** The actual footprint teardown (wrapped by {@link deprovision}'s single-flight). */
|
|
121
|
+
async driveDeprovision(a) {
|
|
122
|
+
if (this.remoteAuthority) {
|
|
123
|
+
if (a.delegated) {
|
|
124
|
+
// The agent is its user's: only that user's retirement intent retires it, so the name stays
|
|
125
|
+
// held until retireDelegatedAgent confirms the host retired this UID.
|
|
126
|
+
const held = this.retiring.get(a.name);
|
|
127
|
+
if (held?.target.lifecycleUid === a.lifecycleUid)
|
|
128
|
+
held.lastError = `"${a.name}" was launched under a delegated user intent and retires only through its user's retirement intent`;
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
// A hosted composition owns grant revocation and resumable footprint release. It calls this
|
|
132
|
+
// prerequisite before the terminal rail. The callback must preserve this UID and its pending
|
|
133
|
+
// state until the host decides terminal retirement, never map deprovisioning to suspension.
|
|
134
|
+
const target = parsePrincipalKey(a.id);
|
|
135
|
+
if (!target)
|
|
136
|
+
throw new Error(`hosted retirement cannot derive the managed principal ${a.id}`);
|
|
137
|
+
await this.remoteAuthority.prepareAgentRetirement({
|
|
138
|
+
target: { owner: target.owner, actor: target.actor, lifecycleUid: a.lifecycleUid },
|
|
139
|
+
opId: managedRetirementOpId(a.lifecycleUid),
|
|
140
|
+
});
|
|
141
|
+
// A delegated seat's fenced close runs only now, after the grant is revoked so its child can
|
|
142
|
+
// obtain no fresh bearer, and before the barrier, which must never run ahead of a create that
|
|
143
|
+
// could still land. A close that cannot prove that yet throws here and keeps the alias held.
|
|
144
|
+
if (a.delegatedHandle) {
|
|
145
|
+
a.delegatedHandle.stop({ graceful: true });
|
|
146
|
+
await this.awaitHandleExit(a.delegatedHandle);
|
|
147
|
+
}
|
|
148
|
+
// THE LOCAL FAMILY IS THIS PARTICIPANT'S, not the host's (#3055). The hosted enrollment wrote
|
|
149
|
+
// it here, so the host's release cannot remove it, and returning after the terminal request
|
|
150
|
+
// left every hosted seat's actor token, sentinel and health file on disk. It goes once the
|
|
151
|
+
// grant is released and the child is gone, by the same rule as the local arm below: every
|
|
152
|
+
// removal is attempted, and a failure keeps the name held instead of reaching the terminal.
|
|
153
|
+
const unshredded = [];
|
|
154
|
+
await this.shredUserSecrets(unshredded, a.secretPaths ?? agentLifecycleSecretFilePaths(this.workspaceRoot, this.space, a.name, a.lifecycleUid));
|
|
155
|
+
if (unshredded.length)
|
|
156
|
+
throw new Error(`could not shred "${a.name}": ${describeCleanupFailures(unshredded)}`);
|
|
157
|
+
await this.requestRetirement(a);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!this.auth)
|
|
161
|
+
return; // guaranteed by deprovision; re-checked for the deprovisionBroker narrowing
|
|
162
|
+
if (!this.userMode && !a.userOwner) {
|
|
163
|
+
// A STATIC lifecycle retires through the terminal barrier - freeze → head
|
|
164
|
+
// retiring → B1 ledger revoke → footprint cleanup (creds file + broker durables/ACL, INSIDE
|
|
165
|
+
// the barrier) → gate retired → head retired → alias free. The eviction step is the process
|
|
166
|
+
// kill the stop path already performed (static's best-effort eviction).
|
|
167
|
+
return this.driveStaticRetirement(a);
|
|
168
|
+
}
|
|
169
|
+
// Drop the local creds file FIRST + unconditionally - it is a usable identity on disk, useless for a
|
|
170
|
+
// departed agent, so it must not survive even if the broker teardown below fails or times out. The
|
|
171
|
+
// teardown mints its OWN deprovisioner cred (not this file), so removing it early is independent.
|
|
172
|
+
// Migrated kinds: the store delete is the authoritative removal; the rmSync clears the FS
|
|
173
|
+
// materialization (a byte-identical no-op under the local composition, real once the manager
|
|
174
|
+
// `secretStore` is a non-FS store).
|
|
175
|
+
//
|
|
176
|
+
// LIFECYCLE-OWNED (SPEC 13.1, the manager-local half): the family deleted here is the RECORDED
|
|
177
|
+
// one (spawn/adoption), else the lifecycle-keyed derivation for THIS uid - never a name-only
|
|
178
|
+
// derivation, so a stale/replayed teardown addresses only names a same-alias successor never
|
|
179
|
+
// uses. It deliberately CANNOT remove a name-keyed family it holds no record of (an operator's
|
|
180
|
+
// standing `cotal mint` cred, a seeded workstation cred, a pre-split leftover): deleting an
|
|
181
|
+
// unowned same-name file is the exact successor-clobber this ownership discipline removes.
|
|
182
|
+
const secrets = this.secrets;
|
|
183
|
+
const files = a.secretPaths ?? agentLifecycleSecretFilePaths(this.workspaceRoot, this.space, a.name, a.lifecycleUid);
|
|
184
|
+
// Every removal is attempted, and a failed one is thrown only after the broker teardown below,
|
|
185
|
+
// so a file fault cannot strand the agent's durables and ACL row on the broker.
|
|
186
|
+
const unshredded = [];
|
|
187
|
+
if (files.creds) {
|
|
188
|
+
const creds = files.creds;
|
|
189
|
+
await attemptCleanup(unshredded, `secret ${creds}`, () => secrets.delete(agentSecretKeyForFile(creds, this.space)));
|
|
190
|
+
await attemptCleanup(unshredded, `file ${creds}`, () => rmSync(creds, { force: true }));
|
|
191
|
+
}
|
|
192
|
+
if (a.userOwner) {
|
|
193
|
+
// USER MODE: this teardown IS revocation, not just footprint reduction - the ledger row is
|
|
194
|
+
// the agent's standing mint authority, so delete it (next exchange refused, next connect
|
|
195
|
+
// denied) and shred the secret/sentinel/health files. A copied actor token dies here; a
|
|
196
|
+
// still-LIVE connection ends at its bearer-bound JWT expiry (≤ the agent TTL).
|
|
197
|
+
await this.shredUserSecrets(unshredded, files);
|
|
198
|
+
// The ledger row IS the agent's STANDING mint authority (a different store from the auth-plane
|
|
199
|
+
// cred ledger the rail retirement covers): while it lives, a copied actor token can still mint a
|
|
200
|
+
// fresh connect credential. So a FAILED revoke must NOT be swallowed into a clean terminal (INT-2):
|
|
201
|
+
// mark the standing authority live on the hold so the retirement can never free the name (a freed
|
|
202
|
+
// name says "this lifecycle is fully gone" - false while the mint authority stands), and carry a
|
|
203
|
+
// legible operator copy. A retry re-drives this whole teardown (the same-name-spawn nudge routes
|
|
204
|
+
// through deprovision, not the rail alone), so the revoke is re-attempted, not stranded.
|
|
205
|
+
const holdRevoke = this.retiring.get(a.name);
|
|
206
|
+
if (holdRevoke && holdRevoke.target.lifecycleUid === a.lifecycleUid)
|
|
207
|
+
holdRevoke.standingAuthorityLive = true;
|
|
208
|
+
try {
|
|
209
|
+
await resolveAuthProvider().revokeAgent({
|
|
210
|
+
dir: userAuthStateDir(this.workspaceRoot, this.space),
|
|
211
|
+
owner: a.userOwner,
|
|
212
|
+
actor: a.name,
|
|
213
|
+
});
|
|
214
|
+
const done = this.retiring.get(a.name);
|
|
215
|
+
if (done && done.target.lifecycleUid === a.lifecycleUid)
|
|
216
|
+
done.standingAuthorityLive = false;
|
|
217
|
+
}
|
|
218
|
+
catch (e) {
|
|
219
|
+
const h = this.retiring.get(a.name);
|
|
220
|
+
if (h && h.target.lifecycleUid === a.lifecycleUid)
|
|
221
|
+
h.lastError = `the agent's standing mint authority could not be revoked (${rejectionText(e)}); the name stays held so a copied actor token cannot mint fresh credentials. NEXT: a same-name spawn re-drives the full teardown (including the revoke), or recover the auth state.`;
|
|
222
|
+
console.error(`revoke agent grant ${a.name}: ${rejectionText(e)}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const shredFailure = unshredded.length ? `could not shred "${a.name}": ${describeCleanupFailures(unshredded)}` : undefined;
|
|
226
|
+
try {
|
|
227
|
+
const res = await this.deprovisionBroker(a);
|
|
228
|
+
const h = this.retiring.get(a.name);
|
|
229
|
+
if (h && h.target.lifecycleUid === a.lifecycleUid)
|
|
230
|
+
h.lastResources = res;
|
|
231
|
+
}
|
|
232
|
+
catch (e) {
|
|
233
|
+
const h = this.retiring.get(a.name);
|
|
234
|
+
if (h && h.target.lifecycleUid === a.lifecycleUid) {
|
|
235
|
+
h.lastError = rejectionText(e);
|
|
236
|
+
if (e instanceof DeprovisionError)
|
|
237
|
+
h.lastResources = e.accounting;
|
|
238
|
+
}
|
|
239
|
+
if (shredFailure)
|
|
240
|
+
throw new Error(`${rejectionText(e)}; ${shredFailure}`, { cause: e });
|
|
241
|
+
throw e;
|
|
242
|
+
}
|
|
243
|
+
if (shredFailure)
|
|
244
|
+
throw new Error(shredFailure);
|
|
245
|
+
// After the footprint teardown, ask the AUTH plane to RETIRE the lifecycle over
|
|
246
|
+
// the auth endpoint rail. The rail re-checks the SERVE-ISSUANCE GATE at serve time (not the
|
|
247
|
+
// space-manager lease - that check was replaced in 02794b2f) and refuses unless the registration
|
|
248
|
+
// this request names belongs to our own principal; the terminal (or an already-retired answer)
|
|
249
|
+
// clears the name reservation. Failures keep the hold with
|
|
250
|
+
// their operator copy - legible, retryable, never a silent half-state.
|
|
251
|
+
await this.requestRetirement(a);
|
|
252
|
+
}
|
|
253
|
+
/** Request the auth-side retirement of a departed agent's lifecycle: an ephemeral
|
|
254
|
+
* `retirement-requester` credential (request + reply only), the generic `retireLifecycle` op,
|
|
255
|
+
* a STABLE opId (derived from the lifecycleUid, so every retry re-drives the SAME operation),
|
|
256
|
+
* and the four-outcome handling in operator vocabulary. */
|
|
257
|
+
async requestRetirement(a) {
|
|
258
|
+
if (!this.userMode)
|
|
259
|
+
return; // NEW-1: lifecycle retirement is a user-mesh concept; a static mint has no head to retire
|
|
260
|
+
// SINGLE-FLIGHT per (name, lifecycleUid) (audit #1): the detached deprovision call and every
|
|
261
|
+
// same-name-spawn nudge for THIS lifecycle share ONE in-flight retirement, so concurrent triggers
|
|
262
|
+
// never stack independent rail requests that dual-enter runAgentRetirementBarrier. Keyed by
|
|
263
|
+
// (name, uid), NOT name alone: driveRetirement clears the hold on rail ok but then yields at
|
|
264
|
+
// `nc.close()` with the flight still stored, so the alias can free and a SUCCESSOR (new uid) spawn.
|
|
265
|
+
// A name-only key would let that successor's own teardown JOIN the predecessor's still-pending
|
|
266
|
+
// flight and never send its OWN retirement - leaving the successor's lifecycle unretired. The uid in
|
|
267
|
+
// the key gives the successor a disjoint flight (mirrors {@link deprovisioningFlight}). A fresh
|
|
268
|
+
// trigger after settle re-drives (a still-present hold => retirement not yet confirmed).
|
|
269
|
+
const key = JSON.stringify([a.name, a.lifecycleUid]);
|
|
270
|
+
const inflight = this.retiringFlight.get(key);
|
|
271
|
+
if (inflight)
|
|
272
|
+
return inflight;
|
|
273
|
+
const flight = this.driveRetirement(a).finally(() => {
|
|
274
|
+
if (this.retiringFlight.get(key) === flight)
|
|
275
|
+
this.retiringFlight.delete(key);
|
|
276
|
+
});
|
|
277
|
+
this.retiringFlight.set(key, flight);
|
|
278
|
+
return flight;
|
|
279
|
+
}
|
|
280
|
+
/** The rail round-trip for one retirement (wrapped by {@link requestRetirement}'s single-flight). */
|
|
281
|
+
async driveRetirement(a) {
|
|
282
|
+
if (!this.auth && !this.remoteAuthority)
|
|
283
|
+
return;
|
|
284
|
+
const held = this.retiring.get(a.name);
|
|
285
|
+
const target = parsePrincipalKey(a.id);
|
|
286
|
+
if (!target) {
|
|
287
|
+
if (held)
|
|
288
|
+
held.lastError = "the target principal could not be derived; the retirement was not requested";
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
// The SERVE identity, not the endpoint identity, is who this request speaks as (#549). The field
|
|
292
|
+
// is declared `!:`, which asserts to the type system what the ordering happens to provide, so it
|
|
293
|
+
// is read here as what it actually is. On today's ordering this guard cannot fire: `start()`
|
|
294
|
+
// assigns the identity before it connects anything, and a retirement needs an agent that only a
|
|
295
|
+
// started manager can hold. It is kept as a fail-closed assertion rather than a live face,
|
|
296
|
+
// because the alternative is carrying `undefined` into the caller triple and surfacing the
|
|
297
|
+
// result as "the rail could not be reached", which would name the wrong cause.
|
|
298
|
+
const serveIdentity = this.managerServeIdentity;
|
|
299
|
+
if (!serveIdentity?.id) {
|
|
300
|
+
if (held)
|
|
301
|
+
held.lastError = `the retirement was NOT requested: this manager has no serve identity yet, so it cannot speak as the registered serving instance. The despawn stopped "${a.name}" and the name stays held. NEXT: let the manager finish registering, then re-attempt the same-name spawn to re-drive the teardown.`;
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const reportFailure = (why, unconfirmed = false) => {
|
|
305
|
+
// An orphan rollback owns no name hold. Re-read after the rail awaits so a successor's
|
|
306
|
+
// hold never receives the predecessor's error or supplies its despawn/retry claims.
|
|
307
|
+
const current = this.retiring.get(a.name);
|
|
308
|
+
const held = current?.target.lifecycleUid === a.lifecycleUid ? current : undefined;
|
|
309
|
+
const copy = !unconfirmed ? why : held
|
|
310
|
+
? `the despawn stopped "${a.name}", but the retirement's completion could NOT be confirmed (${why}). The name stays held - not failed, not done - and a same-name spawn re-drives the same teardown; the auth service also finishes any started retirement on its next boot. NEXT: if the auth rail stays unreachable, recover the stack (\`cotal supervise\`), then re-attempt the same-name spawn.`
|
|
311
|
+
: `the retirement's completion could NOT be confirmed (${why}). No hold reserves the name for this lifecycle.`;
|
|
312
|
+
if (held)
|
|
313
|
+
held.lastError = copy;
|
|
314
|
+
const prefix = held ? `despawn ${a.name}` : `retire ${a.name}: lifecycle ${a.lifecycleUid}`;
|
|
315
|
+
console.error(`${prefix}: ${copy}`);
|
|
316
|
+
};
|
|
317
|
+
try {
|
|
318
|
+
// The caller triple and the TARGET are both grant-pinned now (#350): the `handle` target
|
|
319
|
+
// rides the subject, so this ephemeral credential can ask to retire exactly this
|
|
320
|
+
// incarnation and nothing else.
|
|
321
|
+
//
|
|
322
|
+
// THE TRIPLE IS THE SERVE PRINCIPAL, and it has to be (#549). The auth rail authorizes this
|
|
323
|
+
// request by comparing the caller's `<owner>.<actor>` against the serve issuance gate's bound
|
|
324
|
+
// principal, and that gate is opened with `principalKey(DEV_OWNER, serveIdentity.id)` (see the
|
|
325
|
+
// registration block). Deriving the caller from `ep.ref().id` instead put the manager's
|
|
326
|
+
// ENDPOINT identity nkey on the wire, which is a different, equally real identity of the same
|
|
327
|
+
// manager, so the comparison was unsatisfiable and EVERY user-mesh retirement was refused as a
|
|
328
|
+
// full no-op. Measured before the fix: 8 refusals in one suite run across 5 agents, with the
|
|
329
|
+
// epoch and the instance id both matching and only the principal disagreeing.
|
|
330
|
+
//
|
|
331
|
+
// Both halves come from the gate's own sources rather than from `ep.ref()`: `DEV_OWNER` is
|
|
332
|
+
// hard-coded at the gate site, so taking the owner from `ep.ref().id` would re-open the same
|
|
333
|
+
// mismatch in the owner half the moment a manager ran under a user-shaped identity. This is
|
|
334
|
+
// also the more honest attribution: the authority being exercised is "I am the registered
|
|
335
|
+
// serving instance", which is exactly what the gate records.
|
|
336
|
+
const caller = this.remoteAuthority
|
|
337
|
+
? { owner: this.remoteAuthority.owner, actor: this.remoteAuthority.actors.serve, uid: this.managerLifecycleUid }
|
|
338
|
+
: { owner: DEV_OWNER, actor: serveIdentity.id, uid: this.managerLifecycleUid };
|
|
339
|
+
const requestIdentity = newIdentity();
|
|
340
|
+
const retirementTarget = { owner: target.owner, actor: target.actor, lifecycleUid: a.lifecycleUid };
|
|
341
|
+
const opId = managedRetirementOpId(a.lifecycleUid);
|
|
342
|
+
const serveEpoch = this.deps.serveEpoch() ?? 0;
|
|
343
|
+
const creds = this.remoteAuthority
|
|
344
|
+
? await this.remoteAuthority.mintRetirementRequester({ identity: requestIdentity, target: retirementTarget, opId, serveEpoch })
|
|
345
|
+
: await mintCreds(this.auth, requestIdentity, "retirement-requester", {
|
|
346
|
+
retirementRequester: { ...caller, target: retirementTarget },
|
|
347
|
+
});
|
|
348
|
+
// The requester grant subscribes `_INBOX_<id>.>` only (provision.ts): the endpoint path's
|
|
349
|
+
// JetStream API requests (the contract-store read inside resolveService) must reply under it, not under the client default `_INBOX.`.
|
|
350
|
+
const nc = await this.dial({ authenticator: credsAuthenticator(new TextEncoder().encode(creds)), inboxPrefix: `_INBOX_${requestIdentity.id}`, maxReconnectAttempts: 0 });
|
|
351
|
+
try {
|
|
352
|
+
// The service resolves FRESH on every attempt (never cached on `this`): a plane restart
|
|
353
|
+
// mid-despawn then lands on the new epoch through an ordinary resolve, rather than a
|
|
354
|
+
// caller pinned to a now-superseded incarnation.
|
|
355
|
+
const service = await resolveService(nc, this.space, AUTH_ENDPOINT, caller, { deadlineMs: 10_000, commands: [EP_CMD_RETIRE_LIFECYCLE] });
|
|
356
|
+
// The TARGET rides the invoke's own target (authz mode `exact`, arity 3) - broker-enforced,
|
|
357
|
+
// and pinned by the grant minted above, so it is not a body claim the caller can vary.
|
|
358
|
+
const attributed = await invokeCommand(nc, this.space, service, EP_CMD_RETIRE_LIFECYCLE, {
|
|
359
|
+
opId,
|
|
360
|
+
serveEndpoint: MANAGER_ENDPOINT, serveInstanceId: this.managerInstanceId, serveEpoch,
|
|
361
|
+
}, {
|
|
362
|
+
target: { mode: "exact", owner: target.owner, actor: target.actor, lifecycleUid: a.lifecycleUid },
|
|
363
|
+
deadlineMs: 20_000,
|
|
364
|
+
});
|
|
365
|
+
const r = attributed.reply;
|
|
366
|
+
if (r.ok) {
|
|
367
|
+
this.confirmRetirement(a);
|
|
368
|
+
}
|
|
369
|
+
else if (r.error?.code === "expired") {
|
|
370
|
+
// A stale-epoch refusal cannot confirm retirement. The retry copy follows the
|
|
371
|
+
// current lifecycle's hold, which an orphan rollback does not create.
|
|
372
|
+
reportFailure(r.error.message, true);
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
// The rail's refusal is already the operator copy (lease-loss/stale/foreign-op faces,
|
|
376
|
+
// full-no-op statements included) - surface it INTACT, never flattened.
|
|
377
|
+
const message = r.error?.message ?? "the auth service refused the retirement without a reason";
|
|
378
|
+
reportFailure(message);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
finally {
|
|
382
|
+
await nc.close().catch(() => { });
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
catch (e) {
|
|
386
|
+
reportFailure(rejectionText(e), true);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
/** Apply one terminal retirement answer. The predecessor coordinate is recorded only when the
|
|
390
|
+
* answer clears this exact lifecycle's hold, never for an ABA-late answer or an incomplete hosted
|
|
391
|
+
* teardown whose standing authority still lives. */
|
|
392
|
+
confirmRetirement(a) {
|
|
393
|
+
// CAS the hold clear (audit #1 ABA): free the alias ONLY if the current hold is still THIS
|
|
394
|
+
// lifecycle's. A late reply for a retired predecessor must never clear a successor's newer hold.
|
|
395
|
+
const cur = this.retiring.get(a.name);
|
|
396
|
+
// The record names this incarnation only, so a confirmed retirement removes it and a successor's
|
|
397
|
+
// record stays. A mint authority that is still live keeps the record: the seat is gone, and the
|
|
398
|
+
// next manager has to be able to re-drive the revoke.
|
|
399
|
+
if (!(cur?.target.lifecycleUid === a.lifecycleUid && cur.standingAuthorityLive))
|
|
400
|
+
this.dropSeatRecord(a);
|
|
401
|
+
if (cur && cur.target.lifecycleUid === a.lifecycleUid) {
|
|
402
|
+
if (cur.standingAuthorityLive) {
|
|
403
|
+
// INT-2: the auth-plane lifecycle retired, but the manager-side STANDING mint authority is
|
|
404
|
+
// not yet revoked. A copied token could still mint, so neither free the alias nor classify
|
|
405
|
+
// its presence as a completed predecessor.
|
|
406
|
+
console.error(`despawn ${a.name}: the auth-plane lifecycle retired, but the standing mint authority is not yet revoked; the name stays held. ${cur.lastError ?? ""}`);
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
this.confirmedRetiredPredecessors.set(a.name, { principal: a.id, lifecycleUid: a.lifecycleUid });
|
|
410
|
+
this.retiring.delete(a.name);
|
|
411
|
+
console.error(`despawn ${a.name}: the agent's retirement completed; the name is free for reuse`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
else if (cur) {
|
|
415
|
+
console.error(`despawn ${a.name}: retirement confirmed for a prior lifecycle of "${a.name}"; the current hold is left intact`);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
// No hold stands, as after an orphaned spawn's rollback: that lifecycle was never despawned and
|
|
419
|
+
// has no successor, so this line names neither.
|
|
420
|
+
console.error(`retire ${a.name}: lifecycle ${a.lifecycleUid} retired; the name had no hold to clear`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
/** The teardown's ASYNC BROKER PHASE: mint the ephemeral target-pinned deprovisioner cred and
|
|
424
|
+
* delete the agent's broker footprint (dm_/dlv_ durables + read-ACL row). Split from
|
|
425
|
+
* {@link deprovision} because it runs LAST in the ordered teardown chain - after the creds/secret
|
|
426
|
+
* shred and the awaited ledger revoke, which precede it in that same single-flighted chain (the
|
|
427
|
+
* revoke is awaited and can be deliberately slow, so it is not merely a synchronous prefix). The name
|
|
428
|
+
* is NOT freed while any teardown phase is still in flight - the hold clears only after the
|
|
429
|
+
* standing-authority revoke AND the lifecycle retirement both confirm (see {@link driveRetirement}) -
|
|
430
|
+
* but the deletes here are still lifecycle-uid-pinned so even a replayed/stale teardown can never
|
|
431
|
+
* reach a same-name successor's footprint (its names embed a different uid). Each call reports its
|
|
432
|
+
* own accounting: the return value, or the {@link DeprovisionError} it throws once the deletes ran. */
|
|
433
|
+
async deprovisionBroker(a) {
|
|
434
|
+
// LIFECYCLE-PINNED (SPEC 13.1): both the credential's exact-name grants and the delete names
|
|
435
|
+
// carry a.lifecycleUid, so a stale/replayed teardown for this retired incarnation is broker-denied
|
|
436
|
+
// against a same-name successor's footprint (its names embed a different uid).
|
|
437
|
+
// Durable membership rows are lifecycle-keyed per concrete channel. Start with the launch's
|
|
438
|
+
// concrete read channels, then include wildcard-covered and unnamed channels from the inventory.
|
|
439
|
+
const memberChannels = new Set((a.launch?.allowSubscribe ?? []).filter(isConcreteChannel));
|
|
440
|
+
// Fence the lifecycle before its inventory is read: its read-ACL row narrowed to no reads, which
|
|
441
|
+
// every durable join re-reads around the row it writes, so a join the inventory does not see
|
|
442
|
+
// removes its own row. A fence that cannot be written makes the inventory incomplete.
|
|
443
|
+
const unfenced = await this.fenceRetiringAcl(a);
|
|
444
|
+
// Complete the set from the delivery daemon's lifecycle-exact inventory, which covers rows on
|
|
445
|
+
// wildcard-granted channels and teardowns that carry no launch spec. An inventory that cannot be
|
|
446
|
+
// read leaves those rows RETAINED and says so; it never widens the delete beyond exact keys.
|
|
447
|
+
const listed = await this.lifecycleMembershipInventory(a);
|
|
448
|
+
const inventory = unfenced === undefined ? listed : { ...listed, complete: false, reason: `the ACL fence was not written (${unfenced})${listed.complete ? "" : `; ${listed.reason}`}` };
|
|
449
|
+
for (const ch of inventory.channels)
|
|
450
|
+
memberChannels.add(ch);
|
|
451
|
+
if (!inventory.complete)
|
|
452
|
+
console.error(`deprovision ${a.name} (${a.id}): membership inventory incomplete (${inventory.reason}); rows on channels outside its launch policy stay RETAINED for uid ${a.lifecycleUid}`);
|
|
453
|
+
const creds = await mintCreds(this.auth, newIdentity(), "deprovisioner", {
|
|
454
|
+
deprovisionTarget: { principal: a.id, lifecycleUid: a.lifecycleUid, memberChannels: [...memberChannels] },
|
|
455
|
+
});
|
|
456
|
+
// Bound the detached broker teardown so a wedged broker can't leave the deprovision promise pending
|
|
457
|
+
// forever with no log - the timeout rejects into freeSlot's fail-loud `.catch` (paired with the
|
|
458
|
+
// helper's own fail-fast connect). The durables/ACL row still fall to space teardown as a backstop.
|
|
459
|
+
const accounting = await this.deps.brokerTeardown(deprovisionAgent({
|
|
460
|
+
servers: this.servers ?? DEFAULT_SERVER,
|
|
461
|
+
space: this.space,
|
|
462
|
+
targetId: a.id,
|
|
463
|
+
lifecycleUid: a.lifecycleUid,
|
|
464
|
+
memberChannels: [...memberChannels],
|
|
465
|
+
creds,
|
|
466
|
+
}), `deprovision ${a.name} (${a.id}): broker teardown timed out`);
|
|
467
|
+
if (!inventory.complete)
|
|
468
|
+
throw new DeprovisionError(`membership inventory incomplete (${inventory.reason}); rows on channels outside its launch policy stay RETAINED for uid ${a.lifecycleUid}`, accounting);
|
|
469
|
+
return accounting;
|
|
470
|
+
}
|
|
471
|
+
/** A cleanup spawned by accepted active-mode work is part of that work for maintenance draining,
|
|
472
|
+
* even where the ordinary control reply remains fire-and-forget. */
|
|
473
|
+
trackDeprovision(a, context = "") {
|
|
474
|
+
const release = this.deps.trackLifecycle();
|
|
475
|
+
void this.deprovision(a)
|
|
476
|
+
.catch((e) => console.error(`deprovision${context ? ` ${context}` : ""} ${a.name} (${a.id}): ${rejectionText(e)}`))
|
|
477
|
+
.finally(release);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
//# sourceMappingURL=retirement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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AO,UAAU,CAAC;IACpB,CAAC;IAED;wEACoE;IACpE,gBAAgB,CAAC,CAAiB,EAAE,OAAO,GAAG,EAAE;QAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;QAC3C,KAAK,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;aACrB,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,MAAM,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;aAClH,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type CotalEndpoint, type LaunchSpec, type LifecycleStateTransport, type SecretStore, type StaticManagedSlotRow } from "@cotal-ai/core";
|
|
2
|
+
import { retainConnectorSeat } from "@cotal-ai/workspace";
|
|
3
|
+
import { type AgentHandle, type Runtime } from "./runtime/index.js";
|
|
4
|
+
import type { RuntimeReference } from "@cotal-ai/core";
|
|
5
|
+
import type { ManagedAgent, ManagerResumeAgent, SupervisedRestart } from "./manager.js";
|
|
6
|
+
import { type SeatRecord } from "./resume.js";
|
|
7
|
+
/** Manager-owned authority and lifecycle operations used while recording and recovering seats. */
|
|
8
|
+
export interface SeatCustodyDeps {
|
|
9
|
+
staticAuth: () => boolean;
|
|
10
|
+
workspaceRoot: () => string;
|
|
11
|
+
space: () => string;
|
|
12
|
+
instanceId: () => string;
|
|
13
|
+
endpoint: () => CotalEndpoint;
|
|
14
|
+
secrets: () => SecretStore;
|
|
15
|
+
eventPayloadsWithheld: () => boolean;
|
|
16
|
+
runtimeFor: (kind: string) => Runtime;
|
|
17
|
+
requiredRuntime: () => Runtime;
|
|
18
|
+
withLifecycleExecutor: <T>(pin: {
|
|
19
|
+
owner: string;
|
|
20
|
+
actor: string;
|
|
21
|
+
lifecycleUid: string;
|
|
22
|
+
alias: string;
|
|
23
|
+
}, fn: (t: LifecycleStateTransport) => Promise<T>) => Promise<T>;
|
|
24
|
+
watchConnectorHolder: (handle: AgentHandle, holder: ReturnType<typeof retainConnectorSeat>) => void;
|
|
25
|
+
resumeEntryOf: (agent: ManagedAgent) => ManagerResumeAgent;
|
|
26
|
+
inventoryReferenceError: (entry: ManagerResumeAgent) => string | undefined;
|
|
27
|
+
registerAgent: (name: string, agent: ManagedAgent) => void;
|
|
28
|
+
agentFor: (name: string) => ManagedAgent | undefined;
|
|
29
|
+
watchExit: (agent: ManagedAgent) => void;
|
|
30
|
+
bindOnceSeat: (agent: ManagedAgent) => Promise<void>;
|
|
31
|
+
renewManagedStaticCred: (agent: ManagedAgent) => Promise<void>;
|
|
32
|
+
resumeSupervisedAgent: (entry: ManagerResumeAgent, supervised: SupervisedRestart) => Promise<import("@cotal-ai/core").ControlReply>;
|
|
33
|
+
}
|
|
34
|
+
/** Seat custody references, successor records, and identity-checked recovery for one manager. */
|
|
35
|
+
export declare class SeatCustody {
|
|
36
|
+
private readonly deps;
|
|
37
|
+
constructor(deps: SeatCustodyDeps);
|
|
38
|
+
/** Re-record the custody reference of a managed agent's CURRENT handle on its active slot: a
|
|
39
|
+
* same-lifecycle restart or a resume binds a new custody under the old uid, and the successor's
|
|
40
|
+
* reap must address the live one. Static auth only; a runtime without durable custody records
|
|
41
|
+
* nothing (there is nothing to reap by reference). */
|
|
42
|
+
recordSlotRuntime(a: ManagedAgent): Promise<void>;
|
|
43
|
+
/** Record one custody reference on an agent's ACTIVE slot. Split from {@link recordSlotRuntime}
|
|
44
|
+
* so a restart or a resume can record the reference it RESERVED before spawning, while no
|
|
45
|
+
* handle exists yet. Static auth only; a runtime without durable custody reserves nothing.
|
|
46
|
+
* Throws when the slot does not take the reference: a slot left on the previous one reaps that
|
|
47
|
+
* seat, already gone, so a successor would retire the lifecycle over the new one. */
|
|
48
|
+
recordSlotCustody(a: {
|
|
49
|
+
name: string;
|
|
50
|
+
id: string;
|
|
51
|
+
lifecycleUid: string;
|
|
52
|
+
}, runtime: RuntimeReference): Promise<void>;
|
|
53
|
+
/** Mint the custody reference for a seat this manager is about to spawn, BEFORE the processes
|
|
54
|
+
* exist. Absent for a runtime with no durable custody (there is nothing a successor could reap
|
|
55
|
+
* by reference), which is the only case that still spawns unreserved. */
|
|
56
|
+
reserveCustody(runtime: Runtime): RuntimeReference | undefined;
|
|
57
|
+
/** Spawn under a reserved reference and prove the runtime honoured it. A runtime that minted its
|
|
58
|
+
* own id instead would leave every durable record addressing a seat that does not exist, so the
|
|
59
|
+
* mismatch tears the new seat down and throws rather than returning an unaddressable handle. */
|
|
60
|
+
spawnCustodied(runtime: Runtime, name: string, spec: LaunchSpec, cwd: string, reserved: RuntimeReference | undefined): Promise<AgentHandle>;
|
|
61
|
+
/** Persist what a successor needs to take this seat back if this process ends without stopping
|
|
62
|
+
* it: a supervised seat, which a successor restarts (#4094), and a seat on a runtime that can adopt
|
|
63
|
+
* it by reference, which a successor adopts while it still runs (#4095). Static meshes only: a
|
|
64
|
+
* successor finds the seat through its active slot row, and only a static mesh keeps one. Throws
|
|
65
|
+
* when a supervised seat's entry could not be resumed, because a policy this host cannot keep
|
|
66
|
+
* across a manager restart is one it cannot enforce. */
|
|
67
|
+
recordSeat(a: ManagedAgent): void;
|
|
68
|
+
/** Bring a running seat's record up to date after its credential or restart count changed. A
|
|
69
|
+
* record that cannot be rewritten is removed, so a successor retires the seat rather than taking
|
|
70
|
+
* it back from a stale one. */
|
|
71
|
+
refreshSeatRecord(a: ManagedAgent): void;
|
|
72
|
+
dropSeatRecord(a: {
|
|
73
|
+
name: string;
|
|
74
|
+
lifecycleUid: string;
|
|
75
|
+
}): void;
|
|
76
|
+
/** The seat record behind one active slot this instance owns, when it describes that exact
|
|
77
|
+
* incarnation on this runtime. Anything else is left to the ordinary terminal. */
|
|
78
|
+
seatRecordFor(row: StaticManagedSlotRow): SeatRecord | undefined;
|
|
79
|
+
/** Take back a seat that outlived its manager (#4095): the runtime reattaches to the exact seat
|
|
80
|
+
* the slot names, and this manager holds it under the record's identity and launch, with no
|
|
81
|
+
* relaunch. Returns why it could not, and the caller then retires the lifecycle, which reaps the
|
|
82
|
+
* seat by the same reference. */
|
|
83
|
+
adoptSeat(row: StaticManagedSlotRow, record: SeatRecord): Promise<string | undefined>;
|
|
84
|
+
/** Restart a supervised seat whose manager ended without stopping it (#4094), as one restart of
|
|
85
|
+
* its own policy. It goes through the resume launch, so the seat comes back under the same name,
|
|
86
|
+
* lifecycle uid, credential, persona and cwd, and a pending turn addressed to it is served to it.
|
|
87
|
+
* Returns why it could not, and the caller then retires the lifecycle. */
|
|
88
|
+
restartSupervisedSeat(row: StaticManagedSlotRow, record: SeatRecord): Promise<string | undefined>;
|
|
89
|
+
/** The terminal's process step: an orphan (no live handle in THIS process) is reaped by the custody
|
|
90
|
+
* reference the slot recorded, before its footprint goes. A successor must never retire a
|
|
91
|
+
* lifecycle and free its alias while the predecessor's seat process is still running outside
|
|
92
|
+
* every manager. The runtime verifies the process identity against its own record and proves the
|
|
93
|
+
* exit; a runtime that cannot reap refuses by name and the lifecycle stays terminalizing. A row
|
|
94
|
+
* with no recorded reference has nothing this manager can address. */
|
|
95
|
+
reapOrphanSeat(a: {
|
|
96
|
+
name: string;
|
|
97
|
+
runtime?: RuntimeReference;
|
|
98
|
+
}): Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=seat-custody.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seat-custody.d.ts","sourceRoot":"","sources":["../src/seat-custody.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,KAAK,WAAW,EAAE,KAAK,oBAAoB,EAC/G,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAwD,mBAAm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