@defrex/autobuild 1.11.1 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +177 -54
  3. package/docs/answering-blocked-builds.md +10 -2
  4. package/docs/architecture.md +66 -6
  5. package/docs/assets/headline-wide.png +0 -0
  6. package/docs/configuration.md +13 -11
  7. package/docs/dispatcher.md +1 -1
  8. package/docs/integration-tree.md +28 -16
  9. package/docs/operator-api.md +4 -4
  10. package/docs/operator-surfaces.md +35 -0
  11. package/docs/optimization-nodes.md +3 -2
  12. package/docs/tickets.md +1 -1
  13. package/docs/troubleshooting.md +1 -1
  14. package/package.json +3 -3
  15. package/packages/core/src/cli/ambient-errors.ts +17 -0
  16. package/packages/core/src/cli/bounded-io.ts +174 -0
  17. package/packages/core/src/cli/dashboard/model.ts +81 -23
  18. package/packages/core/src/cli/dashboard/poll.ts +20 -31
  19. package/packages/core/src/cli/dashboard/render.ts +14 -37
  20. package/packages/core/src/cli/dashboard/row-text.ts +24 -7
  21. package/packages/core/src/cli/dashboard/tone-ansi.ts +39 -0
  22. package/packages/core/src/cli/dashboard/vocabulary.ts +161 -20
  23. package/packages/core/src/cli/dispatch-handoff.ts +41 -10
  24. package/packages/core/src/cli/dispatch-launch-contract.ts +5 -0
  25. package/packages/core/src/cli/dispatch-launcher-cadence.ts +80 -0
  26. package/packages/core/src/cli/dispatch-launcher.ts +9 -10
  27. package/packages/core/src/cli/dispatch-preflight.ts +12 -3
  28. package/packages/core/src/cli/dispatch-release-observer.ts +53 -0
  29. package/packages/core/src/cli/dispatch-runtime-cache.ts +204 -82
  30. package/packages/core/src/cli/dispatch-runtime-dependencies.ts +250 -43
  31. package/packages/core/src/cli/dispatch-upgrade-install.ts +36 -16
  32. package/packages/core/src/cli/dispatch-upgrade-source.ts +8 -2
  33. package/packages/core/src/cli/dispatch-yield-observer.ts +82 -0
  34. package/packages/core/src/cli/dispatch.ts +68 -5
  35. package/packages/core/src/cli/env.ts +2 -15
  36. package/packages/core/src/cli/help.ts +5 -4
  37. package/packages/core/src/cli/main.ts +4 -2
  38. package/packages/core/src/cli/production-store.ts +102 -0
  39. package/packages/core/src/cli/repo-state.ts +2 -3
  40. package/packages/core/src/cli/repository-status.ts +28 -22
  41. package/packages/core/src/cli/sessionless-store.ts +26 -0
  42. package/packages/core/src/cli/status.ts +169 -40
  43. package/packages/core/src/cli/store-opening.ts +15 -58
  44. package/packages/core/src/cli/store-ref.ts +6 -1
  45. package/packages/core/src/config/schema.ts +1 -1
  46. package/packages/core/src/distribution-packaging.ts +156 -18
  47. package/packages/core/src/events/catalog-identity.ts +28 -0
  48. package/packages/core/src/events/catalog.ts +3 -9
  49. package/packages/core/src/events/compatibility.ts +2 -30
  50. package/packages/core/src/events/payloads.ts +11 -0
  51. package/packages/core/src/events/policy.ts +3 -0
  52. package/packages/core/src/events/repository.ts +1 -1
  53. package/packages/core/src/events/sessions.ts +1 -1
  54. package/packages/core/src/events/validation-error.ts +12 -0
  55. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +9 -0
  56. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3064e337cc75f8d6.json +310 -0
  57. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a1e90a969d32a367.json +307 -0
  58. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/da3bc91c49211eab.json +310 -0
  59. package/packages/core/src/kernel/auto-merge-default.ts +2 -1
  60. package/packages/core/src/kernel/capacity-build.ts +21 -0
  61. package/packages/core/src/kernel/discard-in-flight.ts +13 -0
  62. package/packages/core/src/kernel/dispatch-capacity.ts +354 -147
  63. package/packages/core/src/kernel/engine.ts +2 -8
  64. package/packages/core/src/kernel/measurement.ts +24 -0
  65. package/packages/core/src/kernel/read-facts.ts +8 -370
  66. package/packages/core/src/kernel/reducer-registry.ts +40 -125
  67. package/packages/core/src/kernel/reducer-revisions.ts +3 -0
  68. package/packages/core/src/kernel/reducer-value-entry.ts +98 -0
  69. package/packages/core/src/kernel/reducer-value-index.ts +75 -0
  70. package/packages/core/src/kernel/reducer.ts +57 -9
  71. package/packages/core/src/kernel/reopen-state.ts +10 -0
  72. package/packages/core/src/kernel/repository-read-facts.ts +375 -0
  73. package/packages/core/src/kernel/verify-stage-state.ts +145 -3
  74. package/packages/core/src/operator/presentation.ts +13 -0
  75. package/packages/core/src/operator/query.ts +40 -39
  76. package/packages/core/src/operator/registry.ts +3 -3
  77. package/packages/core/src/ports/workspace/fake.ts +15 -3
  78. package/packages/core/src/processes/dispatcher.ts +232 -75
  79. package/packages/core/src/processes/execution-no-progress.ts +1 -0
  80. package/packages/core/src/store/local/capabilities.ts +115 -0
  81. package/packages/core/src/store/local/store.ts +86 -56
  82. package/packages/core/src/store/reduced-reads.ts +9 -1
  83. package/packages/core/src/store/reducer-value-read.ts +235 -0
  84. package/packages/core/src/store/reducer-value-shapes.json +1437 -1349
  85. package/packages/core/src/store/reducer-values.ts +36 -204
  86. package/packages/core/src/store/remote/released-clients.json +11 -0
  87. package/packages/core/src/store/remote/released-reducer-values/1.12.0.json +35806 -0
  88. package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
  89. package/packages/core/src/store/rollup-lease.ts +41 -0
  90. package/packages/core/src/store/rollups.ts +7 -38
  91. package/packages/core/src/store/snapshots.ts +1 -1
  92. package/packages/core/src/testing/dispatch-read-budget.ts +265 -4
  93. package/packages/core/src/testing/import-graph.ts +78 -0
  94. package/packages/core/src/testing/reduced-read-budget.ts +221 -22
  95. package/packages/core/src/testing/slot-agreement.ts +52 -0
  96. package/packages/core/src/web/assets/app.js +5 -5
  97. package/skills/guide/SKILL.md +115 -44
  98. package/skills/guide/references/integration-tree.md +28 -16
  99. package/skills/guide/references/operator-api.md +4 -4
  100. package/skills/guide/references/optimization-nodes.md +3 -2
  101. package/skills/operate/SKILL.md +38 -20
  102. package/templates/hosted-service/package.json +2 -2
