@generacy-ai/orchestrator 0.6.0 → 0.7.0

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.
Files changed (178) hide show
  1. package/dist/config/schema.d.ts +7 -7
  2. package/dist/index.d.ts +3 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +4 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/routes/health.d.ts.map +1 -1
  7. package/dist/routes/health.js +5 -0
  8. package/dist/routes/health.js.map +1 -1
  9. package/dist/server.d.ts.map +1 -1
  10. package/dist/server.js +130 -26
  11. package/dist/server.js.map +1 -1
  12. package/dist/services/base-advance-monitor-service.d.ts +78 -0
  13. package/dist/services/base-advance-monitor-service.d.ts.map +1 -0
  14. package/dist/services/base-advance-monitor-service.js +233 -0
  15. package/dist/services/base-advance-monitor-service.js.map +1 -0
  16. package/dist/services/boot-resume-service.d.ts +19 -0
  17. package/dist/services/boot-resume-service.d.ts.map +1 -0
  18. package/dist/services/boot-resume-service.js +87 -0
  19. package/dist/services/boot-resume-service.js.map +1 -0
  20. package/dist/services/epic-completion-monitor-service.d.ts.map +1 -1
  21. package/dist/services/epic-completion-monitor-service.js +2 -0
  22. package/dist/services/epic-completion-monitor-service.js.map +1 -1
  23. package/dist/services/in-memory-queue-adapter.d.ts +4 -0
  24. package/dist/services/in-memory-queue-adapter.d.ts.map +1 -1
  25. package/dist/services/in-memory-queue-adapter.js +30 -3
  26. package/dist/services/in-memory-queue-adapter.js.map +1 -1
  27. package/dist/services/label-monitor-service.d.ts +3 -3
  28. package/dist/services/label-monitor-service.d.ts.map +1 -1
  29. package/dist/services/label-monitor-service.js +58 -41
  30. package/dist/services/label-monitor-service.js.map +1 -1
  31. package/dist/services/label-sync-service.d.ts.map +1 -1
  32. package/dist/services/label-sync-service.js +45 -10
  33. package/dist/services/label-sync-service.js.map +1 -1
  34. package/dist/services/merge-conflict-monitor-service.d.ts +73 -0
  35. package/dist/services/merge-conflict-monitor-service.d.ts.map +1 -0
  36. package/dist/services/merge-conflict-monitor-service.js +295 -0
  37. package/dist/services/merge-conflict-monitor-service.js.map +1 -0
  38. package/dist/services/orchestrator-version.d.ts +2 -0
  39. package/dist/services/orchestrator-version.d.ts.map +1 -0
  40. package/dist/services/orchestrator-version.js +23 -0
  41. package/dist/services/orchestrator-version.js.map +1 -0
  42. package/dist/services/phase-tracker-service.d.ts +10 -0
  43. package/dist/services/phase-tracker-service.d.ts.map +1 -1
  44. package/dist/services/phase-tracker-service.js +38 -0
  45. package/dist/services/phase-tracker-service.js.map +1 -1
  46. package/dist/services/post-activation-dispatch.d.ts +18 -0
  47. package/dist/services/post-activation-dispatch.d.ts.map +1 -0
  48. package/dist/services/post-activation-dispatch.js +30 -0
  49. package/dist/services/post-activation-dispatch.js.map +1 -0
  50. package/dist/services/pr-feedback-monitor-service.d.ts +13 -4
  51. package/dist/services/pr-feedback-monitor-service.d.ts.map +1 -1
  52. package/dist/services/pr-feedback-monitor-service.js +212 -26
  53. package/dist/services/pr-feedback-monitor-service.js.map +1 -1
  54. package/dist/services/redis-queue-adapter.d.ts +4 -0
  55. package/dist/services/redis-queue-adapter.d.ts.map +1 -1
  56. package/dist/services/redis-queue-adapter.js +90 -10
  57. package/dist/services/redis-queue-adapter.js.map +1 -1
  58. package/dist/services/worker-dispatcher.d.ts +14 -2
  59. package/dist/services/worker-dispatcher.d.ts.map +1 -1
  60. package/dist/services/worker-dispatcher.js +55 -2
  61. package/dist/services/worker-dispatcher.js.map +1 -1
  62. package/dist/types/api.d.ts +3 -0
  63. package/dist/types/api.d.ts.map +1 -1
  64. package/dist/types/api.js +1 -0
  65. package/dist/types/api.js.map +1 -1
  66. package/dist/types/index.d.ts +1 -1
  67. package/dist/types/index.d.ts.map +1 -1
  68. package/dist/types/index.js.map +1 -1
  69. package/dist/types/monitor.d.ts +72 -4
  70. package/dist/types/monitor.d.ts.map +1 -1
  71. package/dist/worker/base-merge.d.ts +54 -0
  72. package/dist/worker/base-merge.d.ts.map +1 -0
  73. package/dist/worker/base-merge.js +99 -0
  74. package/dist/worker/base-merge.js.map +1 -0
  75. package/dist/worker/clarification-markers.d.ts +29 -0
  76. package/dist/worker/clarification-markers.d.ts.map +1 -0
  77. package/dist/worker/clarification-markers.js +44 -0
  78. package/dist/worker/clarification-markers.js.map +1 -0
  79. package/dist/worker/clarification-poster.d.ts.map +1 -1
  80. package/dist/worker/clarification-poster.js +266 -25
  81. package/dist/worker/clarification-poster.js.map +1 -1
  82. package/dist/worker/claude-cli-worker.d.ts +21 -2
  83. package/dist/worker/claude-cli-worker.d.ts.map +1 -1
  84. package/dist/worker/claude-cli-worker.js +149 -4
  85. package/dist/worker/claude-cli-worker.js.map +1 -1
  86. package/dist/worker/cli-spawner.d.ts +4 -0
  87. package/dist/worker/cli-spawner.d.ts.map +1 -1
  88. package/dist/worker/cli-spawner.js +51 -7
  89. package/dist/worker/cli-spawner.js.map +1 -1
  90. package/dist/worker/config.d.ts +24 -8
  91. package/dist/worker/config.d.ts.map +1 -1
  92. package/dist/worker/config.js +37 -2
  93. package/dist/worker/config.js.map +1 -1
  94. package/dist/worker/evidence-hash.d.ts +32 -0
  95. package/dist/worker/evidence-hash.d.ts.map +1 -0
  96. package/dist/worker/evidence-hash.js +139 -0
  97. package/dist/worker/evidence-hash.js.map +1 -0
  98. package/dist/worker/handler-outcome-assertion.d.ts +38 -0
  99. package/dist/worker/handler-outcome-assertion.d.ts.map +1 -0
  100. package/dist/worker/handler-outcome-assertion.js +58 -0
  101. package/dist/worker/handler-outcome-assertion.js.map +1 -0
  102. package/dist/worker/handler-outcome.d.ts +50 -0
  103. package/dist/worker/handler-outcome.d.ts.map +1 -0
  104. package/dist/worker/handler-outcome.js +2 -0
  105. package/dist/worker/handler-outcome.js.map +1 -0
  106. package/dist/worker/label-manager.d.ts +58 -2
  107. package/dist/worker/label-manager.d.ts.map +1 -1
  108. package/dist/worker/label-manager.js +225 -27
  109. package/dist/worker/label-manager.js.map +1 -1
  110. package/dist/worker/merge-conflict-handler.d.ts +141 -0
  111. package/dist/worker/merge-conflict-handler.d.ts.map +1 -0
  112. package/dist/worker/merge-conflict-handler.js +642 -0
  113. package/dist/worker/merge-conflict-handler.js.map +1 -0
  114. package/dist/worker/merge-conflict-prompt.d.ts +35 -0
  115. package/dist/worker/merge-conflict-prompt.d.ts.map +1 -0
  116. package/dist/worker/merge-conflict-prompt.js +71 -0
  117. package/dist/worker/merge-conflict-prompt.js.map +1 -0
  118. package/dist/worker/merge-conflict-remedy.d.ts +42 -0
  119. package/dist/worker/merge-conflict-remedy.d.ts.map +1 -0
  120. package/dist/worker/merge-conflict-remedy.js +28 -0
  121. package/dist/worker/merge-conflict-remedy.js.map +1 -0
  122. package/dist/worker/output-tail-synthesis.d.ts +15 -0
  123. package/dist/worker/output-tail-synthesis.d.ts.map +1 -0
  124. package/dist/worker/output-tail-synthesis.js +25 -0
  125. package/dist/worker/output-tail-synthesis.js.map +1 -0
  126. package/dist/worker/output-tail.d.ts +13 -0
  127. package/dist/worker/output-tail.d.ts.map +1 -0
  128. package/dist/worker/output-tail.js +31 -0
  129. package/dist/worker/output-tail.js.map +1 -0
  130. package/dist/worker/pause-context.d.ts +30 -0
  131. package/dist/worker/pause-context.d.ts.map +1 -0
  132. package/dist/worker/pause-context.js +98 -0
  133. package/dist/worker/pause-context.js.map +1 -0
  134. package/dist/worker/phase-loop.d.ts +66 -0
  135. package/dist/worker/phase-loop.d.ts.map +1 -1
  136. package/dist/worker/phase-loop.js +295 -29
  137. package/dist/worker/phase-loop.js.map +1 -1
  138. package/dist/worker/pr-feedback-handler.d.ts +46 -46
  139. package/dist/worker/pr-feedback-handler.d.ts.map +1 -1
  140. package/dist/worker/pr-feedback-handler.js +276 -105
  141. package/dist/worker/pr-feedback-handler.js.map +1 -1
  142. package/dist/worker/pr-manager.d.ts +5 -0
  143. package/dist/worker/pr-manager.d.ts.map +1 -1
  144. package/dist/worker/pr-manager.js +7 -0
  145. package/dist/worker/pr-manager.js.map +1 -1
  146. package/dist/worker/product-diff.d.ts +39 -0
  147. package/dist/worker/product-diff.d.ts.map +1 -0
  148. package/dist/worker/product-diff.js +43 -0
  149. package/dist/worker/product-diff.js.map +1 -0
  150. package/dist/worker/provisioning-failure.d.ts +14 -0
  151. package/dist/worker/provisioning-failure.d.ts.map +1 -0
  152. package/dist/worker/provisioning-failure.js +2 -0
  153. package/dist/worker/provisioning-failure.js.map +1 -0
  154. package/dist/worker/repo-checkout.d.ts +14 -0
  155. package/dist/worker/repo-checkout.d.ts.map +1 -1
  156. package/dist/worker/repo-checkout.js +19 -1
  157. package/dist/worker/repo-checkout.js.map +1 -1
  158. package/dist/worker/stage-comment-manager.d.ts +42 -1
  159. package/dist/worker/stage-comment-manager.d.ts.map +1 -1
  160. package/dist/worker/stage-comment-manager.js +205 -1
  161. package/dist/worker/stage-comment-manager.js.map +1 -1
  162. package/dist/worker/terminal-label-op-error.d.ts +23 -0
  163. package/dist/worker/terminal-label-op-error.d.ts.map +1 -0
  164. package/dist/worker/terminal-label-op-error.js +27 -0
  165. package/dist/worker/terminal-label-op-error.js.map +1 -0
  166. package/dist/worker/types.d.ts +161 -2
  167. package/dist/worker/types.d.ts.map +1 -1
  168. package/dist/worker/types.js +11 -0
  169. package/dist/worker/types.js.map +1 -1
  170. package/dist/worker/validate-fix-handler.d.ts +79 -0
  171. package/dist/worker/validate-fix-handler.d.ts.map +1 -0
  172. package/dist/worker/validate-fix-handler.js +320 -0
  173. package/dist/worker/validate-fix-handler.js.map +1 -0
  174. package/dist/worker/worker-result.d.ts +39 -0
  175. package/dist/worker/worker-result.d.ts.map +1 -0
  176. package/dist/worker/worker-result.js +10 -0
  177. package/dist/worker/worker-result.js.map +1 -0
  178. package/package.json +6 -5
