agents-relay 2.0.212 → 2.0.214
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 +1 -1
- package/dist/agent-prompt-builder.js +1 -0
- package/dist/agent-shortcut.js +10 -28
- package/dist/cli-help.js +14 -5
- package/dist/cli-review.js +33 -3
- package/dist/interactive-request.js +105 -0
- package/dist/interactive-resume.js +6 -0
- package/dist/relayd-control.js +53 -0
- package/dist/shortcut-node-worker.js +5 -9
- package/dist/shortcut-worker-runner.js +3 -12
- package/package.json +1 -1
- package/skills/agents-relay/SKILL.md +3 -1
- package/skills/agents-relay/contracts/event-contract.md +12 -2
package/README.md
CHANGED
|
@@ -152,7 +152,7 @@ Use `job update` for partial mutable metadata changes on an already healthy Job
|
|
|
152
152
|
npx agents-relay job update --repo OWNER/REPO --pr 6 --id job-6 --priority P0 --no-auto-merge
|
|
153
153
|
~~~
|
|
154
154
|
|
|
155
|
-
Request an eligible new review with `npx agents-relay review
|
|
155
|
+
Request an eligible new review with `npx agents-relay review job --repo OWNER/REPO --pr NUMBER --id JOB_ID`.
|
|
156
156
|
Pass optional `--thread-id THREAD_ID` to persist a reviewer-thread override for subsequent
|
|
157
157
|
review routing. Without it, Relay uses the stored reviewer thread, then creator thread,
|
|
158
158
|
or the legacy review path when neither exists. This request wakes graph-owned
|
|
@@ -135,6 +135,7 @@ export async function buildRelayWorkPrompt(input) {
|
|
|
135
135
|
'START: After Bootstrap and the minimal event-contract preflight, publish `task.started` through the canonical events-bus before beginning Task work. Verify the publish response.',
|
|
136
136
|
'PROGRESS: Publish `task.progress` with concrete progress/evidence during long-running work and before the inactivity timeout. Progress is not completion.',
|
|
137
137
|
'TERMINAL: After verifying durable output, publish exactly ONE `task.completed`; if you cannot fulfill the Task, publish `task.failed` with phase, reason and evidence. Do not silently exit or treat a process/browser receipt as completion.',
|
|
138
|
+
'INTERACTIVE PREVIEW: For human video review call Neo MCP `markcut.preview` once with `path` and `relay: {jobId,taskId,executionId}` using the exact execution IDs above. Neo binds the Invocation, suspends the Task, and sends the iPhone notification when the preview is ready. Do not emit `task.interactive_waiting` or a terminal event for this handoff. On resumption, read Task Context for the accepted decision and feedback.',
|
|
138
139
|
'Every event MUST use the exact source above. Do not publish `task.blocked` or `task.unblocked`; those are Relay-owned states. Relay must accept the correlated event.',
|
|
139
140
|
]),
|
|
140
141
|
'', '## Contexts',
|
package/dist/agent-shortcut.js
CHANGED
|
@@ -89,7 +89,7 @@ function shortcutJobCompletionAllowed(job) {
|
|
|
89
89
|
async function runCommand(args, cwd, signal) {
|
|
90
90
|
if (!Array.isArray(args) || args.length === 0 || args.some(item => typeof item !== 'string'))
|
|
91
91
|
throw new Error('runCommand requires a non-empty argument array');
|
|
92
|
-
const child = spawnOwnedProcess(args[0], args.slice(1), { invocation: 'shortcut.run-command',
|
|
92
|
+
const child = spawnOwnedProcess(args[0], args.slice(1), { invocation: 'shortcut.run-command', signal, spawn: { cwd, stdio: ['ignore', 'pipe', 'pipe'] } });
|
|
93
93
|
let stdout = '', stderr = '';
|
|
94
94
|
child.stdout?.setEncoding('utf8');
|
|
95
95
|
child.stderr?.setEncoding('utf8');
|
|
@@ -196,10 +196,8 @@ export async function runAgentShortcut(options) {
|
|
|
196
196
|
throw new Error('Shortcut invocation Task snapshot is stale; reload the durable Task before execution or receipt consumption');
|
|
197
197
|
if (currentJob.executionMode !== 'shortcut' || currentJob.contentOnly !== true)
|
|
198
198
|
throw new Error('Shortcut execution requires durable shortcut and content-only Job policy');
|
|
199
|
-
if (currentJob.shortcutExecutionDeadlineAt && !Number.isFinite(Date.parse(currentJob.shortcutExecutionDeadlineAt)))
|
|
200
|
-
throw new Error('Shortcut execution budget metadata is invalid');
|
|
201
199
|
if (currentJob.shortcutExecutionStartedAt && !Number.isFinite(Date.parse(currentJob.shortcutExecutionStartedAt)))
|
|
202
|
-
throw new Error('Shortcut execution
|
|
200
|
+
throw new Error('Shortcut execution start metadata is invalid');
|
|
203
201
|
const existingShortcut = currentTask.result?.data?.shortcut;
|
|
204
202
|
if (existingShortcut?.workerFallback === true)
|
|
205
203
|
throw new Error('Task is durably routed to the original Worker; shortcut execution is not authorized');
|
|
@@ -262,8 +260,6 @@ export async function runAgentShortcut(options) {
|
|
|
262
260
|
t.leaseExpiresAt = new Date(Date.now() + leaseMs).toISOString();
|
|
263
261
|
if (!fresh.shortcutExecutionStartedAt)
|
|
264
262
|
fresh.shortcutExecutionStartedAt = new Date().toISOString();
|
|
265
|
-
if (!fresh.shortcutExecutionDeadlineAt)
|
|
266
|
-
fresh.shortcutExecutionDeadlineAt = new Date(Date.parse(fresh.shortcutExecutionStartedAt) + 20 * 60 * 1000).toISOString();
|
|
267
263
|
t.executionHistory = [...(t.executionHistory ?? []), { id: t.executionId, attempt: t.attempt, startedAt: new Date().toISOString() }].slice(-8);
|
|
268
264
|
return fresh;
|
|
269
265
|
});
|
|
@@ -332,27 +328,16 @@ export async function runAgentShortcut(options) {
|
|
|
332
328
|
if (Object.keys(state.nodes).length > Object.keys(checkpoint(currentTask).nodes).length)
|
|
333
329
|
await persist(state);
|
|
334
330
|
currentJob = await store.load(job.id);
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
if (!Number.isFinite(startedAt) || !Number.isFinite(deadlineAt) || deadlineAt !== startedAt + 20 * 60 * 1000)
|
|
340
|
-
throw new Error('Shortcut execution budget metadata is invalid');
|
|
341
|
-
if (!currentJob.shortcutExecutionDeadlineAt) {
|
|
342
|
-
await store.mutateJob(job.id, fresh => {
|
|
343
|
-
if (fresh.shortcutExecutionStartedAt !== currentJob.shortcutExecutionStartedAt)
|
|
344
|
-
throw new Error('Shortcut execution budget origin changed');
|
|
345
|
-
fresh.shortcutExecutionDeadlineAt = new Date(deadlineAt).toISOString();
|
|
346
|
-
return fresh;
|
|
347
|
-
});
|
|
348
|
-
}
|
|
331
|
+
// Keep the first execution timestamp for progress/optimization metrics only.
|
|
332
|
+
// Twenty minutes is an orchestrator target, never an execution deadline.
|
|
333
|
+
if (!currentJob.shortcutExecutionStartedAt || !Number.isFinite(Date.parse(currentJob.shortcutExecutionStartedAt)))
|
|
334
|
+
throw new Error('Direct shortcut Job has no durable first-execution timestamp');
|
|
349
335
|
const executionAbort = new AbortController();
|
|
350
336
|
const abortFromCaller = () => executionAbort.abort(options.signal?.reason ?? new Error('Shortcut execution interrupted'));
|
|
351
337
|
if (options.signal?.aborted)
|
|
352
338
|
abortFromCaller();
|
|
353
339
|
else
|
|
354
340
|
options.signal?.addEventListener('abort', abortFromCaller, { once: true });
|
|
355
|
-
const budgetTimer = setTimeout(() => executionAbort.abort(new Error('Shortcut execution budget exceeded (20 minutes)')), Math.max(0, deadlineAt - Date.now()));
|
|
356
341
|
let leaseHeartbeatError;
|
|
357
342
|
let heartbeatInFlight = false;
|
|
358
343
|
const heartbeat = setInterval(() => {
|
|
@@ -369,11 +354,9 @@ export async function runAgentShortcut(options) {
|
|
|
369
354
|
}).catch(error => { leaseHeartbeatError = error; executionAbort.abort(error); }).finally(() => { heartbeatInFlight = false; });
|
|
370
355
|
}, heartbeatMs);
|
|
371
356
|
heartbeat.unref();
|
|
372
|
-
const stopHeartbeat = () => { clearInterval(heartbeat);
|
|
357
|
+
const stopHeartbeat = () => { clearInterval(heartbeat); options.signal?.removeEventListener('abort', abortFromCaller); };
|
|
373
358
|
const emit = (event) => options.onNodeEvent?.({ ...event, timestamp: new Date().toISOString() });
|
|
374
359
|
try {
|
|
375
|
-
if (Date.now() >= deadlineAt)
|
|
376
|
-
return await fail('Shortcut execution budget exceeded (20 minutes)');
|
|
377
360
|
// The existing Graph executor owns node readiness for both code and model
|
|
378
361
|
// nodes. Model nodes execute using Relay's existing durable Worker adapter,
|
|
379
362
|
// never by routing the entire Agent Graph to one Worker.
|
|
@@ -527,9 +510,8 @@ export async function runAgentShortcut(options) {
|
|
|
527
510
|
async function findTask() { const fresh = await store.load(job.id); const found = fresh.tasks.find(item => item.id === task.id); if (!found)
|
|
528
511
|
throw new Error('Task disappeared'); return found; }
|
|
529
512
|
async function fail(reason) {
|
|
530
|
-
const
|
|
531
|
-
const
|
|
532
|
-
const failure = timedOut ? `Shortcut execution timed out after 20 minutes: ${reason}` : interrupted ? `Shortcut execution interrupted: ${reason}` : reason;
|
|
513
|
+
const interrupted = options.signal?.aborted === true;
|
|
514
|
+
const failure = interrupted ? `Shortcut execution interrupted: ${reason}` : reason;
|
|
533
515
|
for (const nodeId of Object.keys(state.inFlight ?? {}))
|
|
534
516
|
emit({ nodeId, type: 'failed', data: { executionId: currentTask.executionId, reason: failure } });
|
|
535
517
|
stopHeartbeat();
|
|
@@ -541,7 +523,7 @@ export async function runAgentShortcut(options) {
|
|
|
541
523
|
t.leaseExpiresAt = null;
|
|
542
524
|
t.executionId = null;
|
|
543
525
|
const prior = t.result ?? { summary: 'Shortcut execution failed', data: {} };
|
|
544
|
-
t.result = { ...prior, summary: failure, data: { ...(prior.data ?? {}), shortcut: { ...state, terminal: { status:
|
|
526
|
+
t.result = { ...prior, summary: failure, data: { ...(prior.data ?? {}), shortcut: { ...state, terminal: { status: interrupted ? 'INTERRUPTED' : 'FAILED', reason: failure, at: new Date().toISOString(), executionId: currentTask.executionId } } } };
|
|
545
527
|
},
|
|
546
528
|
});
|
|
547
529
|
if (!result?.decision.accepted)
|
package/dist/cli-help.js
CHANGED
|
@@ -10,7 +10,8 @@ Usage:
|
|
|
10
10
|
Commands:
|
|
11
11
|
job create|update|show|list|run|shortcut-receipt|merge|unblock|cancel|pause|resume Manage SQLite-authoritative jobs with optional GitHub PRs
|
|
12
12
|
task create|update|show|list|revise|classify|complete|retry|unblock|cancel Manage durable tasks
|
|
13
|
-
review
|
|
13
|
+
review job Request graph-owned review (optional thread override)
|
|
14
|
+
review interactive Bind, wait, ready, fail or abort a host-owned human review
|
|
14
15
|
artifact validate Check a JSON artifact against a project-owned JSON Schema
|
|
15
16
|
plan Invoke the Planner for an existing managed Job
|
|
16
17
|
plan apply Submit a validated Task Tree within one active Plan
|
|
@@ -87,16 +88,24 @@ not GitHub. Old completed Plans are reconstructed from recorded IDs and prior
|
|
|
87
88
|
Task history; their original historical prompt bytes are not persisted. Only
|
|
88
89
|
Codex currently has production Planner dispatch. Web Planner variants show the
|
|
89
90
|
same Builder message targeting the other transports, not a live delivery.`,
|
|
90
|
-
review: `Use review run for
|
|
91
|
+
review: `Use review run for Agent-owned outcome review, review job for final review, or review interactive for host-owned human review.
|
|
91
92
|
|
|
92
93
|
Outcome: agents-relay review run --prompt-file PATH --agents video-director,market --project-path DIR [--output PATH]
|
|
93
94
|
The generic Outcome Reviewer is implicit. Exit 0=PASS, 10=CHANGE_REQUIRED, 20=BLOCKED. The caller owns repair and re-review.
|
|
94
95
|
|
|
95
96
|
Request a new SHA-bound reviewer turn through the existing Relay lifecycle.
|
|
96
97
|
|
|
97
|
-
Usage: npx agents-relay review
|
|
98
|
+
Usage: npx agents-relay review job --repo OWNER/REPO --pr NUMBER --id JOB_ID [--thread-id THREAD_ID]
|
|
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
|
+
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.
|
|
101
|
+
|
|
102
|
+
Managed host interaction (Node Wrapper normally calls these automatically):
|
|
103
|
+
agents-relay review interactive begin --id JOB --task-id TASK --execution-id EXEC
|
|
104
|
+
agents-relay review interactive wait --id JOB --task-id TASK --execution-id EXEC --invocation-id INV
|
|
105
|
+
agents-relay review interactive ready --id JOB --task-id TASK --execution-id EXEC --invocation-id INV --revision SHA256
|
|
106
|
+
agents-relay review interactive fail --id JOB --task-id TASK --execution-id EXEC --invocation-id INV --reason REASON
|
|
107
|
+
agents-relay review interactive abort --id JOB --task-id TASK --execution-id EXEC --invocation-id INV
|
|
108
|
+
The CLI controls the running Relay daemon; this is not a separate Worker step.`,
|
|
100
109
|
artifact: `Check a JSON artifact against a project-owned JSON Schema. Read-only; does not affect Task state or planning.
|
|
101
110
|
|
|
102
111
|
Usage: agents-relay artifact validate --artifact PATH --schema PATH
|
|
@@ -106,7 +115,7 @@ Exit 0 on PASS, 1 on schema mismatch or invalid input. Returns JSON { valid, err
|
|
|
106
115
|
Usage: agents-relay review run (--prompt TEXT | --prompt-file PATH) [--project-path DIR] [--agents role,role] [--output PATH]
|
|
107
116
|
|
|
108
117
|
Return codes: 0 PASS, 10 CHANGE_REQUIRED, 20 BLOCKED; CLI/worker errors fail separately.`,
|
|
109
|
-
'review
|
|
118
|
+
'review job': `Request a review in an existing ChatGPT thread.
|
|
110
119
|
|
|
111
120
|
Required: --repo OWNER/REPO --pr NUMBER --id JOB_ID.
|
|
112
121
|
Optional: --thread-id THREAD_ID persists a reviewer override; omitted uses Job reviewer/creator thread or legacy route. Rejects pending reviews and wakes managed reconciliation.`,
|
package/dist/cli-review.js
CHANGED
|
@@ -7,14 +7,44 @@ export function reviewRequestThreadOverride(args) {
|
|
|
7
7
|
? normalizeThreadId(arg(values, '--thread-id'), '--thread-id')
|
|
8
8
|
: undefined;
|
|
9
9
|
}
|
|
10
|
+
/** Stable local CLI contract for Neo MCP's single-call interactive preview. */
|
|
11
|
+
export async function runInteractiveReviewCommand(argv) {
|
|
12
|
+
const [action, ...args] = argv;
|
|
13
|
+
const commands = ['begin', 'wait', 'ready', 'fail', 'abort'];
|
|
14
|
+
if (!action || !commands.includes(action))
|
|
15
|
+
throw new Error('review interactive requires begin|wait|ready|fail|abort');
|
|
16
|
+
const jobId = arg(args, '--id');
|
|
17
|
+
const taskId = arg(args, '--task-id');
|
|
18
|
+
const executionId = arg(args, '--execution-id');
|
|
19
|
+
const invocationId = arg(args, '--invocation-id');
|
|
20
|
+
if (!jobId || !taskId || !executionId)
|
|
21
|
+
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]{64}$/.test(revision))
|
|
26
|
+
throw new Error('review interactive ready requires --revision SHA256');
|
|
27
|
+
if (action === 'fail' && !arg(args, '--reason').trim())
|
|
28
|
+
throw new Error('review interactive fail requires --reason');
|
|
29
|
+
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
|
+
if (action === 'fail')
|
|
35
|
+
body.reason = arg(args, '--reason');
|
|
36
|
+
console.log(JSON.stringify(await relayControlCommand(args, body)));
|
|
37
|
+
}
|
|
10
38
|
export async function runReviewCommand(action, reviewArgs) {
|
|
11
39
|
if (action === 'run')
|
|
12
40
|
return runOutcomeReview(reviewArgs);
|
|
13
|
-
if (action
|
|
14
|
-
|
|
41
|
+
if (action === 'interactive')
|
|
42
|
+
return runInteractiveReviewCommand(reviewArgs);
|
|
43
|
+
if (action !== 'job')
|
|
44
|
+
throw new Error('review supports: job | run | interactive');
|
|
15
45
|
const jobId = arg(reviewArgs, '--id');
|
|
16
46
|
if (!arg(reviewArgs, '--repo') || !jobId)
|
|
17
|
-
throw new Error('review
|
|
47
|
+
throw new Error('review job requires --repo and --id');
|
|
18
48
|
const threadId = reviewRequestThreadOverride(reviewArgs);
|
|
19
49
|
const job = await relayControlCommand(reviewArgs, { command: 'review.request', jobId, ...(threadId !== undefined ? { threadId } : {}) });
|
|
20
50
|
console.log(JSON.stringify({ jobId: job.id, pr: job.prNumber ?? 0, reviewerThreadId: job.reviewerThreadId ?? null, status: 'requested', note: 'Relay graph will create the review Task once eligible; this is not a delivery receipt.' }, null, 2));
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/** Relay-owned admission/ready/failure for Neo-hosted interactive review requests. */
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { tryTransitionTaskEvent } from './task-transitions.js';
|
|
4
|
+
import { applyTaskUnblockRetrySnapshot } from './task-actions.js';
|
|
5
|
+
import { appendTaskComment } from './task-comments.js';
|
|
6
|
+
export function interactiveTemplate(jobId, taskId, executionId, invocationId) {
|
|
7
|
+
return { type: 'task.interactive_decision', source: `job/${jobId}/task/${taskId}/execution/${executionId}`,
|
|
8
|
+
data: { interactive: { jobId, taskId, executionId, invocationId } } };
|
|
9
|
+
}
|
|
10
|
+
export async function beginInteractiveReview(store, jobId, taskId, executionId) {
|
|
11
|
+
if (!store.mutateJob)
|
|
12
|
+
throw new Error('Interactive review requires atomic durable Job mutation');
|
|
13
|
+
const proposedId = randomUUID();
|
|
14
|
+
let invocationId = '';
|
|
15
|
+
let reused = false;
|
|
16
|
+
await store.mutateJob(jobId, (job) => {
|
|
17
|
+
const task = job.tasks.find((item) => item.id === taskId);
|
|
18
|
+
if (job.state !== 'ACTIVE' || !task || task.state !== 'RUNNING' || task.executionId !== executionId)
|
|
19
|
+
throw new Error('Interactive review requires current ACTIVE/RUNNING Task execution');
|
|
20
|
+
const existing = task.interactiveInvocation;
|
|
21
|
+
if (existing?.status === 'awaiting_decision' && existing.executionId === executionId) {
|
|
22
|
+
invocationId = existing.invocationId;
|
|
23
|
+
reused = true; // Wrapper rejects a second compile for this pending request.
|
|
24
|
+
}
|
|
25
|
+
else if (!existing || (existing.executionId !== executionId &&
|
|
26
|
+
(existing.status === 'changes_requested' || existing.status === 'awaiting_decision'))) {
|
|
27
|
+
// A new authoritative RUNNING execution replaces a stale undelivered
|
|
28
|
+
// invocation left behind by a crashed prior wrapper/worker. The old
|
|
29
|
+
// execution cannot still be current by the Task execution guard above.
|
|
30
|
+
// The prior decision remains in the durable decision ledger and Task
|
|
31
|
+
// comments. A fresh execution may start the next preview revision.
|
|
32
|
+
invocationId = proposedId;
|
|
33
|
+
task.interactiveInvocation = { invocationId, executionId, revision: `pending:${invocationId}`,
|
|
34
|
+
status: 'awaiting_decision', boundAt: new Date().toISOString() };
|
|
35
|
+
task.updatedAt = new Date().toISOString();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error('Conflicting interactive invocation on Task');
|
|
39
|
+
}
|
|
40
|
+
return job;
|
|
41
|
+
});
|
|
42
|
+
return { jobId, taskId, executionId, invocationId, reused,
|
|
43
|
+
eventTemplate: interactiveTemplate(jobId, taskId, executionId, invocationId) };
|
|
44
|
+
}
|
|
45
|
+
export async function abortInteractiveReview(store, jobId, taskId, executionId, invocationId) {
|
|
46
|
+
if (!store.mutateJob)
|
|
47
|
+
throw new Error('Interactive review requires durable mutation');
|
|
48
|
+
await store.mutateJob(jobId, job => {
|
|
49
|
+
const task = job.tasks.find(t => t.id === taskId);
|
|
50
|
+
if (task?.state === 'RUNNING' && task.executionId === executionId &&
|
|
51
|
+
task.interactiveInvocation?.invocationId === invocationId &&
|
|
52
|
+
task.interactiveInvocation.status === 'awaiting_decision') {
|
|
53
|
+
task.interactiveInvocation = undefined;
|
|
54
|
+
task.updatedAt = new Date().toISOString();
|
|
55
|
+
}
|
|
56
|
+
return job;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export async function readyInteractiveReview(store, jobId, taskId, executionId, invocationId, revision) {
|
|
60
|
+
if (!/^[a-f0-9]{64}$/.test(revision))
|
|
61
|
+
throw new Error('Immutable revision must be SHA-256');
|
|
62
|
+
if (!store.mutateJob)
|
|
63
|
+
throw new Error('Interactive review requires durable mutation');
|
|
64
|
+
await store.mutateJob(jobId, job => {
|
|
65
|
+
const task = job.tasks.find(t => t.id === taskId);
|
|
66
|
+
const inv = task?.interactiveInvocation;
|
|
67
|
+
if (!task || task.state !== 'AWAITING_DECISION' || !inv || inv.executionId !== executionId ||
|
|
68
|
+
inv.invocationId !== invocationId || inv.status !== 'awaiting_decision')
|
|
69
|
+
throw new Error('Interactive review is not awaiting this execution/invocation');
|
|
70
|
+
if (inv.revision !== `pending:${invocationId}` && inv.revision !== revision)
|
|
71
|
+
throw new Error('Conflicting immutable review revision');
|
|
72
|
+
inv.revision = revision;
|
|
73
|
+
task.updatedAt = new Date().toISOString();
|
|
74
|
+
return job;
|
|
75
|
+
});
|
|
76
|
+
return { ready: true, invocationId, revision };
|
|
77
|
+
}
|
|
78
|
+
export async function failInteractiveReview(store, jobId, taskId, executionId, invocationId, reason) {
|
|
79
|
+
if (!store.mutateJob)
|
|
80
|
+
throw new Error('Interactive review requires durable mutation');
|
|
81
|
+
let requeued = false;
|
|
82
|
+
await store.mutateJob(jobId, job => {
|
|
83
|
+
const task = job.tasks.find(t => t.id === taskId);
|
|
84
|
+
const inv = task?.interactiveInvocation;
|
|
85
|
+
if (!task || !inv || inv.executionId !== executionId || inv.invocationId !== invocationId ||
|
|
86
|
+
inv.status !== 'awaiting_decision')
|
|
87
|
+
return job;
|
|
88
|
+
if (task.state === 'AWAITING_DECISION') {
|
|
89
|
+
if (!tryTransitionTaskEvent(task, 'interactive.resume').accepted)
|
|
90
|
+
throw new Error('Graph rejected review delivery failure recovery');
|
|
91
|
+
applyTaskUnblockRetrySnapshot(task);
|
|
92
|
+
task.interactiveInvocation = undefined;
|
|
93
|
+
task.error = null;
|
|
94
|
+
task.failureReason = undefined;
|
|
95
|
+
appendTaskComment(job, taskId, `Preview delivery failed; rerun preview request: ${reason.slice(0, 500)}`);
|
|
96
|
+
task.updatedAt = new Date().toISOString();
|
|
97
|
+
requeued = true;
|
|
98
|
+
}
|
|
99
|
+
else if (task.state === 'RUNNING' && task.executionId === executionId) {
|
|
100
|
+
task.interactiveInvocation = undefined;
|
|
101
|
+
}
|
|
102
|
+
return job;
|
|
103
|
+
});
|
|
104
|
+
return { requeued };
|
|
105
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { shouldRecoverInteractiveDecision } from './interactive-invocation.js';
|
|
2
2
|
import { tryTransitionTaskEvent } from './task-transitions.js';
|
|
3
3
|
import { applyTaskUnblockRetrySnapshot } from './task-actions.js';
|
|
4
|
+
import { appendTaskComment } from './task-comments.js';
|
|
4
5
|
export async function resumeInteractiveTask(store, jobId, taskId, invocationId, revision, decision) {
|
|
5
6
|
if (!store.mutateJob)
|
|
6
7
|
throw new Error('Interactive resume requires atomic SQLite Job mutation');
|
|
@@ -17,6 +18,11 @@ export async function resumeInteractiveTask(store, jobId, taskId, invocationId,
|
|
|
17
18
|
throw new Error('Interactive Task release rejected by canonical lifecycle Graph');
|
|
18
19
|
}
|
|
19
20
|
applyTaskUnblockRetrySnapshot(task);
|
|
21
|
+
if (decision === 'changes_requested') {
|
|
22
|
+
// Preserve human feedback across the next Execution/Invocation binding.
|
|
23
|
+
const feedback = invocation.feedback?.trim() || 'Changes requested';
|
|
24
|
+
appendTaskComment(job, taskId, `Interactive review changes requested for revision ${revision}: ${feedback.slice(0, 1000)}`);
|
|
25
|
+
}
|
|
20
26
|
task.error = null;
|
|
21
27
|
task.failureReason = undefined;
|
|
22
28
|
task.updatedAt = new Date().toISOString();
|
package/dist/relayd-control.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { submitTargetedRevisionRequest } from './review-revision-model.js';
|
|
2
|
+
import { beginInteractiveReview, abortInteractiveReview, readyInteractiveReview, failInteractiveReview } from './interactive-request.js';
|
|
2
3
|
import { localSourceHead, localWorkingHead } from './local-git-merge.js';
|
|
3
4
|
import { appendTaskComment } from './task-comments.js';
|
|
4
5
|
import { InMemoryStore } from './store.js';
|
|
@@ -6,6 +7,7 @@ import { openLocalManagedStore } from './local-managed-store.js';
|
|
|
6
7
|
import { relayStoreDirectory } from './relay-store.js';
|
|
7
8
|
import { normalizeThreadId } from './reviewer-thread.js';
|
|
8
9
|
import { publishTaskBlocked } from './cli-support.js';
|
|
10
|
+
import { eventFor } from './events.js';
|
|
9
11
|
import { classifyFailedTask, supersedeCancelledTask } from './task-actions.js';
|
|
10
12
|
import { requestTroubleshooterEscalation, resumeTroubleshooter } from './task-recovery.js';
|
|
11
13
|
import { adoptExistingPullRequestJob } from './cli-job-create.js';
|
|
@@ -93,6 +95,57 @@ export function createWorkspaceControl(deps) {
|
|
|
93
95
|
const binding = await requireLocalJobBinding(jobId);
|
|
94
96
|
const store = binding.store;
|
|
95
97
|
const job = await store.load(jobId);
|
|
98
|
+
if (command.startsWith('review.interactive.')) {
|
|
99
|
+
const taskId = typeof body.taskId === 'string' ? body.taskId : '';
|
|
100
|
+
const executionId = typeof body.executionId === 'string' ? body.executionId : '';
|
|
101
|
+
const invocationId = typeof body.invocationId === 'string' ? body.invocationId : '';
|
|
102
|
+
if (!taskId || !executionId)
|
|
103
|
+
throw new Error('Interactive review requires taskId and executionId');
|
|
104
|
+
if (command === 'review.interactive.begin')
|
|
105
|
+
return await beginInteractiveReview(store, jobId, taskId, executionId);
|
|
106
|
+
if (!invocationId)
|
|
107
|
+
throw new Error('Interactive review requires invocationId');
|
|
108
|
+
if (command === 'review.interactive.abort') {
|
|
109
|
+
await abortInteractiveReview(store, jobId, taskId, executionId, invocationId);
|
|
110
|
+
return { aborted: true };
|
|
111
|
+
}
|
|
112
|
+
if (command === 'review.interactive.wait') {
|
|
113
|
+
const current = (await store.load(jobId)).tasks.find((t) => t.id === taskId);
|
|
114
|
+
if (current?.state === 'AWAITING_DECISION' && current.interactiveInvocation?.invocationId === invocationId)
|
|
115
|
+
return { waiting: true, taskState: 'AWAITING_DECISION' };
|
|
116
|
+
if (current?.state !== 'RUNNING' || current.executionId !== executionId ||
|
|
117
|
+
current.interactiveInvocation?.invocationId !== invocationId)
|
|
118
|
+
throw new Error('Stale interactive waiting request');
|
|
119
|
+
const reconciler = makeReconciler(store, concurrency);
|
|
120
|
+
const event = eventFor(jobId, taskId, current.parentTaskId, 'task.interactive_waiting', 'waiting', 'Neo Preview requested interactive review', 'orchestrator', {}, { id: `job/${jobId}/task/${taskId}/execution/${executionId}`, component: 'neo-preview' });
|
|
121
|
+
try {
|
|
122
|
+
const outcome = await reconciler.applyEvent(event);
|
|
123
|
+
if (!outcome.applied)
|
|
124
|
+
throw new Error('Relay rejected interactive waiting event: ' + outcome.reason);
|
|
125
|
+
// The durable graph transition is authoritative. The ordinary bus
|
|
126
|
+
// records the handoff for event history; duplicate consumption is inert.
|
|
127
|
+
try {
|
|
128
|
+
await bus?.publish(event);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
process.stderr.write(`warning: interactive wait event transport: ${String(error)}\n`);
|
|
132
|
+
}
|
|
133
|
+
return { waiting: true, taskState: 'AWAITING_DECISION' };
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
await reconciler.close();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (command === 'review.interactive.ready')
|
|
140
|
+
return await readyInteractiveReview(store, jobId, taskId, executionId, invocationId, typeof body.revision === 'string' ? body.revision : '');
|
|
141
|
+
if (command === 'review.interactive.fail') {
|
|
142
|
+
const result = await failInteractiveReview(store, jobId, taskId, executionId, invocationId, typeof body.reason === 'string' ? body.reason : 'Preview failed');
|
|
143
|
+
if (result.requeued)
|
|
144
|
+
await pool.reconcileLocalJob(jobId, 'interactive.preview-failed');
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
throw new Error('Unknown interactive review command');
|
|
148
|
+
}
|
|
96
149
|
if (command === 'job.update') {
|
|
97
150
|
const patch = (body.patch && typeof body.patch === 'object' ? body.patch : {});
|
|
98
151
|
if ('executionMode' in patch || 'schedule' in patch)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mkdir, readFile } from 'node:fs/promises';
|
|
2
2
|
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
3
3
|
import { createTaskEntity } from './workflow/entity-creation.js';
|
|
4
|
+
import { taskOverallTimeoutMs } from './types.js';
|
|
4
5
|
/** A model node stays within its original Shortcut Job. Its durable child Task
|
|
5
6
|
* uses the existing Relay Worker adapter, lifecycle Graph and Troubleshooter.
|
|
6
7
|
* The parent Shortcut Graph, not the Worker Reconciler, selects DAG readiness. */
|
|
@@ -25,14 +26,11 @@ export async function runShortcutModelNode(options) {
|
|
|
25
26
|
if (sourceRef && (!declaredRun || dirname(resolve(sourceRef)) !== resolve(runRoot)))
|
|
26
27
|
throw new Error('Shortcut Worker source evidence is not confined to the declared canonical run');
|
|
27
28
|
const outputPath = join(runRoot, '.shortcut-node-results', `${taskId}.json`);
|
|
29
|
+
// No wall-clock cutoff. Child Workers use their standard progress-renewed
|
|
30
|
+
// inactivity watchdog; the foreground Shortcut parent keeps its lease live.
|
|
28
31
|
const started = initial.shortcutExecutionStartedAt && Date.parse(initial.shortcutExecutionStartedAt);
|
|
29
32
|
if (!started || !Number.isFinite(started))
|
|
30
|
-
throw new Error('Model node has no
|
|
31
|
-
const deadline = started + 20 * 60_000;
|
|
32
|
-
if (initial.shortcutExecutionDeadlineAt && Date.parse(initial.shortcutExecutionDeadlineAt) !== deadline)
|
|
33
|
-
throw new Error('Model node deadline differs from the original execution budget');
|
|
34
|
-
if (Date.now() >= deadline)
|
|
35
|
-
throw new Error('Shortcut execution budget exceeded before model node dispatch');
|
|
33
|
+
throw new Error('Model node has no Shortcut start record');
|
|
36
34
|
await mkdir(dirname(outputPath), { recursive: true, mode: 0o700 });
|
|
37
35
|
await store.mutateJob(jobId, current => {
|
|
38
36
|
const active = current.tasks.find(t => t.id === parentTaskId);
|
|
@@ -71,7 +69,7 @@ export async function runShortcutModelNode(options) {
|
|
|
71
69
|
agentName: node.agent, dependencies: [], capabilities: ['model'], workerRequirements: { capabilities: ['model'] },
|
|
72
70
|
adapter: 'codex', input: body, output: { kind: 'file', path: outputPath },
|
|
73
71
|
attempt: 0, maxAttempts: 3, leaseOwner: null, leaseExpiresAt: null, executionId: null, threadId: null,
|
|
74
|
-
result: null, error: null, timeoutMs:
|
|
72
|
+
result: null, error: null, timeoutMs: taskOverallTimeoutMs('L'), createdAt: now, updatedAt: now,
|
|
75
73
|
}));
|
|
76
74
|
}
|
|
77
75
|
return current;
|
|
@@ -79,8 +77,6 @@ export async function runShortcutModelNode(options) {
|
|
|
79
77
|
while (true) {
|
|
80
78
|
if (node.signal.aborted)
|
|
81
79
|
throw node.signal.reason ?? new Error('Shortcut Worker node interrupted');
|
|
82
|
-
if (Date.now() >= deadline)
|
|
83
|
-
throw new Error('Shortcut execution budget exceeded while waiting for model node');
|
|
84
80
|
const current = await store.load(jobId);
|
|
85
81
|
if (current.state !== 'ACTIVE' || current.pause)
|
|
86
82
|
throw new Error('Shortcut Job cancelled/paused while Worker node was pending');
|
|
@@ -5,24 +5,17 @@ export async function driveShortcutWorkers(options) {
|
|
|
5
5
|
const { store, jobId, reconciler, taskId } = options;
|
|
6
6
|
if (!store.mutateJob)
|
|
7
7
|
throw new Error('Foreground Worker fallback requires atomic Relay SQLite');
|
|
8
|
-
|
|
8
|
+
await store.mutateJob(jobId, job => {
|
|
9
9
|
if (job.executionMode !== 'shortcut' || job.contentOnly !== true || job.state !== 'ACTIVE')
|
|
10
10
|
throw new Error('Not an active Shortcut Job');
|
|
11
11
|
if (!job.tasks.find(task => task.id === taskId))
|
|
12
12
|
throw new Error('Shortcut parent Task missing');
|
|
13
|
-
const now = Date.now();
|
|
14
13
|
if (!job.shortcutExecutionStartedAt)
|
|
15
|
-
job.shortcutExecutionStartedAt = new Date(
|
|
16
|
-
|
|
17
|
-
if (!Number.isFinite(first))
|
|
14
|
+
job.shortcutExecutionStartedAt = new Date().toISOString();
|
|
15
|
+
if (!Number.isFinite(Date.parse(job.shortcutExecutionStartedAt)))
|
|
18
16
|
throw new Error('Invalid original Shortcut start time');
|
|
19
|
-
const deadline = new Date(first + 20 * 60_000).toISOString();
|
|
20
|
-
if (job.shortcutExecutionDeadlineAt && job.shortcutExecutionDeadlineAt !== deadline)
|
|
21
|
-
throw new Error('Shortcut deadline changed');
|
|
22
|
-
job.shortcutExecutionDeadlineAt = deadline;
|
|
23
17
|
return job;
|
|
24
18
|
});
|
|
25
|
-
const deadline = Date.parse(initial.shortcutExecutionDeadlineAt);
|
|
26
19
|
const last = new Map();
|
|
27
20
|
const stopWatching = await reconciler.watch(jobId);
|
|
28
21
|
const observe = (job) => {
|
|
@@ -38,8 +31,6 @@ export async function driveShortcutWorkers(options) {
|
|
|
38
31
|
while (true) {
|
|
39
32
|
if (options.signal?.aborted)
|
|
40
33
|
return { status: 'INTERRUPTED', job: await store.load(jobId) };
|
|
41
|
-
if (Date.now() >= deadline)
|
|
42
|
-
return { status: 'TIMED_OUT', job: await store.load(jobId) };
|
|
43
34
|
await reconciler.reconcile(jobId);
|
|
44
35
|
let job = await store.load(jobId);
|
|
45
36
|
observe(job);
|
package/package.json
CHANGED
|
@@ -38,7 +38,9 @@ These are alternative commands for Task and Planner executions. Both fail closed
|
|
|
38
38
|
|
|
39
39
|
## 3. Verify, review, and recover
|
|
40
40
|
|
|
41
|
-
Use the pinned CLI to inspect authoritative status, Task events, comments, and review evidence.
|
|
41
|
+
Use the pinned CLI to inspect authoritative status, Task events, comments, and review evidence. For SHA-bound final Job review, use `agents-relay review job --repo OWNER/REPO --pr NUMBER --id JOB_ID [--thread-id THREAD_ID]`; for independent Agent-owned outcome review, use `agents-relay review run --prompt-file PATH --project-path DIR`.
|
|
42
|
+
|
|
43
|
+
A worker's process exit, browser submission receipt, or emitted event is **not** proof of durable completion. Task agents publish `task.started`, optional `task.progress`, and exactly one correlated terminal `task.completed` or `task.failed` via the canonical `events-bus` capability. Never emit `task.blocked` as a worker terminal outcome. Read `contracts/event-contract.md` for exact identity, event semantics, and reviewer verdict payloads; implementation agents also follow `contracts/worker-self-review.md`.
|
|
42
44
|
|
|
43
45
|
A Reviewer finding defects in a known immutable head emits `task.completed` with `data.verdict: changes-required`, `data.head_sha`, and actionable findings—not `task.failed`. If the Reviewer cannot establish the required head or produce a valid review, it reports an execution failure with `task.failed`, not an invented verdict.
|
|
44
46
|
|
|
@@ -44,8 +44,18 @@ A fix child reports its **own** correlated completion after verified repair. Dow
|
|
|
44
44
|
|
|
45
45
|
## Interactive Task suspension
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
For **Neo-hosted Markcut Preview**, the Worker calls the federated `markcut.preview`
|
|
48
|
+
tool **once** with a video `path` and its authoritative
|
|
49
|
+
`relay: {jobId, taskId, executionId}` context. The Neo MCP wrapper obtains a
|
|
50
|
+
Relay-owned Invocation and Event Template, starts the independent Markcut
|
|
51
|
+
compiler, registers the Task wait, and sends the iPhone notification only after
|
|
52
|
+
the immutable preview is ready. The Worker does **not** publish a separate
|
|
53
|
+
waiting event or manage an Invocation ID. This contract applies only to Neo's
|
|
54
|
+
wrapped tool; standalone Markcut has no Relay or Notification dependency.
|
|
55
|
+
|
|
56
|
+
For other host adapters, after binding an Invocation a RUNNING Worker waiting
|
|
57
|
+
for human input publishes `task.interactive_waiting` with its exact
|
|
58
|
+
Job/Task/Execution source identity.
|
|
49
59
|
Relay checks the pending invocation, persists RUNNING -> AWAITING_DECISION,
|
|
50
60
|
clears the execution lease, and releases the Worker. This is a non-failure
|
|
51
61
|
handoff and is not a Task completion or a Troubleshooter block.
|