@juangcarmona/lighthouse-sdlc 0.21.10 → 0.22.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.
package/README.md CHANGED
@@ -91,6 +91,10 @@ The installer subscribes the router to selected continuation workers and the wor
91
91
 
92
92
  Required PR checks must come from an event [GitHub accepts for PR rules](https://docs.github.com/en/pull-requests/how-tos/merge-and-close-pull-requests/troubleshooting-required-status-checks?plain=1). A green `workflow_dispatch` job supports execution evidence but cannot satisfy those rules. Lighthouse authenticates the native run, SHA and check suite before counting a job; unavailable origin or an ineligible event blocks integration with its execution link. Configure eligible CI for bot publications separately; dispatch alone does not establish unattended merge readiness. Post-merge verification can still use dispatch.
93
93
 
94
+ ## Typed issue controls
95
+
96
+ The optional [issue-control SDK](issue-control.md) provides authenticated observation, stage-only Refine/Propose, ordinary comments and explicit continuation of a verified pending question. Install with `--with-issue-control` to enable the existing router's typed entry and capability declaration. Caller-owned credentials and a durable atomic intent journal are required; source receipts distinguish submission, worker admission and validated results. Native actual-user qualification and release remain separate from this source implementation.
97
+
94
98
  ## Bounded unattended routes
95
99
 
96
100
  Install `--with-unattended` explicitly to add fast-forward and test-first hotfix compositions. [Configuration and execution](unattended.md) describes admission, separate model review, regression proof, scope limits, merge delegation and recovery. Existing supervised routes retain their stops. The bounded `lighthouse-unattended-<run>-<attempt>` artifact contains delivery receipts; full engine and check logs are retained separately as `lighthouse-unattended-diagnostics-<run>-<attempt>`.
@@ -36,6 +36,8 @@ The trusted host probes the selected image without source or credential mounts.
36
36
 
37
37
  The agent and independent checks use different containers, networks and database credentials. Validation starts with an empty database, not the agent's changes. The host removes containers, anonymous volumes and networks after each phase. Validation has no provider authentication volume or GitHub credentials. Neither workload receives the host Docker socket. Public package downloads remain available; these bridge networks are not an egress firewall. This does not change the existing single-trusted-host security model.
38
38
 
39
+ Each admitted validation command has its own ten-minute execution limit; environment preparation and earlier successful commands do not consume later command windows. The installed workflow retains its overall job timeout. Cancellation, failed or unknown command completion still stops subsequent checks and publication.
40
+
39
41
  NuGet packages and .NET CLI state use writable temporary directories rather than the engine's read-only home. Each independent command has fresh temporary storage: combine restore and test in the consumer's verification command instead of assuming a prior command's NuGet cache survives.
40
42
 
41
43
  Cancellation first removes workload containers, then services. The host records repository, native run and attempt ownership before allocating containers or networks, including temporary helpers. It retains journals in `<operator lock path>.resources`; operators must create this private directory and persistently mount it at the same absolute path when the runner is containerized. The journal is never mounted in a workload.
@@ -48,6 +50,8 @@ See the source repository's `src/examples/opencode-engine/ENVIRONMENTS.md` for l
48
50
 
49
51
  Implementation and independent validation each create a local Git repository containing one candidate snapshot commit, without remotes, checkout configuration or hooks. This supports Git-based working-tree checks without exposing the original checkout. It does not certify earlier commits; full-history security checks remain a separate repository CI responsibility.
50
52
 
53
+ Tracked source symlinks remain opaque: the host authenticates their path, mode and blob identity from the admitted revision and excludes them from the executable filesystem. A separate temporary index combines that metadata with the checked regular-file tree; command evidence binds the metadata digest, and its reader independently reconstructs it from the original commit. Publication still requires equality with the complete checked tree. Link target contents are never read through this mechanism.
54
+
51
55
  Agent evidence is bounded to 200 regular files and 64 MiB per collection, including static previews, screenshots and reports. Symbolic links at the collection root or within it are rejected. An exceeded budget reports the file count or byte count that crossed its limit; larger collections must be curated before handoff.
52
56
 
53
57
  ## Resource limits and command completion
@@ -0,0 +1,61 @@
1
+ # Issue-control SDK
2
+
3
+ The `./issue-control` export supplies `createIssueControl`, `parseIssueComment`, `parseIssueIntent` and `validateIssueIntent`. The [intent schema](schemas/issue-control-intent.schema.json) describes version 1; runtime validation also checks canonical JSON and UTF-8 byte limits. This implementation is awaiting packed-consumer and actual-user native qualification. Source availability does not establish a published or adopted release.
4
+
5
+ ## Adoption
6
+
7
+ Install the selected package, review an immutable compatible workflow source pin, then preview:
8
+
9
+ ```sh
10
+ node node_modules/@juangcarmona/lighthouse-sdlc/src/install-workflows.mjs . <immutable-lighthouse-commit> --with-propose --with-issue-control
11
+ ```
12
+
13
+ After reviewing the diff, repeat with `--apply`; differing existing workflows require `--replace-reviewed`. The installer enables the source-owned `client-control` job in the existing router and writes `.lighthouse/issue-control.json`, binding its exact bytes and selected stages. It inventories existing or selected unattended/epic workflows for reservation coverage. Automation, credentials, provider access and execution readiness still require the [operator setup](github-actions.md). The installer preserves existing policy. Without verified version 1 adoption, the SDK reports unsupported and never falls back to legacy commands.
14
+
15
+ ## Authenticated caller
16
+
17
+ ```js
18
+ import { createIssueControl } from '@juangcarmona/lighthouse-sdlc/issue-control';
19
+
20
+ const control = createIssueControl({
21
+ repository: 'owner/repository',
22
+ transport, // authenticated provider adapter described below
23
+ readArtifact, // bounded authenticated artifact reader described below
24
+ readAuthority // trusted acting-user/token permission evidence
25
+ });
26
+
27
+ const state = await control.observe({ number: 7 });
28
+ const prepared = await control.prepare({ number: 7, action: 'refine', id: crypto.randomUUID() });
29
+ // Persist the whole prepared value before its first write.
30
+ const submitted = await control.submit(prepared, { claim });
31
+ // A recreated SDK uses the persisted prepared value and the same durable claim.
32
+ const reconciled = await control.reconcile(prepared);
33
+ ```
34
+
35
+ `prepare` returns either a prepared object with `version`, `intent`, `key`, `payloadDigest` and `effect`, or an explicit unavailable/rejected state. Call `submit` only for a prepared object. `observe` and `prepare` perform reads only. They report source eligibility separately from execution readiness and can become stale while a request queues; source admission rechecks current authority.
36
+
37
+ The transport receives `{scope, repository?, path, method, body?, optional?, apiVersion?}`. Account scope uses `GET user`; repository paths are relative to the explicitly bound repository. Use the actual connected user's credentials, honor the requested API version, return parsed provider JSON, and map optional 404 to `null`. HTTP failures expose a numeric `status`; uncertain network failures retain uncertainty. No credentials, default transport, environment token lookup or ambient network access is supplied by this module. Comments are posted directly as that user. A bot or installation token cannot substitute for the acting account.
38
+
39
+ `readAuthority({api, repository, actor, metadata})` must return verified `actorId`, `repositoryId`, and boolean `commentWrite`/`dispatchWrite` capabilities for the actual credentials. Missing or mismatched evidence denies writes. The current contract supports the personal repository owner; other identities are explicitly unsupported. Reading repository variables may require additional token permission; a denial makes policy unavailable, rather than assuming automation is enabled.
40
+
41
+ `readArtifact(api, repository, runId, exactName, member, optional)` returns parsed JSON from exactly one unexpired artifact in that authenticated run. Return `null` only when an optional artifact is absent. Enforce the existing 2 MiB archive bound, complete inventory of at most 100 artifacts, safe ZIP member paths and duplicate rejection; never execute archive contents. Nested API operations are clamped to GET. The caller owns authenticated download and archive decoding. Do not use the internal operator reader as a browser transport: it uses ambient `gh` credentials.
42
+
43
+ `claim({key, payloadDigest, intent})` must atomically persist and return `{state:'claimed'}`, `{state:'existing'}` for the same payload, or `{state:'conflict'}`. Share this journal across tabs, processes and restarts. A claimed intent may make one POST; an existing claim only reconciles. No automatic resend follows an uncertain outcome. Uncoordinated journals cannot guarantee exactly-once comment creation.
44
+
45
+ ## Actions and source proof
46
+
47
+ | Action | Scope and effect |
48
+ | --- | --- |
49
+ | `refine` / `propose` | One stage-only typed router dispatch, bound to repository/issue/actor, current source, input, capability and policy digests. Global automatic implementation, Product Change and merge grants are not inherited. |
50
+ | `comment` | Direct-user comment with a strict attributable footer. Body text remains data even if it resembles a command or approval; publication never resumes a wait. |
51
+ | `continue` | Direct-user answer bound to the exact verified question, original request and grant. Source admits only the current supported question and the intersection of its original grant with current policy. |
52
+
53
+ The full comment, including metadata, is limited to 48 KiB UTF-8; CRLF becomes LF and other text is preserved. `parseIssueComment` returns `typed`, `legacy` or `invalid`; show parsed typed body as source text, and treat invalid metadata as unsupported. Never strip invalid metadata then re-enter a legacy command parser. Typed comments must have the actual immutable user ID that the footer names.
54
+
55
+ The source records the immutable intent and exact key/payload lookup artifacts before admission. It reuses the native per-issue concurrency group, dispatch artifact and worker receipt. A repeated key reconciles its original result before current freshness checks; a changed payload conflicts. An equivalent new key gets a durable source alias, which reconciliation follows to its authenticated original. A deleted bot comment can be recovered through exact artifact indexes. Missing, expired, ambiguous or incomplete history remains unknown and cannot authorize a resend. Artifacts are retained for 90 days; callers retain their own prepared intents and journal.
56
+
57
+ `submitted` identifies the exact router run returned by GitHub API `2026-03-10`, or the exact published user comment. Its worker ID is unconfirmed. `source-admitted` establishes the source dispatch grant and receipt. `execution` separately exposes authenticated worker run/attempt, source status and validated published result when available. `questionConsumed` requires the matching continuation snapshot and validated source result; `questionResolved` additionally requires that result to pass. Posting an answer or admitting a worker alone never clears the wait.
58
+
59
+ Current v1 limitations include custom-model, handoff, epic and Product Change pending contexts. Repositories with epic admission enabled return explicit unsupported eligibility. Active background runs without authenticated issue binding make reservation coverage unavailable. Question text remains readable when its action is unsupported. No host scheduler, execution control, automatic approval or UI persistence is introduced.
60
+
61
+ Unmarked GitHub labels, comments and dispatches retain their existing lifecycle meaning. Typed client requests use their separate strict source admission and cannot pass through legacy routing. Actual-user OAuth/App-user permission, native source correlation and packed-package behavior must be qualified independently of fixture tests.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juangcarmona/lighthouse-sdlc",
3
- "version": "0.21.10",
3
+ "version": "0.22.0",
4
4
  "type": "module",
5
5
  "description": "Provider-neutral SDLC skills, commands and route contracts for Lighthouse adopters",
6
6
  "repository": {
@@ -45,7 +45,8 @@
45
45
  "unattended.md",
46
46
  "LICENSE",
47
47
  "NOTICE",
48
- "telemetry.md"
48
+ "telemetry.md",
49
+ "issue-control.md"
49
50
  ],
50
51
  "bin": {
51
52
  "lighthouse-sdlc": "./src/sdlc.mjs"
@@ -98,7 +99,9 @@
98
99
  "./unattended": "./src/unattended.mjs",
99
100
  "./telemetry": "./src/telemetry.mjs",
100
101
  "./telemetry-opencode": "./src/telemetry-opencode.mjs",
101
- "./schemas/telemetry-event.schema.json": "./schemas/telemetry-event.schema.json"
102
+ "./schemas/telemetry-event.schema.json": "./schemas/telemetry-event.schema.json",
103
+ "./issue-control": "./src/issue-control.mjs",
104
+ "./schemas/issue-control-intent.schema.json": "./schemas/issue-control-intent.schema.json"
102
105
  },
103
106
  "license": "Apache-2.0"
104
107
  }