@@ -1,3 +1,11 @@
1
+ import { WORKFLOW_LABELS, classifyLabelProvisioningError } from '@generacy-ai/workflow-engine';
2
+ import { TerminalLabelOpError } from './terminal-label-op-error.js';
3
+ const WORKFLOW_LABEL_NAMES = new Set(WORKFLOW_LABELS.map((l) => l.name));
4
+ function extractStderr(error) {
5
+ if (error instanceof Error)
6
+ return error.message;
7
+ return String(error);
8
+ }
1
9
  /**
2
10
  * Manages label transitions on GitHub issues throughout the worker's phase loop.
3
11
  *
@@ -15,12 +23,42 @@ export class LabelManager {
15
23
  repo;
16
24
  issueNumber;
17
25
  logger;
18
- constructor(github, owner, repo, issueNumber, logger) {
26
+ clearResumeDedupe;
27
+ /**
28
+ * Per-process cache of repos whose workflow labels have been ensured.
29
+ * Key: `"owner/repo"`. Shared across every `LabelManager` instance in the
30
+ * process — one boundary ensure-pass per repo per process lifetime.
31
+ */
32
+ static ensuredRepos = new Set();
33
+ /**
34
+ * In-flight-Promise dedupe for concurrent first-callers on the same repo.
35
+ * Key: `"owner/repo"`. Ensures the ensure-pass runs at most once
36
+ * concurrently even if multiple issues in the same repo fire simultaneously.
37
+ */
38
+ static ensureInFlight = new Map();
39
+ /**
40
+ * Lineage map of classified provisioning failures — `"owner/repo"` → labelName → error.
41
+ *
42
+ * Written by the error branch of `ensureRepoLabelsExist` (per FR-008 / #916).
43
+ * Read by `addLabels` on apply-time 404 to enrich the thrown error's message
44
+ * with the provisioning cause so the operator sees inline what actually broke.
45
+ * Per-label entries evict when a subsequent ensure-pass succeeds or races on
46
+ * the same label; whole-repo clear happens on `resetEnsureCacheForTests`.
47
+ */
48
+ static provisioningFailures = new Map();
49
+ /** Test-only: reset the class-level memoization caches. */
50
+ static resetEnsureCacheForTests() {
51
+ LabelManager.ensuredRepos.clear();
52
+ LabelManager.ensureInFlight.clear();
53
+ LabelManager.provisioningFailures.clear();
54
+ }
55
+ constructor(github, owner, repo, issueNumber, logger, clearResumeDedupe) {
19
56
  this.github = github;
20
57
  this.owner = owner;
21
58
  this.repo = repo;
22
59
  this.issueNumber = issueNumber;
23
60
  this.logger = logger;
61
+ this.clearResumeDedupe = clearResumeDedupe;
24
62
  }
