lastlight-core 0.22.0 → 0.23.1

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 (103) hide show
  1. package/config/default.yaml +70 -2
  2. package/dist/config/config.d.ts +35 -0
  3. package/dist/config/config.js +152 -3
  4. package/dist/config/config.js.map +1 -1
  5. package/dist/config/repo-config.d.ts +7 -0
  6. package/dist/config/repo-config.js +15 -0
  7. package/dist/config/repo-config.js.map +1 -1
  8. package/dist/connectors/github-webhook.d.ts +17 -0
  9. package/dist/connectors/github-webhook.js +150 -17
  10. package/dist/connectors/github-webhook.js.map +1 -1
  11. package/dist/connectors/types.d.ts +48 -1
  12. package/dist/cron/dependabot-discovery.d.ts +68 -11
  13. package/dist/cron/dependabot-discovery.js +78 -20
  14. package/dist/cron/dependabot-discovery.js.map +1 -1
  15. package/dist/cron/jobs.d.ts +4 -0
  16. package/dist/cron/jobs.js +38 -4
  17. package/dist/cron/jobs.js.map +1 -1
  18. package/dist/cron/review-discovery.d.ts +33 -20
  19. package/dist/cron/review-discovery.js +23 -30
  20. package/dist/cron/review-discovery.js.map +1 -1
  21. package/dist/engine/agent-executor.d.ts +1 -1
  22. package/dist/engine/agent-executor.js +1 -1
  23. package/dist/engine/agent-executor.js.map +1 -1
  24. package/dist/engine/dispatcher.d.ts +98 -1
  25. package/dist/engine/dispatcher.js +248 -231
  26. package/dist/engine/dispatcher.js.map +1 -1
  27. package/dist/engine/executors/shared.d.ts +43 -0
  28. package/dist/engine/executors/shared.js +65 -0
  29. package/dist/engine/executors/shared.js.map +1 -1
  30. package/dist/engine/fix-harvest.d.ts +169 -0
  31. package/dist/engine/fix-harvest.js +345 -0
  32. package/dist/engine/fix-harvest.js.map +1 -0
  33. package/dist/engine/fix-markers.d.ts +184 -0
  34. package/dist/engine/fix-markers.js +329 -0
  35. package/dist/engine/fix-markers.js.map +1 -0
  36. package/dist/engine/fix-scratch.d.ts +76 -0
  37. package/dist/engine/fix-scratch.js +77 -0
  38. package/dist/engine/fix-scratch.js.map +1 -0
  39. package/dist/engine/github/github.d.ts +212 -5
  40. package/dist/engine/github/github.js +481 -54
  41. package/dist/engine/github/github.js.map +1 -1
  42. package/dist/engine/pr-decisions.d.ts +342 -0
  43. package/dist/engine/pr-decisions.js +721 -0
  44. package/dist/engine/pr-decisions.js.map +1 -0
  45. package/dist/engine/pr-escalation.d.ts +152 -0
  46. package/dist/engine/pr-escalation.js +320 -0
  47. package/dist/engine/pr-escalation.js.map +1 -0
  48. package/dist/engine/pr-notes.d.ts +175 -0
  49. package/dist/engine/pr-notes.js +315 -0
  50. package/dist/engine/pr-notes.js.map +1 -0
  51. package/dist/engine/pr-state.d.ts +313 -0
  52. package/dist/engine/pr-state.js +515 -0
  53. package/dist/engine/pr-state.js.map +1 -0
  54. package/dist/engine/review-check.d.ts +200 -0
  55. package/dist/engine/review-check.js +305 -0
  56. package/dist/engine/review-check.js.map +1 -0
  57. package/dist/engine/router.d.ts +27 -0
  58. package/dist/engine/router.js +156 -22
  59. package/dist/engine/router.js.map +1 -1
  60. package/dist/evals-api.d.ts +7 -0
  61. package/dist/evals-api.js +30 -0
  62. package/dist/evals-api.js.map +1 -1
  63. package/dist/index.js +268 -20
  64. package/dist/index.js.map +1 -1
  65. package/dist/sandbox/index.d.ts +13 -0
  66. package/dist/sandbox/index.js +30 -0
  67. package/dist/sandbox/index.js.map +1 -1
  68. package/dist/sandbox/k8s/init-clone.d.ts +5 -0
  69. package/dist/sandbox/k8s/init-clone.js +27 -0
  70. package/dist/sandbox/k8s/init-clone.js.map +1 -1
  71. package/dist/state/execution-store.d.ts +27 -0
  72. package/dist/state/execution-store.js +45 -0
  73. package/dist/state/execution-store.js.map +1 -1
  74. package/dist/state/workflow-run-store.d.ts +73 -0
  75. package/dist/state/workflow-run-store.js +106 -24
  76. package/dist/state/workflow-run-store.js.map +1 -1
  77. package/dist/workflows/pr-scope.d.ts +63 -0
  78. package/dist/workflows/pr-scope.js +113 -0
  79. package/dist/workflows/pr-scope.js.map +1 -0
  80. package/dist/workflows/resume.js +17 -4
  81. package/dist/workflows/resume.js.map +1 -1
  82. package/dist/workflows/simple.d.ts +94 -1
  83. package/dist/workflows/simple.js +206 -3
  84. package/dist/workflows/simple.js.map +1 -1
  85. package/dist/workflows/target-policy.d.ts +0 -12
  86. package/dist/workflows/target-policy.js +9 -15
  87. package/dist/workflows/target-policy.js.map +1 -1
  88. package/package.json +4 -4
  89. package/skills/README.md +11 -5
  90. package/skills/dependency-impact/SKILL.md +83 -0
  91. package/skills/fixing/SKILL.md +194 -0
  92. package/skills/pr-comment/SKILL.md +4 -1
  93. package/skills/pr-review/SKILL.md +26 -9
  94. package/workflows/cron-dependabot-ci-fix.yaml +8 -5
  95. package/workflows/cron-review.yaml +14 -5
  96. package/workflows/dependabot-ci-fix.yaml +86 -2
  97. package/workflows/dependabot-pr-merge.yaml +13 -1
  98. package/workflows/pr-fix.yaml +84 -1
  99. package/workflows/pr-review.yaml +7 -0
  100. package/workflows/prompts/dependabot-ci-fix.md +70 -17
  101. package/workflows/prompts/dependabot-pr-merge.md +209 -81
  102. package/workflows/prompts/diagnose-ci.md +96 -0
  103. package/workflows/prompts/pr-fix.md +63 -4
