agents-relay 2.0.256 → 2.0.258
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/README.md +26 -13
- package/dist/agent-script-discovery.js +56 -0
- package/dist/cli-coordinator.js +71 -0
- package/dist/cli-help.js +36 -30
- package/dist/cli-job-create.js +37 -4
- package/dist/cli.js +21 -12
- package/dist/dag-result-contract.js +2 -2
- package/dist/{shortcut-stage-contract.js → dag-stage-contract.js} +1 -1
- package/dist/dag-task-runtime.js +4 -33
- package/dist/dashboard-jel.js +8 -12
- package/dist/job-execution-slot.js +3 -11
- package/dist/pool.js +2 -13
- package/dist/reconciler-runtime.js +4 -1
- package/dist/reconciler.js +12 -29
- package/dist/relay-job-snapshot-reads.js +2 -5
- package/dist/relay-workflow-operations.js +2 -3
- package/dist/relayd-control.js +5 -0
- package/dist/relayd.js +1 -3
- package/dist/runtime-status.js +0 -33
- package/dist/script-task-adapter.js +2 -2
- package/dist/task-inactivity-watchdog.js +3 -6
- package/dist/worker-failure-recovery.js +1 -1
- package/dist/workflow/action-ledger.js +1 -1
- package/dist/workflow/contracts.js +0 -28
- package/dist/workflow/definitions-v2.js +1 -8
- package/dist/workflow/runtime.js +0 -9
- package/package.json +6 -6
- package/skills/agents-relay/SKILL.md +41 -20
- package/skills/agents-relay/contracts/event-contract.md +4 -5
- package/skills/agents-relay/contracts/task-job-contract.md +35 -1
- package/workflow/job-lifecycle.mmd +0 -8
- package/workflow/task-lifecycle.mmd +1 -26
- package/dist/agent-shortcut.js +0 -587
- package/dist/cli-shortcut-local.js +0 -50
- package/dist/cli-shortcut.js +0 -267
- package/dist/reconciler-shortcut.js +0 -74
- package/dist/shortcut-node-revision.js +0 -21
- package/dist/shortcut-node-worker.js +0 -144
- package/dist/shortcut-review-wake.js +0 -64
- package/dist/shortcut-worker-runner.js +0 -64
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
function occupiesSlot(job, task) {
|
|
1
|
+
/** Coordinator Tasks hold no Worker slot. Actual Agent executions are leased. */
|
|
2
|
+
function occupiesSlot(_job, task) {
|
|
4
3
|
if (task.agentGraph && task.result?.data?.dag?.version === 1)
|
|
5
4
|
return false;
|
|
6
|
-
|
|
7
|
-
const delegatedWorker = job.executionMode === 'shortcut' && job.contentOnly === true && task.state === 'RUNNING'
|
|
8
|
-
&& shortcut && typeof shortcut === 'object'
|
|
9
|
-
&& Object.keys(shortcut.workerNodes ?? {}).length > 0;
|
|
10
|
-
const durableWait = job.executionMode === 'shortcut' && job.contentOnly === true && task.state === 'RUNNING'
|
|
11
|
-
&& task.leaseOwner === null && shortcut && typeof shortcut === 'object'
|
|
12
|
-
&& Object.keys(shortcut.waits ?? {}).length > 0;
|
|
13
|
-
return task.state !== 'AWAITING_DECISION' && !durableWait && !delegatedWorker &&
|
|
5
|
+
return task.state !== 'AWAITING_DECISION' &&
|
|
14
6
|
(task.state === 'RUNNING' || (task.executionId !== null && !['SUCCEEDED', 'FAILED', 'CANCELLED'].includes(task.state)));
|
|
15
7
|
}
|
|
16
8
|
function plannerOccupies(job, planId) {
|
package/dist/pool.js
CHANGED
|
@@ -76,19 +76,17 @@ export class RepositoryWorkerPool {
|
|
|
76
76
|
makeReconciler;
|
|
77
77
|
localInventory;
|
|
78
78
|
resolveLocalJob;
|
|
79
|
-
onShortcutDecision;
|
|
80
79
|
running = false;
|
|
81
80
|
pending = false;
|
|
82
81
|
reconcileLocks = new Map();
|
|
83
82
|
coordinator;
|
|
84
83
|
dispatchTail = Promise.resolve();
|
|
85
84
|
watchedBus;
|
|
86
|
-
constructor(concurrency, makeReconciler, localInventory, resolveLocalJob
|
|
85
|
+
constructor(concurrency, makeReconciler, localInventory, resolveLocalJob) {
|
|
87
86
|
this.concurrency = concurrency;
|
|
88
87
|
this.makeReconciler = makeReconciler;
|
|
89
88
|
this.localInventory = localInventory;
|
|
90
89
|
this.resolveLocalJob = resolveLocalJob;
|
|
91
|
-
this.onShortcutDecision = onShortcutDecision;
|
|
92
90
|
const reportCoordinatorError = (error, signal) => {
|
|
93
91
|
observability().record({
|
|
94
92
|
stage: 'reconcile', event: 'reconcile.coordinator_failed', level: 'error', outcome: 'failed',
|
|
@@ -178,12 +176,6 @@ export class RepositoryWorkerPool {
|
|
|
178
176
|
if (signal.event.type === 'github.webhook')
|
|
179
177
|
continue;
|
|
180
178
|
const outcome = await reconciler.applyEvent(signal.event);
|
|
181
|
-
// The decision is durably applied before invoking the Shortcut CLI hook.
|
|
182
|
-
// A replay can also wake a still-QUEUED Task without a new decision.
|
|
183
|
-
if (signal.event.type === 'task.interactive_decision' && !target.job.tasks.some(t => unifiedDAG(target.job, t)) &&
|
|
184
|
-
['task.interactive_decision.accepted', 'task.interactive_decision.duplicate'].includes(outcome.reason) &&
|
|
185
|
-
await this.onShortcutDecision?.(jobId, signal.event.task_id))
|
|
186
|
-
continue;
|
|
187
179
|
shouldReconcile ||= outcome.reconcile;
|
|
188
180
|
}
|
|
189
181
|
if (shouldReconcile)
|
|
@@ -195,9 +187,6 @@ export class RepositoryWorkerPool {
|
|
|
195
187
|
for (const job of jobs) {
|
|
196
188
|
if (capacity <= 0)
|
|
197
189
|
break;
|
|
198
|
-
// Legacy in-flight Shortcut Jobs retain their original foreground owner.
|
|
199
|
-
if (job.executionMode === 'shortcut' && !job.tasks.some(t => unifiedDAG(job, t)))
|
|
200
|
-
continue;
|
|
201
190
|
const store = await this.requireLocalStore(job.id);
|
|
202
191
|
await store.hydrate?.(job);
|
|
203
192
|
const ready = job.tasks.filter(task => (task.state === 'QUEUED' && task.executionId === null) || (task.state === 'DRAFT' && task.dependencies.length > 0)).length;
|
|
@@ -280,7 +269,7 @@ export class RepositoryWorkerPool {
|
|
|
280
269
|
// GitHub transport is observational. It must never wake lifecycle execution.
|
|
281
270
|
if (event.type === 'github.webhook')
|
|
282
271
|
return;
|
|
283
|
-
const wake = event.type === 'job.wake' || event.type === 'review.created' || event.type === 'planner.completed'
|
|
272
|
+
const wake = event.type === 'job.wake' || event.type === 'review.created' || event.type === 'planner.completed';
|
|
284
273
|
if (!lifecycle && !wake)
|
|
285
274
|
return;
|
|
286
275
|
await this.coordinator.acceptTransport({
|
|
@@ -94,7 +94,10 @@ export class ReconcilerRuntimeBase {
|
|
|
94
94
|
const latest = await this.store.load(event.job_id);
|
|
95
95
|
const task = latest.tasks.find(item => item.id === event.task_id);
|
|
96
96
|
if (task?.dagNode) {
|
|
97
|
-
|
|
97
|
+
// Use the Coordinator's durable checkout for DAG stage validation.
|
|
98
|
+
// An independent local repo need not resolve through generic workspace lookup.
|
|
99
|
+
const projectPath = latest.graphStartContext?.projectPath ??
|
|
100
|
+
(this.options.projectPathForJob ? await this.options.projectPathForJob(latest, task) : undefined);
|
|
98
101
|
const invalid = await dagCompletionError(task, projectPath);
|
|
99
102
|
if (invalid)
|
|
100
103
|
return this.applyTerminalEvent({ ...event, type: 'task.failed',
|
package/dist/reconciler.js
CHANGED
|
@@ -32,7 +32,6 @@ import { cleanupMergedJobWorktree } from './job-worktree-cleanup.js';
|
|
|
32
32
|
import { jobHasConflictingExecution } from './job-execution-slot.js';
|
|
33
33
|
import { requiresWorkerInactivityWatchdog } from './task-inactivity-watchdog.js';
|
|
34
34
|
import { managedWorkerInput } from './managed-worker-input.js';
|
|
35
|
-
import { launchShortcutEffect, resumeShortcutEffect, resumeShortcutEventWaits } from './reconciler-shortcut.js';
|
|
36
35
|
export { managedWorkerInput } from './managed-worker-input.js';
|
|
37
36
|
import { recoverExpiredExecutions, recoverStartupOrphans as recoverStartupExecutionOrphans } from './execution-recovery.js';
|
|
38
37
|
import { dispatchJobReconcile } from './workflow/job-reconcile-v2.js';
|
|
@@ -57,15 +56,11 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
57
56
|
if (task.kind !== 'planner' && task.adapter !== 'orchestrator')
|
|
58
57
|
await this.launch(job, task);
|
|
59
58
|
}, context => `effect.launchTask:${context.jobId}:${context.taskId ?? 'task'}:${String(context.data?.attempt ?? 0)}:${String(context.data?.reviewInvocationId ?? 'initial')}`));
|
|
60
|
-
this.workflowEffects.register(new CallbackWorkflowEffectHandler('effect.launchShortcut', async (context) => launchShortcutEffect(this.store, this.options, context.jobId, context.taskId, event => this.emit(event)), context => `effect.launchShortcut:${context.jobId}:${context.taskId ?? 'task'}:${String(context.data?.attempt ?? 0)}`));
|
|
61
|
-
this.workflowEffects.register(new CallbackWorkflowEffectHandler('effect.resumeShortcut', async (context) => resumeShortcutEffect(this.store, this.options, context.jobId, context.taskId, context.data, event => this.emit(event)), context => `effect.resumeShortcut:${context.jobId}:${context.taskId ?? 'task'}:${String(context.data?.executionId ?? '')}:${String(context.data?.nodeId ?? '')}:${String(context.data?.waitId ?? '')}`));
|
|
62
59
|
this.workflowEffects.register(new CallbackWorkflowEffectHandler('effect.cancelActiveTasks', async (context) => this.cancelActiveTasks(context.jobId, String(context.data?.reason ?? 'Job terminated'))));
|
|
63
60
|
this.workflowEffects.register(new CallbackWorkflowEffectHandler('effect.cleanupJobWorktree', async (context) => cleanupMergedJobWorktree(await this.store.load(context.jobId), this.options.projectPathForJob), context => `effect.cleanupJobWorktree:${context.jobId}`));
|
|
64
61
|
}
|
|
65
62
|
async dispatchExecutableTasks(jobId) {
|
|
66
63
|
const scheduled = refreshTaskDependencies(await this.store.load(jobId));
|
|
67
|
-
if (scheduled.executionMode === 'shortcut' && !scheduled.tasks.some(t => unifiedDAG(scheduled, t)) && !this.options.shortcutRunnerOwner)
|
|
68
|
-
return scheduled;
|
|
69
64
|
if (scheduled.pause)
|
|
70
65
|
return scheduled;
|
|
71
66
|
for (const task of scheduled.tasks.filter(item => item.state === 'SUCCEEDED' && (item.continuation || scheduled.continuation) && !item.continuationDeliveredAt)) {
|
|
@@ -79,8 +74,7 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
79
74
|
const firstDAG = ready[0]?.dagNode?.parentTaskId;
|
|
80
75
|
const dispatchable = (firstDAG ? ready.filter(t => t.dagNode?.parentTaskId === firstDAG) : ready.slice(0, 1)).slice(0, capacity);
|
|
81
76
|
for (const task of dispatchable) {
|
|
82
|
-
|
|
83
|
-
await transitionTaskEvent(task, 'dispatch', { dispatchable: true, shortcutExecution: scheduled.executionMode === 'shortcut' && scheduled.contentOnly === true && shortcut?.workerFallback !== true && Boolean(task.agentGraph) && !unifiedDAG(scheduled, task), shortcutFallback: shortcut?.workerFallback === true, shortcutHasGraph: Boolean(task.agentGraph) }, async (actionId) => {
|
|
77
|
+
await transitionTaskEvent(task, 'dispatch', { dispatchable: true }, async (actionId) => {
|
|
84
78
|
const outcomes = await this.workflowEffects.execute([actionId], { jobId: scheduled.id, taskId: task.id, transitionKey: `dispatch:${task.attempt}`, data: { attempt: task.attempt, ...(task.interactiveInvocation?.decidedAt ? { reviewInvocationId: task.interactiveInvocation.invocationId } : {}) } });
|
|
85
79
|
await this.applyTaskEffectOutcomes(scheduled, task, outcomes);
|
|
86
80
|
}, async () => { await this.store.saveTask(task); });
|
|
@@ -95,8 +89,6 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
95
89
|
let job = await this.store.load(jobId);
|
|
96
90
|
// The same durable Job flag covers children, retries, and Troubleshooters.
|
|
97
91
|
// Do not let a background Reconciler mutate or dispatch any of them.
|
|
98
|
-
if (job.executionMode === 'shortcut' && !job.tasks.some(t => unifiedDAG(job, t)) && !this.options.shortcutRunnerOwner)
|
|
99
|
-
return job;
|
|
100
92
|
await drainProductionWorkflowOutbox(this.store, this.options);
|
|
101
93
|
await deliverPendingEscalations(this.store, jobId, this.options.escalationNotifier);
|
|
102
94
|
job = await this.store.load(jobId);
|
|
@@ -131,7 +123,6 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
131
123
|
await recoverExpiredExecutions(job, now, this.executionRecoveryPorts(job));
|
|
132
124
|
await repairLegacyOrchestrators(jobId, now, { store: this.store, owner: this.options.owner, emit: event => this.emit(event) });
|
|
133
125
|
await recoverInteractiveDecisions(this.store, jobId);
|
|
134
|
-
await this.resumeShortcutEventWaits(jobId);
|
|
135
126
|
await this.recoverPlannerChildren(job);
|
|
136
127
|
await retryPendingPlannerUnblocks({
|
|
137
128
|
store: this.store,
|
|
@@ -204,7 +195,7 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
204
195
|
scheduled = refreshTaskDependencies(await this.store.load(jobId));
|
|
205
196
|
}
|
|
206
197
|
scheduled = refreshTaskDependencies(await this.maybeCreatePlanner(scheduled));
|
|
207
|
-
scheduled = refreshTaskDependencies(await reconcileDAGSchedule({ store: this.store, jobId, job: scheduled, projectPathForTask: async (j, t) => j.graphStartContext?.projectPath ??
|
|
198
|
+
scheduled = refreshTaskDependencies(await reconcileDAGSchedule({ store: this.store, jobId, job: scheduled, projectPathForTask: async (j, t) => j.graphStartContext?.projectPath ?? (this.options.projectPathForJob ? this.options.projectPathForJob(j, t) : t.routing?.cwd ?? process.cwd()), roots: this.options.executionContextRoots }));
|
|
208
199
|
if (scheduled.state !== previousState || scheduled.updatedAt !== job.updatedAt)
|
|
209
200
|
await this.store.saveJob(scheduled);
|
|
210
201
|
scheduled = await this.dispatchExecutableTasks(jobId);
|
|
@@ -254,17 +245,6 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
254
245
|
this.reconciling = false;
|
|
255
246
|
}
|
|
256
247
|
}
|
|
257
|
-
async resumeShortcutEventWaits(jobId) {
|
|
258
|
-
await resumeShortcutEventWaits(this.store, this.options, jobId, async (job, task, matched) => {
|
|
259
|
-
await transitionTaskEvent(task, 'shortcut.result', { shortcutResultCorrelated: true }, async (actionId) => {
|
|
260
|
-
if (actionId !== 'effect.resumeShortcut')
|
|
261
|
-
throw new Error(`Unexpected action ${actionId} for a correlated shortcut result`);
|
|
262
|
-
const outcomes = await this.workflowEffects.execute([actionId], { jobId, taskId: task.id,
|
|
263
|
-
transitionKey: `shortcut-result:${matched.executionId}:${matched.nodeId}:${matched.waitId}`, data: { ...matched } });
|
|
264
|
-
await this.applyTaskEffectOutcomes(job, task, outcomes);
|
|
265
|
-
}, async () => this.store.saveTask(task));
|
|
266
|
-
}, event => this.emit(event));
|
|
267
|
-
}
|
|
268
248
|
async cancelActiveTasks(jobId, reason) {
|
|
269
249
|
return cancelActiveTasks(this.store, jobId, reason, taskId => { const live = this.plannerLive.get(taskId); if (live) {
|
|
270
250
|
clearTimeout(live.timer);
|
|
@@ -285,11 +265,10 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
285
265
|
emitFailed: async (task, reason) => { await this.emit(eventFor(job.id, task.id, task.parentTaskId, 'task.failed', 'failed', task.error ?? reason, 'user', { reason })); },
|
|
286
266
|
};
|
|
287
267
|
}
|
|
288
|
-
async recoverLostExecutions(job, now) {
|
|
289
|
-
await recoverExpiredExecutions(job, now, this.executionRecoveryPorts(job)); }
|
|
268
|
+
async recoverLostExecutions(job, now) { await recoverExpiredExecutions(job, now, this.executionRecoveryPorts(job)); }
|
|
290
269
|
async recoverStartupOrphans(jobId) {
|
|
291
270
|
const job = await this.store.load(jobId);
|
|
292
|
-
if (job.state === 'ACTIVE'
|
|
271
|
+
if (job.state === 'ACTIVE') {
|
|
293
272
|
await recoverStartupExecutionOrphans(job, this.executionRecoveryPorts(job));
|
|
294
273
|
}
|
|
295
274
|
return this.store.load(jobId);
|
|
@@ -305,8 +284,6 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
305
284
|
// Terminal Jobs can repair projections and re-review, but must not reopen planning.
|
|
306
285
|
if (job.state !== 'ACTIVE')
|
|
307
286
|
return job;
|
|
308
|
-
if (job.executionMode === 'shortcut')
|
|
309
|
-
return job;
|
|
310
287
|
const pending = pendingPlan(job);
|
|
311
288
|
const recoverable = pending && !this.plannerLive.has(pending.id)
|
|
312
289
|
&& (!pending.executionId || pending.leaseOwner !== this.options.owner || !pending.leaseExpiresAt || Date.parse(pending.leaseExpiresAt) <= (this.options.now ?? new Date()).getTime())
|
|
@@ -455,7 +432,13 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
455
432
|
if (!reserved)
|
|
456
433
|
throw new Error('already reserved launch attempt: reconcile existing generation');
|
|
457
434
|
}
|
|
458
|
-
const adapter = task.adapter === 'script' ? new ScriptTaskAdapter(
|
|
435
|
+
const adapter = task.adapter === 'script' ? new ScriptTaskAdapter(async (event) => {
|
|
436
|
+
// Local Script Worker events must update Relay state even if an Event Bus
|
|
437
|
+
// subscriber is not attached to this Reconciler instance. Broadcasting
|
|
438
|
+
// alone is not an acknowledgement of a Task terminal transition.
|
|
439
|
+
await this.handleEvent(event);
|
|
440
|
+
await this.emit(event);
|
|
441
|
+
}, this.options.executionContextRoots) : this.options.adapters.find(x => x.name === task.adapter);
|
|
459
442
|
if (!adapter) {
|
|
460
443
|
await this.failLaunch(job.id, task.id, task.executionId, 'No adapter ' + task.adapter);
|
|
461
444
|
return;
|
|
@@ -463,7 +446,7 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
463
446
|
let executionContext;
|
|
464
447
|
try {
|
|
465
448
|
const role = isFinalReviewAgent(task.agentName) ? 'reviewer' : task.agentName === 'troubleshooter' ? 'troubleshooter' : task.parentTaskId ? 'nested-worker' : 'worker';
|
|
466
|
-
const projectPath = task.dagNode &&
|
|
449
|
+
const projectPath = task.dagNode && job.graphStartContext?.projectPath ? job.graphStartContext.projectPath : this.options.projectPathForJob ? await this.options.projectPathForJob(job, task) : task.routing?.cwd ?? process.cwd();
|
|
467
450
|
executionContext = await this.resolvedContext(job, task, role, projectPath);
|
|
468
451
|
}
|
|
469
452
|
catch (error) {
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { normalizeLegacyTaskLifecycle } from './types.js';
|
|
2
2
|
import { normalizeLegacyJobPrNumber } from './job-pr-number-migration.js';
|
|
3
3
|
export function currentJobMetadata(job) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { schedule: _schedule, executionMode, ...current } = job;
|
|
7
|
-
return (executionMode === 'shortcut'
|
|
8
|
-
? { ...current, executionMode: 'shortcut' } : current);
|
|
4
|
+
const { schedule: _schedule, executionMode: _executionMode, contentOnly: _contentOnly, shortcutExecutionStartedAt: _shortcutStarted, shortcutRunnerContext: _shortcutContext, shortcutExecutionDeadlineAt: _shortcutDeadline, ...current } = job;
|
|
5
|
+
return current;
|
|
9
6
|
}
|
|
10
7
|
export function normalizeRelayJob(json) {
|
|
11
8
|
const job = currentJobMetadata(normalizeLegacyJobPrNumber(JSON.parse(json)));
|
|
@@ -85,11 +85,10 @@ export class SQLiteWorkflowOperations {
|
|
|
85
85
|
throw new Error('authoritative job snapshot unavailable');
|
|
86
86
|
const job = JSON.parse(row.json);
|
|
87
87
|
const task = job.tasks.find(item => item.id === identity.taskId);
|
|
88
|
-
const
|
|
89
|
-
const decision = dispatchWorkflowGraphSync(taskLifecycleV2, { initialState: 'QUEUED', input: { transport: 'event', id: 'dispatch', payload: {} }, durableFacts: { dispatchable: true, shortcutExecution: job.executionMode === 'shortcut' && job.contentOnly === true && shortcut?.workerFallback !== true && Boolean(task?.agentGraph), shortcutFallback: shortcut?.workerFallback === true, shortcutHasGraph: Boolean(task?.agentGraph), shortcutDirectInvocation: job.executionMode === 'shortcut' && job.contentOnly === true } });
|
|
88
|
+
const decision = dispatchWorkflowGraphSync(taskLifecycleV2, { initialState: 'QUEUED', input: { transport: 'event', id: 'dispatch', payload: {} }, durableFacts: { dispatchable: true } });
|
|
90
89
|
if (!decision.accepted)
|
|
91
90
|
throw new Error('canonical Task Graph did not authorize launch');
|
|
92
|
-
const actionId = decision.actions.find(action => action.id === 'effect.launchTask'
|
|
91
|
+
const actionId = decision.actions.find(action => action.id === 'effect.launchTask')?.id;
|
|
93
92
|
if (!actionId)
|
|
94
93
|
throw new Error('canonical Task Graph did not authorize launch');
|
|
95
94
|
return new WorkflowActionLedger(this.db).reserveForClaimedDispatch({
|
package/dist/relayd-control.js
CHANGED
|
@@ -27,6 +27,8 @@ export function createWorkspaceControl(deps) {
|
|
|
27
27
|
throw new Error('job.create requires repository');
|
|
28
28
|
if ('schedule' in options)
|
|
29
29
|
throw new Error('Job schedules are unsupported');
|
|
30
|
+
if (options.coordinator && body.initialPlan === true)
|
|
31
|
+
throw Error('Coordinator Job must not request an initial Planner');
|
|
30
32
|
const result = await ensureManagedGitHubJob(client, repository, trusted, {
|
|
31
33
|
id: typeof options.id === 'string' && options.id ? options.id : undefined,
|
|
32
34
|
idempotencyKey: typeof options.idempotencyKey === 'string' ? options.idempotencyKey : undefined,
|
|
@@ -42,6 +44,7 @@ export function createWorkspaceControl(deps) {
|
|
|
42
44
|
creatorThreadId: typeof options.creatorThreadId === 'string' ? options.creatorThreadId : undefined,
|
|
43
45
|
implementationThreadId: typeof options.implementationThreadId === 'string' ? options.implementationThreadId : undefined,
|
|
44
46
|
noGitHub,
|
|
47
|
+
coordinator: options.coordinator,
|
|
45
48
|
persist: body.initialPlan !== true,
|
|
46
49
|
});
|
|
47
50
|
if (!repositories.includes(repository))
|
|
@@ -73,6 +76,8 @@ export function createWorkspaceControl(deps) {
|
|
|
73
76
|
await reconciler.close();
|
|
74
77
|
}
|
|
75
78
|
}
|
|
79
|
+
if (options.coordinator)
|
|
80
|
+
return { repository, pr: result.pr.number, job: result.job.id, state: result.job.state, taskId: 'coordinator' };
|
|
76
81
|
return { repository, pr: result.pr.number, job: result.job.id, state: result.job.state };
|
|
77
82
|
}
|
|
78
83
|
if (!jobId)
|
package/dist/relayd.js
CHANGED
|
@@ -10,7 +10,6 @@ import { ZAdapter } from './z-adapter.js';
|
|
|
10
10
|
import { CodexThreadContinuation, CommandContinuation, WebhookContinuation } from './continuation.js';
|
|
11
11
|
import { serveDashboard } from './dashboard.js';
|
|
12
12
|
import { RepositoryWorkerPool } from './pool.js';
|
|
13
|
-
import { createShortcutReviewWake } from './shortcut-review-wake.js';
|
|
14
13
|
import { Reconciler } from './reconciler.js';
|
|
15
14
|
import { dashboardManagedJobs, GitHubStore, InMemoryStore, resolvePullRequest } from './store.js';
|
|
16
15
|
import { GitHubProjectionWriter } from './projected-store.js';
|
|
@@ -392,8 +391,7 @@ export async function runDaemon(argv) {
|
|
|
392
391
|
})();
|
|
393
392
|
return githubBindingSyncInFlight;
|
|
394
393
|
};
|
|
395
|
-
const
|
|
396
|
-
const pool = new RepositoryWorkerPool(concurrency, makeReconciler, inventoryFromLocal, localJobBinding, shortcutReviewWake);
|
|
394
|
+
const pool = new RepositoryWorkerPool(concurrency, makeReconciler, inventoryFromLocal, localJobBinding);
|
|
397
395
|
const initial = cachedOverviews;
|
|
398
396
|
const fallback = initial[0]?.job;
|
|
399
397
|
const dashboardStore = fallback ? (await requireLocalJobBinding(fallback.id)).store : new InMemoryStore();
|
package/dist/runtime-status.js
CHANGED
|
@@ -36,39 +36,6 @@ export function deriveJobRuntimeStatus(job, _prState = 'OPEN') {
|
|
|
36
36
|
return 'COMPLETED';
|
|
37
37
|
if (job.state === 'DRAFT')
|
|
38
38
|
return 'IDLE';
|
|
39
|
-
// A Shortcut Job is owned by an external foreground runner, not the Relay
|
|
40
|
-
// scheduler queue. Do not advertise a not-yet-invoked Shortcut as QUEUED,
|
|
41
|
-
// or a content-only Shortcut as pending a PR merge/review.
|
|
42
|
-
if (job.executionMode === 'shortcut' && job.contentOnly === true) {
|
|
43
|
-
const now = Date.now();
|
|
44
|
-
const hasLiveLease = (task) => task.state === 'RUNNING'
|
|
45
|
-
&& Boolean(task.executionId && task.leaseOwner && task.leaseExpiresAt)
|
|
46
|
-
&& Number.isFinite(Date.parse(task.leaseExpiresAt)) && Date.parse(task.leaseExpiresAt) > now;
|
|
47
|
-
const children = job.tasks.filter(task => task.parentTaskId !== null);
|
|
48
|
-
if (children.some(task => task.state === 'BLOCKED') && !children.some(hasLiveLease))
|
|
49
|
-
return 'BLOCKED';
|
|
50
|
-
if (children.some(task => task.state === 'FAILED') && !children.some(hasLiveLease))
|
|
51
|
-
return 'FAILED';
|
|
52
|
-
if (job.tasks.some(task => task.state === 'FAILED') && !job.tasks.some(hasLiveLease))
|
|
53
|
-
return 'FAILED';
|
|
54
|
-
if (job.pause)
|
|
55
|
-
return 'WAITING';
|
|
56
|
-
if (job.tasks.some(task => task.state === 'AWAITING_DECISION'))
|
|
57
|
-
return 'WAITING';
|
|
58
|
-
if (job.tasks.some(hasLiveLease))
|
|
59
|
-
return 'RUNNING';
|
|
60
|
-
const running = job.tasks.filter(task => task.state === 'RUNNING');
|
|
61
|
-
// WAITING_EVENT intentionally releases the runner lease but keeps the Task
|
|
62
|
-
// RUNNING until its correlated event receipt arrives.
|
|
63
|
-
if (running.some(task => task.leaseOwner === null && Boolean(task.executionId)
|
|
64
|
-
&& Object.values(task.result?.data?.shortcut?.waits ?? {})
|
|
65
|
-
.some(wait => wait.executionId === task.executionId)))
|
|
66
|
-
return 'WAITING';
|
|
67
|
-
// A RUNNING Task without a current lease or event wait is not executing.
|
|
68
|
-
if (running.length > 0)
|
|
69
|
-
return 'BLOCKED';
|
|
70
|
-
return 'WAITING'; // External Shortcut Runner has not started or needs a resume.
|
|
71
|
-
}
|
|
72
39
|
// A DAG Coordinator is not a leased worker. Human review waiting takes
|
|
73
40
|
// precedence unless another Agent Task is genuinely running.
|
|
74
41
|
if (job.tasks.some(t => t.state === 'AWAITING_DECISION') &&
|
|
@@ -5,7 +5,7 @@ import { mkdir, writeFile } from 'node:fs/promises';
|
|
|
5
5
|
import { pathToFileURL } from 'node:url';
|
|
6
6
|
import { eventFor } from './events.js';
|
|
7
7
|
import { executionEventSource } from './execution-event-identity.js';
|
|
8
|
-
import {
|
|
8
|
+
import { discoverScriptAgent } from './agent-script-discovery.js';
|
|
9
9
|
import { spawnOwnedProcess } from './owned-process.js';
|
|
10
10
|
const valid = (value) => {
|
|
11
11
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
@@ -75,7 +75,7 @@ export class ScriptTaskAdapter {
|
|
|
75
75
|
const projectPath = context.executionContext?.project.path ?? input.projectPath;
|
|
76
76
|
if (typeof projectPath !== 'string' || !isAbsolute(projectPath))
|
|
77
77
|
throw Error('No trusted Script Project context');
|
|
78
|
-
const script = await
|
|
78
|
+
const script = await discoverScriptAgent(task.agentName, projectPath, this.roots.sharedRoot ?? undefined, this.roots.workspaceRoot ?? undefined, this.roots.globalRoot ?? undefined);
|
|
79
79
|
if (!script)
|
|
80
80
|
throw Error(`Declared Agent Shortcut is unavailable: ${task.agentName}`);
|
|
81
81
|
await send('task.started', 'running', 'Script Worker started');
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { executionEventSource, eventSourceId } from './execution-event-identity.js';
|
|
2
|
-
/** A
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const shortcut = task.result?.data?.shortcut;
|
|
6
|
-
return !(job.executionMode === 'shortcut' && job.contentOnly === true
|
|
7
|
-
&& Boolean(task.agentGraph) && shortcut?.workerFallback !== true);
|
|
2
|
+
/** A Coordinator has no Worker execution; Agent Tasks retain all watchdogs. */
|
|
3
|
+
export function requiresWorkerInactivityWatchdog(_job, task) {
|
|
4
|
+
return !(task.agentGraph && task.executionId === null);
|
|
8
5
|
}
|
|
9
6
|
export function isRecoverableWatchdogFailure(task) {
|
|
10
7
|
if (['worker_start_timeout', 'terminal_event_timeout', 'worker_exit_before_start', 'worker_exit_without_terminal_event', 'worker_delivery_after_start'].includes(task.failureReason ?? ''))
|
|
@@ -16,7 +16,7 @@ export async function handleWorkerLaunchFailure(ports, jobId, taskId, executionI
|
|
|
16
16
|
&& currentTask.executionId === executionId
|
|
17
17
|
&& !currentTask.lastProgressEventAt
|
|
18
18
|
&& !activeExecution?.workerStarted;
|
|
19
|
-
const canRetryNoStart = noStarted
|
|
19
|
+
const canRetryNoStart = noStarted
|
|
20
20
|
&& (currentTask?.adapter === 'chatgpt' || currentTask?.adapter === 'z')
|
|
21
21
|
&& !isFinalReviewAgent(currentTask.agentName)
|
|
22
22
|
&& currentTask.agentName !== 'troubleshooter' && currentTask.kind !== 'planner'
|
|
@@ -50,7 +50,7 @@ export class WorkflowActionLedger {
|
|
|
50
50
|
* execution lease; task.started later transitions it to RUNNING. */
|
|
51
51
|
reserveForClaimedDispatch(identity, decision, conditionId) {
|
|
52
52
|
if (!decision.accepted || decision.source !== 'QUEUED' || decision.target !== 'QUEUED'
|
|
53
|
-
||
|
|
53
|
+
|| identity.actionId !== 'effect.launchTask')
|
|
54
54
|
throw Error('dispatch reservation requires canonical QUEUED Graph launch decision');
|
|
55
55
|
return this.reserveForRunningTask(identity, decision, conditionId, new Date().toISOString(), 'QUEUED');
|
|
56
56
|
}
|
|
@@ -39,13 +39,6 @@ export const WORKFLOW_EVENT_NAMES = [
|
|
|
39
39
|
'task.failed',
|
|
40
40
|
'task.progress',
|
|
41
41
|
'task.started',
|
|
42
|
-
'shortcut.waiting',
|
|
43
|
-
'shortcut.completed',
|
|
44
|
-
'content.completed',
|
|
45
|
-
'shortcut.failed',
|
|
46
|
-
'shortcut.result',
|
|
47
|
-
'effect.launchShortcut.failed',
|
|
48
|
-
'effect.resumeShortcut.failed',
|
|
49
42
|
'task.unblocked',
|
|
50
43
|
'watchdog.failed',
|
|
51
44
|
'worker.delivery_failed',
|
|
@@ -58,12 +51,7 @@ export const WORKFLOW_FACT_NAMES = [
|
|
|
58
51
|
'dependenciesUnsatisfied',
|
|
59
52
|
'runnable',
|
|
60
53
|
'dispatchable',
|
|
61
|
-
'shortcutExecution',
|
|
62
|
-
'shortcutFallback',
|
|
63
|
-
'shortcutHasGraph',
|
|
64
|
-
'shortcutDirectInvocation',
|
|
65
54
|
'shortcutEffectsSafe',
|
|
66
|
-
'shortcutResultCorrelated',
|
|
67
55
|
'notMerged',
|
|
68
56
|
'autoMerge',
|
|
69
57
|
'recoverableExecution',
|
|
@@ -88,16 +76,12 @@ export const WORKFLOW_MUTATION_NAMES = [
|
|
|
88
76
|
'mutation.markStartupOrphanedExhausted',
|
|
89
77
|
'mutation.markUnknownOutcome',
|
|
90
78
|
'mutation.markPlannerUnavailable',
|
|
91
|
-
'mutation.markShortcutWorkerFallback',
|
|
92
|
-
'mutation.markShortcutRecoveryRequired',
|
|
93
79
|
'mutation.preparePlatformFallback',
|
|
94
80
|
'mutation.prepareNoStartFallback',
|
|
95
81
|
'mutation.quarantinePlatformFailure',
|
|
96
82
|
];
|
|
97
83
|
export const WORKFLOW_EFFECT_NAMES = [
|
|
98
84
|
'effect.launchTask',
|
|
99
|
-
'effect.launchShortcut',
|
|
100
|
-
'effect.resumeShortcut',
|
|
101
85
|
'effect.cancelActiveTasks',
|
|
102
86
|
'effect.mergePullRequest',
|
|
103
87
|
'effect.deliverLocalMerge',
|
|
@@ -110,18 +94,6 @@ export const WORKFLOW_EFFECT_POLICIES = {
|
|
|
110
94
|
retry: 'workflow',
|
|
111
95
|
observability: 'workflow.effect',
|
|
112
96
|
},
|
|
113
|
-
'effect.launchShortcut': {
|
|
114
|
-
idempotency: 'job-task-attempt',
|
|
115
|
-
failureEvent: 'effect.launchShortcut.failed',
|
|
116
|
-
retry: 'workflow',
|
|
117
|
-
observability: 'workflow.effect',
|
|
118
|
-
},
|
|
119
|
-
'effect.resumeShortcut': {
|
|
120
|
-
idempotency: 'job-task-attempt',
|
|
121
|
-
failureEvent: 'effect.resumeShortcut.failed',
|
|
122
|
-
retry: 'workflow',
|
|
123
|
-
observability: 'workflow.effect',
|
|
124
|
-
},
|
|
125
97
|
'effect.cancelActiveTasks': {
|
|
126
98
|
idempotency: 'job-transition',
|
|
127
99
|
failureEvent: 'effect.cancelActiveTasks.failed',
|
|
@@ -5,7 +5,7 @@ import { WORKFLOW_EFFECT_NAMES, WORKFLOW_EVENT_NAMES, WORKFLOW_MUTATION_NAMES, }
|
|
|
5
5
|
const TASK_STATES = ['DRAFT', 'QUEUED', 'RUNNING', 'AWAITING_DECISION', 'BLOCKED', 'SUCCEEDED', 'FAILED', 'CANCELLED'];
|
|
6
6
|
const JOB_STATES = ['DRAFT', 'ACTIVE', 'COMPLETED', 'CANCELLED'];
|
|
7
7
|
const conditionRegistry = new ConditionRegistry([
|
|
8
|
-
...new Set(['dependenciesSatisfied', 'dependenciesUnsatisfied', 'runnable', 'dispatchable', 'recoverableExecution', 'troubleshooterRecovery', 'troubleshooterTask', 'awaitingInteractiveDecision', 'retryAvailable', 'notMerged', 'autoMerge', 'prOpen', 'reviewDisabled', 'implementationComplete', 'headAvailable', 'mergeCapable', 'localCompletionAllowed', 'localMergeReady'
|
|
8
|
+
...new Set(['dependenciesSatisfied', 'dependenciesUnsatisfied', 'runnable', 'dispatchable', 'recoverableExecution', 'troubleshooterRecovery', 'troubleshooterTask', 'awaitingInteractiveDecision', 'retryAvailable', 'notMerged', 'autoMerge', 'prOpen', 'reviewDisabled', 'implementationComplete', 'headAvailable', 'mergeCapable', 'localCompletionAllowed', 'localMergeReady'])
|
|
9
9
|
].map(booleanCondition));
|
|
10
10
|
const boolGuard = (name) => conditionRegistry.guard(name);
|
|
11
11
|
export const lifecycleConditions = conditionRegistry;
|
|
@@ -29,12 +29,7 @@ export const taskLifecycleV2 = load('task-lifecycle', TASK_STATES, {
|
|
|
29
29
|
dependenciesUnsatisfied: boolGuard('dependenciesUnsatisfied'),
|
|
30
30
|
runnable: boolGuard('runnable'),
|
|
31
31
|
dispatchable: boolGuard('dispatchable'),
|
|
32
|
-
shortcutExecution: facts => facts.durableFacts.shortcutExecution === true,
|
|
33
|
-
shortcutFallback: facts => facts.durableFacts.shortcutFallback === true,
|
|
34
|
-
shortcutHasGraph: facts => facts.durableFacts.shortcutHasGraph === true,
|
|
35
|
-
shortcutDirectInvocation: facts => facts.durableFacts.shortcutDirectInvocation === true,
|
|
36
32
|
shortcutEffectsSafe: facts => facts.durableFacts.shortcutEffectsSafe === true,
|
|
37
|
-
shortcutResultCorrelated: facts => facts.durableFacts.shortcutResultCorrelated === true,
|
|
38
33
|
recoverableExecution: boolGuard('recoverableExecution'),
|
|
39
34
|
troubleshooterRecovery: boolGuard('troubleshooterRecovery'),
|
|
40
35
|
troubleshooterTask: boolGuard('troubleshooterTask'),
|
|
@@ -63,8 +58,6 @@ export const jobLifecycleV2 = load('job-lifecycle', JOB_STATES, {
|
|
|
63
58
|
&& values.reviewSatisfied === true && values.localMergePresent === true
|
|
64
59
|
&& values.reviewHeadCurrent === true && values.mergeAttemptReady === true;
|
|
65
60
|
},
|
|
66
|
-
shortcutCompletionAllowed: facts => facts.durableFacts.shortcutCompletionAllowed === true,
|
|
67
|
-
contentCompletionAllowed: facts => facts.durableFacts.contentCompletionAllowed === true,
|
|
68
61
|
});
|
|
69
62
|
function topologyTargets(graph, from) {
|
|
70
63
|
const source = [...graph.nodes.values()].find(node => node.kind === 'state' && node.semanticId === from);
|
package/dist/workflow/runtime.js
CHANGED
|
@@ -38,15 +38,6 @@ export function applyTaskMutation(task, mutation) {
|
|
|
38
38
|
}
|
|
39
39
|
if (mutation === 'mutation.markPlannerUnavailable')
|
|
40
40
|
task.error = 'No objective planner configured';
|
|
41
|
-
if (mutation === 'mutation.markShortcutWorkerFallback') {
|
|
42
|
-
const data = task.result?.data ?? {};
|
|
43
|
-
const shortcut = data.shortcut && typeof data.shortcut === 'object' ? data.shortcut : {};
|
|
44
|
-
task.result = { summary: task.result?.summary ?? 'Shortcut fallback selected', data: { ...data, shortcut: { ...shortcut, workerFallback: true } } };
|
|
45
|
-
task.failureReason = 'shortcut_fallback';
|
|
46
|
-
}
|
|
47
|
-
if (mutation === 'mutation.markShortcutRecoveryRequired') {
|
|
48
|
-
task.failureReason = 'shortcut_requires_recovery';
|
|
49
|
-
}
|
|
50
41
|
if (mutation === 'mutation.prepareNoStartFallback') {
|
|
51
42
|
const route = task.routing;
|
|
52
43
|
if (task.adapter !== 'chatgpt' && task.adapter !== 'z')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agents-relay",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.258",
|
|
4
4
|
"description": "Durable async agent jobs coordinated through GitHub pull requests",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"test": "npm run test:full",
|
|
17
17
|
"test:chatgpt-temp-quality": "AGENTS_RELAY_RUN_CHATGPT_TEMP_QUALITY=1 sh -c \"npm run build && node test/quality/run-temporary-chat.mjs\"",
|
|
18
18
|
"dev": "tsx src/cli.ts",
|
|
19
|
-
"test:publish": "npm run build && node --import ./test/test-store-env.mjs --test --test-concurrency=1 --test-force-exit test/*.test.js test/verification/l3-
|
|
20
|
-
"test:l3:
|
|
21
|
-
"test:
|
|
22
|
-
"test:fast": "npm run build && node --import ./test/test-store-env.mjs --test --test-concurrency=2 test/workflow-lifecycle.test.js test/workflow-v2-lifecycle-parity.test.js test/workflow-effects.test.js test/relay-store.test.js test/local-authority.test.js test/local-jobid-routing.test.js test/interactive-request.test.js test/local-sqlite-jobid.test.js test/no-github.test.js test/reconcile-coordinator.test.js test/service-publication.test.js test/github-webhook.test.js test/
|
|
23
|
-
"test:full": "npm run build && node --import ./test/test-store-env.mjs --test --test-concurrency=1 test/*.test.js test/verification/
|
|
19
|
+
"test:publish": "npm run build && node --import ./test/test-store-env.mjs --test --test-concurrency=1 --test-force-exit test/*.test.js test/verification/l3-coordinator-review.test.mjs test/verification/l3-unified-dag.test.mjs",
|
|
20
|
+
"test:l3:dag": "npm run build && node --import ./test/test-store-env.mjs --test --test-concurrency=1 test/verification/l3-coordinator-review.test.mjs test/verification/l3-unified-dag.test.mjs",
|
|
21
|
+
"test:dag": "npm run build && node --import ./test/test-store-env.mjs --test --test-concurrency=1 test/verification/l3-coordinator-review.test.mjs test/verification/l3-unified-dag.test.mjs test/pool-dag-continuation.test.js test/coordinator-atomic-create.test.js",
|
|
22
|
+
"test:fast": "npm run build && node --import ./test/test-store-env.mjs --test --test-concurrency=2 test/workflow-lifecycle.test.js test/workflow-v2-lifecycle-parity.test.js test/workflow-effects.test.js test/relay-store.test.js test/local-authority.test.js test/local-jobid-routing.test.js test/interactive-request.test.js test/local-sqlite-jobid.test.js test/no-github.test.js test/reconcile-coordinator.test.js test/service-publication.test.js test/github-webhook.test.js test/coordinator-atomic-create.test.js test/pool-dag-continuation.test.js",
|
|
23
|
+
"test:full": "npm run build && node --import ./test/test-store-env.mjs --test --test-concurrency=1 test/*.test.js test/verification/l3-coordinator-review.test.mjs test/verification/l3-unified-dag.test.mjs && npm run test:verification:l3",
|
|
24
24
|
"test:verification:l1": "npm run build && node --test test/verification/harness.test.mjs test/verification/contract.test.mjs test/browser-worker-pool-graph.test.js test/verification/graph-inventory.test.mjs test/verification/dashboard-drilldown.test.mjs test/verification/evidence-matrix.test.mjs test/verification/task-resolution-classification.test.mjs test/verification/planner-contract.test.mjs test/verification/force-restate-validation.test.mjs test/planner-child-recovery.test.js",
|
|
25
25
|
"test:verification:l4:contracts": "npm run build && node --test test/verification/l4/prompt-evals.test.mjs",
|
|
26
26
|
"test:verification:l4": "node test/verification/l4/run-all.mjs",
|