@cotal-ai/manager 0.164.17 → 0.165.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/manager-service-contract.d.ts +6 -1
- package/dist/manager-service-contract.d.ts.map +1 -1
- package/dist/manager-service-contract.js +11 -3
- package/dist/manager-service-contract.js.map +1 -1
- package/dist/manager.d.ts +13 -4
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +86 -31
- package/dist/manager.js.map +1 -1
- package/dist/session/bridge.d.ts.map +1 -1
- package/dist/session/bridge.js +8 -3
- package/dist/session/bridge.js.map +1 -1
- package/package.json +12 -12
package/dist/manager.js
CHANGED
|
@@ -330,6 +330,23 @@ const FREE_SLOT_CAUSE_TEXT = {
|
|
|
330
330
|
"supervise-record-failed": "this manager stopped it: its supervise policy could not be recorded for a manager restart",
|
|
331
331
|
"inline-snapshot-changed": "this manager retired it instead of restarting it: its inline persona snapshot changed after launch",
|
|
332
332
|
};
|
|
333
|
+
/** The SPEC 13.6 end reason a live attach session gets when this cause frees its seat. The causes
|
|
334
|
+
* that free the slot in the same step that saw the seat's own process exit report `process-exit`.
|
|
335
|
+
* A failed recovery frees it later, after its own stop, so it reports `target-despawn` with every
|
|
336
|
+
* manager stop. */
|
|
337
|
+
const FREE_SLOT_ATTACH_END = {
|
|
338
|
+
"process-exit": "process-exit",
|
|
339
|
+
"pi-crash-loop": "process-exit",
|
|
340
|
+
"supervise-crash-loop": "process-exit",
|
|
341
|
+
"inline-snapshot-changed": "process-exit",
|
|
342
|
+
"pi-recovery-failed": "target-despawn",
|
|
343
|
+
"supervise-recovery-failed": "target-despawn",
|
|
344
|
+
"session-bind-failed": "target-despawn",
|
|
345
|
+
"resume-session-rebind-failed": "target-despawn",
|
|
346
|
+
"carried-fork-refused": "target-despawn",
|
|
347
|
+
"resume-custody-unrecorded": "target-despawn",
|
|
348
|
+
"supervise-record-failed": "target-despawn",
|
|
349
|
+
};
|
|
333
350
|
/** The stop family's sentences — the same job {@link FREE_SLOT_CAUSE_TEXT} does for the string
|
|
334
351
|
* causes, beside it so both stay the single place a cause becomes a sentence. A requested stop's
|
|
335
352
|
* sentence embeds the authenticated principal and a recursive reap's embeds the parent that
|
|
@@ -2699,7 +2716,7 @@ export class Manager {
|
|
|
2699
2716
|
this.agents.delete(a.name);
|
|
2700
2717
|
this.dropSeatRecord(a);
|
|
2701
2718
|
}
|
|
2702
|
-
const refused = this.stopHandle(a, true);
|
|
2719
|
+
const refused = this.stopHandle(a, true, { kind: "stopped-shutdown" });
|
|
2703
2720
|
if (refused === undefined)
|
|
2704
2721
|
stopped.push(a);
|
|
2705
2722
|
else
|
|
@@ -4186,7 +4203,7 @@ export class Manager {
|
|
|
4186
4203
|
if (process.platform === "win32" && target.handle.kind === "pty") {
|
|
4187
4204
|
return this.stopWindowsSeat(target, graceful, true, { kind: "stopped-self" }).then(() => ({ ok: true, data: { name: target.name, stopped: true, graceful } }));
|
|
4188
4205
|
}
|
|
4189
|
-
this.stopHandle(target, graceful);
|
|
4206
|
+
this.stopHandle(target, graceful, { kind: "stopped-self" });
|
|
4190
4207
|
this.trackStoppedHandle(target, true, { kind: "stopped-self" });
|
|
4191
4208
|
return { ok: true, data: { name: target.name, stopped: true, graceful } };
|
|
4192
4209
|
}
|
|
@@ -4206,11 +4223,12 @@ export class Manager {
|
|
|
4206
4223
|
* footprint, nor (in `reapChildrenOf`) abort the reap of later siblings. The failure is logged and
|
|
4207
4224
|
* returned: a caller that must prove exit (shutdown, a failed resume) reports it as the cause at
|
|
4208
4225
|
* once instead of waiting out a stop the runtime already refused. */
|
|
4209
|
-
stopHandle(a, graceful) {
|
|
4226
|
+
stopHandle(a, graceful, cause) {
|
|
4210
4227
|
// The TERMINALIZING latch: flipped SYNCHRONOUSLY, before any await anywhere on
|
|
4211
4228
|
// this stop path — later renewals refuse, while an already-admitted renewal drains before the
|
|
4212
4229
|
// durable terminal begins.
|
|
4213
4230
|
a.terminalizing = true;
|
|
4231
|
+
a.stopCause ??= cause;
|
|
4214
4232
|
try {
|
|
4215
4233
|
// A delegated seat's close runs only inside its retirement, after the host revoked its grant,
|
|
4216
4234
|
// so stopping it starts that retirement. Every exit wait on a stop path then settles on that
|
|
@@ -4234,7 +4252,7 @@ export class Manager {
|
|
|
4234
4252
|
async stopWindowsSeat(a, graceful, floor, cause) {
|
|
4235
4253
|
if (a.once)
|
|
4236
4254
|
a.once.stopReason ??= onceStopReason(cause);
|
|
4237
|
-
const failure = this.stopHandle(a, graceful);
|
|
4255
|
+
const failure = this.stopHandle(a, graceful, cause);
|
|
4238
4256
|
this.lifecycleInFlight++;
|
|
4239
4257
|
try {
|
|
4240
4258
|
if (failure !== undefined)
|
|
@@ -4718,10 +4736,10 @@ export class Manager {
|
|
|
4718
4736
|
this.dropSeatRecord(a);
|
|
4719
4737
|
if (a.seatHome)
|
|
4720
4738
|
rmSync(a.seatHome, { recursive: true, force: true });
|
|
4721
|
-
// End any live §13.6 attach session bound to THIS incarnation with the
|
|
4722
|
-
//
|
|
4723
|
-
//
|
|
4724
|
-
this.sessionPlane?.endForTarget(a.name, a.lifecycleUid, "target-despawn");
|
|
4739
|
+
// End any live §13.6 attach session bound to THIS incarnation with the reason its cause names.
|
|
4740
|
+
// Fires once per agent on every free path (despawn / self-stop / reap / exit) via the `agents`
|
|
4741
|
+
// guard above; a no-op when no plane or no live session for the target.
|
|
4742
|
+
this.sessionPlane?.endForTarget(a.name, a.lifecycleUid, typeof cause === "string" ? FREE_SLOT_ATTACH_END[cause] : "target-despawn");
|
|
4725
4743
|
// The turn relay's reap hook: every pending turn addressed to THIS incarnation is stamped
|
|
4726
4744
|
// with the death, and its deadline terminal carries it as `agentDownAt`. The addressee is gone
|
|
4727
4745
|
// and no successor may answer for it; the terminal is still the deadline's, not a new reason.
|
|
@@ -5220,8 +5238,9 @@ export class Manager {
|
|
|
5220
5238
|
if (child.spawner !== parentId)
|
|
5221
5239
|
continue;
|
|
5222
5240
|
this.reapChildrenOf(this.managedPrincipal(child));
|
|
5223
|
-
|
|
5224
|
-
this.
|
|
5241
|
+
const cause = { kind: "stopped-reap", parent: parentId };
|
|
5242
|
+
this.stopHandle(child, false, cause);
|
|
5243
|
+
this.trackStoppedHandle(child, true, cause, true);
|
|
5225
5244
|
}
|
|
5226
5245
|
}
|
|
5227
5246
|
readSessionStatePath(path) {
|
|
@@ -5328,7 +5347,7 @@ export class Manager {
|
|
|
5328
5347
|
if (refused === undefined || a.terminalizing || a.handle.status() === "exited")
|
|
5329
5348
|
return;
|
|
5330
5349
|
console.error(`! ${refused}; stopping it`);
|
|
5331
|
-
this.stopHandle(a, false);
|
|
5350
|
+
this.stopHandle(a, false, "carried-fork-refused");
|
|
5332
5351
|
this.trackStoppedHandle(a, true, "carried-fork-refused");
|
|
5333
5352
|
}
|
|
5334
5353
|
readManagedSession(a) {
|
|
@@ -5585,10 +5604,11 @@ export class Manager {
|
|
|
5585
5604
|
}
|
|
5586
5605
|
})();
|
|
5587
5606
|
}
|
|
5588
|
-
/** A managed agent's process exited on its own (crash, /exit, finished)
|
|
5589
|
-
*
|
|
5590
|
-
*
|
|
5591
|
-
*
|
|
5607
|
+
/** A managed agent's process exited: on its own (crash, /exit, finished), or after a stop this
|
|
5608
|
+
* manager started, whose recorded cause then frees the slot. Continuation-capable Pi seats
|
|
5609
|
+
* restart in place after readiness; a spawn carrying `supervise` restarts any connector the same
|
|
5610
|
+
* way, without classifying a session-state file. Every other exit follows the existing terminal
|
|
5611
|
+
* path. */
|
|
5592
5612
|
onAgentExit(a) {
|
|
5593
5613
|
// Preservation owns the child-stop snapshot. Exit watchers must neither delete that snapshot nor
|
|
5594
5614
|
// trigger normal deprovision/reap while the cut is being formed.
|
|
@@ -5617,7 +5637,7 @@ export class Manager {
|
|
|
5617
5637
|
console.error(`! ${a.name}: cannot classify Pi process exit for recovery: ${rejectionText(error)} - retiring the seat`);
|
|
5618
5638
|
}
|
|
5619
5639
|
}
|
|
5620
|
-
this.freeSlot(a, true, "process-exit");
|
|
5640
|
+
this.freeSlot(a, true, a.stopCause ?? "process-exit");
|
|
5621
5641
|
this.reapChildrenOf(this.managedPrincipal(a));
|
|
5622
5642
|
}
|
|
5623
5643
|
/** Agent names become `.cotal/agents/<name>.md` paths and mesh identities, so they must be bare
|
|
@@ -5870,7 +5890,7 @@ export class Manager {
|
|
|
5870
5890
|
catch (error) {
|
|
5871
5891
|
const reason = rejectionText(error);
|
|
5872
5892
|
this.bootNotes.push(`! manager boot: connector inventory unavailable - ${reason}`);
|
|
5873
|
-
this.connectorStatuses = [{ agent: "(inventory)", state: "unavailable", binaries: {}, eventPlane: false, reason }];
|
|
5893
|
+
this.connectorStatuses = [{ agent: "(inventory)", state: "unavailable", binaries: {}, eventPlane: false, permissionRequests: false, reason }];
|
|
5874
5894
|
this.bootNotes.push("! manager: no agent application is available here, so a spawn without --on goes to another manager in this space");
|
|
5875
5895
|
return;
|
|
5876
5896
|
}
|
|
@@ -5880,22 +5900,31 @@ export class Manager {
|
|
|
5880
5900
|
name: connector.name,
|
|
5881
5901
|
requires: connector.requires ?? [],
|
|
5882
5902
|
eventPlane: connector.eventChannel !== undefined,
|
|
5903
|
+
permissionRequests: connector.permissionRequests === true,
|
|
5883
5904
|
}));
|
|
5884
5905
|
}
|
|
5885
|
-
for (const { name, requires, eventPlane } of declared) {
|
|
5906
|
+
for (const { name, requires, eventPlane, permissionRequests = false } of declared) {
|
|
5886
5907
|
const { binaries, reason } = resolveHarness(name, requires);
|
|
5887
5908
|
if (reason) {
|
|
5888
|
-
rows.push({ agent: name, state: "unavailable", binaries, eventPlane, reason });
|
|
5909
|
+
rows.push({ agent: name, state: "unavailable", binaries, eventPlane, permissionRequests, reason });
|
|
5889
5910
|
this.bootNotes.push(`! manager boot: connector ${name} unavailable - ${reason}`);
|
|
5890
5911
|
}
|
|
5891
5912
|
else {
|
|
5892
|
-
rows.push({ agent: name, state: "available", binaries, eventPlane });
|
|
5913
|
+
rows.push({ agent: name, state: "available", binaries, eventPlane, permissionRequests });
|
|
5893
5914
|
}
|
|
5894
5915
|
}
|
|
5895
5916
|
this.connectorStatuses = rows.sort((a, b) => a.agent.localeCompare(b.agent));
|
|
5896
5917
|
if (!this.classSpawnEnabled())
|
|
5897
5918
|
this.bootNotes.push("! manager: no agent application is available here, so a spawn without --on goes to another manager in this space");
|
|
5898
5919
|
}
|
|
5920
|
+
/** The connector rows a status read serves. A connector relays permission prompts only where an
|
|
5921
|
+
* owner can answer them, and only a user-auth mesh mints the interactive ledger rows that answer
|
|
5922
|
+
* (SPEC §8.2), so on an open or static mesh every row reads false. The mode is known only after
|
|
5923
|
+
* boot inspects the connectors, so it is applied here. */
|
|
5924
|
+
servedConnectorStatuses() {
|
|
5925
|
+
const answerable = this.meshMode === "user";
|
|
5926
|
+
return this.connectorStatuses.map((row) => ({ ...row, binaries: { ...row.binaries }, permissionRequests: answerable && row.permissionRequests }));
|
|
5927
|
+
}
|
|
5899
5928
|
/** True when at least one declared connector is available. Empty inventory (or a failed
|
|
5900
5929
|
* inventory load) skips the class `one` subscribe for spawn/launch so this member cannot
|
|
5901
5930
|
* consume an unpinned request a sibling could serve. */
|
|
@@ -6443,6 +6472,15 @@ export class Manager {
|
|
|
6443
6472
|
: `spawn: this spawn hands its helper more than the spawner holds: ${named}. A spawner hands on only what its own issued credential carries (SPEC 13.15). ` +
|
|
6444
6473
|
`Drop these from the persona or the spawn, or have the operator widen the spawner's own persona.`;
|
|
6445
6474
|
}
|
|
6475
|
+
/** Ordinary static control seats can read their holding instance. A run's recorded ceiling is
|
|
6476
|
+
* authoritative, so its helpers receive no additional instance reads. */
|
|
6477
|
+
managedStaticInstanceReads(capabilities) {
|
|
6478
|
+
if (this.meshMode !== "static" || !this.managerInstanceId || !capabilities?.some(c => c === "spawn" || c === "run" || c === "admin"))
|
|
6479
|
+
return [];
|
|
6480
|
+
return ["describe", "inspect"].map(command => ({
|
|
6481
|
+
endpoint: MANAGER_ENDPOINT, command, instanceId: this.managerInstanceId, instanceOnly: true,
|
|
6482
|
+
}));
|
|
6483
|
+
}
|
|
6446
6484
|
async startAgentActive(opts, spawner, hooks, authenticatedCaller) {
|
|
6447
6485
|
// Before the first await, so the grant, the launch, the retained form and the restart slot all read
|
|
6448
6486
|
// the lists and the restart policy as admitted.
|
|
@@ -6723,6 +6761,11 @@ export class Manager {
|
|
|
6723
6761
|
if (this.eventPayloadsWithheld && opts.eventPayloads === true)
|
|
6724
6762
|
return { ok: false, error: "space policy withholds event payloads" };
|
|
6725
6763
|
const eventPayloads = !this.eventPayloadsWithheld && (opts.eventPayloads ?? def?.eventPayloads) !== false;
|
|
6764
|
+
if (run === undefined) {
|
|
6765
|
+
const reads = this.managedStaticInstanceReads(capabilities);
|
|
6766
|
+
if (bound.kind === "exempt" || (bound.kind === "bounded" && !grantOverreach(this.space, bound.caller, bound.ceiling, { endpoints: reads }).length))
|
|
6767
|
+
endpoints.push(...reads);
|
|
6768
|
+
}
|
|
6726
6769
|
// THE DELEGATION BOUND, on the grant as it will be minted: every channel and capability the
|
|
6727
6770
|
// helper gets, from the persona, the raw overrides and the `callerAcl` default alike, and its own
|
|
6728
6771
|
// event plane, so no door reaches the mint around it. Before any reserve or mint, so a refusal
|
|
@@ -7445,7 +7488,7 @@ export class Manager {
|
|
|
7445
7488
|
return { ok: false, error: refused };
|
|
7446
7489
|
}
|
|
7447
7490
|
if (refused !== undefined) {
|
|
7448
|
-
this.stopHandle(managed, false);
|
|
7491
|
+
this.stopHandle(managed, false, "carried-fork-refused");
|
|
7449
7492
|
this.trackStoppedHandle(managed, true, "carried-fork-refused");
|
|
7450
7493
|
await hooks?.onOutcome?.({ kind: "failed", data: { error: refused } });
|
|
7451
7494
|
return { ok: false, error: refused };
|
|
@@ -7469,7 +7512,7 @@ export class Manager {
|
|
|
7469
7512
|
}
|
|
7470
7513
|
catch (error) {
|
|
7471
7514
|
const detail = `${managed.name} joined, but its exact host session could not be bound for supervised recovery: ${rejectionText(error)}`;
|
|
7472
|
-
this.stopHandle(managed, false);
|
|
7515
|
+
this.stopHandle(managed, false, "session-bind-failed");
|
|
7473
7516
|
this.trackStoppedHandle(managed, true, "session-bind-failed");
|
|
7474
7517
|
await hooks?.onOutcome?.({ kind: "failed", data: { error: detail } });
|
|
7475
7518
|
return { ok: false, error: detail };
|
|
@@ -7484,7 +7527,7 @@ export class Manager {
|
|
|
7484
7527
|
}
|
|
7485
7528
|
catch (error) {
|
|
7486
7529
|
const detail = `${managed.name} joined, but supervise cannot cover a manager restart for it: ${rejectionText(error)}`;
|
|
7487
|
-
this.stopHandle(managed, false);
|
|
7530
|
+
this.stopHandle(managed, false, "supervise-record-failed");
|
|
7488
7531
|
this.trackStoppedHandle(managed, true, "supervise-record-failed");
|
|
7489
7532
|
await hooks?.onOutcome?.({ kind: "failed", data: { error: detail } });
|
|
7490
7533
|
return { ok: false, error: detail };
|
|
@@ -8246,7 +8289,7 @@ export class Manager {
|
|
|
8246
8289
|
* would reap it: it is freed only once its exit is proved, and otherwise stays managed until it
|
|
8247
8290
|
* exits or the manager stops it. */
|
|
8248
8291
|
async stopFailedResume(managed, cause, detail) {
|
|
8249
|
-
const refused = this.stopHandle(managed, false);
|
|
8292
|
+
const refused = this.stopHandle(managed, false, cause);
|
|
8250
8293
|
const unproven = refused === undefined
|
|
8251
8294
|
? await this.awaitHandleExit(managed.handle).then(() => undefined, rejectionText)
|
|
8252
8295
|
: `stop failed: ${refused}`;
|
|
@@ -8640,8 +8683,9 @@ export class Manager {
|
|
|
8640
8683
|
return { ok: true, data: { name: a.name, stopped: true, graceful } };
|
|
8641
8684
|
});
|
|
8642
8685
|
}
|
|
8643
|
-
|
|
8644
|
-
this.
|
|
8686
|
+
const cause = { kind: "stopped-requested", requester: caller };
|
|
8687
|
+
this.stopHandle(a, graceful, cause);
|
|
8688
|
+
this.trackStoppedHandle(a, trackNonAdmin, cause);
|
|
8645
8689
|
void this.cancelAgentGoal(a.name, graceful ? "graceful" : "terminate"); // Cancel a live spawn goal
|
|
8646
8690
|
return { ok: true, data: { name: a.name, stopped: true, graceful } };
|
|
8647
8691
|
}
|
|
@@ -8867,7 +8911,7 @@ export class Manager {
|
|
|
8867
8911
|
terminalSessions: this.execution !== "none",
|
|
8868
8912
|
agentCount: ownerFilter === undefined ? this.agents.size : [...this.agents.values()].filter((a) => a.userOwner === ownerFilter).length,
|
|
8869
8913
|
uptimeMs: Date.now() - this.startedAtMs,
|
|
8870
|
-
connectors: this.
|
|
8914
|
+
connectors: this.servedConnectorStatuses(),
|
|
8871
8915
|
classSpawn: this.classSpawnEnabled(),
|
|
8872
8916
|
staticReconciliation: this.staticReconciliationStatus(),
|
|
8873
8917
|
stopImpact: {
|
|
@@ -9250,7 +9294,7 @@ export class Manager {
|
|
|
9250
9294
|
// grant (no new grant, no new writer); core refuses on anything but a gate provably
|
|
9251
9295
|
// reopened past the slot's stamp.
|
|
9252
9296
|
observeHolderGeneration: (holderInstanceId) => readEndpointGateGeneration(authKv, { endpoint: MANAGER_ENDPOINT, instanceId: holderInstanceId }),
|
|
9253
|
-
status: { connectors: this.
|
|
9297
|
+
status: { connectors: this.servedConnectorStatuses() },
|
|
9254
9298
|
});
|
|
9255
9299
|
const fence = serveIssuanceGateKv(authKv, this.space, { endpoint: MANAGER_ENDPOINT, instanceId: iid });
|
|
9256
9300
|
// Open mesh: NO mint - the §13.1 fence is issuance-only and nothing is ever issued, so the
|
|
@@ -11020,8 +11064,9 @@ export class Manager {
|
|
|
11020
11064
|
* stop frees the slot first, so this stop reaps them itself. */
|
|
11021
11065
|
stopOnceSeat(a, reason) {
|
|
11022
11066
|
this.reapChildrenOf(this.managedPrincipal(a));
|
|
11023
|
-
|
|
11024
|
-
this.
|
|
11067
|
+
const cause = { kind: "stopped-once", reason };
|
|
11068
|
+
this.stopHandle(a, true, cause);
|
|
11069
|
+
this.trackStoppedHandle(a, false, cause);
|
|
11025
11070
|
void this.cancelAgentGoal(a.name, "graceful");
|
|
11026
11071
|
}
|
|
11027
11072
|
/** The once task's exit hook, on the handle the seat was launched with: whichever path ends the
|
|
@@ -11903,13 +11948,23 @@ export class Manager {
|
|
|
11903
11948
|
// ceiling, which `confirm` verifies against the recorded evidence before the ledger append. A
|
|
11904
11949
|
// changed ceiling is refused there: that is a fresh issuance on a new connection, never a renewal.
|
|
11905
11950
|
const issued = a.issued;
|
|
11951
|
+
const endpoints = lowerPersonaEndpoints(a.launch.endpoints);
|
|
11952
|
+
const reads = this.managedStaticInstanceReads(a.launch.capabilities);
|
|
11953
|
+
if (reads.length) {
|
|
11954
|
+
// Resolve this incarnation's original issuance, not its current spawner or a reconstructed
|
|
11955
|
+
// run admission. Old seats and run helpers keep the exact ceiling they were minted with.
|
|
11956
|
+
const caller = { owner: DEV_OWNER, actor: a.id, uid: a.lifecycleUid, generation: issued.generation };
|
|
11957
|
+
const { evidence } = await withIssuerSession({ servers: this.servers ?? DEFAULT_SERVER, space: this.space, auth: this.auth, tls: false }, (s) => s.store.resolve({ space: this.space, ...caller }, s.sourceIsLive));
|
|
11958
|
+
if (!grantOverreach(this.space, caller, evidence.permissions, { endpoints: reads }).length)
|
|
11959
|
+
endpoints.push(...reads);
|
|
11960
|
+
}
|
|
11906
11961
|
const creds = await this.withIssuer((i) => mintCreds(this.auth, { id: a.id, seed: a.seed }, "agent", {
|
|
11907
11962
|
eventPayloads: this.eventPayloadsWithheld ? false : a.launch.eventPayloads,
|
|
11908
11963
|
allowSubscribe: a.launch.allowSubscribe,
|
|
11909
11964
|
allowPublish: a.launch.allowPublish,
|
|
11910
11965
|
role: a.role,
|
|
11911
11966
|
capabilities: a.launch.capabilities,
|
|
11912
|
-
...(
|
|
11967
|
+
...(endpoints.length ? { endpointCapabilities: endpoints } : {}),
|
|
11913
11968
|
lifecycleUid: a.lifecycleUid,
|
|
11914
11969
|
expiresAt: exp,
|
|
11915
11970
|
issued,
|