@cotal-ai/manager 0.171.1 → 0.171.2
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/manager.d.ts +21 -107
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +80 -507
- package/dist/manager.js.map +1 -1
- package/dist/run-hosting.d.ts +5 -2
- package/dist/run-hosting.d.ts.map +1 -1
- package/dist/run-hosting.js +55 -16
- package/dist/run-hosting.js.map +1 -1
- package/dist/seat-launch.d.ts +1 -1
- package/dist/seat-launch.d.ts.map +1 -1
- package/dist/seat-launch.js +4 -2
- package/dist/seat-launch.js.map +1 -1
- package/dist/seat-stop.d.ts +232 -0
- package/dist/seat-stop.d.ts.map +1 -0
- package/dist/seat-stop.js +552 -0
- package/dist/seat-stop.js.map +1 -0
- package/dist/service-adapter.d.ts.map +1 -1
- package/dist/service-adapter.js +8 -5
- package/dist/service-adapter.js.map +1 -1
- package/package.json +12 -12
package/dist/manager.js
CHANGED
|
@@ -7,7 +7,7 @@ import { existsSync, lstatSync, readFileSync, readdirSync, realpathSync, rmSync
|
|
|
7
7
|
import { join, resolve } from "node:path";
|
|
8
8
|
import { parse as parseYaml } from "yaml";
|
|
9
9
|
import Headless from "@xterm/headless";
|
|
10
|
-
import { CotalEndpoint, canonicalJson, copyPersonaEndpoints, lowerPersonaEndpoints, parsePersonaEndpoints, accountFromCreds, credsClaims, DEFAULT_SERVER, DEV_OWNER, MANAGER_LEASE_RENEW_MS, STANDING_RENEWABLE_TTL_SEC, discardLaunchArtifacts, injectedSecretStoreIdentity, agentFilePath,
|
|
10
|
+
import { CotalEndpoint, canonicalJson, copyPersonaEndpoints, lowerPersonaEndpoints, parsePersonaEndpoints, accountFromCreds, credsClaims, DEFAULT_SERVER, DEV_OWNER, MANAGER_LEASE_RENEW_MS, STANDING_RENEWABLE_TTL_SEC, discardLaunchArtifacts, injectedSecretStoreIdentity, agentFilePath, dialerFor, connectorServers, spawnEnvAllow, idFromCreds, identityFromCreds, inspectCredHealth, composeWirePersona, loadAgentFile, listPersonaCatalog, personaCatalogDescription, personaCatalogReadable, loadCotalConfig, mintCreds, bindIssuedStores, mintLifecycleUid, newIdentity, oneLine, parsePrincipalKey, principalKey, probeConnect, registry, resolveAuthProvider, saveAgentFile, capabilityWithin, } from "@cotal-ai/core";
|
|
11
11
|
import { retainConnectorSeat } from "@cotal-ai/workspace";
|
|
12
12
|
import { logicalExecutionEntry, OFFICIAL_CONNECTORS } from "@cotal-ai/workspace";
|
|
13
13
|
import { agentAuthState, agentCredsDir, agentLifecycleSecretFilePaths, agentSecretFilePaths, agentSecretKeyForFile, authDir, claimIdentityRecord, connectorInstallHint, DEFAULT_SEAT_CAP, extensionConnectors, findCotalRoot, getSpaceAuth, hasUserAuthState, loadExtensionsManifest, loadManagerInstanceIdentity, loadMeshes, localTrustOfSpace, manifestExtensionNames, materializeFromManifest, resolveOnPath, runtimeInstallHint, createManagerInstanceIdentity, spaceKey, userAuthStateDir, workspaceSecretStore } from "@cotal-ai/workspace";
|
|
@@ -26,15 +26,15 @@ export { ManagerInstanceLeaseHeld } from "./lease-keeper.js";
|
|
|
26
26
|
import { SessionRecovery } from "./session-recovery.js";
|
|
27
27
|
import { SeatCustody, watchConnectorHolder } from "./seat-custody.js";
|
|
28
28
|
import { GoalWriter } from "./goal-writer.js";
|
|
29
|
+
import { DEPROVISION_TIMEOUT_MS, SeatStop } from "./seat-stop.js";
|
|
29
30
|
import { CredentialRenewal, credRenewIntervalMs, REMOTE_STANDING_BUDGET_MS, remoteStandingTimeLeft, sameStrings } from "./credential-renewal.js";
|
|
30
31
|
import { SeatLaunch, foreignEventChannels, userMeshEndpointsRefusal } from "./seat-launch.js";
|
|
31
32
|
import { withTimeout } from "./manager-timeout.js";
|
|
32
33
|
import { GateReconcileRefused, reconcileEndpointGate } from "./reconcile-gate.js";
|
|
33
|
-
import { inlineSnapshotPath, launchSpecForRun, materializePersona, launchAgentToStartOpts,
|
|
34
|
+
import { inlineSnapshotPath, launchSpecForRun, materializePersona, launchAgentToStartOpts, parseLaunchSpec, persistLaunchSpec } from "./launch.js";
|
|
34
35
|
import { authorizeLaunch, authorizeNamedControl } from "./authorize.js";
|
|
35
|
-
import { controlShutdown } from "./control-shutdown.js";
|
|
36
36
|
import { RunHosting, servedRequestSubject } from "./run-hosting.js";
|
|
37
|
-
import { rejectionText, attemptCleanup
|
|
37
|
+
import { rejectionText, attemptCleanup } from "@cotal-ai/core";
|
|
38
38
|
import { MAX_AGENTS, parseResumeCommitArgs, parseResumeControlArgs, parseResumeFinalizeArgs, readReleasedSeatReference, readSeatRecord, writeReleasedSeatReference, writeSeatRecord } from "./resume.js";
|
|
39
39
|
import { TranscriptReceiver } from "./transcript-receive.js";
|
|
40
40
|
// The static §13.1 lifecycle executor: the shared grammar/stores from core plus the
|
|
@@ -49,7 +49,7 @@ import { ManagerSessionPlane } from "./session/index.js";
|
|
|
49
49
|
// The manager as an ordinary v0.4 `service` endpoint — the §13.1
|
|
50
50
|
// endpoint-serve credential subsystem (gate provisioning, registration barrier, mint fence) plus
|
|
51
51
|
// the register/authorize/serve seams, all driven over a scoped one-shot executor connection.
|
|
52
|
-
import { epgateKey, parseEndpointGate, readEndpointGateGeneration, deregisterServiceInstance, bindGoal, createGoal,
|
|
52
|
+
import { epgateKey, parseEndpointGate, readEndpointGateGeneration, deregisterServiceInstance, bindGoal, createGoal, commitGoalResult, goalAlreadyTerminal, settleGoalUncertain, readGoalResult, readGoalSpec, recordGoalIndex, readGoalIndex, clearGoalIndex, listGoalIndex, MAX_SCHEDULE_MS, goalRefOf, turnNoticeSubject, submissionFingerprint, EpEnvelopeError, lifecycleBlocked, lifecycleBlockedFrom } from "@cotal-ai/core";
|
|
53
53
|
import { MANAGER_ENDPOINT, managerCommandDefs } from "./manager-service-contract.js";
|
|
54
54
|
import { measureManagerVitals } from "./vitals.js";
|
|
55
55
|
import { staticLifecycleTransport, recordSlotCredential, appendStaticCredentialRow, ownedBySibling, observeStaticSlot, listStaticSlotObservations, renderStaticSlotObservation, StaticSlotReadError, STATIC_SLOT_READ_FAILED_DETAIL, } from "./static-lifecycle.js";
|
|
@@ -85,11 +85,6 @@ const LATE_JOIN_POLL_MS = 1_000;
|
|
|
85
85
|
* must run without exiting before it is ready: long enough that a harness refusing its arguments
|
|
86
86
|
* exits first and is reported as failed. */
|
|
87
87
|
const OPERATOR_READINESS_MS = 3_000;
|
|
88
|
-
/** Upper bound on a detached agent-exit deprovision (#159 B2). A wedged broker must not leave the
|
|
89
|
-
* fire-and-forget teardown pending forever with no log — past this it rejects into freeSlot's fail-loud
|
|
90
|
-
* `.catch`. Generous over the helper's 5s connect timeout to allow the two consumer-deletes + ACL purge
|
|
91
|
-
* + drain on a healthy-but-slow broker. */
|
|
92
|
-
const DEPROVISION_TIMEOUT_MS = 15_000;
|
|
93
88
|
/** At most this many retirements run at once (#4965). A retirement dials up to four fresh broker
|
|
94
89
|
* connections in turn and queues an eviction and an inventory on the delivery daemon's admin rail,
|
|
95
90
|
* each against a fixed deadline. A stop that started all 50 seats' retirements together lost most of
|
|
@@ -181,50 +176,6 @@ function failedTerminal(error, source) {
|
|
|
181
176
|
function bearerEntryArgv() {
|
|
182
177
|
return [process.execPath, ...process.execArgv, realpathSync(process.argv[1])];
|
|
183
178
|
}
|
|
184
|
-
/** Operator-facing phrasing per cause. Kept beside the union so adding a member without a sentence
|
|
185
|
-
* is a type error rather than a blank in the log. The stop family's sentences carry the principal
|
|
186
|
-
* from the cause, so they render through {@link STOP_CAUSE_TEXT} under the same exhaustive-Record
|
|
187
|
-
* discipline: a new stop kind without a renderer is a type error too. */
|
|
188
|
-
const FREE_SLOT_CAUSE_TEXT = {
|
|
189
|
-
"process-exit": "its own process exited and this manager did not stop it",
|
|
190
|
-
"pi-crash-loop": "this manager retired it after a Pi crash loop",
|
|
191
|
-
"pi-recovery-failed": "this manager retired it after Pi session recovery failed",
|
|
192
|
-
"supervise-crash-loop": "this manager retired it after its supervise restart budget was spent",
|
|
193
|
-
"supervise-recovery-failed": "this manager retired it after a supervised restart failed",
|
|
194
|
-
"session-bind-failed": "this manager stopped it: its host session could not be bound at launch",
|
|
195
|
-
"resume-session-rebind-failed": "this manager stopped it: its host session could not be rebound on resume",
|
|
196
|
-
"carried-fork-refused": "this manager stopped it: it recorded no fork of the carried transcript",
|
|
197
|
-
"resume-custody-unrecorded": "this manager stopped it: its custody reference could not be recorded on resume",
|
|
198
|
-
"supervise-record-failed": "this manager stopped it: its supervise policy could not be recorded for a manager restart",
|
|
199
|
-
"inline-snapshot-changed": "this manager retired it instead of restarting it: its inline persona snapshot changed after launch",
|
|
200
|
-
};
|
|
201
|
-
/** The stop family's sentences — the same job {@link FREE_SLOT_CAUSE_TEXT} does for the string
|
|
202
|
-
* causes, beside it so both stay the single place a cause becomes a sentence. A requested stop's
|
|
203
|
-
* sentence embeds the authenticated principal and a recursive reap's embeds the parent that
|
|
204
|
-
* left, so they cannot sit in a static Record keyed by kind; this exhaustive switch is their
|
|
205
|
-
* single home, and the `satisfies never` default keeps the discipline: a new stop kind without a
|
|
206
|
-
* sentence is a type error rather than a blank in the log. */
|
|
207
|
-
function stopCauseText(cause) {
|
|
208
|
-
switch (cause.kind) {
|
|
209
|
-
case "stopped-requested": return `this manager stopped it at ${cause.requester}'s request`;
|
|
210
|
-
case "stopped-self": return "it stopped itself (self-stop)";
|
|
211
|
-
case "stopped-reap": return `this manager stopped it because its parent ${cause.parent} left (recursive reap)`;
|
|
212
|
-
case "stopped-shutdown": return "this manager stopped it on manager shutdown";
|
|
213
|
-
case "stopped-once": return `this manager stopped it: its once task ended (${cause.reason})`;
|
|
214
|
-
default: return cause;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/** The reason a once task is cancelled with when a stop of this kind ends its seat first. */
|
|
218
|
-
function onceStopReason(cause) {
|
|
219
|
-
switch (cause.kind) {
|
|
220
|
-
case "stopped-requested": return "despawned";
|
|
221
|
-
case "stopped-self": return "stopped-itself";
|
|
222
|
-
case "stopped-reap": return "parent-left";
|
|
223
|
-
case "stopped-shutdown": return "manager-shutdown";
|
|
224
|
-
case "stopped-once": return cause.reason;
|
|
225
|
-
default: return cause;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
179
|
const TURN_PARTICIPATION_TTL_MS = 5 * 60_000;
|
|
229
180
|
function participantKey(owner, actor, uid) {
|
|
230
181
|
return `${owner}.${actor}.${uid}`;
|
|
@@ -781,6 +732,43 @@ export class Manager {
|
|
|
781
732
|
shredUserSecrets: (failures, family) => this.shredUserSecrets(failures, family),
|
|
782
733
|
bearerEntryArgv,
|
|
783
734
|
});
|
|
735
|
+
/** Seat stop, exit, recursive reap and named despawn. Every dependency reads through at its use. */
|
|
736
|
+
seatStopComponent = new SeatStop({
|
|
737
|
+
agentGoals: () => this.agentGoals,
|
|
738
|
+
agents: () => this.agents,
|
|
739
|
+
auth: () => this.auth,
|
|
740
|
+
ep: () => this.ep,
|
|
741
|
+
execution: () => this.execution,
|
|
742
|
+
goalWriter: () => this.goalWriter,
|
|
743
|
+
lifecycleInFlight: () => this.lifecycleInFlight,
|
|
744
|
+
setLifecycleInFlight: (value) => { this.lifecycleInFlight = value; },
|
|
745
|
+
maintenanceState: () => this.maintenanceState,
|
|
746
|
+
managerInstanceId: () => this.managerInstanceId,
|
|
747
|
+
remoteAuthority: () => this.remoteAuthority,
|
|
748
|
+
retirement: () => this.retirement,
|
|
749
|
+
servers: () => this.servers,
|
|
750
|
+
serviceServe: () => this.serviceServe,
|
|
751
|
+
space: () => this.space,
|
|
752
|
+
unverifiedStops: () => this.unverifiedStops,
|
|
753
|
+
setUnverifiedStops: (value) => { this.unverifiedStops = value; },
|
|
754
|
+
workspaceRoot: () => this.workspaceRoot,
|
|
755
|
+
assertGoalWriterEpochCurrent: (...args) => this.assertGoalWriterEpochCurrent(...args),
|
|
756
|
+
authorizeNamed: (...args) => this.authorizeNamed(...args),
|
|
757
|
+
awaitHandleExit: (...args) => this.awaitHandleExit(...args),
|
|
758
|
+
beginLifecycle: (...args) => this.beginLifecycle(...args),
|
|
759
|
+
confirmRetirement: (...args) => this.confirmRetirement(...args),
|
|
760
|
+
emitGoalProgress: (...args) => this.emitGoalProgress(...args),
|
|
761
|
+
executionRefusal: (...args) => this.executionRefusal(...args),
|
|
762
|
+
expireGoalAcceptance: (...args) => this.expireGoalAcceptance(...args),
|
|
763
|
+
freeSlot: (...args) => this.freeSlot(...args),
|
|
764
|
+
maintenanceError: (...args) => this.maintenanceError(...args),
|
|
765
|
+
managedPrincipal: (...args) => this.managedPrincipal(...args),
|
|
766
|
+
readManagedSessionState: (...args) => this.readManagedSessionState(...args),
|
|
767
|
+
recoverManagedSession: (...args) => this.recoverManagedSession(...args),
|
|
768
|
+
releaseLifecycle: (...args) => this.releaseLifecycle(...args),
|
|
769
|
+
shredUserSecrets: (...args) => this.shredUserSecrets(...args),
|
|
770
|
+
trackDeprovision: (...args) => this.trackDeprovision(...args),
|
|
771
|
+
});
|
|
784
772
|
/** The goal-writer connection and the goal index it reconciles. Every dependency reads through at its use. */
|
|
785
773
|
goalWriterComponent = new GoalWriter({
|
|
786
774
|
auth: () => this.auth,
|
|
@@ -3378,120 +3366,12 @@ export class Manager {
|
|
|
3378
3366
|
// `ctl.delivery` control service (endpoint.startPlane3 → handleDeliveryControl). The manager is
|
|
3379
3367
|
// lifecycle-only; it records each agent's read ACL at spawn (commitAcl) so the daemon can validate
|
|
3380
3368
|
// those ops against the durable ACL registry — the single source of truth, no in-memory ledger.
|
|
3381
|
-
/**
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
*
|
|
3388
|
-
* Never throws (#159 B2): a runtime hard-stop CAN throw (tmux `closeWindow` / cmux `closeWorkspace`
|
|
3389
|
-
* are direct calls), and a throwing stop must not abort a caller's cleanup and leak the agent's
|
|
3390
|
-
* footprint, nor (in `reapChildrenOf`) abort the reap of later siblings. The failure is logged and
|
|
3391
|
-
* returned: a caller that must prove exit (shutdown, a failed resume) reports it as the cause at
|
|
3392
|
-
* once instead of waiting out a stop the runtime already refused. */
|
|
3393
|
-
stopHandle(a, graceful, cause) {
|
|
3394
|
-
// The TERMINALIZING latch: flipped SYNCHRONOUSLY, before any await anywhere on
|
|
3395
|
-
// this stop path — later renewals refuse, while an already-admitted renewal drains before the
|
|
3396
|
-
// durable terminal begins.
|
|
3397
|
-
a.terminalizing = true;
|
|
3398
|
-
a.stopCause ??= cause;
|
|
3399
|
-
try {
|
|
3400
|
-
// A delegated seat's close runs only inside its retirement, after the host revoked its grant,
|
|
3401
|
-
// so stopping it starts that retirement. Every exit wait on a stop path then settles on that
|
|
3402
|
-
// close; the free path's own teardown joins the same flight.
|
|
3403
|
-
if (a.handedOff)
|
|
3404
|
-
this.trackDeprovision(this.teardownTarget(a));
|
|
3405
|
-
else
|
|
3406
|
-
a.handle.stop({ graceful });
|
|
3407
|
-
// The runtime captured its cohort synchronously before the cooperative
|
|
3408
|
-
// request can let a root exit and orphan its already-running children.
|
|
3409
|
-
if (graceful && process.platform === "win32" && a.control)
|
|
3410
|
-
controlShutdown(a.control);
|
|
3411
|
-
}
|
|
3412
|
-
catch (e) {
|
|
3413
|
-
const failure = rejectionText(e);
|
|
3414
|
-
console.error(`stop ${a.name} (${a.id}): ${failure}`);
|
|
3415
|
-
return failure;
|
|
3416
|
-
}
|
|
3417
|
-
}
|
|
3418
|
-
/** Windows PTY stops release their name only after the captured process cohort and PTY exited. */
|
|
3419
|
-
async stopWindowsSeat(a, graceful, floor, cause) {
|
|
3420
|
-
if (a.once)
|
|
3421
|
-
a.once.stopReason ??= onceStopReason(cause);
|
|
3422
|
-
const failure = this.stopHandle(a, graceful, cause);
|
|
3423
|
-
this.lifecycleInFlight++;
|
|
3424
|
-
try {
|
|
3425
|
-
if (failure !== undefined)
|
|
3426
|
-
throw new Error(failure);
|
|
3427
|
-
await this.awaitHandleExit(a.handle);
|
|
3428
|
-
this.unverifiedStops = this.unverifiedStops.filter((stopped) => stopped.handle !== a.handle);
|
|
3429
|
-
this.freeSlot(a, floor, cause, true);
|
|
3430
|
-
}
|
|
3431
|
-
catch (error) {
|
|
3432
|
-
const detail = `Windows stop could not prove the captured process tree exited: ${rejectionText(error)}`;
|
|
3433
|
-
this.unverifiedStops = this.unverifiedStops.filter((stopped) => stopped.handle !== a.handle);
|
|
3434
|
-
this.unverifiedStops.push({ name: a.name, id: a.id, handle: a.handle, authoritative: true, error: detail });
|
|
3435
|
-
throw new EpEnvelopeError("unavailable", detail, undefined, "unknown");
|
|
3436
|
-
}
|
|
3437
|
-
finally {
|
|
3438
|
-
this.releaseLifecycle();
|
|
3439
|
-
}
|
|
3440
|
-
}
|
|
3441
|
-
/** Keep an accepted stop inside the lifecycle drain until the runtime proves the child is gone,
|
|
3442
|
-
* so a maintenance prepare can never fence ahead of a child that is still dying. The `cause` is
|
|
3443
|
-
* the stop-family cause the door already knows (which door, and who asked); it rides every
|
|
3444
|
-
* freeSlot below so the reap line can say it.
|
|
3445
|
-
*
|
|
3446
|
-
* An operator-accepted stop frees its slot at once: `stop` replying ✓ means `ps` no longer lists
|
|
3447
|
-
* the agent. That cannot omit a still-live child from a cut, because runPreparation drains the
|
|
3448
|
-
* lifecycle BEFORE it reads the roster — the exit proof below is what closes the race, not the
|
|
3449
|
-
* slot lingering. A recursive reap (`requireAuthoritativeExit`) instead keeps the slot until the
|
|
3450
|
-
* wait proves exit: nobody asked for those children to be gone, so they stay managed until the
|
|
3451
|
-
* runtime says otherwise, and a runtime that cannot prove exit records an unverified stop. */
|
|
3452
|
-
trackStoppedHandle(a, floor, cause, requireAuthoritativeExit = false) {
|
|
3453
|
-
if (process.platform === "win32" && a.handle.kind === "pty")
|
|
3454
|
-
requireAuthoritativeExit = true;
|
|
3455
|
-
// What a once seat's task is cancelled with if this stop ends it before the task has a terminal.
|
|
3456
|
-
if (a.once && typeof cause !== "string")
|
|
3457
|
-
a.once.stopReason ??= onceStopReason(cause);
|
|
3458
|
-
if (!a.handle.waitForExit) {
|
|
3459
|
-
// Preserve ordinary external-runtime stop behavior, but retain enough evidence for a later
|
|
3460
|
-
// maintenance prepare to fail if that runtime still cannot prove the surface disappeared.
|
|
3461
|
-
this.unverifiedStops.push({
|
|
3462
|
-
name: a.name,
|
|
3463
|
-
id: a.id,
|
|
3464
|
-
handle: a.handle,
|
|
3465
|
-
authoritative: requireAuthoritativeExit,
|
|
3466
|
-
error: requireAuthoritativeExit
|
|
3467
|
-
? `recursive reap cannot prove exit on runtime "${a.handle.kind}" (AgentHandle.waitForExit is not implemented)`
|
|
3468
|
-
: undefined,
|
|
3469
|
-
});
|
|
3470
|
-
if (requireAuthoritativeExit)
|
|
3471
|
-
return;
|
|
3472
|
-
this.freeSlot(a, floor, cause, true);
|
|
3473
|
-
return;
|
|
3474
|
-
}
|
|
3475
|
-
if (!requireAuthoritativeExit)
|
|
3476
|
-
this.freeSlot(a, floor, cause, true);
|
|
3477
|
-
this.lifecycleInFlight++;
|
|
3478
|
-
void this.awaitHandleExit(a.handle)
|
|
3479
|
-
.then(() => {
|
|
3480
|
-
this.unverifiedStops = this.unverifiedStops.filter((stopped) => stopped.handle !== a.handle);
|
|
3481
|
-
this.freeSlot(a, floor, cause, true);
|
|
3482
|
-
}) // no-op once an accepted stop already freed it
|
|
3483
|
-
.catch((e) => {
|
|
3484
|
-
this.unverifiedStops = this.unverifiedStops.filter((stopped) => stopped.handle !== a.handle);
|
|
3485
|
-
this.unverifiedStops.push({
|
|
3486
|
-
name: a.name,
|
|
3487
|
-
id: a.id,
|
|
3488
|
-
handle: a.handle,
|
|
3489
|
-
authoritative: true,
|
|
3490
|
-
error: `accepted stop could not prove exit: ${rejectionText(e)}`,
|
|
3491
|
-
});
|
|
3492
|
-
})
|
|
3493
|
-
.finally(() => this.releaseLifecycle());
|
|
3494
|
-
}
|
|
3369
|
+
/** {@link SeatStop.stopHandle}. */
|
|
3370
|
+
stopHandle(...args) { return this.seatStopComponent.stopHandle(...args); }
|
|
3371
|
+
/** {@link SeatStop.stopWindowsSeat}. */
|
|
3372
|
+
stopWindowsSeat(...args) { return this.seatStopComponent.stopWindowsSeat(...args); }
|
|
3373
|
+
/** {@link SeatStop.trackStoppedHandle}. */
|
|
3374
|
+
trackStoppedHandle(...args) { return this.seatStopComponent.trackStoppedHandle(...args); }
|
|
3495
3375
|
provisionUserAgent(name, opts) { return this.userProvision.provisionUserAgent(name, opts); }
|
|
3496
3376
|
/** Shred a user agent's secret family from the store and from disk. Every removal is attempted,
|
|
3497
3377
|
* and each failure joins `unshredded`, so one fault cannot leave the rest of the family behind. */
|
|
@@ -3503,96 +3383,17 @@ export class Manager {
|
|
|
3503
3383
|
if (path)
|
|
3504
3384
|
await attemptCleanup(unshredded, `file ${path}`, () => rmSync(path, { force: true }));
|
|
3505
3385
|
}
|
|
3506
|
-
/**
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
* chokepoint for despawn, self-stop, reap and exit, which is why the line lives here rather than
|
|
3513
|
-
* being remembered at each of the six callers.
|
|
3514
|
-
*
|
|
3515
|
-
* THE RUNTIME'S EXIT DETAIL IS OPTIONAL AND ITS ABSENCE IS SAID OUT LOUD. `AgentHandle.exitInfo`
|
|
3516
|
-
* is only implemented by backends that own the child process; the rest genuinely cannot see how
|
|
3517
|
-
* it ended. Printing `code 0` for those would be a fabricated clean exit on exactly the seats
|
|
3518
|
-
* whose death nobody can explain, so an absent answer prints as unavailable and names the runtime
|
|
3519
|
-
* that could not provide it.
|
|
3520
|
-
*/
|
|
3521
|
-
logSeatReaped(a, cause) {
|
|
3522
|
-
const causeText = typeof cause === "string" ? FREE_SLOT_CAUSE_TEXT[cause] : stopCauseText(cause);
|
|
3523
|
-
let detail;
|
|
3524
|
-
try {
|
|
3525
|
-
const info = a.handle.exitInfo?.();
|
|
3526
|
-
detail = info === undefined
|
|
3527
|
-
? `exit detail unavailable from runtime "${a.handle.kind}"`
|
|
3528
|
-
: `exit code ${info.code ?? "unknown"}${info.signal === undefined ? "" : `, signal ${info.signal}`}${info.diagnostic ? `; diagnostic: ${info.diagnostic}` : ""}`;
|
|
3529
|
-
}
|
|
3530
|
-
catch (e) {
|
|
3531
|
-
// A runtime that throws while being asked has told us something real; it must not take the
|
|
3532
|
-
// log line (or the free path it sits on) down with it.
|
|
3533
|
-
detail = `exit detail unreadable from runtime "${a.handle.kind}": ${rejectionText(e)}`;
|
|
3534
|
-
}
|
|
3535
|
-
console.error(`seat reaped: ${a.name} (${a.id}, uid ${a.lifecycleUid}${a.handle.pid !== undefined ? `, pid ${a.handle.pid}` : ""}) - ${causeText}; ${detail}`);
|
|
3536
|
-
}
|
|
3537
|
-
/**
|
|
3538
|
-
* A SEAT THAT LEAVES THE MESH WHILE ITS SLOT IS HELD GETS A LINE, AND SO DOES ITS RETURN.
|
|
3539
|
-
*
|
|
3540
|
-
* Seats once read `running · mesh offline` for many hours with no manager log line, so a watchdog
|
|
3541
|
-
* keyed on process liveness saw nothing wrong and nobody could say when each seat dropped (#1208).
|
|
3542
|
-
* The line follows the same state `ps` reads, checked on every roster change and view transition,
|
|
3543
|
-
* because not every offline record arrives as a presence event: after a reconnect the fresh snapshot
|
|
3544
|
-
* records an already-offline seat quietly. Only a current view is a verdict, so a stale or
|
|
3545
|
-
* unpopulated one logs nothing. The match is {@link isOwnPresence}. A seat being stopped is left to
|
|
3546
|
-
* the reap line. The heartbeat is the seat's own record and nothing validated it, so an unreadable
|
|
3547
|
-
* one prints as unknown instead of throwing inside the watch.
|
|
3548
|
-
*/
|
|
3549
|
-
logSeatMeshTransitions() {
|
|
3550
|
-
if (typeof this.ep.presenceView === "function" && this.ep.presenceView().state !== "current")
|
|
3551
|
-
return;
|
|
3552
|
-
const roster = new Map(this.ep.getRoster().map((p) => [p.card.id, p]));
|
|
3553
|
-
for (const a of this.agents.values()) {
|
|
3554
|
-
const seen = roster.get(this.managedPrincipal(a));
|
|
3555
|
-
if (a.terminalizing || !this.isOwnPresence(a, seen))
|
|
3556
|
-
continue;
|
|
3557
|
-
if (seen.status !== "offline")
|
|
3558
|
-
a.joinIssue = undefined;
|
|
3559
|
-
const who = `${a.name} (${a.id}, uid ${a.lifecycleUid}${a.handle.pid !== undefined ? `, pid ${a.handle.pid}` : ""})`;
|
|
3560
|
-
if (seen.status === "offline" && !a.offMesh) {
|
|
3561
|
-
a.offMesh = true;
|
|
3562
|
-
const ts = seen.ts;
|
|
3563
|
-
const last = typeof ts === "number" && !Number.isNaN(new Date(ts).getTime()) ? new Date(ts).toISOString() : "unknown";
|
|
3564
|
-
console.error(`seat offline on the mesh: ${who} - last heartbeat ${last}; process ${a.handle.status()}`);
|
|
3565
|
-
}
|
|
3566
|
-
else if (seen.status !== "offline" && a.offMesh) {
|
|
3567
|
-
a.offMesh = false;
|
|
3568
|
-
console.error(`seat back on the mesh: ${who}`);
|
|
3569
|
-
}
|
|
3570
|
-
}
|
|
3571
|
-
}
|
|
3572
|
-
/** Whether a roster record is this seat's own: the readiness fence's exact principal and
|
|
3573
|
-
* incarnation, so a same-named foreign peer or an older incarnation never speaks for it (#1208). */
|
|
3574
|
-
isOwnPresence(a, p) {
|
|
3575
|
-
return p !== undefined && p.card.id === this.managedPrincipal(a) && p.lifecycleUid === a.lifecycleUid;
|
|
3576
|
-
}
|
|
3386
|
+
/** {@link SeatStop.logSeatReaped}. */
|
|
3387
|
+
logSeatReaped(...args) { return this.seatStopComponent.logSeatReaped(...args); }
|
|
3388
|
+
/** {@link SeatStop.logSeatMeshTransitions}. */
|
|
3389
|
+
logSeatMeshTransitions(...args) { return this.seatStopComponent.logSeatMeshTransitions(...args); }
|
|
3390
|
+
/** {@link SeatStop.isOwnPresence}. */
|
|
3391
|
+
isOwnPresence(a, p) { return this.seatStopComponent.isOwnPresence(a, p); }
|
|
3577
3392
|
freeSlot(a, floor, cause, acceptedBeforeFence = false) { this.namesCapacity.freeSlot(a, floor, cause, acceptedBeforeFence); }
|
|
3578
|
-
/**
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
try {
|
|
3583
|
-
removeInlineSnapshot(this.workspaceRoot, lifecycleUid);
|
|
3584
|
-
return true;
|
|
3585
|
-
}
|
|
3586
|
-
catch (e) {
|
|
3587
|
-
console.error(`! ${name}: its inline persona snapshot could not be removed: ${rejectionText(e)}`);
|
|
3588
|
-
return false;
|
|
3589
|
-
}
|
|
3590
|
-
}
|
|
3591
|
-
/** A live agent's teardown target, built field by field so the rest of its record (handle, seed,
|
|
3592
|
-
* restart state) never rides into the detached teardown or its single-flight map. */
|
|
3593
|
-
teardownTarget(a) {
|
|
3594
|
-
return { id: a.id, name: a.name, lifecycleUid: a.lifecycleUid, userOwner: a.userOwner, delegated: a.delegated, secretPaths: a.secretPaths, runtime: a.handle?.reference, ...(a.handedOff ? { delegatedHandle: a.handle } : {}), launch: { allowSubscribe: a.launch.allowSubscribe }, staticCredentialRenewal: a.staticCredentialRenewal };
|
|
3595
|
-
}
|
|
3393
|
+
/** {@link SeatStop.dropInlineSnapshot}. */
|
|
3394
|
+
dropInlineSnapshot(...args) { return this.seatStopComponent.dropInlineSnapshot(...args); }
|
|
3395
|
+
/** {@link SeatStop.teardownTarget}. */
|
|
3396
|
+
teardownTarget(...args) { return this.seatStopComponent.teardownTarget(...args); }
|
|
3596
3397
|
deprovision(a) { return this.retirement.deprovision(a); }
|
|
3597
3398
|
/** Run one retirement in a {@link RETIREMENT_CONCURRENCY} slot, oldest first: a seat's deprovision, a
|
|
3598
3399
|
* chat session's terminal and a static reconcile's terminal all take one. No retirement awaits
|
|
@@ -3616,47 +3417,12 @@ export class Manager {
|
|
|
3616
3417
|
}
|
|
3617
3418
|
confirmRetirement(a) { this.retirement.confirmRetirement(a); }
|
|
3618
3419
|
deprovisionBroker(a) { return this.retirement.deprovisionBroker(a); }
|
|
3619
|
-
/**
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
return undefined;
|
|
3626
|
-
}
|
|
3627
|
-
catch (e) {
|
|
3628
|
-
return rejectionText(e);
|
|
3629
|
-
}
|
|
3630
|
-
}
|
|
3631
|
-
/** The retiring lifecycle's durable membership channels, read from the delivery daemon's
|
|
3632
|
-
* `lifecycleMemberships` admin verb (read-only, lifecycle-exact). Incomplete on any refusal. */
|
|
3633
|
-
async lifecycleMembershipInventory(a) {
|
|
3634
|
-
const t = deprovisionTargetPrincipal({ principal: a.id, lifecycleUid: a.lifecycleUid });
|
|
3635
|
-
try {
|
|
3636
|
-
const r = await this.ep.requestDeliveryAdmin("lifecycleMemberships", { principal: principalKey(t.owner, t.actor).key, lifecycleUid: t.lifecycleUid }, 5_000);
|
|
3637
|
-
const data = r.data;
|
|
3638
|
-
if (!r.ok || data?.complete !== true || !Array.isArray(data.channels) || !data.channels.every((c) => typeof c === "string" && (isConcreteChannel(c) || isChannelFamily(c))))
|
|
3639
|
-
return { complete: false, channels: [], reason: r.ok ? "malformed inventory reply" : (r.error ?? "refused") };
|
|
3640
|
-
return { complete: true, channels: data.channels };
|
|
3641
|
-
}
|
|
3642
|
-
catch (e) {
|
|
3643
|
-
return { complete: false, channels: [], reason: rejectionText(e) };
|
|
3644
|
-
}
|
|
3645
|
-
}
|
|
3646
|
-
/** Reap a parent's children on its exit (P4b). Every descendant remains managed until the runtime's
|
|
3647
|
-
* authoritative wait proves exit; the wait participates in the lifecycle drain, so preservation can
|
|
3648
|
-
* never omit a child that may still be alive. Recursive descendants are scheduled before their parent
|
|
3649
|
-
* slot can disappear. */
|
|
3650
|
-
reapChildrenOf(parentId) {
|
|
3651
|
-
for (const child of [...this.agents.values()]) {
|
|
3652
|
-
if (child.spawner !== parentId)
|
|
3653
|
-
continue;
|
|
3654
|
-
this.reapChildrenOf(this.managedPrincipal(child));
|
|
3655
|
-
const cause = { kind: "stopped-reap", parent: parentId };
|
|
3656
|
-
this.stopHandle(child, false, cause);
|
|
3657
|
-
this.trackStoppedHandle(child, true, cause, true);
|
|
3658
|
-
}
|
|
3659
|
-
}
|
|
3420
|
+
/** {@link SeatStop.fenceRetiringAcl}. */
|
|
3421
|
+
fenceRetiringAcl(...args) { return this.seatStopComponent.fenceRetiringAcl(...args); }
|
|
3422
|
+
/** {@link SeatStop.lifecycleMembershipInventory}. */
|
|
3423
|
+
lifecycleMembershipInventory(...args) { return this.seatStopComponent.lifecycleMembershipInventory(...args); }
|
|
3424
|
+
/** {@link SeatStop.reapChildrenOf}. */
|
|
3425
|
+
reapChildrenOf(...args) { return this.seatStopComponent.reapChildrenOf(...args); }
|
|
3660
3426
|
readManagedSessionState(a) {
|
|
3661
3427
|
return this.sessionRecovery.readManagedSessionState(a);
|
|
3662
3428
|
}
|
|
@@ -3708,42 +3474,8 @@ export class Manager {
|
|
|
3708
3474
|
recoverManagedSession(a) {
|
|
3709
3475
|
return this.sessionRecovery.recoverManagedSession(a);
|
|
3710
3476
|
}
|
|
3711
|
-
/**
|
|
3712
|
-
|
|
3713
|
-
* restart in place after readiness; a spawn carrying `supervise` restarts any connector the same
|
|
3714
|
-
* way, without classifying a session-state file. Every other exit follows the existing terminal
|
|
3715
|
-
* path. */
|
|
3716
|
-
onAgentExit(a) {
|
|
3717
|
-
// Preservation owns the child-stop snapshot. Exit watchers must neither delete that snapshot nor
|
|
3718
|
-
// trigger normal deprovision/reap while the cut is being formed.
|
|
3719
|
-
if (this.maintenanceState !== "active")
|
|
3720
|
-
return;
|
|
3721
|
-
// A Windows stop owns the exit proof and its truthful reap cause. The raw
|
|
3722
|
-
// terminal event must not release a slot while cohort verification is pending.
|
|
3723
|
-
if (process.platform === "win32" && a.handle.kind === "pty" && a.terminalizing)
|
|
3724
|
-
return;
|
|
3725
|
-
// A replacement is proving readiness under this row. Its own wait owns a failed
|
|
3726
|
-
// relaunch; treating that exit as a seat death would free the slot mid-recovery.
|
|
3727
|
-
if (a.restart?.recovering && !a.terminalizing)
|
|
3728
|
-
return;
|
|
3729
|
-
if (a.restart?.armed && !a.terminalizing) {
|
|
3730
|
-
if (a.restart.policy !== undefined) {
|
|
3731
|
-
this.recoverManagedSession(a);
|
|
3732
|
-
return;
|
|
3733
|
-
}
|
|
3734
|
-
try {
|
|
3735
|
-
if (this.readManagedSessionState(a).status === "running") {
|
|
3736
|
-
this.recoverManagedSession(a);
|
|
3737
|
-
return;
|
|
3738
|
-
}
|
|
3739
|
-
}
|
|
3740
|
-
catch (error) {
|
|
3741
|
-
console.error(`! ${a.name}: cannot classify Pi process exit for recovery: ${rejectionText(error)} - retiring the seat`);
|
|
3742
|
-
}
|
|
3743
|
-
}
|
|
3744
|
-
this.freeSlot(a, true, a.stopCause ?? "process-exit");
|
|
3745
|
-
this.reapChildrenOf(this.managedPrincipal(a));
|
|
3746
|
-
}
|
|
3477
|
+
/** {@link SeatStop.onAgentExit}. */
|
|
3478
|
+
onAgentExit(...args) { return this.seatStopComponent.onAgentExit(...args); }
|
|
3747
3479
|
nameError(name) { return this.namesCapacity.nameError(name); }
|
|
3748
3480
|
/** Spawn a teammate by persona ref (`name` loads `.cotal/agents/<name>.md`; the peer presents
|
|
3749
3481
|
* under that file's own `name:`), as if a peer asked via the control plane. Used to pre-spawn the
|
|
@@ -5185,118 +4917,15 @@ export class Manager {
|
|
|
5185
4917
|
ownerSeats(owner) { return this.namesCapacity.ownerSeats(owner); }
|
|
5186
4918
|
/** The per-owner ceiling at accept: {@link NamesCapacity.seatCapRefusal}. */
|
|
5187
4919
|
seatCapRefusal(owner) { return this.namesCapacity.seatCapRefusal(owner); }
|
|
4920
|
+
/** {@link SeatStop.opStop}. */
|
|
5188
4921
|
// @ts-expect-error TS6133: retained fixtures call this private adapter through structural views.
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
}
|
|
5197
|
-
catch (error) {
|
|
5198
|
-
return { ok: false, error: rejectionText(error) };
|
|
5199
|
-
}
|
|
5200
|
-
}
|
|
5201
|
-
/** The ONE named-terminal core both doors share: the ctl named `stop`
|
|
5202
|
-
* and the v0.4 targeted `despawn` are the same terminal — authorize by the shared policy
|
|
5203
|
-
* ({@link authorizeNamed}: own-child / owner-domain on privileged, any on admin), stop, track.
|
|
5204
|
-
* The ep door runs the SAME two pieces separately so a policy denial surfaces as the §13.3
|
|
5205
|
-
* `permission-denied` (never a generic failure). */
|
|
5206
|
-
async despawnCore(a, caller, admin, graceful) {
|
|
5207
|
-
const denied = await this.authorizeNamed(a, caller, admin);
|
|
5208
|
-
if (denied)
|
|
5209
|
-
return { ok: false, error: denied };
|
|
5210
|
-
return this.despawnAuthorized(a, graceful, !admin, caller);
|
|
5211
|
-
}
|
|
5212
|
-
/** The post-authorization terminal effect (both doors). `trackNonAdmin` mirrors the ctl door's
|
|
5213
|
-
* `trackStoppedHandle(a, !admin)` disposition. The reap line names `caller` — the AUTHENTICATED
|
|
5214
|
-
* wire principal the door already resolved — so an operator reading the log can tell one peer's
|
|
5215
|
-
* despawn from another's. */
|
|
5216
|
-
despawnAuthorized(a, graceful, trackNonAdmin, caller) {
|
|
5217
|
-
if (process.platform === "win32" && a.handle.kind === "pty") {
|
|
5218
|
-
return this.stopWindowsSeat(a, graceful, trackNonAdmin, { kind: "stopped-requested", requester: caller }).then(() => {
|
|
5219
|
-
void this.cancelAgentGoal(a.name, graceful ? "graceful" : "terminate");
|
|
5220
|
-
return { ok: true, data: { name: a.name, stopped: true, graceful } };
|
|
5221
|
-
});
|
|
5222
|
-
}
|
|
5223
|
-
const cause = { kind: "stopped-requested", requester: caller };
|
|
5224
|
-
this.stopHandle(a, graceful, cause);
|
|
5225
|
-
this.trackStoppedHandle(a, trackNonAdmin, cause);
|
|
5226
|
-
void this.cancelAgentGoal(a.name, graceful ? "graceful" : "terminate"); // Cancel a live spawn goal
|
|
5227
|
-
return { ok: true, data: { name: a.name, stopped: true, graceful } };
|
|
5228
|
-
}
|
|
5229
|
-
/** Retire one agent this manager launched under a delegated user intent, through the host
|
|
5230
|
-
* (SPEC 13.16). It sends the user's retirement intent for the UID of the running slot or its
|
|
5231
|
-
* retirement hold, and only on `retired: true` for that exact target stops the slot, shreds the
|
|
5232
|
-
* seat's local secret family and frees the name; every other answer leaves the slot running or
|
|
5233
|
-
* the name held, and a failed shred keeps the name held. It never calls the holder's own prepare
|
|
5234
|
-
* or requester. */
|
|
5235
|
-
async retireDelegatedAgent(name, intentId) {
|
|
5236
|
-
const execute = this.remoteAuthority?.executeDelegatedUserIntent;
|
|
5237
|
-
if (!execute)
|
|
5238
|
-
return { ok: false, error: `this manager has no host execution for a delegated user intent; "${name}" was not retired` };
|
|
5239
|
-
const release = this.beginLifecycle();
|
|
5240
|
-
if (!release)
|
|
5241
|
-
return { ok: false, error: this.maintenanceError() };
|
|
5242
|
-
try {
|
|
5243
|
-
const live = this.agents.get(name);
|
|
5244
|
-
const held = live ? undefined : this.retirement.held(name);
|
|
5245
|
-
const principal = live?.delegated ? parsePrincipalKey(live.id) : held?.target.delegated ? held : null;
|
|
5246
|
-
const lifecycleUid = live?.lifecycleUid ?? held?.target.lifecycleUid;
|
|
5247
|
-
if (!principal || !lifecycleUid)
|
|
5248
|
-
return { ok: false, error: `no agent named "${name}" was launched on this manager under a delegated user intent` };
|
|
5249
|
-
const target = { owner: principal.owner, actor: principal.actor, lifecycleUid };
|
|
5250
|
-
try {
|
|
5251
|
-
const result = await execute({ intentId, operation: "retire", target });
|
|
5252
|
-
if (result.operation !== "retire" || result.intentId !== intentId || result.opId !== managedRetirementOpId(target.lifecycleUid) ||
|
|
5253
|
-
result.target.owner !== target.owner || result.target.actor !== target.actor || result.target.lifecycleUid !== target.lifecycleUid)
|
|
5254
|
-
throw new Error(`the host answered delegated intent ${intentId} with another execution`);
|
|
5255
|
-
if (result.retired !== true)
|
|
5256
|
-
return { ok: false, error: `the host did not confirm the delegated retirement of "${name}" at ${target.lifecycleUid}; "${name}" is unchanged` };
|
|
5257
|
-
}
|
|
5258
|
-
catch (e) {
|
|
5259
|
-
const error = `the delegated retirement under intent ${intentId} did not complete (${rejectionText(e)})`;
|
|
5260
|
-
const hold = this.retirement.held(name);
|
|
5261
|
-
if (hold?.target.lifecycleUid === target.lifecycleUid)
|
|
5262
|
-
hold.lastError = error;
|
|
5263
|
-
return { ok: false, error: `${error}; "${name}" is unchanged` };
|
|
5264
|
-
}
|
|
5265
|
-
// The host's retirement closed this UID's provider handle before its barrier, so the stop only
|
|
5266
|
-
// reaps the slot, and its hold clears with the confirmation.
|
|
5267
|
-
const slot = this.agents.get(name);
|
|
5268
|
-
if (slot?.lifecycleUid === target.lifecycleUid)
|
|
5269
|
-
await this.despawnAuthorized(slot, true, false, `delegated retirement ${intentId}`);
|
|
5270
|
-
// The host owns the grant and the footprint, but the secret family enrollUserAgent wrote here
|
|
5271
|
-
// is this participant's, and no teardown arm of a delegated seat removes it.
|
|
5272
|
-
const unshredded = [];
|
|
5273
|
-
await this.shredUserSecrets(unshredded, (live ?? held?.target)?.secretPaths ?? agentLifecycleSecretFilePaths(this.workspaceRoot, this.space, name, target.lifecycleUid));
|
|
5274
|
-
if (unshredded.length) {
|
|
5275
|
-
const error = `the host retired "${name}" at ${target.lifecycleUid}, but cleanup failed: ${describeCleanupFailures(unshredded)}; the name stays held until a retried retirement intent removes it`;
|
|
5276
|
-
const hold = this.retirement.held(name);
|
|
5277
|
-
if (hold?.target.lifecycleUid === target.lifecycleUid)
|
|
5278
|
-
hold.lastError = error;
|
|
5279
|
-
return { ok: false, error };
|
|
5280
|
-
}
|
|
5281
|
-
this.confirmRetirement({ id: principalKey(target.owner, target.actor).key, name, lifecycleUid: target.lifecycleUid });
|
|
5282
|
-
return { ok: true, data: { name, lifecycleUid: target.lifecycleUid, retired: true } };
|
|
5283
|
-
}
|
|
5284
|
-
finally {
|
|
5285
|
-
release();
|
|
5286
|
-
}
|
|
5287
|
-
}
|
|
5288
|
-
/** Resolve a v0.4 TARGET triple (owner, actor, lifecycleUid — broker-validated subject/body
|
|
5289
|
-
* agreement, currency re-checked by the serve boundary's resolver) to the live managed agent it
|
|
5290
|
-
* names. Static agents key `(DEV_OWNER, nkey)`; user-mode agents store the principal dot-form
|
|
5291
|
-
* in `id`. A uid mismatch is a superseded incarnation — never resolved to its successor. */
|
|
5292
|
-
findManagedByTarget(t) {
|
|
5293
|
-
for (const a of this.agents.values()) {
|
|
5294
|
-
const matches = a.userOwner ? a.id === principalKey(t.owner, t.actor).key : t.owner === DEV_OWNER && a.id === t.actor;
|
|
5295
|
-
if (matches && a.lifecycleUid === t.lifecycleUid)
|
|
5296
|
-
return a;
|
|
5297
|
-
}
|
|
5298
|
-
return undefined;
|
|
5299
|
-
}
|
|
4922
|
+
opStop(...args) { return this.seatStopComponent.opStop(...args); }
|
|
4923
|
+
/** {@link SeatStop.despawnAuthorized}. */
|
|
4924
|
+
despawnAuthorized(...args) { return this.seatStopComponent.despawnAuthorized(...args); }
|
|
4925
|
+
/** {@link SeatStop.retireDelegatedAgent}. */
|
|
4926
|
+
retireDelegatedAgent(name, intentId) { return this.seatStopComponent.retireDelegatedAgent(name, intentId); }
|
|
4927
|
+
/** {@link SeatStop.findManagedByTarget}. */
|
|
4928
|
+
findManagedByTarget(...args) { return this.seatStopComponent.findManagedByTarget(...args); }
|
|
5300
4929
|
/** Run one static §13.1 lifecycle OPERATION over an ephemeral, key-pinned `lifecycle-executor`
|
|
5301
4930
|
* connection: the credential's grants name exactly ONE incarnation's head/uid/gate/
|
|
5302
4931
|
* cred-family/slot keys, so the write authority exists only for this operation's window and
|
|
@@ -6018,31 +5647,8 @@ export class Manager {
|
|
|
6018
5647
|
/** Make an adopted seat a once seat again: its exit settles its task, and the task is served to
|
|
6019
5648
|
* it. A task that ended before the restart owes the stop the predecessor may not have made. */
|
|
6020
5649
|
bindOnceSeat(a) { return this.turnRelay.bindOnceSeat(a); }
|
|
6021
|
-
/**
|
|
6022
|
-
|
|
6023
|
-
* wins: if the readiness outcome already committed (succeeded/failed/uncertain) the transition or
|
|
6024
|
-
* the create-only commit loses gracefully and the readiness terminal stands. Fire-and-forget from
|
|
6025
|
-
* despawn (the process teardown is authoritative for the agent; this settles the GOAL honestly).
|
|
6026
|
-
* Cancel rides the despawn's own authorizeNamed reach - there is no cancel-by-goalId. */
|
|
6027
|
-
async cancelAgentGoal(name, mode) {
|
|
6028
|
-
const gw = this.goalWriter;
|
|
6029
|
-
const ref = this.agentGoals.get(name);
|
|
6030
|
-
if (!gw || !ref)
|
|
6031
|
-
return;
|
|
6032
|
-
this.agentGoals.delete(name);
|
|
6033
|
-
const epoch = this.serviceServe?.grant.epoch ?? 0;
|
|
6034
|
-
try {
|
|
6035
|
-
await this.assertGoalWriterEpochCurrent(epoch); // a superseded corpse never commits a cancel terminal either
|
|
6036
|
-
await transitionGoal(gw.ctx, ref, "cancelling", { fields: { cancelMode: mode } });
|
|
6037
|
-
const r = await commitGoalResult(gw.ctx, { ref, now: Date.now(), cause: "cancel", data: { cancelledBy: "despawn" }, committer: { instanceId: this.managerInstanceId, epoch } });
|
|
6038
|
-
this.expireGoalAcceptance(ref);
|
|
6039
|
-
this.emitGoalProgress(ref, epoch, { phase: "terminal", state: r.fact.state, ...(r.fact.data !== undefined ? { data: r.fact.data } : {}) });
|
|
6040
|
-
await clearGoalIndex(gw.ctx, ref); // terminal reached - the successor never reconciles it
|
|
6041
|
-
}
|
|
6042
|
-
catch {
|
|
6043
|
-
// the goal already terminalized (the readiness outcome won the settle race) - nothing to cancel.
|
|
6044
|
-
}
|
|
6045
|
-
}
|
|
5650
|
+
/** {@link SeatStop.cancelAgentGoal}. */
|
|
5651
|
+
cancelAgentGoal(...args) { return this.seatStopComponent.cancelAgentGoal(...args); }
|
|
6046
5652
|
recordSlotRuntime(a) {
|
|
6047
5653
|
return this.seatCustody.recordSlotRuntime(a);
|
|
6048
5654
|
}
|
|
@@ -6113,21 +5719,8 @@ export class Manager {
|
|
|
6113
5719
|
reconcileStaticLifecycles(postAdoption = false) {
|
|
6114
5720
|
return this.staticLifecycle.reconcileStaticLifecycles(postAdoption);
|
|
6115
5721
|
}
|
|
6116
|
-
/**
|
|
6117
|
-
|
|
6118
|
-
* hold or a RETIRED static incarnation refuses even with a tier-valid JWT (the
|
|
6119
|
-
* copied-credential vector — its subject can never collide with a successor's, so this match
|
|
6120
|
-
* is non-forgeable); any OTHER principal is not a managed lifecycle (an operator instrument:
|
|
6121
|
-
* the credential tier governs, exactly as before). Never name alone, never a payload field. */
|
|
6122
|
-
lifecycleMembershipRefusal(caller) {
|
|
6123
|
-
for (const a of this.agents.values()) {
|
|
6124
|
-
if (this.managedPrincipal(a) === caller)
|
|
6125
|
-
return a.terminalizing
|
|
6126
|
-
? `the caller's lifecycle ${a.lifecycleUid} is terminalizing; control is refused from the first terminal step`
|
|
6127
|
-
: undefined;
|
|
6128
|
-
}
|
|
6129
|
-
return this.retirement.membershipRefusal(caller);
|
|
6130
|
-
}
|
|
5722
|
+
/** {@link SeatStop.lifecycleMembershipRefusal}. */
|
|
5723
|
+
lifecycleMembershipRefusal(...args) { return this.seatStopComponent.lifecycleMembershipRefusal(...args); }
|
|
6131
5724
|
/** Open a short-lived PROVISIONER connection, run the onboarding ops on it, and drain it (closure (ii),
|
|
6132
5725
|
* residual 2). The DM/DLV consumer-create surface — the irreducible onboarding power — lives only for
|
|
6133
5726
|
* this window, never as a standing grant on the long-lived supervisor. A provision-only endpoint
|
|
@@ -6161,28 +5754,8 @@ export class Manager {
|
|
|
6161
5754
|
await drainAndClose(nc);
|
|
6162
5755
|
}
|
|
6163
5756
|
}
|
|
6164
|
-
/**
|
|
6165
|
-
|
|
6166
|
-
* supervisor); regular agents are denied STREAM.PURGE under auth. Cleanup only: leaves live agents and
|
|
6167
|
-
* the TASK queue alone. */
|
|
6168
|
-
async opPurge(args, _caller) {
|
|
6169
|
-
if (this.execution === "none")
|
|
6170
|
-
throw new EpEnvelopeError("unimplemented", this.executionRefusal());
|
|
6171
|
-
const includeDms = args.includeDms === true;
|
|
6172
|
-
try {
|
|
6173
|
-
const creds = this.auth ? await mintCreds(this.auth, newIdentity(), "purger") : undefined;
|
|
6174
|
-
const result = await clearSpaceHistory({
|
|
6175
|
-
servers: this.servers ?? DEFAULT_SERVER,
|
|
6176
|
-
space: this.space,
|
|
6177
|
-
creds,
|
|
6178
|
-
includeDms,
|
|
6179
|
-
});
|
|
6180
|
-
return { ok: true, data: result };
|
|
6181
|
-
}
|
|
6182
|
-
catch (e) {
|
|
6183
|
-
return { ok: false, error: rejectionText(e) };
|
|
6184
|
-
}
|
|
6185
|
-
}
|
|
5757
|
+
/** {@link SeatStop.opPurge}. */
|
|
5758
|
+
opPurge(...args) { return this.seatStopComponent.opPurge(...args); }
|
|
6186
5759
|
/** Persist a peer-defined persona as config. After this, `start name` auto-discovers
|
|
6187
5760
|
* .cotal/agents/<name>.md and the connector applies its persona/model at spawn.
|
|
6188
5761
|
*
|