patchrelay 0.35.3 → 0.35.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 +3 -3
- package/dist/webhook-handler.js +57 -0
- package/package.json +1 -1
package/dist/build-info.json
CHANGED
package/dist/webhook-handler.js
CHANGED
|
@@ -98,6 +98,40 @@ export class WebhookHandler {
|
|
|
98
98
|
const result = await this.recordDesiredStage(project, hydrated);
|
|
99
99
|
const trackedIssue = result.issue;
|
|
100
100
|
const newlyReadyDependents = this.reconcileDependentReadiness(project.id, issue.id);
|
|
101
|
+
// Handle issue removal: release active runs, mark as failed.
|
|
102
|
+
if (hydrated.triggerEvent === "issueRemoved" && trackedIssue) {
|
|
103
|
+
const removedIssue = this.db.getIssue(project.id, issue.id);
|
|
104
|
+
if (removedIssue?.activeRunId) {
|
|
105
|
+
const run = this.db.getRun(removedIssue.activeRunId);
|
|
106
|
+
if (run) {
|
|
107
|
+
this.db.finishRun(run.id, { status: "released", failureReason: "Issue removed from Linear" });
|
|
108
|
+
}
|
|
109
|
+
this.db.upsertIssue({
|
|
110
|
+
projectId: project.id,
|
|
111
|
+
linearIssueId: issue.id,
|
|
112
|
+
activeRunId: null,
|
|
113
|
+
pendingRunType: null,
|
|
114
|
+
factoryState: "failed",
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
else if (removedIssue && !TERMINAL_STATES.has(removedIssue.factoryState)) {
|
|
118
|
+
this.db.upsertIssue({
|
|
119
|
+
projectId: project.id,
|
|
120
|
+
linearIssueId: issue.id,
|
|
121
|
+
pendingRunType: null,
|
|
122
|
+
factoryState: "failed",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
this.feed?.publish({
|
|
126
|
+
level: "warn",
|
|
127
|
+
kind: "stage",
|
|
128
|
+
issueKey: issue.identifier,
|
|
129
|
+
projectId: project.id,
|
|
130
|
+
stage: "failed",
|
|
131
|
+
status: "issue_removed",
|
|
132
|
+
summary: "Issue removed from Linear",
|
|
133
|
+
});
|
|
134
|
+
}
|
|
101
135
|
// Handle agent session events
|
|
102
136
|
await this.handleAgentSession(hydrated, project, trackedIssue, result.desiredStage, result.delegated);
|
|
103
137
|
// Handle comments during active run
|
|
@@ -179,6 +213,17 @@ export class WebhookHandler {
|
|
|
179
213
|
clearPendingImplementation = Boolean(existingIssue.pendingRunType);
|
|
180
214
|
}
|
|
181
215
|
}
|
|
216
|
+
// Un-delegation: transition to awaiting_input unless past point of no return.
|
|
217
|
+
// awaiting_queue means the PR is approved and in the merge queue — let it merge.
|
|
218
|
+
let undelegatedFactoryState;
|
|
219
|
+
if (normalized.triggerEvent === "delegateChanged" && !delegated && existingIssue) {
|
|
220
|
+
const pastNoReturn = existingIssue.factoryState === "awaiting_queue"
|
|
221
|
+
|| TERMINAL_STATES.has(existingIssue.factoryState);
|
|
222
|
+
if (!pastNoReturn) {
|
|
223
|
+
undelegatedFactoryState = "awaiting_input";
|
|
224
|
+
clearPendingImplementation = Boolean(existingIssue.pendingRunType);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
182
227
|
// Resolve agent session
|
|
183
228
|
const agentSessionId = normalized.agentSession?.id ??
|
|
184
229
|
(!activeRun && (pendingRunType || (normalized.triggerEvent === "delegateChanged" && !delegated)) ? null : undefined);
|
|
@@ -201,11 +246,23 @@ export class WebhookHandler {
|
|
|
201
246
|
: {}),
|
|
202
247
|
...(agentSessionId !== undefined ? { agentSessionId } : {}),
|
|
203
248
|
...(clearActiveRun ? { activeRunId: null } : {}),
|
|
249
|
+
...(undelegatedFactoryState ? { factoryState: undelegatedFactoryState } : {}),
|
|
204
250
|
});
|
|
205
251
|
if (clearActiveRun && activeRun) {
|
|
206
252
|
const reason = terminalForAutomation ? "Issue reached terminal state during active run" : "Un-delegated from PatchRelay";
|
|
207
253
|
this.db.finishRun(activeRun.id, { status: "released", failureReason: reason });
|
|
208
254
|
}
|
|
255
|
+
if (undelegatedFactoryState) {
|
|
256
|
+
this.feed?.publish({
|
|
257
|
+
level: "warn",
|
|
258
|
+
kind: "stage",
|
|
259
|
+
issueKey: issue.issueKey,
|
|
260
|
+
projectId: project.id,
|
|
261
|
+
stage: "awaiting_input",
|
|
262
|
+
status: "un_delegated",
|
|
263
|
+
summary: "Issue un-delegated from PatchRelay",
|
|
264
|
+
});
|
|
265
|
+
}
|
|
209
266
|
return {
|
|
210
267
|
issue: this.db.issueToTrackedIssue(issue),
|
|
211
268
|
desiredStage: pendingRunType,
|