25
63
  /**
26
64
  * Called when a phase begins execution.
@@ -28,9 +66,10 @@ export class LabelManager {
28
66
  * Adds `phase:<current>` label and removes any previous `phase:*` labels.
29
67
  */
30
68
  async onPhaseStart(phase) {
69
+ const phaseLabel = `phase:${phase}`;
31
70
  await this.retryWithBackoff(async () => {
71
+ await this.ensureRepoLabelsExist();
32
72
  const currentLabels = await this.getCurrentPhaseLabels();
33
- const phaseLabel = `phase:${phase}`;
34
73
  // Remove any existing phase labels that aren't the new one
35
74
  const labelsToRemove = currentLabels.filter((l) => l !== phaseLabel);
36
75
  if (labelsToRemove.length > 0) {
@@ -39,8 +78,8 @@ export class LabelManager {
39
78
  }
40
79
  // Add the new phase label
41
80
  this.logger.info({ label: phaseLabel, issue: this.issueNumber }, `Adding phase label: ${phaseLabel}`);
42
- await this.github.addLabels(this.owner, this.repo, this.issueNumber, [phaseLabel]);
43
- });
81
+ await this.applyLabels([phaseLabel]);
82
+ }, { site: 'phase-start', labelOp: `addLabels([${phaseLabel}])` });
44
83
  }
