agl 43.8.0 → 43.10.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/changelog.md +28 -0
- package/dist_serve/bundle.js +1157 -1122
- package/dist_serve/bundle.js.map +2 -2
- package/dist_ts/00_commitinfo_data.js +2 -2
- package/dist_ts/aglapi/aglapisurface.document.js +826 -8
- package/dist_ts/aglapi/interfaces.d.ts +8 -0
- package/dist_ts/aglapi/interfaces.js +3 -1
- package/dist_ts/classes.accountsactions.d.ts +3 -1
- package/dist_ts/classes.accountsactions.js +17 -1
- package/dist_ts/classes.controller.d.ts +1 -1
- package/dist_ts/classes.controller.js +21 -7
- package/dist_ts/classes.inferencegateway.js +7 -5
- package/dist_ts/classes.inferenceplacement.d.ts +1 -1
- package/dist_ts/classes.inferencerouter.d.ts +20 -3
- package/dist_ts/classes.inferencerouter.js +37 -10
- package/dist_ts/classes.inferenceservice.js +2 -2
- package/dist_ts/classes.mcpclient.js +3 -3
- package/dist_ts/classes.mcpcontrollerhost.js +3 -2
- package/dist_ts/classes.mcptools.d.ts +1 -1
- package/dist_ts/classes.mcptools.js +2 -1
- package/dist_ts/classes.ticketnotifier.d.ts +2 -2
- package/dist_ts/classes.ticketnotifier.js +6 -4
- package/dist_ts/classes.ticketstore.d.ts +36 -8
- package/dist_ts/classes.ticketstore.js +131 -29
- package/dist_ts/classes.workercallers.d.ts +35 -1
- package/dist_ts/classes.workercallers.js +139 -28
- package/dist_ts/fleet/classes.boardpump.d.ts +1 -1
- package/dist_ts/fleet/classes.boardpump.js +4 -2
- package/dist_ts/fleet/classes.ticketeffects.d.ts +11 -0
- package/dist_ts/fleet/classes.ticketeffects.js +28 -1
- package/dist_ts/fleet/classes.workers.d.ts +18 -1
- package/dist_ts/fleet/classes.workers.js +49 -8
- package/dist_ts/fleet/functions.workervalidation.js +7 -4
- package/dist_ts/functions.deviceapi.js +3 -1
- package/dist_ts/functions.fleetworkercli.d.ts +3 -1
- package/dist_ts/functions.fleetworkercli.js +6 -2
- package/dist_ts/functions.inferencecli.js +4 -1
- package/dist_ts/functions.mcpfleetworkertools.js +3 -3
- package/dist_ts/functions.mcptickettools.d.ts +60 -0
- package/dist_ts/functions.mcptickettools.js +4 -3
- package/dist_ts/functions.proxycapacity.d.ts +2 -1
- package/dist_ts/functions.proxycapacity.js +6 -3
- package/dist_ts/functions.proxycapacitycli.js +2 -2
- package/dist_ts/functions.ticketcli.d.ts +4 -2
- package/dist_ts/functions.ticketcli.js +70 -4
- package/dist_ts/functions.ticketlisting.d.ts +38 -0
- package/dist_ts/functions.ticketlisting.js +211 -0
- package/dist_ts/functions.ticketvalidation.d.ts +62 -0
- package/dist_ts/functions.ticketvalidation.js +41 -3
- package/dist_ts/functions.workerprocessproof.d.ts +6 -0
- package/dist_ts/functions.workerprocessproof.js +8 -3
- package/dist_ts/interfaces.auth.d.ts +1 -1
- package/dist_ts/interfaces.auth.js +2 -1
- package/dist_ts/interfaces.flexipc.d.ts +3 -1
- package/dist_ts/interfaces.flexipc.js +1 -1
- package/dist_ts_authswitch/authority-contract.d.ts +25 -0
- package/dist_ts_authswitch/authority-contract.js +1 -1
- package/dist_ts_authswitch/authority-overview.d.ts +7 -0
- package/dist_ts_authswitch/authority-overview.js +10 -6
- package/dist_ts_authswitch/authority-placement.d.ts +5 -2
- package/dist_ts_authswitch/authority-placement.js +6 -3
- package/dist_ts_authswitch/classes.authoritybroker.d.ts +6 -0
- package/dist_ts_authswitch/classes.authoritybroker.js +26 -1
- package/dist_ts_authswitch/classes.authoritycli.d.ts +1 -0
- package/dist_ts_authswitch/classes.authoritycli.js +50 -4
- package/dist_ts_authswitch/classes.authorityclient.d.ts +3 -1
- package/dist_ts_authswitch/classes.authorityclient.js +9 -4
- package/dist_ts_authswitch/classes.authoritydaemon.js +7 -1
- package/dist_ts_authswitch/classes.authoritydatabase.js +5 -1
- package/dist_ts_authswitch/classes.authoritymodels.d.ts +7 -0
- package/dist_ts_authswitch/classes.authoritymodels.js +13 -6
- package/dist_ts_interfaces/fleetworkers.d.ts +26 -1
- package/dist_ts_interfaces/fleetworkers.js +1 -1
- package/dist_ts_interfaces/interfaces.d.ts +4 -2
- package/dist_ts_interfaces/interfaces.js +1 -1
- package/dist_ts_interfaces/mcprequests.d.ts +1 -1
- package/dist_ts_interfaces/proxycapacity.d.ts +1 -1
- package/dist_ts_interfaces/requests.accounts.d.ts +19 -0
- package/dist_ts_interfaces/requests.accounts.js +1 -1
- package/dist_ts_interfaces/requests.d.ts +2 -2
- package/dist_ts_interfaces/requests.fleetworkers.d.ts +3 -1
- package/dist_ts_interfaces/requests.js +1 -1
- package/dist_ts_interfaces/requests.tickets.d.ts +31 -3
- package/dist_ts_interfaces/requests.tickets.js +2 -2
- package/dist_ts_interfaces/tickets.d.ts +174 -2
- package/dist_ts_interfaces/tickets.js +20 -2
- package/dist_ts_migration/v41_ticketclosedcolumn.js +7 -3
- package/docs/authswitch.md +22 -0
- package/package.json +2 -2
- package/readme.md +85 -6
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +825 -7
- package/ts/aglapi/interfaces.ts +2 -0
- package/ts/classes.accountsactions.ts +25 -0
- package/ts/classes.controller.ts +18 -3
- package/ts/classes.inferencegateway.ts +6 -4
- package/ts/classes.inferenceplacement.ts +1 -1
- package/ts/classes.inferencerouter.ts +49 -10
- package/ts/classes.inferenceservice.ts +1 -1
- package/ts/classes.mcpclient.ts +2 -2
- package/ts/classes.mcpcontrollerhost.ts +2 -1
- package/ts/classes.mcptools.ts +1 -0
- package/ts/classes.ticketnotifier.ts +5 -3
- package/ts/classes.ticketstore.ts +124 -27
- package/ts/classes.workercallers.ts +165 -28
- package/ts/fleet/classes.boardpump.ts +3 -2
- package/ts/fleet/classes.ticketeffects.ts +25 -0
- package/ts/fleet/classes.workers.ts +47 -7
- package/ts/fleet/functions.workervalidation.ts +6 -3
- package/ts/functions.deviceapi.ts +2 -0
- package/ts/functions.fleetworkercli.ts +5 -1
- package/ts/functions.inferencecli.ts +2 -0
- package/ts/functions.mcpfleetworkertools.ts +2 -2
- package/ts/functions.mcptickettools.ts +3 -2
- package/ts/functions.proxycapacity.ts +5 -2
- package/ts/functions.proxycapacitycli.ts +1 -1
- package/ts/functions.ticketcli.ts +70 -5
- package/ts/functions.ticketlisting.ts +214 -0
- package/ts/functions.ticketvalidation.ts +41 -2
- package/ts/functions.workerprocessproof.ts +10 -2
- package/ts/interfaces.auth.ts +1 -0
- package/ts/interfaces.flexipc.ts +3 -1
- package/ts_authswitch/authority-contract.ts +20 -0
- package/ts_authswitch/authority-overview.ts +17 -6
- package/ts_authswitch/authority-placement.ts +7 -3
- package/ts_authswitch/classes.authoritybroker.ts +24 -0
- package/ts_authswitch/classes.authoritycli.ts +58 -4
- package/ts_authswitch/classes.authorityclient.ts +11 -4
- package/ts_authswitch/classes.authoritydaemon.ts +8 -1
- package/ts_authswitch/classes.authoritydatabase.ts +3 -0
- package/ts_authswitch/classes.authoritymodels.ts +12 -4
- package/ts_interfaces/fleetworkers.ts +26 -1
- package/ts_interfaces/interfaces.ts +4 -2
- package/ts_interfaces/proxycapacity.ts +1 -1
- package/ts_interfaces/requests.accounts.ts +17 -0
- package/ts_interfaces/requests.fleetworkers.ts +3 -1
- package/ts_interfaces/requests.tickets.ts +32 -2
- package/ts_interfaces/requests.ts +2 -0
- package/ts_interfaces/tickets.ts +136 -3
- package/ts_migration/v41_ticketclosedcolumn.ts +6 -2
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/accounts.templates.ts +12 -2
- package/ts_web/classes.accountsreadmodel.ts +42 -6
- package/ts_web/elements.accounts.ts +45 -3
- package/ts_web/elements.harnesscontrollerapp.ts +6 -1
- package/ts_web/elements.inbox.ts +50 -9
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
type IWorkerCallerReadiness, type TWorkerCallerEnrollment, type IWorkerCallerEnrollmentResponse,
|
|
7
7
|
type IConfigurationMaster, type IConfigurationMcpStdioServer, type IControllerMcpCaller, type IControllerMcpWireCaller,
|
|
8
8
|
type IWorkerClaudeJobRequest, type TWorkerClaudeJobObservation,
|
|
9
|
-
type IWorkerClaudeProcessRequest, type TWorkerClaudeProcessIdentification,
|
|
9
|
+
type IWorkerClaudeProcessRequest, type TWorkerClaudeProcessIdentification, type IFleetWorkerIdentity,
|
|
10
10
|
} from '../ts_interfaces/index.js';
|
|
11
11
|
import { anonymousControllerMcpCaller, ControllerMcpCallerRegistry } from './classes.mcpcallerregistry.js';
|
|
12
12
|
import {
|
|
13
13
|
resolveWorkerBridgeCommand, resolveClaudeWorkerExecutable, verifyClaudeWorkerProcess, verifyClaudeReleaseProcess,
|
|
14
14
|
readWorkerBridge, verifyWorkerBridge, readWorkerProcessSnapshot, workerSnapshotsEqual, WorkerCallerProofError, WorkerProcessChangedError,
|
|
15
|
-
isWorkerCallerProofRefusal,
|
|
15
|
+
isWorkerCallerProofRefusal, inClaudeReleaseDirectory,
|
|
16
16
|
type IWorkerCallerConnection, type IWorkerProcessSnapshot, type IWorkerBridgeCommand,
|
|
17
17
|
} from './functions.workerprocessproof.js';
|
|
18
18
|
import {
|
|
@@ -88,9 +88,47 @@ export interface IWorkerProcessRefusal {
|
|
|
88
88
|
nativeSessionId?: string;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
/**
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Every reason a fleet worker shows as unverified for (`IFleetWorkerIdentity.reason`, AGL-1888): fixed phrases, so the
|
|
93
|
+
* views, the ticket notice and its key never carry error text, a path or an id, and one cause is one notice.
|
|
94
|
+
*/
|
|
95
|
+
export const workerUnverifiedReasons = [
|
|
96
|
+
'the process its bridge runs under runs a Claude Code release that is no longer installed',
|
|
97
|
+
'a fleet wake of its worker is in flight',
|
|
98
|
+
'its worker changed in the fleet while its process was identified',
|
|
99
|
+
'its caller record could not be bound',
|
|
100
|
+
'its worker\'s caller record changed while it was enrolled',
|
|
101
|
+
'the approved Claude Code release cannot be resolved',
|
|
102
|
+
'the process of its Claude job is not an installed Claude Code release',
|
|
103
|
+
'its bridge is not proved to be a direct child of the process of its Claude job',
|
|
104
|
+
] as const;
|
|
105
|
+
export type TWorkerUnverifiedReason = (typeof workerUnverifiedReasons)[number];
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A process enrollment's refusal once the fleet identified the bridge's parent as the process of the worker's job, so
|
|
109
|
+
* checks 1–4 passed: the refused call is the worker's (`refusedWorker`), and its reason one of the fixed phrases.
|
|
110
|
+
*/
|
|
111
|
+
interface IWorkerIdentifiedRefusal extends IWorkerProcessRefusal {
|
|
112
|
+
reason: TWorkerUnverifiedReason;
|
|
113
|
+
workerId: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The outcome of a process enrollment: the bridge's enrollment answer, a refusal (`forGood` when it is remembered for the
|
|
118
|
+
* process's life; `identified` once checks 1–4 passed), or a refusal remembered from before.
|
|
119
|
+
*/
|
|
120
|
+
type TProcessEnrollment = { kind: 'enrolled'; response: IWorkerCallerEnrollmentResponse }
|
|
121
|
+
| { kind: 'refused'; refusal: IWorkerProcessRefusal; forGood: boolean; identified: false }
|
|
122
|
+
| { kind: 'refused'; refusal: IWorkerIdentifiedRefusal; forGood: boolean; identified: true } | { kind: 'remembered' };
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The refused calls of a fleet worker's bridges since its last verified one (AGL-1888): when the first came, and the
|
|
126
|
+
* reason the worker shows as unverified for, once it does.
|
|
127
|
+
*/
|
|
128
|
+
interface IWorkerRefusedCalls {
|
|
129
|
+
since: number;
|
|
130
|
+
shown?: TWorkerUnverifiedReason;
|
|
131
|
+
}
|
|
94
132
|
|
|
95
133
|
/**
|
|
96
134
|
* The outcome of a job re-proof: the launch is bound to the bridge's process, the bridge is refused (or was refused
|
|
@@ -121,6 +159,12 @@ export interface IControllerWorkerCallerOptions {
|
|
|
121
159
|
identifyClaudeProcess?(request: IWorkerClaudeProcessRequest): Promise<TWorkerClaudeProcessIdentification>;
|
|
122
160
|
/** Where the reason a worker enrollment stays pending is written once; the controller log by default. */
|
|
123
161
|
log?(line: string): void;
|
|
162
|
+
/**
|
|
163
|
+
* Told when a fleet worker shows as unverified (`workerCallerIdentity`), each time the reason it shows changes, and
|
|
164
|
+
* when its next verified call or its revocation clears that (`undefined`): the fleet's views follow it, and the fleet
|
|
165
|
+
* notices the worker's ticket.
|
|
166
|
+
*/
|
|
167
|
+
workerIdentityChanged?(workerId: string, identity: IFleetWorkerIdentity | undefined): void;
|
|
124
168
|
}
|
|
125
169
|
|
|
126
170
|
export interface IWorkerCallerProcessProof {
|
|
@@ -140,6 +184,10 @@ const maximumRefusals = 64;
|
|
|
140
184
|
/** Bridge images and parent processes a process enrollment refused, each a key; the oldest give way. */
|
|
141
185
|
const maximumProcessRefusals = 1024;
|
|
142
186
|
const maximumLoggedReasons = 4096;
|
|
187
|
+
/** How long the refused calls of a named worker's bridges run, since its last verified call, before it shows as unverified. */
|
|
188
|
+
const unverifiedAfterMs = 60_000;
|
|
189
|
+
/** Workers whose refused calls are remembered; the oldest give way. */
|
|
190
|
+
const maximumRefusedWorkers = 1024;
|
|
143
191
|
/** A message as a clause of a pending reason, without its final period: the log line ends the sentence. */
|
|
144
192
|
const clause = (messageArg: string): string => messageArg.replace(/\.+$/u, '');
|
|
145
193
|
const proofReason = (errorArg: unknown): string => errorArg instanceof WorkerCallerProofError
|
|
@@ -176,6 +224,8 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
176
224
|
* under it wait for that one read, until the fleet adopts or re-binds a worker.
|
|
177
225
|
*/
|
|
178
226
|
private readonly identifications = new Map<string, { epoch: number; identification: Promise<TWorkerClaudeProcessIdentification> }>();
|
|
227
|
+
/** Per fleet worker, its bridges' refused calls since its last verified one (`refusedWorker`), in memory only. */
|
|
228
|
+
private readonly refusedCalls = new Map<string, IWorkerRefusedCalls>();
|
|
179
229
|
private closed = false;
|
|
180
230
|
private readonly proof: IWorkerCallerProcessProof;
|
|
181
231
|
private readonly log: (lineArg: string) => void;
|
|
@@ -267,6 +317,8 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
267
317
|
this.refusalEpoch += 1;
|
|
268
318
|
const record = this.workers.get(workerId);
|
|
269
319
|
if (record) this.markRevoked(record);
|
|
320
|
+
// Stopped, archived, re-bound or failed: what its refused calls showed was of the job's process before.
|
|
321
|
+
this.clearRefusedCalls(workerId);
|
|
270
322
|
if (forGood) await this.options.bindings?.delete(workerId);
|
|
271
323
|
return record;
|
|
272
324
|
});
|
|
@@ -349,6 +401,17 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
349
401
|
});
|
|
350
402
|
}
|
|
351
403
|
|
|
404
|
+
/**
|
|
405
|
+
* Whether the fleet worker `workerIdArg`'s MCP calls run without its identity (AGL-1888): shown once a bridge the
|
|
406
|
+
* fleet identified as the worker's was refused for good, or its refused calls since its last verified one spanned
|
|
407
|
+
* `unverifiedAfterMs`; cleared by its next verified call or its revocation (a stop, an archive, a re-bind). Derived
|
|
408
|
+
* from those calls alone: no timer and no sweep, so a worker that does not call never shows.
|
|
409
|
+
*/
|
|
410
|
+
public workerCallerIdentity(workerIdArg: string): IFleetWorkerIdentity | undefined {
|
|
411
|
+
const refused = this.refusedCalls.get(workerIdArg);
|
|
412
|
+
return refused?.shown === undefined ? undefined : { unverified: true, reason: refused.shown, since: new Date(refused.since).toISOString() };
|
|
413
|
+
}
|
|
414
|
+
|
|
352
415
|
public clearCallerRefusals(): void {
|
|
353
416
|
this.refusalEpoch += 1;
|
|
354
417
|
this.processRefusals.clear();
|
|
@@ -462,12 +525,17 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
462
525
|
if (this.closed) return pending();
|
|
463
526
|
const outcome = await this.identifyProcess(bridgePidArg, connectionArg);
|
|
464
527
|
if (outcome.kind === 'enrolled') return outcome.response;
|
|
465
|
-
if (outcome.kind === 'refused')
|
|
528
|
+
if (outcome.kind === 'refused') {
|
|
529
|
+
this.noteProcessRefusal(outcome.refusal);
|
|
530
|
+
// Only a call the fleet identified as the worker's (checks 1–4 passed) shows it. A refusal the fleet answered for a
|
|
531
|
+
// worker it named (a lost or pending dispatch, its state, its profile home) is on the worker's record already.
|
|
532
|
+
if (outcome.identified) this.refusedWorker(outcome.refusal.workerId, outcome.refusal.reason, outcome.forGood);
|
|
533
|
+
}
|
|
466
534
|
return pending();
|
|
467
535
|
}
|
|
468
536
|
|
|
469
537
|
private async identifyProcess(bridgePidArg: number, connectionArg?: IWorkerCallerConnection): Promise<TProcessEnrollment> {
|
|
470
|
-
const refused = (refusalArg: IWorkerProcessRefusal): TProcessEnrollment => ({ kind: 'refused', refusal: refusalArg });
|
|
538
|
+
const refused = (refusalArg: IWorkerProcessRefusal): TProcessEnrollment => ({ kind: 'refused', refusal: refusalArg, forGood: false, identified: false });
|
|
471
539
|
// The epoch the local proof below begins in; the fleet's identification carries the epoch it began in.
|
|
472
540
|
const started = this.refusalEpoch;
|
|
473
541
|
// The bridge's image and the process it runs under directly, as the kernel shows them; nothing is proved by them yet.
|
|
@@ -501,18 +569,26 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
501
569
|
if (!workerSnapshotsEqual(bridge, image)) return refused({ check: 'bridge', reason: 'its bridge process changed while it was proved' });
|
|
502
570
|
// Remembered only while no adoption, re-bind or revoke happened since the evidence for it began to be read (`epochArg`): one
|
|
503
571
|
// read before may name the registry as it was, and would refuse the session just adopted for the process's life.
|
|
504
|
-
const remember = (forGoodArg: boolean, epochArg: number):
|
|
505
|
-
if (epochArg !== this.refusalEpoch) return;
|
|
572
|
+
const remember = (forGoodArg: boolean, epochArg: number): boolean => {
|
|
573
|
+
if (epochArg !== this.refusalEpoch) return false;
|
|
506
574
|
for (const key of keys) {
|
|
507
575
|
this.processRefusals.delete(key);
|
|
508
576
|
if (this.processRefusals.size >= maximumProcessRefusals) this.processRefusals.delete(this.processRefusals.keys().next().value!);
|
|
509
577
|
this.processRefusals.set(key, forGoodArg ? Number.POSITIVE_INFINITY : Date.now() + transientRefusalMs);
|
|
510
578
|
}
|
|
579
|
+
return true;
|
|
511
580
|
};
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
581
|
+
// A refusal holds for good only once it is remembered for the process's life.
|
|
582
|
+
const refuse = (refusalArg: IWorkerProcessRefusal, forGoodArg: boolean, epochArg: number): TProcessEnrollment => (
|
|
583
|
+
{ kind: 'refused', refusal: refusalArg, forGood: remember(forGoodArg, epochArg) && forGoodArg, identified: false });
|
|
584
|
+
// The parent, read again after the fleet's inventory: it ran unchanged across the read.
|
|
585
|
+
const unchanged = async (): Promise<boolean> => {
|
|
586
|
+
try { return workerSnapshotsEqual(parent, await this.proof.readProcess(parent.pid)); } catch (errorArg) {
|
|
587
|
+
if (!isWorkerCallerProofRefusal(errorArg)) throw errorArg;
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
515
590
|
};
|
|
591
|
+
const identify = this.options.identifyClaudeProcess;
|
|
516
592
|
// 5. Its parent runs an installed Claude Code release, as `reprove` requires of a job's next process: a local read of
|
|
517
593
|
// the process, before anything of the fleet is read, so a shell or a terminal the bridge runs under is refused for
|
|
518
594
|
// the process's life without an inventory read.
|
|
@@ -527,13 +603,28 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
527
603
|
if (errorArg instanceof WorkerProcessChangedError) {
|
|
528
604
|
return refuse({ check: 'release', reason: 'the process its bridge runs under changed while its release was proved' }, false, started);
|
|
529
605
|
}
|
|
530
|
-
|
|
606
|
+
if (!inClaudeReleaseDirectory(parent.executable, release)) {
|
|
607
|
+
return refuse({ check: 'release', reason: 'the process its bridge runs under is not an installed Claude Code release' }, true, started);
|
|
608
|
+
}
|
|
609
|
+
// A process in the directory of Claude Code's releases whose release file fails the check runs a release removed
|
|
610
|
+
// or replaced since it started: still a Claude job, so the fleet names its worker, for this refusal only (AGL-1888).
|
|
611
|
+
const removed = 'the process its bridge runs under runs a Claude Code release that is no longer installed';
|
|
612
|
+
if (!identify) return refuse({ check: 'release', reason: removed }, true, started);
|
|
613
|
+
const { epoch, identification } = this.identifyOnce(parent, identify);
|
|
614
|
+
const identified = await identification;
|
|
615
|
+
if (!await unchanged()) return refuse({ check: 'release', reason: 'the process its bridge runs under changed while the inventory was read' }, false, epoch);
|
|
616
|
+
if (identified.state === 'identified') {
|
|
617
|
+
return { kind: 'refused', refusal: { check: 'release', reason: removed, workerId: identified.workerId, nativeSessionId: identified.nativeSessionId },
|
|
618
|
+
forGood: remember(true, epoch), identified: true };
|
|
619
|
+
}
|
|
620
|
+
// An inventory that could not name the job yet is asked again after the short wait.
|
|
621
|
+
return refuse({ check: 'release', reason: removed, ...(identified.workerId ? { workerId: identified.workerId } : {}),
|
|
622
|
+
...(identified.nativeSessionId ? { nativeSessionId: identified.nativeSessionId } : {}) }, identified.forGood, epoch);
|
|
531
623
|
}
|
|
532
624
|
if (!workerSnapshotsEqual(job, parent)) {
|
|
533
625
|
return refuse({ check: 'release', reason: 'the process its bridge runs under changed while its release was proved' }, false, started);
|
|
534
626
|
}
|
|
535
627
|
// 3 and 4. One fresh read of the fleet's inventory and registry for every enrollment waiting under this process.
|
|
536
|
-
const identify = this.options.identifyClaudeProcess;
|
|
537
628
|
if (!identify) return refused({ check: 'inventory', reason: 'no fleet identifies the job its bridge runs under' });
|
|
538
629
|
const { epoch, identification } = this.identifyOnce(parent, identify);
|
|
539
630
|
const identified = await identification;
|
|
@@ -542,11 +633,8 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
542
633
|
...(identified.nativeSessionId ? { nativeSessionId: identified.nativeSessionId } : {}) }, identified.forGood, epoch);
|
|
543
634
|
}
|
|
544
635
|
const named = { workerId: identified.workerId, nativeSessionId: identified.nativeSessionId };
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
if (!isWorkerCallerProofRefusal(errorArg)) throw errorArg;
|
|
548
|
-
}
|
|
549
|
-
if (!after || !workerSnapshotsEqual(parent, after)) {
|
|
636
|
+
// Check 3 holds only for a parent that ran unchanged across the read: until then the call is not the worker's.
|
|
637
|
+
if (!await unchanged()) {
|
|
550
638
|
return refuse({ check: 'inventory', reason: 'the process its bridge runs under changed while the inventory was read', ...named }, false, epoch);
|
|
551
639
|
}
|
|
552
640
|
const outcome = await this.enrollIdentified(identified, epoch, job, command, bridgePidArg, connectionArg);
|
|
@@ -565,7 +653,9 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
565
653
|
parentArg: IWorkerProcessSnapshot, commandArg: IWorkerBridgeCommand, bridgePidArg: number,
|
|
566
654
|
connectionArg?: IWorkerCallerConnection): Promise<Exclude<TProcessEnrollment, { kind: 'remembered' }>> {
|
|
567
655
|
const workerId = identifiedArg.workerId;
|
|
568
|
-
|
|
656
|
+
// Every refusal here is the worker's: the fleet identified the bridge's parent as its job's process.
|
|
657
|
+
const refuse = (reasonArg: TWorkerUnverifiedReason): Exclude<TProcessEnrollment, { kind: 'remembered' }> => ({ kind: 'refused',
|
|
658
|
+
refusal: { check: 'record', reason: reasonArg, workerId, nativeSessionId: identifiedArg.nativeSessionId }, forGood: false, identified: true });
|
|
569
659
|
const state = (recordArg: IWorkerLaunch): IWorkerLaunch['state'] => recordArg.state;
|
|
570
660
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
571
661
|
const current = this.workers.get(workerId);
|
|
@@ -573,7 +663,7 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
573
663
|
// A record bound for another bridge of the same job right now: its bind runs on the record's chain.
|
|
574
664
|
if (!current.kept && state(current) !== 'bound') await this.serialize(current, async () => undefined);
|
|
575
665
|
if (state(current) === 'prepared' || state(current) === 'quiescing') {
|
|
576
|
-
return
|
|
666
|
+
return refuse('a fleet wake of its worker is in flight');
|
|
577
667
|
}
|
|
578
668
|
if (state(current) === 'bound') {
|
|
579
669
|
const response = await this.enrollClaude(current, bridgePidArg, connectionArg);
|
|
@@ -607,7 +697,7 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
607
697
|
return { record, binding };
|
|
608
698
|
});
|
|
609
699
|
if (created === 'stale') {
|
|
610
|
-
return
|
|
700
|
+
return refuse('its worker changed in the fleet while its process was identified');
|
|
611
701
|
}
|
|
612
702
|
if (!created) {
|
|
613
703
|
if (this.closed) break;
|
|
@@ -615,11 +705,14 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
615
705
|
}
|
|
616
706
|
try { await created.binding; } catch (errorArg) {
|
|
617
707
|
await this.revokeWorkerCaller({ launchId: created.record.launch.launchId, reason: 'failure' });
|
|
618
|
-
|
|
708
|
+
// The store's or the proof's words go to the controller log only; the refusal names the fixed reason.
|
|
709
|
+
this.log(`The caller record of fleet worker ${workerId} (claude:${identifiedArg.nativeSessionId}) could not be bound: `
|
|
710
|
+
+ `${errorArg instanceof Error ? clause(errorArg.message) : 'unknown failure'}.`);
|
|
711
|
+
return refuse('its caller record could not be bound');
|
|
619
712
|
}
|
|
620
713
|
return { kind: 'enrolled', response: await this.enrollClaude(created.record, bridgePidArg, connectionArg) };
|
|
621
714
|
}
|
|
622
|
-
return
|
|
715
|
+
return refuse('its worker\'s caller record changed while it was enrolled');
|
|
623
716
|
}
|
|
624
717
|
|
|
625
718
|
/** The current, verified record of a worker that is bound to `processArg`: the same PID and start. */
|
|
@@ -662,6 +755,41 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
662
755
|
this.log(`The MCP caller of ${subject} stays unverified: ${refusalArg.reason}.`);
|
|
663
756
|
}
|
|
664
757
|
|
|
758
|
+
/**
|
|
759
|
+
* A refused call of a bridge the fleet identified as the worker `workerIdArg`'s (AGL-1888). The worker shows as
|
|
760
|
+
* unverified once a refusal holds for good, or once its refused calls since its last verified one span
|
|
761
|
+
* `unverifiedAfterMs`, and that is told (`workerIdentityChanged`). Once it shows, only a refusal for good for another
|
|
762
|
+
* reason changes the reason it shows and is told again: a refusal that may pass never is, so the owner's own steps
|
|
763
|
+
* (a stop, a wake) write no second notice.
|
|
764
|
+
*/
|
|
765
|
+
private refusedWorker(workerIdArg: string, reasonArg: TWorkerUnverifiedReason, forGoodArg: boolean): void {
|
|
766
|
+
const now = Date.now();
|
|
767
|
+
let refused = this.refusedCalls.get(workerIdArg);
|
|
768
|
+
if (!refused) {
|
|
769
|
+
if (this.refusedCalls.size >= maximumRefusedWorkers) {
|
|
770
|
+
const [oldest, given] = this.refusedCalls.entries().next().value!;
|
|
771
|
+
this.refusedCalls.delete(oldest);
|
|
772
|
+
if (given.shown !== undefined) this.options.workerIdentityChanged?.(oldest, undefined);
|
|
773
|
+
}
|
|
774
|
+
refused = { since: now };
|
|
775
|
+
this.refusedCalls.set(workerIdArg, refused);
|
|
776
|
+
}
|
|
777
|
+
if (refused.shown !== undefined ? (!forGoodArg || refused.shown === reasonArg) : (!forGoodArg && now - refused.since < unverifiedAfterMs)) return;
|
|
778
|
+
refused.shown = reasonArg;
|
|
779
|
+
this.options.workerIdentityChanged?.(workerIdArg, this.workerCallerIdentity(workerIdArg));
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* A verified call of the fleet worker `workerIdArg`, or its revocation (a stop, an archive, a re-bind): its refused
|
|
784
|
+
* calls are forgotten, and it no longer shows as unverified.
|
|
785
|
+
*/
|
|
786
|
+
private clearRefusedCalls(workerIdArg: string): void {
|
|
787
|
+
const refused = this.refusedCalls.get(workerIdArg);
|
|
788
|
+
if (!refused) return;
|
|
789
|
+
this.refusedCalls.delete(workerIdArg);
|
|
790
|
+
if (refused.shown !== undefined) this.options.workerIdentityChanged?.(workerIdArg, undefined);
|
|
791
|
+
}
|
|
792
|
+
|
|
665
793
|
/**
|
|
666
794
|
* Proves the bridge's process to be the current process of the job the launch is bound to, from a fresh inventory the
|
|
667
795
|
* fleet reads, and binds the launch to it at the current revision. A bridge refused for good is remembered for its
|
|
@@ -704,6 +832,12 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
704
832
|
record.refusals.set(key, forGoodArg ? Number.POSITIVE_INFINITY : Date.now() + transientRefusalMs);
|
|
705
833
|
return { kind: 'refused', reason: reasonArg };
|
|
706
834
|
};
|
|
835
|
+
// Refused once the inventory showed the bridge's parent to be the process of the worker's job: the refused call is
|
|
836
|
+
// the worker's (`refusedWorker`), unless its launch was revoked meanwhile (a stop, an archive or a re-bind clears it).
|
|
837
|
+
const refuseNamed = (reasonArg: TWorkerUnverifiedReason, forGoodArg: boolean): TReproof => {
|
|
838
|
+
if (!this.revoked(record)) this.refusedWorker(record.launch.workerId, reasonArg, forGoodArg);
|
|
839
|
+
return refuse(reasonArg, forGoodArg);
|
|
840
|
+
};
|
|
707
841
|
const observed = await observe({ workerId: record.launch.workerId, projectId: record.launch.projectId,
|
|
708
842
|
nativeSessionId: binding.nativeSessionId, jobId: binding.claudeJobId });
|
|
709
843
|
if (observed.state === 'ended') return { kind: 'ended', reason: observed.reason };
|
|
@@ -732,17 +866,17 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
732
866
|
// resolves to now; a job Claude Code continues on the release it started on is the same job (AGL-1888).
|
|
733
867
|
let release: string;
|
|
734
868
|
try { release = await this.proof.resolveClaude(); } catch {
|
|
735
|
-
return
|
|
869
|
+
return refuseNamed('the approved Claude Code release cannot be resolved', false);
|
|
736
870
|
}
|
|
737
871
|
try { parent = await this.proof.verifyClaudeRelease(observed.process, release); } catch (errorArg) {
|
|
738
872
|
if (!isWorkerCallerProofRefusal(errorArg)) throw errorArg;
|
|
739
|
-
return
|
|
873
|
+
return refuseNamed('the process of its Claude job is not an installed Claude Code release', false);
|
|
740
874
|
}
|
|
741
875
|
executable = parent.executable;
|
|
742
876
|
}
|
|
743
877
|
try { await this.proof.verifyBridge(connectionArg, bridge.pid, command, parent, port); } catch (errorArg) {
|
|
744
878
|
if (!isWorkerCallerProofRefusal(errorArg)) throw errorArg;
|
|
745
|
-
return
|
|
879
|
+
return refuseNamed('its bridge is not proved to be a direct child of the process of its Claude job', true);
|
|
746
880
|
}
|
|
747
881
|
record.claudeExecutable = executable;
|
|
748
882
|
try {
|
|
@@ -912,11 +1046,13 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
912
1046
|
if (challengeArg !== undefined) this.clearChallenge(recordArg);
|
|
913
1047
|
const previous = recordArg.credentials.get(bridgePidArg);
|
|
914
1048
|
if (previous && workerSnapshotsEqual(previous.bridge, bridge) && previous.bindingRevision === revision) {
|
|
1049
|
+
this.clearRefusedCalls(recordArg.launch.workerId);
|
|
915
1050
|
return { ...this.getWorkerCallerStatus(recordArg.launch.launchId), credential: previous.credential };
|
|
916
1051
|
}
|
|
917
1052
|
this.clearCredentials(recordArg);
|
|
918
1053
|
await this.drain(recordArg);
|
|
919
|
-
|
|
1054
|
+
// Revoked or bound again while its leases drained: the bridge stays pending, as for any change before.
|
|
1055
|
+
if (this.closed || recordArg.state !== 'bound' || recordArg.revision !== revision) return pending();
|
|
920
1056
|
const credential = this.options.registry.mintWorker({ kind: 'worker_launch', launchId: recordArg.launch.launchId,
|
|
921
1057
|
controllerGeneration: this.options.controllerGeneration, bindingRevision: revision,
|
|
922
1058
|
projectId: recordArg.launch.projectId, harnessId: recordArg.launch.harnessId,
|
|
@@ -925,6 +1061,7 @@ export class ControllerWorkerCallers implements IFleetWorkerCallerHooks {
|
|
|
925
1061
|
// A worker id is `${projectId}:${name}`: prepared and kept launches are refused otherwise.
|
|
926
1062
|
workerName: recordArg.launch.workerId.slice(recordArg.launch.projectId.length + 1) });
|
|
927
1063
|
recordArg.credentials.set(bridgePidArg, { credential, bridge, bindingRevision: revision });
|
|
1064
|
+
this.clearRefusedCalls(recordArg.launch.workerId);
|
|
928
1065
|
return { ...this.getWorkerCallerStatus(recordArg.launch.launchId), credential };
|
|
929
1066
|
});
|
|
930
1067
|
}
|
|
@@ -6,7 +6,7 @@ import type { IFleetBoardPumpConfiguration, IFleetRepository, IFleetUnboundDrive
|
|
|
6
6
|
import type { IFleetDeployPlan, IFleetDeployStatus, IFleetDeployTargetStatus } from '../../ts_interfaces/deployments.js';
|
|
7
7
|
import type { IFleetEvent } from '../../ts_interfaces/fleetworkers.js';
|
|
8
8
|
import type { IControllerFleetWorkerView } from '../../ts_interfaces/index.js';
|
|
9
|
-
import type
|
|
9
|
+
import { workerIdentityActor, type FleetTicketEffects, type IFleetTicketEffectDocument } from './classes.ticketeffects.js';
|
|
10
10
|
import { quoteAgentMessageHeaderText } from '../functions.agentmessage.js';
|
|
11
11
|
import { unboundDriverLines } from './functions.unbounddrivers.js';
|
|
12
12
|
import { compareFleetVersions, findFleetRepository, fleetRepositorySlug } from './functions.releasefacts.js';
|
|
@@ -113,7 +113,8 @@ const clip = (textArg: string, maximumArg = 32 * 1024): string => {
|
|
|
113
113
|
};
|
|
114
114
|
/** The facts of one history; see `IBoardPumpTicketFacts`. */
|
|
115
115
|
const ticketFacts = ({ ticket, activity, questions }: ITicketHistory): IBoardPumpTicketFacts => {
|
|
116
|
-
|
|
116
|
+
// The pump's own comments and the worker identity notice (AGL-1888) are AGL's, never an answer: neither hides a comment nobody followed.
|
|
117
|
+
const own = (entryArg: ITicketActivity) => entryArg.actor.id === boardPumpActor.id || entryArg.actor.id === workerIdentityActor.id;
|
|
117
118
|
const index = activity.findLastIndex((entryArg) => discussionActions.has(entryArg.action) && !own(entryArg));
|
|
118
119
|
const entry = activity[index];
|
|
119
120
|
const comment = entry && entry.action === 'commented' && entry.actor.role !== 'driver' ? entry.changes.comment?.after as ITicketComment | undefined : undefined;
|
|
@@ -8,6 +8,11 @@ import { releasedEvents } from './classes.releasereconciler.js';
|
|
|
8
8
|
|
|
9
9
|
/** How often an effect whose ticket transaction met a concurrent change is tried again before it is marked failed. */
|
|
10
10
|
export const fleetTicketEffectRetries = 4;
|
|
11
|
+
/**
|
|
12
|
+
* Who writes the notice that a fleet worker's MCP calls run without its identity (AGL-1888): the controller, in the
|
|
13
|
+
* driver role. `TicketNotifier` skips it, so the notice never steers the worker it is about.
|
|
14
|
+
*/
|
|
15
|
+
export const workerIdentityActor: ITicketActor = { id: 'agl:worker-identity', name: 'AGL worker identity', role: 'driver' };
|
|
11
16
|
|
|
12
17
|
export interface IFleetTicketEffectDocument {
|
|
13
18
|
id: string; owner: string; request: TTicketFleetEvent; state: IFleetTicketEffect['state']; updateId: string;
|
|
@@ -189,6 +194,26 @@ export class FleetTicketEffects {
|
|
|
189
194
|
const { effect, commentId } = await this.dispatch(await this.prepare(owner, event, `${worker.harness}:${worker.nativeId}`), signal);
|
|
190
195
|
return { sync: this.summary([effect]), ...(commentId ? { commentId } : {}) };
|
|
191
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Notices on the worker's ticket that its MCP calls run without its identity for `reason` (AGL-1888), once per
|
|
199
|
+
* worker, session, ticket and reason: the key and its board receipt are durable, so a notice applied before a
|
|
200
|
+
* restart is never written again. Resolves with the sync of the notice it dispatched, undefined for one applied before.
|
|
201
|
+
*/
|
|
202
|
+
public async unverifiedCaller(owner: string, worker: IFleetWorker, reason: string, signal?: AbortSignal): Promise<IFleetTicketSync | undefined> {
|
|
203
|
+
if (!worker.ticketKey || !worker.nativeId || !reason.trim()) throw new Error('A caller identity notice requires the worker\'s ticket, native session and reason.');
|
|
204
|
+
const body = `Fleet worker ${worker.name} (${worker.harness}:${worker.nativeId}) calls AGL without its identity: its MCP bridge called the `
|
|
205
|
+
+ `controller and was traced to this worker, but the controller refused to verify it: ${reason}.\n`
|
|
206
|
+
+ 'Until one of its calls is verified, its MCP calls are anonymous, so its ticket writes are refused and nothing it does is attributed to it. '
|
|
207
|
+
+ 'Nothing was sent to the worker.\n'
|
|
208
|
+
+ `What the owner can do: stop ${worker.name} and steer it again, so Claude Code continues its job in a new process whose MCP bridge proves `
|
|
209
|
+
+ 'itself at its first call; or, if its lane continues in another session, re-bind the worker onto that session (agl fleet worker adopt … --rebind). '
|
|
210
|
+
+ '`agl fleet worker list` shows the worker\'s identity as unverified until its next verified call.';
|
|
211
|
+
const identity = plugins.crypto.createHash('sha256').update(JSON.stringify([owner, worker.id, worker.ticketKey, worker.harness, worker.nativeId, reason, body])).digest('hex');
|
|
212
|
+
const prepared = await this.prepare(owner, { ticketKey: worker.ticketKey, actor: this.actor(workerIdentityActor), kind: 'comment', body,
|
|
213
|
+
idempotencyKey: `fleet:caller-identity:${identity}` });
|
|
214
|
+
if (prepared.state === 'applied') return undefined;
|
|
215
|
+
return this.summary([(await this.dispatch(prepared, signal)).effect]);
|
|
216
|
+
}
|
|
192
217
|
public async lostDispatch(owner: string, worker: IFleetWorker, signal?: AbortSignal): Promise<IFleetTicketSync> {
|
|
193
218
|
const lost = worker.lostDispatch;
|
|
194
219
|
if (!lost || !worker.ticketKey) throw new Error('Lost dispatch comment requires a durable attributed resolution and ticket.');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as plugins from '../plugins.js';
|
|
2
2
|
import { controllerRuntimeIdKey, type IWorkerClaudeJobRequest, type TWorkerClaudeJobObservation, type IWorkerClaudeProcessRequest,
|
|
3
3
|
type TWorkerClaudeProcessIdentification } from '../../ts_interfaces/index.js';
|
|
4
|
-
import type { IFleetEvent, IFleetWorker, IFleetWorkerProfile, IFleetWorkerJob, IFleetNativeMessageReceipt, TFleetEventKind, TFleetWorkerAction, TFleetWorkerRequest, TFleetWorkerResponse, TFleetWorkerResponseTo, TFleetWorkerJobAction, IFleetWorkerReport, IFleetRelaunchBlocker, IFleetWorkerDispatchHolder, IFleetWorkerSummary, IFleetWorkerSummaryPage } from '../../ts_interfaces/fleetworkers.js';
|
|
4
|
+
import type { IFleetEvent, IFleetWorker, IFleetWorkerProfile, IFleetWorkerJob, IFleetNativeMessageReceipt, TFleetEventKind, TFleetWorkerAction, TFleetWorkerRequest, TFleetWorkerResponse, TFleetWorkerResponseTo, TFleetWorkerJobAction, IFleetWorkerReport, IFleetRelaunchBlocker, IFleetWorkerDispatchHolder, IFleetWorkerSummary, IFleetWorkerSummaryPage, IFleetWorkerIdentity } from '../../ts_interfaces/fleetworkers.js';
|
|
5
5
|
import type { IFleetConfiguration, IFleetOperation, IFleetTicketSync } from '../../ts_interfaces/fleet.js';
|
|
6
6
|
import type { ITicketActor } from '../../ts_interfaces/tickets.js';
|
|
7
7
|
import type { FleetTicketEffects, IFleetTicketReport } from './classes.ticketeffects.js';
|
|
@@ -52,6 +52,11 @@ export interface IFleetWorkersOptions {
|
|
|
52
52
|
claudeReleases?: (releaseArg: string) => void;
|
|
53
53
|
/** Told of each native Codex thread whose requests the default Codex backend holds for AGL came or went. */
|
|
54
54
|
onNativeCodexAttention?: (nativeIdArg: string) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Whether the worker's MCP calls run without its identity, as the controller shows it (`workerCallerIdentity`); the
|
|
57
|
+
* views and lists show it. Absent, no worker shows it.
|
|
58
|
+
*/
|
|
59
|
+
callerIdentity?: (workerIdArg: string) => IFleetWorkerIdentity | undefined;
|
|
55
60
|
}
|
|
56
61
|
/** The fleet events that change what the Driver view shows of the fleet's workers. */
|
|
57
62
|
export const fleetWorkerViewEventKinds: ReadonlySet<TFleetEventKind> = new Set<TFleetEventKind>(['worker.changed', 'worker.turn.ended', 'worker.report.mid_turn', 'worker.reaped', 'worker.credential.failed']);
|
|
@@ -110,6 +115,8 @@ export class FleetWorkers {
|
|
|
110
115
|
private callerJobs: Promise<unknown> = Promise.resolve();
|
|
111
116
|
/** Set once the controller began to stop: no new worker job is admitted. */
|
|
112
117
|
private admissionClosed = false;
|
|
118
|
+
/** The notices of workers whose MCP calls run without their identity that are being written; `close` waits for them. */
|
|
119
|
+
private readonly identityNotices = new Set<Promise<void>>();
|
|
113
120
|
constructor(private readonly options: IFleetWorkersOptions = {}) {
|
|
114
121
|
this.store = options.store ?? new FleetWorkerStore(); this.events = options.events ?? new FleetEvents();
|
|
115
122
|
this.backends = options.backends ?? { claude: new FleetClaudeWorkers(this.abort.signal, undefined, undefined, options.callers, options.claudeReleases),
|
|
@@ -354,7 +361,12 @@ export class FleetWorkers {
|
|
|
354
361
|
const workers = (await this.store.list(owner)).map((doc) => doc.worker);
|
|
355
362
|
const matching = workers.filter((worker) => (request.archived || worker.state !== 'archived') && (!request.ticketKey || worker.ticketKey === request.ticketKey)
|
|
356
363
|
&& (!request.state || worker.state === request.state) && (!request.harness || worker.harness === request.harness));
|
|
357
|
-
if (request.view !== 'summary')
|
|
364
|
+
if (request.view !== 'summary') {
|
|
365
|
+
return { workers: matching.map((worker) => {
|
|
366
|
+
const identity = this.options.callerIdentity?.(worker.id);
|
|
367
|
+
return { ...this.publicWorker(worker), ...(identity ? { identity } : {}) };
|
|
368
|
+
}) };
|
|
369
|
+
}
|
|
358
370
|
const filter = listFilterDigest(request);
|
|
359
371
|
matching.sort(compareListed);
|
|
360
372
|
let start = 0;
|
|
@@ -374,13 +386,13 @@ export class FleetWorkers {
|
|
|
374
386
|
return result;
|
|
375
387
|
}
|
|
376
388
|
private summary(worker: IFleetWorker): IFleetWorkerSummary {
|
|
377
|
-
const { status, turn, nativeWait } = this.observation(worker), outcome = turn?.outcome;
|
|
389
|
+
const { status, turn, nativeWait } = this.observation(worker), outcome = turn?.outcome, identity = this.options.callerIdentity?.(worker.id);
|
|
378
390
|
return { id: worker.id, name: worker.name, harness: worker.harness, profileId: worker.profileId, ...(worker.ticketKey ? { ticketKey: worker.ticketKey } : {}),
|
|
379
391
|
state: worker.state, ...(worker.nativeId ? { nativeId: worker.nativeId } : {}), cwd: worker.cwd, updatedAt: worker.updatedAt,
|
|
380
392
|
observed: { ...(status ? { status } : {}), ...(outcome ? { outcome: structuredClone(outcome) } : {}), ...(nativeWait ? { nativeWait: structuredClone(nativeWait) } : {}) },
|
|
381
393
|
fence: { ...(worker.pending ? { pending: { action: worker.pending.action, since: worker.pending.startedAt } } : {}),
|
|
382
394
|
...(worker.lostDispatch ? { lostDispatch: true } : {}), ...(worker.reconfirmedDispatch ? { reconfirmed: true } : {}),
|
|
383
|
-
...(worker.error !== undefined ? { error: true } : {}) } };
|
|
395
|
+
...(worker.error !== undefined ? { error: true } : {}) }, ...(identity ? { identity } : {}) };
|
|
384
396
|
}
|
|
385
397
|
/**
|
|
386
398
|
* The owner's job `id` once it settled, or as it is after `timeoutMs` (`timedOut`). Neither the timeout nor an
|
|
@@ -409,9 +421,10 @@ export class FleetWorkers {
|
|
|
409
421
|
return this.publicJob(job.snapshot);
|
|
410
422
|
}
|
|
411
423
|
private view(worker: IFleetWorker): IControllerFleetWorkerView {
|
|
412
|
-
const { status, turn, nativeWait, excerpt } = this.observation(worker);
|
|
424
|
+
const { status, turn, nativeWait, excerpt } = this.observation(worker), identity = this.options.callerIdentity?.(worker.id);
|
|
413
425
|
return { worker: this.publicWorker(worker), ...(status ? { status } : {}), ...(turn?.outcome ? { outcome: structuredClone(turn.outcome) } : {}),
|
|
414
|
-
...(turn?.startedAt ? { turnStartedAt: turn.startedAt } : {}), ...(nativeWait ? { nativeWait: structuredClone(nativeWait) } : {}), ...(excerpt ? { excerpt } : {})
|
|
426
|
+
...(turn?.startedAt ? { turnStartedAt: turn.startedAt } : {}), ...(nativeWait ? { nativeWait: structuredClone(nativeWait) } : {}), ...(excerpt ? { excerpt } : {}),
|
|
427
|
+
...(identity ? { identity } : {}) };
|
|
415
428
|
}
|
|
416
429
|
/**
|
|
417
430
|
* What the views show of a worker's native session, the one place a lost dispatch is applied: it is gone (archived once
|
|
@@ -514,6 +527,33 @@ export class FleetWorkers {
|
|
|
514
527
|
if ((worker.profile.home ?? '') !== home) return refused('worker', 'its fleet worker\'s profile home is not the one whose inventory lists it', true, named);
|
|
515
528
|
return { state: 'identified', workerId: worker.id, projectId: owner, nativeSessionId: agent.sessionId, jobId: agent.id };
|
|
516
529
|
}
|
|
530
|
+
/**
|
|
531
|
+
* The controller shows the worker `workerId`'s MCP calls as running without its identity, for the reason `identity`
|
|
532
|
+
* names, or as verified again (`undefined`) (AGL-1888). The views' listeners hear of it; a worker shown unverified
|
|
533
|
+
* gets one notice on its ticket for each reason the controller tells (`FleetTicketEffects.unverifiedCaller`), never
|
|
534
|
+
* again after a restart. A notice whose ticket write failed stays saved as failed or unknown, with its `ticket.failed`
|
|
535
|
+
* or `ticket.unknown` event, and is written by the next `fleet reconcile` of the ticket or when the reason is told
|
|
536
|
+
* again. Resolves once that notice is written or failed; it never rejects.
|
|
537
|
+
*/
|
|
538
|
+
public callerIdentityChanged(workerId: string, identity: IFleetWorkerIdentity | undefined): Promise<void> {
|
|
539
|
+
if (this.abort.signal.aborted) return Promise.resolve();
|
|
540
|
+
for (const listener of this.viewListeners) listener();
|
|
541
|
+
if (!identity) return Promise.resolve();
|
|
542
|
+
const notice = this.noticeCallerIdentity(workerId, identity.reason).catch((error: unknown) => {
|
|
543
|
+
if (!this.abort.signal.aborted) console.error(`The notice that fleet worker ${workerId} calls AGL without its identity was not written.`, error);
|
|
544
|
+
});
|
|
545
|
+
this.identityNotices.add(notice);
|
|
546
|
+
void notice.then(() => this.identityNotices.delete(notice));
|
|
547
|
+
return notice;
|
|
548
|
+
}
|
|
549
|
+
private async noticeCallerIdentity(workerId: string, reason: string): Promise<void> {
|
|
550
|
+
const effects = this.options.ticketEffects;
|
|
551
|
+
if (!effects) return;
|
|
552
|
+
const found = (await this.store.list()).find(({ worker }) => worker.id === workerId);
|
|
553
|
+
if (!found || found.worker.state === 'archived' || !found.worker.ticketKey || !found.worker.nativeId) return;
|
|
554
|
+
const sync = await effects.unverifiedCaller(found.owner, found.worker, reason, this.abort.signal);
|
|
555
|
+
if (sync) this.ticketEvent(found.owner, found.worker.ticketKey, sync, found.worker.id);
|
|
556
|
+
}
|
|
517
557
|
/** The newest root threads on the host's shared Codex app-server, read at most `maxAgeMs` ago. */
|
|
518
558
|
public async nativeThreads(maxAgeMs: number): Promise<IFleetNativeThread[]> {
|
|
519
559
|
return await this.backends.codex.threads?.(plugins.os.homedir(), maxAgeMs) ?? [];
|
|
@@ -1042,7 +1082,7 @@ export class FleetWorkers {
|
|
|
1042
1082
|
}
|
|
1043
1083
|
public async close(): Promise<void> {
|
|
1044
1084
|
if (this.pollTimer) clearInterval(this.pollTimer); this.abort.abort(); this.events.close(); this.viewListeners.clear();
|
|
1045
|
-
await Promise.allSettled([...this.jobs.values()].map((job) => job.completion)); await Promise.allSettled([this.polling]);
|
|
1085
|
+
await Promise.allSettled([...this.jobs.values()].map((job) => job.completion)); await Promise.allSettled([this.polling, ...this.identityNotices]);
|
|
1046
1086
|
await Promise.allSettled(Object.values(this.backends).map((backend) => backend.close()));
|
|
1047
1087
|
}
|
|
1048
1088
|
}
|
|
@@ -145,17 +145,20 @@ const event = plugins.z.object({ id: plugins.z.number().int().positive(),
|
|
|
145
145
|
ticketSync: ticketSync.optional(),
|
|
146
146
|
text: plugins.z.string().max(64 * 1024).optional(), truncated: plugins.z.boolean().optional(), error: plugins.z.string().max(4096).optional(),
|
|
147
147
|
repo: text.optional(), operationId: text.optional(), version: text.optional(), target: text.optional(), metrics: plugins.z.record(plugins.z.string(), plugins.z.unknown()).optional() }).strict();
|
|
148
|
+
/** `IFleetWorkerIdentity`: derived by the controller, never part of a stored worker. */
|
|
149
|
+
const identity = plugins.z.object({ unverified: plugins.z.literal(true), reason: plugins.z.string().min(1).max(4096), since: text }).strict();
|
|
148
150
|
const summary = plugins.z.object({ id: text, name, harness, profileId: name, ticketKey: ticketKey.optional(), state: workerState, nativeId: text.optional(), cwd, updatedAt: text,
|
|
149
151
|
observed: plugins.z.object({ status: reportStatus.optional(), outcome: outcome.optional(), nativeWait: nativeWait.optional() }).strict(),
|
|
150
152
|
fence: plugins.z.object({ pending: plugins.z.object({ action: text, since: text }).strict().optional(), lostDispatch: plugins.z.literal(true).optional(),
|
|
151
|
-
reconfirmed: plugins.z.literal(true).optional(), error: plugins.z.literal(true).optional() }).strict() }).strict();
|
|
153
|
+
reconfirmed: plugins.z.literal(true).optional(), error: plugins.z.literal(true).optional() }).strict(), identity: identity.optional() }).strict();
|
|
152
154
|
const count = plugins.z.number().int().min(0).max(1024);
|
|
153
155
|
const summaryPage = plugins.z.object({ view: plugins.z.literal('summary'), workers: plugins.z.array(summary).max(100), total: count, fenced: count, failed: count,
|
|
154
156
|
nextCursor: listCursor.optional() }).strict();
|
|
155
157
|
const view = plugins.z.object({ worker: fleetWorkerSchema, status: reportStatus.optional(), outcome: outcome.optional(), turnStartedAt: text.optional(),
|
|
156
|
-
nativeWait: nativeWait.optional(), excerpt: plugins.z.string().max(controllerSessionFeedLimits.excerptChars).optional() }).strict();
|
|
158
|
+
nativeWait: nativeWait.optional(), excerpt: plugins.z.string().max(controllerSessionFeedLimits.excerptChars).optional(), identity: identity.optional() }).strict();
|
|
159
|
+
const listedWorker = fleetWorkerSchema.safeExtend({ identity: identity.optional() });
|
|
157
160
|
export const assertFleetWorkerResponse = <T extends TFleetWorkerAction>(action: T, input: unknown): TFleetWorkerResponse<T> => {
|
|
158
|
-
const schema = action === 'list' ? plugins.z.union([plugins.z.object({ workers: plugins.z.array(
|
|
161
|
+
const schema = action === 'list' ? plugins.z.union([plugins.z.object({ workers: plugins.z.array(listedWorker).max(1024) }).strict(), summaryPage])
|
|
159
162
|
: action === 'get' ? view
|
|
160
163
|
: action === 'job-wait' ? plugins.z.object({ job, timedOut: plugins.z.boolean() }).strict()
|
|
161
164
|
: action === 'watch' ? plugins.z.object({ cursor: fleetWorkerRequestSchemas.watch.shape.cursor.unwrap(), reset: plugins.z.boolean(), events: plugins.z.array(event).max(64) }).strict()
|
|
@@ -455,6 +455,8 @@ const deviceTicketStoreRefusals: Readonly<Record<Exclude<TTicketErrorCode, keyof
|
|
|
455
455
|
outcome_unknown: 'outcome_unknown',
|
|
456
456
|
ticket_fleet_event_conflict: 'invalid_request',
|
|
457
457
|
unauthorized: 'invalid_request',
|
|
458
|
+
ticket_cursor_invalid: 'invalid_request',
|
|
459
|
+
ticket_cursor_mismatch: 'invalid_request',
|
|
458
460
|
};
|
|
459
461
|
|
|
460
462
|
const deviceTicketCodes: ReadonlySet<string> = new Set(deviceTicketRefusalCodes);
|
|
@@ -26,6 +26,8 @@ export const fleetWorkerCliHelp = `Usage: agl fleet worker start NAME --profile
|
|
|
26
26
|
[--gitea URL] [--gitea-token-file FILE] [--probe-interval SECONDS]
|
|
27
27
|
All accept --ticket KEY, --json and --port PORT. Actions and report require --ticket, except message; list/status/watch accept it as a filter.
|
|
28
28
|
Profiles live in fleet.workerProfiles in the Configuration master.
|
|
29
|
+
list prints the workers' records; a worker whose MCP calls the controller refused its identity carries
|
|
30
|
+
identity {unverified, reason, since} until its next verified call.
|
|
29
31
|
Mutation and report commands wait for the returned job; MCP tools return its handle immediately.
|
|
30
32
|
refresh --profile ID starts the successor on that configured profile, which must run the worker's own harness (only move
|
|
31
33
|
changes the harness); without --profile the successor keeps the worker's recorded profile.
|
|
@@ -185,6 +187,8 @@ export const parseFleetWorkerCliArguments = async (args: string[]): Promise<IFle
|
|
|
185
187
|
return { action, request, port, json, once, ...(lines ? { lines } : {}), ...(probing ? { probes } : {}),
|
|
186
188
|
...(message ? { target: (request as TFleetWorkerRequest<'steer'>).messages[0]!.name, ...(messageFile ? { messageFile } : {}) } : {}) };
|
|
187
189
|
};
|
|
190
|
+
/** What a worker command other than watch prints: its result as indented JSON, or as one line with --json. */
|
|
191
|
+
export const fleetWorkerCliOutput = (resultArg: unknown, jsonArg: boolean): string => `${JSON.stringify(resultArg, null, jsonArg ? undefined : 2)}\n`;
|
|
188
192
|
/** The line a continuing watch writes for each failed attempt to reach the controller. */
|
|
189
193
|
export interface IFleetWatchDisconnection { disconnected: { at: string; error: string; retryInMs: number } }
|
|
190
194
|
export type { IFleetWatchChange };
|
|
@@ -257,7 +261,7 @@ export const runFleetWorkerCli = async (args: string[]): Promise<void> => {
|
|
|
257
261
|
}
|
|
258
262
|
} catch (cause) { throw new Error(`Observation ended; inspect fleet worker status ${id} before retrying.`, { cause }); }
|
|
259
263
|
}
|
|
260
|
-
process.stdout.write(
|
|
264
|
+
process.stdout.write(fleetWorkerCliOutput(result, parsed.json));
|
|
261
265
|
if ('job' in result && result.job.state === 'failed') process.exitCode = 1;
|
|
262
266
|
if ('job' in result && result.job.ticketSync && result.job.ticketSync.state !== 'applied') process.exitCode = 1;
|
|
263
267
|
}, 60 * 60_000));
|
|
@@ -44,6 +44,8 @@ const scoreText = (scoreArg: number | null): string => scoreArg === null ? 'unsc
|
|
|
44
44
|
const placementText = (accountArg: NonNullable<TReportedProxyStatus['accounts']>[number]): string => {
|
|
45
45
|
if (accountArg.lifecycle === undefined) return '';
|
|
46
46
|
if (accountArg.lifecycle === 'lapsed') return `; lapsed ${accountArg.lapsesAt}, never routed to again`;
|
|
47
|
+
// Paused by its owner (AGL-1933): its state says so, and it has no placement to name.
|
|
48
|
+
if (accountArg.pausedAt) return '';
|
|
47
49
|
return `${accountArg.lifecycle === 'canceled' ? `; canceled, lapses ${accountArg.lapsesAt}` : ''}`
|
|
48
50
|
+ `${accountArg.priorityUntil ? `; priority until ${accountArg.priorityUntil} (set by the owner)` : ''}`
|
|
49
51
|
+ `${accountArg.renewal ? `; renews ${accountArg.renewal.at} (set by the owner`
|