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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isFinalReviewAgent } from './final-review-role.js';
|
|
2
|
+
/** One durable newly authored Task per effective Agent responsibility in each Plan.
|
|
3
|
+
* Null/blank agentName is the generic implementation role. Existing plans
|
|
4
|
+
* and later genuine revision rounds are not retroactively constrained.
|
|
5
|
+
*/
|
|
6
|
+
export function validatePlannerAgentRoles(specs) {
|
|
7
|
+
const owners = new Map();
|
|
8
|
+
for (const spec of specs) {
|
|
9
|
+
const role = spec.agentName?.trim() || 'implementation';
|
|
10
|
+
if (isFinalReviewAgent(role)) {
|
|
11
|
+
throw new Error(`Task ${spec.id} must not plan job-acceptance-reviewer: Relay creates the immutable-head Final Review gate automatically`);
|
|
12
|
+
}
|
|
13
|
+
const previous = owners.get(role);
|
|
14
|
+
if (previous)
|
|
15
|
+
throw new Error(`Tasks ${previous} and ${spec.id} have duplicate effective Agent role ${role}; consolidate all phases into one Task owned by that Agent in this Plan round. Future rounds may reuse the role for genuine revisions.`);
|
|
16
|
+
owners.set(role, spec.id);
|
|
17
|
+
}
|
|
18
|
+
}
|
package/dist/planner-runtime.js
CHANGED
|
@@ -2,7 +2,7 @@ import { assignPlannerTaskIds } from './planner-task-ids.js';
|
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { jobHasActiveExecution } from './job-execution-slot.js';
|
|
4
4
|
import { eventFor } from './events.js';
|
|
5
|
-
import { materializePlannerChild, parsePlannerResult, validatePlannerHierarchy, validatePlannerLifecycleOwnership, validatePlannerProgress, validatePlannerResolutionMaterialization } from './planner.js';
|
|
5
|
+
import { materializePlannerChild, parsePlannerResult, validatePlannerHierarchy, validatePlannerAgentRoles, validatePlannerLifecycleOwnership, validatePlannerProgress, validatePlannerResolutionMaterialization } from './planner.js';
|
|
6
6
|
import { attachResolutionOwnership } from './workflow/task-resolution.js';
|
|
7
7
|
import { samePlannerChildDefinition } from './planner-child.js';
|
|
8
8
|
import { dispatchJobLifecycleSync } from './workflow/lifecycle.js';
|
|
@@ -184,6 +184,12 @@ export async function finishPlanner(ports, jobId, planId, executionId, error, ra
|
|
|
184
184
|
const historyCleanup = parsed.history_cleanup ?? [];
|
|
185
185
|
const result = assignPlannerTaskIds(parsed, job.repository, job.id, plan.id);
|
|
186
186
|
const executionContext = await ports.plannerContext(job, plan);
|
|
187
|
+
try {
|
|
188
|
+
validatePlannerAgentRoles(result.next_tasks);
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
throw new PlannerApplyValidationError('candidate', [error instanceof Error ? error.message : String(error)]);
|
|
192
|
+
}
|
|
187
193
|
validatePlannerHierarchy(job.tasks, result.next_tasks);
|
|
188
194
|
if (!plan.forceRestate)
|
|
189
195
|
validatePlannerResolutionMaterialization(job.tasks, result.next_tasks);
|
package/dist/planner-task-ids.js
CHANGED
|
@@ -10,6 +10,7 @@ export function assignPlannerTaskIds(result, repository, jobId, planId, director
|
|
|
10
10
|
id: aliases.get(spec.id),
|
|
11
11
|
parentTaskId: spec.parentTaskId ? (aliases.get(spec.parentTaskId) ?? spec.parentTaskId) : spec.parentTaskId,
|
|
12
12
|
dependencies: spec.dependencies?.map(dep => aliases.get(dep) ?? dep),
|
|
13
|
+
...(spec.dependencyValidity ? { dependencyValidity: Object.fromEntries(Object.entries(spec.dependencyValidity).map(([dep, policy]) => [aliases.get(dep) ?? dep, policy])) } : {}),
|
|
13
14
|
})),
|
|
14
15
|
};
|
|
15
16
|
}
|
package/dist/planner.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isFinalReviewAgent } from './final-review-role.js';
|
|
1
2
|
import { buildRelayWorkPrompt } from './agent-prompt-builder.js';
|
|
2
3
|
import { readFile } from 'node:fs/promises';
|
|
3
4
|
import { fileURLToPath } from 'node:url';
|
|
@@ -15,6 +16,7 @@ import { requiredPlannerTaskTitle } from './planner-task-title.js';
|
|
|
15
16
|
import { parsePlannerHistoryCleanup } from './planner-history-cleanup.js';
|
|
16
17
|
import { plannerTaskContext } from './planner-task-context.js';
|
|
17
18
|
import { relayStoreDirectory } from './local-job-path.js';
|
|
19
|
+
import { validateDependencyValidity } from './dependency-validity.js';
|
|
18
20
|
export function semanticTaskTree(tasks) {
|
|
19
21
|
const work = tasks.filter(task => task.kind !== 'planner');
|
|
20
22
|
const ids = new Set(work.map(task => task.id));
|
|
@@ -105,22 +107,22 @@ export function materializePlannerChild(job, planner, spec, executionContext) {
|
|
|
105
107
|
const source = 'round' in planner ? planner.source : planner.planningSource ?? 'model-planner';
|
|
106
108
|
const round = 'round' in planner ? planner.round : planner.planningRound ?? 1;
|
|
107
109
|
const plannerHeadSha = 'round' in planner ? planner.headSha : undefined;
|
|
108
|
-
const reviewHeadSha = spec.agentName
|
|
110
|
+
const reviewHeadSha = isFinalReviewAgent(spec.agentName) && !(spec.dependencies?.length) ? plannerHeadSha ?? job.headSha : undefined;
|
|
109
111
|
const resolution = spec.resolution;
|
|
110
112
|
if (resolution) {
|
|
111
113
|
const target = resolution.targetTaskId ? job.tasks.find(task => task.id === resolution.targetTaskId) : undefined;
|
|
112
114
|
if (!target || !unresolvedTask(target))
|
|
113
115
|
throw new Error(`Planner resolution for ${spec.id} must target one unresolved durable Task`);
|
|
114
116
|
}
|
|
115
|
-
const reviewerThread = spec.agentName
|
|
116
|
-
return createTaskEntity(job, { jobId: job.id, id: spec.id, title: spec.agentName
|
|
117
|
+
const reviewerThread = isFinalReviewAgent(spec.agentName) ? prepareReviewerThreadDelivery(job, { id: spec.id, agentName: spec.agentName, reviewHeadSha }) : undefined, implementationThread = (spec.agentName === 'implementation' || spec.agentName == null) && job.implementationThreadId ? job.implementationThreadId : undefined, threadOwned = Boolean(reviewerThread || implementationThread);
|
|
118
|
+
return createTaskEntity(job, { jobId: job.id, id: spec.id, title: isFinalReviewAgent(spec.agentName) ? 'Review' : spec.title, kind: 'work', priority: spec.priority ?? job.priority, storySize: spec.storySize ?? 'M', projectName: spec.projectName, agentName: spec.agentName, agentGraph: spec.agentGraph, review: spec.review, parentTaskId: isFinalReviewAgent(spec.agentName) ? null : spec.parentTaskId ?? null, dependencies: spec.dependencies ?? [], dependencyValidity: spec.dependencyValidity, capabilities: spec.capabilities ?? [], workerRequirements: threadOwned ? chatgptThreadRequirements(spec.workerRequirements) : spec.workerRequirements, adapter: threadOwned ? 'chatgpt' : (spec.adapter ?? 'codex'), chatgptThreadDelivery: reviewerThread, input: spec.input, output: spec.output, continuation: spec.continuation ?? null, continuationDeliveredAt: null, attempt: 0, maxAttempts: spec.maxAttempts ?? 3, leaseOwner: null, leaseExpiresAt: null, executionId: null, threadId: null, result: null, plannerResult: null, error: null, timeoutMs: spec.timeoutMs ?? taskOverallTimeoutMs(spec.storySize ?? 'M'), createdAt: now, updatedAt: now, planningDecisionId: decisionId, planningSource: source, planningRound: round, reviewHeadSha, resolution: resolution ? { ...resolution, state: 'proposed', owner: 'planner', updatedAt: now } : undefined });
|
|
117
119
|
}
|
|
118
120
|
export function planningSpec(task) {
|
|
119
121
|
if (!task.output)
|
|
120
122
|
throw new Error(`Initial task ${task.id} requires an output contract`);
|
|
121
123
|
if (!['codex', 'chatgpt', 'z'].includes(task.adapter))
|
|
122
124
|
throw new Error(`Initial task ${task.id} requires a supported worker adapter`);
|
|
123
|
-
return { id: task.id, title: task.title, parentTaskId: task.parentTaskId, input: task.input, priority: task.priority, storySize: task.storySize, projectName: task.projectName, agentName: task.agentName, agentGraph: task.agentGraph, review: task.review, dependencies: task.dependencies, capabilities: task.capabilities, workerRequirements: task.workerRequirements, adapter: task.adapter, output: task.output ?? { kind: 'task_pr' }, routing: task.routing, continuation: task.continuation, maxAttempts: task.maxAttempts, timeoutMs: task.timeoutMs, resolution: task.resolution ? { ...task.resolution, state: undefined, owner: undefined, updatedAt: undefined } : undefined };
|
|
125
|
+
return { id: task.id, title: task.title, parentTaskId: task.parentTaskId, input: task.input, priority: task.priority, storySize: task.storySize, projectName: task.projectName, agentName: task.agentName, agentGraph: task.agentGraph, review: task.review, dependencies: task.dependencies, dependencyValidity: task.dependencyValidity, capabilities: task.capabilities, workerRequirements: task.workerRequirements, adapter: task.adapter, output: task.output ?? { kind: 'task_pr' }, routing: task.routing, continuation: task.continuation, maxAttempts: task.maxAttempts, timeoutMs: task.timeoutMs, resolution: task.resolution ? { ...task.resolution, state: undefined, owner: undefined, updatedAt: undefined } : undefined };
|
|
124
126
|
}
|
|
125
127
|
function record(value, field = 'result') {
|
|
126
128
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
@@ -278,6 +280,8 @@ export function parsePlannerResult(value) {
|
|
|
278
280
|
if (typeof task.input !== 'string' || task.input.length === 0)
|
|
279
281
|
throw new Error(`Planner next_tasks[${index}].input is required`);
|
|
280
282
|
const parentTaskId = task.parentTaskId === undefined || task.parentTaskId === null ? task.parentTaskId : optionalString(task.parentTaskId, `next_tasks[${index}].parentTaskId`);
|
|
283
|
+
const dependencies = stringArray(task.dependencies, `next_tasks[${index}].dependencies`);
|
|
284
|
+
const dependencyValidity = validateDependencyValidity(dependencies, task.dependencyValidity, `next_tasks[${index}].dependencyValidity`);
|
|
281
285
|
const adapter = task.adapter;
|
|
282
286
|
if (adapter !== undefined && !['codex', 'chatgpt', 'z'].includes(String(adapter)))
|
|
283
287
|
throw new Error(`Planner next_tasks[${index}].adapter must be codex, chatgpt, or z when provided`);
|
|
@@ -312,7 +316,7 @@ export function parsePlannerResult(value) {
|
|
|
312
316
|
return {
|
|
313
317
|
id, title: requiredPlannerTaskTitle(task.title, index), parentTaskId, input: task.input, priority, storySize,
|
|
314
318
|
projectName: optionalString(task.projectName, 'projectName'), agentName: optionalString(task.agentName, 'agentName'), agentGraph, review,
|
|
315
|
-
dependencies
|
|
319
|
+
dependencies, dependencyValidity, capabilities: stringArray(task.capabilities, 'capabilities'), workerRequirements: requirements,
|
|
316
320
|
adapter: adapter, output: output, routing: route,
|
|
317
321
|
continuation: task.continuation, maxAttempts, timeoutMs, resolution: resolutionProposal(task.resolution, `next_tasks[${index}].resolution`)
|
|
318
322
|
};
|
|
@@ -322,7 +326,7 @@ export function parsePlannerResult(value) {
|
|
|
322
326
|
export function validatePlannerProgress(job, result) {
|
|
323
327
|
if (result.objective_status !== 'in_progress' || result.next_tasks.length > 0 || result.unblocks.length > 0)
|
|
324
328
|
return;
|
|
325
|
-
const previousReviewFinished = job.tasks.some(task => task.agentName
|
|
329
|
+
const previousReviewFinished = job.tasks.some(task => isFinalReviewAgent(task.agentName) && task.state === 'SUCCEEDED');
|
|
326
330
|
if (previousReviewFinished)
|
|
327
331
|
return;
|
|
328
332
|
const liveWork = job.tasks.some(task => task.kind !== 'planner' && !['SUCCEEDED', 'FAILED', 'CANCELLED'].includes(task.state));
|
|
@@ -330,6 +334,7 @@ export function validatePlannerProgress(job, result) {
|
|
|
330
334
|
return;
|
|
331
335
|
throw new Error('Planner returned in_progress with no executable tasks or unblocks while no live work remains; return satisfied when only Relay-owned review/merge/completion effects remain');
|
|
332
336
|
}
|
|
337
|
+
export { validatePlannerAgentRoles } from './planner-agent-roles.js';
|
|
333
338
|
export function validatePlannerLifecycleOwnership(job, specs) {
|
|
334
339
|
if (!job.localMerge?.sourceRef)
|
|
335
340
|
return;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { settleReviewRevisionRound } from './review-revision-settlement.js';
|
|
2
|
+
import { isFinalReviewAgent, FINAL_REVIEW_AGENT, nextFinalReviewTaskId } from './final-review-role.js';
|
|
3
|
+
import { normalizeReviewEvidence } from './review-evidence.js';
|
|
1
4
|
import { browserWorkerPool } from './browser-worker-runtime.js';
|
|
2
5
|
import { storySizeTimeoutMs, taskOverallTimeoutMs } from './types.js';
|
|
3
6
|
import { completionGateSatisfied, refreshTaskDependencies, transitionTaskEvent, tryTransitionTaskEvent } from './task-transitions.js';
|
|
@@ -8,12 +11,15 @@ import { routeExecution } from './execution-routing.js';
|
|
|
8
11
|
import { recordRouteOutcome } from './route-outcome-recording.js';
|
|
9
12
|
import { ReconcilerRuntimeBase } from './reconciler-runtime.js';
|
|
10
13
|
import { dispatchReviewLifecycle, reviewOutcome } from './workflow/review-v2.js';
|
|
14
|
+
import { staleReviewRevisions } from './review-revision-stale.js';
|
|
11
15
|
import { dispatchTaskLifecycleSync } from './workflow/lifecycle.js';
|
|
12
16
|
import { createTaskEntity } from './workflow/entity-creation.js';
|
|
13
17
|
import { localSourceHead, localWorkingHead } from './local-git-merge.js';
|
|
14
18
|
import { chatgptThreadRequirements, resolveReviewerThreadDestination, resolveImplementationTaskThreadDestination, prepareReviewerThreadDelivery } from './reviewer-thread.js';
|
|
15
19
|
import { reviewGenerationMatches } from './review-generation-fence.js';
|
|
16
|
-
import {
|
|
20
|
+
import { targetedRequestsForReview, targetedRequestsCoverReview } from './review-revision-model.js';
|
|
21
|
+
import { reviewFindingFingerprint } from './review-revision-policy.js';
|
|
22
|
+
import { codexNoStartFallbackRoute, quarantineUnavailableCodexFallback } from './chatgpt-platform-fallback.js';
|
|
17
23
|
export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
18
24
|
async currentHeadSha(job) {
|
|
19
25
|
// Tests may replace the external Git effect entirely; in that case its
|
|
@@ -36,7 +42,7 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
reviewFacts(job, headSha) {
|
|
39
|
-
const reviewTasks = job.tasks.filter(task => task.agentName
|
|
45
|
+
const reviewTasks = job.tasks.filter(task => isFinalReviewAgent(task.agentName) && task.reviewHeadSha === headSha);
|
|
40
46
|
const currentReviewTask = job.review?.taskId ? job.tasks.find(task => task.id === job.review?.taskId) : undefined;
|
|
41
47
|
return {
|
|
42
48
|
reviewEnabled: job.reviewEnabled !== false,
|
|
@@ -49,45 +55,6 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
49
55
|
noApprovedCurrentReview: !reviewTasks.some(task => task.state === 'SUCCEEDED' && job.review?.headSha === headSha && job.review.outcome === 'approved'),
|
|
50
56
|
};
|
|
51
57
|
}
|
|
52
|
-
static reviewRecord(value) {
|
|
53
|
-
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
54
|
-
}
|
|
55
|
-
static reviewHeadSha(event) {
|
|
56
|
-
const data = ReconcilerReviewBase.reviewRecord(event.data);
|
|
57
|
-
const outcome = ReconcilerReviewBase.reviewRecord(data.outcome);
|
|
58
|
-
const review = ReconcilerReviewBase.reviewRecord(data.review);
|
|
59
|
-
return [outcome.head_sha, outcome.headSha, review.head_sha, review.headSha, data.head_sha, data.headSha]
|
|
60
|
-
.find((value) => typeof value === 'string' && value.length > 0);
|
|
61
|
-
}
|
|
62
|
-
static reviewIssues(event) {
|
|
63
|
-
const data = ReconcilerReviewBase.reviewRecord(event.data);
|
|
64
|
-
const outcome = ReconcilerReviewBase.reviewRecord(data.outcome);
|
|
65
|
-
const review = ReconcilerReviewBase.reviewRecord(data.review);
|
|
66
|
-
const rawIssues = outcome.blocking_findings !== undefined ? outcome.blocking_findings
|
|
67
|
-
: outcome.blockingFindings !== undefined ? outcome.blockingFindings
|
|
68
|
-
: review.issues !== undefined ? review.issues
|
|
69
|
-
: data.issues;
|
|
70
|
-
if (!Array.isArray(rawIssues))
|
|
71
|
-
return [];
|
|
72
|
-
return rawIssues.map(item => {
|
|
73
|
-
if (typeof item === 'string')
|
|
74
|
-
return item.trim();
|
|
75
|
-
if (!item || typeof item !== 'object' || Array.isArray(item))
|
|
76
|
-
return '';
|
|
77
|
-
const value = item;
|
|
78
|
-
return (typeof value.summary === 'string' ? value.summary
|
|
79
|
-
: typeof value.message === 'string' ? value.message
|
|
80
|
-
: typeof value.finding === 'string' ? value.finding
|
|
81
|
-
: typeof value.title === 'string' ? value.title : '').trim();
|
|
82
|
-
}).filter(Boolean);
|
|
83
|
-
}
|
|
84
|
-
static normalizeReviewEvidence(event, task) {
|
|
85
|
-
const explicitHeadSha = ReconcilerReviewBase.reviewHeadSha(event);
|
|
86
|
-
const headSha = explicitHeadSha ?? (event.type === 'review.approved' ? task.reviewHeadSha : undefined);
|
|
87
|
-
if (!headSha)
|
|
88
|
-
return null;
|
|
89
|
-
return { headSha, issues: ReconcilerReviewBase.reviewIssues(event) };
|
|
90
|
-
}
|
|
91
58
|
async cancelStaleReviewTask(job) {
|
|
92
59
|
const staleTask = job.review?.taskId ? job.tasks.find(task => task.id === job.review?.taskId) : undefined;
|
|
93
60
|
if (!staleTask || !['DRAFT', 'QUEUED', 'RUNNING'].includes(staleTask.state))
|
|
@@ -100,11 +67,14 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
100
67
|
await this.store.saveTask(staleTask);
|
|
101
68
|
}
|
|
102
69
|
async invalidateStaleReview(job, headSha) {
|
|
103
|
-
|
|
70
|
+
const staleReview = job.review;
|
|
71
|
+
if (!headSha || !staleReview || staleReview.headSha === headSha)
|
|
104
72
|
return;
|
|
105
|
-
const decision = await dispatchReviewLifecycle(
|
|
73
|
+
const decision = await dispatchReviewLifecycle(staleReview.outcome, 'head.changed', {}, async (actionId) => {
|
|
106
74
|
if (actionId === 'review.cancelStale') {
|
|
107
75
|
await this.cancelStaleReviewTask(job);
|
|
76
|
+
if (staleReview.taskId)
|
|
77
|
+
await staleReviewRevisions(this.store, job, staleReview.taskId, staleReview.headSha, (taskId, executionId) => this.cancelExecutionGeneration(job.id, taskId, executionId));
|
|
108
78
|
return {};
|
|
109
79
|
}
|
|
110
80
|
throw new Error('Unsupported stale review action ' + actionId);
|
|
@@ -114,33 +84,32 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
114
84
|
const outcome = reviewOutcome(decision.target);
|
|
115
85
|
if (!outcome)
|
|
116
86
|
throw new Error('Review graph produced invalid stale target ' + decision.target);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
87
|
+
const updatedAt = new Date().toISOString();
|
|
88
|
+
if (this.store.mutateJob) {
|
|
89
|
+
const persisted = await this.store.mutateJob(job.id, current => {
|
|
90
|
+
const currentReview = current.review;
|
|
91
|
+
if (!currentReview || currentReview.taskId !== staleReview.taskId || currentReview.headSha !== staleReview.headSha)
|
|
92
|
+
return current;
|
|
93
|
+
current.review = { ...currentReview, outcome, updatedAt };
|
|
94
|
+
current.updatedAt = updatedAt;
|
|
95
|
+
return current;
|
|
96
|
+
});
|
|
97
|
+
Object.assign(job, persisted);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
job.review = { ...staleReview, outcome, updatedAt };
|
|
101
|
+
await this.store.saveJob(job);
|
|
129
102
|
}
|
|
130
|
-
throw new Error('Too many final review rounds for ' + headSha);
|
|
131
|
-
}
|
|
132
|
-
externalReviewPrNumber(job) {
|
|
133
|
-
return job.prNumber;
|
|
134
103
|
}
|
|
135
104
|
async createFinalReviewTask(job, headSha) {
|
|
136
|
-
const id =
|
|
137
|
-
const reviewPrNumber =
|
|
105
|
+
const id = nextFinalReviewTaskId(job, headSha);
|
|
106
|
+
const reviewPrNumber = job.prNumber;
|
|
138
107
|
const now = new Date().toISOString();
|
|
139
108
|
const reviewGateTasks = implementationTasks(job);
|
|
140
109
|
const reviewThread = resolveReviewerThreadDestination(job, this.options.reviewer?.threadId);
|
|
141
110
|
const reviewerRouting = await this.selectReviewer(reviewGateTasks, reviewThread ? chatgptThreadRequirements(this.options.reviewer?.requirements) : undefined);
|
|
142
111
|
const chatgptThreadDelivery = prepareReviewerThreadDelivery(job, {
|
|
143
|
-
id, agentName:
|
|
112
|
+
id, agentName: FINAL_REVIEW_AGENT, reviewHeadSha: headSha, routing: reviewerRouting.candidate.routing,
|
|
144
113
|
}, this.options.reviewer?.threadId);
|
|
145
114
|
const input = [
|
|
146
115
|
`Job ID: ${job.id}`,
|
|
@@ -154,7 +123,7 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
154
123
|
'Do not treat historical failed attempts as current artifact defects; distinguish preserved baseline files from implementation.',
|
|
155
124
|
].join('\n\n');
|
|
156
125
|
const task = createTaskEntity(job, {
|
|
157
|
-
jobId: job.id, id, title: 'Review', kind: 'work', priority: job.priority, storySize: 'M', projectName: job.title, agentName:
|
|
126
|
+
jobId: job.id, id, title: 'Review', kind: 'work', priority: job.priority, storySize: 'M', projectName: job.title, agentName: FINAL_REVIEW_AGENT,
|
|
158
127
|
parentTaskId: null, dependencies: reviewGateTasks.map(item => item.id), capabilities: ['review'],
|
|
159
128
|
workerSelection: reviewerRouting.selection, adapter: reviewerRouting.candidate.adapter,
|
|
160
129
|
input,
|
|
@@ -165,7 +134,7 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
165
134
|
error: null, timeoutMs: this.options.reviewer?.timeoutMs ?? storySizeTimeoutMs('M'), createdAt: now, updatedAt: now
|
|
166
135
|
});
|
|
167
136
|
await this.store.appendTask(task);
|
|
168
|
-
await this.emit(eventFor(job.id, id, task.parentTaskId, 'review.created', 'queued', 'Final review task ' + id + ' created for ' + headSha + ' using ' + reviewerRouting.reason, 'orchestrator', { headSha, agentName:
|
|
137
|
+
await this.emit(eventFor(job.id, id, task.parentTaskId, 'review.created', 'queued', 'Final review task ' + id + ' created for ' + headSha + ' using ' + reviewerRouting.reason, 'orchestrator', { headSha, agentName: FINAL_REVIEW_AGENT, reviewerRouting: { workerId: reviewerRouting.selection.workerId, reason: reviewerRouting.reason, selectedBy: reviewerRouting.selection.selectedBy } }));
|
|
169
138
|
return id;
|
|
170
139
|
}
|
|
171
140
|
async projectedReviewHeadReady(job, headSha) {
|
|
@@ -185,11 +154,12 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
185
154
|
async ensureFinalReview(job, headSha) {
|
|
186
155
|
if (headSha && !(await this.projectedReviewHeadReady(job, headSha)))
|
|
187
156
|
return;
|
|
157
|
+
job = await settleReviewRevisionRound(this.store, job);
|
|
188
158
|
// Restore the review gate only after an authoritative unblock of the original reviewer.
|
|
189
159
|
const priorReviewTask = job.tasks.find(task => task.id === job.review?.taskId);
|
|
190
160
|
if (job.review?.outcome === 'blocked' && job.review.headSha === headSha
|
|
191
|
-
&& priorReviewTask?.agentName
|
|
192
|
-
&& ['QUEUED', 'RUNNING', 'FAILED'].includes(priorReviewTask
|
|
161
|
+
&& isFinalReviewAgent(priorReviewTask?.agentName) && priorReviewTask?.unblock?.event === 'task.unblocked'
|
|
162
|
+
&& ['QUEUED', 'RUNNING', 'FAILED'].includes(priorReviewTask?.state ?? '')) {
|
|
193
163
|
const recovered = await dispatchReviewLifecycle('blocked', 'review.retry', { reviewUnblocked: true });
|
|
194
164
|
if (recovered.accepted && recovered.target === 'PENDING') {
|
|
195
165
|
job.review = { ...job.review, outcome: 'pending', updatedAt: new Date().toISOString() };
|
|
@@ -271,7 +241,7 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
271
241
|
}
|
|
272
242
|
async routeTaskForExecution(job, task) {
|
|
273
243
|
const implementationThread = resolveImplementationTaskThreadDestination(job, task);
|
|
274
|
-
const reviewerThread = task.agentName
|
|
244
|
+
const reviewerThread = isFinalReviewAgent(task.agentName) ? resolveReviewerThreadDestination(job, this.options.reviewer?.threadId) : null;
|
|
275
245
|
if (task.routing && !((implementationThread || reviewerThread) && task.adapter !== 'chatgpt'))
|
|
276
246
|
return { task, routed: false };
|
|
277
247
|
if (!task.output || task.adapter === 'orchestrator')
|
|
@@ -293,7 +263,7 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
293
263
|
id: job.id, title: job.title, objective: job.objective ?? null,
|
|
294
264
|
description: job.description ?? null, priority: job.priority ?? null,
|
|
295
265
|
repository: job.repository,
|
|
296
|
-
prNumber:
|
|
266
|
+
prNumber: job.prNumber, state: job.state,
|
|
297
267
|
},
|
|
298
268
|
task: {
|
|
299
269
|
id: task.id, kind: task.kind ?? 'work', storySize: task.storySize ?? 'M',
|
|
@@ -315,18 +285,22 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
315
285
|
: [];
|
|
316
286
|
const taskExcludedRoutes = (task.routingExclusions ?? []).map(item => ({ provider: item.provider, model: item.model, profile: item.profile }));
|
|
317
287
|
const excludedRoutes = [...taskExcludedRoutes, ...parentExcludedRoutes];
|
|
318
|
-
const routed =
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
288
|
+
const routed = task.noStartFallback
|
|
289
|
+
? await codexNoStartFallbackRoute(task, this.options.adapters, registered, usage)
|
|
290
|
+
: await routeExecution(candidates, requirements, {
|
|
291
|
+
decisionEngine: this.options.decisionEngine,
|
|
292
|
+
decisionMode: this.options.decisionMode,
|
|
293
|
+
taskFacts: { ...taskFacts, recovery: task.recoveryContext ?? null, recovery_parent_failed_route: excludedRoutes[0] ?? null },
|
|
294
|
+
usage,
|
|
295
|
+
registered,
|
|
296
|
+
chatgptRunning: runtimeSummary?.chatgptRunning ?? 0,
|
|
297
|
+
routingConstraints,
|
|
298
|
+
excludedRoutes,
|
|
299
|
+
auditStore: this.options.decisionAuditStore,
|
|
300
|
+
auditTask: task,
|
|
301
|
+
});
|
|
302
|
+
if (!routed)
|
|
303
|
+
throw new Error('Codex configured default unavailable for no-start recovery');
|
|
330
304
|
task.workerSelection = routed.selection;
|
|
331
305
|
task.adapter = routed.candidate.adapter;
|
|
332
306
|
task.routing = routed.candidate.routing;
|
|
@@ -342,6 +316,21 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
342
316
|
return await this.routeTaskForExecution(job, task);
|
|
343
317
|
}
|
|
344
318
|
catch (error) {
|
|
319
|
+
if (task.noStartFallback) {
|
|
320
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
321
|
+
const transition = await this.taskTransitions.apply(job.id, task.id, 'fail', {
|
|
322
|
+
eligible: (_job, current) => current.state === 'QUEUED'
|
|
323
|
+
&& current.executionId === null
|
|
324
|
+
&& current.noStartFallback?.failedExecutionId === task.noStartFallback?.failedExecutionId,
|
|
325
|
+
mutate: (_job, current) => {
|
|
326
|
+
current.error = 'Codex default fallback route unavailable: ' + message;
|
|
327
|
+
current.failureReason = 'codex_default_fallback_unavailable';
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
if (transition?.decision.accepted)
|
|
331
|
+
await this.emit(eventFor(job.id, task.id, task.parentTaskId, 'task.failed', 'failed', transition.task.error ?? message, 'user', { reason: 'codex_default_fallback_unavailable' }, { agent: 'relay', component: 'agents-relay' }));
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
345
334
|
if (!['chatgpt', 'z'].includes(task.adapter) || !task.platformFailure?.safeToReroute)
|
|
346
335
|
throw error;
|
|
347
336
|
await quarantineUnavailableCodexFallback(this.taskTransitions, event => this.emit(event), job.id, task.id, error);
|
|
@@ -350,10 +339,10 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
350
339
|
}
|
|
351
340
|
async applyReviewEvent(event) {
|
|
352
341
|
const job = await this.store.load(event.job_id);
|
|
353
|
-
const task = job.tasks.find(item => item.id === event.task_id && item.agentName
|
|
342
|
+
const task = job.tasks.find(item => item.id === event.task_id && isFinalReviewAgent(item.agentName));
|
|
354
343
|
if (!task)
|
|
355
344
|
return { applied: false, reconcile: false, reason: event.type + '.ignored' };
|
|
356
|
-
const normalizedEvidence =
|
|
345
|
+
const normalizedEvidence = normalizeReviewEvidence(event, task);
|
|
357
346
|
if (!normalizedEvidence)
|
|
358
347
|
return { applied: false, reconcile: false, reason: event.type + '.ignored' };
|
|
359
348
|
const headSha = normalizedEvidence.headSha;
|
|
@@ -362,6 +351,13 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
362
351
|
const currentHeadSha = await this.currentHeadSha(job);
|
|
363
352
|
if (currentHeadSha ? currentHeadSha !== headSha : Boolean(job.headSha && job.headSha !== headSha))
|
|
364
353
|
return { applied: false, reconcile: false, reason: event.type + '.stale' };
|
|
354
|
+
// Reviewer attempts may restart at the same SHA. Graph-stale requests
|
|
355
|
+
// from prior execution generations before accepting this generation's
|
|
356
|
+
// verdict; otherwise their DRAFT children can block approval forever.
|
|
357
|
+
if (task.executionId && job.reviewRevisionRequests?.some(request => request.reviewTaskId === task.id && request.reviewHeadSha === headSha
|
|
358
|
+
&& request.reviewExecutionId !== task.executionId && request.status !== 'stale')) {
|
|
359
|
+
await staleReviewRevisions(this.store, job, task.id, headSha, (taskId, executionId) => this.cancelExecutionGeneration(job.id, taskId, executionId), task.executionId);
|
|
360
|
+
}
|
|
365
361
|
// Planner-created reviewer tasks predate the final-review Job gate. Bind
|
|
366
362
|
// their first trustworthy review event to PENDING before dispatching it.
|
|
367
363
|
const freshAfterStale = job.review?.outcome === 'stale'
|
|
@@ -383,22 +379,19 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
383
379
|
await this.store.saveTask(task);
|
|
384
380
|
}
|
|
385
381
|
let needsReconcile = false;
|
|
386
|
-
let
|
|
387
|
-
const reviewDecision = await dispatchReviewLifecycle(initialReviewOutcome, event.type, { autoMerge: job.autoMerge !== false }, async (actionId) => {
|
|
388
|
-
if (actionId === 'review.
|
|
382
|
+
let revisionDisposition;
|
|
383
|
+
const reviewDecision = await dispatchReviewLifecycle(initialReviewOutcome, event.type, { autoMerge: job.autoMerge !== false, targetedRevisionRequestsReady: targetedRequestsCoverReview(job, task, headSha, normalizedEvidence.issues) }, async (actionId) => {
|
|
384
|
+
if (actionId === 'review.awaitTargetedRevisions') {
|
|
385
|
+
revisionDisposition = 'targeted';
|
|
386
|
+
// Subsequent revision child scheduling is owned by the revision Graph;
|
|
387
|
+
// the review verdict never creates an unowned generic fix.
|
|
389
388
|
needsReconcile = true;
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const fixPrNumber = this.externalReviewPrNumber(job);
|
|
397
|
-
const fixTarget = fixPrNumber > 0 ? `PR #${fixPrNumber}` : `Job ${job.id} artifact`;
|
|
398
|
-
const input = 'Address all reviewer findings for ' + fixTarget + ' at ' + headSha + ':\n\n' + issues.map((issue, index) => (index + 1) + '. ' + issue).join('\n');
|
|
399
|
-
const fixTask = createTaskEntity(job, { jobId: job.id, id, title: `Fix review ${headSha.slice(0, 8)}`, kind: 'work', priority: job.priority, storySize: 'M', projectName: job.title, agentName: 'implementation', parentTaskId: task.id, dependencies: [task.id], capabilities: ['implementation'], workerRequirements: { capabilities: [] }, adapter: 'codex', input, output: { kind: 'task_pr' }, continuation: null, continuationDeliveredAt: null, attempt: 0, maxAttempts: 3, leaseOwner: null, leaseExpiresAt: null, executionId: null, threadId: null, result: null, plannerResult: null, error: null, timeoutMs: 0, createdAt: now, updatedAt: now });
|
|
400
|
-
pendingFixTask = fixTask;
|
|
401
|
-
}
|
|
389
|
+
return {};
|
|
390
|
+
}
|
|
391
|
+
if (actionId === 'review.requireOwnerResolution') {
|
|
392
|
+
revisionDisposition = 'needs-ownership';
|
|
393
|
+
// An explicitly authorized Planner re-plan may resolve ownership,
|
|
394
|
+
// but there is no implicit generic fix or automatic escalation.
|
|
402
395
|
return {};
|
|
403
396
|
}
|
|
404
397
|
if (actionId === 'review.requestMerge') {
|
|
@@ -426,6 +419,13 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
426
419
|
if (!freshTask || !reviewGenerationMatches(current, job, task, headSha))
|
|
427
420
|
return current;
|
|
428
421
|
const candidate = structuredClone(freshTask);
|
|
422
|
+
// The graph verdict was decided on the outer snapshot. Never commit a
|
|
423
|
+
// different disposition if concurrent intake changed the requests.
|
|
424
|
+
if (event.type === 'review.changes_required'
|
|
425
|
+
&& targetedRequestsCoverReview(current, freshTask, headSha, normalizedEvidence.issues)
|
|
426
|
+
!== (revisionDisposition === 'targeted'))
|
|
427
|
+
return current;
|
|
428
|
+
const requestIds = targetedRequestsForReview(current, freshTask, headSha).map(item => item.requestId);
|
|
429
429
|
const freshDecision = tryTransitionTaskEvent(candidate, event.type);
|
|
430
430
|
if (!freshDecision.accepted || !freshDecision.target)
|
|
431
431
|
return current;
|
|
@@ -447,9 +447,18 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
447
447
|
freshTask.error = null;
|
|
448
448
|
if (freshDecision.target !== 'RUNNING')
|
|
449
449
|
freshTask.result = { summary: event.message || `Review ${event.type}`, data: event.data ?? {} };
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
450
|
+
current.review = { outcome, headSha, taskId: freshTask.id, evidence, updatedAt: reviewUpdatedAt,
|
|
451
|
+
...(revisionDisposition ? { revisionDisposition } : {}) };
|
|
452
|
+
if ((event.type === 'review.changes_required' || event.type === 'review.approved') && terminalExecutionId
|
|
453
|
+
&& !current.reviewRevisionRounds?.some(round => round.reviewTaskId === freshTask.id && round.reviewExecutionId === terminalExecutionId)) {
|
|
454
|
+
current.reviewRevisionRounds = [...(current.reviewRevisionRounds ?? []), {
|
|
455
|
+
reviewTaskId: freshTask.id, reviewExecutionId: terminalExecutionId, headSha,
|
|
456
|
+
requestIds,
|
|
457
|
+
status: outcome === 'approved' ? 'approved' : 'changes_required',
|
|
458
|
+
findingFingerprint: reviewFindingFingerprint(normalizedEvidence.issues),
|
|
459
|
+
recordedAt: reviewUpdatedAt,
|
|
460
|
+
}];
|
|
461
|
+
}
|
|
453
462
|
current.updatedAt = reviewUpdatedAt;
|
|
454
463
|
committed = true;
|
|
455
464
|
return current;
|
|
@@ -461,17 +470,9 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
461
470
|
if (terminalExecutionId) {
|
|
462
471
|
this.finalizeReviewExecution(job.id, { ...task, executionId: terminalExecutionId }, event);
|
|
463
472
|
}
|
|
464
|
-
const committedFixTask = pendingFixTask;
|
|
465
|
-
if (committedFixTask)
|
|
466
|
-
await this.emit(eventFor(job.id, committedFixTask.id, task.id, 'review.fix_task_created', 'queued', 'Created one fix task ' + committedFixTask.id + ' for reviewer findings', 'orchestrator', { headSha }, { agent: 'relay', component: 'agents-relay' }));
|
|
467
473
|
}
|
|
468
474
|
else {
|
|
469
|
-
|
|
470
|
-
if (legacyFixTask) {
|
|
471
|
-
await this.store.appendTask(legacyFixTask);
|
|
472
|
-
await this.emit(eventFor(job.id, legacyFixTask.id, task.id, 'review.fix_task_created', 'queued', 'Created one fix task ' + legacyFixTask.id + ' for reviewer findings', 'orchestrator', { headSha }, { agent: 'relay', component: 'agents-relay' }));
|
|
473
|
-
}
|
|
474
|
-
job.review = { outcome, headSha, taskId: task.id, evidence, updatedAt: reviewUpdatedAt };
|
|
475
|
+
job.review = { outcome, headSha, taskId: task.id, evidence, updatedAt: reviewUpdatedAt, ...(revisionDisposition ? { revisionDisposition } : {}) };
|
|
475
476
|
job.updatedAt = reviewUpdatedAt;
|
|
476
477
|
await this.store.saveTask(task);
|
|
477
478
|
await this.store.saveJob(job);
|