@@ -5,7 +5,7 @@ import { verifyMemberKey } from './verify-stage-state'
5
5
  import { mixedVersionDeferred } from './mixed-version'
6
6
  import { integrationCurrent, integrationConfig, integrationFailed } from './integration-state'
7
7
  import { proposeRunDue, proposeStarted } from './optimization'
8
- import { reopenSpecPending } from './reopen-state'
8
+ import { reopenSpecPending, reviseSpecPending } from './reopen-state'
9
9
  /**
10
10
  * The kernel pipeline engine (SPEC §8): "read the event log, decide the next
11
11
  * phase per the transition table, invoke the AgentRunner with `/{skill}
@@ -501,13 +501,7 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
501
501
  // below. guidance and dismiss-finding resolutions do not decide anything
502
502
  // here — they route inside the loop rules (feedback priority and stall
503
503
  // suppression respectively).
504
- if (
505
- state.answeredEscalations.some(
506
- (e) => e.resolution === 'revise-spec' && e.answeredSeq > log.restartSeq,
507
- )
508
- ) {
509
- return { kind: 'wait', reason: 'awaiting-spec' }
510
- }
504
+ if (reviseSpecPending(state)) return { kind: 'wait', reason: 'awaiting-spec' }
511
505
 
512
506
  // ── 4. Spec (§6.3: dispatch owns the import; `spec` is not a phase §5) ─────
513
507
  if (state.specRev === undefined) return { kind: 'wait', reason: 'awaiting-spec' }
@@ -389,6 +389,30 @@ export function nodeMeasurementDue(state: BuildState): boolean {
389
389
  return baselineMeasurementDue(state) || progressMeasurementDue(state) !== undefined
390
390
  }
391
391
 
392
+ /** The key of the node measurement owed now, starting or progress, for slot
393
+ * accounting (SPEC §12 "What holds a slot"): `measure:baseline:<revision>:<pin>`
394
+ * or `measure:progress:<head>`. Unlike `nodeMeasurementDue` it is not gated
395
+ * on a pause or pending commands, so an admitted measurement keeps its slot
396
+ * until its runner acknowledges a requested pause or abort. Read from
397
+ * reduced state alone. */
398
+ export function nodeMeasurementNeed(state: BuildState): string | undefined {
399
+ const optimization = state.optimization
400
+ if (
401
+ state.kind !== 'node' ||
402
+ state.nodeOpened === undefined ||
403
+ optimization === undefined ||
404
+ terminal(state)
405
+ )
406
+ return undefined
407
+ if (optimization.starting === undefined)
408
+ return optimization.stopped === undefined
409
+ ? `measure:baseline:${optimization.revision}:${optimization.accepted.harnessPin}`
410
+ : undefined
411
+ const head = optimization.progressQueue?.[0]
412
+ if (optimization.objective.metric.kind !== 'panel' || head === undefined) return undefined
413
+ return `measure:progress:${head}`
414
+ }
415
+
392
416
  /** The deterministic id of the escalation a failed node panel raises. */
393
417
  export function nodePanelEscalationId(panelId: string): string {
394
418
  return `node-panel-failed-${panelId}`
@@ -1,14 +1,5 @@
1
- import { ticketPreparationReducer } from './ticket-preparation'
2
- import { ticketHandbacksReducer } from './ticket-handbacks'
3
- import { ticketStartsReducer } from './ticket-starts'
4
1
  import { ticketMigrationsReducer } from './ticket-migrations'
5
- import { dispatchUpgradeReducer } from './dispatch-upgrade'
6
- import {
7
- advanceCompatibility,
8
- initialCompatibility,
9
- projectEvents,
10
- type CompatibilityState,
11
- } from '../events/compatibility'
2
+ import { projectEvents } from '../events/compatibility'
12
3
  import { awaitsConsent } from './landing-readiness'
13
4
  import { leafRestackReducer, type LeafRestackState } from './leaf-restack-state'
14
5
  import { landingCandidateId } from './landing-policy'
@@ -621,364 +612,11 @@ export const buildReadFactsReducer = defineReducer({
621
612
  }),
622
613
  })
