@defrex/autobuild 1.10.0 → 1.11.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.
- package/README.md +1 -1
- package/SPEC.md +745 -69
- package/bin/ab-dispatch-generation.ts +3 -1
- package/docs/accounts.md +2 -1
- package/docs/answering-blocked-builds.md +20 -0
- package/docs/architecture.md +165 -29
- package/docs/build-store.md +10 -7
- package/docs/cli.md +33 -1
- package/docs/configuration-overview.md +4 -1
- package/docs/configuration.md +381 -29
- package/docs/dispatcher.md +64 -4
- package/docs/forges.md +7 -0
- package/docs/integration-tree.md +2 -2
- package/docs/operating.md +4 -2
- package/docs/operator-api.md +134 -6
- package/docs/operator-surfaces.md +85 -0
- package/docs/optimization-nodes.md +69 -11
- package/docs/plugin-authoring.md +37 -1
- package/docs/remote-store-protocol.md +94 -13
- package/docs/remote-ticket-protocol.md +40 -0
- package/docs/restacking.md +20 -4
- package/docs/setup.md +14 -2
- package/docs/ticket-dependencies.md +10 -3
- package/docs/ticket-sources.md +24 -2
- package/docs/tickets.md +7 -1
- package/docs/troubleshooting.md +8 -0
- package/docs/verification.md +4 -3
- package/docs/workspaces.md +3 -0
- package/package.json +9 -5
- package/packages/core/src/cli/accounts.ts +7 -2
- package/packages/core/src/cli/attention.ts +3 -1
- package/packages/core/src/cli/binary-direct.ts +2 -0
- package/packages/core/src/cli/binary-lifecycle.ts +2 -1
- package/packages/core/src/cli/build-control.ts +79 -1
- package/packages/core/src/cli/context.ts +4 -0
- package/packages/core/src/cli/dashboard/facts.ts +49 -53
- package/packages/core/src/cli/dashboard/header.ts +111 -0
- package/packages/core/src/cli/dashboard/model.ts +31 -39
- package/packages/core/src/cli/dashboard/objective-row.ts +46 -14
- package/packages/core/src/cli/dashboard/poll.ts +179 -76
- package/packages/core/src/cli/dashboard/render.ts +159 -230
- package/packages/core/src/cli/dashboard/row-text.ts +538 -0
- package/packages/core/src/cli/dashboard/timeline.ts +288 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +188 -0
- package/packages/core/src/cli/dispatch-args.ts +44 -1
- package/packages/core/src/cli/dispatch-frontend.ts +40 -40
- package/packages/core/src/cli/dispatch-launch-stop.ts +18 -0
- package/packages/core/src/cli/dispatch-launcher.ts +20 -7
- package/packages/core/src/cli/dispatch-web.ts +155 -0
- package/packages/core/src/cli/dispatch.ts +202 -38
- package/packages/core/src/cli/help.ts +87 -3
- package/packages/core/src/cli/init-validation.ts +3 -3
- package/packages/core/src/cli/main.ts +70 -6
- package/packages/core/src/cli/mcp.ts +35 -3
- package/packages/core/src/cli/objective.ts +1 -1
- package/packages/core/src/cli/operator-preference.ts +57 -0
- package/packages/core/src/cli/repo-lease.ts +2 -0
- package/packages/core/src/cli/repo-state.ts +56 -6
- package/packages/core/src/cli/repository-status.ts +105 -49
- package/packages/core/src/cli/status.ts +82 -1
- package/packages/core/src/cli/terminal-restore.ts +32 -7
- package/packages/core/src/cli/ticket.ts +98 -36
- package/packages/core/src/cli/wait.ts +14 -6
- package/packages/core/src/cli/watch.ts +20 -4
- package/packages/core/src/cli/web.ts +139 -0
- package/packages/core/src/config/live.ts +99 -14
- package/packages/core/src/config/load.ts +61 -20
- package/packages/core/src/config/local.ts +212 -0
- package/packages/core/src/config/pipeline-source.ts +2 -0
- package/packages/core/src/config/reference.ts +18 -0
- package/packages/core/src/config/schema.ts +45 -10
- package/packages/core/src/events/catalog.ts +4 -0
- package/packages/core/src/events/payloads.ts +97 -0
- package/packages/core/src/events/policy.ts +10 -0
- package/packages/core/src/events/repository.ts +46 -3
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +381 -30
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/017d8dd5bb6dd80b.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/178e12f1759b7552.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4932c70a2af97faf.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/536085773daf6b58.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6bd6275061aaffa5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/89625654b02e9ac1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a98af134be2da8a9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d5d5ccca80a893d8.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f8155387eb5f375c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3c27f918b194e3b3.json +465 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/46196d8f0076496a.json +97 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/79f0e0f4ccd43ba2.json +455 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/859c09edac738823.json +1086 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a283c1f3462b1cc1.json +81 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a6e570fb126991ff.json +36 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a8acf22c968b6e3d.json +81 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/ba7b85895bf6698e.json +1153 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fc66408cde0b6b04.json +637 -0
- package/packages/core/src/kernel/build-roster.ts +230 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +4 -2
- package/packages/core/src/kernel/dispatch-status.ts +139 -0
- package/packages/core/src/kernel/engine.ts +43 -5
- package/packages/core/src/kernel/execution-intervals.ts +61 -0
- package/packages/core/src/kernel/generators/optimization-log.ts +101 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +13 -0
- package/packages/core/src/kernel/leaf-restack-base.ts +33 -7
- package/packages/core/src/kernel/leaf-restack-state.ts +82 -3
- package/packages/core/src/kernel/log-index.ts +19 -0
- package/packages/core/src/kernel/optimization-admission.ts +244 -3
- package/packages/core/src/kernel/optimization.ts +183 -4
- package/packages/core/src/kernel/phase-failures.ts +121 -0
- package/packages/core/src/kernel/published-branch-head.ts +60 -0
- package/packages/core/src/kernel/read-facts.ts +15 -13
- package/packages/core/src/kernel/reducer-registry.ts +27 -8
- package/packages/core/src/kernel/reducer-revisions.ts +27 -0
- package/packages/core/src/kernel/reducer.ts +63 -4
- package/packages/core/src/kernel/rollup.ts +61 -0
- package/packages/core/src/kernel/setup-streak.ts +38 -0
- package/packages/core/src/kernel/step-durations.ts +257 -0
- package/packages/core/src/kernel/target-observation.ts +6 -1
- package/packages/core/src/kernel/target-rewrite-recovery.ts +116 -0
- package/packages/core/src/kernel/verify-diff-base.ts +5 -0
- package/packages/core/src/kernel/verify-stages.ts +13 -3
- package/packages/core/src/ontology.ts +5 -0
- package/packages/core/src/operator/agent-context-serve.ts +631 -0
- package/packages/core/src/operator/annotations.ts +75 -5
- package/packages/core/src/operator/attention.ts +470 -0
- package/packages/core/src/operator/canonical-skills.ts +35 -0
- package/packages/core/src/operator/cli-equivalents.ts +270 -0
- package/packages/core/src/operator/context-prompts.ts +61 -0
- package/packages/core/src/operator/index.ts +49 -1
- package/packages/core/src/operator/landings.ts +28 -19
- package/packages/core/src/operator/optimization.ts +7 -0
- package/packages/core/src/operator/protocol.ts +3 -0
- package/packages/core/src/operator/query.ts +129 -74
- package/packages/core/src/operator/read-view.ts +5 -2
- package/packages/core/src/operator/registry.ts +406 -46
- package/packages/core/src/operator/requests.ts +20 -18
- package/packages/core/src/operator/sandbox-host.ts +107 -11
- package/packages/core/src/operator/sandbox-resolver.ts +253 -0
- package/packages/core/src/operator/sandbox.ts +778 -82
- package/packages/core/src/operator/ticket-asset-list.ts +77 -0
- package/packages/core/src/operator/ticket-assets.ts +167 -0
- package/packages/core/src/operator/tickets.ts +33 -2
- package/packages/core/src/plugin-sdk/index.ts +22 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/ports/forge/fake.ts +92 -1
- package/packages/core/src/ports/forge/git-blob.ts +15 -0
- package/packages/core/src/ports/forge/github.ts +82 -0
- package/packages/core/src/ports/forge/local-git.ts +61 -1
- package/packages/core/src/ports/forge-failure.ts +24 -0
- package/packages/core/src/ports/runner/antigravity-test.fixture.ts +149 -0
- package/packages/core/src/ports/runner/claude-test.fixture.ts +71 -0
- package/packages/core/src/ports/runner/codex-test.fixture.ts +63 -0
- package/packages/core/src/ports/tickets/contract.ts +71 -0
- package/packages/core/src/ports/tickets/fake.ts +11 -0
- package/packages/core/src/ports/tickets/file.ts +18 -0
- package/packages/core/src/ports/tickets/github-fake.ts +136 -4
- package/packages/core/src/ports/tickets/github.ts +387 -30
- package/packages/core/src/ports/tickets/hosted-index.ts +10 -0
- package/packages/core/src/ports/tickets/linear.ts +130 -0
- package/packages/core/src/ports/tickets/priority.ts +9 -0
- package/packages/core/src/ports/tickets/remote-protocol.ts +34 -0
- package/packages/core/src/ports/tickets/remote.ts +70 -6
- package/packages/core/src/ports/tickets/search.ts +139 -0
- package/packages/core/src/ports/types.ts +104 -2
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +9 -0
- package/packages/core/src/ports/workspace/create.ts +15 -1
- package/packages/core/src/ports/workspace/fake.ts +340 -12
- package/packages/core/src/ports/workspace/git-worktree.ts +833 -42
- package/packages/core/src/ports/workspace/operator-sandbox.ts +129 -12
- package/packages/core/src/ports/workspace/process-group.ts +48 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +1260 -123
- package/packages/core/src/processes/agent-context-assemble.ts +576 -0
- package/packages/core/src/processes/agent-context.ts +469 -0
- package/packages/core/src/processes/build-runner.ts +387 -236
- package/packages/core/src/processes/dispatcher.ts +211 -55
- package/packages/core/src/processes/execution-no-progress.ts +4 -0
- package/packages/core/src/processes/optimization-activity.ts +120 -0
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/repo-view.ts +78 -2
- package/packages/core/src/processes/sandbox-state.ts +53 -6
- package/packages/core/src/processes/tick-publication.ts +2 -0
- package/packages/core/src/processes/workspace-preparation.ts +76 -0
- package/packages/core/src/scenarios/harness.ts +0 -5
- package/packages/core/src/store/account-redaction.ts +1 -0
- package/packages/core/src/store/adapter.ts +52 -1
- package/packages/core/src/store/agent-context.ts +432 -0
- package/packages/core/src/store/build-feed.ts +291 -0
- package/packages/core/src/store/build-scope.ts +19 -1
- package/packages/core/src/store/contract.ts +911 -14
- package/packages/core/src/store/digest.ts +19 -6
- package/packages/core/src/store/histogram.ts +113 -0
- package/packages/core/src/store/local/schema.ts +62 -0
- package/packages/core/src/store/local/store.ts +628 -22
- package/packages/core/src/store/local/ticket-asset-heads.ts +23 -0
- package/packages/core/src/store/memory.ts +461 -69
- package/packages/core/src/store/open-builds.ts +19 -0
- package/packages/core/src/store/phase-session.ts +32 -4
- package/packages/core/src/store/reduced-reads.ts +14 -4
- package/packages/core/src/store/reducer-value-shapes.json +7027 -5751
- package/packages/core/src/store/reducer-values.ts +6 -1
- package/packages/core/src/store/remote/client.ts +208 -2
- package/packages/core/src/store/remote/compatibility.ts +1 -1
- package/packages/core/src/store/remote/index.ts +33 -0
- package/packages/core/src/store/remote/protocol.ts +69 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.11.0.json +35680 -0
- package/packages/core/src/store/remote/released-reducer-values/1.11.1.json +35718 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
- package/packages/core/src/store/retention.ts +23 -1
- package/packages/core/src/store/rollups.ts +337 -0
- package/packages/core/src/store/session-handle.ts +20 -2
- package/packages/core/src/store/snapshots.ts +10 -0
- package/packages/core/src/store/types.ts +108 -9
- package/packages/core/src/testing/dispatch-journals.ts +117 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +1092 -2
- package/packages/core/src/testing/git-config-isolation.ts +7 -5
- package/packages/core/src/testing/index.ts +27 -0
- package/packages/core/src/testing/memory-operator-sandbox.ts +346 -0
- package/packages/core/src/testing/reduced-read-budget.ts +1873 -98
- package/packages/core/src/web/analytics-source.ts +303 -0
- package/packages/core/src/web/assets/Atkinson-OFL.txt +93 -0
- package/packages/core/src/web/assets/AtkinsonHyperlegibleNext.latin.woff2 +0 -0
- package/packages/core/src/web/assets/JetBrains-OFL.txt +93 -0
- package/packages/core/src/web/assets/JetBrainsMono.latin.woff2 +0 -0
- package/packages/core/src/web/assets/app.css +1 -0
- package/packages/core/src/web/assets/app.js +9 -0
- package/packages/core/src/web/assets/manifest.json +31 -0
- package/packages/core/src/web/assets/theme.js +1 -0
- package/packages/core/src/web/bounded.ts +31 -0
- package/packages/core/src/web/http.ts +315 -0
- package/packages/core/src/web/hub.ts +160 -0
- package/packages/core/src/web/options.ts +38 -0
- package/packages/core/src/web/overview-source.ts +322 -0
- package/packages/core/src/web/page.ts +56 -0
- package/packages/core/src/web/protocol.ts +151 -0
- package/packages/core/src/web/read-only.ts +23 -0
- package/packages/core/src/web/repository-source.ts +39 -0
- package/packages/core/src/web/server.ts +97 -0
- package/skills/code-review/SKILL.md +10 -2
- package/skills/guide/SKILL.md +376 -54
- package/skills/guide/references/accounts.md +2 -1
- package/skills/guide/references/integration-tree.md +2 -2
- package/skills/guide/references/operator-api.md +134 -6
- package/skills/guide/references/optimization-nodes.md +69 -11
- package/skills/guide/references/plugin-authoring.md +37 -1
- package/skills/guide/references/remote-store-protocol.md +94 -13
- package/skills/guide/references/remote-ticket-protocol.md +40 -0
- package/skills/guide/references/restacking.md +20 -4
- package/skills/guide/references/setup.md +14 -2
- package/skills/guide/references/ticket-dependencies.md +10 -3
- package/skills/implement/SKILL.md +23 -4
- package/skills/operate/SKILL.md +134 -32
- package/skills/plan/SKILL.md +10 -4
- package/skills/plan-review/SKILL.md +9 -2
- package/skills/spec/SKILL.md +34 -8
- package/skills/tickets/SKILL.md +51 -5
- package/templates/hosted-service/package.json +2 -2
|
@@ -22,6 +22,13 @@ import { relaunchTarget } from './execution-relaunch'
|
|
|
22
22
|
import { runtimeIdentity } from '../runtime-identity'
|
|
23
23
|
import { publishExact } from '../kernel/publication'
|
|
24
24
|
import { leafVerifiedRestack } from '../kernel/verify-stages'
|
|
25
|
+
import { leafBaseInUse } from '../kernel/leaf-restack-base'
|
|
26
|
+
import {
|
|
27
|
+
classifyAcceptedLocal,
|
|
28
|
+
openPublishingOwner,
|
|
29
|
+
reprovisionResume,
|
|
30
|
+
targetRewriteQuestion,
|
|
31
|
+
} from '../kernel/target-rewrite-recovery'
|
|
25
32
|
import { waitResumeSupersedes } from '../kernel/ticket-wait'
|
|
26
33
|
import {
|
|
27
34
|
deferMixedVersion,
|
|
@@ -69,7 +76,6 @@ import {
|
|
|
69
76
|
requireRewrite,
|
|
70
77
|
} from '../kernel/reconcile-restack'
|
|
71
78
|
import { RetainedHistoryUnavailable, restoreRetainedHead } from '../kernel/history-retention'
|
|
72
|
-
import { reconcileHead, reconcileRewriteHead } from '../kernel/reconcile-head'
|
|
73
79
|
import {
|
|
74
80
|
readBuildFacts,
|
|
75
81
|
readBuildSelector,
|
|
@@ -130,7 +136,6 @@ import type { EventPayload } from '../events/payloads'
|
|
|
130
136
|
import { KERNEL, agentActor, type Actor } from '../events/envelope'
|
|
131
137
|
import type { IdSource } from '../ids'
|
|
132
138
|
import { decideNextFromFacts, type Decision } from '../kernel/engine'
|
|
133
|
-
import { defineReducer } from '../kernel/incremental'
|
|
134
139
|
import { continuesVerifyCycle } from '../kernel/pr-summary'
|
|
135
140
|
import { isPhaseTerminalEvent, PHASE_SPECS } from '../kernel/phases'
|
|
136
141
|
import type { BuildState } from '../kernel/reducer'
|
|
@@ -168,7 +173,6 @@ import { BUILD_EXECUTION_LEASE_TTL_MS } from '../ports/workspace/build-execution
|
|
|
168
173
|
import { phaseScratchRejection, scratchPathsTouchedInRange } from '../ports/workspace/phase-scratch'
|
|
169
174
|
import type { Exec } from '../ports/workspace/git-worktree'
|
|
170
175
|
import type { BuildScopedStore, Clock } from '../store/types'
|
|
171
|
-
import { resetsPhaseFailureBudget, type PhaseFailureResetEscalation } from './phase-failure-budget'
|
|
172
176
|
import {
|
|
173
177
|
attemptPanelId,
|
|
174
178
|
baselineMeasurementDue,
|
|
@@ -184,6 +188,7 @@ import {
|
|
|
184
188
|
progressMeasurementDue,
|
|
185
189
|
} from '../kernel/measurement'
|
|
186
190
|
import { runPairedMeasurement, type MeasurementResult } from './measurement-runner'
|
|
191
|
+
import { preparationStale, type WorkspacePreparation } from './workspace-preparation'
|
|
187
192
|
import { JUDGE_ROLE } from '../config/roles'
|
|
188
193
|
import type { PanelMetric } from '../objective'
|
|
189
194
|
import type { PanelJudgeOutcome, PanelOrder } from '../kernel/panel'
|
|
@@ -490,202 +495,17 @@ function providerAttemptSummary(attempts: readonly ProviderAttempt[] | undefined
|
|
|
490
495
|
)
|
|
491
496
|
}
|
|
492
497
|
|
|
493
|
-
export interface PhaseFailureTally {
|
|
494
|
-
count: number
|
|
495
|
-
lastError?: string
|
|
496
|
-
lastWillRetry?: boolean
|
|
497
|
-
lastProviderAttempts?: readonly ProviderAttempt[]
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* phase.failed tally for one phase+round — D5's retry-guard input. A factory
|
|
502
|
-
* because phase and round are parameters of the projection.
|
|
503
|
-
*
|
|
504
|
-
* An answered escalation re-arms this budget only when its semantic class
|
|
505
|
-
* acknowledges phase-runner failures (§15.6-B). Runner-failure causes reset
|
|
506
|
-
* their matching round, the phase-level verify cause resets all rounds, and
|
|
507
|
-
* unrelated policy causes reset nothing. Cause-less historical and
|
|
508
|
-
* non-policy raises retain the legacy round-shaped behavior. Failures after
|
|
509
|
-
* an applicable answer count again, so a still-failing phase re-escalates on
|
|
510
|
-
* new evidence instead of deadlocking before its recovery session starts.
|
|
511
|
-
*/
|
|
512
|
-
export function phaseFailuresReducer(phase: Phase, round: number) {
|
|
513
|
-
return defineReducer<
|
|
514
|
-
{
|
|
515
|
-
/** id → the raise's reset semantics — answers are matched by id (§15.3). */
|
|
516
|
-
raised: Record<string, PhaseFailureResetEscalation & { session?: string }>
|
|
517
|
-
owners: Record<string, string>
|
|
518
|
-
cancelled: Record<string, boolean>
|
|
519
|
-
count: number
|
|
520
|
-
lastError?: string
|
|
521
|
-
lastWillRetry?: boolean
|
|
522
|
-
lastProviderAttempts?: readonly ProviderAttempt[]
|
|
523
|
-
},
|
|
524
|
-
AbEvent,
|
|
525
|
-
PhaseFailureTally
|
|
526
|
-
>({
|
|
527
|
-
identity: 'phaseFailures',
|
|
528
|
-
initial: () => ({ raised: {}, owners: {}, cancelled: {}, count: 0 }),
|
|
529
|
-
fold(acc, events) {
|
|
530
|
-
for (const event of events) {
|
|
531
|
-
switch (event.type) {
|
|
532
|
-
case 'session.started':
|
|
533
|
-
if (event.payload.phase?.startsWith('verify:') && event.payload.round !== undefined)
|
|
534
|
-
acc.owners[event.payload.session] = verifyMemberKey(
|
|
535
|
-
event.payload.phase.slice(7),
|
|
536
|
-
event.payload.round,
|
|
537
|
-
)
|
|
538
|
-
break
|
|
539
|
-
case 'verify.cancelled':
|
|
540
|
-
acc.cancelled[verifyMemberKey(event.payload.step, event.payload.attempt)] = true
|
|
541
|
-
break
|
|
542
|
-
case 'phase.deferral-escalated':
|
|
543
|
-
acc.raised[event.payload.id] = {
|
|
544
|
-
phase: event.payload.phase,
|
|
545
|
-
round: event.payload.round,
|
|
546
|
-
source: 'policy',
|
|
547
|
-
deferral: 'own-build-read',
|
|
548
|
-
}
|
|
549
|
-
break
|
|
550
|
-
// A ticket wait's escalation (`wait.entered`) is deliberately not
|
|
551
|
-
// registered: ending a wait is not a failure retry, so its answer
|
|
552
|
-
// re-arms no budget.
|
|
553
|
-
case 'escalation.raised':
|
|
554
|
-
acc.raised[event.payload.id] = {
|
|
555
|
-
phase: event.payload.phase,
|
|
556
|
-
source: event.payload.source,
|
|
557
|
-
...(event.actor.kind === 'agent' ? { session: event.actor.session } : {}),
|
|
558
|
-
...(event.payload.policyCause !== undefined
|
|
559
|
-
? { policyCause: event.payload.policyCause }
|
|
560
|
-
: {}),
|
|
561
|
-
...(event.payload.round !== undefined ? { round: event.payload.round } : {}),
|
|
562
|
-
}
|
|
563
|
-
break
|
|
564
|
-
case 'escalation.answered': {
|
|
565
|
-
const raise = acc.raised[event.payload.id]
|
|
566
|
-
if (raise?.session && acc.cancelled[acc.owners[raise.session] ?? '']) break
|
|
567
|
-
if (raise !== undefined && resetsPhaseFailureBudget(raise, phase, round)) {
|
|
568
|
-
acc.count = 0
|
|
569
|
-
delete acc.lastError
|
|
570
|
-
delete acc.lastWillRetry
|
|
571
|
-
delete acc.lastProviderAttempts
|
|
572
|
-
}
|
|
573
|
-
break
|
|
574
|
-
}
|
|
575
|
-
case 'phase.failed':
|
|
576
|
-
if (event.payload.phase === phase && event.payload.round === round) {
|
|
577
|
-
acc.count += 1
|
|
578
|
-
acc.lastError = event.payload.error
|
|
579
|
-
acc.lastWillRetry = event.payload.willRetry
|
|
580
|
-
acc.lastProviderAttempts = event.payload.providerAttempts
|
|
581
|
-
}
|
|
582
|
-
break
|
|
583
|
-
default:
|
|
584
|
-
break
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
},
|
|
588
|
-
finish: (acc) => ({
|
|
589
|
-
count: acc.count,
|
|
590
|
-
...(acc.lastError !== undefined ? { lastError: acc.lastError } : {}),
|
|
591
|
-
...(acc.lastWillRetry !== undefined ? { lastWillRetry: acc.lastWillRetry } : {}),
|
|
592
|
-
...(acc.lastProviderAttempts !== undefined
|
|
593
|
-
? { lastProviderAttempts: acc.lastProviderAttempts }
|
|
594
|
-
: {}),
|
|
595
|
-
}),
|
|
596
|
-
})
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
/** Consecutive durable setup failures since the latest successful attachment
|
|
600
|
-
* or explicit human answer. The accumulator keeps the boundary seq and the
|
|
601
|
-
* failure seqs, so it is exact for any array order. */
|
|
602
|
-
export const setupStreakReducer = defineReducer<
|
|
603
|
-
{ escalations: string[]; boundary: number; failures: number[] },
|
|
604
|
-
AbEvent,
|
|
605
|
-
number
|
|
606
|
-
>({
|
|
607
|
-
identity: 'setupStreak',
|
|
608
|
-
initial: () => ({ escalations: [], boundary: 0, failures: [] }),
|
|
609
|
-
fold(acc, events) {
|
|
610
|
-
for (const event of events) {
|
|
611
|
-
if (event.type === 'runner.attached') acc.boundary = event.seq
|
|
612
|
-
else if (
|
|
613
|
-
event.type === 'escalation.raised' &&
|
|
614
|
-
event.payload.phase === 'setup' &&
|
|
615
|
-
event.payload.source === 'policy'
|
|
616
|
-
) {
|
|
617
|
-
if (!acc.escalations.includes(event.payload.id)) acc.escalations.push(event.payload.id)
|
|
618
|
-
} else if (
|
|
619
|
-
event.type === 'escalation.answered' &&
|
|
620
|
-
acc.escalations.includes(event.payload.id)
|
|
621
|
-
) {
|
|
622
|
-
acc.boundary = event.seq
|
|
623
|
-
} else if (event.type === 'runner.setup-failed') {
|
|
624
|
-
acc.failures.push(event.seq)
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
},
|
|
628
|
-
finish: (acc) => acc.failures.filter((seq) => seq > acc.boundary).length,
|
|
629
|
-
})
|
|
630
|
-
|
|
631
|
-
/** Latest event-checkpointed branch head that kernel plumbing published;
|
|
632
|
-
* undefined while the build has none. */
|
|
633
|
-
export const publishedBranchHeadReducer = defineReducer<
|
|
634
|
-
{ head?: string },
|
|
635
|
-
AbEvent,
|
|
636
|
-
string | undefined
|
|
637
|
-
>({
|
|
638
|
-
identity: 'publishedBranchHead',
|
|
639
|
-
initial: () => ({}),
|
|
640
|
-
fold(acc, events) {
|
|
641
|
-
for (const event of events) {
|
|
642
|
-
if (event.type === 'implement.completed') {
|
|
643
|
-
acc.head = event.payload.commits.head
|
|
644
|
-
} else if (event.type === 'restack.rewritten' || event.type === 'restack.completed') {
|
|
645
|
-
acc.head =
|
|
646
|
-
event.type === 'restack.rewritten'
|
|
647
|
-
? (event.payload.observedHead ?? event.payload.headSha)
|
|
648
|
-
: event.payload.headSha
|
|
649
|
-
} else if (event.type === 'reconcile.rewritten') {
|
|
650
|
-
acc.head = reconcileRewriteHead(event.payload)
|
|
651
|
-
} else if (event.type === 'reconcile.completed') {
|
|
652
|
-
acc.head = reconcileHead(event.payload)
|
|
653
|
-
} else if (
|
|
654
|
-
event.type === 'wait.requested' &&
|
|
655
|
-
event.payload.publication?.settlement === 'published'
|
|
656
|
-
) {
|
|
657
|
-
acc.head = event.payload.publication.sha
|
|
658
|
-
} else if (event.type === 'wait.published') {
|
|
659
|
-
acc.head = event.payload.sha
|
|
660
|
-
} else if (
|
|
661
|
-
event.type === 'finalize.step-completed' &&
|
|
662
|
-
event.payload.ok &&
|
|
663
|
-
event.payload.headSha !== undefined
|
|
664
|
-
) {
|
|
665
|
-
acc.head = event.payload.headSha
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
},
|
|
669
|
-
finish: (acc) => acc.head,
|
|
670
|
-
})
|
|
671
|
-
|
|
672
|
-
/** Latest event-checkpointed branch head that kernel plumbing published. */
|
|
673
|
-
export function selectPublishedBranchHead(events: readonly AbEvent[]): string {
|
|
674
|
-
const head = publishedBranchHeadReducer.reduce(events)
|
|
675
|
-
if (head === undefined) {
|
|
676
|
-
throw new Error(
|
|
677
|
-
'finalize publication requires a prior implement.completed, reconcile.completed, ' +
|
|
678
|
-
'or successful finalize publication head, but this build has none',
|
|
679
|
-
)
|
|
680
|
-
}
|
|
681
|
-
return head
|
|
682
|
-
}
|
|
683
|
-
|
|
684
498
|
export {
|
|
685
499
|
selectVerifyDiffBase,
|
|
686
500
|
VERIFY_BASE_ENV,
|
|
687
501
|
verifyDiffBaseReducer,
|
|
688
502
|
} from '../kernel/verify-diff-base'
|
|
503
|
+
export { type PhaseFailureTally, phaseFailuresReducer } from '../kernel/phase-failures'
|
|
504
|
+
export {
|
|
505
|
+
publishedBranchHeadReducer,
|
|
506
|
+
selectPublishedBranchHead,
|
|
507
|
+
} from '../kernel/published-branch-head'
|
|
508
|
+
export { setupStreakReducer } from '../kernel/setup-streak'
|
|
689
509
|
|
|
690
510
|
/**
|
|
691
511
|
* The commit verification compares against: a node's integration cycle
|
|
@@ -1018,6 +838,9 @@ export class BuildRunner {
|
|
|
1018
838
|
private readonly streamSessions: boolean
|
|
1019
839
|
private readonly onDiagnostic: (message: string) => void
|
|
1020
840
|
private attached = false
|
|
841
|
+
/** The base this process's own setup run prepared the workspace for;
|
|
842
|
+
* undefined when setup is unconfigured or the runner is unattached. */
|
|
843
|
+
private preparedFor: WorkspacePreparation | undefined
|
|
1021
844
|
private cancelHeartbeat: (() => void) | undefined
|
|
1022
845
|
/** Set when a heartbeat reports the lease lapsed (§7.4): the store never
|
|
1023
846
|
* renews an expired lease, so the holder must re-claim before doing any
|
|
@@ -1321,44 +1144,10 @@ export class BuildRunner {
|
|
|
1321
1144
|
}, this.heartbeatMs)
|
|
1322
1145
|
|
|
1323
1146
|
const setup = config.commands.setup
|
|
1147
|
+
const preparedBase = verifyDiffBaseFrom(facts)
|
|
1324
1148
|
if (setup !== undefined) {
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
const result = await this.deps.exec(['sh', '-c', setup], {
|
|
1328
|
-
cwd: this.deps.workspacePath,
|
|
1329
|
-
})
|
|
1330
|
-
if (result.exitCode !== 0) {
|
|
1331
|
-
failure = {
|
|
1332
|
-
command: setup,
|
|
1333
|
-
attempt: streak + 1,
|
|
1334
|
-
exitStatus: result.exitCode,
|
|
1335
|
-
output: [result.stderr, result.stdout].filter((text) => text !== '').join('\n'),
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
} catch (error) {
|
|
1339
|
-
failure = {
|
|
1340
|
-
command: setup,
|
|
1341
|
-
attempt: streak + 1,
|
|
1342
|
-
exitStatus: null,
|
|
1343
|
-
output: errorMessage(error),
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
if (failure !== undefined) {
|
|
1348
|
-
try {
|
|
1349
|
-
await store.append(slug, {
|
|
1350
|
-
actor: KERNEL,
|
|
1351
|
-
type: 'runner.setup-failed',
|
|
1352
|
-
payload: failure,
|
|
1353
|
-
} satisfies EventWrite<'runner.setup-failed'>)
|
|
1354
|
-
const exhausted = failure.attempt >= config.policy.maxSetupAttempts
|
|
1355
|
-
if (exhausted) await this.raiseSetupEscalation(failure)
|
|
1356
|
-
throw new SetupFailureError(slug, failure, exhausted)
|
|
1357
|
-
} finally {
|
|
1358
|
-
this.stopHeartbeat()
|
|
1359
|
-
this.attached = false
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1149
|
+
const failure = await this.executeSetup(setup, streak + 1)
|
|
1150
|
+
if (failure !== undefined) await this.failSetup(failure, config)
|
|
1362
1151
|
}
|
|
1363
1152
|
|
|
1364
1153
|
if (recovering) {
|
|
@@ -1368,13 +1157,82 @@ export class BuildRunner {
|
|
|
1368
1157
|
} catch (error) {
|
|
1369
1158
|
this.stopHeartbeat()
|
|
1370
1159
|
this.attached = false
|
|
1160
|
+
this.preparedFor = undefined
|
|
1371
1161
|
throw error
|
|
1372
1162
|
}
|
|
1373
1163
|
}
|
|
1164
|
+
this.preparedFor = setup === undefined ? undefined : { base: preparedBase }
|
|
1374
1165
|
this.attached = true
|
|
1375
1166
|
return { kind: 'workspace-ready' }
|
|
1376
1167
|
}
|
|
1377
1168
|
|
|
1169
|
+
/** Run `[commands].setup` in the workspace; the failure payload, if any. */
|
|
1170
|
+
private async executeSetup(
|
|
1171
|
+
setup: string,
|
|
1172
|
+
attempt: number,
|
|
1173
|
+
): Promise<EventPayload<'runner.setup-failed'> | undefined> {
|
|
1174
|
+
try {
|
|
1175
|
+
const result = await this.deps.exec(['sh', '-c', setup], {
|
|
1176
|
+
cwd: this.deps.workspacePath,
|
|
1177
|
+
})
|
|
1178
|
+
if (result.exitCode === 0) return undefined
|
|
1179
|
+
return {
|
|
1180
|
+
command: setup,
|
|
1181
|
+
attempt,
|
|
1182
|
+
exitStatus: result.exitCode,
|
|
1183
|
+
output: [result.stderr, result.stdout].filter((text) => text !== '').join('\n'),
|
|
1184
|
+
}
|
|
1185
|
+
} catch (error) {
|
|
1186
|
+
return { command: setup, attempt, exitStatus: null, output: errorMessage(error) }
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Record a setup failure durably, raise the policy blocker at the attempt
|
|
1192
|
+
* limit, and leave the runner unattached. Always throws `SetupFailureError`:
|
|
1193
|
+
* only a later successful setup (`runner.attached`) clears the failure.
|
|
1194
|
+
*/
|
|
1195
|
+
private async failSetup(
|
|
1196
|
+
failure: EventPayload<'runner.setup-failed'>,
|
|
1197
|
+
config: Config,
|
|
1198
|
+
): Promise<never> {
|
|
1199
|
+
const { store, slug } = this.deps
|
|
1200
|
+
try {
|
|
1201
|
+
await store.append(slug, {
|
|
1202
|
+
actor: KERNEL,
|
|
1203
|
+
type: 'runner.setup-failed',
|
|
1204
|
+
payload: failure,
|
|
1205
|
+
} satisfies EventWrite<'runner.setup-failed'>)
|
|
1206
|
+
const exhausted = failure.attempt >= config.policy.maxSetupAttempts
|
|
1207
|
+
if (exhausted) await this.raiseSetupEscalation(failure)
|
|
1208
|
+
throw new SetupFailureError(slug, failure, exhausted)
|
|
1209
|
+
} finally {
|
|
1210
|
+
this.stopHeartbeat()
|
|
1211
|
+
this.attached = false
|
|
1212
|
+
this.preparedFor = undefined
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* Rerun setup before a workspace-using decision when a kernel operation
|
|
1218
|
+
* moved the build onto a new base since this process prepared it
|
|
1219
|
+
* (§15.6-C). Compares against facts `step()` already read; the only store
|
|
1220
|
+
* read is the setup streak, once per base move.
|
|
1221
|
+
*/
|
|
1222
|
+
private async refreshPreparation(
|
|
1223
|
+
facts: Awaited<ReturnType<typeof readBuildFacts>>['value'],
|
|
1224
|
+
decision: Decision,
|
|
1225
|
+
config: Config,
|
|
1226
|
+
): Promise<void> {
|
|
1227
|
+
const setup = config.commands.setup
|
|
1228
|
+
const base = verifyDiffBaseFrom(facts)
|
|
1229
|
+
if (setup === undefined || !preparationStale(this.preparedFor, base, decision)) return
|
|
1230
|
+
const streak = await readBuildSelector(this.deps.store, this.deps.slug, 'setupStreak')
|
|
1231
|
+
const failure = await this.executeSetup(setup, streak + 1)
|
|
1232
|
+
if (failure !== undefined) await this.failSetup(failure, config)
|
|
1233
|
+
this.preparedFor = { base }
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1378
1236
|
/**
|
|
1379
1237
|
* One read→decide→execute cycle (§8): the unit-test surface. Returns the
|
|
1380
1238
|
* decision it executed; `wait` decisions execute nothing.
|
|
@@ -1395,6 +1253,7 @@ export class BuildRunner {
|
|
|
1395
1253
|
const config = await this.captureConfig()
|
|
1396
1254
|
const facts = (await readBuildFacts(store, slug)).value
|
|
1397
1255
|
const decision = decideNextFromFacts(facts.state, facts.log, config)
|
|
1256
|
+
await this.refreshPreparation(facts, decision, config)
|
|
1398
1257
|
// A requested measurement runs where the pipeline is otherwise parked.
|
|
1399
1258
|
const parked =
|
|
1400
1259
|
decision.kind === 'run-measurement' ||
|
|
@@ -1488,6 +1347,12 @@ export class BuildRunner {
|
|
|
1488
1347
|
case 'restack':
|
|
1489
1348
|
await this.restack(decision)
|
|
1490
1349
|
return decision
|
|
1350
|
+
case 'recover-target-rewrite':
|
|
1351
|
+
await this.recoverTargetRewrite()
|
|
1352
|
+
return decision
|
|
1353
|
+
case 'accept-target-rewrite':
|
|
1354
|
+
await this.acceptTargetRewrite(decision)
|
|
1355
|
+
return decision
|
|
1491
1356
|
case 'capture-reconcile-policy':
|
|
1492
1357
|
await store.append(slug, {
|
|
1493
1358
|
actor: KERNEL,
|
|
@@ -2737,8 +2602,17 @@ export class BuildRunner {
|
|
|
2737
2602
|
})
|
|
2738
2603
|
}
|
|
2739
2604
|
|
|
2740
|
-
/** Snapshot the frozen target in a build-private ref without tracking-ref
|
|
2605
|
+
/** Snapshot the frozen target in a build-private ref without tracking-ref
|
|
2606
|
+
* updates, then admit it through target observation. */
|
|
2741
2607
|
private async refreshReconcileBase(recordAccepted = false): Promise<string> {
|
|
2608
|
+
const { branch, sha } = await this.snapshotTargetBase()
|
|
2609
|
+
await this.admitReconcileBase(branch, sha, recordAccepted)
|
|
2610
|
+
return sha
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
/** Snapshot the frozen target in a build-private ref without tracking-ref
|
|
2614
|
+
* updates or observation: the caller decides what the snapshot means. */
|
|
2615
|
+
private async snapshotTargetBase(): Promise<{ branch: string; sha: string }> {
|
|
2742
2616
|
const baseBranch = await readBuildSelector(this.deps.store, this.deps.slug, 'baseBranch')
|
|
2743
2617
|
if (baseBranch === undefined) {
|
|
2744
2618
|
throw new Error(
|
|
@@ -2759,8 +2633,7 @@ export class BuildRunner {
|
|
|
2759
2633
|
`${this.deps.forge.name} base snapshot did not return a commit SHA: ${JSON.stringify(sha)}`,
|
|
2760
2634
|
)
|
|
2761
2635
|
}
|
|
2762
|
-
|
|
2763
|
-
return sha
|
|
2636
|
+
return { branch: baseBranch, sha }
|
|
2764
2637
|
}
|
|
2765
2638
|
|
|
2766
2639
|
const fetchArgs = [
|
|
@@ -2789,8 +2662,286 @@ export class BuildRunner {
|
|
|
2789
2662
|
`${resolved.stderr.trim() || sha || '(no output)'}`,
|
|
2790
2663
|
)
|
|
2791
2664
|
}
|
|
2792
|
-
|
|
2793
|
-
|
|
2665
|
+
return { branch: baseBranch, sha }
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
/** One git command in the workspace; throws on failure unless allowed. */
|
|
2669
|
+
private async workspaceGit(args: string[], allowFailure = false) {
|
|
2670
|
+
const result = await this.deps.exec(['git', ...args], { cwd: this.deps.workspacePath })
|
|
2671
|
+
if (result.exitCode !== 0 && !allowFailure)
|
|
2672
|
+
throw new Error(
|
|
2673
|
+
`git ${args.join(' ')} exited ${result.exitCode}: ${result.stderr.trim() || '(no output)'}`,
|
|
2674
|
+
)
|
|
2675
|
+
return result
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
private async localBranchHead(): Promise<string | undefined> {
|
|
2679
|
+
const result = await this.workspaceGit(
|
|
2680
|
+
['rev-parse', '-q', '--verify', `refs/heads/${this.deps.branch}^{commit}`],
|
|
2681
|
+
true,
|
|
2682
|
+
)
|
|
2683
|
+
return result.exitCode === 0 ? result.stdout.trim() : undefined
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
private async trackedTreeClean(): Promise<boolean> {
|
|
2687
|
+
return (
|
|
2688
|
+
(await this.workspaceGit(['status', '--porcelain', '--untracked-files=no'])).stdout.trim() ===
|
|
2689
|
+
''
|
|
2690
|
+
)
|
|
2691
|
+
}
|
|
2692
|
+
|
|
2693
|
+
/** `sha subject` of each commit in `from..to`, oldest first. */
|
|
2694
|
+
private async commitsBetween(from: string, to: string) {
|
|
2695
|
+
const out = (await this.workspaceGit(['log', '--reverse', '--format=%H %s', `${from}..${to}`]))
|
|
2696
|
+
.stdout
|
|
2697
|
+
return out
|
|
2698
|
+
.split('\n')
|
|
2699
|
+
.filter((line) => line.trim() !== '')
|
|
2700
|
+
.map((line) => {
|
|
2701
|
+
const space = line.indexOf(' ')
|
|
2702
|
+
return space < 0
|
|
2703
|
+
? { sha: line, subject: '' }
|
|
2704
|
+
: { sha: line.slice(0, space), subject: line.slice(space + 1) }
|
|
2705
|
+
})
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
private async isAncestor(ancestor: string, descendant: string): Promise<boolean> {
|
|
2709
|
+
const result = await this.workspaceGit(
|
|
2710
|
+
['merge-base', '--is-ancestor', ancestor, descendant],
|
|
2711
|
+
true,
|
|
2712
|
+
)
|
|
2713
|
+
if (result.exitCode === 0) return true
|
|
2714
|
+
if (result.exitCode === 1) return false
|
|
2715
|
+
throw new Error(
|
|
2716
|
+
`git merge-base --is-ancestor exited ${result.exitCode}: ${result.stderr.trim()}`,
|
|
2717
|
+
)
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
/**
|
|
2721
|
+
* Leave the `target-rewritten` wait (SPEC §7.4). An open no-work reset is
|
|
2722
|
+
* completed forward first. Otherwise a leaf with no work of its own (no
|
|
2723
|
+
* published head, no PR, no commits beyond its base in use, a clean tracked
|
|
2724
|
+
* tree) is reprovisioned from the current target through a durable
|
|
2725
|
+
* prepare → reset → recovered transaction; a leaf with work raises the
|
|
2726
|
+
* episode's one `policy/target-rewritten` escalation.
|
|
2727
|
+
*/
|
|
2728
|
+
private async recoverTargetRewrite(): Promise<void> {
|
|
2729
|
+
const { store, slug } = this.deps
|
|
2730
|
+
await this.closeProducerSessions()
|
|
2731
|
+
try {
|
|
2732
|
+
for (;;) {
|
|
2733
|
+
const current = await readBuildFacts(store, slug)
|
|
2734
|
+
const facts = current.value
|
|
2735
|
+
const prepared = facts.log.restack.reprovision
|
|
2736
|
+
if (prepared !== undefined) {
|
|
2737
|
+
await this.resumeReprovision(prepared)
|
|
2738
|
+
return
|
|
2739
|
+
}
|
|
2740
|
+
const rewrite = facts.log.restack.targetRewrite
|
|
2741
|
+
if (rewrite === undefined) return
|
|
2742
|
+
const base = facts.verifyDiffBase
|
|
2743
|
+
if (base === undefined) throw new Error('missing contribution base')
|
|
2744
|
+
const published = await readBuildSelector(store, slug, 'publishedBranchHead')
|
|
2745
|
+
const local = await this.localBranchHead()
|
|
2746
|
+
if (local === undefined) throw new Error(`missing local branch ${this.deps.branch}`)
|
|
2747
|
+
const commits = await this.commitsBetween(base, local)
|
|
2748
|
+
const clean = await this.trackedTreeClean()
|
|
2749
|
+
if (
|
|
2750
|
+
published !== undefined ||
|
|
2751
|
+
facts.state.pr !== undefined ||
|
|
2752
|
+
commits.length > 0 ||
|
|
2753
|
+
!clean
|
|
2754
|
+
) {
|
|
2755
|
+
await this.raiseTargetRewrite({
|
|
2756
|
+
previousSha: rewrite.previousSha,
|
|
2757
|
+
branch: rewrite.branch,
|
|
2758
|
+
sha: rewrite.sha,
|
|
2759
|
+
commits,
|
|
2760
|
+
...(published === undefined ? {} : { published }),
|
|
2761
|
+
...(facts.state.pr === undefined ? {} : { pr: facts.state.pr.number }),
|
|
2762
|
+
})
|
|
2763
|
+
return
|
|
2764
|
+
}
|
|
2765
|
+
const { sha } = await this.snapshotTargetBase()
|
|
2766
|
+
const written = await store.appendIfCurrent(slug, current.cursor, {
|
|
2767
|
+
actor: KERNEL,
|
|
2768
|
+
type: 'target.rewrite-reprovision-prepared',
|
|
2769
|
+
payload: {
|
|
2770
|
+
branch: rewrite.branch,
|
|
2771
|
+
previousSha: rewrite.previousSha,
|
|
2772
|
+
base,
|
|
2773
|
+
from: local,
|
|
2774
|
+
sha,
|
|
2775
|
+
},
|
|
2776
|
+
})
|
|
2777
|
+
// A concurrent observation or control: classify again from the log.
|
|
2778
|
+
if (!written) continue
|
|
2779
|
+
await this.assertAutomaticRewriteOwnership()
|
|
2780
|
+
await this.workspaceGit(['checkout', '-q', '-B', this.deps.branch, sha])
|
|
2781
|
+
await this.completeReprovision()
|
|
2782
|
+
return
|
|
2783
|
+
}
|
|
2784
|
+
} catch (error) {
|
|
2785
|
+
if (error instanceof AutomaticRewriteDeferred) return
|
|
2786
|
+
throw error
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
|
|
2790
|
+
/** Complete an open reprovision preparation forward, never re-classifying. */
|
|
2791
|
+
private async resumeReprovision(
|
|
2792
|
+
prepared: EventPayload<'target.rewrite-reprovision-prepared'>,
|
|
2793
|
+
): Promise<void> {
|
|
2794
|
+
const local = await this.localBranchHead()
|
|
2795
|
+
const clean = await this.trackedTreeClean()
|
|
2796
|
+
switch (reprovisionResume(prepared, local, clean)) {
|
|
2797
|
+
case 'complete':
|
|
2798
|
+
await this.completeReprovision()
|
|
2799
|
+
return
|
|
2800
|
+
case 'redo': {
|
|
2801
|
+
await this.assertAutomaticRewriteOwnership()
|
|
2802
|
+
let sha = prepared.sha
|
|
2803
|
+
const exists = async (oid: string) =>
|
|
2804
|
+
(await this.workspaceGit(['cat-file', '-e', `${oid}^{commit}`], true)).exitCode === 0
|
|
2805
|
+
if (!(await exists(sha))) {
|
|
2806
|
+
// A fresh guest may lack the prepared commit: refresh the snapshot,
|
|
2807
|
+
// else re-prepare from it with the same proven head.
|
|
2808
|
+
const fresh = await this.snapshotTargetBase()
|
|
2809
|
+
if (!(await exists(sha))) {
|
|
2810
|
+
sha = fresh.sha
|
|
2811
|
+
await this.deps.store.append(this.deps.slug, {
|
|
2812
|
+
actor: KERNEL,
|
|
2813
|
+
type: 'target.rewrite-reprovision-prepared',
|
|
2814
|
+
// The reduced preparation also carries its seq: name each
|
|
2815
|
+
// payload field so the strict schema sees only the fact.
|
|
2816
|
+
payload: {
|
|
2817
|
+
branch: prepared.branch,
|
|
2818
|
+
previousSha: prepared.previousSha,
|
|
2819
|
+
base: prepared.base,
|
|
2820
|
+
from: prepared.from,
|
|
2821
|
+
sha,
|
|
2822
|
+
},
|
|
2823
|
+
})
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
await this.workspaceGit(['checkout', '-q', '-B', this.deps.branch, sha])
|
|
2827
|
+
await this.completeReprovision()
|
|
2828
|
+
return
|
|
2829
|
+
}
|
|
2830
|
+
case 'unknown':
|
|
2831
|
+
await this.raiseTargetRewrite({
|
|
2832
|
+
previousSha: prepared.previousSha,
|
|
2833
|
+
branch: prepared.branch,
|
|
2834
|
+
sha: prepared.sha,
|
|
2835
|
+
commits: local === undefined ? [] : await this.commitsBetween(prepared.from, local),
|
|
2836
|
+
})
|
|
2837
|
+
return
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2841
|
+
/** Append the reset's completion from the open preparation, idempotently. */
|
|
2842
|
+
private async completeReprovision(): Promise<void> {
|
|
2843
|
+
const { store, slug } = this.deps
|
|
2844
|
+
for (;;) {
|
|
2845
|
+
const current = await readBuildFacts(store, slug)
|
|
2846
|
+
const prepared = current.value.log.restack.reprovision
|
|
2847
|
+
if (prepared === undefined) return
|
|
2848
|
+
const { seq: _seq, from: _from, ...payload } = prepared
|
|
2849
|
+
if (
|
|
2850
|
+
await store.appendIfCurrent(slug, current.cursor, {
|
|
2851
|
+
actor: KERNEL,
|
|
2852
|
+
type: 'target.rewrite-recovered',
|
|
2853
|
+
payload: { ...payload, recovery: 'reprovisioned' },
|
|
2854
|
+
})
|
|
2855
|
+
)
|
|
2856
|
+
return
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
/** Raise the episode's one operator question (or a refused accept's). */
|
|
2861
|
+
private async raiseTargetRewrite(
|
|
2862
|
+
input: Omit<Parameters<typeof targetRewriteQuestion>[0], 'slug'>,
|
|
2863
|
+
): Promise<void> {
|
|
2864
|
+
const { store, slug, ids } = this.deps
|
|
2865
|
+
const facts = (await readBuildFacts(store, slug)).value
|
|
2866
|
+
await store.append(slug, {
|
|
2867
|
+
actor: KERNEL,
|
|
2868
|
+
type: 'escalation.raised',
|
|
2869
|
+
payload: {
|
|
2870
|
+
id: ids('esc'),
|
|
2871
|
+
phase: facts.state.currentPhase?.phase ?? facts.state.lastCompletedPhase?.phase ?? 'setup',
|
|
2872
|
+
source: 'policy',
|
|
2873
|
+
policyCause: 'target-rewritten',
|
|
2874
|
+
question: targetRewriteQuestion({ slug, ...input }),
|
|
2875
|
+
},
|
|
2876
|
+
} satisfies EventWrite<'escalation.raised'>)
|
|
2877
|
+
}
|
|
2878
|
+
|
|
2879
|
+
/**
|
|
2880
|
+
* Record an operator's accept-target: waive the rejected base in use and
|
|
2881
|
+
* accept the current target. The engine restacks the build's published
|
|
2882
|
+
* commits at the new replay boundary. Unpublished local commits inside an
|
|
2883
|
+
* open publishing occurrence are named as `pendingLocal`, withholding the
|
|
2884
|
+
* boundary until that occurrence publishes them; local commits nothing owns
|
|
2885
|
+
* refuse the accept with a fresh escalation.
|
|
2886
|
+
*/
|
|
2887
|
+
private async acceptTargetRewrite(
|
|
2888
|
+
decision: Extract<Decision, { kind: 'accept-target-rewrite' }>,
|
|
2889
|
+
): Promise<void> {
|
|
2890
|
+
const { store, slug } = this.deps
|
|
2891
|
+
await this.closeProducerSessions()
|
|
2892
|
+
for (;;) {
|
|
2893
|
+
const current = await readBuildFacts(store, slug)
|
|
2894
|
+
const facts = current.value
|
|
2895
|
+
const rewrite = facts.log.restack.targetRewrite
|
|
2896
|
+
const prepared = facts.log.restack.reprovision
|
|
2897
|
+
if (rewrite === undefined && prepared === undefined) return
|
|
2898
|
+
const previousSha = rewrite?.previousSha ?? prepared!.previousSha
|
|
2899
|
+
const branch = rewrite?.branch ?? prepared!.branch
|
|
2900
|
+
const base = leafBaseInUse(facts.log)
|
|
2901
|
+
if (base === undefined) throw new Error('missing contribution base')
|
|
2902
|
+
const { sha } = await this.snapshotTargetBase()
|
|
2903
|
+
const published = await readBuildSelector(store, slug, 'publishedBranchHead')
|
|
2904
|
+
const local = await this.localBranchHead()
|
|
2905
|
+
if (local === undefined) throw new Error(`missing local branch ${this.deps.branch}`)
|
|
2906
|
+
const verdict = classifyAcceptedLocal({
|
|
2907
|
+
local,
|
|
2908
|
+
published,
|
|
2909
|
+
base,
|
|
2910
|
+
localInPublished: published !== undefined && (await this.isAncestor(local, published)),
|
|
2911
|
+
localDescends: await this.isAncestor(published ?? base, local),
|
|
2912
|
+
owner: openPublishingOwner(facts.state, facts.log),
|
|
2913
|
+
})
|
|
2914
|
+
if (verdict.kind === 'refuse') {
|
|
2915
|
+
const from = (await this.isAncestor(verdict.from, local))
|
|
2916
|
+
? verdict.from
|
|
2917
|
+
: (await this.workspaceGit(['merge-base', verdict.from, local], true)).stdout.trim() ||
|
|
2918
|
+
verdict.from
|
|
2919
|
+
await this.raiseTargetRewrite({
|
|
2920
|
+
previousSha,
|
|
2921
|
+
branch,
|
|
2922
|
+
sha,
|
|
2923
|
+
commits: await this.commitsBetween(from, local),
|
|
2924
|
+
...(published === undefined ? {} : { published }),
|
|
2925
|
+
...(facts.state.pr === undefined ? {} : { pr: facts.state.pr.number }),
|
|
2926
|
+
unowned: true,
|
|
2927
|
+
})
|
|
2928
|
+
return
|
|
2929
|
+
}
|
|
2930
|
+
const written = await store.appendIfCurrent(slug, current.cursor, {
|
|
2931
|
+
actor: KERNEL,
|
|
2932
|
+
type: 'target.rewrite-recovered',
|
|
2933
|
+
payload: {
|
|
2934
|
+
branch,
|
|
2935
|
+
previousSha,
|
|
2936
|
+
sha,
|
|
2937
|
+
base,
|
|
2938
|
+
recovery: 'accepted',
|
|
2939
|
+
escalation: decision.escalation,
|
|
2940
|
+
...(verdict.kind === 'pending' ? { pendingLocal: verdict.pendingLocal } : {}),
|
|
2941
|
+
},
|
|
2942
|
+
})
|
|
2943
|
+
if (written) return
|
|
2944
|
+
}
|
|
2794
2945
|
}
|
|
2795
2946
|
|
|
2796
2947
|
private async admitReconcileBase(
|