45
84
  /**
46
85
  * Called when a phase completes successfully.
@@ -48,13 +87,14 @@ export class LabelManager {
48
87
  * Adds `completed:<current>` label and removes `phase:<current>` label.
49
88
  */
50
89
  async onPhaseComplete(phase) {
90
+ const phaseLabel = `phase:${phase}`;
91
+ const completedLabel = `completed:${phase}`;
51
92
  await this.retryWithBackoff(async () => {
52
- const phaseLabel = `phase:${phase}`;
53
- const completedLabel = `completed:${phase}`;
93
+ await this.ensureRepoLabelsExist();
54
94
  this.logger.info({ phase, issue: this.issueNumber }, `Phase complete: removing ${phaseLabel}, adding ${completedLabel}`);
55
95
  await this.github.removeLabels(this.owner, this.repo, this.issueNumber, [phaseLabel]);
56
- await this.github.addLabels(this.owner, this.repo, this.issueNumber, [completedLabel]);
57
- });
96
+ await this.applyLabels([completedLabel]);
97
+ }, { site: 'phase-complete', labelOp: `addLabels([${completedLabel}])` });
58
98
  }
59
99
  /**
60
100
  * Called when a gate is hit and the workflow must pause for human review.
@@ -62,19 +102,36 @@ export class LabelManager {
62
102
  * Adds `waiting-for:<gate>` and `agent:paused` labels, removes `phase:<current>`.
63
103
  */
64
104
  async onGateHit(phase, gateLabel) {
105
+ const phaseLabel = `phase:${phase}`;
106
+ const completedLabel = `completed:${phase}`;
65
107
  await this.retryWithBackoff(async () => {
66
- const phaseLabel = `phase:${phase}`;
67
- const completedLabel = `completed:${phase}`;
108
+ await this.ensureRepoLabelsExist();
68
109
  this.logger.info({ phase, gateLabel, issue: this.issueNumber }, `Gate hit: removing ${phaseLabel} and ${completedLabel}, adding ${gateLabel} and agent:paused`);
69
110
  await this.github.removeLabels(this.owner, this.repo, this.issueNumber, [
70
111
  phaseLabel,
71
112
  completedLabel,
72
113
  ]);
73
- await this.github.addLabels(this.owner, this.repo, this.issueNumber, [
74
- gateLabel,
75
- 'agent:paused',
76
- ]);
77
- });
114
+ await this.applyLabels([gateLabel, 'agent:paused']);
115
+ }, { site: 'gate-hit', labelOp: `addLabels([${gateLabel}, agent:paused])` });
116
+ // #849: clear paired resume:<gate> dedupe on successful pause.
117
+ // Best-effort — swallow failures so a Redis blip cannot fail the pause.
118
+ if (this.clearResumeDedupe) {
119
+ const gateSuffix = gateLabel.replace(/^waiting-for:/, '');
120
+ try {
121
+ await this.clearResumeDedupe(gateSuffix);
122
+ this.logger.info({ phase, gateLabel, owner: this.owner, repo: this.repo, issueNumber: this.issueNumber }, 'Cleared paired resume dedupe on pause');
123
+ }
124
+ catch (err) {
125
+ this.logger.warn({
126
+ err: String(err),
127
+ phase,
128
+ gateLabel,
129
+ owner: this.owner,
130
+ repo: this.repo,
131
+ issueNumber: this.issueNumber,
132
+ }, 'Failed to clear paired resume dedupe on pause (non-fatal)');
133
+ }
134
+ }
78
135
  }
79
136
  /**
80
137
  * Called when an error occurs during phase execution.
@@ -82,16 +139,17 @@ export class LabelManager {
82
139
  * Adds `agent:error` label and removes `phase:<current>`.
83
140
  */
