@defrex/autobuild 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +107 -10
  3. package/docs/agent-runtimes.md +1 -1
  4. package/docs/architecture.md +62 -22
  5. package/docs/configuration-overview.md +10 -0
  6. package/docs/configuration.md +285 -5
  7. package/docs/forges.md +1 -0
  8. package/docs/operator-api.md +19 -8
  9. package/docs/operator-surfaces.md +6 -3
  10. package/docs/plugin-authoring.md +44 -6
  11. package/docs/remote-store-protocol.md +19 -6
  12. package/docs/restacking.md +12 -7
  13. package/docs/ticket-sources.md +34 -6
  14. package/docs/tickets.md +6 -0
  15. package/docs/workspaces.md +1 -1
  16. package/package.json +3 -3
  17. package/packages/core/src/cli/attention.ts +1 -0
  18. package/packages/core/src/cli/binary-direct.ts +1 -0
  19. package/packages/core/src/cli/dispatch-frontend.ts +10 -14
  20. package/packages/core/src/cli/dispatch-preflight.ts +1 -0
  21. package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
  22. package/packages/core/src/cli/dispatch.ts +9 -3
  23. package/packages/core/src/cli/help.ts +11 -4
  24. package/packages/core/src/cli/init-validation.ts +14 -1
  25. package/packages/core/src/cli/repository-status.ts +37 -2
  26. package/packages/core/src/cli/status.ts +8 -0
  27. package/packages/core/src/cli/ticket.ts +22 -4
  28. package/packages/core/src/cli/watch.ts +2 -0
  29. package/packages/core/src/config/live.ts +4 -0
  30. package/packages/core/src/config/profiles.ts +96 -0
  31. package/packages/core/src/config/ready-assignee.ts +43 -11
  32. package/packages/core/src/config/roles.ts +33 -10
  33. package/packages/core/src/config/schema.ts +166 -24
  34. package/packages/core/src/events/compatibility.ts +3 -1
  35. package/packages/core/src/events/forge-degradation-policy.ts +16 -2
  36. package/packages/core/src/events/payloads.ts +8 -0
  37. package/packages/core/src/events/policy.ts +1 -0
  38. package/packages/core/src/events/repository.ts +17 -0
  39. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +73 -124
  40. package/packages/core/src/kernel/build-creation.ts +29 -0
  41. package/packages/core/src/kernel/forge-health.ts +47 -0
  42. package/packages/core/src/kernel/guarded-forge.ts +76 -18
  43. package/packages/core/src/kernel/node-parent.ts +2 -0
  44. package/packages/core/src/kernel/read-facts.ts +9 -1
  45. package/packages/core/src/kernel/reducer.ts +18 -1
  46. package/packages/core/src/kernel/ticket-preparation.ts +4 -1
  47. package/packages/core/src/operator/protocol.ts +10 -0
  48. package/packages/core/src/operator/query.ts +1 -1
  49. package/packages/core/src/operator/registry.ts +25 -5
  50. package/packages/core/src/operator/sandbox-host.ts +3 -0
  51. package/packages/core/src/operator/tickets.ts +15 -3
  52. package/packages/core/src/plugin-sdk/index.ts +4 -0
  53. package/packages/core/src/ports/forge/create.ts +6 -0
  54. package/packages/core/src/ports/forge/github-transport.ts +40 -3
  55. package/packages/core/src/ports/forge/github.ts +12 -1
  56. package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
  57. package/packages/core/src/ports/forge-failure.ts +31 -2
  58. package/packages/core/src/ports/runner/routing.ts +66 -5
  59. package/packages/core/src/ports/tickets/assignees.ts +54 -0
  60. package/packages/core/src/ports/tickets/contract.ts +164 -4
  61. package/packages/core/src/ports/tickets/create.ts +17 -3
  62. package/packages/core/src/ports/tickets/github-fake.ts +18 -2
  63. package/packages/core/src/ports/tickets/github.ts +247 -29
  64. package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
  65. package/packages/core/src/ports/tickets/operations.ts +6 -1
  66. package/packages/core/src/ports/tickets/tree.ts +12 -2
  67. package/packages/core/src/ports/tickets/update.ts +6 -2
  68. package/packages/core/src/ports/types.ts +33 -3
  69. package/packages/core/src/ports/workspace/vercel-sandbox.ts +9 -0
  70. package/packages/core/src/processes/build-child.ts +28 -7
  71. package/packages/core/src/processes/build-execution-state.ts +4 -1
  72. package/packages/core/src/processes/build-runner.ts +15 -1
  73. package/packages/core/src/processes/dispatcher.ts +98 -18
  74. package/packages/core/src/processes/harvest-child.ts +4 -0
  75. package/packages/core/src/processes/harvest-runner.ts +5 -0
  76. package/packages/core/src/processes/repo-view.ts +2 -0
  77. package/packages/core/src/scenarios/harness.ts +15 -1
  78. package/packages/core/src/store/reducer-value-shapes.json +3119 -2926
  79. package/packages/core/src/store/remote/client.ts +21 -8
  80. package/packages/core/src/store/remote/index.ts +4 -0
  81. package/packages/core/src/store/remote/protocol.ts +7 -0
  82. package/packages/core/src/store/remote/released-clients.json +11 -0
  83. package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
  84. package/packages/core/src/store/remote/released-reducer-values/index.ts +2 -0
  85. package/packages/core/src/store/repo-state-events.ts +1 -0
  86. package/packages/core/src/store/types.ts +11 -0
  87. package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
  88. package/packages/core/src/testing/index.ts +2 -0
  89. package/packages/core/src/testing/reduced-read-budget.ts +72 -9
  90. package/skills/guide/SKILL.md +116 -21
  91. package/skills/guide/references/operator-api.md +19 -8
  92. package/skills/guide/references/plugin-authoring.md +44 -6
  93. package/skills/guide/references/remote-store-protocol.md +19 -6
  94. package/skills/guide/references/restacking.md +12 -7
  95. package/skills/operate/SKILL.md +29 -3
  96. package/skills/tickets/SKILL.md +18 -2
  97. package/templates/hosted-service/package.json +2 -2