@@ -0,0 +1,408 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "Lighthouse issue-control intent v1",
4
+ "description": "Wire shape. The SDK validator also enforces canonical sorted JSON, exact UTF-8 byte bounds, repository identity, and attributable comment binding. Maximum serialized intent: 128000 bytes.",
5
+ "oneOf": [
6
+ {
7
+ "type": "object",
8
+ "additionalProperties": false,
9
+ "required": [
10
+ "version",
11
+ "id",
12
+ "repository",
13
+ "issue",
14
+ "actorId",
15
+ "action",
16
+ "scope",
17
+ "binding"
18
+ ],
19
+ "properties": {
20
+ "version": {
21
+ "const": 1
22
+ },
23
+ "id": {
24
+ "type": "string",
25
+ "pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$"
26
+ },
27
+ "repository": {
28
+ "type": "object",
29
+ "additionalProperties": false,
30
+ "required": [
31
+ "id",
32
+ "name"
33
+ ],
34
+ "properties": {
35
+ "id": {
36
+ "type": "integer",
37
+ "minimum": 1,
38
+ "maximum": 9007199254740991
39
+ },
40
+ "name": {
41
+ "type": "string",
42
+ "pattern": "^[a-z0-9_.-]{1,100}/[a-z0-9_.-]{1,100}$"
43
+ }
44
+ }
45
+ },
46
+ "issue": {
47
+ "type": "object",
48
+ "additionalProperties": false,
49
+ "required": [
50
+ "id",
51
+ "number"
52
+ ],
53
+ "properties": {
54
+ "id": {
55
+ "type": "integer",
56
+ "minimum": 1,
57
+ "maximum": 9007199254740991
58
+ },
59
+ "number": {
60
+ "type": "integer",
61
+ "minimum": 1,
62
+ "maximum": 9007199254740991
63
+ }
64
+ }
65
+ },
66
+ "actorId": {
67
+ "type": "integer",
68
+ "minimum": 1,
69
+ "maximum": 9007199254740991
70
+ },
71
+ "action": {
72
+ "const": "refine"
73
+ },
74
+ "scope": {
75
+ "const": "stage-only"
76
+ },
77
+ "binding": {
78
+ "type": "object",
79
+ "additionalProperties": false,
80
+ "required": [
81
+ "sourceRevision",
82
+ "defaultBranch",
83
+ "inputDigest",
84
+ "policyDigest",
85
+ "capabilityDigest"
86
+ ],
87
+ "properties": {
88
+ "sourceRevision": {
89
+ "type": "string",
90
+ "pattern": "^[a-f0-9]{40}$"
91
+ },
92
+ "defaultBranch": {
93
+ "type": "string",
94
+ "minLength": 1,
95
+ "maxLength": 256,
96
+ "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
97
+ },
98
+ "inputDigest": {
99
+ "$ref": "#/$defs/hash"
100
+ },
101
+ "policyDigest": {
102
+ "$ref": "#/$defs/hash"
103
+ },
104
+ "capabilityDigest": {
105
+ "$ref": "#/$defs/hash"
106
+ }
107
+ }
108
+ }
109
+ }
110
+ },
111
+ {
112
+ "type": "object",
113
+ "additionalProperties": false,
114
+ "required": [
115
+ "version",
116
+ "id",
117
+ "repository",
118
+ "issue",
119
+ "actorId",
120
+ "action",
121
+ "scope",
122
+ "binding"
123
+ ],
124
+ "properties": {
125
+ "version": {
126
+ "const": 1
127
+ },
128
+ "id": {
129
+ "type": "string",
130
+ "pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$"
131
+ },
132
+ "repository": {
133
+ "type": "object",
134
+ "additionalProperties": false,
135
+ "required": [
136
+ "id",
137
+ "name"
138
+ ],
139
+ "properties": {
140
+ "id": {
141
+ "type": "integer",
142
+ "minimum": 1,
143
+ "maximum": 9007199254740991
144
+ },
145
+ "name": {
146
+ "type": "string",
147
+ "pattern": "^[a-z0-9_.-]{1,100}/[a-z0-9_.-]{1,100}$"
148
+ }
149
+ }
150
+ },
151
+ "issue": {
152
+ "type": "object",
153
+ "additionalProperties": false,
154
+ "required": [
155
+ "id",
156
+ "number"
157
+ ],
158
+ "properties": {
159
+ "id": {
160
+ "type": "integer",
161
+ "minimum": 1,
162
+ "maximum": 9007199254740991
163
+ },
164
+ "number": {
165
+ "type": "integer",
166
+ "minimum": 1,
167
+ "maximum": 9007199254740991
168
+ }
169
+ }
170
+ },
171
+ "actorId": {
172
+ "type": "integer",
173
+ "minimum": 1,
174
+ "maximum": 9007199254740991
175
+ },
176
+ "action": {
177
+ "const": "propose"
178
+ },
179
+ "scope": {
180
+ "const": "stage-only"
181
+ },
182
+ "binding": {
183
+ "type": "object",
184
+ "additionalProperties": false,
185
+ "required": [
186
+ "sourceRevision",
187
+ "defaultBranch",
188
+ "inputDigest",
189
+ "policyDigest",
190
+ "capabilityDigest"
191
+ ],
192
+ "properties": {
193
+ "sourceRevision": {
194
+ "type": "string",
195
+ "pattern": "^[a-f0-9]{40}$"
196
+ },
197
+ "defaultBranch": {
198
+ "type": "string",
199
+ "minLength": 1,
200
+ "maxLength": 256,
201
+ "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
202
+ },
203
+ "inputDigest": {
204
+ "$ref": "#/$defs/hash"
205
+ },
206
+ "policyDigest": {
207
+ "$ref": "#/$defs/hash"
208
+ },
209
+ "capabilityDigest": {
210
+ "$ref": "#/$defs/hash"
211
+ }
212
+ }
213
+ }
214
+ }
215
+ },
216
+ {
217
+ "type": "object",
218
+ "additionalProperties": false,
219
+ "required": [
220
+ "version",
221
+ "id",
222
+ "repository",
223
+ "issue",
224
+ "actorId",
225
+ "action",
226
+ "scope",
227
+ "body"
228
+ ],
229
+ "properties": {
230
+ "version": {
231
+ "const": 1
232
+ },
233
+ "id": {
234
+ "type": "string",
235
+ "pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$"
236
+ },
237
+ "repository": {
238
+ "type": "object",
239
+ "additionalProperties": false,
240
+ "required": [
241
+ "id",
242
+ "name"
243
+ ],
244
+ "properties": {
245
+ "id": {
246
+ "type": "integer",
247
+ "minimum": 1,
248
+ "maximum": 9007199254740991
249
+ },
250
+ "name": {
251
+ "type": "string",
252
+ "pattern": "^[a-z0-9_.-]{1,100}/[a-z0-9_.-]{1,100}$"
253
+ }
254
+ }
255
+ },
256
+ "issue": {
257
+ "type": "object",
258
+ "additionalProperties": false,
259
+ "required": [
260
+ "id",
261
+ "number"
262
+ ],
263
+ "properties": {
264
+ "id": {
265
+ "type": "integer",
266
+ "minimum": 1,
267
+ "maximum": 9007199254740991
268
+ },
269
+ "number": {
270
+ "type": "integer",
271
+ "minimum": 1,
272
+ "maximum": 9007199254740991
273
+ }
274
+ }
275
+ },
276
+ "actorId": {
277
+ "type": "integer",
278
+ "minimum": 1,
279
+ "maximum": 9007199254740991
280
+ },
281
+ "action": {
282
+ "const": "comment"
283
+ },
284
+ "scope": {
285
+ "const": "comment-only"
286
+ },
287
+ "body": {
288
+ "type": "string",
289
+ "minLength": 1,
290
+ "maxLength": 49152,
291
+ "description": "Runtime validation additionally enforces Unicode validity, nonblank text, LF normalization and the complete formatted comment limit of 48 KiB UTF-8."
292
+ }
293
+ }
294
+ },
295
+ {
296
+ "type": "object",
297
+ "additionalProperties": false,
298
+ "required": [
299
+ "version",
300
+ "id",
301
+ "repository",
302
+ "issue",
303
+ "actorId",
304
+ "action",
305
+ "scope",
306
+ "body",
307
+ "question"
308
+ ],
309
+ "properties": {
310
+ "version": {
311
+ "const": 1
312
+ },
313
+ "id": {
314
+ "type": "string",
315
+ "pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$"
316
+ },
317
+ "repository": {
318
+ "type": "object",
319
+ "additionalProperties": false,
320
+ "required": [
321
+ "id",
322
+ "name"
323
+ ],
324
+ "properties": {
325
+ "id": {
326
+ "type": "integer",
327
+ "minimum": 1,
328
+ "maximum": 9007199254740991
329
+ },
330
+ "name": {
331
+ "type": "string",
332
+ "pattern": "^[a-z0-9_.-]{1,100}/[a-z0-9_.-]{1,100}$"
333
+ }
334
+ }
335
+ },
336
+ "issue": {
337
+ "type": "object",
338
+ "additionalProperties": false,
339
+ "required": [
340
+ "id",
341
+ "number"
342
+ ],
343
+ "properties": {
344
+ "id": {
345
+ "type": "integer",
346
+ "minimum": 1,
347
+ "maximum": 9007199254740991
348
+ },
349
+ "number": {
350
+ "type": "integer",
351
+ "minimum": 1,
352
+ "maximum": 9007199254740991
353
+ }
354
+ }
355
+ },
356
+ "actorId": {
357
+ "type": "integer",
358
+ "minimum": 1,
359
+ "maximum": 9007199254740991
360
+ },
361
+ "action": {
362
+ "const": "continue"
363
+ },
364
+ "scope": {
365
+ "const": "original-grant"
366
+ },
367
+ "body": {
368
+ "type": "string",
369
+ "minLength": 1,
370
+ "maxLength": 49152,
371
+ "description": "Runtime validation additionally enforces Unicode validity, nonblank text, LF normalization and the complete formatted comment limit of 48 KiB UTF-8."
372
+ },
373
+ "question": {
374
+ "type": "object",
375
+ "additionalProperties": false,
376
+ "required": [
377
+ "commentId",
378
+ "requestId",
379
+ "questionDigest",
380
+ "grantDigest"
381
+ ],
382
+ "properties": {
383
+ "commentId": {
384
+ "type": "integer",
385
+ "minimum": 1,
386
+ "maximum": 9007199254740991
387
+ },
388
+ "requestId": {
389
+ "$ref": "#/$defs/hash"
390
+ },
391
+ "questionDigest": {
392
+ "$ref": "#/$defs/hash"
393
+ },
394
+ "grantDigest": {
395
+ "$ref": "#/$defs/hash"
396
+ }
397
+ }
398
+ }
399
+ }
400
+ }
401
+ ],
402
+ "$defs": {
403
+ "hash": {
404
+ "type": "string",
405
+ "pattern": "^[a-f0-9]{64}$"
406
+ }
407
+ }
408
+ }
@@ -8,18 +8,24 @@ const stop = 'Inspect the rejected execution and current authority before reques
8
8
  const same = (a, b) => digest(JSON.stringify(a)) === digest(JSON.stringify(b));
