patchrelay 0.74.3 → 0.74.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "service": "patchrelay",
3
- "version": "0.74.3",
4
- "commit": "21e6267a7b1c",
5
- "builtAt": "2026-05-28T21:47:39.635Z"
3
+ "version": "0.74.4",
4
+ "commit": "c6959e0ae3d7",
5
+ "builtAt": "2026-05-29T01:07:21.410Z"
6
6
  }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Every failure-provenance field on an issue, set to null.
3
+ *
4
+ * Spread into an issue upsert when a run reaches a clean advancing or terminal
5
+ * state (for example `awaiting_queue` or `done`) and any previously recorded
6
+ * GitHub failure or queue-incident context must not leak into the next
7
+ * decision. Keeping the field set in one place stops it from drifting between
8
+ * the run finalizer, the reconcilers, the completion check, and the webhook
9
+ * state projector.
10
+ */
11
+ export const CLEARED_FAILURE_PROVENANCE = {
12
+ lastGitHubFailureSource: null,
13
+ lastGitHubFailureHeadSha: null,
14
+ lastGitHubFailureSignature: null,
15
+ lastGitHubFailureCheckName: null,
16
+ lastGitHubFailureCheckUrl: null,
17
+ lastGitHubFailureContextJson: null,
18
+ lastGitHubFailureAt: null,
19
+ lastQueueIncidentJson: null,
20
+ lastAttemptedFailureHeadSha: null,
21
+ lastAttemptedFailureSignature: null,
22
+ lastAttemptedFailureAt: null,
23
+ };
@@ -1,3 +1,4 @@
1
+ import { CLEARED_FAILURE_PROVENANCE } from "./failure-provenance.js";
1
2
  import { createGitHubCiSnapshotResolver, createGitHubFailureContextResolver } from "./github-failure-context.js";
2
3
  import { buildClosedPrCleanupFields } from "./pr-state.js";
3
4
  import { canClearFailureProvenance, deriveImmediatePrCheckStatus, getGateCheckNames, getPrimaryGateCheckName, isGateCheckEvent, isMetadataOnlyCheckEvent, isQueueEvictionFailure, isStaleGateEvent, isSettledBranchFailure, resolveGitHubFactoryStateForEvent, } from "./github-webhook-policy.js";
@@ -313,17 +314,7 @@ async function updateGitHubFailureProvenance(deps, issue, event, project, failur
313
314
  deps.db.issues.upsertIssue({
314
315
  projectId: issue.projectId,
315
316
  linearIssueId: issue.linearIssueId,
316
- lastGitHubFailureSource: null,
317
- lastGitHubFailureHeadSha: null,
318
- lastGitHubFailureSignature: null,
319
- lastGitHubFailureCheckName: null,
320
- lastGitHubFailureCheckUrl: null,
321
- lastGitHubFailureContextJson: null,
322
- lastGitHubFailureAt: null,
323
- lastQueueIncidentJson: null,
324
- lastAttemptedFailureHeadSha: null,
325
- lastAttemptedFailureSignature: null,
326
- lastAttemptedFailureAt: null,
317
+ ...CLEARED_FAILURE_PROVENANCE,
327
318
  });
328
319
  }
329
320
  }
@@ -1,4 +1,5 @@
1
1
  import { TERMINAL_STATES } from "./factory-state.js";
2
+ import { CLEARED_FAILURE_PROVENANCE } from "./failure-provenance.js";
2
3
  import { DEPLOY_WATCH_TIMEOUT_MS, evaluateDeploy, isDeployTrackingEnabled, } from "./post-merge-deploy.js";
3
4
  import { buildBranchUpkeepContext, buildFailureContext, getGateCheckNames, hasCompletedReviewQuillVerdict, hasFailureProvenance, isDuplicateRepairAttempt, isFailingCheckStatus, isReviewDecisionApproved, isReviewDecisionReviewRequired, } from "./idle-reconciliation-helpers.js";