@@ -0,0 +1,515 @@
1
+ /**
2
+ * The PR state machine — one resolved snapshot per dispatch.
3
+ *
4
+ * Before this module, what the harness "knew" about a pull request was read
5
+ * from six sites (`dependencyDedupSkip`, `handlePrFix`, `dispatchWorkflow`,
6
+ * `review-discovery`, and both dependency cron sweeps), each fetching an
7
+ * overlapping subset and each free to disagree — while the state itself lived
8
+ * across seven stores (GitHub labels, the `last-light/review` check run, run
9
+ * `context`, run `scratch`, execution status, live GitHub reads, and a file in
10
+ * the sandbox workspace). Three shipped-defect-grade bugs fell out of that; see
11
+ * `docs/plans/dependency-pr-resilience/09-state-machine.md`.
12
+ *
13
+ * The fix is structural, not incremental: **resolve the PR's state once, then
14
+ * decide**. `resolvePrState` is the only place that reads it; every policy
15
+ * question is a PURE function over the result (`../engine/pr-decisions.ts`), so
16
+ * the decisions are table-testable against literal fixtures with no GitHub mock
17
+ * and no sandbox.
18
+ *
19
+ * {@link PrState} is therefore the documentation of the state machine: it can be
20
+ * read, reviewed and diffed, which prose across ten documents cannot.
21
+ */
22
+ import { PR_FIX_SHAPED_WORKFLOWS } from "../workflows/target-policy.js";
23
+ import { prScopedWorkflows } from "../workflows/pr-scope.js";
24
+ import { REQUIRES_HUMAN_LABEL } from "../cron/dependabot-discovery.js";
25
+ import { readHarvestedMarkers } from "./fix-harvest.js";
26
+ import { ATTEMPT_FREE_CLASSES, boundAttemptLines, renderAttemptLine, } from "./fix-markers.js";
27
+ import { boundNotes, coerceNotes, markNotesStale } from "./pr-notes.js";
28
+ /**
29
+ * Every PR-scoped workflow — the span of the run lock (09 → S4).
30
+ *
31
+ * Re-exported from `../workflows/pr-scope.ts`, which derives it from each
32
+ * workflow's own `pr_scoped: true` metadata rather than from a hardcoded list
33
+ * of four names the operator is free to route around. The argument for both the
34
+ * span and the derivation lives there; every reader inside the PR state machine
35
+ * reaches for it through this module.
36
+ */
37
+ export { prScopedWorkflows } from "../workflows/pr-scope.js";
38
+ /** The trigger id every PR-scoped run and ledger row is keyed by. */
39
+ export function prTriggerId(repo, prNumber) {
40
+ return `${repo}#${prNumber}`;
41
+ }
42
+ /** The App slug behind a `<slug>[bot]` login. */
43
+ function appSlug(deps) {
44
+ const slug = deps.botName || deps.botLogin.replace(/\[bot\]$/, "");
45
+ return slug || undefined;
46
+ }
47
+ /**
48
+ * Resolve the whole snapshot. Called ONCE per dispatch, at the
49
+ * `dispatchWorkflow` choke point every route crosses.
50
+ *
51
+ * Never throws. Every live read is independently best-effort; a failure records
52
+ * a line in {@link PrState.readErrors} and leaves the field at a value that
53
+ * cannot itself cause a skip.
54
+ */
55
+ export async function resolvePrState(owner, repo, prNumber, deps) {
56
+ const full = `${owner}/${repo}`;
57
+ const readErrors = [];
58
+ const note = (what, err) => {
59
+ const msg = err instanceof Error ? err.message : String(err);
60
+ readErrors.push(`${what}: ${msg}`);
61
+ console.warn(`[pr-state] ${full}#${prNumber} ${what} failed: ${msg}`);
62
+ };
63
+ const state = {
64
+ repo: full,
65
+ prNumber,
66
+ headSha: "",
67
+ headAuthor: "",
68
+ headIsOurs: false,
69
+ headRef: "",
70
+ baseRef: "",
71
+ isDraft: false,
72
+ isFork: false,
73
+ headRepoFullName: null,
74
+ labels: [],
75
+ title: "",
76
+ body: "",
77
+ checksState: "none",
78
+ settledCheckCount: 0,
79
+ baseChecksState: "none",
80
+ botReviewAtHead: null,
81
+ ciReport: null,
82
+ attempt: 1,
83
+ flakyDeferrals: 0,
84
+ escalatedAtSha: null,
85
+ escalatedBy: null,
86
+ forkNoticedAtSha: null,
87
+ priorAttempts: [],
88
+ notes: [],
89
+ priorDiagnosisClass: null,
90
+ cumulativeCostUsd: 0,
91
+ costBaselineUsd: 0,
92
+ assessedHeadShaByWorkflow: {},
93
+ runInFlight: null,
94
+ readErrors,
95
+ };
96
+ const github = deps.github;
97
+ if (github) {
98
+ try {
99
+ const pr = await github.getPullRequest(owner, repo, prNumber);
100
+ state.headSha = pr.head?.sha ?? "";
101
+ state.headRef = pr.head?.ref ?? "";
102
+ state.baseRef = pr.base?.ref ?? "";
103
+ state.isDraft = !!pr.draft;
104
+ state.title = pr.title ?? "";
105
+ state.body = pr.body ?? "";
106
+ state.labels = (pr.labels ?? [])
107
+ .map((l) => (typeof l === "string" ? l : l?.name ?? ""))
108
+ .filter(Boolean);
109
+ // `head.repo` is null when the source fork was deleted; the branch is
110
+ // gone either way, so treat it as a fork.
111
+ state.headRepoFullName = pr.head?.repo?.full_name ?? null;
112
+ const baseRepoFullName = pr.base?.repo?.full_name ?? full;
113
+ state.isFork =
114
+ state.headRepoFullName === null || state.headRepoFullName !== baseRepoFullName;
115
+ }
116
+ catch (err) {
117
+ note("getPullRequest", err);
118
+ }
119
+ // Everything below needs the head SHA / base ref the PR read produced. When
120
+ // that read failed there is nothing to point them at, and issuing them
121
+ // against an empty ref would 404 four more times for no information.
122
+ if (state.headSha) {
123
+ // Both check reads gate DISPATCH, so neither may see our own review
124
+ // check: a `last-light/review` sitting queued/in-progress would pin the
125
+ // aggregate at `pending`, and `pending` is a skip in `mayMerge`,
126
+ // `resolveMergeDisposition` and `resolveReviewTrigger` alike — the review
127
+ // would be waiting on itself (07 §7.2).
128
+ const checkOpts = { excludeApp: appSlug(deps) };
129
+ const [summary, baseState, review, author] = await Promise.all([
130
+ github
131
+ .getChecksSummary(owner, repo, state.headSha, checkOpts)
132
+ .catch((err) => {
133
+ note("getChecksSummary", err);
134
+ return null;
135
+ }),
136
+ state.baseRef
137
+ ? github.getBaseChecksState(owner, repo, state.baseRef, checkOpts).catch((err) => {
138
+ note("getBaseChecksState", err);
139
+ // "none" and not "failing": a base we could not read must never
140
+ // be reported as upstream-broken, which would skip the fix.
141
+ return "none";
142
+ })
143
+ : Promise.resolve("none"),
144
+ github
145
+ .getLatestBotReview(owner, repo, prNumber, state.headSha, deps.botLogin)
146
+ .catch((err) => {
147
+ note("getLatestBotReview", err);
148
+ // null = "not reviewed", which dispatches a review rather than
149
+ // suppressing one. `post-review` is itself idempotent per head SHA.
150
+ return null;
151
+ }),
152
+ github.getCommitAuthorName(owner, repo, state.headSha).catch((err) => {
153
+ note("getCommitAuthorName", err);
154
+ return "";
155
+ }),
156
+ ]);
157
+ if (summary) {
158
+ state.checksState = summary.state;
159
+ state.settledCheckCount = summary.settledCount;
160
+ }
161
+ state.baseChecksState = baseState;
162
+ state.botReviewAtHead = review ? { state: review.state } : null;
163
+ state.headAuthor = author;
164
+ state.headIsOurs = !!deps.botLogin && author === deps.botLogin;
165
+ // The heavy read (one Actions job-log download per failed check) only
166
+ // when there is a failure to explain. Phase 1's `logsAvailable` flag
167
+ // rides along so the prompt can say the evidence degraded.
168
+ //
169
+ // `checkOpts` for the same reason the reads above take it, one step
170
+ // further on: `concludeReviewCheck` writes `conclusion: "failure"` for a
171
+ // CHANGES_REQUESTED review, so without it our own reviewer's verdict is
172
+ // picked up as a failed check and handed to the fix agent as CI evidence
173
+ // to fix.
174
+ if (state.checksState === "failing") {
175
+ state.ciReport = await github
176
+ .getCiFailureReport(owner, repo, state.headSha, checkOpts)
177
+ .catch((err) => {
178
+ note("getCiFailureReport", err);
179
+ return null;
180
+ });
181
+ }
182
+ }
183
+ }
184
+ applyDerivedState(state, deps);
185
+ return state;
186
+ }
187
+ /**
188
+ * Fill the derived half from our own run history.
189
+ *
190
+ * Split out (and exported) because it is a pure-ish function of the DB: a test
191
+ * can hand it a literal live half plus a fake store and assert the attempt
192
+ * table without touching GitHub.
193
+ */
194
+ export function applyDerivedState(state, deps) {
195
+ const family = [...PR_FIX_SHAPED_WORKFLOWS];
196
+ const prScoped = [...prScopedWorkflows()];
197
+ const triggerId = prTriggerId(state.repo, state.prNumber);
198
+ const inFlight = deps.db.runs.activeForTrigger(prScoped, triggerId);
199
+ state.runInFlight = inFlight ? { workflow: inFlight.workflowName, runId: inFlight.id } : null;
200
+ const lifetimeCostUsd = deps.db.executions.costForTriggerWorkflows(triggerId, family);
201
+ const succeeded = deps.db.runs.latestSucceededForTriggers(prScoped, triggerId);
202
+ state.assessedHeadShaByWorkflow = {};
203
+ for (const [name, run] of Object.entries(succeeded)) {
204
+ const sha = priorPrState(run.context)?.headSha;
205
+ if (typeof sha === "string" && sha)
206
+ state.assessedHeadShaByWorkflow[name] = sha;
207
+ }
208
+ const prior = deps.db.runs.latestForTrigger(family, triggerId);
209
+ const priorState = priorPrState(prior?.context);
210
+ // The prior run's HARVEST — what its agent actually concluded, read back off
211
+ // the same row. `context.prState` is written at dispatch, before any phase
212
+ // runs, so the post-hoc facts live on `scratch` (see `./fix-harvest.ts`).
213
+ const priorMarkers = prior ? readHarvestedMarkers(prior) : null;
214
+ // The widest prior run of ours on this PR — every PR-SCOPED workflow, not
215
+ // just the fix family, because it is keyed on the PR (10-pr-memory.md). Two
216
+ // things read it: the journal (a `pr-review` between two fix attempts carries
217
+ // the accumulation forward and may have added to it) and the escalation
218
+ // record, which has to answer "have we ever touched this PR at all" and would
219
+ // get the wrong answer from the fix family alone. Falls back to the
220
+ // fix-family row when there is no wider one.
221
+ const priorAny = deps.db.runs.latestForTrigger(prScoped, triggerId) ?? prior;
222
+ const priorAnyState = priorPrState(priorAny?.context);
223
+ applyEscalationRecord(state, priorState, priorAny, priorAnyState);
224
+ state.notes = deriveNotes(state, priorAny, priorAnyState);
225
+ // The fork-PR notice's dedup, carried forward off the WIDEST prior row for
226
+ // the same reason the escalation record is: `noticeForkPr` records under
227
+ // whichever workflow was dispatching. Never invalidated by a push — see the
228
+ // field's own doc.
229
+ state.forkNoticedAtSha =
230
+ (typeof priorState?.forkNoticedAtSha === "string" ? priorState.forkNoticedAtSha : null) ??
231
+ (typeof priorAnyState?.forkNoticedAtSha === "string" ? priorAnyState.forkNoticedAtSha : null);
232
+ // The cost WINDOW, on the same boundary the attempt counter uses. `sameProblem`
233
+ // is the whole definition: while it holds we carry the prior run's baseline,
234
+ // and when someone else pushes we re-stamp it to the lifetime total so the
235
+ // fresh problem starts at zero — which is exactly what makes a maintainer's
236
+ // push re-arm the budget the way it already re-armed the attempt counter.
237
+ const freshProblem = !sameProblem(state, priorState);
238
+ const priorBaseline = typeof priorState?.costBaselineUsd === "number" ? priorState.costBaselineUsd : 0;
239
+ state.costBaselineUsd = freshProblem ? lifetimeCostUsd : priorBaseline;
240
+ // `max(0, …)` for the one case that can go negative: a run row written before
241
+ // this field existed carries no baseline, so a PR mid-flight at upgrade reads
242
+ // 0 and gets its full lifetime spend — correct — while a later re-stamp can
243
+ // only ever move the baseline forward.
244
+ state.cumulativeCostUsd = Math.max(0, lifetimeCostUsd - state.costBaselineUsd);
245
+ const history = deriveAttemptHistory(state, priorState, priorMarkers, prior ? didSpendAttempt(prior, deps) : false);
246
+ state.attempt = history.attempt;
247
+ state.priorAttempts = history.priorAttempts;
248
+ state.flakyDeferrals = history.flakyDeferrals;
249
+ state.priorDiagnosisClass = history.priorDiagnosisClass;
250
+ }
251
+ /**
252
+ * Whose `requires-human` is this, and at which head did we put it there?
253
+ *
254
+ * The two fields resolve together because they are one answer, and splitting
255
+ * them is how they come to contradict each other.
256
+ *
257
+ * `requires-human` is a NOTIFICATION (09 → S1). The STATE is "**we** escalated
258
+ * at head SHA X", because that is the only form a later push can invalidate —
259
+ * which is what distinguishes a bot escalation (cleared by the next human push,
260
+ * with no label to remove by hand) from a maintainer applying the label to mean
261
+ * "bot, stay out" (a permanent override we must honour).
262
+ *
263
+ * `escalatedAtSha` is written by `./pr-escalation.ts` and by nothing else — but
264
+ * `escalatePr` is not the only way OUR label reaches a pull request, and the two
265
+ * other routes leave it on with no SHA behind it:
266
+ *
267
+ * 1. **The agent applies it mid-run.** The packaged prompts instruct it to —
268
+ * `prompts/dependabot-ci-fix.md` when it cannot land the PR, and
269
+ * `prompts/dependabot-pr-merge.md` for a FUNCTIONAL bump, by design.
270
+ * `context.prState` is written at DISPATCH, before any phase runs, and is
271
+ * never rewritten, so however correct that label is, the run persists no
272
+ * escalation record.
273
+ * 2. **The row predates this module.** Every PR already carrying the label at
274
+ * upgrade has run rows with no `prState` at all.
275
+ *
276
+ * Under a bare `escalatedAtSha ? "us" : "human"` test both read as a
277
+ * MAINTAINER's permanent hold: the bot mistaking its own label for a "stay
278
+ * out", which is the exact one-way door 09 → S1 set out to remove — and case 2
279
+ * does it to every already-labelled PR at once, on upgrade.
280
+ *
281
+ * So the discriminator is not the SHA but **whether any run of ours has ever
282
+ * touched this PR**. A label on a PR no run of ours has ever seen can only be a
283
+ * maintainer's; that is the hard permanent override, and it is preserved
284
+ * exactly. A label on a PR we have worked is ours. Misreading in this direction
285
+ * costs at most further dispatches on a PR already bounded by
286
+ * `fix.maxAttempts` and `fix.maxCostUsd`; misreading it the other way is
287
+ * permanent and needs a human to un-stick each PR by hand.
288
+ *
289
+ * When we conclude `"us"` with no recorded SHA, the prior run's head stands in
290
+ * for it — that IS the head we were at when the label landed. Without it
291
+ * `resolveFixDisposition`'s "same problem" test would compare against null, so
292
+ * a bot that had just said "a human must look at this" would keep re-attempting
293
+ * until the budget ran out, and `dependabot-pr-merge` would re-label and
294
+ * re-comment a functional bump on every event.
295
+ */
296
+ function applyEscalationRecord(state, prior, priorAny, priorAnyState) {
297
+ // Carried forward off the prior run's context, so the stateful guard costs no
298
+ // new storage, no extra API call and no label mutation (09 → S1). Read from
299
+ // the fix family first and the wider PR-scoped row second: `escalatePr` records
300
+ // under whichever workflow was dispatching, which may be `dependabot-pr-merge`
301
+ // or `pr-review`.
302
+ const recorded = prior?.escalatedAtSha ?? priorAnyState?.escalatedAtSha ?? null;
303
+ state.escalatedAtSha = recorded;
304
+ if (!state.labels.includes(REQUIRES_HUMAN_LABEL)) {
305
+ state.escalatedBy = null;
306
+ return;
307
+ }
308
+ if (!priorAny) {
309
+ // No run of ours has ever touched this PR, so nobody but a maintainer can
310
+ // have applied the label. The one case the whole distinction exists for.
311
+ state.escalatedBy = "human";
312
+ return;
313
+ }
314
+ state.escalatedBy = "us";
315
+ state.escalatedAtSha = recorded ?? priorAnyState?.headSha ?? null;
316
+ }
317
+ /**
318
+ * Fold the PR's journal forward: what the prior run carried, plus what its own
319
+ * agent wrote, capped — and marked stale when the world moved under it.
320
+ *
321
+ * Deliberately NOT part of {@link deriveAttemptHistory}, and the reason is the
322
+ * one interesting thing about this function. Those three fields move together
323
+ * because a fresh problem CLEARS all three; the journal does not clear. 09 → S1's
324
+ * third row (a head SHA change authored by someone else) is still the boundary
325
+ * that matters, but here it MARKS rather than deletes: a claim about the old
326
+ * head is not evidence about the new one, yet "attempt 1 believed the lockfile
327
+ * was stale" is still worth a later run seeing, and deleting it silently would
328
+ * be indistinguishable from never having written it. Staleness is sticky —
329
+ * `markNotesStale` never unsets — because a second push does not re-validate
330
+ * what the first invalidated.
331
+ *
332
+ * Both sources are re-sanitized on the way through (`coerceNotes`), so a row
333
+ * written by an older build cannot carry a note past today's rejection rules.
334
+ */
335
+ function deriveNotes(state, priorRun, prior) {
336
+ const carried = coerceNotes(prior?.notes);
337
+ const harvested = coerceNotes(priorRun ? readHarvestedMarkers(priorRun)?.notes : null);
338
+ const merged = boundNotes([...carried, ...harvested]);
339
+ return sameProblem(state, prior) ? merged : markNotesStale(merged);
340
+ }
341
+ /**
342
+ * Fold one finished run into the PR's retry history.
343
+ *
344
+ * The three fields move TOGETHER and are derived in one place for that reason:
345
+ * `attempt`, the journal replayed as `{{priorAttempts}}`, and the consecutive-
346
+ * `flaky` counter all answer the same question — "what has happened to THIS
347
+ * PROBLEM so far" — and a partial update is how they drift apart. The clearest
348
+ * symptom of deriving them separately: a maintainer's push resets `attempt` to
349
+ * 1 while `{{priorAttempts}}` still narrates attempts 1–3, so the prompt tells
350
+ * the agent it is on attempt 1 and then recounts three of them.
351
+ *
352
+ * So a FRESH PROBLEM clears all three at once. Everything else appends the
353
+ * prior run's rendered line and advances (or does not advance) the counter.
354
+ */
355
+ function deriveAttemptHistory(state, prior, priorMarkers, priorSpent) {
356
+ const fresh = {
357
+ attempt: 1,
358
+ priorAttempts: [],
359
+ flakyDeferrals: 0,
360
+ priorDiagnosisClass: null,
361
+ };
362
+ const priorAttempt = typeof prior?.attempt === "number" ? prior.attempt : 0;
363
+ // No prior run of the family at all.
364
+ if (priorAttempt === 0)
365
+ return fresh;
366
+ // Someone else's push — a maintainer, a Dependabot rebase, a Renovate
367
+ // recreate. The world moved, so the counter, the journal, the deferral count
368
+ // and the last verdict are all about a problem that no longer exists.
369
+ if (!sameProblem(state, prior))
370
+ return fresh;
371
+ const carried = Array.isArray(prior?.priorAttempts)
372
+ ? prior.priorAttempts.filter((l) => typeof l === "string")
373
+ : [];
374
+ // A run that produced no marker leaves no line, exactly as it consumes no
375
+ // attempt: there is nothing for the next attempt to learn from a crash.
376
+ const line = renderAttemptLine(priorAttempt, priorMarkers);
377
+ const priorAttempts = boundAttemptLines(line ? [...carried, line] : carried);
378
+ const priorFlaky = typeof prior?.flakyDeferrals === "number" ? prior.flakyDeferrals : 0;
379
+ // CONSECUTIVE, which is the whole point of the cap: three `flaky` verdicts in
380
+ // a row means the job is not flaky, it is intermittently really failing, and
381
+ // `fix.maxFlakyDeferrals` promotes it to `reproducible`. Any other class
382
+ // breaks the run and resets to 0. A run with no diagnosis at all (a crash)
383
+ // neither advances nor resets it — it says nothing about flakiness.
384
+ const flakyDeferrals = priorMarkers?.diagnosis
385
+ ? priorMarkers.diagnosis.class === "flaky"
386
+ ? priorFlaky + 1
387
+ : 0
388
+ : priorFlaky;
389
+ return {
390
+ attempt: nextAttempt(state, prior, priorSpent),
391
+ priorAttempts,
392
+ flakyDeferrals,
393
+ // Only ever the LAST run's verdict — see `PrState.priorDiagnosisClass` for
394
+ // why this one does not persist across a run that diagnosed nothing.
395
+ priorDiagnosisClass: priorMarkers?.diagnosis?.class ?? null,
396
+ };
397
+ }
398
+ /**
399
+ * Is the live head the same PROBLEM the prior run worked on?
400
+ *
401
+ * True when the head is unchanged (we made no progress — covers `no-change`
402
+ * and `gave-up`) or when WE authored the new head (our fix landed and CI is
403
+ * still red). False only when someone else pushed.
404
+ *
405
+ * THE boundary of a problem, and read in two places on purpose: the attempt
406
+ * counter and {@link PrState.costBaselineUsd}. Those two are the pair of
407
+ * budgets `fix.maxAttempts` and `fix.maxCostUsd` bound, so a maintainer's push
408
+ * has to re-arm both or neither — re-arming only the counter is what let
409
+ * `budget-exhausted` re-comment on every push (#256).
410
+ */
411
+ function sameProblem(state, prior) {
412
+ const priorHead = typeof prior?.headSha === "string" ? prior.headSha : "";
413
+ const headChanged = !!state.headSha && !!priorHead && state.headSha !== priorHead;
414
+ return !(headChanged && !state.headIsOurs);
415
+ }
416
+ /**
417
+ * §S1's attempt table, in code.
418
+ *
419
+ * `priorSpent` is the robustness rule the whole design rests on: **a crashed
420
+ * run never consumes budget.** Without it, one bad hour — a sandbox
421
+ * provisioning outage, a quota rejection, a model API wobble — silently
422
+ * escalates every open dependency PR across every managed repo to
423
+ * `requires-human`, and a human then has to un-stick each one by hand. Nothing
424
+ * else in this design can cause damage that broad. `fix.maxCostUsd` and
425
+ * `MAX_RESTART_RESUMES` bound the crash-loop case instead, and neither poisons
426
+ * a label.
427
+ */
428
+ function nextAttempt(state, prior, priorSpent) {
429
+ const priorAttempt = typeof prior?.attempt === "number" ? prior.attempt : 0;
430
+ if (priorAttempt === 0)
431
+ return 1;
432
+ // Someone else's push. The world moved: fresh problem, fresh counter. This is
433
+ // what stops an exhausted human PR being permanently un-fixable for the life
434
+ // of the PR.
435
+ if (!sameProblem(state, prior))
436
+ return 1;
437
+ // Same head (we made no progress — covers `no-change` and `gave-up`), or a
438
+ // head WE authored on top of it (our fix landed, CI is still red). Same
439
+ // problem either way, so the counter advances — but only if the prior run got
440
+ // far enough to spend it.
441
+ return priorSpent ? priorAttempt + 1 : priorAttempt;
442
+ }
443
+ /**
444
+ * Did this prior run actually SPEND an attempt?
445
+ *
446
+ * §S1 answers it in two clauses, and BOTH are necessary:
447
+ *
448
+ * 1. **The run produced a `DIAGNOSIS_COMPLETE` marker.** This is a read of the
449
+ * harvest (`./fix-harvest.ts`), written by `onPhaseEnd` as each phase
450
+ * completes. A run that crashed before `diagnose` finished — sandbox
451
+ * provisioning failure, quota rejection, model API error — harvested no
452
+ * diagnosis and costs nothing. That rule is the single most important
453
+ * robustness property in the design: without it, one bad hour silently
454
+ * escalates EVERY open dependency PR across EVERY managed repo to
455
+ * `requires-human`, and a human then un-sticks each one by hand.
456
+ * `fix.maxCostUsd` and `MAX_RESTART_RESUMES` bound the crash-loop case
457
+ * instead, and neither poisons a label.
458
+ * 2. **Its class is one that costs an attempt** — §S1's class table, encoded as
459
+ * {@link ATTEMPT_FREE_CLASSES}. `flaky` and `upstream-broken` are correct
460
+ * stopping verdicts about something other than this PR's code; charging for
461
+ * them would leave the PR with no attempts left at the moment it becomes
462
+ * fixable, and would make `fix.maxFlakyDeferrals` unreachable.
463
+ *
464
+ * An UNRECOGNISED class counts. A hallucinated class token is not evidence that
465
+ * the run cost nothing, and the free-attempt direction is the unbounded one.
466
+ *
467
+ * Two fallbacks, in order:
468
+ *
469
+ * - **No PARSED diagnosis** — the ledger decides. Two very different runs land
470
+ * here and it is deliberate that they are NOT told apart: one has no harvest
471
+ * namespace at all (it predates the harvest, or died before its first
472
+ * `onPhaseEnd`), the other harvested and parsed nothing. Reading the second as
473
+ * "spent nothing" was the defect — `harvestFixMarkers` writes the namespace
474
+ * unconditionally for the fix family, so a malformed marker produces a
475
+ * non-null harvest carrying `diagnosis: null`, and treating that as a free run
476
+ * pinned the PR at attempt 1 for its whole life with `fix.maxCostUsd` as the
477
+ * only remaining brake.
478
+ *
479
+ * The probe is `diagnose`'s own ledger row: the phase carries
480
+ * `on_output.requires_marker: "DIAGNOSIS_COMPLETE:"`, so a SUCCEEDED
481
+ * `diagnose` cannot exist without a well-formed marker having been emitted.
482
+ * Same fact, read less directly, and without the class. Failing CLOSED here
483
+ * costs a crashed run nothing, because a run whose `diagnose` genuinely never
484
+ * finished has no succeeded row for the probe to find.
485
+ * - **A read error** — fail CLOSED (count it). A read failure must not silently
486
+ * grant a free attempt forever; the cost cap is the backstop, and the
487
+ * alternative is an unbounded retry loop.
488
+ */
489
+ function didSpendAttempt(prior, deps) {
490
+ try {
491
+ const diagnosis = readHarvestedMarkers(prior)?.diagnosis ?? null;
492
+ if (!diagnosis)
493
+ return deps.db.executions.phaseSucceededInRun(prior.id, "diagnose");
494
+ return !(diagnosis.class && ATTEMPT_FREE_CLASSES.has(diagnosis.class));
495
+ }
496
+ catch {
497
+ return true;
498
+ }
499
+ }
500
+ /** Read a persisted snapshot off a stored run context, tolerating old rows. */
501
+ function priorPrState(context) {
502
+ if (!context || typeof context !== "object")
503
+ return null;
504
+ const ctx = context;
505
+ const snap = ctx.prState;
506
+ if (snap && typeof snap === "object")
507
+ return snap;
508
+ // Pre-`prState` rows persisted a bare `headSha` (and nothing else). Honour it
509
+ // so the "already assessed at this SHA" dedup keeps working across the
510
+ // upgrade instead of re-assessing every open PR once.
511
+ if (typeof ctx.headSha === "string")
512
+ return { headSha: ctx.headSha };
513
+ return null;
514
+ }
515
+ //# sourceMappingURL=pr-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pr-state.js","sourceRoot":"","sources":["../../src/engine/pr-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAA4B,MAAM,kBAAkB,CAAC;AAClF,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,GAElB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAe,MAAM,eAAe,CAAC;AAoPrF;;;;;;;;GAQG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,qEAAqE;AACrE,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,QAAgB;IACxD,OAAO,GAAG,IAAI,IAAI,QAAQ,EAAE,CAAC;AAC/B,CAAC;AAuBD,iDAAiD;AACjD,SAAS,OAAO,CAAC,IAAiB;IAChC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACnE,OAAO,IAAI,IAAI,SAAS,CAAC;AAC3B,CAAC;AASD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,KAAa,EACb,IAAY,EACZ,QAAgB,EAChB,IAAiB;IAEjB,MAAM,IAAI,GAAG,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC;IAChC,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,CAAC,IAAY,EA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