agents-relay 2.0.208 → 2.0.210
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/dist/adapters.js +2 -1
- package/dist/agent-shortcut.js +113 -41
- package/dist/browser-worker-runtime.js +7 -2
- package/dist/chatgpt-platform-fallback.js +30 -0
- package/dist/cli-help.js +10 -4
- package/dist/cli-prompt.js +2 -1
- package/dist/cli-revision.js +49 -0
- package/dist/cli-shortcut-local.js +49 -0
- package/dist/cli-shortcut.js +81 -19
- package/dist/cli-worker-task.js +15 -0
- package/dist/cli.js +19 -5
- package/dist/dashboard-html.js +2 -2
- package/dist/dependency-revision-execution.js +152 -0
- package/dist/dependency-validity.js +17 -0
- package/dist/final-review-role.js +17 -0
- package/dist/force-restate-validation.js +6 -3
- package/dist/job-execution-slot.js +4 -1
- package/dist/job-pr-number-migration.js +2 -1
- package/dist/managed-worker-input.js +2 -1
- package/dist/model-routing.js +8 -0
- package/dist/planner-agent-roles.js +18 -0
- package/dist/planner-runtime.js +7 -1
- package/dist/planner-task-ids.js +1 -0
- package/dist/planner.js +11 -6
- package/dist/reconciler-review.js +110 -109
- package/dist/reconciler-runtime.js +56 -58
- package/dist/reconciler.js +33 -13
- package/dist/relay-job-snapshot-reads.js +5 -2
- package/dist/relay-store.js +2 -0
- package/dist/relay-workflow-operations.js +1 -1
- package/dist/relayd-control.js +31 -0
- package/dist/review-evidence.js +44 -0
- package/dist/review-generation-fence.js +2 -1
- package/dist/review-revision-execution.js +86 -0
- package/dist/review-revision-merge.js +15 -0
- package/dist/review-revision-model.js +191 -0
- package/dist/review-revision-policy.js +49 -0
- package/dist/review-revision-settlement.js +54 -0
- package/dist/review-revision-stale.js +57 -0
- package/dist/reviewer-thread.js +41 -1
- package/dist/runtime-status.js +24 -8
- package/dist/shortcut-node-worker.js +128 -0
- package/dist/shortcut-stage-contract.js +50 -0
- package/dist/shortcut-worker-runner.js +73 -0
- package/dist/single-job-task-control.js +1 -1
- package/dist/task-actions.js +4 -13
- package/dist/task-context.js +3 -2
- package/dist/task-inactivity-watchdog.js +7 -0
- package/dist/terminal-event-recovery.js +13 -0
- package/dist/worker-failure-recovery.js +90 -0
- package/dist/workflow/contracts.js +4 -0
- package/dist/workflow/definitions-v2.js +2 -0
- package/dist/workflow/dependency-revision-v2.js +16 -0
- package/dist/workflow/entity-creation.js +2 -0
- package/dist/workflow/review-v2.js +6 -2
- package/dist/workflow/revision-v2.js +32 -0
- package/dist/workflow/runtime.js +30 -0
- package/dist/workflow/task-reconcile.js +3 -0
- package/dist/workflow/task-resolution.js +1 -4
- package/package.json +4 -3
- package/skills/agents-relay/agents/job-acceptance-reviewer.agent.md +41 -0
- package/skills/agents-relay/agents/planner.agent.md +18 -5
- package/skills/agents-relay/agents/reviewer.agent.md +2 -0
- package/skills/agents-relay/contracts/event-contract.md +7 -0
- package/skills/agents-relay/contracts/orchestrator-workflows.md +6 -0
- package/skills/agents-relay/contracts/task-job-contract.md +10 -0
- package/workflow/dependency-revision.mmd +30 -0
- package/workflow/force-restate-validation.mmd +1 -1
- package/workflow/review-lifecycle.mmd +41 -10
- package/workflow/revision-lifecycle.mmd +68 -0
- package/workflow/task-lifecycle.mmd +13 -12
- package/workflow/task-resolution.mmd +1 -6
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dependencyRevisionStillCurrent } from './dependency-revision-execution.js';
|
|
2
|
+
import { isFinalReviewAgent } from './final-review-role.js';
|
|
3
|
+
import { handleWorkerLaunchFailure } from './worker-failure-recovery.js';
|
|
2
4
|
import { normalizeReviewerTerminalEvent } from './review-terminal-normalization.js';
|
|
3
5
|
import { executionEventSource, eventSourceId, executionIdFromSource, claimTerminalExecution, terminalExecutionClaimed } from './execution-event-identity.js';
|
|
4
6
|
export { executionEventSource } from './execution-event-identity.js';
|
|
5
7
|
import { applyJobEffectOutcomes, applyTaskEffectOutcomes } from './workflow-effect-failures.js';
|
|
6
|
-
import {
|
|
8
|
+
import { classifyWorkerRejection, reroutableWorkerRejections } from './worker-rejection.js';
|
|
7
9
|
import { applyTaskRetryAction } from './task-actions.js';
|
|
8
10
|
import { DurableTaskTransitionRuntime } from './workflow/durable-transition.js';
|
|
9
11
|
import { eventFor } from './events.js';
|
|
10
|
-
import { recordTerminalRouteOutcome,
|
|
12
|
+
import { recordTerminalRouteOutcome, recordWatchdogRouteOutcome } from './route-outcome-recording.js';
|
|
11
13
|
import { WorkflowEffectExecutor } from './workflow/effects.js';
|
|
12
14
|
import { ReconcileCoordinator } from './reconcile-coordinator.js';
|
|
13
15
|
import { acceptedReportedTag, eventDataWithoutTag } from './task-tag.js';
|
|
@@ -15,7 +17,6 @@ import { createWorkerStartAck } from './worker-start-ack.js';
|
|
|
15
17
|
import { monitorExecutionProcess } from './execution-process-tracker.js';
|
|
16
18
|
import { HostInteractiveInvocationCoordinator, hostInvocationPorts } from './interactive-invocation.js';
|
|
17
19
|
import { resumeInteractiveTask } from './interactive-resume.js';
|
|
18
|
-
import { persistChatGptPlatformFailure } from './chatgpt-platform-fallback.js';
|
|
19
20
|
import { acceptTaskProgress, armInactivityWatchdog, inactivityDeadline, isCorrelatedWorkerEvent, isRecoverableWatchdogFailure } from './task-inactivity-watchdog.js';
|
|
20
21
|
const activeExecutionOwners = new Map();
|
|
21
22
|
import { withExecutionBoundary } from './execution-boundary.js';
|
|
@@ -89,8 +90,15 @@ export class ReconcilerRuntimeBase {
|
|
|
89
90
|
if (event.type === 'task.progress')
|
|
90
91
|
return this.markWorkerProgress(event);
|
|
91
92
|
if (event.type === 'task.completed') {
|
|
92
|
-
const
|
|
93
|
-
const
|
|
93
|
+
const latest = await this.store.load(event.job_id);
|
|
94
|
+
const task = latest.tasks.find(item => item.id === event.task_id);
|
|
95
|
+
// Source generation still goes through canonical Task terminal
|
|
96
|
+
// correlation; convert stale verification into a safe supersede event.
|
|
97
|
+
if (task?.revision && task.revision.kind !== 'targeted' && !dependencyRevisionStillCurrent(latest, task)) {
|
|
98
|
+
return this.applyTerminalEvent({ ...event, type: 'task.cancelled',
|
|
99
|
+
message: 'Superseded upstream dependency evidence vector changed before terminal validation' });
|
|
100
|
+
}
|
|
101
|
+
const normalized = isFinalReviewAgent(task?.agentName) ? normalizeReviewerTerminalEvent(event) : null;
|
|
94
102
|
if (normalized)
|
|
95
103
|
return normalized.type === 'task.failed' ? this.applyTerminalEvent(normalized) : this.applyReviewEvent(normalized);
|
|
96
104
|
}
|
|
@@ -256,57 +264,26 @@ export class ReconcilerRuntimeBase {
|
|
|
256
264
|
return true;
|
|
257
265
|
}
|
|
258
266
|
async failLaunch(jobId, taskId, executionId, failure, phase = 'launch') {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
:
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
this.launchFailureClaims.add(claim);
|
|
275
|
-
const cleanup = setTimeout(() => this.launchFailureClaims.delete(claim), 60000);
|
|
276
|
-
cleanup.unref();
|
|
277
|
-
const workflowEvent = platformFailure ? 'worker.platform_failure' : phase === 'start-ack' ? 'worker.start_ack_failed' : 'worker.delivery_failed';
|
|
278
|
-
const transition = await this.taskTransitions.apply(jobId, taskId, platformFailure ? 'worker.platform_failure' : workflowEvent, {
|
|
279
|
-
eligible: (_job, task) => task.executionId === executionId,
|
|
280
|
-
facts: () => ({ platformFallbackSafe: platformFailure?.safeToReroute === true && alternative }),
|
|
281
|
-
mutate: (_job, task, decision) => {
|
|
282
|
-
if (platformFailure)
|
|
283
|
-
persistChatGptPlatformFailure(task, currentTask, executionId, platformFailure.classification, platformFailure.evidence, platformFailure.safeToReroute);
|
|
284
|
-
task.error = decision.target === 'QUEUED' ? null : `Worker ${phase} failed: ${message}`;
|
|
285
|
-
task.failureReason = decision.target === 'QUEUED' ? undefined : unknownOutcome
|
|
286
|
-
? 'worker_outcome_unknown' : platformFailure ? 'worker_platform_failure' : failureReason;
|
|
287
|
-
task.leaseOwner = null;
|
|
288
|
-
task.leaseExpiresAt = null;
|
|
289
|
-
task.executionId = null;
|
|
267
|
+
await handleWorkerLaunchFailure({
|
|
268
|
+
store: this.store,
|
|
269
|
+
adapters: this.options.adapters,
|
|
270
|
+
usageSnapshotProvider: this.options.usageSnapshotProvider,
|
|
271
|
+
decisionAuditStore: this.options.decisionAuditStore,
|
|
272
|
+
taskTransitions: this.taskTransitions,
|
|
273
|
+
live: id => this.live.get(id),
|
|
274
|
+
launchFailureClaims: this.launchFailureClaims,
|
|
275
|
+
clearExecution: (id, execution) => this.clearExecution(id, execution),
|
|
276
|
+
clearTerminalWaiter: (id, execution) => {
|
|
277
|
+
const waiter = this.terminalWaiters.get(id);
|
|
278
|
+
if (waiter?.executionId === execution) {
|
|
279
|
+
waiter.resolve();
|
|
280
|
+
this.terminalWaiters.delete(id);
|
|
281
|
+
}
|
|
290
282
|
},
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
await this.emit(eventFor(jobId, taskId, transition.task.parentTaskId, 'task.process.delivery_failed', 'failed', `Worker ${phase} reported after lifecycle moved to ${transition.from}: ${message}`, 'orchestrator', { phase, authoritative: false, executionId, workflowEvent }, { agent: 'relay', component: 'agents-relay' }));
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
await recordLaunchRouteOutcome(this.options.decisionAuditStore, transition.task, message, phase, executionId, unknownOutcome);
|
|
299
|
-
if (executionId) {
|
|
300
|
-
const live = this.live.get(taskId);
|
|
301
|
-
if (live?.executionId === executionId) {
|
|
302
|
-
live.controller.abort();
|
|
303
|
-
live.execution.cancel();
|
|
304
|
-
this.clearExecution(taskId, executionId);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
const event = eventFor(jobId, taskId, transition.task.parentTaskId, transition.task.state === 'QUEUED' ? 'worker.pre_submission_rejected' : 'task.failed', transition.task.state === 'QUEUED' ? 'queued' : 'failed', transition.task.error ?? `Worker ${phase} failed: ${message}`, 'user', { phase, reason: transition.task.failureReason ?? failureReason, workflowEvent, ...(transition.task.platformFailure ? { platformFailure: transition.task.platformFailure } : {}) }, { agent: 'relay', component: 'agents-relay', watchdog: true });
|
|
308
|
-
this.detach(this.emit(event), jobId, taskId, 'worker failure event');
|
|
309
|
-
this.detach(this.eventCoordinator.accept({ jobId, reason: `worker-${phase}-failure` }), jobId, taskId, 'worker failure reconcile wake');
|
|
283
|
+
emit: event => this.emit(event),
|
|
284
|
+
detach: (promise, job, task, context) => this.detach(promise, job, task, context),
|
|
285
|
+
wake: (job, task, reason) => this.detach(this.eventCoordinator.accept({ jobId: job, reason }), job, task, 'worker failure reconcile wake'),
|
|
286
|
+
}, jobId, taskId, executionId, failure, phase);
|
|
310
287
|
}
|
|
311
288
|
async runtimeSettled(jobId, taskId, executionId, result, error) {
|
|
312
289
|
const live = this.live.get(taskId);
|
|
@@ -318,6 +295,12 @@ export class ReconcilerRuntimeBase {
|
|
|
318
295
|
const task = job.tasks.find(item => item.id === taskId);
|
|
319
296
|
if (!task)
|
|
320
297
|
return;
|
|
298
|
+
if (error && ['chatgpt', 'z'].includes(task.adapter)
|
|
299
|
+
&& task.executionId === executionId && task.state === 'QUEUED'
|
|
300
|
+
&& !live?.workerStarted) {
|
|
301
|
+
await this.failLaunch(jobId, taskId, executionId, error, 'process');
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
321
304
|
if (task.adapter !== 'chatgpt' && task.adapter !== 'z') {
|
|
322
305
|
const exited = await this.taskTransitions.updateFact(jobId, taskId, current => current.executionId === executionId && ['RUNNING', 'QUEUED'].includes(current.state), current => { current.processExitedAt = new Date().toISOString(); });
|
|
323
306
|
if (exited)
|
|
@@ -341,6 +324,11 @@ export class ReconcilerRuntimeBase {
|
|
|
341
324
|
return;
|
|
342
325
|
}
|
|
343
326
|
const live = this.live.get(taskId);
|
|
327
|
+
if ((current.adapter === 'chatgpt' || current.adapter === 'z')
|
|
328
|
+
&& current.state === 'QUEUED' && !live?.workerStarted) {
|
|
329
|
+
await this.failLaunch(jobId, taskId, executionId, new Error('Worker failed to publish task.started before the inactivity deadline'), 'start-ack');
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
344
332
|
// Do not cancel before the serialized watchdog transition rechecks the
|
|
345
333
|
// deadline: a concurrent accepted progress event may have extended it.
|
|
346
334
|
const exit = live?.executionId === executionId && live.processSettled ? live.execution.processExit : undefined;
|
|
@@ -400,6 +388,16 @@ export class ReconcilerRuntimeBase {
|
|
|
400
388
|
}
|
|
401
389
|
}
|
|
402
390
|
async applyTerminalEvent(event, trustedInternal = false) {
|
|
391
|
+
if (event.type === 'task.failed') {
|
|
392
|
+
const job = await this.store.load(event.job_id);
|
|
393
|
+
const original = job.tasks.find(task => task.id === event.task_id);
|
|
394
|
+
if (original && ['chatgpt', 'z'].includes(original.adapter)
|
|
395
|
+
&& original.state === 'QUEUED' && original.executionId
|
|
396
|
+
&& isCorrelatedWorkerEvent(original, event)) {
|
|
397
|
+
await this.failLaunch(event.job_id, event.task_id, original.executionId, new Error(event.message || 'Worker reported failure before task.started'), 'terminal');
|
|
398
|
+
return { applied: true, reconcile: false, reason: 'task.failed.no-start-fallback' };
|
|
399
|
+
}
|
|
400
|
+
}
|
|
403
401
|
const liveAtTerminal = this.live.get(event.task_id);
|
|
404
402
|
const terminalEventExecutionId = executionIdFromSource(eventSourceId(event), event.job_id, event.task_id);
|
|
405
403
|
const lifecycleEvent = event.type === 'task.blocked'
|
|
@@ -412,7 +410,7 @@ export class ReconcilerRuntimeBase {
|
|
|
412
410
|
return false;
|
|
413
411
|
if (event.type === 'task.blocked' && lifecycleEvent !== 'interactive.waiting' && (!trustedInternal || task.agentName !== 'troubleshooter'))
|
|
414
412
|
return false;
|
|
415
|
-
if (task.agentName
|
|
413
|
+
if (isFinalReviewAgent(task.agentName) && event.type === 'task.completed')
|
|
416
414
|
return false;
|
|
417
415
|
if (event.type === 'task.completed' && task.interactiveInvocation?.status !== undefined && task.interactiveInvocation.status !== 'approved')
|
|
418
416
|
return false; // current interactive revision requires durable approval
|
|
@@ -488,7 +486,7 @@ export class ReconcilerRuntimeBase {
|
|
|
488
486
|
}
|
|
489
487
|
if (event.type === 'task.completed')
|
|
490
488
|
await this.deliverContinuation(transition.job, transition.task);
|
|
491
|
-
const reviewWorker = transition.task.agentName
|
|
489
|
+
const reviewWorker = isFinalReviewAgent(transition.task.agentName);
|
|
492
490
|
return { applied: true, reconcile: lifecycleEvent !== 'interactive.waiting' && (!reviewWorker || event.type === 'task.failed'), reason: reviewWorker ? `${event.type}.review-worker` : event.type, reconcileMode: reviewWorker || lifecycleEvent === 'interactive.waiting' ? undefined : 'detached' };
|
|
493
491
|
}
|
|
494
492
|
terminalWait(taskId, executionId, launchBarrier) {
|
package/dist/reconciler.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { revisionRequestReady, reconcileReviewRevisions } from './review-revision-execution.js';
|
|
2
|
+
import { reconcileDependencyRevisions } from './dependency-revision-execution.js';
|
|
3
|
+
import { isFinalReviewAgent } from './final-review-role.js';
|
|
1
4
|
import { deliverPendingEscalations } from './escalation-notifier.js';
|
|
2
5
|
import { createFailedPlanRecovery } from './planner-recovery.js';
|
|
3
6
|
import { recoverPlannerChildren } from './planner-child-recovery.js';
|
|
@@ -18,7 +21,7 @@ import { retryPendingPlannerUnblocks } from './planner-runtime.js';
|
|
|
18
21
|
import { dispatchPlannerOrchestration, plannerOrchestrationFacts } from './workflow/planner-orchestration-v2.js';
|
|
19
22
|
import { ReconcilerReviewBase } from './reconciler-review.js';
|
|
20
23
|
import { executeForceRestate } from './force-restate.js';
|
|
21
|
-
import { recordThreadDelivery, resolveImplementationTaskThreadDestination, prepareReviewerThreadDelivery, resolveReviewerThreadDestination } from './reviewer-thread.js';
|
|
24
|
+
import { recordThreadDelivery, resolveImplementationTaskThreadDestination, prepareRevisionThreadDelivery, prepareReviewerThreadDelivery, resolveReviewerThreadDestination } from './reviewer-thread.js';
|
|
22
25
|
import { executeManualPlan } from './manual-plan.js';
|
|
23
26
|
import { executionEventSource, withExecutionBoundary } from './reconciler-runtime.js';
|
|
24
27
|
export { executionEventSource } from './reconciler-runtime.js';
|
|
@@ -27,6 +30,7 @@ import { exhaustedTroubleshooterRecoveries, pendingTroubleshooterTasks, pendingT
|
|
|
27
30
|
import { fallbackFailedTroubleshooters, escalateExhaustedTroubleshooters } from './troubleshooter-fallback.js';
|
|
28
31
|
import { cleanupMergedJobWorktree } from './job-worktree-cleanup.js';
|
|
29
32
|
import { jobHasActiveExecution } from './job-execution-slot.js';
|
|
33
|
+
import { requiresWorkerInactivityWatchdog } from './task-inactivity-watchdog.js';
|
|
30
34
|
import { managedWorkerInput } from './managed-worker-input.js';
|
|
31
35
|
import { launchShortcutEffect, resumeShortcutEffect, resumeShortcutEventWaits } from './reconciler-shortcut.js';
|
|
32
36
|
export { managedWorkerInput } from './managed-worker-input.js';
|
|
@@ -58,6 +62,10 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
58
62
|
}
|
|
59
63
|
async dispatchExecutableTasks(jobId) {
|
|
60
64
|
const scheduled = refreshTaskDependencies(await this.store.load(jobId));
|
|
65
|
+
// Ordinary daemon/queue never owns Shortcut Jobs, including recovery Tasks.
|
|
66
|
+
// Only the explicit foreground runner may use existing Worker Adapters.
|
|
67
|
+
if (scheduled.executionMode === 'shortcut' && !this.options.shortcutRunnerOwner)
|
|
68
|
+
return scheduled;
|
|
61
69
|
if (scheduled.pause)
|
|
62
70
|
return scheduled;
|
|
63
71
|
for (const task of scheduled.tasks.filter(item => item.state === 'SUCCEEDED' && (item.continuation || scheduled.continuation) && !item.continuationDeliveredAt)) {
|
|
@@ -65,7 +73,7 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
65
73
|
}
|
|
66
74
|
const capacity = Math.max(0, (this.options.maxConcurrent ?? 4) - this.live.size - this.plannerLive.size);
|
|
67
75
|
const dispatchable = (jobHasActiveExecution(scheduled) ? [] : scheduled.tasks)
|
|
68
|
-
.filter(task => task.state === 'QUEUED'
|
|
76
|
+
.filter(task => revisionRequestReady(scheduled, task) && task.state === 'QUEUED'
|
|
69
77
|
&& task.executionId === null
|
|
70
78
|
&& task.kind !== 'planner'
|
|
71
79
|
&& task.adapter !== 'orchestrator'
|
|
@@ -74,7 +82,7 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
74
82
|
.slice(0, Math.min(capacity, 1));
|
|
75
83
|
for (const task of dispatchable) {
|
|
76
84
|
const shortcut = task.result?.data?.shortcut;
|
|
77
|
-
await transitionTaskEvent(task, 'dispatch', { dispatchable: true, shortcutExecution: scheduled.executionMode === 'shortcut' && scheduled.contentOnly === true, shortcutFallback: shortcut?.workerFallback === true, shortcutHasGraph: Boolean(task.agentGraph) }, async (actionId) => {
|
|
85
|
+
await transitionTaskEvent(task, 'dispatch', { dispatchable: true, shortcutExecution: scheduled.executionMode === 'shortcut' && scheduled.contentOnly === true && shortcut?.workerFallback !== true && Boolean(task.agentGraph), shortcutFallback: shortcut?.workerFallback === true, shortcutHasGraph: Boolean(task.agentGraph) }, async (actionId) => {
|
|
78
86
|
const outcomes = await this.workflowEffects.execute([actionId], { jobId: scheduled.id, taskId: task.id, transitionKey: `dispatch:${task.attempt}`, data: { attempt: task.attempt } });
|
|
79
87
|
await this.applyTaskEffectOutcomes(scheduled, task, outcomes);
|
|
80
88
|
}, async () => { await this.store.saveTask(task); });
|
|
@@ -87,6 +95,10 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
87
95
|
this.reconciling = true;
|
|
88
96
|
try {
|
|
89
97
|
let job = await this.store.load(jobId);
|
|
98
|
+
// The same durable Job flag covers children, retries, and Troubleshooters.
|
|
99
|
+
// Do not let a background Reconciler mutate or dispatch any of them.
|
|
100
|
+
if (job.executionMode === 'shortcut' && !this.options.shortcutRunnerOwner)
|
|
101
|
+
return job;
|
|
90
102
|
await drainProductionWorkflowOutbox(this.store, this.options);
|
|
91
103
|
await deliverPendingEscalations(this.store, jobId, this.options.escalationNotifier);
|
|
92
104
|
job = await this.store.load(jobId);
|
|
@@ -174,11 +186,14 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
174
186
|
this.cancelExecutionGeneration(job.id, task.id, task.executionId ?? task.executionHistory?.at(-1)?.id);
|
|
175
187
|
this.plannerLive.get(task.id)?.controller.abort();
|
|
176
188
|
}
|
|
189
|
+
await reconcileReviewRevisions(this.store, jobId);
|
|
190
|
+
await reconcileDependencyRevisions(this.store, jobId);
|
|
177
191
|
const beforeSchedule = await this.store.load(jobId);
|
|
178
192
|
const taskStatesBeforeSchedule = new Map(beforeSchedule.tasks.map(task => [task.id, task.state]));
|
|
179
193
|
let scheduled = refreshTaskDependencies(beforeSchedule);
|
|
180
194
|
for (const task of scheduled.tasks)
|
|
181
|
-
if (task.executionId && ['QUEUED', 'RUNNING'].includes(task.state)
|
|
195
|
+
if (task.executionId && ['QUEUED', 'RUNNING'].includes(task.state)
|
|
196
|
+
&& requiresWorkerInactivityWatchdog(scheduled, task))
|
|
182
197
|
this.armInactivityWatchdog(task, task.executionId);
|
|
183
198
|
for (const task of scheduled.tasks) {
|
|
184
199
|
if (taskStatesBeforeSchedule.get(task.id) !== task.state)
|
|
@@ -345,16 +360,17 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
345
360
|
const claimedTask = await withExecutionBoundary(job.id, '__job_execution_slot__', async () => {
|
|
346
361
|
const freshJob = await this.store.load(job.id);
|
|
347
362
|
let freshTask = freshJob.tasks.find(item => item.id === task.id);
|
|
348
|
-
if (!freshTask || freshTask.state !== 'QUEUED' || !
|
|
363
|
+
if (!freshTask || freshTask.state !== 'QUEUED' || !revisionRequestReady(freshJob, freshTask)
|
|
364
|
+
|| !dependencyReady(freshTask, new Map(freshJob.tasks.map(item => [item.id, item]))))
|
|
349
365
|
return;
|
|
350
366
|
if (freshTask.executionId !== null)
|
|
351
367
|
return;
|
|
352
368
|
if (jobHasActiveExecution(freshJob, { taskId: freshTask.id }))
|
|
353
369
|
return;
|
|
354
|
-
if (freshTask.agentName
|
|
370
|
+
if (isFinalReviewAgent(freshTask.agentName) && freshTask.planningDecisionId && freshTask.dependencies.length)
|
|
355
371
|
await bindPlannedReviewHead(this.store, freshTask, await this.currentHeadSha(freshJob));
|
|
356
372
|
const implementationThread = resolveImplementationTaskThreadDestination(freshJob, freshTask);
|
|
357
|
-
if ((!freshTask.routing || ((implementationThread || (freshTask.agentName
|
|
373
|
+
if ((!freshTask.routing || ((implementationThread || (isFinalReviewAgent(freshTask.agentName) && resolveReviewerThreadDestination(freshJob, this.options.reviewer?.threadId))) && freshTask.adapter !== 'chatgpt')) && freshTask.adapter !== 'orchestrator') {
|
|
358
374
|
const routed = await this.routeTaskForExecutionFailClosed(freshJob, freshTask);
|
|
359
375
|
if (!routed)
|
|
360
376
|
return;
|
|
@@ -377,9 +393,11 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
377
393
|
attempt: freshTask.attempt,
|
|
378
394
|
startedAt: new Date(startedAt).toISOString(),
|
|
379
395
|
}].slice(-8);
|
|
380
|
-
if (freshTask.agentName
|
|
396
|
+
if (isFinalReviewAgent(freshTask.agentName))
|
|
381
397
|
freshTask.chatgptThreadDelivery = prepareReviewerThreadDelivery(freshJob, freshTask, this.options.reviewer?.threadId);
|
|
382
|
-
if (
|
|
398
|
+
if (freshTask.revision?.kind === 'targeted')
|
|
399
|
+
freshTask.chatgptThreadDelivery = prepareRevisionThreadDelivery(freshJob, freshTask);
|
|
400
|
+
if (implementationThread && !freshTask.revision && freshTask.adapter === 'chatgpt') {
|
|
383
401
|
freshTask.chatgptThreadDelivery = {
|
|
384
402
|
kind: 'new-turn', threadId: implementationThread, threadSource: 'implementation',
|
|
385
403
|
requestId: `${freshJob.id}:${freshTask.id}:${freshTask.executionId}`,
|
|
@@ -391,7 +409,7 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
391
409
|
let claimed;
|
|
392
410
|
await this.store.mutateJob(job.id, current => {
|
|
393
411
|
const durable = current.tasks.find(item => item.id === freshTask.id);
|
|
394
|
-
if (!durable || durable.state !== 'QUEUED' || durable.executionId !== null
|
|
412
|
+
if (!durable || durable.state !== 'QUEUED' || !revisionRequestReady(current, durable) || durable.executionId !== null
|
|
395
413
|
|| !dependencyReady(durable, new Map(current.tasks.map(item => [item.id, item]))))
|
|
396
414
|
return current;
|
|
397
415
|
if (freshTask.routing)
|
|
@@ -409,9 +427,11 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
409
427
|
id: durable.executionId, attempt: durable.attempt, startedAt: new Date(startedAt).toISOString(),
|
|
410
428
|
}].slice(-8);
|
|
411
429
|
const implementationThread = resolveImplementationTaskThreadDestination(current, durable);
|
|
412
|
-
if (durable.agentName
|
|
430
|
+
if (isFinalReviewAgent(durable.agentName))
|
|
413
431
|
durable.chatgptThreadDelivery = prepareReviewerThreadDelivery(current, { ...durable, routing: freshTask.routing }, this.options.reviewer?.threadId);
|
|
414
|
-
if (
|
|
432
|
+
if (durable.revision?.kind === 'targeted')
|
|
433
|
+
durable.chatgptThreadDelivery = prepareRevisionThreadDelivery(current, durable);
|
|
434
|
+
if (implementationThread && !durable.revision && durable.adapter === 'chatgpt') {
|
|
415
435
|
durable.chatgptThreadDelivery = {
|
|
416
436
|
kind: 'new-turn', threadId: implementationThread, threadSource: 'implementation',
|
|
417
437
|
requestId: `${current.id}:${durable.id}:${durable.executionId}`,
|
|
@@ -442,7 +462,7 @@ export class Reconciler extends ReconcilerReviewBase {
|
|
|
442
462
|
}
|
|
443
463
|
let executionContext;
|
|
444
464
|
try {
|
|
445
|
-
const role = task.agentName
|
|
465
|
+
const role = isFinalReviewAgent(task.agentName) ? 'reviewer' : task.agentName === 'troubleshooter' ? 'troubleshooter' : task.parentTaskId ? 'nested-worker' : 'worker';
|
|
446
466
|
const projectPath = this.options.projectPathForJob ? await this.options.projectPathForJob(job, task) : task.routing?.cwd ?? process.cwd();
|
|
447
467
|
executionContext = await this.resolvedContext(job, task, role, projectPath);
|
|
448
468
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { normalizeLegacyTaskLifecycle } from './types.js';
|
|
2
2
|
import { normalizeLegacyJobPrNumber } from './job-pr-number-migration.js';
|
|
3
3
|
export function currentJobMetadata(job) {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// Retired historical modes must not survive reads or writes. Only the
|
|
5
|
+
// supported opt-in Direct Shortcut mode is part of the active Job contract.
|
|
6
|
+
const { schedule: _schedule, executionMode, ...current } = job;
|
|
7
|
+
return (executionMode === 'shortcut'
|
|
8
|
+
? { ...current, executionMode: 'shortcut' } : current);
|
|
6
9
|
}
|
|
7
10
|
export function normalizeRelayJob(json) {
|
|
8
11
|
const job = currentJobMetadata(normalizeLegacyJobPrNumber(JSON.parse(json)));
|
package/dist/relay-store.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { currentJobMetadata, loadRelayJob, listRelayJobs } from './relay-job-snapshot-reads.js';
|
|
2
2
|
import { SQLiteWorkflowOperations } from './relay-workflow-operations.js';
|
|
3
3
|
import { preserveTaskComments } from './task-comments.js';
|
|
4
|
+
import { preserveReviewRevisionHistory } from './review-revision-merge.js';
|
|
4
5
|
import { DatabaseSync } from 'node:sqlite';
|
|
5
6
|
import { migrateLegacyBlockedTasks } from './legacy-blocked-task-migration.js';
|
|
6
7
|
import { dirname } from 'node:path';
|
|
@@ -31,6 +32,7 @@ function mergeRecords(local, remote) {
|
|
|
31
32
|
export function mergeInboundJobSnapshot(local, remote) {
|
|
32
33
|
const base = remote.updatedAt > local.updatedAt ? structuredClone(remote) : structuredClone(local);
|
|
33
34
|
base.tasks = preserveTaskComments(local.tasks, mergeRecords(local.tasks, remote.tasks));
|
|
35
|
+
preserveReviewRevisionHistory(local, base);
|
|
34
36
|
const localPlans = local.plans ?? [];
|
|
35
37
|
const remotePlans = remote.plans ?? [];
|
|
36
38
|
if (localPlans.length > 0 || remotePlans.length > 0) {
|
|
@@ -86,7 +86,7 @@ export class SQLiteWorkflowOperations {
|
|
|
86
86
|
const job = JSON.parse(row.json);
|
|
87
87
|
const task = job.tasks.find(item => item.id === identity.taskId);
|
|
88
88
|
const shortcut = task?.result?.data?.shortcut;
|
|
89
|
-
const decision = dispatchWorkflowGraphSync(taskLifecycleV2, { initialState: 'QUEUED', input: { transport: 'event', id: 'dispatch', payload: {} }, durableFacts: { dispatchable: true, shortcutExecution: job.executionMode === 'shortcut' && job.contentOnly === true, shortcutFallback: shortcut?.workerFallback === true, shortcutHasGraph: Boolean(task?.agentGraph) } });
|
|
89
|
+
const decision = dispatchWorkflowGraphSync(taskLifecycleV2, { initialState: 'QUEUED', input: { transport: 'event', id: 'dispatch', payload: {} }, durableFacts: { dispatchable: true, shortcutExecution: job.executionMode === 'shortcut' && job.contentOnly === true && shortcut?.workerFallback !== true && Boolean(task?.agentGraph), shortcutFallback: shortcut?.workerFallback === true, shortcutHasGraph: Boolean(task?.agentGraph), shortcutDirectInvocation: job.executionMode === 'shortcut' && job.contentOnly === true } });
|
|
90
90
|
if (!decision.accepted)
|
|
91
91
|
throw new Error('canonical Task Graph did not authorize launch');
|
|
92
92
|
const actionId = decision.actions.find(action => action.id === 'effect.launchTask' || action.id === 'effect.launchShortcut')?.id;
|
package/dist/relayd-control.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { submitTargetedRevisionRequest } from './review-revision-model.js';
|
|
2
|
+
import { localSourceHead, localWorkingHead } from './local-git-merge.js';
|
|
1
3
|
import { appendTaskComment } from './task-comments.js';
|
|
2
4
|
import { InMemoryStore } from './store.js';
|
|
3
5
|
import { openLocalManagedStore } from './local-managed-store.js';
|
|
@@ -7,6 +9,7 @@ import { publishTaskBlocked } from './cli-support.js';
|
|
|
7
9
|
import { classifyFailedTask, supersedeCancelledTask } from './task-actions.js';
|
|
8
10
|
import { requestTroubleshooterEscalation, resumeTroubleshooter } from './task-recovery.js';
|
|
9
11
|
import { adoptExistingPullRequestJob } from './cli-job-create.js';
|
|
12
|
+
import { resolveManagedProjectPath, resolveRepositoryProjectPath } from './workspace.js';
|
|
10
13
|
export function createWorkspaceControl(deps) {
|
|
11
14
|
const { client, trusted, noGitHub, repositories, refreshAll, requireLocalJobBinding, makeReconciler, concurrency, pool, bus, isEffectivelyBlocked, unblockTask, publishTaskUnblocked, dispatchTaskAction, registerBlockerDependency, discoverAgents, ensureManagedGitHubJob } = deps;
|
|
12
15
|
const workspaceControl = async (body) => {
|
|
@@ -137,6 +140,34 @@ export function createWorkspaceControl(deps) {
|
|
|
137
140
|
await pool.reconcileLocalJob(jobId, 'control.job.unblock');
|
|
138
141
|
return await store.load(jobId);
|
|
139
142
|
}
|
|
143
|
+
if (command === 'task.revise') {
|
|
144
|
+
const repository = typeof body.repository === 'string' ? body.repository : '';
|
|
145
|
+
const originalTaskId = typeof body.taskId === 'string' ? body.taskId : '';
|
|
146
|
+
const reviewTaskId = typeof body.reviewTaskId === 'string' ? body.reviewTaskId : '';
|
|
147
|
+
const reviewExecutionId = typeof body.reviewExecutionId === 'string' ? body.reviewExecutionId : '';
|
|
148
|
+
const headSha = typeof body.headSha === 'string' ? body.headSha : '';
|
|
149
|
+
const requestId = typeof body.requestId === 'string' ? body.requestId : '';
|
|
150
|
+
const findings = body.findings;
|
|
151
|
+
if (!repository || repository !== job.repository || !originalTaskId || !reviewTaskId || !reviewExecutionId || !requestId
|
|
152
|
+
|| !/^[a-f0-9]{40,64}$/i.test(headSha) || !Array.isArray(findings) || findings.length < 1 || findings.length > 200)
|
|
153
|
+
throw new Error('task.revise requires matching repository, original/reviewer IDs, active execution ID, valid SHA, stable request ID and nonempty findings');
|
|
154
|
+
// Trust fresh local Git truth, not the caller or PR projection. The
|
|
155
|
+
// atomic reducer independently checks durable head and execution.
|
|
156
|
+
const projectRoot = await resolveManagedProjectPath(job.repository);
|
|
157
|
+
const projectPath = resolveRepositoryProjectPath(projectRoot, job.projectPath);
|
|
158
|
+
const liveHead = job.localMerge?.sourceRef
|
|
159
|
+
? localSourceHead(projectPath, job.localMerge.sourceRef)
|
|
160
|
+
: localWorkingHead(projectPath);
|
|
161
|
+
if (liveHead !== headSha)
|
|
162
|
+
throw new Error('task.revise rejected: local Git source head changed since immutable review');
|
|
163
|
+
const response = await submitTargetedRevisionRequest(store, jobId, {
|
|
164
|
+
requestId, reviewTaskId, reviewExecutionId, headSha, originalTaskId,
|
|
165
|
+
findings: findings,
|
|
166
|
+
});
|
|
167
|
+
// Reviewer is still RUNNING: verdict event will wake the reconciler.
|
|
168
|
+
// The committed receipt must not be obscured by an unrelated wake failure.
|
|
169
|
+
return response;
|
|
170
|
+
}
|
|
140
171
|
if (command === 'task.comment') {
|
|
141
172
|
const taskId = typeof body.taskId === 'string' ? body.taskId : '';
|
|
142
173
|
const message = typeof body.message === 'string' ? body.message : '';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
function reviewRecord(value) {
|
|
2
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
3
|
+
}
|
|
4
|
+
function reviewHeadSha(event) {
|
|
5
|
+
const data = reviewRecord(event.data);
|
|
6
|
+
const outcome = reviewRecord(data.outcome);
|
|
7
|
+
const review = reviewRecord(data.review);
|
|
8
|
+
return [outcome.head_sha, outcome.headSha, review.head_sha, review.headSha, data.head_sha, data.headSha]
|
|
9
|
+
.find((value) => typeof value === 'string' && value.length > 0);
|
|
10
|
+
}
|
|
11
|
+
function reviewIssues(event) {
|
|
12
|
+
const data = reviewRecord(event.data);
|
|
13
|
+
const outcome = reviewRecord(data.outcome);
|
|
14
|
+
const review = reviewRecord(data.review);
|
|
15
|
+
const rawIssues = data.findings !== undefined ? data.findings
|
|
16
|
+
: outcome.blocking_findings !== undefined ? outcome.blocking_findings
|
|
17
|
+
: outcome.blockingFindings !== undefined ? outcome.blockingFindings
|
|
18
|
+
: outcome.findings !== undefined ? outcome.findings
|
|
19
|
+
: review.findings !== undefined ? review.findings
|
|
20
|
+
: review.issues !== undefined ? review.issues
|
|
21
|
+
: data.blocking_findings !== undefined ? data.blocking_findings
|
|
22
|
+
: data.issues;
|
|
23
|
+
if (rawIssues === undefined)
|
|
24
|
+
return [];
|
|
25
|
+
if (!Array.isArray(rawIssues))
|
|
26
|
+
return ['[unparseable blocking finding]'];
|
|
27
|
+
return rawIssues.map(item => {
|
|
28
|
+
if (typeof item === 'string')
|
|
29
|
+
return item.trim() || '[unparseable blocking finding]';
|
|
30
|
+
if (!item || typeof item !== 'object' || Array.isArray(item))
|
|
31
|
+
return '[unparseable blocking finding]';
|
|
32
|
+
const value = item;
|
|
33
|
+
const text = [value.summary, value.message, value.finding, value.title, value.id]
|
|
34
|
+
.find(candidate => typeof candidate === 'string' && candidate.trim().length > 0);
|
|
35
|
+
return typeof text === 'string' ? text.trim() : '[unparseable blocking finding]';
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export function normalizeReviewEvidence(event, task) {
|
|
39
|
+
const explicitHeadSha = reviewHeadSha(event);
|
|
40
|
+
const headSha = explicitHeadSha ?? (event.type === 'review.approved' ? task.reviewHeadSha : undefined);
|
|
41
|
+
if (!headSha)
|
|
42
|
+
return null;
|
|
43
|
+
return { headSha, issues: reviewIssues(event) };
|
|
44
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isFinalReviewAgent } from './final-review-role.js';
|
|
1
2
|
/** Called inside SQLite mutateJob against the latest durable Job snapshot. */
|
|
2
3
|
export function reviewGenerationMatches(current, original, task, headSha) {
|
|
3
4
|
const fresh = current.tasks.find(item => item.id === task.id);
|
|
@@ -10,7 +11,7 @@ export function reviewGenerationMatches(current, original, task, headSha) {
|
|
|
10
11
|
// generation. Reject competing reviewers of that same head deterministically.
|
|
11
12
|
if (current.review?.outcome === 'stale' && original.review?.outcome === 'stale'
|
|
12
13
|
&& current.review.headSha !== headSha && task.planningDecisionId) {
|
|
13
|
-
const currentHeadReviewers = current.tasks.filter(item => item.agentName
|
|
14
|
+
const currentHeadReviewers = current.tasks.filter(item => isFinalReviewAgent(item.agentName)
|
|
14
15
|
&& item.reviewHeadSha === headSha && item.state !== 'CANCELLED');
|
|
15
16
|
return currentHeadReviewers.at(-1)?.id === task.id;
|
|
16
17
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { decideRevisionLifecycle } from './workflow/revision-v2.js';
|
|
2
|
+
/** Only Graph-authorized, fully covered review feedback can dispatch a child. */
|
|
3
|
+
export function revisionRequestReady(job, task) {
|
|
4
|
+
if (task.revision?.kind !== 'targeted')
|
|
5
|
+
return true;
|
|
6
|
+
const review = job.review;
|
|
7
|
+
if (!review || review.outcome !== 'changes_required' || review.revisionDisposition !== 'targeted'
|
|
8
|
+
|| review.taskId !== task.revision.reviewTaskId)
|
|
9
|
+
return false;
|
|
10
|
+
const requests = job.reviewRevisionRequests ?? [];
|
|
11
|
+
return task.revision.requestIds.length > 0 && task.revision.requestIds.every(id => {
|
|
12
|
+
const request = requests.find(item => item.requestId === id);
|
|
13
|
+
return request?.revisionTaskId === task.id && request.status === 'queued'
|
|
14
|
+
&& request.reviewHeadSha === task.revision?.basedOnHeadSha;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function updateStatus(request, next) {
|
|
18
|
+
request.status = next;
|
|
19
|
+
}
|
|
20
|
+
/** Reconstruct Graph transitions from durable correlated Task results on restart.
|
|
21
|
+
* Task completion is independently fenced by the canonical Task Graph and its
|
|
22
|
+
* execution generation. Never infer success from a browser submission receipt.
|
|
23
|
+
*/
|
|
24
|
+
export function reconcileReviewRevisionFacts(job) {
|
|
25
|
+
let changed = false;
|
|
26
|
+
for (const request of job.reviewRevisionRequests ?? []) {
|
|
27
|
+
const task = request.revisionTaskId && job.tasks.find(item => item.id === request.revisionTaskId);
|
|
28
|
+
if (!task || task.revision?.reviewTaskId !== request.reviewTaskId || !task.revision.requestIds.includes(request.requestId))
|
|
29
|
+
continue;
|
|
30
|
+
// Only the Task Graph's already-authorized recovery to QUEUED can reopen
|
|
31
|
+
// a failed/in-flight revision request. Never retry from a stale event.
|
|
32
|
+
if ((request.status === 'failed' || request.status === 'running')
|
|
33
|
+
&& task.state === 'QUEUED' && task.executionId === null
|
|
34
|
+
&& job.review?.outcome === 'changes_required' && job.review.revisionDisposition === 'targeted'
|
|
35
|
+
&& job.review.taskId === request.reviewTaskId) {
|
|
36
|
+
const decision = decideRevisionLifecycle(request.status === 'failed' ? 'FAILED' : 'RUNNING', 'revision.retry', { taskRetryQueued: true });
|
|
37
|
+
if (decision.accepted && decision.target === 'QUEUED'
|
|
38
|
+
&& decision.actions.some(action => action.id === 'revision.queueTask')) {
|
|
39
|
+
updateStatus(request, 'queued');
|
|
40
|
+
changed = true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (request.status === 'requested' && job.review?.outcome === 'changes_required'
|
|
44
|
+
&& job.review.taskId === request.reviewTaskId && job.review.revisionDisposition === 'targeted') {
|
|
45
|
+
const decision = decideRevisionLifecycle('REQUESTED', 'revision.queue', { changesRequiredRecorded: true });
|
|
46
|
+
if (decision.accepted && decision.target === 'QUEUED' && decision.actions.some(action => action.id === 'revision.queueTask')) {
|
|
47
|
+
updateStatus(request, 'queued');
|
|
48
|
+
changed = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (request.status === 'queued' && ['RUNNING', 'SUCCEEDED', 'FAILED'].includes(task.state)) {
|
|
52
|
+
const started = decideRevisionLifecycle('QUEUED', 'revision.started');
|
|
53
|
+
if (started.accepted && started.target === 'RUNNING') {
|
|
54
|
+
if (task.state === 'RUNNING') {
|
|
55
|
+
updateStatus(request, 'running');
|
|
56
|
+
changed = true;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const finished = decideRevisionLifecycle('RUNNING', task.state === 'SUCCEEDED' ? 'revision.verified' : 'revision.failed');
|
|
60
|
+
if (finished.accepted && finished.target === (task.state === 'SUCCEEDED' ? 'VERIFIED' : 'FAILED')) {
|
|
61
|
+
updateStatus(request, task.state === 'SUCCEEDED' ? 'verified' : 'failed');
|
|
62
|
+
changed = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (request.status === 'running' && (task.state === 'SUCCEEDED' || task.state === 'FAILED')) {
|
|
68
|
+
const finished = decideRevisionLifecycle('RUNNING', task.state === 'SUCCEEDED' ? 'revision.verified' : 'revision.failed');
|
|
69
|
+
if (finished.accepted && finished.target === (task.state === 'SUCCEEDED' ? 'VERIFIED' : 'FAILED')) {
|
|
70
|
+
updateStatus(request, task.state === 'SUCCEEDED' ? 'verified' : 'failed');
|
|
71
|
+
changed = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (changed)
|
|
76
|
+
job.updatedAt = new Date().toISOString();
|
|
77
|
+
return changed;
|
|
78
|
+
}
|
|
79
|
+
export async function reconcileReviewRevisions(store, jobId) {
|
|
80
|
+
if (!store.mutateJob)
|
|
81
|
+
return;
|
|
82
|
+
await store.mutateJob(jobId, current => {
|
|
83
|
+
reconcileReviewRevisionFacts(current);
|
|
84
|
+
return current;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Revision and Review-round provenance belongs exclusively to local SQLite.
|
|
2
|
+
* Collaboration projections must NEVER invent or advance these records.
|
|
3
|
+
* The remote snapshot may be newer for other data, but it is not the source
|
|
4
|
+
* of operational review requests, statuses, or execution generations.
|
|
5
|
+
*/
|
|
6
|
+
export function preserveReviewRevisionHistory(local, merged) {
|
|
7
|
+
if (local.reviewRevisionRequests)
|
|
8
|
+
merged.reviewRevisionRequests = structuredClone(local.reviewRevisionRequests);
|
|
9
|
+
else
|
|
10
|
+
delete merged.reviewRevisionRequests;
|
|
11
|
+
if (local.reviewRevisionRounds)
|
|
12
|
+
merged.reviewRevisionRounds = structuredClone(local.reviewRevisionRounds);
|
|
13
|
+
else
|
|
14
|
+
delete merged.reviewRevisionRounds;
|
|
15
|
+
}
|