9
9
  const preparation = 'Verify accepted commit, checks and evidence protection';
10
10
 
11
+ async function rejectedJobs(api, { dispatch, run }) {
12
+ if (run.status !== 'completed' || run.run_attempt !== 1 || run.conclusion !== 'failure') return null;
13
+ if (dispatch.receipt.workerRunId && String(dispatch.receipt.workerRunId) !== String(run.id)) return null;
14
+ const inventory = await api(`actions/runs/${run.id}/attempts/1/jobs?per_page=100`);
15
+ if (!Array.isArray(inventory.jobs) || inventory.total_count !== inventory.jobs.length || inventory.total_count > 100) return null;
16
+ const jobs = inventory.jobs;
17
+ const preparationJobs = jobs.filter(job => job.name === preparation), publicationJobs = jobs.filter(job => job.name === 'Validate, publish and release');
18
+ if (preparationJobs.length !== 1 || preparationJobs[0].conclusion !== 'failure' || publicationJobs.length !== 1 || publicationJobs[0].conclusion !== 'skipped' || ['pre_activation', 'activation', 'agent'].some(name => jobs.filter(job => job.name === name).length !== 1 || jobs.find(job => job.name === name).conclusion !== 'skipped') || jobs.some(job => job.name !== preparation && job.conclusion !== 'skipped')) return null;
19
+ return jobs;
20
+ }
21
+
11
22
  // A changed ref never admits work; only a terminal native job inventory can establish skipped effects.
