agents-relay 2.0.213 → 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.
@@ -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', timeoutMs: 300_000, signal, spawn: { cwd, stdio: ['ignore', 'pipe', 'pipe'] } });
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 budget metadata is invalid');
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
- if (!currentJob.shortcutExecutionStartedAt)
336
- throw new Error('Direct shortcut Job has no durable first-execution timestamp; refusing to start or reset its budget');
337
- const startedAt = Date.parse(currentJob.shortcutExecutionStartedAt);
338
- const deadlineAt = currentJob.shortcutExecutionDeadlineAt ? Date.parse(currentJob.shortcutExecutionDeadlineAt) : startedAt + 20 * 60 * 1000;
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); clearTimeout(budgetTimer); options.signal?.removeEventListener('abort', abortFromCaller); };
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 timedOut = reason.includes('budget exceeded') || Date.now() >= deadlineAt;
531
- const interrupted = options.signal?.aborted === true && !timedOut;
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: timedOut ? 'TIMED_OUT' : interrupted ? 'INTERRUPTED' : 'FAILED', reason: failure, at: new Date().toISOString(), executionId: currentTask.executionId } } } };
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)
@@ -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 immutable Shortcut deadline origin');
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: Math.max(1, deadline - Date.now()), createdAt: now, updatedAt: now,
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
- const initial = await store.mutateJob(jobId, job => {
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(now).toISOString();
16
- const first = Date.parse(job.shortcutExecutionStartedAt);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agents-relay",
3
- "version": "2.0.213",
3
+ "version": "2.0.214",
4
4
  "description": "Durable async agent jobs coordinated through GitHub pull requests",
5
5
  "repository": {
6
6
  "type": "git",