84
141
  async onError(phase) {
142
+ const phaseLabel = `phase:${phase}`;
143
+ const failedLabel = `failed:${phase}`;
85
144
  await this.retryWithBackoff(async () => {
86
- const phaseLabel = `phase:${phase}`;
87
- const failedLabel = `failed:${phase}`;
145
+ await this.ensureRepoLabelsExist();
88
146
  this.logger.info({ phase, issue: this.issueNumber }, `Error in phase: removing ${phaseLabel} and agent:in-progress, adding ${failedLabel} and agent:error`);
89
147
  await this.github.removeLabels(this.owner, this.repo, this.issueNumber, [
90
148
  phaseLabel,
91
149
  'agent:in-progress',
92
150
  ]);
93
- await this.github.addLabels(this.owner, this.repo, this.issueNumber, [failedLabel, 'agent:error']);
94
- });
151
+ await this.applyLabels([failedLabel, 'agent:error']);
152
+ }, { site: 'error', labelOp: `addLabels([${failedLabel}, agent:error])` });
95
153
  }
96
154
  /**
97
155
  * Called when the entire workflow completes (all phases finished).
@@ -100,11 +158,12 @@ export class LabelManager {
100
158
  */
101
159
  async onWorkflowComplete() {
102
160
  await this.retryWithBackoff(async () => {
161
+ await this.ensureRepoLabelsExist();
103
162
  this.logger.info({ issue: this.issueNumber }, 'Workflow complete: removing agent:in-progress');
104
163
  await this.github.removeLabels(this.owner, this.repo, this.issueNumber, [
105
164
  'agent:in-progress',
106
165
  ]);
107
- });
166
+ }, { site: 'workflow-complete', labelOp: 'removeLabels([agent:in-progress])' });
108
167
  }
109
168
  /**
110
169
  * Called at the start of a resume (continue command) before the phase loop.
@@ -115,6 +174,7 @@ export class LabelManager {
115
174
  */
116
175
  async onResumeStart() {
117
176
  await this.retryWithBackoff(async () => {
177
+ await this.ensureRepoLabelsExist();
118
178
  const issue = await this.github.getIssue(this.owner, this.repo, this.issueNumber);
119
179
  const currentLabels = issue.labels.map((l) => typeof l === 'string' ? l : l.name);
120
180
  const labelsToRemove = currentLabels.filter((l) => l.startsWith('waiting-for:') || l === 'agent:paused');
@@ -136,8 +196,8 @@ export class LabelManager {
136
196
  }
137
197
  // Add agent:in-progress to reflect active workflow state
138
198
  this.logger.info({ issue: this.issueNumber }, 'Resume: adding agent:in-progress label');
139
- await this.github.addLabels(this.owner, this.repo, this.issueNumber, ['agent:in-progress']);
140
- });
199
+ await this.applyLabels(['agent:in-progress']);
200
+ }, { site: 'resume-start', labelOp: 'addLabels([agent:in-progress])' });
141
201
  }