623
614
 
624
- import type { RepositoryEvent } from '../events/repository'
625
- import { repositoryAttentionReducer } from './repository-attention'
626
- import { dispatchSettingsReducer } from './dispatch-settings'
627
- import { harvestReducer } from './harvest'
628
- import { forgeCredentialLimitsReducer, forgeHealthReducer } from './forge-health'
629
- import { kernelGitHealthReducer } from './kernel-git'
630
- import { openPrBackpressureReducer } from './open-pr-backpressure-state'
631
- import { ticketSourceHealthReducer } from './ticket-source-health'
632
- import { autoMergeDefaultReducer } from './auto-merge-default'
633
- import { effectiveConfigReducer } from './service-facts'
634
- import { sandboxStatesReducer } from '../processes/sandbox-state'
635
- import { openHarvestExecutionsReducer } from '../processes/harvest-execution-state'
636
- import {
637
- dispatchStatusReducer,
638
- foldReportedDispatch,
639
- initialReportedDispatch,
615
+ export {
640
616
  RECENT_DISPATCH_RUN_LIMIT,
641
- type ReportedDispatch,
642
- } from './dispatch-status'
643
-
644
- export { RECENT_DISPATCH_RUN_LIMIT } from './dispatch-status'
645
- export interface RepositoryReadAcc {
646
- missingAccounts: Record<string, import('../accounts/availability').MissingAccountCredential>
647
- preparation: ReturnType<typeof ticketPreparationReducer.initial>
648
- handbacks: ReturnType<typeof ticketHandbacksReducer.initial>
649
- ticketStarts: ReturnType<typeof ticketStartsReducer.initial>
650
- compatibility: CompatibilityState
651
- presence: Record<
652
- string,
653
- Extract<RepositoryEvent, { type: 'change-presence.observed' }>['payload']
654
- >
655
-
656
- upgrades: ReturnType<typeof dispatchUpgradeReducer.initial>
657
- openHarvest: ReturnType<typeof openHarvestExecutionsReducer.initial>
658
- attention: ReturnType<typeof repositoryAttentionReducer.initial>
659
- harvestFailures: Record<
660
- string,
661
- { count: number; latest: Extract<RepositoryEvent, { type: 'harvest.failed' }> }
662
- >
663
- harvestTerminals: Record<
664
- string,
665
- Extract<RepositoryEvent, { type: 'harvest.proposals.submitted' | 'harvest.review.verdict' }>
666
- >
667
- harvestVerdicts: Record<
668
- string,
669
- {
670
- first: Extract<RepositoryEvent, { type: 'harvest.review.verdict' }>
671
- latest: Extract<RepositoryEvent, { type: 'harvest.review.verdict' }>
672
- }
673
- >
674
- harvestAuthorizations: Record<
675
- string,
676
- Extract<RepositoryEvent, { type: 'harvest.execution.authorized' }>
677
- >
678
- harvestExecutionStarts: Record<string, string>
679
- latestHarvestResumedSeq: number
680
- harvestSessionEndings: Record<string, number>
681
- harvestSessions: (import('../cli/harvest').HarvestSessionStatusView & { run: string })[]
682
- pendingHumanResume?: number
683
- dismissedThrough: number
684
- failedAt: Record<string, string>
685
- settings: ReturnType<typeof dispatchSettingsReducer.initial>
686
- harvest: ReturnType<typeof harvestReducer.initial>
687
- forgeHealth: ReturnType<typeof forgeHealthReducer.initial>
688
- forgeCredentialLimits: ReturnType<typeof forgeCredentialLimitsReducer.initial>
689
- kernelGit: ReturnType<typeof kernelGitHealthReducer.initial>
690
- openPrBackpressure: ReturnType<typeof openPrBackpressureReducer.initial>
691
- ticketMigrations: ReturnType<typeof ticketMigrationsReducer.initial>
692
- health: ReturnType<typeof ticketSourceHealthReducer.initial>
693
- autoMerge: ReturnType<typeof autoMergeDefaultReducer.initial>
694
- config: ReturnType<typeof effectiveConfigReducer.initial>
695
- sandboxes: ReturnType<typeof sandboxStatesReducer.initial>
696
- /** The dispatcher run the reduced status describes; see `foldReportedDispatch`. */
697
- dispatch: ReportedDispatch
698
- scanSeq?: number
699
- scan?: Extract<RepositoryEvent, { type: 'dispatcher.ticket-scan-completed' }>['payload']
700
- recentRuns: [string, DispatcherRunFacts][]
701
- latestRun?: string
702
- latestStoppedRun?: string
703
- publications: Extract<RepositoryEvent, { type: 'orchestrator.sandbox.published' }>[]
704
- }
705
- export const repositoryReadFactsReducer = defineReducer({
706
- rawEvents: true,
707
- identity: 'repositoryReadFacts',
708
- parts: [
709
- ticketMigrationsReducer,
710
- dispatchUpgradeReducer,
711
- ticketPreparationReducer,
712
- ticketHandbacksReducer,
713
- ticketStartsReducer,
714
- dispatcherRunFactsReducer('version'),
715
- openHarvestExecutionsReducer,
716
- forgeHealthReducer,
717
- forgeCredentialLimitsReducer,
718
- kernelGitHealthReducer,
719
- openPrBackpressureReducer,
720
- repositoryAttentionReducer,
721
- dispatchSettingsReducer,
722
- harvestReducer,
723
- ticketSourceHealthReducer,
724
- autoMergeDefaultReducer,
725
- effectiveConfigReducer,
726
- sandboxStatesReducer,
727
- dispatchStatusReducer('version'),
728
- ],
729
- initial: (): RepositoryReadAcc => ({
730
- missingAccounts: {},
731
- compatibility: initialCompatibility(),
732
- presence: {},
733
- preparation: ticketPreparationReducer.initial(),
734
- handbacks: ticketHandbacksReducer.initial(),
735
- ticketStarts: ticketStartsReducer.initial(),
736
- upgrades: dispatchUpgradeReducer.initial(),
737
- recentRuns: [],
738
- openHarvest: openHarvestExecutionsReducer.initial(),
739
- attention: repositoryAttentionReducer.initial(),
740
- dismissedThrough: 0,
741
- failedAt: {},
742
- harvestSessions: [],
743
- harvestSessionEndings: {},
744
- harvestFailures: {},
745
- harvestTerminals: {},
746
- harvestVerdicts: {},
747
- harvestAuthorizations: {},
748
- latestHarvestResumedSeq: 0,
749
- harvestExecutionStarts: {},
750
- settings: dispatchSettingsReducer.initial(),
751
- harvest: harvestReducer.initial(),
752
- forgeHealth: forgeHealthReducer.initial(),
753
- forgeCredentialLimits: forgeCredentialLimitsReducer.initial(),
754
- kernelGit: kernelGitHealthReducer.initial(),
755
- openPrBackpressure: openPrBackpressureReducer.initial(),
756
- ticketMigrations: ticketMigrationsReducer.initial(),
757
- health: ticketSourceHealthReducer.initial(),
758
- autoMerge: autoMergeDefaultReducer.initial(),
759
- config: effectiveConfigReducer.initial(),
760
- sandboxes: sandboxStatesReducer.initial(),
761
- dispatch: initialReportedDispatch(),
762
- publications: [],
763
- }),
764
- fold(acc: RepositoryReadAcc, events: readonly RepositoryEvent[]) {
765
- acc.preparation = ticketPreparationReducer.advance(acc.preparation, events)
766
- acc.handbacks = ticketHandbacksReducer.advance(acc.handbacks, events)
767
- acc.ticketStarts = ticketStartsReducer.advance(acc.ticketStarts, events)
768
- advanceCompatibility(acc.compatibility, events)
769
- acc.upgrades = dispatchUpgradeReducer.advance(acc.upgrades, events)
770
- acc.attention = repositoryAttentionReducer.advance(acc.attention, events)
771
- acc.openHarvest = openHarvestExecutionsReducer.advance(acc.openHarvest, events)
772
- acc.settings = dispatchSettingsReducer.advance(acc.settings, events)
773
- acc.harvest = harvestReducer.advance(acc.harvest, events)
774
- acc.forgeHealth = forgeHealthReducer.advance(acc.forgeHealth, events)
775
- acc.forgeCredentialLimits = forgeCredentialLimitsReducer.advance(
776
- acc.forgeCredentialLimits,
777
- events,
778
- )
779
- acc.kernelGit = kernelGitHealthReducer.advance(acc.kernelGit, events)
780
- acc.openPrBackpressure = openPrBackpressureReducer.advance(acc.openPrBackpressure, events)
781
- acc.ticketMigrations = ticketMigrationsReducer.advance(acc.ticketMigrations, events)
782
- acc.health = ticketSourceHealthReducer.advance(acc.health, events)
783
- acc.autoMerge = autoMergeDefaultReducer.advance(acc.autoMerge, events)
784
- acc.config = effectiveConfigReducer.advance(acc.config, events)
785
- acc.sandboxes = sandboxStatesReducer.advance(acc.sandboxes, events)
786
- for (const event of projectEvents(events)) {
787
- if (event.type === 'account.credentials-unavailable')
788
- acc.missingAccounts[event.payload.name] = event.payload
789
- if (event.type === 'account.credentials-recovered')
790
- delete acc.missingAccounts[event.payload.name]
791
- if (event.type === 'change-presence.observed')
792
- acc.presence[event.payload.destination] = event.payload
793
- if (event.type === 'harvest.failed') {
794
- const key = JSON.stringify([event.payload.run, event.payload.step, event.payload.round])
795
- acc.harvestFailures[key] = {
796
- count: (acc.harvestFailures[key]?.count ?? 0) + 1,
797
- latest: event,
798
- }
799
- }
800
- if (
801
- (event.type === 'harvest.proposals.submitted' || event.type === 'harvest.review.verdict') &&
802
- event.actor.kind === 'agent'
803
- )
804
- acc.harvestTerminals[event.actor.session] = event
805
- if (event.type === 'harvest.review.verdict') {
806
- const key = JSON.stringify([event.payload.run, event.payload.round])
807
- acc.harvestVerdicts[key] = {
808
- first: acc.harvestVerdicts[key]?.first ?? event,
809
- latest: event,
810
- }
811
- }
812
- if (event.type === 'harvest.execution.started')
813
- acc.harvestExecutionStarts[String(event.seq)] = event.payload.execution
814
- if (event.type === 'harvest.execution.authorized')
815
- acc.harvestAuthorizations[JSON.stringify(event.payload.execution)] ??= event
816
- if (event.type === 'harvest.resumed') acc.latestHarvestResumedSeq = event.seq
817
- if (event.type === 'harvest.session.started' && event.payload.continuation) {
818
- const prior = acc.harvestSessions.find(
819
- (s) => s.session === event.payload.continuation!.predecessor,
820
- )
821
- if (prior) prior.status = 'ended'
822
- }
823
- if (event.type === 'harvest.session.started')
824
- acc.harvestSessions.push({
825
- run: event.payload.run,
826
- session: event.payload.session,
827
- role: event.payload.role,
828
- step: event.payload.step,
829
- round: event.payload.round,
830
- status: 'open',
831
- ...(event.payload.continuation ? { continuation: event.payload.continuation } : {}),
832
- ...(event.payload.stream === undefined ? {} : { stream: event.payload.stream }),
833
- streamStatus: event.payload.stream === undefined ? 'closed' : 'open',
834
- })
835
- if (event.type === 'harvest.session.ended' || event.type === 'harvest.session.suspended') {
836
- acc.harvestSessionEndings[JSON.stringify(event.payload.session)] ??= event.seq
837
- const session = acc.harvestSessions.findLast(
838
- (session) => session.session === event.payload.session && session.status === 'open',
839
- )
840
- if (session) {
841
- session.status = event.type === 'harvest.session.suspended' ? 'suspended' : 'ended'
842
- session.transcript = event.payload.transcript
843
- session.streamStatus = 'closed'
844
- }
845
- }
846
- if (event.type === 'harvest.resume-requested' && event.actor.kind === 'human')
847
- acc.pendingHumanResume = event.seq
848
- if (event.type === 'harvest.pause-requested') delete acc.pendingHumanResume
849
- if (event.type === 'harvest.resumed' && acc.pendingHumanResume !== undefined)
850
- acc.dismissedThrough = Math.max(acc.dismissedThrough, acc.pendingHumanResume)
851
- if (event.type === 'harvest.failed' && !event.payload.willRetry)
852
- acc.failedAt[JSON.stringify(event.payload.run)] = event.ts
853
- foldReportedDispatch(acc.dispatch, event)
854
- if (event.type === 'dispatcher.ticket-scan-completed') {
855
- acc.scan = event.payload
856
- acc.scanSeq = event.seq
857
- }
858
- if (event.type === 'dispatcher.run-started') acc.latestRun = event.payload.run
859
- if (event.type === 'dispatcher.run-stopped') acc.latestStoppedRun = event.payload.run
860
- if (
861
- event.type.startsWith('dispatcher.') &&
862
- 'run' in event.payload &&
863
- typeof event.payload.run === 'string'
864
- ) {
865
- const run = event.payload.run
866
- let entry = acc.recentRuns.find(([id]) => id === run)
867
- if (!entry) {
868
- entry = [run, {}]
869
- acc.recentRuns.push(entry)
870
- }
871
- foldDispatcherRunFact(entry[1], event)
872
- while (acc.recentRuns.length > RECENT_DISPATCH_RUN_LIMIT) {
873
- const index = acc.recentRuns.findIndex(
874
- ([id]) => id !== acc.latestRun && id !== acc.latestStoppedRun,
875
- )
876
- acc.recentRuns.splice(index, 1)
877
- }
878
- }
879
- if (event.type === 'orchestrator.sandbox.published') {
880
- acc.publications = acc.publications.filter(
881
- (prior) =>
882
- prior.payload.operator !== event.payload.operator ||
883
- prior.payload.branch !== event.payload.branch,
884
- )
885
- acc.publications.push(event)
886
- }
887
- }
888
- },
889
- finish: (acc: RepositoryReadAcc) => ({
890
- missingAccounts: structuredClone(acc.missingAccounts),
891
- compatibility: structuredClone(acc.compatibility),
892
- presence: structuredClone(acc.presence),
893
- preparation: ticketPreparationReducer.finish(acc.preparation),
894
- handbacks: ticketHandbacksReducer.finish(acc.handbacks),
895
- ticketStarts: ticketStartsReducer.finish(acc.ticketStarts),
896
- upgrades: dispatchUpgradeReducer.finish(acc.upgrades),
897
- harvestFailures: structuredClone(acc.harvestFailures),
898
- harvestTerminals: structuredClone(acc.harvestTerminals),
899
- harvestVerdicts: structuredClone(acc.harvestVerdicts),
900
- harvestAuthorizations: structuredClone(acc.harvestAuthorizations),
901
- harvestExecutionStarts: { ...acc.harvestExecutionStarts },
902
- latestHarvestResumedSeq: acc.latestHarvestResumedSeq,
903
- harvestSessionEndings: { ...acc.harvestSessionEndings },
904
- harvestSessions: structuredClone(acc.harvestSessions),
905
- attention: repositoryAttentionReducer.finish(acc.attention),
906
- dismissedThrough: acc.dismissedThrough,
907
- failedAt: { ...acc.failedAt },
908
- openHarvest: openHarvestExecutionsReducer.finish(acc.openHarvest),
909
- settings: dispatchSettingsReducer.finish(acc.settings),
910
- harvest: harvestReducer.finish(acc.harvest),
911
- forgeHealth: forgeHealthReducer.finish(acc.forgeHealth),
912
- forgeCredentialLimits: forgeCredentialLimitsReducer.finish(acc.forgeCredentialLimits),
913
- kernelGit: kernelGitHealthReducer.finish(acc.kernelGit),
914
- openPrBackpressure: openPrBackpressureReducer.finish(acc.openPrBackpressure),
915
- ticketMigrations: ticketMigrationsReducer.finish(acc.ticketMigrations),
916
- health: ticketSourceHealthReducer.finish(acc.health),
917
- autoMerge: autoMergeDefaultReducer.finish(acc.autoMerge),
918
- config: effectiveConfigReducer.finish(acc.config),
919
- sandboxes: sandboxStatesReducer.finish(acc.sandboxes),
920
- status: acc.dispatch.run
921
- ? dispatchStatusReducer(acc.dispatch.run).finish(acc.dispatch.status)
922
- : undefined,
923
- scan: acc.scan,
924
- scanSeq: acc.scanSeq,
925
- recentRuns: structuredClone(acc.recentRuns),
926
- latestRun: acc.latestRun,
927
- latestStoppedRun: acc.latestStoppedRun,
928
- publications: structuredClone(acc.publications),
929
- }),
930
- })
931
-
932
- import type { IncrementalReducer } from './incremental'
933
- /** Companion for an optional finished answer: absence is represented by an
934
- * omitted object field, never top-level undefined. */
935
- export function optionalValue<A, E, V>(reducer: IncrementalReducer<A, E, V>) {
936
- return {
937
- ...reducer,
938
- finish: (acc: A) => ({ value: reducer.finish(acc) }),
939
- reduce: (events: readonly E[]) => ({ value: reducer.reduce(events) }),
940
- }
941
- }
942
-
943
- /** One run's correlation facts. History for unrelated runs never enters this value. */
944
- export interface DispatcherRunFacts {
945
- runtime?: RepositoryEvent
946
- start?: RepositoryEvent
947
- latestStart?: RepositoryEvent
948
- stop?: RepositoryEvent
949
- tick?: RepositoryEvent
950
- completed?: RepositoryEvent
951
- boundary?: 'dispatcher.tick-started' | 'dispatcher.tick-completed' | 'dispatcher.tick-failed'
952
- stopRequest?: Extract<RepositoryEvent, { type: 'dispatcher.stop-requested' }>
953
- }
954
- export function dispatcherRunFactsReducer(run: string) {
955
- return defineReducer<DispatcherRunFacts, RepositoryEvent, DispatcherRunFacts>({
956
- identity: 'dispatcherRunFacts',
957
- initial: () => ({}),
958
- fold(acc, events) {
959
- for (const event of projectEvents(events)) {
960
- if (!('run' in event.payload) || event.payload.run !== run) continue
961
- foldDispatcherRunFact(acc, event)
962
- }
963
- },
964
- finish: (acc) => structuredClone(acc),
965
- })
966
- }
967
-
968
- function foldDispatcherRunFact(acc: DispatcherRunFacts, event: RepositoryEvent): void {
969
- if (event.type === 'dispatcher.run-started') {
970
- acc.start ??= event
971
- acc.latestStart = event
972
- } else if (event.type === 'dispatcher.runtime-recorded') acc.runtime = event
973
- else if (event.type === 'dispatcher.run-stopped') acc.stop = event
974
- else if (event.type === 'dispatcher.stop-requested') acc.stopRequest ??= event
975
- else if (
976
- event.type === 'dispatcher.tick-started' ||
977
- event.type === 'dispatcher.tick-completed' ||
978
- event.type === 'dispatcher.tick-failed'
979
- ) {
980
- acc.boundary = event.type
981
- if (event.type !== 'dispatcher.tick-started') acc.tick = event
982
- if (event.type === 'dispatcher.tick-completed') acc.completed = event
983
- }
984
- }
617
+ repositoryReadFactsReducer,
618
+ optionalValue,
619
+ dispatcherRunFactsReducer,
620
+ type RepositoryReadAcc,
621
+ type DispatcherRunFacts,
622
+ } from './repository-read-facts'
@@ -22,16 +22,14 @@ import {
22
22
  repositoryReadFactsReducer,
23
23
  optionalValue,
24
24
  } from './read-facts'