4
5
  import { resolveMergeQueueProtocol } from "./merge-queue-protocol.js";
@@ -9,7 +10,7 @@ import { getReviewFixBudget } from "./run-budgets.js";
9
10
  import { queueSettledOrchestrationIssue } from "./orchestration-parent-wake.js";
10
11
  import { fetchPullRequestSnapshot } from "./reconcile-pr-fetch.js";
11
12
  import { buildPrStateUpdates } from "./reconcile-pr-state-updates.js";
12
- import { buildRequestedChangesWakeIdentity } from "./reactive-wake-keys.js";
13
+ import { buildRepairWakeDedupeKey, buildRequestedChangesWakeIdentity, reactiveWakeEventType } from "./reactive-wake-keys.js";
13
14
  import { execCommand } from "./utils.js";
14
15
  export class IdleIssueReconciler {
15
16
  db;
@@ -239,19 +240,7 @@ export class IdleIssueReconciler {
239
240
  }
240
241
  : {}),
241
242
  ...(options?.clearFailureProvenance
242
- ? {
243
- lastGitHubFailureSource: null,
244
- lastGitHubFailureHeadSha: null,
245
- lastGitHubFailureSignature: null,
246
- lastGitHubFailureCheckName: null,
247
- lastGitHubFailureCheckUrl: null,
248
- lastGitHubFailureContextJson: null,
249
- lastGitHubFailureAt: null,
250
- lastQueueIncidentJson: null,
251
- lastAttemptedFailureHeadSha: null,
252
- lastAttemptedFailureSignature: null,
253
- lastAttemptedFailureAt: null,
254
- }
243
+ ? { ...CLEARED_FAILURE_PROVENANCE }
255
244
  : {}),
256
245
  });
257
246
  const updatedIssue = this.db.issues.getIssue(issue.projectId, issue.linearIssueId) ?? issue;
@@ -277,18 +266,19 @@ export class IdleIssueReconciler {
277
266
  // is needed here.
278
267
  }