12
23
  export async function observeAdmissionRejection(api, repository, owner, rejection, issue, comments) {
13
24
  const { dispatch, parent, run } = rejection, request = dispatch.request;
14
25
  const base = { issue: issue.number, worker: request.worker ?? request.stage, runId: String(run.id), rootId: request.recovery?.rootId ?? request.id, attempt: request.recovery?.attempt ?? 0, outcome: 'failed', admissionRejected: true, dispatch, run };
15
26
  const result = (state, code, nextAction = stop, extra = {}) => ({ ...base, state, code, nextAction, ...extra });
16
- if (run.status !== 'completed' || run.run_attempt !== 1 || run.conclusion !== 'failure') return result('uncertain', 'admission-effects-unconfirmed');
17
- if (dispatch.receipt.workerRunId && String(dispatch.receipt.workerRunId) !== String(run.id)) return result('uncertain', 'admission-effects-unconfirmed');
18
- const inventory = await api(`actions/runs/${run.id}/attempts/1/jobs?per_page=100`);
19
- if (!Array.isArray(inventory.jobs) || inventory.total_count !== inventory.jobs.length || inventory.total_count > 100) return result('uncertain', 'admission-effects-unconfirmed');
20
- const jobs = inventory.jobs;
21
- const preparationJobs = jobs.filter(job => job.name === preparation), publicationJobs = jobs.filter(job => job.name === 'Validate, publish and release');
22
- if (preparationJobs.length !== 1 || preparationJobs[0].conclusion !== 'failure' || publicationJobs.length !== 1 || publicationJobs[0].conclusion !== 'skipped' || ['pre_activation', 'activation', 'agent'].some(name => jobs.filter(job => job.name === name).length !== 1 || jobs.find(job => job.name === name).conclusion !== 'skipped') || jobs.some(job => job.name !== preparation && job.conclusion !== 'skipped')) return result('uncertain', 'admission-effects-unconfirmed');
27
+ const jobs = await rejectedJobs(api, rejection);
28
+ if (!jobs) return result('uncertain', 'admission-effects-unconfirmed');
23
29
  const confirmed = extra => result('blocked', 'admission-authority-changed', stop, { confirmed: true, jobs, ...extra });
24
30
  if (request.recovery) return result('exhausted', 'admission-retry-exhausted', stop, { confirmed: true, jobs });
25
31
  if (request.stage !== 'review' || request.worker || request.handoff || request.completionRecovery || !request.admissionBinding || !isBotContinuation(request.event, parent.event, parent.actor?.login, parent.triggering_actor?.login)) return confirmed();
@@ -65,7 +71,7 @@ export function admissionRetryRequest(observation, parent) {
65
71
  return next;
66
72
  }
67
73
 
68
- export async function verifyAdmissionRecovery(api, repository, owner, dispatch, parent, readArtifact) {
74
+ export async function verifyAdmissionRecovery(api, repository, owner, dispatch, parent, readArtifact, revalidate = false) {
69
75
  const request = dispatch.request, retry = request.recovery;
70
76
  if (parent.path !== '.github/workflows/lighthouse-worker-maintenance.yml' || retry.attempt !== 1 || !/^[1-9][0-9]*$/.test(String(retry.previousComment))) throw Error('Invalid before-admission recovery');
71
77
  const comment = await api(`issues/comments/${retry.previousComment}`), receipt = readDispatchReceipt(comment, repository, request.issue);
@@ -75,6 +81,10 @@ export async function verifyAdmissionRecovery(api, repository, owner, dispatch,
75
81
  try { await loadDispatch(api, repository, owner, request.issue, comment.id, run, readArtifact); }
76
82
  catch (error) { rejection = error.rejection; }
77
83
  if (!rejection || rejection.dispatch.request.recovery || retry.rootId !== rejection.dispatch.request.id || run.path !== stagePath('review')) throw Error('Invalid original admission rejection');
84
+ if (!await rejectedJobs(api, rejection)) throw Error('Original admission rejection effects are unconfirmed');
85
+ const expected = admissionRetryRequest({ dispatch: rejection.dispatch, rootId: retry.rootId, revision: request.sourceRevision }, parent);
86
+ if (!same(request, expected)) throw Error('Before-admission recovery authorization changed');
87
+ if (!revalidate) return;
78
88
  const issue = await api(`issues/${request.issue}`);
79
89
  const comments = await (await import('./stage-dispatch.mjs')).issueComments(api, request.issue);
80
90
  // The current retry is allowed; any other newer dispatch supersedes the original request.
@@ -159,6 +159,49 @@ export function assertChecks(observation) {
159
159
  }
160
160
  if (!observation.checks.length || observation.checks.some(c => c.status !== 'passed')) throw Error('Required checks are missing, pending or failed');
161
161
  }
162
+ // The caller supplies the original route deadline, never a renewed CI allowance.
163
+ export async function waitForIntegration({ api, repository, owner, authorization, workflowRunId, deadline, signal, recheck, promote,
164
+ inspect = inspectCompletion, now = Date.now, delay = ms => new Promise(resolve => setTimeout(resolve, ms)) }) {
165
+ if (!Number.isFinite(deadline)) throw Error('Integration requires the original finite delivery deadline');
166
+ const until = deadline;
167
+ const guard = () => {
168
+ if (signal?.aborted || now() >= until) throw Error('Delivery was cancelled or exceeded its execution limit; retain the PR for a new authorized action');
169
+ };
170
+ const authorize = async () => { guard(); await recheck(); guard(); };
171
+ let promoted = false;
172
+ while (true) {
173
+ await authorize();
174
+ const current = await api('pulls/' + authorization.pr);
175
+ guard();
176
+ if (current.head.sha !== authorization.head || current.state !== 'open') throw Error('Published candidate changed before integration');
177
+ if (promoted && current.draft) throw Error('PR returned to draft; new authorization is required');
178
+ // Observe a draft without promoting it while CI is pending. Merge still rejects drafts.
179
+ let observation = await inspect(api, repository, owner, authorization, 'integrate', workflowRunId, { observeDraft: true });
180
+ guard();
181
+ let checked = false;
182
+ try { assertChecks(observation); checked = true; }
183
+ catch (error) { if (observation.checks.some(check => ['ineligible-event', 'unverified-workflow'].includes(check.state))) throw error; }
184
+ if (checked) {
185
+ await authorize();
186
+ if (current.draft) {
187
+ try { await promote(current); }
188
+ catch (error) {
189
+ guard();
190
+ const reconciled = await api('pulls/' + authorization.pr);
191
+ guard();
192
+ if (reconciled.state !== 'open' || reconciled.head.sha !== authorization.head || reconciled.draft) throw error;
193
+ }
194
+ }
195
+ await authorize();
196
+ promoted = true;
197
+ observation = await inspect(api, repository, owner, authorization, 'integrate', workflowRunId);
198
+ await authorize();
199
+ if (observation.mergeable) return observation;
200
+ }
201
+ guard();
202
+ await delay(Math.min(30000, until - now()));
203
+ }
204
+ }
162
205
  export async function mergeAccepted(api, snapshot, recheck, beforeMerge = async () => {}) {
163
206
  const fresh = await recheck();
164
207
  if (fresh.merged && fresh.binding.head === snapshot.binding.head) return { state: 'merged', sha: fresh.merge, recovered: true };