25
- import { validateAccumulator, encodeReducerValue } from '../store/reducer-value-validation'
26
25
  import {
27
26
  effectiveConfigReducer,
28
27
  buildDelegationReducer,
29
28
  harvestDelegationReducer,
30
29
  } from './service-facts'
31
- import { phaseSchema } from '../ontology'
32
- import { z } from 'zod'
33
30
  import { dispatchPlacementReducer } from './dispatch-placement'
34
31
  import type { ValueCatalogEntry } from '../store/reducer-values'
32
+ import { valueReadEntry, type RegisteredReducer } from './reducer-value-entry'
35
33
  import { dispatchFrontendReducer } from '../cli/dispatch-repository-feed'
36
34
  import { executionNoProgressReducer } from '../processes/execution-no-progress'
37
35
  import { summaryBoundaryReducer, summaryRequestsReducer } from './pr-summary'
@@ -79,7 +77,6 @@ import { currentDeferralObservationReducer } from './auto-merge'
79
77
  import { dispatchSettingsReducer } from './dispatch-settings'
80
78
  import { dispatchStatusReducer } from './dispatch-status'
81
79
  import { harvestReducer } from './harvest'
82
- import type { IncrementalReducer } from './incremental'
83
80
  import { logIndexReducer } from './log-index'
