agents-relay 2.0.70 → 2.0.72

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.
@@ -133,6 +133,8 @@ export class LocalAuthorityDurableStore {
133
133
  const children = mergeInboundJobSnapshot(current, incoming);
134
134
  const preserveTerminal = ['COMPLETED', 'CANCELLED'].includes(current.state)
135
135
  && !['COMPLETED', 'CANCELLED'].includes(incoming.state);
136
+ // A stale snapshot must not undo an already committed Graph activation.
137
+ const preserveActivation = current.state === 'ACTIVE' && incoming.state === 'DRAFT';
136
138
  const review = current.review && incoming.review
137
139
  && current.review.updatedAt > incoming.review.updatedAt
138
140
  ? current.review : incoming.review;
@@ -142,7 +144,7 @@ export class LocalAuthorityDurableStore {
142
144
  const scalarSource = incoming.updatedAt > current.updatedAt ? incoming : current;
143
145
  return {
144
146
  ...current, ...scalarSource,
145
- state: preserveTerminal ? current.state : scalarSource.state,
147
+ state: preserveTerminal || preserveActivation ? current.state : scalarSource.state,
146
148
  updatedAt: current.updatedAt > incoming.updatedAt ? current.updatedAt : incoming.updatedAt,
147
149
  tasks: children.tasks,
148
150
  ...(children.plans ? { plans: children.plans } : {}),
@@ -1,3 +1,4 @@
1
+ import { dispatchJobLifecycleSync } from './workflow/lifecycle.js';
1
2
  import { createPlanRound, pendingPlan } from './planner.js';
2
3
  import { applyJobActivateAction } from './job-actions.js';
3
4
  export async function executeManualPlan(store, jobId, guidance, timeoutMs, launchPlanner) {
@@ -22,8 +23,11 @@ export async function executeManualPlan(store, jobId, guidance, timeoutMs, launc
22
23
  round = createPlanRound(current, { guidance, manual: true, timeoutMs });
23
24
  current.plans = [...(current.plans ?? []), structuredClone(round)].sort((a, b) => a.round - b.round);
24
25
  }
25
- if (current.state === 'DRAFT')
26
- applyJobActivateAction(current);
26
+ if (current.state === 'DRAFT') {
27
+ const activation = dispatchJobLifecycleSync(current, 'activate');
28
+ if (!activation.accepted)
29
+ throw new Error(`Job ${current.id} activation rejected`);
30
+ }
27
31
  return current;
28
32
  });
29
33
  job = structuredClone(committed);
@@ -3,8 +3,18 @@ import { jobHasActiveExecution } from './job-execution-slot.js';
3
3
  import { eventFor } from './events.js';
4
4
  import { materializePlannerChild, parsePlannerResult, validatePlannerHierarchy, validatePlannerLifecycleOwnership, validatePlannerProgress } from './planner.js';
5
5
  import { samePlannerChildDefinition } from './planner-child.js';
6
+ import { dispatchJobLifecycleSync } from './workflow/lifecycle.js';
6
7
  import { withExecutionBoundary } from './reconciler-runtime.js';
7
8
  import { storySizeTimeoutMs } from './types.js';
9
+ /** Activate queued planner work inside the same authoritative SQLite mutation. */
10
+ export function activateCommittedPlannerWork(job) {
11
+ if (job.state !== 'DRAFT' || !job.tasks.some(item => item.state === 'QUEUED'))
12
+ return false;
13
+ const activation = dispatchJobLifecycleSync(job, 'activate');
14
+ if (!activation.accepted)
15
+ throw new Error(`Job ${job.id} activation rejected after planning`);
16
+ return true;
17
+ }
8
18
  export async function drainPlannerUnblocks(ports, jobId, planId) {
9
19
  const job = await ports.store.load(jobId);
10
20
  const plan = (job.plans ?? []).find(item => item.id === planId);
@@ -150,6 +160,9 @@ async function finishPlanner(ports, jobId, planId, executionId, error, raw) {
150
160
  else if (!samePlannerChildDefinition(existing, child))
151
161
  throw new Error(`Planner child ${child.id} already exists with a different definition`);
152
162
  }
163
+ // Planner children are committed atomically with Job activation.
164
+ // Otherwise the DRAFT Job is invisible to the ACTIVE-only dispatcher.
165
+ activateCommittedPlannerWork(current);
153
166
  current.updatedAt = now;
154
167
  committedPlan = true;
155
168
  return current;
@@ -1,11 +1,13 @@
1
1
  #!/usr/bin/env node
2
+ import { dispatchJobLifecycleSync } from './workflow/lifecycle.js';
2
3
  export function createDashboardActions(deps) {
3
- const { cachedOverviews, requireLocalJobBinding, pool, dashboardJobAction, makeReconciler, concurrency, dashboardJobSetState, refreshAll, applyJobActivateAction, applyOrchestratorStartAction, applyOrchestratorCompleteAction, publishOrchestratorTaskStarted, publishOrchestratorTaskCompletion, bus, dashboardTaskAction, dashboardTaskSetState } = deps;
4
- const dashboardOverview = (jobId, target) => cachedOverviews.find((item) => item.job.id === jobId
4
+ const { getOverviews, requireLocalJobBinding, pool, dashboardJobAction, makeReconciler, concurrency, dashboardJobSetState, refreshAll, applyJobActivateAction, applyOrchestratorStartAction, applyOrchestratorCompleteAction, publishOrchestratorTaskStarted, publishOrchestratorTaskCompletion, bus, dashboardTaskAction, dashboardTaskSetState } = deps;
5
+ const currentOverviews = () => getOverviews();
6
+ const dashboardOverview = (jobId, target) => currentOverviews().find((item) => item.job.id === jobId
5
7
  && (!target?.repository || item.job.repository === target.repository)
6
8
  && (!target?.prNumber || (item.job.externalPrNumber ?? item.job.prNumber) === target.prNumber));
7
9
  const workspaceJobAction = (action) => async (jobId) => {
8
- const overview = cachedOverviews.find((item) => item.job.id === jobId);
10
+ const overview = currentOverviews().find((item) => item.job.id === jobId);
9
11
  if (!overview)
10
12
  throw new Error(`Managed job ${jobId} not found`);
11
13
  const store = (await requireLocalJobBinding(jobId)).store;
@@ -25,7 +27,7 @@ export function createDashboardActions(deps) {
25
27
  return result;
26
28
  };
27
29
  const workspaceTaskCreate = async (jobId, task) => {
28
- const overview = cachedOverviews.find((item) => item.job.id === jobId);
30
+ const overview = currentOverviews().find((item) => item.job.id === jobId);
29
31
  if (!overview)
30
32
  throw new Error(`Managed job ${jobId} not found`);
31
33
  if (task.jobId !== jobId)
@@ -41,8 +43,11 @@ export function createDashboardActions(deps) {
41
43
  if (current.tasks.some((item) => item.id === task.id))
42
44
  throw new Error(`Task ${task.id} already exists`);
43
45
  current.tasks.push(structuredClone(task));
44
- if (current.state === 'DRAFT')
45
- applyJobActivateAction(current);
46
+ if (current.state === 'DRAFT') {
47
+ const activation = dispatchJobLifecycleSync(current, 'activate');
48
+ if (!activation.accepted)
49
+ throw new Error(`Job ${current.id} activation rejected`);
50
+ }
46
51
  current.updatedAt = new Date().toISOString();
47
52
  return current;
48
53
  });
@@ -59,7 +64,7 @@ export function createDashboardActions(deps) {
59
64
  return await store.load(jobId);
60
65
  };
61
66
  const workspaceTaskStart = async (jobId, taskId) => {
62
- const overview = cachedOverviews.find((item) => item.job.id === jobId);
67
+ const overview = currentOverviews().find((item) => item.job.id === jobId);
63
68
  if (!overview)
64
69
  throw new Error(`Managed job ${jobId} not found`);
65
70
  const store = (await requireLocalJobBinding(jobId)).store;
@@ -74,7 +79,7 @@ export function createDashboardActions(deps) {
74
79
  return await store.load(jobId);
75
80
  };
76
81
  const workspaceTaskComplete = async (jobId, taskId, summary) => {
77
- const overview = cachedOverviews.find((item) => item.job.id === jobId);
82
+ const overview = currentOverviews().find((item) => item.job.id === jobId);
78
83
  if (!overview)
79
84
  throw new Error(`Managed job ${jobId} not found`);
80
85
  const store = (await requireLocalJobBinding(jobId)).store;
@@ -89,7 +94,7 @@ export function createDashboardActions(deps) {
89
94
  return await store.load(jobId);
90
95
  };
91
96
  const workspaceTaskAction = (action) => async (jobId, taskId) => {
92
- const overview = cachedOverviews.find((item) => item.job.id === jobId);
97
+ const overview = currentOverviews().find((item) => item.job.id === jobId);
93
98
  if (!overview)
94
99
  throw new Error(`Managed job ${jobId} not found`);
95
100
  const store = (await requireLocalJobBinding(jobId)).store;
package/dist/relayd.js CHANGED
@@ -338,7 +338,7 @@ export async function runDaemon(argv) {
338
338
  const initial = cachedOverviews;
339
339
  const fallback = initial[0]?.job;
340
340
  const dashboardStore = fallback ? (await requireLocalJobBinding(fallback.id)).store : new InMemoryStore();
341
- const { dashboardOverview, workspaceJobAction, workspaceJobSetState, workspaceTaskCreate, workspaceTaskStart, workspaceTaskComplete, workspaceTaskAction, workspaceTaskSetState } = createDashboardActions({ cachedOverviews, requireLocalJobBinding, pool, dashboardJobAction, makeReconciler, concurrency, dashboardJobSetState, refreshAll, applyJobActivateAction, applyOrchestratorStartAction, applyOrchestratorCompleteAction, publishOrchestratorTaskStarted, publishOrchestratorTaskCompletion, bus, dashboardTaskAction, dashboardTaskSetState });
341
+ const { dashboardOverview, workspaceJobAction, workspaceJobSetState, workspaceTaskCreate, workspaceTaskStart, workspaceTaskComplete, workspaceTaskAction, workspaceTaskSetState } = createDashboardActions({ getOverviews: () => cachedOverviews, requireLocalJobBinding, pool, dashboardJobAction, makeReconciler, concurrency, dashboardJobSetState, refreshAll, applyJobActivateAction, applyOrchestratorStartAction, applyOrchestratorCompleteAction, publishOrchestratorTaskStarted, publishOrchestratorTaskCompletion, bus, dashboardTaskAction, dashboardTaskSetState });
342
342
  const workspaceControl = createWorkspaceControl({ client, trusted, noGitHub, repositories, refreshAll, requireLocalJobBinding, makeReconciler, concurrency, pool, bus, isEffectivelyBlocked, unblockAutonomousTasks, unblockTask, publishTaskUnblocked, dispatchTaskAction, registerBlockerDependency, discoverAgents, ensureManagedGitHubJob });
343
343
  const secretFile = value(argv, '--github-webhook-secret-file');
344
344
  const secret = noGitHub ? '' : value(argv, '--github-webhook-secret') || process.env.AGENTS_RELAY_GITHUB_WEBHOOK_SECRET || (secretFile ? (await readFile(secretFile, 'utf8')).trim() : '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agents-relay",
3
- "version": "2.0.70",
3
+ "version": "2.0.72",
4
4
  "description": "Durable async agent jobs coordinated through GitHub pull requests",
5
5
  "type": "module",
6
6
  "bin": {