@@ -5,6 +5,8 @@ import { isRemoteWorkspace } from '../events/workspace-remote'
5
5
  import { readBuildFacts } from '../store/reduced-reads'
6
6
  import { hostname } from 'node:os'
7
7
  import { createForge } from '../ports/forge/create'
8
+ import { GITHUB_REQUIRE_CREDENTIAL_ENV } from '../ports/forge/github-transport'
9
+ import { withWorkspaceAncestry } from '../ports/forge/workspace-ancestry'
8
10
  import { createProductionRuntimes } from '../ports/runner/production'
9
11
  import { spawnExec } from '../ports/workspace/git-worktree'
10
12
  import { loadPlugins } from '../plugins/load'
@@ -67,14 +69,30 @@ export async function runBuildChild(
67
69
  repoRoot: workspace.path ?? workspace.ref,
68
70
  env,
69
71
  })
72
+ const workspaceRemote = opts.guest === true || isRemoteWorkspace(workspace)
73
+ const created = await createForge({
74
+ name: currentConfig.forge,
75
+ registry: plugins,
76
+ env,
77
+ repoRoot: workspace.path ?? workspace.ref,
78
+ })
79
+ // A remote guest holds no forge credential: ancestry proofs run through the
80
+ // workspace's own Git read channel instead of an anonymous API request.
81
+ // The runner's limits are its own; only the dispatcher pauses the repository.
70
82
  const forge = guardForge(
71
- await createForge({
83
+ workspaceRemote
84
+ ? withWorkspaceAncestry(created, {
85
+ exec: spawnExec,
86
+ workspacePath: workspace.path ?? workspace.ref,
87
+ })
88
+ : created,
89
+ {
90
+ store: fullStore,
91
+ repo: record.repo,
72
92
  name: currentConfig.forge,
73
- registry: plugins,
74
- env,
75
- repoRoot: workspace.path ?? workspace.ref,
76
- }),
77
- { store: fullStore, repo: record.repo, name: currentConfig.forge, wait: true },
93
+ wait: true,
94
+ scope: { process: `build-runner ${input.slug}` },
95
+ },
78
96
  )