84
81
  import {
85
82
  currentPrAttachmentsReducer,
@@ -91,13 +88,7 @@ import { buildReducer } from './reducer'
91
88
  import type { AnyRollupDefinition } from './rollup'
92
89
  import { stepDurationsRollup } from './step-durations'
93
90
 
94
- export interface RegisteredReducer {
95
- valueRead: ValueCatalogEntry | { excluded: string }
96
- // biome-ignore lint/suspicious/noExplicitAny: the registry is heterogeneous
97
- reducer: IncrementalReducer<any, any, any>
98
- /** The whole-array functions (or private methods) this reducer backs. */
99
- covers: readonly string[]
100
- }
91
+ export type { RegisteredReducer } from './reducer-value-entry'
101
92
 
102
93
  /** Parameterized reducers are registered with representative arguments; the
103
94
  * accumulator shape does not depend on them. */
@@ -216,80 +207,16 @@ const REGISTERED: Record<string, Omit<RegisteredReducer, 'valueRead'>> = {
216
207
  dispatchPlacement: { reducer: dispatchPlacementReducer, covers: [] },
217
208
  }
218
209
 
219
- /** Qualification concerns the existing finished contract, including absence. */
220
- const valueExclusions: Record<string, string> = {
221
- dispatchFrontend: 'returns a list of raw repository journal events',
222
- journalView: 'returns a list of raw repository journal events',
223
- repositoryStateEvents: 'returns a list of raw repository journal events',
224
- session: 'consumes operator-session logs rather than build or repository events',
225
- publicationState: 'finished value contains executable selector functions',
226
- logIndex: 'finished value contains Maps and Sets',
227
- hostedPrAttachments: 'finished value is a Map',
228
- ...Object.fromEntries(
229
- [
230
- 'summaryBoundary',
231
- 'ticketSourceHealth',
232
- 'frozenPrImageHost',
233
- 'publishedBranchHead',
234
- 'verifyDiffBase',
235
- 'recordedBaseSha',
236
- 'baseBranch',
237
- 'provisionMarker',
238
- 'recoveryCheckpoint',
239
- ].map((name) => [name, 'finished contract can return top-level undefined, which is not JSON']),
240
- ),
241
- }
242
- const repositoryValues = new Set([
243
- 'dispatchPlacement',
244
- 'ticketPreparation',
245
- 'ticketHandbacks',
246
- 'ticketStarts',
247
- 'ticketMigrations',
248
- 'forgeHealthValue',
249
- 'repositoryReadFacts',
250
- 'dispatchUpgrade',
251
- 'dispatcherRunFacts',
252
- 'repositoryAttention',
253
- 'effectiveConfig',
254
- 'harvestDelegation',
255
- 'harvest',
256
- 'dispatchSettings',
257
- 'dispatchStatus',
258
- 'sandboxStates',
259
- 'openHarvestExecutions',
260
- 'hostedHarvestAuthority',
261
- 'openTick',
262
- 'autoMergeDefault',
263
- ])
264
- const noArgs = z.object({}).strict()
265
- const parameterized: Record<string, Pick<ValueCatalogEntry, 'args' | 'create'>> = {
266
- terminalGuard: {
267
- args: z
268
- .object({ phase: phaseSchema, round: z.number().int(), session: z.string().min(1) })
269
- .strict(),
270
- create: (args) => terminalGuardReducer(args),
271
- },
272
- dispatchStatus: {
273
- args: z.object({ run: z.string().min(1) }).strict(),
274
- create: ({ run }) => dispatchStatusReducer(run),
275
- },
276
- dispatcherRunFacts: {
277
- args: z.object({ run: z.string().min(1) }).strict(),
278
- create: ({ run }) => dispatcherRunFactsReducer(run),
279
- },
280
- openTick: {
281
- args: z.object({ run: z.string().min(1) }).strict(),
282
- create: ({ run }) => openTickReducer(run),
283
- },
284
- dispatchFailureBudget: {
285
- args: z.object({ infrastructureOwnsWorkspace: z.boolean() }).strict(),
286
- create: ({ infrastructureOwnsWorkspace }) =>
287
- dispatchFailureBudgetReducer(infrastructureOwnsWorkspace),
288
- },
289
- phaseFailures: {
290
- args: z.object({ phase: phaseSchema, round: z.number().int().nonnegative() }).strict(),
291
- create: ({ phase, round }) => phaseFailuresReducer(phase, round),
292
- },
210
+ /** Constructors of the parameterized reducers; `parameterizedArgs` holds their
211
+ * argument schemas. */
212
+ const parameterizedCreate: Record<string, ValueCatalogEntry['create']> = {
213
+ terminalGuard: (args) => terminalGuardReducer(args),
214
+ dispatchStatus: ({ run }) => dispatchStatusReducer(run),
215
+ dispatcherRunFacts: ({ run }) => dispatcherRunFactsReducer(run),
216
+ openTick: ({ run }) => openTickReducer(run),
217
+ dispatchFailureBudget: ({ infrastructureOwnsWorkspace }) =>
218
+ dispatchFailureBudgetReducer(infrastructureOwnsWorkspace),
219
+ phaseFailures: ({ phase, round }) => phaseFailuresReducer(phase, round),
293
220
  }
294
221
  /** The node slugs one digest row names: a `build.created` target, or either
295
222
  * side of a node parent move. Undecodable payloads name none. */
@@ -361,51 +288,39 @@ function digestTicketWaitOf(
361
288
  return {}
362
289
  }
363
290
 
291
+ /** The build digest folds compact rows rather than whole events. */
292
+ function adaptDigestRows(events: Parameters<ValueCatalogEntry['adapt']>[0]) {
293
+ return events.map((event) => ({
294
+ ...(decodeStoredEvent(event) === null ? { rawUnknown: event } : {}),
295
+ type: event.type,
296
+ seq: event.seq,
297
+ ts: event.ts,
298
+ ...(event.payload !== null && typeof event.payload === 'object' && 'hostedSeq' in event.payload
299
+ ? { hostedSeq: event.payload.hostedSeq }
300
+ : {}),
301
+ ...(event.type === 'integration.landed' ? { auditRequested: !!event.payload.operation } : {}),
302
+ ...(event.type === 'pr.merged' ? { mergedSha: event.payload.sha } : {}),
303
+ ...(event.type === 'node.contribution-recorded' ? { nodeContribution: event.payload } : {}),
304
+ ...(event.type === 'build.created' ? { kind: event.payload.kind } : {}),
305
+ ...digestNodeTargetsOf(event),
306
+ ...(event.payload !== null && typeof event.payload === 'object' && 'instance' in event.payload
307
+ ? { instance: event.payload.instance }
308
+ : {}),
309
+ ...digestTicketWaitOf(event),
310
+ ...digestAttemptOf(event),
311
+ ...digestOptimizationOf(event),
312
+ }))
313
+ }
314
+
364
315
  export const REDUCERS: Record<string, RegisteredReducer> = Object.fromEntries(
365
316
  Object.entries(REGISTERED).map(([name, entry]) => [
366
317
  name,
367
318
  {
368
319
  ...entry,
369
- valueRead: valueExclusions[name]
370
- ? { excluded: valueExclusions[name] }
371
- : {
372
- scope: repositoryValues.has(name) ? 'repo' : 'build',
373
- args: parameterized[name]?.args ?? noArgs,
374
- validate: (state: unknown) => validateAccumulator(name, state),
375
- value: encodeReducerValue,
376
- adapt: (events: Parameters<ValueCatalogEntry['adapt']>[0]) =>
377
- name === 'buildDigest'
378
- ? events.map((event) => ({
379
- ...(decodeStoredEvent(event) === null ? { rawUnknown: event } : {}),
380
- type: event.type,
381
- seq: event.seq,
382
- ts: event.ts,
383
- ...(event.payload !== null &&
384
- typeof event.payload === 'object' &&
385
- 'hostedSeq' in event.payload
386
- ? { hostedSeq: event.payload.hostedSeq }
387
- : {}),
388
- ...(event.type === 'integration.landed'
389
- ? { auditRequested: !!event.payload.operation }
390
- : {}),
391
- ...(event.type === 'pr.merged' ? { mergedSha: event.payload.sha } : {}),
392
- ...(event.type === 'node.contribution-recorded'
393
- ? { nodeContribution: event.payload }
394
- : {}),
395
- ...(event.type === 'build.created' ? { kind: event.payload.kind } : {}),
396
- ...digestNodeTargetsOf(event),
397
- ...(event.payload !== null &&
398
- typeof event.payload === 'object' &&
399
- 'instance' in event.payload
400
- ? { instance: event.payload.instance }
401
- : {}),
402
- ...digestTicketWaitOf(event),
403
- ...digestAttemptOf(event),
404
- ...digestOptimizationOf(event),
405
- }))
406
- : events,
407
- create: parameterized[name]?.create ?? (() => entry.reducer),
408
- },
320
+ valueRead: valueReadEntry(name, entry.reducer, {
321
+ ...(parameterizedCreate[name] ? { create: parameterizedCreate[name] } : {}),
322
+ ...(name === 'buildDigest' ? { adapt: adaptDigestRows } : {}),
323
+ }),
409
324
  },
410
325
  ]),
411
326
  )
@@ -74,4 +74,7 @@ export const REDUCER_REVISIONS: Readonly<Record<string, string>> = {
74
74
  'verifyDiffBase/fold/p2si2x55v7': '#1274 rewritten-target reprovision, accept waiver, episodes',
75
75
  'repositoryReadFacts/shape/mggr8x6l5z': '#1279 reported dispatcher run tracks pending runs',
76
76
  'repositoryReadFacts/fold/vvcfmd23zp': '#1279 status describes the authority run',
77
+ 'build/shape/rclfl10h8j': 'Durable slot admission and release seqs (SPEC §12 What holds a slot)',
78
+ 'build/shape/i4uoqi67lx': 'Node slot admission names its need (#1340)',
79
+ 'build/fold/4hkypq2buv': '#1348 answers release a slot only when the build was not carried',
77
80
  }