@moondeck/station 1.0.5 → 1.0.7
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/lib/agent.ts +3 -0
- package/lib/agents/skill-index-preamble.fixture.ts +2 -0
- package/lib/credential-consumers/engines.ts +4 -0
- package/lib/engine-accounts.ts +25 -2
- package/lib/machine-exec.ts +6 -2
- package/lib/machine-provider-aws.ts +264 -86
- package/lib/machine-provider.ts +43 -0
- package/lib/orchestrator.ts +223 -52
- package/lib/skills.ts +122 -114
- package/lib/task-env-forwarder.ts +123 -17
- package/lib/task-environment/machine-task-up.ts +4 -0
- package/lib/task-environment/machine.ts +365 -8
- package/lib/task-environment/types.ts +28 -0
- package/package.json +5 -1
- package/src/cloud-credentials.ts +10 -2
- package/src/event-outbox.ts +50 -1
- package/src/index.ts +134 -1
- package/src/main.ts +70 -2
- package/src/model-limits.ts +103 -0
- package/src/protocol.ts +70 -1
- package/src/task-note-publisher.ts +65 -0
package/lib/orchestrator.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isOwnedInternalConnectionRuntime } from "./internal-connections";
|
|
2
|
+
import { accountAllowsModel } from "../src/model-limits";
|
|
2
3
|
import { prepareNodeData } from "./node-state";
|
|
3
4
|
import { registerConnectionSecret } from "./connection-secret-redaction";
|
|
4
5
|
import { buildCustomConnectionLaunch, tomlString, connectionNativeBlanks, connectionHomePreparation, newConnectionHome, connectionDnsLookupArgv, validateConnectionAddresses, connectionConnectArgv, CustomConnectionLaunchError, launchRefusal, CONNECTION_CONNECT_TIMEOUT_MS } from "./custom-connection-launch";
|
|
@@ -68,7 +69,7 @@ import {
|
|
|
68
69
|
import { ACTIVE_STATUSES, isActive, isOnDashboard } from "./task-status";
|
|
69
70
|
import { isSafeHostTaskId } from "./task-identity";
|
|
70
71
|
import { projectEnvForTask } from "./host-env";
|
|
71
|
-
import { shadowRoute } from "./routing/shadow";
|
|
72
|
+
import { CLASSIFIER_MODEL, shadowRoute } from "./routing/shadow";
|
|
72
73
|
import {
|
|
73
74
|
closeCurrentTaskRunAssignmentForStoppedRuntime,
|
|
74
75
|
getHostTask,
|
|
@@ -132,16 +133,18 @@ import type {
|
|
|
132
133
|
} from "./task-environment/types";
|
|
133
134
|
import { renderSkillLayout } from "./skill-layout";
|
|
134
135
|
import {
|
|
135
|
-
containerSkillFile,
|
|
136
136
|
installedSkillPath,
|
|
137
137
|
installPackageSkills,
|
|
138
138
|
type SkillExec,
|
|
139
139
|
writeAgentSkills,
|
|
140
|
+
renderSkillMd,
|
|
141
|
+
type SkillDelivery,
|
|
140
142
|
} from "./skills";
|
|
141
143
|
import {
|
|
142
144
|
ensureMachineGatewayTunnel,
|
|
143
145
|
ensureMachineGatewayTunnelReady,
|
|
144
146
|
MACHINE_GATEWAY_TUNNEL_PORT,
|
|
147
|
+
stopMachineGatewayTunnel,
|
|
145
148
|
} from "./machine-gateway-tunnel";
|
|
146
149
|
import { ensureContainerTaskEnvForwarder } from "./task-env-forwarder";
|
|
147
150
|
import { STATION_AGENT_CLI } from "../src/station-identity";
|
|
@@ -324,6 +327,7 @@ interface Channel {
|
|
|
324
327
|
agentHandle: TaskEnvironmentHandle<unknown> | null;
|
|
325
328
|
/** Per-agent system preamble (channel briefing + assembled persona). */
|
|
326
329
|
preambles: Map<string, string>;
|
|
330
|
+
skillDeliveries: Map<string, SkillDelivery>;
|
|
327
331
|
/** Per-agent first-turn message — only agents whose `initialPrompt` is
|
|
328
332
|
* non-empty have an entry. Delivered once at container-ready. */
|
|
329
333
|
firstTurns: Map<string, string>;
|
|
@@ -1094,10 +1098,10 @@ export class Orchestrator {
|
|
|
1094
1098
|
// array exactly also makes absence authoritative for live removal.
|
|
1095
1099
|
channel.roster = [...spec.agents];
|
|
1096
1100
|
this.cancelStaleConnectionRetries(channel);
|
|
1097
|
-
for (const agent of
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
+
for (const agent of channel.roster) {
|
|
1102
|
+
if (JSON.stringify(previousById.get(agent.id)?.skills) !== JSON.stringify(agent.skills)) {
|
|
1103
|
+
channel.skillDeliveries.delete(agent.id);
|
|
1104
|
+
}
|
|
1101
1105
|
}
|
|
1102
1106
|
for (const { agent, reason } of changed) {
|
|
1103
1107
|
const recoveryAbortPublished = this.supersedeRecovery(
|
|
@@ -1199,6 +1203,7 @@ export class Orchestrator {
|
|
|
1199
1203
|
spec.mode,
|
|
1200
1204
|
spec.secretaryAgentId,
|
|
1201
1205
|
taskProxiedKeys(channel.taskId),
|
|
1206
|
+
channel.skillDeliveries.get(agent.id),
|
|
1202
1207
|
),
|
|
1203
1208
|
);
|
|
1204
1209
|
}
|
|
@@ -1261,6 +1266,7 @@ export class Orchestrator {
|
|
|
1261
1266
|
}
|
|
1262
1267
|
this.retireRunnerGeneration(channel, agentId);
|
|
1263
1268
|
channel.preambles.delete(agentId);
|
|
1269
|
+
channel.skillDeliveries.delete(agentId);
|
|
1264
1270
|
channel.firstTurns.delete(agentId);
|
|
1265
1271
|
channel.browserStaleSessions.delete(agentId);
|
|
1266
1272
|
channel.rosterSessionChanges.delete(agentId);
|
|
@@ -1464,6 +1470,7 @@ export class Orchestrator {
|
|
|
1464
1470
|
agentEnvironment: null,
|
|
1465
1471
|
agentHandle: null,
|
|
1466
1472
|
preambles,
|
|
1473
|
+
skillDeliveries: new Map(),
|
|
1467
1474
|
firstTurns,
|
|
1468
1475
|
sessionsReady: null,
|
|
1469
1476
|
browserReady: false,
|
|
@@ -1525,13 +1532,6 @@ export class Orchestrator {
|
|
|
1525
1532
|
leasedLaunches: new Map(),
|
|
1526
1533
|
};
|
|
1527
1534
|
this.channels.set(taskId, channel);
|
|
1528
|
-
// ADR-046: materialise each agent's skills to its per-agent SKILL.md in
|
|
1529
|
-
// the workspace (bind-mounted into the container), best-effort, once the
|
|
1530
|
-
// channel can give the task's runtime: where only it can make the
|
|
1531
|
-
// agent's directory (macOS, #cb3j0z), it is asked for then.
|
|
1532
|
-
for (const agent of roster) {
|
|
1533
|
-
writeAgentSkills(taskId, agent, () => this.workspaceRuntime(taskId));
|
|
1534
|
-
}
|
|
1535
1535
|
return channel;
|
|
1536
1536
|
}
|
|
1537
1537
|
|
|
@@ -1815,6 +1815,7 @@ export class Orchestrator {
|
|
|
1815
1815
|
scope: account.scope,
|
|
1816
1816
|
authKind: account.authKind as "env" | "config-dir",
|
|
1817
1817
|
execEnv: {},
|
|
1818
|
+
...(account.allowedModels ? { allowedModels: account.allowedModels } : {}),
|
|
1818
1819
|
}));
|
|
1819
1820
|
}
|
|
1820
1821
|
|
|
@@ -1825,17 +1826,21 @@ export class Orchestrator {
|
|
|
1825
1826
|
kind: string,
|
|
1826
1827
|
exclude?: Set<string>,
|
|
1827
1828
|
preferredId?: string,
|
|
1829
|
+
/** ADR-168: the agent's model; only accounts allowing it are picked. */
|
|
1830
|
+
model?: string | null,
|
|
1828
1831
|
): ResolvedEngineAccount | null {
|
|
1829
1832
|
if (!this.isLeasedChannel(channel)) {
|
|
1830
1833
|
return pickEngineAccount(kind, {
|
|
1831
1834
|
scope: channel.engineAccountScope,
|
|
1832
1835
|
exclude,
|
|
1833
1836
|
preferredId,
|
|
1837
|
+
model,
|
|
1834
1838
|
});
|
|
1835
1839
|
}
|
|
1836
1840
|
return selectAccount(this.engineAccounts(channel, kind), {
|
|
1837
1841
|
exclude,
|
|
1838
1842
|
preferredId,
|
|
1843
|
+
model,
|
|
1839
1844
|
});
|
|
1840
1845
|
}
|
|
1841
1846
|
|
|
@@ -2668,12 +2673,7 @@ export class Orchestrator {
|
|
|
2668
2673
|
// Same per-agent materialisation the initial start does. Browser setup
|
|
2669
2674
|
// is awaited before EVERY missing-session spawn: that reasserts configs
|
|
2670
2675
|
// clobbered by resume/auth injection and covers roster generation.
|
|
2671
|
-
|
|
2672
|
-
if (skillExec) {
|
|
2673
|
-
await installPackageSkills(channel.taskId, missing, skillExec);
|
|
2674
|
-
} else {
|
|
2675
|
-
await installPackageSkills(channel.taskId, missing);
|
|
2676
|
-
}
|
|
2676
|
+
await this.prepareSkills(channel, missing);
|
|
2677
2677
|
if (!this.isActiveChannel(channel)) return;
|
|
2678
2678
|
|
|
2679
2679
|
// One materialization gate owns provisioning and (when enabled)
|
|
@@ -2877,6 +2877,7 @@ export class Orchestrator {
|
|
|
2877
2877
|
const account = pickEngineAccount(agent.kind, {
|
|
2878
2878
|
scope: channel.engineAccountScope,
|
|
2879
2879
|
preferredId: agent.accountId,
|
|
2880
|
+
model: agent.model ?? null,
|
|
2880
2881
|
});
|
|
2881
2882
|
if (!account) {
|
|
2882
2883
|
channel.accountByAgent.delete(agent.id);
|
|
@@ -3119,7 +3120,9 @@ export class Orchestrator {
|
|
|
3119
3120
|
if (!account) {
|
|
3120
3121
|
reason = args.agent.accountBinding === "required"
|
|
3121
3122
|
? args.agent.accountId && open.connectionsUnsupported?.includes(args.agent.accountId) ? "unsupported" : "connection removed"
|
|
3122
|
-
:
|
|
3123
|
+
: leasedModelExcluded(open, kind, args.agent.model)
|
|
3124
|
+
? `no ${kind} account this task can use allows model "${args.agent.model || "(default)"}" — pick an allowed model, or ask an admin to change the accounts' allowed models or roles`
|
|
3125
|
+
: `no ${kind} account this task can use`;
|
|
3123
3126
|
break;
|
|
3124
3127
|
}
|
|
3125
3128
|
if (account.authKind === "env") {
|
|
@@ -3348,12 +3351,16 @@ export class Orchestrator {
|
|
|
3348
3351
|
owner: { agentId: string; slot: LeasedLaunchSlot } | null,
|
|
3349
3352
|
identity: LeasedIdentity,
|
|
3350
3353
|
environment: TaskEnvironmentHandle<unknown>,
|
|
3354
|
+
/** ADR-168: a one-shot's own model (the shadow classifier's): admitted
|
|
3355
|
+
* only while the account still allows it. */
|
|
3356
|
+
oneShotModel?: { kind: string; model: string | null },
|
|
3351
3357
|
): TaskEnvironmentHandle<unknown> {
|
|
3352
3358
|
const agentId = owner?.agentId ?? null;
|
|
3353
3359
|
const held = (): boolean =>
|
|
3354
3360
|
this.isActiveChannel(channel) &&
|
|
3355
3361
|
(owner === null
|
|
3356
|
-
? this.leasedMaterialServed(channel, identity)
|
|
3362
|
+
? this.leasedMaterialServed(channel, identity) &&
|
|
3363
|
+
(oneShotModel === undefined || this.leasedIdentityAllowsModel(channel, identity, oneShotModel.kind, oneShotModel.model))
|
|
3357
3364
|
: channel.leasedLaunches.get(owner.agentId) === owner.slot &&
|
|
3358
3365
|
(owner.slot.session === null
|
|
3359
3366
|
? !owner.slot.created
|
|
@@ -3566,6 +3573,23 @@ export class Orchestrator {
|
|
|
3566
3573
|
});
|
|
3567
3574
|
}
|
|
3568
3575
|
|
|
3576
|
+
/** ADR-168: whether the leased account `identity` names allows `model`
|
|
3577
|
+
* right now (a connection or the task token: always). */
|
|
3578
|
+
private leasedIdentityAllowsModel(channel: Channel, identity: LeasedIdentity, kind: string, model: string | null): boolean {
|
|
3579
|
+
if (identity.subject !== "account" || identity.connection) return true;
|
|
3580
|
+
const lease = leasedEnginesFor(channel.taskId);
|
|
3581
|
+
const account = lease?.open ? lease.accounts.find((candidate) => candidate.credentialId === identity.credentialId) : undefined;
|
|
3582
|
+
return account !== undefined && accountAllowsModel(account.allowedModels, kind, model);
|
|
3583
|
+
}
|
|
3584
|
+
|
|
3585
|
+
/** ADR-168: whether the account an agent is bound to still allows its
|
|
3586
|
+
* model (a connection or the task token: always). */
|
|
3587
|
+
private leasedAccountAllowsAgent(lease: TaskEngineLease, identity: LeasedIdentity, agent: RosterAgent): boolean {
|
|
3588
|
+
if (identity.subject !== "account" || identity.connection) return true;
|
|
3589
|
+
const account = lease.accounts.find((candidate) => candidate.credentialId === identity.credentialId);
|
|
3590
|
+
return !account || accountAllowsModel(account.allowedModels, agent.kind, agent.model ?? null);
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3569
3593
|
/** Whether the task's open gate still serves `identity`'s account at its
|
|
3570
3594
|
* revision and version, for its run, and that version is not being held
|
|
3571
3595
|
* back for a newer one: what a one-shot may start on. An agent's task
|
|
@@ -3598,11 +3622,18 @@ export class Orchestrator {
|
|
|
3598
3622
|
}
|
|
3599
3623
|
|
|
3600
3624
|
/** Whether the agent may start on `identity` right now: still bound to it,
|
|
3601
|
-
*
|
|
3602
|
-
* version, for that run
|
|
3625
|
+
* the task's open gate still serves that account at that revision and
|
|
3626
|
+
* version, for that run, and (ADR-168) the account still allows the
|
|
3627
|
+
* agent's current model. The last can change with no new revision: an
|
|
3628
|
+
* admin narrowing `allowedModels`, or the agent's model changing, while
|
|
3629
|
+
* its session is still being created. Launch admission and the
|
|
3630
|
+
* post-creation checks all read this. */
|
|
3603
3631
|
private leasedIdentityHeld(channel: Channel, agentId: string, identity: LeasedIdentity): boolean {
|
|
3604
3632
|
const bound = channel.leasedIdentityByAgent.get(agentId);
|
|
3605
|
-
|
|
3633
|
+
if (bound === undefined || !sameLeasedIdentity(bound, identity) || !this.leasedMaterialServed(channel, identity)) return false;
|
|
3634
|
+
const agent = channel.roster.find((candidate) => candidate.id === agentId);
|
|
3635
|
+
const lease = leasedEnginesFor(channel.taskId);
|
|
3636
|
+
return !agent || !lease?.open || this.leasedAccountAllowsAgent(lease, identity, agent);
|
|
3606
3637
|
}
|
|
3607
3638
|
|
|
3608
3639
|
/** The leased account an agent runs on: the one it is bound to while that
|
|
@@ -3612,15 +3643,25 @@ export class Orchestrator {
|
|
|
3612
3643
|
agentId: string,
|
|
3613
3644
|
kind: string,
|
|
3614
3645
|
lease: TaskEngineLease,
|
|
3646
|
+
/** ADR-168: the model the launch will run, when it isn't the agent's own
|
|
3647
|
+
* (the shadow classifier's); null = unknown, so only an unlimited
|
|
3648
|
+
* account qualifies. */
|
|
3649
|
+
model?: string | null,
|
|
3615
3650
|
): LeasedEngineAccount | undefined {
|
|
3616
3651
|
const agent = channel.roster.find(candidate => candidate.id === agentId);
|
|
3617
3652
|
if (agent?.accountBinding === "required") {
|
|
3618
3653
|
return lease.accounts.find((account): account is LeasedEngineAccount => account.credentialId === agent.accountId && account.engineKind === kind && account.authKind === "custom-connection" && isLeasedEngineAccount(account));
|
|
3619
3654
|
}
|
|
3620
3655
|
if (lease.accounts.some(account => account.credentialId === agent?.accountId && account.authKind === "custom-connection")) return undefined;
|
|
3656
|
+
// ADR-168: only accounts allowing the agent's current model — so a model
|
|
3657
|
+
// changed mid-task, or an account an admin narrowed, moves the agent off
|
|
3658
|
+
// a binding that no longer allows it.
|
|
3621
3659
|
const accounts = lease.accounts.filter(
|
|
3622
3660
|
(account): account is LeasedEngineAccount =>
|
|
3623
|
-
account.engineKind === kind &&
|
|
3661
|
+
account.engineKind === kind &&
|
|
3662
|
+
account.authKind !== "custom-connection" &&
|
|
3663
|
+
isLeasedEngineAccount(account) &&
|
|
3664
|
+
accountAllowsModel(account.allowedModels, kind, model !== undefined ? model : (agent?.model ?? null)),
|
|
3624
3665
|
);
|
|
3625
3666
|
const bound = channel.accountByAgent.get(agentId);
|
|
3626
3667
|
const preferredId = channel.roster.find(
|
|
@@ -3808,7 +3849,9 @@ export class Orchestrator {
|
|
|
3808
3849
|
let stale = false;
|
|
3809
3850
|
for (const agent of channel.roster) {
|
|
3810
3851
|
const identity = channel.leasedIdentityByAgent.get(agent.id);
|
|
3811
|
-
|
|
3852
|
+
// ADR-168: an account narrowed so it no longer allows the agent's model
|
|
3853
|
+
// is left too: the agent restarts on one that does, or stops saying so.
|
|
3854
|
+
if (!identity || (this.leasedMaterialServed(channel, identity) && this.leasedAccountAllowsAgent(lease, identity, agent))) continue;
|
|
3812
3855
|
if (!channel.sessions.has(agent.id)) continue;
|
|
3813
3856
|
channel.browserStaleSessions.add(agent.id);
|
|
3814
3857
|
stale = true;
|
|
@@ -4392,9 +4435,14 @@ export class Orchestrator {
|
|
|
4392
4435
|
maxOutputBytes: 64 * 1024,
|
|
4393
4436
|
admit,
|
|
4394
4437
|
});
|
|
4438
|
+
// ADR-168 (review #5): the account is chosen and admitted for the model
|
|
4439
|
+
// the classifier actually runs, never the agent's own. Grok's is the
|
|
4440
|
+
// CLI's default, unknown here, so only an account without a limit
|
|
4441
|
+
// qualifies. No compatible account: null, and the pass routes by rules.
|
|
4442
|
+
const classifierModel = CLASSIFIER_MODEL[kind] ?? null;
|
|
4395
4443
|
if (!this.isLeasedChannel(channel)) {
|
|
4396
4444
|
const running = whileOnOwnCredentials(async () => {
|
|
4397
|
-
const env = { ...(pickEngineAccount(kind, { scope: channel.engineAccountScope })?.execEnv ?? {}) };
|
|
4445
|
+
const env = { ...(pickEngineAccount(kind, { scope: channel.engineAccountScope, model: classifierModel })?.execEnv ?? {}) };
|
|
4398
4446
|
const r = await handle.exec(
|
|
4399
4447
|
request(env, () => {
|
|
4400
4448
|
if (!this.isActiveChannel(channel) || !onOwnCredentials()) throw new LeftOwnCredentialsError();
|
|
@@ -4408,7 +4456,7 @@ export class Orchestrator {
|
|
|
4408
4456
|
}
|
|
4409
4457
|
const lease = leasedEnginesFor(channel.taskId);
|
|
4410
4458
|
if (!lease?.open) return null;
|
|
4411
|
-
const account = this.leasedAccountFor(channel, agentId, kind, lease);
|
|
4459
|
+
const account = this.leasedAccountFor(channel, agentId, kind, lease, classifierModel);
|
|
4412
4460
|
if (!account || account.authKind === "custom-connection") return null;
|
|
4413
4461
|
const identity: LeasedIdentity = {
|
|
4414
4462
|
subject: "account",
|
|
@@ -4429,10 +4477,13 @@ export class Orchestrator {
|
|
|
4429
4477
|
this.trackEventOperation(channel, entry.settled);
|
|
4430
4478
|
try {
|
|
4431
4479
|
const env = await this.leasedOneShotEnv(channel, lease, account, handle);
|
|
4432
|
-
|
|
4433
|
-
|
|
4480
|
+
const servedForClassifier = (): boolean =>
|
|
4481
|
+
this.leasedMaterialServed(channel, identity) &&
|
|
4482
|
+
this.leasedIdentityAllowsModel(channel, identity, kind, classifierModel);
|
|
4483
|
+
if (!env || !servedForClassifier()) return null;
|
|
4484
|
+
const r = await this.leasedLaunchEnvironment(channel, null, identity, handle, { kind, model: classifierModel }).exec(
|
|
4434
4485
|
request(env, () => {
|
|
4435
|
-
if (!this.isActiveChannel(channel) || !
|
|
4486
|
+
if (!this.isActiveChannel(channel) || !servedForClassifier()) {
|
|
4436
4487
|
throw new CredentialLeaseUnavailableError("the shadow classifier's account moved");
|
|
4437
4488
|
}
|
|
4438
4489
|
}),
|
|
@@ -4513,12 +4564,10 @@ export class Orchestrator {
|
|
|
4513
4564
|
return tracked;
|
|
4514
4565
|
}
|
|
4515
4566
|
|
|
4516
|
-
/**
|
|
4517
|
-
*
|
|
4518
|
-
* actually been reconstructed, avoiding a new await during cold admission.
|
|
4567
|
+
/** Adapt a settled environment for package installation. Only local container
|
|
4568
|
+
* callers may use the default Docker executor when no handle is available.
|
|
4519
4569
|
*/
|
|
4520
|
-
private providerSkillExec(
|
|
4521
|
-
const environment = channel.agentHandle;
|
|
4570
|
+
private providerSkillExec(environment: TaskEnvironmentHandle<unknown> | null | undefined): SkillExec | undefined {
|
|
4522
4571
|
if (!environment) return undefined;
|
|
4523
4572
|
return async (_container, cmd, cwd) => {
|
|
4524
4573
|
const argv = cmd as [string, ...string[]];
|
|
@@ -4538,6 +4587,45 @@ export class Orchestrator {
|
|
|
4538
4587
|
};
|
|
4539
4588
|
}
|
|
4540
4589
|
|
|
4590
|
+
/** Skills are launch material: await delivery, then rebuild the brief from its result. */
|
|
4591
|
+
private async prepareSkills(channel: Channel, agents: RosterAgent[]): Promise<void> {
|
|
4592
|
+
const remote = isEnvironmentTransportProvider(getHostTask(channel.taskId)?.environmentProvider);
|
|
4593
|
+
let environment: TaskEnvironmentHandle<unknown> | undefined;
|
|
4594
|
+
if (remote) {
|
|
4595
|
+
try {
|
|
4596
|
+
environment = await this.agentEnvironment(channel);
|
|
4597
|
+
} catch (error) {
|
|
4598
|
+
console.warn(`[skills] ${channel.taskId}: task environment unavailable: ${String(error)}`);
|
|
4599
|
+
}
|
|
4600
|
+
}
|
|
4601
|
+
if (!this.isActiveChannel(channel)) return;
|
|
4602
|
+
// Use the reconstructed handle directly, not the channel cache: a channel
|
|
4603
|
+
// invalidated during reconstruction never publishes agentHandle.
|
|
4604
|
+
const skillExec = this.providerSkillExec(remote ? environment : channel.agentHandle);
|
|
4605
|
+
// Remote packages must never select installPackageSkills' default Docker executor.
|
|
4606
|
+
const installedPackages = remote && !skillExec ? [] : await installPackageSkills(
|
|
4607
|
+
channel.taskId, agents, skillExec,
|
|
4608
|
+
);
|
|
4609
|
+
for (const agent of agents) {
|
|
4610
|
+
if (!this.isActiveChannel(channel)) return;
|
|
4611
|
+
const path = remote && !environment ? null : await writeAgentSkills(
|
|
4612
|
+
channel.taskId, agent, () => this.workspaceRuntime(channel.taskId), environment,
|
|
4613
|
+
);
|
|
4614
|
+
if (!this.isActiveChannel(channel) || !this.hasDesiredLaunchSettings(channel, agent.id, agent)) continue;
|
|
4615
|
+
const desired = channel.roster.find((entry) => entry.id === agent.id);
|
|
4616
|
+
if (JSON.stringify(desired?.skills) !== JSON.stringify(agent.skills)) continue;
|
|
4617
|
+
const delivery = { path, installedPackages };
|
|
4618
|
+
channel.skillDeliveries.set(agent.id, delivery);
|
|
4619
|
+
const spec = this.channelSpecs.get(channel.taskId);
|
|
4620
|
+
if (!spec) continue;
|
|
4621
|
+
channel.preambles.set(agent.id, buildSystemPreamble(
|
|
4622
|
+
channel.roster, agent, spec.projects, spec.globalContext, spec.workspacePath,
|
|
4623
|
+
spec.branch, channel.humans, channel.browserTesting, channel.sharedFiles,
|
|
4624
|
+
spec.mode, spec.secretaryAgentId, taskProxiedKeys(channel.taskId), delivery,
|
|
4625
|
+
));
|
|
4626
|
+
}
|
|
4627
|
+
}
|
|
4628
|
+
|
|
4541
4629
|
private async startSessions(channel: Channel): Promise<boolean> {
|
|
4542
4630
|
const task = getHostTask(channel.taskId);
|
|
4543
4631
|
if (
|
|
@@ -4611,12 +4699,7 @@ export class Orchestrator {
|
|
|
4611
4699
|
// turn. Idempotent + best-effort (returns fast when there are none); a slow
|
|
4612
4700
|
// clone/install briefly delays start, which is acceptable for skill-bearing
|
|
4613
4701
|
// tasks. Never throws.
|
|
4614
|
-
|
|
4615
|
-
if (skillExec) {
|
|
4616
|
-
await installPackageSkills(channel.taskId, initialRoster, skillExec);
|
|
4617
|
-
} else {
|
|
4618
|
-
await installPackageSkills(channel.taskId, initialRoster);
|
|
4619
|
-
}
|
|
4702
|
+
await this.prepareSkills(channel, initialRoster);
|
|
4620
4703
|
if (!this.isActiveChannel(channel)) return false;
|
|
4621
4704
|
|
|
4622
4705
|
// ADR-053: wire the Playwright MCP browser before agents spawn — configs
|
|
@@ -6143,7 +6226,10 @@ export class Orchestrator {
|
|
|
6143
6226
|
// handled by the path that owns this spawn slot.
|
|
6144
6227
|
if (channel.spawning.has(agentId)) return true;
|
|
6145
6228
|
if (agent.accountBinding === "required") return false;
|
|
6146
|
-
|
|
6229
|
+
// ADR-168: only accounts allowing the agent's model count. With one (or
|
|
6230
|
+
// none) left, the normal error path benches the agent until it resets;
|
|
6231
|
+
// the model rule is never broken to keep it running.
|
|
6232
|
+
if (accountsAllowingModel(this.engineAccounts(channel, agent.kind), agent.model ?? null).length < 2) {
|
|
6147
6233
|
return false;
|
|
6148
6234
|
}
|
|
6149
6235
|
|
|
@@ -6161,6 +6247,7 @@ export class Orchestrator {
|
|
|
6161
6247
|
agent.kind,
|
|
6162
6248
|
current ? new Set([current]) : undefined,
|
|
6163
6249
|
agent.accountId,
|
|
6250
|
+
agent.model ?? null,
|
|
6164
6251
|
);
|
|
6165
6252
|
if (!next) return false;
|
|
6166
6253
|
|
|
@@ -6708,7 +6795,8 @@ export class Orchestrator {
|
|
|
6708
6795
|
return;
|
|
6709
6796
|
}
|
|
6710
6797
|
|
|
6711
|
-
|
|
6798
|
+
// ADR-168: never restart it on an account that doesn't allow its model.
|
|
6799
|
+
const accounts = accountsAllowingModel(this.engineAccounts(channel, agent.kind), agent.model ?? null);
|
|
6712
6800
|
const account =
|
|
6713
6801
|
accounts.find((a) => a.id === channel.accountByAgent.get(agentId)) ??
|
|
6714
6802
|
accounts[0];
|
|
@@ -7444,6 +7532,7 @@ export function buildSystemPreamble(
|
|
|
7444
7532
|
mode?: "open" | "secretary",
|
|
7445
7533
|
secretaryAgentId?: string,
|
|
7446
7534
|
proxiedKeys?: readonly { readonly key: string; readonly domains: readonly string[] }[],
|
|
7535
|
+
skillDelivery?: SkillDelivery,
|
|
7447
7536
|
): string {
|
|
7448
7537
|
const channelList = roster
|
|
7449
7538
|
.map((a) =>
|
|
@@ -7924,16 +8013,18 @@ export function buildSystemPreamble(
|
|
|
7924
8013
|
? [
|
|
7925
8014
|
"## Your skills",
|
|
7926
8015
|
"",
|
|
7927
|
-
...(
|
|
8016
|
+
...(!skillDelivery?.path
|
|
8017
|
+
? ["Skill files are unavailable. The complete guide follows inline:", "", renderSkillMd(agent)]
|
|
8018
|
+
: skillIndex.length > 0
|
|
7928
8019
|
? [
|
|
7929
|
-
`Your skills are indexed at \`${
|
|
8020
|
+
`Your skills are indexed at \`${skillDelivery?.path}\`:`,
|
|
7930
8021
|
`${skillNameList(skillIndex)}. Read the index at the start. Before work a skill`,
|
|
7931
8022
|
"covers, or an action the index names, read that file in full with `cat`; the",
|
|
7932
8023
|
"paths are beside the index. They're yours — other agents have their own.",
|
|
7933
8024
|
]
|
|
7934
8025
|
: [
|
|
7935
8026
|
"Reference material (links + documents) has been prepared for you at",
|
|
7936
|
-
`\`${
|
|
8027
|
+
`\`${skillDelivery?.path}\`. Read it when a task touches what`,
|
|
7937
8028
|
"it covers. It's yours — other agents have their own.",
|
|
7938
8029
|
]),
|
|
7939
8030
|
"",
|
|
@@ -7945,13 +8036,14 @@ export function buildSystemPreamble(
|
|
|
7945
8036
|
...(agent.kind === "claude" &&
|
|
7946
8037
|
(agent.skills ?? []).some((s) => s.type === "package")
|
|
7947
8038
|
? [
|
|
7948
|
-
"##
|
|
8039
|
+
"## Package skills",
|
|
7949
8040
|
"",
|
|
7950
|
-
"
|
|
7951
|
-
"when a task touches what they cover:",
|
|
8041
|
+
"Installation status for this task:",
|
|
7952
8042
|
...(agent.skills ?? [])
|
|
7953
8043
|
.filter((s) => s.type === "package")
|
|
7954
|
-
.map((s) =>
|
|
8044
|
+
.map((s) => skillDelivery?.installedPackages.includes(installedSkillPath(s))
|
|
8045
|
+
? `- **${s.name}** (\`${installedSkillPath(s)}\`) — installed`
|
|
8046
|
+
: `- **${s.name}** — unavailable; installation did not succeed.`),
|
|
7955
8047
|
"",
|
|
7956
8048
|
]
|
|
7957
8049
|
: []),
|
|
@@ -8246,6 +8338,27 @@ function finishAllTaskRecovery(): void {
|
|
|
8246
8338
|
for (const taskId of [...taskRecoveryBarriers.keys()]) {
|
|
8247
8339
|
finishTaskRecovery(taskId);
|
|
8248
8340
|
}
|
|
8341
|
+
abandonedTaskRecoveries.clear();
|
|
8342
|
+
}
|
|
8343
|
+
|
|
8344
|
+
/** Boot-recovery attempts under way, by task: a barrier is never released
|
|
8345
|
+
* under one (the attempt may be starting the task's runtime). */
|
|
8346
|
+
const recoveringTaskIds = new Set<string>();
|
|
8347
|
+
/** Tasks whose boot recovery a terminal command ended (F4): never retried. */
|
|
8348
|
+
const abandonedTaskRecoveries = new Set<string>();
|
|
8349
|
+
|
|
8350
|
+
/**
|
|
8351
|
+
* Terminal intent (task deletion / teardown of the current run): end this
|
|
8352
|
+
* task's boot recovery. Its barrier opens now, or as soon as an attempt
|
|
8353
|
+
* under way returns, and no later pass retries it, so the teardown queued
|
|
8354
|
+
* behind the barrier runs instead of waiting out every retry (F4, test 6.2:
|
|
8355
|
+
* a deleted task whose machine was never launched kept recovery retrying
|
|
8356
|
+
* until the next restart). A no-op once the task's recovery is over.
|
|
8357
|
+
*/
|
|
8358
|
+
export function abandonTaskRecovery(taskId: string): void {
|
|
8359
|
+
if (!taskRecoveryBarriers.has(taskId)) return;
|
|
8360
|
+
abandonedTaskRecoveries.add(taskId);
|
|
8361
|
+
if (!recoveringTaskIds.has(taskId)) finishTaskRecovery(taskId);
|
|
8249
8362
|
}
|
|
8250
8363
|
|
|
8251
8364
|
export function taskRecoveryComplete(taskId: string): Promise<void> {
|
|
@@ -9725,6 +9838,12 @@ async function recoveryPass(
|
|
|
9725
9838
|
);
|
|
9726
9839
|
for (const task of rows) {
|
|
9727
9840
|
if (!isCurrent()) break;
|
|
9841
|
+
if (!lifecycle && abandonedTaskRecoveries.has(task.taskId)) {
|
|
9842
|
+
abandonedTaskRecoveries.delete(task.taskId);
|
|
9843
|
+
finishTaskRecovery(task.taskId);
|
|
9844
|
+
continue;
|
|
9845
|
+
}
|
|
9846
|
+
if (!lifecycle) recoveringTaskIds.add(task.taskId);
|
|
9728
9847
|
try {
|
|
9729
9848
|
const recovered = lifecycle
|
|
9730
9849
|
? await lifecycle.runTaskLifecycle(task.taskId, async () => {
|
|
@@ -9753,7 +9872,10 @@ async function recoveryPass(
|
|
|
9753
9872
|
isCurrent,
|
|
9754
9873
|
consumerLifecycle,
|
|
9755
9874
|
);
|
|
9756
|
-
if (
|
|
9875
|
+
if (!lifecycle && abandonedTaskRecoveries.delete(task.taskId)) {
|
|
9876
|
+
// Ended by a terminal command while this attempt ran.
|
|
9877
|
+
finishTaskRecovery(task.taskId);
|
|
9878
|
+
} else if (recovered) {
|
|
9757
9879
|
if (!lifecycle) finishTaskRecovery(task.taskId);
|
|
9758
9880
|
} else {
|
|
9759
9881
|
deferred.add(task.taskId);
|
|
@@ -9765,6 +9887,8 @@ async function recoveryPass(
|
|
|
9765
9887
|
`[orchestrator] recovery: ${task.taskId} failed:`,
|
|
9766
9888
|
err instanceof Error ? err.message : err,
|
|
9767
9889
|
);
|
|
9890
|
+
} finally {
|
|
9891
|
+
if (!lifecycle) recoveringTaskIds.delete(task.taskId);
|
|
9768
9892
|
}
|
|
9769
9893
|
}
|
|
9770
9894
|
} catch (err) {
|
|
@@ -10086,6 +10210,18 @@ async function recoverPersistedTaskEnvironment(
|
|
|
10086
10210
|
: {}),
|
|
10087
10211
|
});
|
|
10088
10212
|
if (result.outcome === "recovered" && !consumersPrepared && isCurrent()) {
|
|
10213
|
+
const settled = result.status?.state;
|
|
10214
|
+
if (settled === "absent" || settled === "stopped") {
|
|
10215
|
+
// F4 (test 6.2): the provider proved nothing runs, so there is no
|
|
10216
|
+
// consumer to prepare. Preparing them anyway waited on a gateway
|
|
10217
|
+
// tunnel to a machine that does not exist, deferred recovery every
|
|
10218
|
+
// pass, and held Resume and deletion behind the task's barrier.
|
|
10219
|
+
// Settle the row as stopped instead, like Docker and Apple recovery:
|
|
10220
|
+
// Resume provisions it (starting a stopped machine, launching an
|
|
10221
|
+
// absent one), and deletion tears it down.
|
|
10222
|
+
settleRecoveredWithoutRuntime(task.taskId, settled);
|
|
10223
|
+
return true;
|
|
10224
|
+
}
|
|
10089
10225
|
const current = getHostTask(task.taskId);
|
|
10090
10226
|
if (current?.statusMirror && isActive(current.statusMirror)) {
|
|
10091
10227
|
await prepareConsumers();
|
|
@@ -10101,6 +10237,22 @@ async function recoverPersistedTaskEnvironment(
|
|
|
10101
10237
|
}
|
|
10102
10238
|
}
|
|
10103
10239
|
|
|
10240
|
+
/** A recovered environment with nothing running: drop the gateway tunnel the
|
|
10241
|
+
* recovery armed, mark an active row stopped, and revoke its gateway token. */
|
|
10242
|
+
function settleRecoveredWithoutRuntime(
|
|
10243
|
+
taskId: string,
|
|
10244
|
+
state: "absent" | "stopped",
|
|
10245
|
+
): void {
|
|
10246
|
+
stopMachineGatewayTunnel(taskId);
|
|
10247
|
+
const current = getHostTask(taskId);
|
|
10248
|
+
if (!current?.statusMirror || !isActive(current.statusMirror)) return;
|
|
10249
|
+
db_setStatus(taskId, "stopped", { codeServerPort: null, previewPorts: "[]" });
|
|
10250
|
+
clearTaskGatewayAcl(taskId);
|
|
10251
|
+
console.log(
|
|
10252
|
+
`[orchestrator] recovery: ${taskId} has no running environment (${state}); marked stopped until Resume`,
|
|
10253
|
+
);
|
|
10254
|
+
}
|
|
10255
|
+
|
|
10104
10256
|
/** A durable row the provider can never reconcile with its locator. Retrying
|
|
10105
10257
|
* cannot change the verdict, so the sweep must not treat it as an unknown
|
|
10106
10258
|
* runtime state: that kept the whole runtime in checking, retrying every
|
|
@@ -11407,3 +11559,22 @@ function db_setRuntime(
|
|
|
11407
11559
|
): void {
|
|
11408
11560
|
upsertHostTask(taskId, extras);
|
|
11409
11561
|
}
|
|
11562
|
+
|
|
11563
|
+
/** ADR-168: the lease names native accounts of `kind`, but none allows
|
|
11564
|
+
* `model` — the words an agent stops with when an admin narrowed them. */
|
|
11565
|
+
function leasedModelExcluded(lease: TaskEngineLease, kind: string, model: string | undefined): boolean {
|
|
11566
|
+
const native = lease.accounts.filter(
|
|
11567
|
+
(account): account is LeasedEngineAccount =>
|
|
11568
|
+
account.engineKind === kind && account.authKind !== "custom-connection" && isLeasedEngineAccount(account),
|
|
11569
|
+
);
|
|
11570
|
+
return native.length > 0 && !native.some((account) => accountAllowsModel(account.allowedModels, kind, model ?? null));
|
|
11571
|
+
}
|
|
11572
|
+
|
|
11573
|
+
/** ADR-168: the accounts allowing `model` (pure; kept here so a test that
|
|
11574
|
+
* mocks the engine-accounts module wholesale still filters). */
|
|
11575
|
+
function accountsAllowingModel<T extends { kind: string; allowedModels?: readonly string[] }>(
|
|
11576
|
+
accounts: readonly T[],
|
|
11577
|
+
model: string | null,
|
|
11578
|
+
): T[] {
|
|
11579
|
+
return accounts.filter((account) => accountAllowsModel(account.allowedModels, account.kind, model));
|
|
11580
|
+
}
|