79
97
  const getConfig = async () => {
80
98
  const latest = await store.getArtifact(input.slug, BUILD_EFFECTIVE_CONFIG_ARTIFACT)
@@ -99,7 +117,7 @@ export async function runBuildChild(
99
117
  runtimes,
100
118
  workspacePath: workspace.path ?? workspace.ref,
101
119
  workspaceProvider: workspace.provider,
102
- workspaceRemote: opts.guest === true || isRemoteWorkspace(workspace),
120
+ workspaceRemote,
103
121
  shutdownSignal: opts.shutdownSignal,
104
122
  branch: workspace.branch,
105
123
  slug: input.slug,
@@ -112,6 +130,9 @@ export async function runBuildChild(
112
130
  sessionEnv: {
113
131
  AB_STORE: input.storeRef,
114
132
  ...(env.AB_TOKEN !== undefined && env.AB_TOKEN !== '' ? { AB_TOKEN: env.AB_TOKEN } : {}),
133
+ ...(env[GITHUB_REQUIRE_CREDENTIAL_ENV] === '1'
134
+ ? { [GITHUB_REQUIRE_CREDENTIAL_ENV]: '1' }
135
+ : {}),
115
136
  },
116
137
  })
117
138
  await runner.run()
@@ -20,9 +20,12 @@ export interface BuildRunnerDiagnostic {
20
20
 
21
21
  /** JSON form of the normalized config's strict declarative input shape. */
22
22
  export function effectiveBuildConfigContent(config: Config): string {
23
- const { verify, finalize, ...root } = config
23
+ const { verify, finalize, profiles, ...root } = config
24
24
  return JSON.stringify({
25
25
  ...root,
26
+ // Omitted when empty so repositories without profiles keep byte-identical
27
+ // artifacts that an older client's strict root parse still accepts.
28
+ ...(profiles !== undefined && Object.keys(profiles).length > 0 ? { profiles } : {}),
26
29
  verify: {
27
30
  steps: verify.stages ?? verify.steps,
28
31
  afterReconcile: verify.afterReconcile,
@@ -787,6 +787,8 @@ export class BuildRunner {
787
787
 
788
788
  private async startBracket(write: EventWrite<'session.started'>) {
789
789
  const { store, slug } = this.deps
790
+ if (this.boundaryProfile !== undefined)
791
+ write = { ...write, payload: { ...write.payload, profile: { ...this.boundaryProfile } } }
790
792
  const old = this.recovery
791
793
  const budgetMs = this.resolveSessionRole(write.payload.role).sessionBudgetSeconds * 1000
792
794
  if (
@@ -941,6 +943,8 @@ export class BuildRunner {
941
943
  * consults the mutable owner again. */
942
944
  private boundaryConfig: Config
943
945
  private boundaryResolver: RuntimeResolver
946
+ /** The build's profile and whether the boundary config still defines it. */
947
+ private boundaryProfile: { name: string; configured: boolean } | undefined
944
948
 
945
949
  constructor(private readonly deps: BuildRunnerDeps) {
946
950
  const redactor = accountRedactor(
@@ -979,12 +983,22 @@ export class BuildRunner {
979
983
  const state = (await readBuildFacts(this.deps.store, this.deps.slug)).value.state
980
984
  const config = await capturedBuildConfig(this.deps.store, this.deps.slug, state, deployment)
981
985
  this.boundaryConfig = config
982
- this.boundaryResolver = createRuntimeResolver(
986
+ const base = createRuntimeResolver(
983
987
  this.deps.runtimes,
984
988
  config.roles,
985
989
  config.policy.sessionBudgetSeconds,
986
990
  config.accounts,
991
+ config.profiles,
987
992
  )
993
+ // The build's profile was fixed at claim; its contents come from the
994
+ // boundary-current config. A profile a reload removed falls back to the
995
+ // repository roles, and the next session.started records that.
996
+ const profile = state.profile === undefined ? undefined : base.profile(state.profile.name)
997
+ this.boundaryResolver = profile ?? base
998
+ this.boundaryProfile =
999
+ state.profile === undefined
1000
+ ? undefined
1001
+ : { name: state.profile.name, configured: profile !== undefined }
988
1002
  return config
989
1003
  }
990
1004
 
@@ -187,6 +187,7 @@ import { recordAutoMergeDeferralObservation } from '../kernel/auto-merge'
187
187
  import type { AutoMergeDefaultFact } from '../kernel/auto-merge-default'
188
188
  import { decideNextFromFacts, landingRestackDue } from '../kernel/engine'
189
189
  import { composeBuildConfig } from '../config/live'
190
+ import { profileConflictDiagnostic, selectProfile } from '../config/profiles'
190
191
  import { BUILD_EFFECTIVE_CONFIG_ARTIFACT, parseEffectiveBuildConfig } from './build-execution-state'
191
192
  import {
192
193
  DEFAULT_MAX_HARVEST_RECOVERY_ATTEMPTS,
@@ -214,6 +215,7 @@ import {
214
215
  } from '../kernel/node-issue-links'
215
216
  import type { Exec, ExecResult } from '../ports/workspace/git-worktree'
216
217
  import type { ArtifactMeta, BuildDigest, BuildRecord, BuildStore, Clock } from '../store/types'
218
+ import { creationBuildSlug } from '../kernel/build-creation'
217
219
  import { preparePinnedAssets } from '../store/ticket-assets'
218
220
  import { resolveRepoOrigin } from '../cli/repo-state'
219
221
  import { specConformance } from '../spec-standard'
@@ -1483,9 +1485,15 @@ export class Dispatcher {
1483
1485
  if (record.ticket && digest.terminal === undefined) refs.push(record.ticket)
1484
1486
  }
1485
1487
  const activeTicketIds = await this.activeTicketIdentities(refs, listing.tickets)
1488
+ const conflicts = this.profileConflicts(
1489
+ listing.tickets.filter(
1490
+ (ticket) => !activeTicketIds.has(`${ticket.ref.source}:${ticket.ref.id}`),
1491
+ ),
1492
+ )
1486
1493
  report.queued = listing.tickets.filter(
1487
1494
  (ticket) =>
1488
1495
  !activeTicketIds.has(`${ticket.ref.source}:${ticket.ref.id}`) &&
1496
+ !conflicts.tickets.has(ticket) &&
1489
1497
  !Object.values(this.store.repositoryFacts().preparation).some((attempt) => {
1490
1498
  const ref = resolveTicketRef(
1491
1499
  this.store.repositoryFacts().ticketMigrations,
@@ -1496,8 +1504,8 @@ export class Dispatcher {
1496
1504
  return ref.source === ticket.ref.source && ref.id === ticket.ref.id
1497
1505
  }),
1498
1506
  ).length
1499
- report.invalidTickets = listing.diagnostics.length
1500
- report.ticketDiagnostics = [...listing.diagnostics]
1507
+ report.invalidTickets = listing.diagnostics.length + conflicts.diagnostics.length
1508
+ report.ticketDiagnostics = [...listing.diagnostics, ...conflicts.diagnostics]
1501
1509
  report.dependencyBlocked = 0
1502
1510
  report.dependencyDiagnostics = []
1503
1511
  report.creationWithheld = 0
@@ -4680,11 +4688,36 @@ export class Dispatcher {
4680
4688
  /** The claim-time `build.created` payload. Assets and issue links are
4681
4689
  * omitted when the ticket had none, so such a build's log is exactly what it
4682
4690
  * was before. */
4691
+ /** Ready tickets whose labels select two or more profiles (SPEC §9). They
4692
+ * are never claimed; each gets a ticket diagnostic until relabelled. Pure
4693
+ * over the listing the scan already holds. */
4694
+ private profileConflicts(tickets: readonly Ticket[]): {
4695
+ tickets: Set<Ticket>
4696
+ diagnostics: string[]
4697
+ } {
4698
+ const conflicting = new Set<Ticket>()
4699
+ const diagnostics: string[] = []
4700
+ for (const ticket of tickets) {
4701
+ const selection = selectProfile(this.deps.config.profiles, ticket.labels)
4702
+ if (selection.kind !== 'conflict') continue
4703
+ conflicting.add(ticket)
4704
+ diagnostics.push(profileConflictDiagnostic(ticket.ref.id, selection.matches))
4705
+ }
4706
+ return { tickets: conflicting, diagnostics }
4707
+ }
4708
+
4709
+ /** The profile a ticket's labels select at claim, if exactly one. */
4710
+ private selectedProfile(ticket: Ticket): { profile: string } | Record<string, never> {
4711
+ const selection = selectProfile(this.deps.config.profiles, ticket.labels)
4712
+ return selection.kind === 'selected' ? { profile: selection.name } : {}
4713
+ }
4714
+
4683
4715
  private buildCreatedPayload(
4684
4716
  ticket: TicketRef,
4685
4717
  repo: string,
4686
4718
  seed:
4687
4719
  | {
4720
+ profile?: string
4688
4721
  autoMergeUser?: string
4689
4722
  autoMergeDefaultSeq?: number
4690
4723
  assets?: PinnedAsset[]
@@ -4711,6 +4744,7 @@ export class Dispatcher {
4711
4744
  ...(seed?.issueLinks !== undefined && seed.issueLinks.length > 0
4712
4745
  ? { issueLinks: seed.issueLinks.map(({ issue, intent }) => ({ issue, intent })) }
4713
4746
  : {}),
4747
+ ...(seed?.profile !== undefined ? { profile: seed.profile } : {}),
4714
4748
  }
4715
4749
  }
4716
4750
 
@@ -4780,6 +4814,7 @@ export class Dispatcher {
4780
4814
  ...(seed?.ticket.issueLinks !== undefined
4781
4815
  ? { issueLinks: seed.ticket.issueLinks }
4782
4816
  : {}),
4817
+ ...(seed !== undefined ? this.selectedProfile(seed.ticket) : {}),
4783
4818
  }),
4784
4819
  })
4785
4820
  events = (await readBuildFacts(store, record.slug)).value
@@ -5481,29 +5516,58 @@ export class Dispatcher {
5481
5516
  this.tickAbandonments.push(abandonedPreparationDiagnostic(attempt, recorded))
5482
5517
  }
5483
5518
 
5519
+ /** Whether the build at `slug` was created for this attempt's ticket. */
5520
+ private async preparationOwns(attempt: TicketPreparation, record: BuildRecord): Promise<boolean> {
5521
+ const created = (await this.store.buildFacts(record.slug)).created
5522
+ return (
5523
+ record.repo === this.deps.repo &&
5524
+ record.ticket?.source === attempt.ticket.source &&
5525
+ record.ticket?.id === attempt.ticket.id &&
5526
+ created?.payload.repo === this.deps.repo &&
5527
+ created.payload.ticket?.source === attempt.ticket.source &&
5528
+ created.payload.ticket?.id === attempt.ticket.id
5529
+ )
5530
+ }
5531
+
5484
5532
  private async recoverTicketPreparation(attempt: TicketPreparation): Promise<void> {
5485
5533
  try {
5486
5534
  // A rejected create can have committed. Unavailable or conflicting readback
5487
- // is never absence and must not authorize a ticket transition.
5535
+ // is never absence and must not authorize a ticket transition. A keyed
5536
+ // attempt's build is at its proposed slug (exact-slug store) or the slug
5537
+ // its own key derives (allocating store): at most two point reads, and
5538
+ // never another attempt's build.
5488
5539
  if (attempt.slug) {
5489
- const record = await this.store.getBuild(attempt.slug)
5490
- if (record) {
5491
- const created = (await this.store.buildFacts(attempt.slug)).created
5492
- if (
5493
- record.repo !== this.deps.repo ||
5494
- record.ticket?.source !== attempt.ticket.source ||
5495
- record.ticket?.id !== attempt.ticket.id ||
5496
- created?.payload.repo !== this.deps.repo ||
5497
- created.payload.ticket?.source !== attempt.ticket.source ||
5498
- created.payload.ticket?.id !== attempt.ticket.id
5540
+ const candidates = attempt.creationKey
5541
+ ? [attempt.slug, creationBuildSlug(this.deps.repo, attempt.slug, attempt.creationKey)]
5542
+ : [attempt.slug]
5543
+ const found: BuildRecord[] = []
5544
+ for (const slug of candidates) {
5545
+ const record = await this.store.getBuild(slug)
5546
+ if (record) found.push(record)
5547
+ }
5548
+ if (found.length > 1)
5549
+ return await this.abandonPreparation(
5550
+ attempt,
5551
+ `Ambiguous creation identity: builds at ${found.map((record) => record.slug).join(' and ')} both answer this attempt; ticket unchanged. Inspect ownership before manually retrying. Original failure: ${attempt.error ?? 'unknown'}`,
5499
5552
  )
5553
+ const [record] = found
5554
+ if (record) {
5555
+ if (!(await this.preparationOwns(attempt, record)))
5500
5556
  return await this.abandonPreparation(
5501
5557
  attempt,
5502
- `Conflicting build ownership at ${attempt.slug}; ticket unchanged. Inspect ownership before manually retrying. Original failure: ${attempt.error ?? 'unknown'}`,
5558
+ `Conflicting build ownership at ${record.slug}; ticket unchanged. Inspect ownership before manually retrying. Original failure: ${attempt.error ?? 'unknown'}`,
5503
5559
  )
5504
5560
  await this.preparationResolved(attempt, 'owned')
5505
5561
  return
5506
5562
  }
5563
+ // Absence is evidence only where the creation slug is known: an
5564
+ // allocating store may have committed an unkeyed create under a slug
5565
+ // no point read can find, and enumerating builds is never a fallback.
5566
+ if (!attempt.creationKey && (await this.store.buildCreationIdentity?.()) !== undefined)
5567
+ return await this.abandonPreparation(
5568
+ attempt,
5569
+ `Creation outcome unknown: the build store allocates canonical slugs and this attempt recorded no creation key, so a build created under an unrecorded slug cannot be ruled out; ticket unchanged. Inspect the repository's builds for ticket ${attempt.ticket.id} before manually retrying. Original failure: ${attempt.error ?? 'unknown'}`,
5570
+ )
5507
5571
  }
5508
5572
  const ref = resolveTicketRef(
5509
5573
  this.store.repositoryFacts().ticketMigrations,
@@ -5639,9 +5703,12 @@ export class Dispatcher {
5639
5703
  )
5640
5704
  // Urgent first, each class in source order (stable). Every gate below is
5641
5705
  // unchanged; a source without the priority capability is all normal.
5642
- const ready = this.deps.tickets.priority ? urgentFirst(eligible) : eligible
5643
- report.invalidTickets += listing.diagnostics.length
5644
- report.ticketDiagnostics.push(...listing.diagnostics)
5706
+ // A ticket whose labels select two profiles is never claimed (SPEC §9).
5707
+ const conflicts = this.profileConflicts(eligible)
5708
+ const claimable = eligible.filter((ticket) => !conflicts.tickets.has(ticket))
5709
+ const ready = this.deps.tickets.priority ? urgentFirst(claimable) : claimable
5710
+ report.invalidTickets += listing.diagnostics.length + conflicts.diagnostics.length
5711
+ report.ticketDiagnostics.push(...listing.diagnostics, ...conflicts.diagnostics)
5645
5712
  report.queued = ready.length
5646
5713
  const withheld = new Set<string>()
5647
5714
  for (const ticket of ready) {
@@ -5972,6 +6039,10 @@ export class Dispatcher {
5972
6039
  const slug = await this.uniqueSlug(baseSlug, prefix)
5973
6040
  const branch = `${prefix}/${slug}`
5974
6041
  const repoOrigin = await this.resolveRepoOriginOnce()
6042
+ // Recorded only on the store's attestation, so recovery never treats
6043
+ // an unkeyed creation's absence at the derived slug as evidence.
6044
+ const creationKey =
6045
+ (await store.buildCreationIdentity?.()) === 'keyed' ? attempt.attempt : undefined
5975
6046
  createdSeed = {
5976
6047
  ...(ticket.kind === 'node' ? { kind: ticket.kind } : {}),
5977
6048
  ...(target !== undefined ? { target: target.target, baseBranch: target.branch } : {}),
@@ -5988,15 +6059,23 @@ export class Dispatcher {
5988
6059
  // Frozen from the same claimed ticket sample as the body (SPEC
5989
6060
  // "Forge issue links"); later ticket edits never reach this build.
5990
6061
  ...(ticket.issueLinks !== undefined ? { issueLinks: ticket.issueLinks } : {}),
6062
+ // Fixed at claim from the same sample: relabelling never changes it.
6063
+ ...this.selectedProfile(ticket),
5991
6064
  }
5992
6065
  // `build.created` rides with the record so the pinned assets and the
5993
6066
  // record exist together or not at all.
5994
6067
  stage = 'creation-identity'
5995
6068
  attempt.slug = slug
6069
+ if (creationKey !== undefined) attempt.creationKey = creationKey
5996
6070
  await store.appendRepo(this.deps.repo, {
5997
6071
  actor: DISPATCHER,
5998
6072
  type: 'ticket-preparation.creation-selected',
5999
- payload: { attempt: attempt.attempt, ticket: attempt.ticket, slug },
6073
+ payload: {
6074
+ attempt: attempt.attempt,
6075
+ ticket: attempt.ticket,
6076
+ slug,
6077
+ ...(creationKey !== undefined ? { creationKey } : {}),
6078
+ },
6000
6079
  })
6001
6080
  stage = 'create-build'
6002
6081
  record = await store.createBuild({
@@ -6005,6 +6084,7 @@ export class Dispatcher {
6005
6084
  ticket: ticket.ref,
6006
6085
  branch,
6007
6086
  ...(repoOrigin !== undefined ? { repoOrigin } : {}),
6087
+ ...(creationKey !== undefined ? { creationKey } : {}),
6008
6088
  created: {
6009
6089
  actor: DISPATCHER,
6010
6090
  type: 'build.created',
@@ -20,6 +20,7 @@ import { openProductionStore, type StoreOpener } from '../cli/store-opening'
20
20
  import { resolveRepoStatePaths } from '../cli/repo-state'
21
21
  import { DEFAULT_MAX_HARVEST_RECOVERY_ATTEMPTS } from '../kernel/harvest'
22
22
  import { HarvestRunner } from './harvest-runner'
23
+ import { GITHUB_REQUIRE_CREDENTIAL_ENV } from '../ports/forge/github-transport'
23
24
 
24
25
  export type { HarvestExecutionEnvironment }
25
26
 
@@ -124,6 +125,9 @@ export async function runHarvestChild(
124
125
  ...(env.AB_TICKET_TOKEN ? { AB_TICKET_TOKEN: env.AB_TICKET_TOKEN } : {}),
125
126
  AB_STORE: input.storeRef,
126
127
  ...(env.AB_TOKEN !== undefined && env.AB_TOKEN !== '' ? { AB_TOKEN: env.AB_TOKEN } : {}),
128
+ ...(env[GITHUB_REQUIRE_CREDENTIAL_ENV] === '1'
129
+ ? { [GITHUB_REQUIRE_CREDENTIAL_ENV]: '1' }
130
+ : {}),
127
131
  },
128
132
  opts: {
129
133
  maxRecoveryAttempts: DEFAULT_MAX_HARVEST_RECOVERY_ATTEMPTS,
@@ -1,4 +1,5 @@
1
1
  import { accountRedactor, redactAccountStore } from '../store/account-redaction'
2
+ import { creationAssignees } from '../ports/tickets/assignees'
2
3
  import {
3
4
  guardNativeHandle,
4
5
  nativeSessionHandleSchema,
@@ -1434,6 +1435,9 @@ export class HarvestRunner {
1434
1435
  reservations.set(proposalKey, reservation)
1435
1436
  }
1436
1437
  const body = renderHarvestProposal(proposal, observations)
1438
+ // A configured createAssignee (`me` is this dispatcher's credential
1439
+ // owner) assigns the proposal; none sends no assignee.
1440
+ const assignees = creationAssignees(config.tickets)
1437
1441
  // Harvest proposals are always normal priority; grooming may mark one urgent.
1438
1442
  const ticket = (
1439
1443
  await tickets.create(
@@ -1442,6 +1446,7 @@ export class HarvestRunner {
1442
1446
  body,
1443
1447
  labels: [HARVEST_PROPOSAL_LABEL],
1444
1448
  ...(blockers.blockedBy.length > 0 ? { blockedBy: blockers.blockedBy } : {}),
1449
+ ...(assignees !== undefined ? { assignees } : {}),
1445
1450
  },
1446
1451
  {
1447
1452
  state: defaultProposalState(config),
@@ -127,6 +127,7 @@ export class RepoViewStore implements BuildStore {
127
127
  opts: RepoViewOptions,
128
128
  ) {
129
129
  this.getBuildEventPage = backing.getBuildEventPage?.bind(backing)
130
+ this.buildCreationIdentity = backing.buildCreationIdentity?.bind(backing)
130
131
  this.getRepositoryTail = backing.getRepositoryTail?.bind(backing)
131
132
  this.getStreamSeed = backing.getStreamSeed?.bind(backing)
132
133
  this.getHarvestHistoryPage = backing.getHarvestHistoryPage?.bind(backing)
@@ -295,6 +296,7 @@ export class RepoViewStore implements BuildStore {
295
296
  return this.backing.getRepoStateEvents(repo)
296
297
  }
297
298
  getBuildEventPage: BuildStore['getBuildEventPage']
299
+ buildCreationIdentity: BuildStore['buildCreationIdentity']
298
300
  getRepositoryTail: BuildStore['getRepositoryTail']
299
301
  getStreamSeed: BuildStore['getStreamSeed']
300
302
  getHarvestHistoryPage: BuildStore['getHarvestHistoryPage']
@@ -84,6 +84,17 @@ import { steppingClock } from '../testing/fixed'
84
84
  // The check command is the harness's control knob (§15.6-A): `test -f
85
85
  // ok.marker` fails until an implement round commits the marker file.
86
86
 
87
+ /** Repository dispatch lease budget for every scenario deriving from
88
+ * CONFIG_TOML. `steppingClock` advances 1 s per read while the lease heartbeat
89
+ * renews on real time, so nothing renews inside a fast scenario: under the
90
+ * 60 s product default a pass (or an in-process child sharing the clock)
91
+ * lapses its own authority after ~60 incidental reads. An hour keeps ordinary
92
+ * passes inside authority; scenarios that test expiry advance the clock past
93
+ * it explicitly (see overlap-lease-fencing). Mirrors the runner leaseTtlMs
94
+ * pinned in makeHarness. */
95
+ export const SCENARIO_DISPATCH_LEASE_SECONDS = 3600
96
+ export const SCENARIO_DISPATCH_LEASE_RENEWAL_SECONDS = 20
97
+
87
98
  export const CONFIG_TOML = `
88
99
  baseBranch = "main"
89
100
  capacity = 2
@@ -100,6 +111,8 @@ command = "test"
100
111
 
101
112
  [policy]
102
113
  stallRounds = 3
114
+ dispatchLeaseTimeoutSeconds = ${SCENARIO_DISPATCH_LEASE_SECONDS}
115
+ dispatchLeaseRenewalSeconds = ${SCENARIO_DISPATCH_LEASE_RENEWAL_SECONDS}
103
116
 
104
117
  [roles.default]
105
118
  runtime = "scripted"
@@ -697,7 +710,8 @@ export async function makeHarness(opts: {
697
710
  host: 'e2e-host',
698
711
  ...(sessionEnv !== undefined ? { sessionEnv } : {}),
699
712
  // Long lease/heartbeat: liveness is driven by the shared stepping
700
- // clock; scenarios advance it explicitly to expire a lease.
713
+ // clock; scenarios advance it explicitly to expire a lease. The
714
+ // repository dispatch lease follows SCENARIO_DISPATCH_LEASE_SECONDS.
701
715
  opts: {
702
716
  heartbeatMs: 3_600_000,
703
717
  leaseTtlMs: 3_600_000,