279
268
  recordWakeEvent(issue, runType, context, dedupeScope = "idle_reconciliation") {
280
- let eventType;
269
+ const eventType = reactiveWakeEventType(runType);
281
270
  let dedupeKey;
282
- if (runType === "queue_repair") {
283
- eventType = "merge_steward_incident";
284
- dedupeKey = `${dedupeScope}:queue_repair:${issue.linearIssueId}:${issue.lastGitHubFailureSignature ?? issue.prHeadSha ?? issue.lastGitHubFailureHeadSha ?? "unknown"}`;
285
- }
286
- else if (runType === "ci_repair") {
287
- eventType = "settled_red_ci";
288
- dedupeKey = `${dedupeScope}:ci_repair:${issue.linearIssueId}:${issue.lastGitHubFailureSignature ?? issue.prHeadSha ?? issue.lastGitHubFailureHeadSha ?? "unknown"}`;
271
+ if (runType === "queue_repair" || runType === "ci_repair") {
272
+ dedupeKey = buildRepairWakeDedupeKey({
273
+ scope: dedupeScope,
274
+ runType,
275
+ linearIssueId: issue.linearIssueId,
276
+ signature: issue.lastGitHubFailureSignature,
277
+ prHeadSha: issue.prHeadSha,
278
+ failureHeadSha: issue.lastGitHubFailureHeadSha,
279
+ });
289
280
  }
290
281
  else if (runType === "review_fix" || runType === "branch_upkeep") {
291
- eventType = "review_changes_requested";
292
282
  dedupeKey = buildRequestedChangesWakeIdentity({
293
283
  linearIssueId: issue.linearIssueId,
294
284
  runType,
@@ -296,7 +286,6 @@ export class IdleIssueReconciler {
296
286
  }).dedupeKey;
297
287
  }
298
288
  else {
299
- eventType = "delegated";
300
289
  dedupeKey = `${dedupeScope}:implementation:${issue.linearIssueId}`;
301
290
  }
302
291
  const requestedChangesIdentity = eventType === "review_changes_requested"
@@ -1,9 +1,7 @@
1
1
  import { ACTIVE_RUN_STATES } from "./factory-state.js";
2
2
  import { buildRunFailureActivity } from "./linear-session-reporting.js";
3
3
  import { deriveIssueSessionReactiveIntent } from "./issue-session.js";
4
- function isRequestedChangesRunType(runType) {
5
- return runType === "review_fix" || runType === "branch_upkeep";
6
- }
4
+ import { isRequestedChangesRunType } from "./reactive-pr-state.js";
7
5
  function resolveRetryRunType(runType, context) {
8
6
  if (runType === "branch_upkeep") {
9
7
  return "branch_upkeep";
@@ -1,3 +1,4 @@
1
+ import { CLEARED_FAILURE_PROVENANCE } from "./failure-provenance.js";
1
2
  import { buildCompletionCheckActivity } from "./linear-session-reporting.js";
2
3
  import { wakeOrchestrationParentsForChildEvent } from "./orchestration-parent-wake.js";
3
4
  function shouldContinueForUnpublishedLocalChanges(message) {
@@ -183,17 +184,7 @@ export async function handleNoPrCompletionCheck(params) {
183
184
  pendingRunType: null,
184
185
  pendingRunContextJson: null,
185
186
  orchestrationSettleUntil: null,
186
- lastGitHubFailureSource: null,
187
- lastGitHubFailureHeadSha: null,
188
- lastGitHubFailureSignature: null,
189
- lastGitHubFailureCheckName: null,
190
- lastGitHubFailureCheckUrl: null,
191
- lastGitHubFailureContextJson: null,
192
- lastGitHubFailureAt: null,
193
- lastQueueIncidentJson: null,
194
- lastAttemptedFailureHeadSha: null,
195
- lastAttemptedFailureSignature: null,
196
- lastAttemptedFailureAt: null,
187
+ ...CLEARED_FAILURE_PROVENANCE,
197
188
  });
198
189
  return true;
199
190
  });
@@ -1,4 +1,5 @@
1
1
  import { resolveMergeQueueProtocol } from "./merge-queue-protocol.js";
2
+ import { buildRepairWakeDedupeKey } from "./reactive-wake-keys.js";
2
3
  import { execCommand } from "./utils.js";
3
4
  const QUEUE_HEALTH_GRACE_MS = 120_000;
4
5
  const QUEUE_HEALTH_PROBE_FAILURE_COOLDOWN_MS = 300_000;
@@ -167,7 +168,12 @@ export class QueueHealthMonitor {
167
168
  this.advancer.wakeDispatcher.recordEventAndDispatch(issue.projectId, issue.linearIssueId, {
168
169
  eventType: "merge_steward_incident",
169
170
  eventJson: JSON.stringify(pendingRunContext),
170
- dedupeKey: `queue_health:queue_repair:${issue.linearIssueId}:${signature}`,
171
+ dedupeKey: buildRepairWakeDedupeKey({
172
+ scope: "queue_health",
173
+ runType: "queue_repair",
174
+ linearIssueId: issue.linearIssueId,
175
+ signature,
176
+ }),
171
177
  });
172
178
  this.advancer.advanceIdleIssue(issue, "repairing_queue");
173
179
  this.logger.info({ issueKey: issue.issueKey, prNumber: issue.prNumber, headRefOid, reason }, "Queue health: queue issue detected, dispatching repair");
@@ -2,6 +2,15 @@ import { readRemotePrState } from "./remote-pr-state.js";
2
2
  export function isRequestedChangesRunType(runType) {
3
3
  return runType === "review_fix" || runType === "branch_upkeep";
4
4
  }
5
+ /**
6
+ * The terminal state a failed run should land the issue in: requested-changes
7
+ * repairs escalate (a human asked for the change, so a silent failure must
8
+ * surface), everything else fails. Centralized so the mapping cannot diverge
9
+ * between the launcher and the notification handler.
10
+ */
11
+ export function resolveFailureFactoryState(runType) {
12
+ return isRequestedChangesRunType(runType) ? "escalated" : "failed";
13
+ }
5
14
  export function normalizeRemotePrState(value) {
6
15
  const normalized = value?.trim().toUpperCase();
7
16
  if (normalized === "OPEN")
@@ -1,3 +1,4 @@
1
+ import { CLEARED_FAILURE_PROVENANCE } from "./failure-provenance.js";
1
2
  import { buildReviewFixBranchUpkeepContext, isDirtyMergeStateStatus, isRequestedChangesRunType, readReactivePrSnapshot, } from "./reactive-pr-state.js";
2
3
  import { readReactivePublishDelta } from "./reactive-publish-delta.js";
3
4
  import { readLatestRequestedChangesReviewContext } from "./remote-pr-review.js";
@@ -173,17 +174,7 @@ export class ReactiveRunPolicy {
173
174
  ...((headAdvanced || reviewFixHeadAdvanced)
174
175
  ? {
175
176
  prCheckStatus: "pending",
176
- lastGitHubFailureSource: null,
177
- lastGitHubFailureHeadSha: null,
178
- lastGitHubFailureSignature: null,
179
- lastGitHubFailureCheckName: null,
180
- lastGitHubFailureCheckUrl: null,
181
- lastGitHubFailureContextJson: null,
182
- lastGitHubFailureAt: null,
183
- lastQueueIncidentJson: null,
184
- lastAttemptedFailureHeadSha: null,
185
- lastAttemptedFailureSignature: null,
186
- lastAttemptedFailureAt: null,
177
+ ...CLEARED_FAILURE_PROVENANCE,
187
178
  lastGitHubCiSnapshotHeadSha: snapshot.headSha ?? null,
188
179
  lastGitHubCiSnapshotGateCheckName: snapshot.gateCheckName,
189
180
  lastGitHubCiSnapshotGateCheckStatus: "pending",
@@ -62,3 +62,32 @@ function parseObject(raw) {
62
62
  return undefined;
63
63
  }
64
64
  }
65
+ /**
66
+ * Map a run type to the issue-session event type that wakes it. Shared by every
67
+ * reconciler that records a reactive wake (idle reconciliation, startup
68
+ * recovery, queue health) so the mapping stays in one place.
69
+ */
70
+ export function reactiveWakeEventType(runType) {
71
+ switch (runType) {
72
+ case "queue_repair":
73
+ return "merge_steward_incident";
74
+ case "ci_repair":
75
+ return "settled_red_ci";
76
+ case "review_fix":
77
+ case "branch_upkeep":
78
+ return "review_changes_requested";
79
+ default:
80
+ return "delegated";
81
+ }
82
+ }
83
+ /**
84
+ * Build the dedupe key for a CI/queue repair wake. The discriminator prefers the
85
+ * failure signature, then the PR head, then the recorded failure head, falling
86
+ * back to "unknown" — the same precedence every reconciler used independently
87
+ * before this was consolidated (a prior divergence here swallowed fresh repair
88
+ * incidents after the main branch advanced).
89
+ */
90
+ export function buildRepairWakeDedupeKey(params) {
91
+ const discriminator = params.signature ?? params.prHeadSha ?? params.failureHeadSha ?? "unknown";
92
+ return `${params.scope}:${params.runType}:${params.linearIssueId}:${discriminator}`;
93
+ }
@@ -1,3 +1,4 @@
1
+ import { CLEARED_FAILURE_PROVENANCE } from "./failure-provenance.js";
1
2
  import { buildStageReport, countEventMethods } from "./run-reporting.js";
2
3
  import { buildRunCompletedActivity, buildRunFailureActivity } from "./linear-session-reporting.js";
3
4
  import { handleNoPrCompletionCheck } from "./no-pr-completion-check.js";
@@ -449,19 +450,7 @@ export class RunFinalizer {
449
450
  pendingRunType: null,
450
451
  pendingRunContextJson: null,
451
452
  ...(postRunFollowUp ? {} : (postRunState === "awaiting_queue" || postRunState === "done"
452
- ? {
453
- lastGitHubFailureSource: null,
454
- lastGitHubFailureHeadSha: null,
455
- lastGitHubFailureSignature: null,
456
- lastGitHubFailureCheckName: null,
457
- lastGitHubFailureCheckUrl: null,
458
- lastGitHubFailureContextJson: null,
459
- lastGitHubFailureAt: null,
460
- lastQueueIncidentJson: null,
461
- lastAttemptedFailureHeadSha: null,
462
- lastAttemptedFailureSignature: null,
463
- lastAttemptedFailureAt: null,
464
- }
453
+ ? { ...CLEARED_FAILURE_PROVENANCE }
465
454
  : {})),
466
455
  });
467
456
  if (postRunFollowUp) {
@@ -1,3 +1,4 @@
1
+ import { resolveFailureFactoryState } from "./reactive-pr-state.js";
1
2
  import { buildHookEnv, runProjectHook } from "./hook-runner.js";
2
3
  import { buildRunFailureActivity } from "./linear-session-reporting.js";
3
4
  import { loadPatchRelayRepoPrompting } from "./patchrelay-customization.js";
@@ -228,7 +229,7 @@ export class RunLauncher {
228
229
  const message = error instanceof Error ? error.message : String(error);
229
230
  const lostLease = error instanceof Error && error.name === "IssueSessionLeaseLostError";
230
231
  if (!lostLease) {
231
- const nextState = params.isRequestedChangesRunType(params.runType) ? "escalated" : "failed";
232
+ const nextState = resolveFailureFactoryState(params.runType);
232
233
  this.db.issueSessions.finishRunWithLease({ projectId: params.project.id, linearIssueId: params.issue.linearIssueId, leaseId: params.leaseId }, params.run.id, {
233
234
  status: "failed",
234
235
  failureReason: message,
@@ -1,9 +1,7 @@
1
1
  import { buildRunFailureActivity } from "./linear-session-reporting.js";
2
2
  import { extractTurnId, resolveRunCompletionStatus } from "./run-reporting.js";
3
3
  import { resolveRecoverablePostRunState } from "./interrupted-run-recovery.js";
4
- function isRequestedChangesRunType(runType) {
5
- return runType === "review_fix" || runType === "branch_upkeep";
6
- }
4
+ import { resolveFailureFactoryState } from "./reactive-pr-state.js";
7
5
  const DEFAULT_PUBLISH_COMMAND_TIMEOUT_MS = 10 * 60 * 1000;
8
6
  export class RunNotificationHandler {
9
7
  config;
@@ -91,7 +89,7 @@ export class RunNotificationHandler {
91
89
  this.activeThreadId = undefined;
92
90
  return;
93
91
  }
94
- const nextState = isRequestedChangesRunType(run.runType) ? "escalated" : "failed";
92
+ const nextState = resolveFailureFactoryState(run.runType);
95
93
  const updated = this.withHeldIssueSessionLease(run.projectId, run.linearIssueId, (lease) => {
96
94
  this.db.issueSessions.finishRunWithLease(lease, run.id, {
97
95
  status: "failed",
@@ -1,3 +1,4 @@
1
+ import { isRequestedChangesRunType } from "./reactive-pr-state.js";
1
2
  import { summarizeCurrentThread } from "./run-reporting.js";
2
3
  import { buildReviewRoundStartedActivity, buildRunStartedActivity, } from "./linear-session-reporting.js";
3
4
  import { CompletionCheckService } from "./completion-check.js";
@@ -25,9 +26,6 @@ import { CodexThreadMaterializingError, isThreadMaterializingError } from "./cod
25
26
  function lowerCaseFirst(value) {
26
27
  return value ? `${value.slice(0, 1).toLowerCase()}${value.slice(1)}` : value;
27
28
  }
28
- function isRequestedChangesRunType(runType) {
29
- return runType === "review_fix" || runType === "branch_upkeep";
30
- }
31
29
  function shouldDelayZombieRecoveryLaunch(issue, issueSession, runType) {
32
30
  if (issue.zombieRecoveryAttempts <= 0)
33
31
  return 0;
@@ -420,7 +418,6 @@ export class RunOrchestrator {
420
418
  assertLaunchLease: (targetRun, phase) => this.assertLaunchLease(targetRun, phase),
421
419
  linearSync: this.linearSync,
422
420
  releaseLease: (projectId, issueId) => this.releaseIssueSessionLease(projectId, issueId),
423
- isRequestedChangesRunType,
424
421
  lowerCaseFirst,
425
422
  });
426
423
  this.assertLaunchLease(run, "before recording the active thread");
@@ -1,7 +1,7 @@
1
1
  import { appendDelegationObservedEvent } from "./delegation-audit.js";
2
2
  import { deriveIssueSessionReactiveIntent } from "./issue-session.js";
3
3
  import { isResumablePausedLocalWork } from "./paused-issue-state.js";
4
- import { buildRequestedChangesWakeIdentity } from "./reactive-wake-keys.js";
4
+ import { buildRepairWakeDedupeKey, buildRequestedChangesWakeIdentity, reactiveWakeEventType } from "./reactive-wake-keys.js";
5
5
  export class ServiceStartupRecovery {
6
6
  db;
7
7
  linearProvider;
@@ -170,20 +170,21 @@ export class ServiceStartupRecovery {
170
170
  }
171
171
  }
172
172
  appendReactiveWakeEvent(projectId, linearIssueId, issue, runType) {
173
- const eventType = runType === "queue_repair"
174
- ? "merge_steward_incident"
175
- : runType === "ci_repair"
176
- ? "settled_red_ci"
177
- : "review_changes_requested";
178
- const dedupeKey = runType === "queue_repair"
179
- ? `startup_recovery:queue_repair:${linearIssueId}:${issue.lastGitHubFailureSignature ?? issue.prHeadSha ?? issue.lastGitHubFailureHeadSha ?? "unknown"}`
180
- : runType === "ci_repair"
181
- ? `startup_recovery:ci_repair:${linearIssueId}:${issue.lastGitHubFailureSignature ?? issue.prHeadSha ?? issue.lastGitHubFailureHeadSha ?? "unknown"}`
182
- : buildRequestedChangesWakeIdentity({
183
- linearIssueId,
184
- runType,
185
- headSha: issue.prHeadSha,
186
- }).dedupeKey;
173
+ const eventType = reactiveWakeEventType(runType);
174
+ const dedupeKey = runType === "queue_repair" || runType === "ci_repair"
175
+ ? buildRepairWakeDedupeKey({
176
+ scope: "startup_recovery",
177
+ runType,
178
+ linearIssueId,
179
+ signature: issue.lastGitHubFailureSignature,
180
+ prHeadSha: issue.prHeadSha,
181
+ failureHeadSha: issue.lastGitHubFailureHeadSha,
182
+ })
183
+ : buildRequestedChangesWakeIdentity({
184
+ linearIssueId,
185
+ runType,
186
+ headSha: issue.prHeadSha,
187
+ }).dedupeKey;
187
188
  const requestedChangesIdentity = eventType === "review_changes_requested"
188
189
  ? buildRequestedChangesWakeIdentity({
189
190
  linearIssueId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "patchrelay",
3
- "version": "0.74.3",
3
+ "version": "0.74.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {