agents-relay 2.0.251 → 2.0.253
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 +12 -9
- package/dist/agent-shortcut.js +2 -2
- package/dist/cli-help.js +4 -7
- package/dist/cli-review.js +29 -12
- package/dist/cli-shortcut.js +32 -0
- package/dist/dag-result-contract.js +48 -0
- package/dist/dag-task-runtime.js +214 -0
- package/dist/interactive-invocation.js +15 -24
- package/dist/interactive-request.js +11 -34
- package/dist/job-execution-slot.js +27 -21
- package/dist/pool.js +6 -3
- package/dist/reconciler-runtime.js +13 -5
- package/dist/reconciler.js +20 -21
- package/dist/relayd-control.js +5 -10
- package/dist/script-task-adapter.js +118 -0
- package/dist/shortcut-node-worker.js +1 -1
- package/dist/shortcut-review-wake.js +1 -1
- package/dist/workflow/contracts.js +1 -0
- package/dist/workflow/definitions-v2.js +2 -1
- package/package.json +4 -4
- package/skills/agents-relay/SKILL.md +36 -26
- package/skills/agents-relay/contracts/event-contract.md +17 -15
- package/workflow/job-lifecycle.mmd +4 -0
package/README.md
CHANGED
|
@@ -19,17 +19,20 @@ Relay appends `--handoff-file`, optional `--on-needs-user-file`, and `--cwd`
|
|
|
19
19
|
without using a shell. No Neo executable is assumed. Missing/failed executors
|
|
20
20
|
produce `technical_failure` rather than silently resolving a blocker.
|
|
21
21
|
|
|
22
|
-
**Shortcut
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Request Changes
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
**Unified DAG/Shortcut L3 gate:** `npm run test:l3:shortcut` covers both
|
|
23
|
+
legacy in-flight Shortcut recovery (four three-agent scenarios) and the new
|
|
24
|
+
ordinary Task Runtime: three Script Tasks without Review; all approvals;
|
|
25
|
+
Request Changes and fresh approval for Script and Model Agents; actual Shortcut
|
|
26
|
+
CLI activation; Normal-vs-Shortcut DAG equivalence; restart/idempotency;
|
|
27
|
+
fork/join concurrency; failed child Task using ordinary Relay recovery; EventBus
|
|
28
|
+
wake; and single-Agent Script execution. `Coordinator` only creates dependency-
|
|
29
|
+
ready Agent Tasks; each child uses existing Retry, Troubleshooter and Review.
|
|
30
|
+
No `NodeExecution`, Git Review commit, or second task scheduler. An inbox
|
|
31
|
+
receipt is not user approval. The L3 gate is included in `test:publish`.
|
|
29
32
|
|
|
30
33
|
**Interactive Review:** Relay owns the generic
|
|
31
|
-
`review.interactive.begin/wait/
|
|
32
|
-
|
|
34
|
+
`review.interactive.begin/wait/fail/abort` lifecycle, execution-bound
|
|
35
|
+
identity and decision correlation. The caller (Neo `review.preview`, backed by Markcut)
|
|
33
36
|
owns preview generation, media, UI and notifications. New waiting events use
|
|
34
37
|
`component: interactive-review`; existing recorded events retain their history.
|
|
35
38
|
|
package/dist/agent-shortcut.js
CHANGED
|
@@ -107,7 +107,7 @@ async function runCommand(args, cwd, signal) {
|
|
|
107
107
|
}
|
|
108
108
|
/** A Shortcut belongs to an Agent source, not to an independent name search.
|
|
109
109
|
* Only explicit Agent inheritance permits falling back to a parent's Shortcut. */
|
|
110
|
-
async function discoverShortcut(agent, projectPath, sharedRoot, workspaceRoot, globalRoot) {
|
|
110
|
+
export async function discoverShortcut(agent, projectPath, sharedRoot, workspaceRoot, globalRoot) {
|
|
111
111
|
let sources;
|
|
112
112
|
try {
|
|
113
113
|
({ sources } = await resolveAgentMarkdown(agent, BUNDLED_AGENTS_ROOT, projectPath, sharedRoot, agentSourceLayers(projectPath, { sharedRoot, workspaceRoot, globalRoot: globalRoot ?? process.env.AGENTS_HOME ?? join(homedir(), '.agents') })));
|
|
@@ -234,7 +234,7 @@ export async function runAgentShortcut(options) {
|
|
|
234
234
|
const pending = Object.entries(state.inFlight);
|
|
235
235
|
const inv = currentTask.interactiveInvocation;
|
|
236
236
|
if (pending.length !== 1 || !inv?.decidedAt || !['approved', 'changes_requested'].includes(inv.status) ||
|
|
237
|
-
inv.executionId !== pending[0][1] ||
|
|
237
|
+
inv.executionId !== pending[0][1] || inv.revision !== inv.executionId)
|
|
238
238
|
throw new Error('Shortcut checkpoint contains an interrupted module execution; refusing automatic replay');
|
|
239
239
|
resumedReview = { nodeId: pending[0][0], status: inv.status,
|
|
240
240
|
revision: inv.revision, invocationId: inv.invocationId, feedback: inv.feedback, comments: inv.comments };
|
package/dist/cli-help.js
CHANGED
|
@@ -98,13 +98,10 @@ Usage: npx agents-relay review job --repo OWNER/REPO --id JOB_ID [--thread-id TH
|
|
|
98
98
|
|
|
99
99
|
When provided, --thread-id persists a reviewer destination; otherwise the Job reviewer thread, then creator thread, then legacy review route is used. The command wakes Relay. Review Task creation, idempotency, routing and delivery remain graph/daemon-owned. Rejects in-flight/queued reviews; does not itself mark review delivered.
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
agents-relay review interactive fail --id JOB --task-id TASK --execution-id EXEC --invocation-id INV --reason REASON
|
|
106
|
-
agents-relay review interactive abort --id JOB --task-id TASK --execution-id EXEC --invocation-id INV
|
|
107
|
-
The CLI controls the running Relay daemon; this is not a separate Worker step.`,
|
|
101
|
+
Worker-facing: agents-relay review interactive --path /absolute/file.md --id JOB --task-id TASK --execution-id EXEC
|
|
102
|
+
This calls Neo review.preview and requests exactly one human review for the current execution. No Git commit or extra invocation ID.
|
|
103
|
+
Internal Neo delivery: review interactive begin|wait|fail|abort with --id, --task-id and --execution-id; fail adds --reason.
|
|
104
|
+
Task AWAITING_DECISION resumes on an execution-bound Approve or Request Changes event.`,
|
|
108
105
|
artifact: `Check a JSON artifact against a project-owned JSON Schema. Read-only; does not affect Task state or planning.
|
|
109
106
|
|
|
110
107
|
Usage: agents-relay artifact validate --artifact PATH --schema PATH
|
package/dist/cli-review.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { arg, hasArg, relayControlCommand } from './cli-support.js';
|
|
2
2
|
import { normalizeThreadId } from './reviewer-thread.js';
|
|
3
3
|
import { runOutcomeReview } from './outcome-review.js';
|
|
4
|
+
import { mkdtemp, writeFile, rm } from 'node:fs/promises';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join, isAbsolute } from 'node:path';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
8
|
+
import { execFile } from 'node:child_process';
|
|
9
|
+
const execFileAsync = promisify(execFile);
|
|
4
10
|
export function reviewRequestThreadOverride(args) {
|
|
5
11
|
const values = [...args];
|
|
6
12
|
return hasArg(values, '--thread-id')
|
|
@@ -10,27 +16,38 @@ export function reviewRequestThreadOverride(args) {
|
|
|
10
16
|
/** Stable local CLI contract for a caller-supplied single-call interactive review tool. */
|
|
11
17
|
export async function runInteractiveReviewCommand(argv) {
|
|
12
18
|
const [action, ...args] = argv;
|
|
13
|
-
const commands = ['begin', 'wait', '
|
|
19
|
+
const commands = ['begin', 'wait', 'fail', 'abort'];
|
|
20
|
+
if (action === 'request' || action === '--path') {
|
|
21
|
+
const options = action === '--path' ? argv : ['request', ...args];
|
|
22
|
+
const flags = action === '--path' ? options : options.slice(1);
|
|
23
|
+
const path = arg(flags, '--path'), jobId = arg(flags, '--id'), taskId = arg(flags, '--task-id'), executionId = arg(flags, '--execution-id');
|
|
24
|
+
if (!path || !isAbsolute(path) || !jobId || !taskId || !executionId)
|
|
25
|
+
throw new Error('review interactive requires --path ABS --id JOB --task-id TASK --execution-id EXEC');
|
|
26
|
+
const dir = await mkdtemp(join(tmpdir(), 'relay-review-'));
|
|
27
|
+
try {
|
|
28
|
+
const file = join(dir, 'request.json');
|
|
29
|
+
await writeFile(file, JSON.stringify({ path, relay: { jobId, taskId, executionId } }), { mode: 0o600 });
|
|
30
|
+
const { stdout } = await execFileAsync('neo', ['mcp', 'call', 'review.preview', '--args-file', file], { timeout: 120000, maxBuffer: 1024 * 1024 });
|
|
31
|
+
const receipt = JSON.parse(stdout);
|
|
32
|
+
if (receipt?.isError === true || receipt?.result?.isError === true)
|
|
33
|
+
throw Error('Neo review.preview rejected: ' + JSON.stringify(receipt).slice(0, 600));
|
|
34
|
+
console.log(JSON.stringify(receipt));
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
await rm(dir, { recursive: true, force: true });
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
14
41
|
if (!action || !commands.includes(action))
|
|
15
|
-
throw new Error('review interactive requires begin|wait|
|
|
42
|
+
throw new Error('review interactive requires --path or begin|wait|fail|abort');
|
|
16
43
|
const jobId = arg(args, '--id');
|
|
17
44
|
const taskId = arg(args, '--task-id');
|
|
18
45
|
const executionId = arg(args, '--execution-id');
|
|
19
|
-
const invocationId = arg(args, '--invocation-id');
|
|
20
46
|
if (!jobId || !taskId || !executionId)
|
|
21
47
|
throw new Error('review interactive requires --id --task-id --execution-id');
|
|
22
|
-
if (action !== 'begin' && !invocationId)
|
|
23
|
-
throw new Error('review interactive ' + action + ' requires --invocation-id');
|
|
24
|
-
const revision = arg(args, '--revision');
|
|
25
|
-
if (action === 'ready' && !/^[a-f0-9]{40}$/.test(revision))
|
|
26
|
-
throw new Error('review interactive ready requires full 40-character Git Commit SHA');
|
|
27
48
|
if (action === 'fail' && !arg(args, '--reason').trim())
|
|
28
49
|
throw new Error('review interactive fail requires --reason');
|
|
29
50
|
const body = { command: `review.interactive.${action}`, jobId, taskId, executionId };
|
|
30
|
-
if (action !== 'begin')
|
|
31
|
-
body.invocationId = invocationId;
|
|
32
|
-
if (action === 'ready')
|
|
33
|
-
body.revision = revision;
|
|
34
51
|
if (action === 'fail')
|
|
35
52
|
body.reason = arg(args, '--reason');
|
|
36
53
|
console.log(JSON.stringify(await relayControlCommand(args, body)));
|
package/dist/cli-shortcut.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { readFile } from 'node:fs/promises';
|
|
2
3
|
import { missingShortcutNodes, recordShortcutReceipt, runAgentShortcut, shortcutResumeEvent } from './agent-shortcut.js';
|
|
3
4
|
import { parseAgentGraph } from './agent-graph.js';
|
|
@@ -105,6 +106,37 @@ export async function runShortcutJobCommand(args, id, makeRunner) {
|
|
|
105
106
|
current.shortcutRunnerContext = ctx;
|
|
106
107
|
return current;
|
|
107
108
|
});
|
|
109
|
+
// Shortcut is an explicit activation point, not a separate Task engine.
|
|
110
|
+
// Previously launched, in-flight Shortcut checkpoints retain their legacy
|
|
111
|
+
// foreground owner; new Jobs use the ordinary Reconciler/DAG Task path.
|
|
112
|
+
const oldCheckpoint = task.result?.data?.shortcut;
|
|
113
|
+
const dagCheckpoint = task.result?.data?.dag;
|
|
114
|
+
const unified = dagCheckpoint?.version === 1 || (!hasArg(args, '--legacy-shortcut-runtime') && !oldCheckpoint && !job.shortcutExecutionStartedAt);
|
|
115
|
+
if (unified) {
|
|
116
|
+
if (!loaded.store.mutateJob)
|
|
117
|
+
throw Error('Unified DAG activation requires SQLite');
|
|
118
|
+
const hash = createHash('sha256').update(task.agentGraph).digest('hex');
|
|
119
|
+
await loaded.store.mutateJob(id, current => {
|
|
120
|
+
const root = current.tasks.find(t => t.id === taskId);
|
|
121
|
+
if (current.state !== 'ACTIVE' || !root || !root.agentGraph || root.agentGraph !== task.agentGraph)
|
|
122
|
+
throw Error('DAG activation Task identity changed');
|
|
123
|
+
if (root.state !== 'QUEUED' && root.state !== 'RUNNING')
|
|
124
|
+
throw Error('DAG Task cannot start from ' + root.state);
|
|
125
|
+
const prior = root.result?.data?.dag;
|
|
126
|
+
if (prior && (prior.version !== 1 || prior.graphHash !== hash))
|
|
127
|
+
throw Error('DAG runtime identity changed');
|
|
128
|
+
if (!prior)
|
|
129
|
+
root.result = { summary: 'DAG ready', data: { ...(root.result?.data ?? {}), dag: { version: 1, graphHash: hash } } };
|
|
130
|
+
if (!current.shortcutExecutionStartedAt)
|
|
131
|
+
current.shortcutExecutionStartedAt = new Date().toISOString();
|
|
132
|
+
return current;
|
|
133
|
+
});
|
|
134
|
+
const scheduled = await loaded.store.load(id);
|
|
135
|
+
await withEventBus(args, bus => publishWake(bus, scheduled, taskId, 'Shortcut DAG activation (normal Task scheduler)'));
|
|
136
|
+
console.log(JSON.stringify({ jobId: id, taskId, mode: 'shortcut', scheduled: true, state: scheduled.state,
|
|
137
|
+
graphRuntime: 'tasks', message: 'Task scheduling and Review are owned by the ordinary Relay Reconciler' }, null, 2));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
108
140
|
const missing = await missingShortcutNodes(task.agentGraph, projectPath, sharedRoot, workspaceRoot, globalRoot);
|
|
109
141
|
const previous = task.result?.data?.shortcut;
|
|
110
142
|
if (previous?.workerFallback === true)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { once } from 'node:events';
|
|
4
|
+
import { spawnOwnedProcess } from './owned-process.js';
|
|
5
|
+
import { validateShortcutStageGate } from './shortcut-stage-contract.js';
|
|
6
|
+
/** Validate an Agent DAG Task's required on-disk result before accepting
|
|
7
|
+
* task.completed. Invalid output is an ordinary Task failure and enters the
|
|
8
|
+
* existing Troubleshooter path; it must not strand a running Coordinator. */
|
|
9
|
+
export async function dagCompletionError(task, projectPath) {
|
|
10
|
+
if (!task.dagNode)
|
|
11
|
+
return null;
|
|
12
|
+
if (task.output?.kind !== 'file')
|
|
13
|
+
return 'DAG Agent Task has no file result target';
|
|
14
|
+
let parsed;
|
|
15
|
+
try {
|
|
16
|
+
parsed = JSON.parse(await readFile(task.output.path, 'utf8'));
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
return `DAG Agent result unreadable: ${error instanceof Error ? error.message : String(error)}`;
|
|
20
|
+
}
|
|
21
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
22
|
+
return 'DAG Agent result is not an object';
|
|
23
|
+
const record = parsed;
|
|
24
|
+
if (record.status !== 'COMPLETED' || !record.output || typeof record.output !== 'object' || Array.isArray(record.output))
|
|
25
|
+
return 'DAG Agent result must contain status COMPLETED and an output object';
|
|
26
|
+
if (!record.artifacts || typeof record.artifacts !== 'object' || Array.isArray(record.artifacts) &&
|
|
27
|
+
!record.artifacts.every(item => typeof item === 'string'))
|
|
28
|
+
return 'DAG Agent result must contain a list or object of artifacts';
|
|
29
|
+
if (projectPath && task.agentName) {
|
|
30
|
+
try {
|
|
31
|
+
await validateShortcutStageGate({ projectPath, agent: task.agentName, runPath: dirname(dirname(task.output.path)),
|
|
32
|
+
execute: async (args, cwd) => {
|
|
33
|
+
const abort = AbortSignal.timeout(300_000);
|
|
34
|
+
const child = spawnOwnedProcess(args[0], args.slice(1), { invocation: 'dag.stage-validation', signal: abort,
|
|
35
|
+
spawn: { cwd, stdio: ['ignore', 'pipe', 'pipe'] } });
|
|
36
|
+
let stdout = '', stderr = '';
|
|
37
|
+
child.stdout?.on('data', chunk => { stdout += String(chunk); });
|
|
38
|
+
child.stderr?.on('data', chunk => { stderr += String(chunk); });
|
|
39
|
+
const [code] = await once(child, 'close');
|
|
40
|
+
return { stdout, stderr, code: code ?? -1 };
|
|
41
|
+
} });
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return `DAG Stage contract rejected Task completion: ${error instanceof Error ? error.message : String(error)}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { dirname, isAbsolute, join } from 'node:path';
|
|
3
|
+
import { mkdir, readFile } from 'node:fs/promises';
|
|
4
|
+
import { taskOverallTimeoutMs } from './types.js';
|
|
5
|
+
import { parseAgentGraph } from './agent-graph.js';
|
|
6
|
+
import { discoverShortcut } from './agent-shortcut.js';
|
|
7
|
+
import { createTaskEntity } from './workflow/entity-creation.js';
|
|
8
|
+
import { tryTransitionTaskEvent } from './task-transitions.js';
|
|
9
|
+
import { dispatchJobLifecycleSync } from './workflow/lifecycle.js';
|
|
10
|
+
export function dagChildId(parentTaskId, nodeId) { return `dag-${parentTaskId}-${nodeId}`; }
|
|
11
|
+
export function unifiedDAG(job, task) {
|
|
12
|
+
if (!task.agentGraph)
|
|
13
|
+
return false;
|
|
14
|
+
if (job.executionMode !== 'shortcut')
|
|
15
|
+
return true;
|
|
16
|
+
return task.result?.data?.dag?.version === 1;
|
|
17
|
+
}
|
|
18
|
+
export function dagCoordinator(task) { return Boolean(task.agentGraph && task.result?.data?.dag?.version === 1); }
|
|
19
|
+
const sha = (s) => createHash('sha256').update(s).digest('hex');
|
|
20
|
+
const out = (task) => {
|
|
21
|
+
if (task.output?.kind !== 'file' || !isAbsolute(task.output.path))
|
|
22
|
+
throw Error('Graph Task requires a canonical absolute file output');
|
|
23
|
+
return dirname(task.output.path);
|
|
24
|
+
};
|
|
25
|
+
async function graphNodeOutput(task) {
|
|
26
|
+
if (task.state !== 'SUCCEEDED')
|
|
27
|
+
return null;
|
|
28
|
+
const data = task.result?.data;
|
|
29
|
+
if (data?.status === 'COMPLETED' && data.output && typeof data.output === 'object' && !Array.isArray(data.output))
|
|
30
|
+
return data.output;
|
|
31
|
+
if (task.output?.kind === 'file') {
|
|
32
|
+
let value;
|
|
33
|
+
try {
|
|
34
|
+
value = JSON.parse(await readFile(task.output.path, 'utf8'));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const record = value;
|
|
40
|
+
if (record?.status === 'COMPLETED' && record.output && typeof record.output === 'object' && !Array.isArray(record.output))
|
|
41
|
+
return record.output;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/** One durable Task is one DAG node. No independent node lease, retry, review or recovery.
|
|
46
|
+
* This is a reconciliation projection, not an execution scheduler: the normal
|
|
47
|
+
* Task graph owns dispatch and dependencies for every materialized child. */
|
|
48
|
+
export async function reconcileDAGTasks(options) {
|
|
49
|
+
const { store, jobId } = options;
|
|
50
|
+
if (!store.mutateJob)
|
|
51
|
+
throw Error('DAG Tasks require an atomic SQLite store');
|
|
52
|
+
const snapshot = await store.load(jobId);
|
|
53
|
+
for (const parent of snapshot.tasks.filter(t => unifiedDAG(snapshot, t))) {
|
|
54
|
+
if (parent.state === 'SUCCEEDED' || parent.state === 'CANCELLED' || parent.state === 'FAILED' || parent.state === 'BLOCKED')
|
|
55
|
+
continue;
|
|
56
|
+
const graph = parseAgentGraph(parent.agentGraph);
|
|
57
|
+
const graphHash = sha(parent.agentGraph);
|
|
58
|
+
const projectPath = await options.projectPathForTask(snapshot, parent);
|
|
59
|
+
const root = parent.output?.kind === 'file' && isAbsolute(parent.output.path) ? out(parent) : join(projectPath, '.relay-dag-results', jobId, parent.id);
|
|
60
|
+
if (parent.state === 'QUEUED') {
|
|
61
|
+
await store.mutateJob(jobId, job => {
|
|
62
|
+
const current = job.tasks.find(t => t.id === parent.id);
|
|
63
|
+
if (job.state !== 'ACTIVE' || job.pause || !current || current.state !== 'QUEUED' || !unifiedDAG(job, current))
|
|
64
|
+
return job;
|
|
65
|
+
const step = tryTransitionTaskEvent(current, 'task.started');
|
|
66
|
+
if (!step.accepted || step.target !== 'RUNNING')
|
|
67
|
+
throw Error('Task lifecycle rejected DAG coordinator start');
|
|
68
|
+
current.title = 'Coordinator';
|
|
69
|
+
current.result = { summary: 'DAG coordinator', data: { dag: { version: 1, graphHash } } };
|
|
70
|
+
current.updatedAt = new Date().toISOString();
|
|
71
|
+
return job;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const currentJob = await store.load(jobId);
|
|
75
|
+
const currentParent = currentJob.tasks.find(t => t.id === parent.id);
|
|
76
|
+
if (currentParent.state !== 'RUNNING' || !dagCoordinator(currentParent))
|
|
77
|
+
continue;
|
|
78
|
+
if ((currentParent.result?.data?.dag).graphHash !== graphHash)
|
|
79
|
+
throw Error('DAG changed after execution began');
|
|
80
|
+
for (const wave of graph.waves) {
|
|
81
|
+
for (const nodeId of wave) {
|
|
82
|
+
const childId = dagChildId(parent.id, nodeId);
|
|
83
|
+
if (currentJob.tasks.some(t => t.id === childId))
|
|
84
|
+
continue;
|
|
85
|
+
const parents = graph.edges.filter(e => e.to === nodeId).map(e => e.from);
|
|
86
|
+
const incoming = parents.map(id => currentJob.tasks.find(t => t.id === dagChildId(parent.id, id)));
|
|
87
|
+
if (incoming.some(t => !t || t.state !== 'SUCCEEDED'))
|
|
88
|
+
continue;
|
|
89
|
+
const predecessorOutputs = {};
|
|
90
|
+
for (let i = 0; i < parents.length; i++) {
|
|
91
|
+
const value = await graphNodeOutput(incoming[i]);
|
|
92
|
+
if (!value)
|
|
93
|
+
throw Error(`Completed DAG dependency ${parents[i]} has no structured result`);
|
|
94
|
+
predecessorOutputs[parents[i]] = value;
|
|
95
|
+
}
|
|
96
|
+
const node = graph.nodes.find(n => n.id === nodeId);
|
|
97
|
+
const script = await discoverShortcut(node.agent, projectPath, options.roots?.sharedRoot ?? undefined, options.roots?.workspaceRoot ?? undefined, options.roots?.globalRoot ?? undefined);
|
|
98
|
+
const childOut = join(root, '.dag-node-results', childId + '.json');
|
|
99
|
+
let supplied = { taskInput: parent.input };
|
|
100
|
+
try {
|
|
101
|
+
const parsed = JSON.parse(parent.input);
|
|
102
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed))
|
|
103
|
+
supplied = parsed;
|
|
104
|
+
}
|
|
105
|
+
catch { /* Plain Task Markdown remains taskInput. */ }
|
|
106
|
+
const { reviewDecision: _ignored, interactiveInvocation: _ignored2, jobId: _job, taskId: _task, projectPath: _project, ...projectInput } = supplied;
|
|
107
|
+
const input = JSON.stringify({ ...projectInput, source: 'relay-dag-task', jobId, parentTaskId: parent.id, nodeId, taskId: childId,
|
|
108
|
+
agent: node.agent, projectPath, predecessorOutputs, taskInput: parent.input, outputPath: childOut,
|
|
109
|
+
requiredResult: { status: 'COMPLETED', output: {}, artifacts: [] },
|
|
110
|
+
instruction: 'Execute this Agent DAG role using only declared predecessorOutputs and authorized project inputs. Write the structured result to outputPath. Do not invent source evidence, review decisions or publishing authorization.' });
|
|
111
|
+
await mkdir(dirname(childOut), { recursive: true, mode: 0o700 });
|
|
112
|
+
await store.mutateJob(jobId, job => {
|
|
113
|
+
const current = job.tasks.find(t => t.id === parent.id);
|
|
114
|
+
if (job.state !== 'ACTIVE' || job.pause || current?.state !== 'RUNNING' || !dagCoordinator(current) || job.tasks.some(t => t.id === childId))
|
|
115
|
+
return job;
|
|
116
|
+
if (!parents.every(id => job.tasks.some(t => t.id === dagChildId(parent.id, id) && t.state === 'SUCCEEDED')))
|
|
117
|
+
return job;
|
|
118
|
+
const now = new Date().toISOString();
|
|
119
|
+
const dagNode = { parentTaskId: parent.id, nodeId, graphHash, executor: script ? 'script' : 'model' };
|
|
120
|
+
job.tasks.push(createTaskEntity(job, { jobId, id: childId, parentTaskId: parent.id,
|
|
121
|
+
dagNode, title: node.agent, kind: 'work', agentName: node.agent,
|
|
122
|
+
dependencies: parents.map(id => dagChildId(parent.id, id)), capabilities: script ? ['script'] : ['model'],
|
|
123
|
+
adapter: script ? 'script' : 'codex', workerRequirements: script ? undefined : { capabilities: ['model'] },
|
|
124
|
+
input, output: { kind: 'file', path: childOut }, attempt: 0, maxAttempts: 3,
|
|
125
|
+
leaseOwner: null, leaseExpiresAt: null, executionId: null, threadId: null, result: null, error: null,
|
|
126
|
+
timeoutMs: taskOverallTimeoutMs('L'), createdAt: now, updatedAt: now }));
|
|
127
|
+
return job;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const latest = await store.load(jobId);
|
|
132
|
+
const done = graph.nodes.map(n => latest.tasks.find(t => t.id === dagChildId(parent.id, n.id)));
|
|
133
|
+
if (done.length && done.every(t => t?.state === 'SUCCEEDED')) {
|
|
134
|
+
await store.mutateJob(jobId, job => {
|
|
135
|
+
const current = job.tasks.find(t => t.id === parent.id);
|
|
136
|
+
if (!current || current.state !== 'RUNNING' || !dagCoordinator(current))
|
|
137
|
+
return job;
|
|
138
|
+
if (!graph.nodes.every(n => job.tasks.some(t => t.id === dagChildId(parent.id, n.id) && t.state === 'SUCCEEDED')))
|
|
139
|
+
return job;
|
|
140
|
+
const changed = tryTransitionTaskEvent(current, 'task.completed');
|
|
141
|
+
if (!changed.accepted || changed.target !== 'SUCCEEDED')
|
|
142
|
+
throw Error('Task Lifecycle rejected DAG completion');
|
|
143
|
+
current.result = { summary: 'DAG completed', data: { dag: { version: 1, graphHash },
|
|
144
|
+
nodes: Object.fromEntries(graph.nodes.map(n => [n.id, dagChildId(parent.id, n.id)])) } };
|
|
145
|
+
current.updatedAt = new Date().toISOString();
|
|
146
|
+
return job;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
await completeContentJobIfEligible(store, jobId);
|
|
151
|
+
}
|
|
152
|
+
/** Human Request Changes on a scripted Agent goes to its model Worker within
|
|
153
|
+
* the SAME durable Task. Approval goes back to the Script for stage validation.
|
|
154
|
+
* This is routing, not a second revision Task or recovery state machine. */
|
|
155
|
+
export async function selectDAGReviewExecutors(store, jobId) {
|
|
156
|
+
if (!store.mutateJob)
|
|
157
|
+
return;
|
|
158
|
+
await store.mutateJob(jobId, job => {
|
|
159
|
+
if (job.state !== 'ACTIVE' || job.pause)
|
|
160
|
+
return job;
|
|
161
|
+
for (const task of job.tasks) {
|
|
162
|
+
if (task.dagNode?.executor !== 'script' || task.state !== 'QUEUED' || task.executionId !== null)
|
|
163
|
+
continue;
|
|
164
|
+
const status = task.interactiveInvocation?.status;
|
|
165
|
+
const desired = status === 'changes_requested' ? 'codex' : 'script';
|
|
166
|
+
if (task.adapter === desired)
|
|
167
|
+
continue;
|
|
168
|
+
task.adapter = desired;
|
|
169
|
+
task.capabilities = desired === 'codex' ? ['model'] : ['script'];
|
|
170
|
+
task.workerRequirements = desired === 'codex' ? { capabilities: ['model'] } : undefined;
|
|
171
|
+
task.routing = undefined;
|
|
172
|
+
task.workerSelection = undefined;
|
|
173
|
+
if (status === 'changes_requested') {
|
|
174
|
+
const input = JSON.parse(task.input);
|
|
175
|
+
input.reviewRevision = { status, feedback: task.interactiveInvocation?.feedback ?? '',
|
|
176
|
+
comments: task.interactiveInvocation?.comments ?? [],
|
|
177
|
+
instruction: 'Revise the current Stage Artifact from the human feedback. Verify it, then use agents-relay review interactive --path to submit a NEW review for this same Task Execution. Do not publish or emit task.completed until the new review is approved.' };
|
|
178
|
+
task.input = JSON.stringify(input);
|
|
179
|
+
}
|
|
180
|
+
task.updatedAt = new Date().toISOString();
|
|
181
|
+
}
|
|
182
|
+
return job;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/** Run the DAG projection at the ordinary Reconciler scheduling boundary. */
|
|
186
|
+
export async function reconcileDAGSchedule(options) {
|
|
187
|
+
if (!options.job.tasks.some(t => unifiedDAG(options.job, t))) {
|
|
188
|
+
await completeContentJobIfEligible(options.store, options.jobId);
|
|
189
|
+
return options.store.load(options.jobId);
|
|
190
|
+
}
|
|
191
|
+
await reconcileDAGTasks(options);
|
|
192
|
+
await selectDAGReviewExecutors(options.store, options.jobId);
|
|
193
|
+
return options.store.load(options.jobId);
|
|
194
|
+
}
|
|
195
|
+
/** Content completion is independent of the Job activation source. Its legal
|
|
196
|
+
* ACTIVE -> COMPLETED transition belongs to the canonical Job graph. */
|
|
197
|
+
export async function completeContentJobIfEligible(store, jobId) {
|
|
198
|
+
if (!store.mutateJob)
|
|
199
|
+
return;
|
|
200
|
+
const eligible = (job) => job.state === 'ACTIVE' && job.contentOnly === true && job.prNumber === 0 &&
|
|
201
|
+
!job.localMerge && job.autoMerge === false && job.reviewEnabled === false && !job.review && !(job.plans?.length) &&
|
|
202
|
+
job.tasks.length > 0 && job.tasks.every(t => t.state === 'SUCCEEDED');
|
|
203
|
+
const snapshot = await store.load(jobId);
|
|
204
|
+
if (!eligible(snapshot))
|
|
205
|
+
return;
|
|
206
|
+
await store.mutateJob(jobId, job => {
|
|
207
|
+
if (!eligible(job))
|
|
208
|
+
return job;
|
|
209
|
+
const decision = dispatchJobLifecycleSync(job, 'content.completed', { contentCompletionAllowed: true });
|
|
210
|
+
if (!decision.accepted || decision.target !== 'COMPLETED')
|
|
211
|
+
throw Error('Content Job completion rejected by canonical Job lifecycle');
|
|
212
|
+
return job;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
@@ -23,7 +23,7 @@ export const interactiveInvocationGraph = new GraphRuntime(graphSource, {
|
|
|
23
23
|
events: { 'task.interactive_decision': { id: 'task.interactive_decision' }, 'task.interactive_recover': { id: 'task.interactive_recover' } },
|
|
24
24
|
});
|
|
25
25
|
export function hostInteractiveDecisionEvent(context, feedback, receivedAt = new Date().toISOString()) {
|
|
26
|
-
if (!feedback.eventId ||
|
|
26
|
+
if (!feedback.eventId ||
|
|
27
27
|
!['approved', 'changes_requested'].includes(feedback.decision)) {
|
|
28
28
|
throw new Error('Incomplete generic interactive decision');
|
|
29
29
|
}
|
|
@@ -31,7 +31,7 @@ export function hostInteractiveDecisionEvent(context, feedback, receivedAt = new
|
|
|
31
31
|
version: 1, event_id: feedback.eventId, job_id: context.jobId,
|
|
32
32
|
task_id: context.taskId, parent_task_id: null, type: 'task.interactive_decision',
|
|
33
33
|
status: 'running', timestamp: receivedAt, visibility: 'orchestrator', level: 'info',
|
|
34
|
-
message: `Host interactive decision received for
|
|
34
|
+
message: `Host interactive decision received for execution ${context.executionId}`,
|
|
35
35
|
source: { id: `job/${context.jobId}/task/${context.taskId}/execution/${context.executionId}`, component: 'agents-relay' },
|
|
36
36
|
data: { interactive: { ...context, ...feedback, eventId: undefined } },
|
|
37
37
|
};
|
|
@@ -47,22 +47,20 @@ export function normalizeInteractiveDecision(event) {
|
|
|
47
47
|
const jobId = string('jobId');
|
|
48
48
|
const taskId = string('taskId');
|
|
49
49
|
const executionId = string('executionId');
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
// The current Task execution is the sole review identity.
|
|
51
|
+
if (!executionId)
|
|
52
|
+
return null;
|
|
53
|
+
const invocationId = executionId;
|
|
54
|
+
const revision = executionId;
|
|
52
55
|
const decision = value.decision === 'approved' || value.decision === 'changes_requested' ? value.decision : null;
|
|
53
|
-
if (!jobId || !taskId || !executionId || !
|
|
56
|
+
if (!jobId || !taskId || !executionId || !decision)
|
|
57
|
+
return null;
|
|
58
|
+
if (['invocationId', 'revision', 'commitSha', 'revisionId', 'contentHash'].some(key => Object.hasOwn(value, key)))
|
|
54
59
|
return null;
|
|
55
60
|
if (event.source?.id !== `job/${jobId}/task/${taskId}/execution/${executionId}`)
|
|
56
61
|
return null;
|
|
57
62
|
const feedback = typeof value.feedback === 'string' ? value.feedback : null;
|
|
58
|
-
|
|
59
|
-
const contentHash = string('contentHash');
|
|
60
|
-
if (commitSha) {
|
|
61
|
-
if (!/^[a-f0-9]{40}$/.test(commitSha) || revision !== commitSha ||
|
|
62
|
-
value.contentHash !== undefined || value.revisionId !== undefined || feedback === null)
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
else if (contentHash && (contentHash !== revision || feedback === null))
|
|
63
|
+
if (feedback === null)
|
|
66
64
|
return null;
|
|
67
65
|
const comments = value.comments;
|
|
68
66
|
if (comments !== undefined && (!Array.isArray(comments) || comments.length > 100 ||
|
|
@@ -72,8 +70,6 @@ export function normalizeInteractiveDecision(event) {
|
|
|
72
70
|
return {
|
|
73
71
|
jobId, taskId, executionId, invocationId, revision, decision,
|
|
74
72
|
feedback: feedback ?? undefined,
|
|
75
|
-
commitSha: commitSha ?? undefined,
|
|
76
|
-
contentHash: contentHash ?? undefined, revisionId: string('revisionId') ?? undefined,
|
|
77
73
|
previewId: string('previewId') ?? undefined, requestId: string('requestId') ?? undefined,
|
|
78
74
|
idempotencyKey: string('idempotencyKey') ?? undefined,
|
|
79
75
|
comments: comments,
|
|
@@ -93,14 +89,8 @@ export function interactiveDecisionFingerprint(decision) {
|
|
|
93
89
|
comments: decision.comments ?? null,
|
|
94
90
|
})).digest('hex');
|
|
95
91
|
}
|
|
96
|
-
/**
|
|
97
|
-
export function eventOnlyReviewEligible(
|
|
98
|
-
return Boolean(delivery.commitSha && /^[a-f0-9]{40}$/.test(delivery.commitSha) &&
|
|
99
|
-
delivery.revision === delivery.commitSha && !delivery.contentHash && !delivery.revisionId &&
|
|
100
|
-
delivery.feedback !== undefined &&
|
|
101
|
-
[delivery.requestId, delivery.idempotencyKey, delivery.invocationId]
|
|
102
|
-
.every(value => typeof value === 'string' && value.length > 0 && value.length <= 128));
|
|
103
|
-
}
|
|
92
|
+
/** Unbound event-only decisions cannot authorize a Task. */
|
|
93
|
+
export function eventOnlyReviewEligible(_delivery) { return false; }
|
|
104
94
|
function invocationState(invocation) {
|
|
105
95
|
return invocation?.status ?? 'awaiting_decision';
|
|
106
96
|
}
|
|
@@ -159,11 +149,12 @@ export class HostInteractiveInvocationCoordinator {
|
|
|
159
149
|
constructor(options) {
|
|
160
150
|
this.options = options;
|
|
161
151
|
}
|
|
162
|
-
async bind(jobId, task, executionId
|
|
152
|
+
async bind(jobId, task, executionId) {
|
|
163
153
|
if (task.state !== 'RUNNING')
|
|
164
154
|
throw new Error(`Task ${task.id} must be RUNNING to bind an interactive invocation`);
|
|
165
155
|
if (task.executionId !== executionId)
|
|
166
156
|
throw new Error(`Task ${task.id} does not own execution ${executionId}`);
|
|
157
|
+
const invocationId = executionId, revision = executionId;
|
|
167
158
|
const now = (this.options.now ?? (() => new Date()))().toISOString();
|
|
168
159
|
const invocation = { invocationId, revision, executionId, status: 'awaiting_decision', boundAt: now };
|
|
169
160
|
const boundJobId = task.jobId ?? jobId;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/** Relay-owned admission/ready/failure for host-owned interactive review requests. */
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
1
|
import { tryTransitionTaskEvent } from './task-transitions.js';
|
|
4
2
|
import { applyTaskUnblockRetrySnapshot } from './task-actions.js';
|
|
5
3
|
import { appendTaskComment } from './task-comments.js';
|
|
@@ -8,15 +6,15 @@ import { eventFor } from './events.js';
|
|
|
8
6
|
export function interactiveWaitingEvent(jobId, taskId, parentTaskId, executionId) {
|
|
9
7
|
return eventFor(jobId, taskId, parentTaskId, 'task.interactive_waiting', 'waiting', 'Interactive review requested', 'orchestrator', {}, { id: `job/${jobId}/task/${taskId}/execution/${executionId}`, component: 'interactive-review' });
|
|
10
8
|
}
|
|
11
|
-
export function interactiveTemplate(jobId, taskId, executionId
|
|
9
|
+
export function interactiveTemplate(jobId, taskId, executionId) {
|
|
12
10
|
return { type: 'task.interactive_decision', source: `job/${jobId}/task/${taskId}/execution/${executionId}`,
|
|
13
|
-
data: { interactive: { jobId, taskId, executionId
|
|
11
|
+
data: { interactive: { jobId, taskId, executionId } } };
|
|
14
12
|
}
|
|
15
13
|
export async function beginInteractiveReview(store, jobId, taskId, executionId) {
|
|
16
14
|
if (!store.mutateJob)
|
|
17
15
|
throw new Error('Interactive review requires atomic durable Job mutation');
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
// An execution owns at most one review. No separate review identity.
|
|
17
|
+
const invocationId = executionId;
|
|
20
18
|
let reused = false;
|
|
21
19
|
await store.mutateJob(jobId, (job) => {
|
|
22
20
|
const task = job.tasks.find((item) => item.id === taskId);
|
|
@@ -24,7 +22,6 @@ export async function beginInteractiveReview(store, jobId, taskId, executionId)
|
|
|
24
22
|
throw new Error('Interactive review requires current ACTIVE/RUNNING Task execution');
|
|
25
23
|
const existing = task.interactiveInvocation;
|
|
26
24
|
if (existing?.status === 'awaiting_decision' && existing.executionId === executionId) {
|
|
27
|
-
invocationId = existing.invocationId;
|
|
28
25
|
reused = true; // Wrapper rejects a second compile for this pending request.
|
|
29
26
|
}
|
|
30
27
|
else if (!existing || (existing.executionId !== executionId &&
|
|
@@ -33,8 +30,7 @@ export async function beginInteractiveReview(store, jobId, taskId, executionId)
|
|
|
33
30
|
// a prior approval, requested revision, or stale undelivered preview.
|
|
34
31
|
// The current execution guard prevents replacing an in-flight decision;
|
|
35
32
|
// historical decisions remain in the ledger and Task comments.
|
|
36
|
-
|
|
37
|
-
task.interactiveInvocation = { invocationId, executionId, revision: `pending:${invocationId}`,
|
|
33
|
+
task.interactiveInvocation = { invocationId, executionId, revision: executionId,
|
|
38
34
|
status: 'awaiting_decision', boundAt: new Date().toISOString() };
|
|
39
35
|
task.updatedAt = new Date().toISOString();
|
|
40
36
|
}
|
|
@@ -43,16 +39,16 @@ export async function beginInteractiveReview(store, jobId, taskId, executionId)
|
|
|
43
39
|
}
|
|
44
40
|
return job;
|
|
45
41
|
});
|
|
46
|
-
return { jobId, taskId, executionId,
|
|
47
|
-
eventTemplate: interactiveTemplate(jobId, taskId, executionId
|
|
42
|
+
return { jobId, taskId, executionId, reused,
|
|
43
|
+
eventTemplate: interactiveTemplate(jobId, taskId, executionId) };
|
|
48
44
|
}
|
|
49
|
-
export async function abortInteractiveReview(store, jobId, taskId, executionId
|
|
45
|
+
export async function abortInteractiveReview(store, jobId, taskId, executionId) {
|
|
50
46
|
if (!store.mutateJob)
|
|
51
47
|
throw new Error('Interactive review requires durable mutation');
|
|
52
48
|
await store.mutateJob(jobId, job => {
|
|
53
49
|
const task = job.tasks.find(t => t.id === taskId);
|
|
54
50
|
if (task?.state === 'RUNNING' && task.executionId === executionId &&
|
|
55
|
-
task.interactiveInvocation?.
|
|
51
|
+
task.interactiveInvocation?.executionId === executionId &&
|
|
56
52
|
task.interactiveInvocation.status === 'awaiting_decision') {
|
|
57
53
|
task.interactiveInvocation = undefined;
|
|
58
54
|
task.updatedAt = new Date().toISOString();
|
|
@@ -60,33 +56,14 @@ export async function abortInteractiveReview(store, jobId, taskId, executionId,
|
|
|
60
56
|
return job;
|
|
61
57
|
});
|
|
62
58
|
}
|
|
63
|
-
export async function
|
|
64
|
-
if (!/^[a-f0-9]{40}$/.test(revision))
|
|
65
|
-
throw new Error('Immutable review revision must be full Git Commit SHA');
|
|
66
|
-
if (!store.mutateJob)
|
|
67
|
-
throw new Error('Interactive review requires durable mutation');
|
|
68
|
-
await store.mutateJob(jobId, job => {
|
|
69
|
-
const task = job.tasks.find(t => t.id === taskId);
|
|
70
|
-
const inv = task?.interactiveInvocation;
|
|
71
|
-
if (!task || task.state !== 'AWAITING_DECISION' || !inv || inv.executionId !== executionId ||
|
|
72
|
-
inv.invocationId !== invocationId || inv.status !== 'awaiting_decision')
|
|
73
|
-
throw new Error('Interactive review is not awaiting this execution/invocation');
|
|
74
|
-
if (inv.revision !== `pending:${invocationId}` && inv.revision !== revision)
|
|
75
|
-
throw new Error('Conflicting immutable review revision');
|
|
76
|
-
inv.revision = revision;
|
|
77
|
-
task.updatedAt = new Date().toISOString();
|
|
78
|
-
return job;
|
|
79
|
-
});
|
|
80
|
-
return { ready: true, invocationId, revision };
|
|
81
|
-
}
|
|
82
|
-
export async function failInteractiveReview(store, jobId, taskId, executionId, invocationId, reason) {
|
|
59
|
+
export async function failInteractiveReview(store, jobId, taskId, executionId, reason) {
|
|
83
60
|
if (!store.mutateJob)
|
|
84
61
|
throw new Error('Interactive review requires durable mutation');
|
|
85
62
|
let requeued = false;
|
|
86
63
|
await store.mutateJob(jobId, job => {
|
|
87
64
|
const task = job.tasks.find(t => t.id === taskId);
|
|
88
65
|
const inv = task?.interactiveInvocation;
|
|
89
|
-
if (!task || !inv || inv.executionId !== executionId || inv.
|
|
66
|
+
if (!task || !inv || inv.executionId !== executionId || inv.executionId !== executionId ||
|
|
90
67
|
inv.status !== 'awaiting_decision')
|
|
91
68
|
return job;
|
|
92
69
|
if (task.state === 'AWAITING_DECISION') {
|