142
202
  /**
143
203
  * Ensures `agent:in-progress` and any lingering `phase:*` labels are removed.
@@ -160,7 +220,7 @@ export class LabelManager {
160
220
  this.logger.info({ labels: labelsToRemove, issue: this.issueNumber }, 'Ensuring cleanup: removing agent:in-progress and phase labels');
161
221
  await this.retryWithBackoff(async () => {
162
222
  await this.github.removeLabels(this.owner, this.repo, this.issueNumber, labelsToRemove);
163
- });
223
+ }, { site: 'error', labelOp: `removeLabels(${JSON.stringify(labelsToRemove)})` });
164
224
  }
165
225
  }
166
226
  catch (error) {
@@ -168,6 +228,136 @@ export class LabelManager {
168
228
  this.logger.warn({ error: String(error), issue: this.issueNumber }, 'Failed to ensure label cleanup (non-fatal)');
169
229
  }
170
230
  }
231
+ /**
232
+ * Ensures every label in `WORKFLOW_LABELS` exists on the target repo.
233
+ *
234
+ * Memoized per-process, keyed on `"owner/repo"`. First caller on a given
235
+ * repo runs the pass; concurrent callers await the shared in-flight Promise;
236
+ * subsequent callers return immediately. This is the load-bearing safety net
237
+ * that catches labels not proactively provisioned by `LabelSyncService`.
238
+ */
239
+ async ensureRepoLabelsExist() {
240
+ const key = `${this.owner}/${this.repo}`;
241
+ if (LabelManager.ensuredRepos.has(key))
242
+ return;
243
+ const inFlight = LabelManager.ensureInFlight.get(key);
244
+ if (inFlight) {
245
+ await inFlight;
246
+ return;
247
+ }
248
+ const promise = (async () => {
249
+ let hadNonRaceFailure = false;
250
+ const succeededOrRaced = new Set();
251
+ const existing = await this.github.listLabels(this.owner, this.repo);
252
+ const existingNames = new Set(existing.map((l) => l.name));
253
+ const missing = WORKFLOW_LABELS.filter((l) => !existingNames.has(l.name));
254
+ for (const label of missing) {
255
+ try {
256
+ await this.github.createLabel(this.owner, this.repo, label.name, label.color, label.description);
257
+ this.logger.info({ label: label.name, owner: this.owner, repo: this.repo }, 'Created missing workflow label');
258
+ succeededOrRaced.add(label.name);
259
+ }
260
+ catch (err) {
261
+ const classification = classifyLabelProvisioningError(err);
262
+ if (classification.kind === 'already-exists') {
263
+ // Create-race with a sibling worker on the same repo is expected and
264
+ // safe — the label exists after our attempt regardless of who wrote
265
+ // it. Log at debug so healthy multi-worker startup does not spam warns.
266
+ this.logger.debug({
267
+ label: label.name,
268
+ owner: this.owner,
269
+ repo: this.repo,
270
+ err: String(err),
271
+ }, 'Workflow label already exists (race)');
272
+ succeededOrRaced.add(label.name);
273
+ }
274
+ else {
275
+ // Real provisioning failure (422 validation, 401 auth, 403 permission,
276
+ // 5xx). Log loud so the operator can act before the first apply 404s.
277
+ this.logger.error({
278
+ label: label.name,
279
+ owner: this.owner,
280
+ repo: this.repo,
281
+ err: String(err),
282
+ statusCode: classification.statusCode,
283
+ cause: classification.cause,
284
+ }, 'Failed to create workflow label (provisioning error)');
285
+ const repoMap = LabelManager.provisioningFailures.get(key) ?? new Map();
286
+ repoMap.set(label.name, {
287
+ cause: classification.cause,
288
+ statusCode: classification.statusCode,
289
+ classifiedAt: Date.now(),
290
+ });
291
+ LabelManager.provisioningFailures.set(key, repoMap);
292
+ hadNonRaceFailure = true;
293
+ }
294
+ }
295
+ }
296
+ // Clear stale lineage for labels that succeeded or raced in this pass —
297
+ // a subsequent successful/raced attempt supersedes the earlier failure.
298
+ const repoLineage = LabelManager.provisioningFailures.get(key);
299
+ if (repoLineage) {
300
+ for (const name of succeededOrRaced) {
301
+ repoLineage.delete(name);
302
+ }
303
+ if (repoLineage.size === 0) {
304
+ LabelManager.provisioningFailures.delete(key);
305
+ }
306
+ }
307
+ return { hadNonRaceFailure };
308
+ })();
309
+ // Share only the void-resolution shape with concurrent awaiters (Q3→A —
310
+ // the shared Promise resolves normally regardless of hadNonRaceFailure so
311
+ // one optional label's 422 does not fail every concurrent phase run).
312
+ LabelManager.ensureInFlight.set(key, promise.then(() => undefined));
313
+ try {
314
+ const { hadNonRaceFailure } = await promise;
315
+ if (!hadNonRaceFailure) {
316
+ LabelManager.ensuredRepos.add(key);
317
+ }
318
+ }
319
+ finally {
320
+ LabelManager.ensureInFlight.delete(key);
321
+ }
322
+ }
323
+ /**
324
+ * Wrap `github.addLabels` with lineage-map enrichment.
325
+ *
326
+ * On apply-time 404 for a label that failed provisioning in the same process,
327
+ * splice `label "<name>": <cause> (HTTP <statusCode>)` into the thrown error's
328
+ * message so the operator sees the provisioning cause inline instead of a
329
+ * bare 404. Cross-process gaps (map miss) rethrow the raw 404 unchanged —
330
+ * `ensureRepoLabelsExist`'s error log is the trace surface (FR-003 floor).
331
+ *
332
+ * All other error shapes rethrow unchanged.
333
+ */
334
+ async applyLabels(labels) {
335
+ try {
336
+ await this.github.addLabels(this.owner, this.repo, this.issueNumber, labels);
337
+ }
338
+ catch (err) {
339
+ const message = err instanceof Error ? err.message : String(err);
340
+ if (!/HTTP\s+404|Not\s+Found/.test(message))
341
+ throw err;
342
+ const key = `${this.owner}/${this.repo}`;
343
+ const repoLineage = LabelManager.provisioningFailures.get(key);
344
+ if (!repoLineage || repoLineage.size === 0)
345
+ throw err;
346
+ const enrichments = [];
347
+ for (const name of labels) {
348
+ if (!WORKFLOW_LABEL_NAMES.has(name))
349
+ continue;
350
+ const entry = repoLineage.get(name);
351
+ if (!entry)
352
+ continue;
353
+ const status = entry.statusCode !== undefined ? ` (HTTP ${entry.statusCode})` : '';
354
+ enrichments.push(`label "${name}": ${entry.cause}${status}`);
355
+ }
356
+ if (enrichments.length === 0)
357
+ throw err;
358
+ throw new Error(`${enrichments.join('\n')}\n${message}`);
359
+ }
360
+ }
171
361
  /**
172
362
  * Fetch current labels on the issue and return those matching the `phase:*` pattern.
173
363
  */
