patchrelay 0.52.2 → 0.52.4
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/build-info.json
CHANGED
|
@@ -38,7 +38,7 @@ export class ImplementationOutcomePolicy {
|
|
|
38
38
|
return await this.describeLocalImplementationOutcome(issue, baseBranch);
|
|
39
39
|
}
|
|
40
40
|
async detectPublishedPrState(run, issue, repoFullName) {
|
|
41
|
-
if (issue.prNumber && issue.prState
|
|
41
|
+
if (issue.prNumber && isOpenPrState(issue.prState)) {
|
|
42
42
|
return "open";
|
|
43
43
|
}
|
|
44
44
|
if (!repoFullName || !issue.branchName) {
|
|
@@ -61,24 +61,30 @@ export class ImplementationOutcomePolicy {
|
|
|
61
61
|
return "unknown";
|
|
62
62
|
}
|
|
63
63
|
const matches = JSON.parse(stdout);
|
|
64
|
-
const pr = matches[0];
|
|
64
|
+
const pr = matches.find((candidate) => isOpenPrState(candidate.state)) ?? matches[0];
|
|
65
65
|
if (!pr?.number) {
|
|
66
|
+
this.clearObservedPrIfLeaseHeld(issue, "published PR verification found no PRs for branch");
|
|
66
67
|
return "none";
|
|
67
68
|
}
|
|
68
69
|
const state = pr.state?.toLowerCase();
|
|
69
|
-
|
|
70
|
-
projectId
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
if (isOpenPrState(state)) {
|
|
71
|
+
this.upsertIssueIfLeaseHeld(issue.projectId, issue.linearIssueId, {
|
|
72
|
+
projectId: issue.projectId,
|
|
73
|
+
linearIssueId: issue.linearIssueId,
|
|
74
|
+
prNumber: pr.number,
|
|
75
|
+
...(pr.url ? { prUrl: pr.url } : {}),
|
|
76
|
+
...(state ? { prState: state } : {}),
|
|
77
|
+
...(pr.headRefOid ? { prHeadSha: pr.headRefOid } : {}),
|
|
78
|
+
...(pr.author?.login ? { prAuthorLogin: pr.author.login } : {}),
|
|
79
|
+
}, "published PR verification refresh");
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this.clearObservedPrIfLeaseHeld(issue, "published PR verification found only historical PRs for branch");
|
|
83
|
+
}
|
|
84
|
+
if (isOpenPrState(state) && isMainRepairIssue(issue)) {
|
|
79
85
|
await this.ensurePriorityQueueLabel(run.projectId, pr.number, repoFullName);
|
|
80
86
|
}
|
|
81
|
-
return state
|
|
87
|
+
return isOpenPrState(state) ? "open" : "closed";
|
|
82
88
|
}
|
|
83
89
|
catch (error) {
|
|
84
90
|
this.logger.debug({
|
|
@@ -97,6 +103,20 @@ export class ImplementationOutcomePolicy {
|
|
|
97
103
|
}
|
|
98
104
|
return updated;
|
|
99
105
|
}
|
|
106
|
+
clearObservedPrIfLeaseHeld(issue, context) {
|
|
107
|
+
this.upsertIssueIfLeaseHeld(issue.projectId, issue.linearIssueId, {
|
|
108
|
+
projectId: issue.projectId,
|
|
109
|
+
linearIssueId: issue.linearIssueId,
|
|
110
|
+
prNumber: null,
|
|
111
|
+
prUrl: null,
|
|
112
|
+
prState: null,
|
|
113
|
+
prIsDraft: null,
|
|
114
|
+
prHeadSha: null,
|
|
115
|
+
prAuthorLogin: null,
|
|
116
|
+
prReviewState: null,
|
|
117
|
+
prCheckStatus: null,
|
|
118
|
+
}, context);
|
|
119
|
+
}
|
|
100
120
|
async describeLocalImplementationOutcome(issue, baseBranch) {
|
|
101
121
|
if (!issue.worktreePath) {
|
|
102
122
|
return undefined;
|
|
@@ -177,3 +197,9 @@ export class ImplementationOutcomePolicy {
|
|
|
177
197
|
}
|
|
178
198
|
}
|
|
179
199
|
}
|
|
200
|
+
function isOpenPrState(state) {
|
|
201
|
+
if (!state)
|
|
202
|
+
return false;
|
|
203
|
+
const normalized = state.trim().toLowerCase();
|
|
204
|
+
return normalized !== "closed" && normalized !== "merged";
|
|
205
|
+
}
|
|
@@ -37,12 +37,7 @@ export class MainBranchHealthMonitor {
|
|
|
37
37
|
return;
|
|
38
38
|
const baseBranch = project.github.baseBranch ?? "main";
|
|
39
39
|
const branchName = buildMainRepairBranchName(baseBranch);
|
|
40
|
-
const existing = this.
|
|
41
|
-
&& issue.branchName === branchName
|
|
42
|
-
&& isMainRepairIssue(issue)
|
|
43
|
-
&& issue.factoryState !== "done"
|
|
44
|
-
&& issue.factoryState !== "failed"
|
|
45
|
-
&& issue.factoryState !== "escalated"));
|
|
40
|
+
const existing = this.findExistingMainRepair(projectId, branchName);
|
|
46
41
|
const summary = await this.readMainBranchFailure(project.github.repoFullName, baseBranch);
|
|
47
42
|
if (!summary) {
|
|
48
43
|
if (existing) {
|
|
@@ -114,6 +109,33 @@ export class MainBranchHealthMonitor {
|
|
|
114
109
|
detail: summary.failingChecks.map((check) => check.name).join(", "),
|
|
115
110
|
});
|
|
116
111
|
}
|
|
112
|
+
findExistingMainRepair(projectId, branchName) {
|
|
113
|
+
const candidates = this.db.listIssues()
|
|
114
|
+
.filter((issue) => (issue.projectId === projectId
|
|
115
|
+
&& issue.branchName === branchName
|
|
116
|
+
&& isMainRepairIssue(issue)
|
|
117
|
+
&& issue.factoryState !== "done"))
|
|
118
|
+
.sort((left, right) => this.compareMainRepairCandidates(left, right));
|
|
119
|
+
return candidates[0];
|
|
120
|
+
}
|
|
121
|
+
compareMainRepairCandidates(left, right) {
|
|
122
|
+
const leftPriority = this.rankMainRepairCandidate(left);
|
|
123
|
+
const rightPriority = this.rankMainRepairCandidate(right);
|
|
124
|
+
if (leftPriority !== rightPriority)
|
|
125
|
+
return leftPriority - rightPriority;
|
|
126
|
+
return Date.parse(right.updatedAt) - Date.parse(left.updatedAt);
|
|
127
|
+
}
|
|
128
|
+
rankMainRepairCandidate(issue) {
|
|
129
|
+
if (issue.activeRunId !== undefined)
|
|
130
|
+
return 0;
|
|
131
|
+
if (issue.prState === "open" || issue.factoryState === "awaiting_queue" || issue.factoryState === "pr_open")
|
|
132
|
+
return 1;
|
|
133
|
+
if (issue.factoryState === "delegated" || issue.factoryState === "implementing")
|
|
134
|
+
return 2;
|
|
135
|
+
if (issue.factoryState === "failed" || issue.factoryState === "escalated")
|
|
136
|
+
return 3;
|
|
137
|
+
return 4;
|
|
138
|
+
}
|
|
117
139
|
queueExistingMainRepair(issue, summary, priorityLabel) {
|
|
118
140
|
if (issue.activeRunId !== undefined)
|
|
119
141
|
return;
|
|
@@ -121,6 +143,15 @@ export class MainBranchHealthMonitor {
|
|
|
121
143
|
return;
|
|
122
144
|
if (issue.prState === "open" || issue.factoryState === "awaiting_queue" || issue.factoryState === "pr_open")
|
|
123
145
|
return;
|
|
146
|
+
this.db.upsertIssue({
|
|
147
|
+
projectId: issue.projectId,
|
|
148
|
+
linearIssueId: issue.linearIssueId,
|
|
149
|
+
delegatedToPatchRelay: true,
|
|
150
|
+
factoryState: "delegated",
|
|
151
|
+
pendingRunType: null,
|
|
152
|
+
pendingRunContextJson: null,
|
|
153
|
+
activeRunId: null,
|
|
154
|
+
});
|
|
124
155
|
this.db.issueSessions.appendIssueSessionEventRespectingActiveLease(issue.projectId, issue.linearIssueId, {
|
|
125
156
|
projectId: issue.projectId,
|
|
126
157
|
linearIssueId: issue.linearIssueId,
|
|
@@ -131,6 +162,7 @@ export class MainBranchHealthMonitor {
|
|
|
131
162
|
failingChecks: summary.failingChecks,
|
|
132
163
|
pendingChecks: summary.pendingChecks,
|
|
133
164
|
priorityLabel,
|
|
165
|
+
promptContext: buildMainRepairPromptContext(this.config.projects.find((project) => project.id === issue.projectId) ?? { id: issue.projectId }, summary, priorityLabel),
|
|
134
166
|
}),
|
|
135
167
|
dedupeKey: `main_repair:${issue.projectId}:${summary.baseSha}:${summary.failingChecks.map((check) => check.name).join("|")}`,
|
|
136
168
|
});
|
|
@@ -170,6 +170,51 @@ export async function handleNoPrCompletionCheck(params) {
|
|
|
170
170
|
});
|
|
171
171
|
return;
|
|
172
172
|
}
|
|
173
|
+
if (params.run.runType === "main_repair") {
|
|
174
|
+
const continued = params.withHeldLease(params.run.projectId, params.run.linearIssueId, (lease) => {
|
|
175
|
+
params.db.runs.finishRun(params.run.id, runUpdate);
|
|
176
|
+
params.db.runs.saveCompletionCheck(params.run.id, {
|
|
177
|
+
...completionCheck,
|
|
178
|
+
outcome: "continue",
|
|
179
|
+
summary: "Main repair cannot finish without a published repair PR; continuing automatically until the fix is published or main recovers externally.",
|
|
180
|
+
why: completionCheck.summary,
|
|
181
|
+
});
|
|
182
|
+
params.db.issues.upsertIssue({
|
|
183
|
+
projectId: params.run.projectId,
|
|
184
|
+
linearIssueId: params.run.linearIssueId,
|
|
185
|
+
activeRunId: null,
|
|
186
|
+
factoryState: "delegated",
|
|
187
|
+
pendingRunType: null,
|
|
188
|
+
pendingRunContextJson: null,
|
|
189
|
+
});
|
|
190
|
+
return Boolean(params.db.issueSessions.appendIssueSessionEventWithLease(lease, {
|
|
191
|
+
projectId: params.run.projectId,
|
|
192
|
+
linearIssueId: params.run.linearIssueId,
|
|
193
|
+
eventType: "completion_check_continue",
|
|
194
|
+
eventJson: JSON.stringify({
|
|
195
|
+
runType: params.run.runType,
|
|
196
|
+
summary: params.publishedOutcomeError,
|
|
197
|
+
}),
|
|
198
|
+
dedupeKey: `completion_check_continue:${params.run.id}`,
|
|
199
|
+
}));
|
|
200
|
+
});
|
|
201
|
+
if (!continued) {
|
|
202
|
+
params.logger.warn({ runId: params.run.id, issueId: params.run.linearIssueId }, "Skipping main-repair completion-check continue writes after losing issue-session lease");
|
|
203
|
+
params.clearProgressAndRelease(params.run);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
params.syncCompletionCheckOutcome({
|
|
207
|
+
run: params.run,
|
|
208
|
+
fallbackIssue: params.issue,
|
|
209
|
+
level: "info",
|
|
210
|
+
status: "completion_check_continue",
|
|
211
|
+
summary: "No repair PR found; continuing automatically",
|
|
212
|
+
detail: "Main repair cannot close until PatchRelay publishes a repair PR or main recovers externally.",
|
|
213
|
+
activity: buildCompletionCheckActivity("continue"),
|
|
214
|
+
enqueue: true,
|
|
215
|
+
});
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
173
218
|
const orchestrationOpenChildren = params.issue.issueClass === "orchestration"
|
|
174
219
|
? params.db.issues.countOpenChildIssues(params.run.projectId, params.run.linearIssueId)
|
|
175
220
|
: 0;
|