@@ -181,9 +371,12 @@ export class LabelManager {
181
371
  * Retry an async operation with exponential backoff.
182
372
  *
183
373
  * Attempts the operation up to 3 times with delays of 1000ms, 2000ms, and 4000ms
184
- * between attempts. The final attempt's error is re-thrown.
374
+ * between attempts. On final-attempt failure, throws `TerminalLabelOpError`
375
+ * carrying the `{ site, labelOp, ghStderr, cause }` context so callers can
376
+ * translate to `WorkerResult.status === 'failed-terminal'` without releasing
377
+ * the item back to the queue (#889 crash-loop fix).
185
378
  */
186
- async retryWithBackoff(fn) {
379
+ async retryWithBackoff(fn, context) {
187
380
  const maxAttempts = 3;
188
381
  const delays = [1000, 2000, 4000];
189
382
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
@@ -192,8 +385,13 @@ export class LabelManager {
192
385
  }
193
386
  catch (error) {
194
387
  if (attempt === maxAttempts) {
195
- this.logger.error({ attempt, error: String(error), issue: this.issueNumber }, `Label operation failed after ${maxAttempts} attempts`);
196
- throw error;
388
+ this.logger.error({ attempt, error: String(error), issue: this.issueNumber, site: context.site, labelOp: context.labelOp }, `Label operation failed after ${maxAttempts} attempts`);
389
+ throw new TerminalLabelOpError({
390
+ site: context.site,
391
+ labelOp: context.labelOp,
392
+ ghStderr: extractStderr(error),
393
+ cause: error,
394
+ });
197
395
  }
198
396
  const delay = delays[attempt - 1];
199
397
  this.logger.warn({ attempt, delay, error: String(error), issue: this.issueNumber }, `Label operation failed (attempt ${attempt}/${maxAttempts}), retrying in ${delay}ms`);
@@ -1 +1 @@
1
- {"version":3,"file":"label-manager.js","sourceRoot":"","sources":["../../src/worker/label-manager.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,YAAY;IAEJ;IACA;IACA;IACA;IACA;IALnB,YACmB,MAAoB,EACpB,KAAa,EACb,IAAY,EACZ,WAAmB,EACnB,MAAc;QAJd,WAAM,GAAN,MAAM,CAAc;QACpB,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAQ;QACZ,gBAAW,GAAX,WAAW,CAAQ;QACnB,WAAM,GAAN,MAAM,CAAQ;IAC9B,CAAC;IAEJ;;;;OAIG;IACH,KAAK,CAAC,YAAY,CAAC,KAAoB;QACrC,MAAM,IAAI,CAAC,gBAAgB,CAAC,KAAK,IAAI,EAAE;YACrC,MAAM,aA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AAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC"}
@@ -0,0 +1,141 @@
1
+ import type { QueueItem } from '../types/index.js';
2
+ import type { Logger } from './types.js';
3
+ import type { WorkerConfig } from './config.js';
4
+ import type { SSEEventEmitter } from './output-capture.js';
5
+ import type { AgentLauncher } from '../launcher/agent-launcher.js';
6
+ import type { HandlerOutcome } from './handler-outcome.js';
7
+ /**
8
+ * Evidence emitted when the agent-CLI attempt fails to produce a conflict-
9
+ * free committed merge (FR-009).
10
+ */
11
+ export interface BlockedStuckMergeConflictsEvidence {
12
+ /** Paths that still had conflict markers after the agent-CLI attempt. */
13
+ unresolvedPaths: string[];
14
+ /**
15
+ * Paths the agent successfully resolved (staged, no markers).
16
+ * Empty if the agent produced no diff at all.
17
+ */
18
+ partiallyResolvedPaths: string[];
19
+ /** Base ref that was being merged. */
20
+ baseRef: string;
21
+ /** Short SHA of the branch tip at attempt time. */
22
+ branchTipSha: string;
23
+ /** ISO timestamp of the attempt. */
24
+ attemptedAt: string;
25
+ /** Optional short human-readable reason (e.g., "no linked PR"). */
26
+ reason?: string;
27
+ }
28
+ /**
29
+ * Handles the `resolve-merge-conflicts` command per #898.
30
+ *
31
+ * Processing flow (see `handler-contract.md` §"Flow"):
32
+ * 1-3. Parse item, create GitHub client, resolve PR via PrLinker.
33
+ * 4. switchBranch with 3× retry.
34
+ * 5. resolveBaseBranch (reuses #864 helper).
35
+ * 6-7. fetch + merge origin/<base> with 3× retry. No-op merge → immediate success.
36
+ * 8. Enumerate conflicted paths.
37
+ * 9-10.Enumerate open PRs targeting same base, cache file lists.
38
+ * 11. Build MergeConflictIntent prompt via buildMergeConflictPrompt.
39
+ * 12. agentLauncher.launch EXACTLY ONCE.
40
+ * 13. Success predicate: no MERGE_HEAD, no unresolved paths, no conflict markers.
41
+ * 14. git push origin <branch> with 3× retry (network only; NFF is a hard fail).
42
+ * 15. On success: apply completed:merge-conflicts + remove waiting-for + agent:paused.
43
+ * 17. On block: apply blocked:stuck-merge-conflicts, leave waiting-for in place,
44
+ * emit evidence block, return normally.
45
+ */
46
+ export declare class MergeConflictHandler {
47
+ private readonly config;
48
+ private readonly logger;
49
+ private readonly agentLauncher;
50
+ private readonly sseEmitter?;
51
+ private readonly repoCheckout;
52
+ private readonly prLinker;
53
+ constructor(config: WorkerConfig, logger: Logger, agentLauncher: AgentLauncher, sseEmitter?: SSEEventEmitter | undefined);
54
+ /**
55
+ * Process a merge-conflict resolution task (#902 FR-005 return type).
56
+ *
57
+ * Returns a `HandlerOutcome` — the dispatcher (via `ClaudeCliWorker.handle`)
58
+ * routes on the discriminant to decide re-arm vs failed-terminal.
59
+ *
60
+ * Success/no-op/push-succeeded → `re-armed` with `startPhase` from
61
+ * `metadata.phase`. Blocked branches → `failed` with evidence. Missing
62
+ * `metadata.phase` at a would-be `re-armed` return → fail-loud path
63
+ * (FR-004): applies `blocked:stuck-merge-conflicts`, returns `failed` with
64
+ * evidence citing the missing pause-context.
65
+ */
66
+ handle(item: QueueItem, checkoutPath: string): Promise<HandlerOutcome>;
67
+ /**
68
+ * Enumerate open PRs targeting `baseName` (excluding the target issue's own PR)
69
+ * and build a Map<path, prNumber[]> of files each sibling PR touches.
70
+ *
71
+ * Uses `gh pr view <number> --json files` per sibling (call site is bounded
72
+ * to the poll cycle, per handler-contract §Observability). Missing files
73
+ * data is treated as an empty set.
74
+ */
75
+ private enumerateSiblingFileMap;
76
+ /**
77
+ * `gh pr view <number> --json files` on the local checkout. Called
78
+ * per-sibling; failures are non-fatal (the scope guard degrades to
79
+ * "no siblings" for that PR, which is safer than throwing).
80
+ */
81
+ private fetchPrFiles;
82
+ /**
83
+ * Success predicate (handler-contract §"Success predicate"):
84
+ * - `.git/MERGE_HEAD` does NOT exist (merge is complete)
85
+ * - `git diff --name-only --diff-filter=U` is empty (no unresolved paths)
86
+ * - No file in the tree contains `<<<<<<< ` at line-start (belt & suspenders)
87
+ */
88
+ private verifyMergeResolved;
89
+ private listUnresolvedPaths;
90
+ /**
91
+ * Best-effort scan for the `<<<<<<< ` conflict marker at line start across
92
+ * tracked files. Uses `git ls-files` to enumerate, then reads each file
93
+ * synchronously (bounded — small worker workloads).
94
+ */
95
+ private scanForConflictMarkers;
96
+ /**
97
+ * `git push origin <branch>` with 3× retry on transient network errors.
98
+ * Non-fast-forward rejection does NOT retry — it escalates to blocked.
99
+ * On success, applies the combined label cleanup and returns re-armed.
100
+ */
101
+ private pushAndSucceed;
102
+ /**
103
+ * Success-terminal branch (#902 FR-001, FR-004, FR-007).
104
+ *
105
+ * - FR-001: consume `completed:merge-conflicts` and clear `agent:in-progress` /
106
+ * `agent:paused` residue so the next natural conflict pause is not
107
+ * insta-resumed by the generic pair path.
108
+ * - FR-004: fail-loud if `metadata.phase` is missing — never re-derive from
109
+ * labels. Applies `blocked:stuck-merge-conflicts`, returns `failed` with
110
+ * evidence citing the missing pause-context.
111
+ * - FR-007: one combined `gh issue edit --remove-label …` invocation (via
112
+ * `github.removeLabels` which already batches removes into a single call).
113
+ */
114
+ private finishSuccess;
115
+ /**
116
+ * #902 FR-007: single combined `gh issue edit --remove-label …` for all four
117
+ * ownership-transition removes. No adds — re-arm is direct enqueue, not a
118
+ * resume-pair, so no `waiting-for:<gate>` / `completed:<gate>` labels are
119
+ * needed. The next `continue` item's normal in-progress labels are applied
120
+ * by `LabelManager.onResumeStart` when the phase loop enters.
121
+ *
122
+ * `github.removeLabels` batches all four `--remove-label` flags into one
123
+ * `gh issue edit` invocation — one HTTP round-trip, atomic at the label-set
124
+ * level (per contracts/handler-outcome.md §"Label edit shape").
125
+ */
126
+ private applySuccessDisposition;
127
+ private applyBlockedDisposition;
128
+ /**
129
+ * Spawn the agent CLI with a MergeConflictIntent. Runs at most once
130
+ * (Q4 → D). Returns true if the CLI exited 0, false otherwise.
131
+ */
132
+ private spawnAgentForConflict;
133
+ private retry;
134
+ private isTransientGitError;
135
+ private isTransientNetworkError;
136
+ private isNonFastForward;
137
+ private baseIsAncestor;
138
+ private getBranchTipSha;
139
+ private sleep;
140
+ }
141
+ //# sourceMappingURL=merge-conflict-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-conflict-handler.d.ts","sourceRoot":"","sources":["../../src/worker/merge-conflict-handler.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,SAAS,EAAiC,MAAM,mBAAmB,CAAC;AAClF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AA8B3D;;;GAGG;AACH,MAAM,WAAW,kCAAkC;IACjD,yEAAyE;IACzE,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B;;;OAGG;IACH,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,YAAY,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,oBAAoB;IAK7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;IAP9B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;gBAGjB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,aAA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