@kici-dev/orchestrator 0.1.26 → 0.2.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 (310) hide show
  1. package/dist/__test-helpers__/mock-db.d.ts +2 -0
  2. package/dist/agent/dispatcher.d.ts +52 -2
  3. package/dist/agent/host-roster-reaper.d.ts +1 -2
  4. package/dist/agent/host-roster.d.ts +34 -0
  5. package/dist/agent/ownership-refusal.d.ts +12 -0
  6. package/dist/agent/ownership-tracker.d.ts +64 -16
  7. package/dist/agent/token-store.d.ts +13 -0
  8. package/dist/agent-packaging/availability.d.ts +27 -0
  9. package/dist/agent-packaging/build-package.d.ts +16 -0
  10. package/dist/agent-packaging/download.d.ts +30 -0
  11. package/dist/agent-packaging/index.d.ts +9 -0
  12. package/dist/agent-packaging/install-closure.d.ts +30 -0
  13. package/dist/agent-packaging/node-binary.d.ts +26 -0
  14. package/dist/agent-packaging/refresh.d.ts +50 -0
  15. package/dist/agent-packaging/store.d.ts +15 -0
  16. package/dist/agent-packaging/upload.d.ts +24 -0
  17. package/dist/app-on-error.d.ts +29 -0
  18. package/dist/app.d.ts +69 -8
  19. package/dist/approvals/apply-decision.d.ts +1 -1
  20. package/dist/approvals/step-approval-bridge.d.ts +1 -1
  21. package/dist/artifacts/artifact-store.d.ts +233 -0
  22. package/dist/artifacts/failure-messages.d.ts +46 -0
  23. package/dist/audit/access-log.d.ts +18 -1
  24. package/dist/cache/dep-cache.d.ts +15 -0
  25. package/dist/cache/pending-inits.d.ts +4 -4
  26. package/dist/cache/user-cache.d.ts +37 -0
  27. package/dist/cancel/cancel-run.d.ts +10 -3
  28. package/dist/cancel/dashboard-cancel-handler.d.ts +19 -0
  29. package/dist/cli/api-client.d.ts +51 -5
  30. package/dist/cli/commands/agent-package.d.ts +34 -0
  31. package/dist/cli/commands/check-run.d.ts +26 -0
  32. package/dist/cli/commands/cluster-settings.d.ts +55 -0
  33. package/dist/cli/commands/context.d.ts +25 -0
  34. package/dist/cli/commands/dashboard-encryption-key.d.ts +3 -0
  35. package/dist/cli/commands/db-backup.d.ts +71 -0
  36. package/dist/cli/commands/debug-bundle.d.ts +1 -1
  37. package/dist/cli/commands/orchestrator-service/drain.d.ts +31 -0
  38. package/dist/cli/commands/orchestrator-service/index.d.ts +7 -4
  39. package/dist/cli/commands/orchestrator-service/install-env.d.ts +58 -0
  40. package/dist/cli/commands/secret.d.ts +45 -1
  41. package/dist/cli/commands/shared/admin-cli-access-log.d.ts +46 -0
  42. package/dist/cli/commands/shared/versioned-upgrade.d.ts +65 -2
  43. package/dist/cli/commands/signing-key.d.ts +3 -0
  44. package/dist/cli/commands/source.d.ts +12 -0
  45. package/dist/cli/commands/token.d.ts +9 -0
  46. package/dist/cli/commands/trust-policy.d.ts +48 -0
  47. package/dist/cli/commands/variable.d.ts +6 -6
  48. package/dist/cli/join.d.ts +1 -1
  49. package/dist/cli/service/index.d.ts +2 -2
  50. package/dist/cli/service/instance/manifest.d.ts +17 -0
  51. package/dist/cli/service/instance/resolve.d.ts +11 -0
  52. package/dist/cli/service/windows.d.ts +6 -0
  53. package/dist/cli/wizard/orchestrator-wizard.d.ts +39 -11
  54. package/dist/cli.js +10263 -3667
  55. package/dist/cluster/cluster-settings-reader.d.ts +78 -0
  56. package/dist/cluster/coordinator.d.ts +81 -9
  57. package/dist/cluster/join-client.d.ts +1 -1
  58. package/dist/cluster/leader-gated-scheduler.d.ts +50 -0
  59. package/dist/cluster/orphan-recovery.d.ts +14 -0
  60. package/dist/cluster/peer-client.d.ts +12 -2
  61. package/dist/cluster/peer-handler.d.ts +15 -4
  62. package/dist/cluster/peer-registry.d.ts +12 -0
  63. package/dist/cluster/verified-issuer-poller.d.ts +11 -0
  64. package/dist/cluster/verified-issuer.d.ts +63 -0
  65. package/dist/cold-store/tables/access-log.d.ts +1 -1
  66. package/dist/cold-store/tables/event-log.d.ts +1 -1
  67. package/dist/cold-store/tables/execution-jobs.d.ts +1 -1
  68. package/dist/cold-store/tables/execution-runs.d.ts +1 -1
  69. package/dist/cold-store/tables/execution-steps.d.ts +1 -1
  70. package/dist/cold-store/tables/secret-audit-log.d.ts +1 -1
  71. package/dist/config/loader.d.ts +1 -1
  72. package/dist/config/resolver.d.ts +2 -1
  73. package/dist/config/schema.d.ts +8 -6
  74. package/dist/config/types.d.ts +3 -2
  75. package/dist/config.d.ts +372 -46
  76. package/dist/contexts/binding-store.d.ts +36 -0
  77. package/dist/contexts/context-store.d.ts +100 -0
  78. package/dist/contexts/glob-specificity.d.ts +30 -0
  79. package/dist/{environments → contexts}/held-runs.d.ts +64 -32
  80. package/dist/{environments → contexts}/index.d.ts +1 -1
  81. package/dist/contexts/protection/aggregate.d.ts +43 -0
  82. package/dist/contexts/protection/branch-gate.d.ts +5 -0
  83. package/dist/contexts/protection/concurrency-gate.d.ts +4 -0
  84. package/dist/{environments → contexts}/protection/pipeline.d.ts +3 -3
  85. package/dist/contexts/protection/reviewer-gate.d.ts +4 -0
  86. package/dist/{environments → contexts}/protection/satisfiability.d.ts +22 -22
  87. package/dist/contexts/protection/trust-gate.d.ts +4 -0
  88. package/dist/contexts/protection/wait-timer-gate.d.ts +4 -0
  89. package/dist/contexts/variable-store.d.ts +39 -0
  90. package/dist/cron/cron-scheduler.d.ts +24 -4
  91. package/dist/cron/cron-store.d.ts +21 -7
  92. package/dist/dashboard/attestation-filters.d.ts +94 -74
  93. package/dist/dashboard/handler.d.ts +63 -3
  94. package/dist/db/migration-test-harness.d.ts +41 -0
  95. package/dist/db/migrations/067_environments_to_contexts.d.ts +36 -0
  96. package/dist/db/migrations/068_request_idempotency.d.ts +17 -0
  97. package/dist/db/migrations/069_reroute_tunables.d.ts +21 -0
  98. package/dist/db/migrations/070_execution_runs_failure_class.d.ts +4 -0
  99. package/dist/db/migrations/071_batch_accumulation.d.ts +26 -0
  100. package/dist/db/migrations/072_dispatch_queue_run_id_index.d.ts +15 -0
  101. package/dist/db/migrations/073_org_settings_ingest_concurrency.d.ts +13 -0
  102. package/dist/db/migrations/074_normalize_zero_concurrency_limit.d.ts +13 -0
  103. package/dist/db/migrations/075_ingest_overflow_buffer.d.ts +16 -0
  104. package/dist/db/migrations/076_artifacts.d.ts +19 -0
  105. package/dist/db/migrations/077_backup_runs.d.ts +13 -0
  106. package/dist/db/migrations/078_org_settings_backup_staleness.d.ts +12 -0
  107. package/dist/db/migrations/079_org_settings_scaler_spawn_timeout.d.ts +14 -0
  108. package/dist/db/migrations/080_cluster_settings.d.ts +17 -0
  109. package/dist/db/migrations/081_org_settings_queue_timeout.d.ts +19 -0
  110. package/dist/db/migrations/082_host_s3_reachable.d.ts +16 -0
  111. package/dist/db/migrations/083_org_settings_artifact_caps.d.ts +18 -0
  112. package/dist/db/migrations/084_orchestrator_signing_keys.d.ts +20 -0
  113. package/dist/db/migrations/085_cluster_settings_reroute_flap_grace_ms.d.ts +12 -0
  114. package/dist/db/migrations/086_cluster_settings_max_fanout_hosts.d.ts +12 -0
  115. package/dist/db/migrations/087_cluster_settings_event_router_rate_limit.d.ts +12 -0
  116. package/dist/db/migrations/088_cluster_settings_cache_max_tarball_bytes.d.ts +12 -0
  117. package/dist/db/migrations/089_cluster_settings_cache_ttl_days.d.ts +12 -0
  118. package/dist/db/migrations/090_cluster_settings_concurrency_wait_timeout_ms.d.ts +12 -0
  119. package/dist/db/migrations/091_cluster_settings_agent_token_ttl_ms.d.ts +12 -0
  120. package/dist/db/migrations/092_cluster_settings_version.d.ts +16 -0
  121. package/dist/db/migrations/093_org_settings_sandbox_allowlist.d.ts +4 -0
  122. package/dist/db/migrations/094_dashboard_encryption_keys.d.ts +21 -0
  123. package/dist/db/migrations/095_dashboard_write_policy_tristate.d.ts +20 -0
  124. package/dist/db/migrations/096_multi_schedule_cron_last_fired.d.ts +4 -0
  125. package/dist/db/migrations/097_execution_runs_pr_number.d.ts +4 -0
  126. package/dist/db/migrations/098_execution_runs_customer_id.d.ts +4 -0
  127. package/dist/db/migrations/099_cluster_settings_dashboard_verified_issuer.d.ts +21 -0
  128. package/dist/db/migrations/100_held_runs_hold_type_vocabulary.d.ts +31 -0
  129. package/dist/db/migrations/101_contexts_hold_expiry_drop_default.d.ts +31 -0
  130. package/dist/db/migrations/102_dispatch_queue_agent_id.d.ts +20 -0
  131. package/dist/db/migrations/103_cluster_settings_ownership_db_check_timeout_ms.d.ts +20 -0
  132. package/dist/db/migrations/104_check_run_terminal_sent.d.ts +22 -0
  133. package/dist/db/migrations/105_org_trust_policy.d.ts +19 -0
  134. package/dist/db/migrations/106_cluster_settings_check_run_tracking_ttl_days.d.ts +18 -0
  135. package/dist/db/migrations/107_check_run_tracking_updated_at_index.d.ts +23 -0
  136. package/dist/db/repos/dashboard-encryption-keys-repo.d.ts +48 -0
  137. package/dist/db/repos/signing-keys-repo.d.ts +34 -0
  138. package/dist/db/types.d.ts +499 -66
  139. package/dist/deployment/deployment-identity.d.ts +87 -2
  140. package/dist/diagnostics/checks/backup.d.ts +18 -0
  141. package/dist/diagnostics/checks/index.d.ts +2 -1
  142. package/dist/diagnostics/fleet-collector.d.ts +1 -1
  143. package/dist/drain/drain-controller.d.ts +52 -0
  144. package/dist/events/batch-accumulator.d.ts +63 -0
  145. package/dist/events/circuit-breaker.d.ts +9 -3
  146. package/dist/events/event-emitter.d.ts +31 -0
  147. package/dist/events/event-retry-scanner.d.ts +12 -2
  148. package/dist/events/event-router.d.ts +29 -0
  149. package/dist/firecracker/host-network.d.ts +2 -0
  150. package/dist/firecracker/net-interfaces.d.ts +14 -0
  151. package/dist/github-app-name-refresher/github-app-name-refresher.d.ts +19 -9
  152. package/dist/index.d.ts +2 -0
  153. package/dist/index.js +625 -22
  154. package/dist/lockfile-cache.d.ts +4 -0
  155. package/dist/lockfile-validate.d.ts +16 -9
  156. package/dist/metrics/prometheus.d.ts +114 -15
  157. package/dist/oidc/aws-kms-signer.d.ts +37 -0
  158. package/dist/oidc/command-signer.d.ts +23 -0
  159. package/dist/oidc/db-signer.d.ts +48 -0
  160. package/dist/oidc/id-token-claims.d.ts +76 -0
  161. package/dist/oidc/jwt.d.ts +18 -0
  162. package/dist/oidc/local-dev-signer.d.ts +31 -0
  163. package/dist/oidc/local-mint.d.ts +77 -0
  164. package/dist/oidc/oidc-mint-registration.d.ts +65 -0
  165. package/dist/oidc/orchestrator-mint.d.ts +97 -0
  166. package/dist/oidc/orchestrator-signer-factory.d.ts +33 -0
  167. package/dist/oidc/reconcile-signing-key.d.ts +21 -0
  168. package/dist/oidc/signer.d.ts +25 -0
  169. package/dist/oidc/signing-key-status.d.ts +23 -0
  170. package/dist/orchestrator-core.d.ts +42 -2
  171. package/dist/pipeline/decorating-secret-resolver.d.ts +5 -4
  172. package/dist/pipeline/dispatch-matched-workflow.d.ts +44 -3
  173. package/dist/pipeline/inline-eval.d.ts +2 -2
  174. package/dist/pipeline/install-secrets-resolver.d.ts +25 -14
  175. package/dist/pipeline/{job-environments.d.ts → job-contexts.d.ts} +23 -23
  176. package/dist/pipeline/manual-schedule.d.ts +28 -14
  177. package/dist/pipeline/pending-workflow-context.d.ts +1 -1
  178. package/dist/pipeline/process-webhook.d.ts +57 -2
  179. package/dist/pipeline/processor.d.ts +49 -13
  180. package/dist/pipeline/request-idempotency.d.ts +28 -0
  181. package/dist/pipeline/rerun.d.ts +20 -13
  182. package/dist/pipeline/resolve-sandbox-grant.d.ts +28 -0
  183. package/dist/pipeline/resume-workflow.d.ts +1 -1
  184. package/dist/pipeline/route-or-dispatch-jobs.d.ts +71 -0
  185. package/dist/pipeline/sandbox-allowlist-reader.d.ts +33 -0
  186. package/dist/pipeline/test-pipeline.d.ts +2 -2
  187. package/dist/policy/dashboard-write-policy.d.ts +9 -4
  188. package/dist/provenance/backfill-run.d.ts +1 -0
  189. package/dist/provenance/trust-root.d.ts +20 -0
  190. package/dist/provider-registry.d.ts +8 -0
  191. package/dist/providers/generic/normalizer.d.ts +1 -1
  192. package/dist/providers/github/auth.d.ts +1 -1
  193. package/dist/providers/github/changed-files.d.ts +14 -6
  194. package/dist/providers/github/check-status-poster.d.ts +19 -3
  195. package/dist/providers/github/contributor-resolver.d.ts +1 -1
  196. package/dist/providers/github/lock-file.d.ts +1 -1
  197. package/dist/providers/github/normalizer.d.ts +1 -1
  198. package/dist/providers/github/repo-url.d.ts +1 -1
  199. package/dist/providers/local/index.d.ts +1 -0
  200. package/dist/providers/local/local-source-config.d.ts +1 -0
  201. package/dist/providers/local/lock-file-fetcher.d.ts +1 -1
  202. package/dist/providers/local/normalizer.d.ts +1 -1
  203. package/dist/providers/local/repo-url-builder.d.ts +1 -1
  204. package/dist/providers/universal-git/changed-files.d.ts +8 -7
  205. package/dist/providers/universal-git/clone-token.d.ts +1 -1
  206. package/dist/providers/universal-git/config.d.ts +4 -4
  207. package/dist/providers/universal-git/index.d.ts +5 -1
  208. package/dist/providers/universal-git/lock-file.d.ts +6 -1
  209. package/dist/providers/universal-git/normalizer.d.ts +1 -1
  210. package/dist/providers/universal-git/repo-url.d.ts +1 -1
  211. package/dist/queue/cleanup.d.ts +69 -8
  212. package/dist/queue/job-queue.d.ts +94 -14
  213. package/dist/queue/scheduled-job.d.ts +2 -2
  214. package/dist/registration/registration-index.d.ts +1 -1
  215. package/dist/reporting/agent-failure-category.d.ts +4 -1
  216. package/dist/reporting/check-run-reporter.d.ts +34 -14
  217. package/dist/reporting/check-run-tracking-store.d.ts +70 -8
  218. package/dist/reporting/execution-tracker.d.ts +173 -17
  219. package/dist/reporting/fs-log-storage.d.ts +31 -2
  220. package/dist/reporting/job-check-run-completion.d.ts +50 -0
  221. package/dist/reporting/log-chunk-sink.d.ts +47 -0
  222. package/dist/reporting/log-retention.d.ts +16 -0
  223. package/dist/reporting/log-storage.d.ts +64 -4
  224. package/dist/reporting/log-writer.d.ts +22 -7
  225. package/dist/reporting/peer-log-normalize.d.ts +14 -0
  226. package/dist/reporting/run-aggregator.d.ts +36 -36
  227. package/dist/reporting/s3-log-storage.d.ts +102 -8
  228. package/dist/routes/admin-auth.d.ts +90 -0
  229. package/dist/routes/admin-cluster-settings.d.ts +31 -0
  230. package/dist/routes/admin-contexts.d.ts +47 -0
  231. package/dist/routes/admin-events.d.ts +3 -0
  232. package/dist/routes/admin-orchestrator-drain.d.ts +35 -0
  233. package/dist/routes/admin-registrations.d.ts +2 -2
  234. package/dist/routes/admin-runs.d.ts +9 -0
  235. package/dist/routes/admin-sources.d.ts +7 -0
  236. package/dist/routes/admin-trust-policy.d.ts +49 -0
  237. package/dist/routes/admin.d.ts +15 -1
  238. package/dist/routes/github-webhook.d.ts +9 -3
  239. package/dist/routes/provenance-oidc.d.ts +38 -0
  240. package/dist/routes/verify-attestation.d.ts +21 -0
  241. package/dist/scaler/bare-metal-backend.d.ts +9 -2
  242. package/dist/scaler/config.d.ts +25 -4
  243. package/dist/scaler/container-backend.d.ts +9 -1
  244. package/dist/scaler/firecracker-backend.d.ts +29 -2
  245. package/dist/scaler/index.d.ts +1 -1
  246. package/dist/scaler/manager.d.ts +166 -8
  247. package/dist/scaler/pending-scale-sweeper.d.ts +35 -0
  248. package/dist/scaler/types.d.ts +75 -6
  249. package/dist/secrets/backend-registry.d.ts +32 -1
  250. package/dist/secrets/context-secret-resolver.d.ts +30 -0
  251. package/dist/secrets/dashboard-encryption-key.d.ts +48 -0
  252. package/dist/secrets/ephemeral-keys.d.ts +16 -0
  253. package/dist/secrets/index.d.ts +1 -1
  254. package/dist/secrets/pg-secret-store.d.ts +13 -3
  255. package/dist/secrets/rbac.d.ts +5 -1
  256. package/dist/secrets/routing-key-scope.d.ts +6 -0
  257. package/dist/secrets/scope-routing.d.ts +126 -0
  258. package/dist/secrets/secret-resolver.d.ts +19 -32
  259. package/dist/secrets/token-manager.d.ts +5 -1
  260. package/dist/security/comment-handler.d.ts +1 -1
  261. package/dist/security/contributor-cache.d.ts +9 -1
  262. package/dist/security/trust-policy-gate.d.ts +117 -0
  263. package/dist/security/trust-policy-store.d.ts +78 -0
  264. package/dist/server.js +44012 -32721
  265. package/dist/sources/source-manager.d.ts +24 -0
  266. package/dist/stale-detector/stale-run-detector.d.ts +8 -1
  267. package/dist/standalone.js +44106 -33690
  268. package/dist/storage/blob-routes.d.ts +16 -0
  269. package/dist/storage/filesystem.d.ts +17 -0
  270. package/dist/storage/key-discriminator.d.ts +20 -0
  271. package/dist/storage/s3.d.ts +2 -0
  272. package/dist/storage/types.d.ts +16 -0
  273. package/dist/webhook/dedup.d.ts +9 -1
  274. package/dist/webhook/event-log.d.ts +13 -2
  275. package/dist/webhook/generic-sources-listener.d.ts +4 -0
  276. package/dist/webhook/ingest-admission.d.ts +140 -0
  277. package/dist/webhook/ingest-overflow-buffer.d.ts +27 -0
  278. package/dist/webhook/ingest-overflow-replayer.d.ts +49 -0
  279. package/dist/webhook/ingest-overflow-types.d.ts +73 -0
  280. package/dist/webhook/loop-lag-source.d.ts +40 -0
  281. package/dist/webhook/observed-relay-guard.d.ts +40 -0
  282. package/dist/webhook/org-ingest-cap-reader.d.ts +24 -0
  283. package/dist/webhook/register-source-bundle.d.ts +3 -0
  284. package/dist/webhook/relay-reinject.d.ts +43 -0
  285. package/dist/worker/in-memory-job-queue.d.ts +8 -3
  286. package/dist/worker-core.d.ts +10 -0
  287. package/dist/ws/agent-api-registry.d.ts +20 -0
  288. package/dist/ws/agent-handler.d.ts +63 -7
  289. package/dist/ws/bringup-api.d.ts +99 -0
  290. package/dist/ws/{dashboard-env-handler.d.ts → dashboard-context-handler.d.ts} +43 -25
  291. package/dist/ws/dashboard-run-state-handler.d.ts +31 -0
  292. package/dist/ws/failure-messages.d.ts +29 -0
  293. package/dist/ws/oidc-token-relay.d.ts +15 -0
  294. package/dist/ws/ownership-gate.d.ts +22 -0
  295. package/dist/ws/platform-client.d.ts +96 -1
  296. package/dist/ws/replay-chunker.d.ts +37 -0
  297. package/installer-image-digests.json +3 -3
  298. package/package.json +22 -21
  299. package/sbom.spdx.json +1245 -1793
  300. package/dist/cli/commands/environment.d.ts +0 -25
  301. package/dist/environments/binding-store.d.ts +0 -36
  302. package/dist/environments/environment-store.d.ts +0 -87
  303. package/dist/environments/protection/aggregate.d.ts +0 -43
  304. package/dist/environments/protection/branch-gate.d.ts +0 -5
  305. package/dist/environments/protection/concurrency-gate.d.ts +0 -7
  306. package/dist/environments/protection/reviewer-gate.d.ts +0 -7
  307. package/dist/environments/protection/trust-gate.d.ts +0 -7
  308. package/dist/environments/protection/wait-timer-gate.d.ts +0 -7
  309. package/dist/environments/variable-store.d.ts +0 -39
  310. package/dist/routes/admin-environments.d.ts +0 -47
@@ -44,7 +44,7 @@ export declare function createInstallationOctokit(config: GitHubAppConfig, insta
44
44
  */
45
45
  export declare class GitHubCloneTokenProvider implements CloneTokenProvider {
46
46
  private readonly config;
47
- readonly provider: "github";
47
+ readonly provider: 'github';
48
48
  constructor(config: GitHubAppConfig);
49
49
  /** Get the GitHub App config for this provider instance. */
50
50
  getAppConfig(): GitHubAppConfig;
@@ -4,7 +4,7 @@
4
4
  * Implements the ChangedFilesFetcher interface from @kici-dev/engine for GitHub.
5
5
  * Retrieves changed files for PR and push events via the GitHub API.
6
6
  */
7
- import type { ChangedFilesFetcher } from '@kici-dev/engine';
7
+ import type { ChangedFilesFetcher, ChangedFilesResult } from '@kici-dev/engine';
8
8
  import { type GitHubAppConfig } from './auth.js';
9
9
  /**
10
10
  * Check if an error is a GitHub 429 rate limit response.
@@ -12,9 +12,17 @@ import { type GitHubAppConfig } from './auth.js';
12
12
  */
13
13
  export declare function isRateLimitError(err: unknown): boolean;
14
14
  /**
15
- * Execute a function with retry on 429 rate limit errors.
16
- * Uses exponential backoff: 1s, 2s, 4s.
17
- * Non-429 errors are rethrown immediately.
15
+ * Check if an error is a transient GitHub 5xx server error worth retrying.
16
+ * A pure network error (no numeric `status`) is deliberately NOT transient
17
+ * here it rethrows immediately (loud) rather than masking a persistent
18
+ * connectivity fault behind silent retries.
19
+ */
20
+ export declare function isTransientServerError(err: unknown): boolean;
21
+ /**
22
+ * Execute a function with bounded retry on 429 rate-limit AND 5xx server
23
+ * errors, each with its own budget and exponential backoff (1s, 2s, …).
24
+ * Every other error — a 4xx, or a network error with no `status` — is
25
+ * rethrown immediately (loud; not retried).
18
26
  */
19
27
  export declare function withRateLimitRetry<T>(fn: () => Promise<T>, context: string): Promise<T>;
20
28
  /**
@@ -27,7 +35,7 @@ export declare function withRateLimitRetry<T>(fn: () => Promise<T>, context: str
27
35
  */
28
36
  export declare class GitHubChangedFilesFetcher implements ChangedFilesFetcher {
29
37
  private readonly config;
30
- readonly provider: "github";
38
+ readonly provider: 'github';
31
39
  constructor(config: GitHubAppConfig);
32
40
  /**
33
41
  * Get changed files for a GitHub webhook event.
@@ -38,7 +46,7 @@ export declare class GitHubChangedFilesFetcher implements ChangedFilesFetcher {
38
46
  * @param credentials - Must be GitHubCredentials with installationId
39
47
  * @returns Array of changed file paths
40
48
  */
41
- getChangedFiles(repoIdentifier: string, eventType: string, payload: unknown, credentials: unknown): Promise<string[]>;
49
+ getChangedFiles(repoIdentifier: string, eventType: string, payload: unknown, credentials: unknown): Promise<ChangedFilesResult>;
42
50
  /**
43
51
  * Get changed files for a pull request event using paginated listFiles API.
44
52
  */
@@ -2,10 +2,15 @@
2
2
  * GitHub implementation of the CheckStatusPoster interface.
3
3
  *
4
4
  * Posts check statuses to GitHub PRs using the Checks API for:
5
- * - Security holds (pending): "KiCI Security: Held for approval"
6
- * - Workflow modifications (neutral): "KiCI: Workflow changes detected"
5
+ * - Security holds (pending): "KiCI Security" — "Held for approval"
6
+ * - Workflow modifications (neutral): "KiCI: Workflow changes"
7
+ * - Org globals skipped by the trust policy (neutral): "KiCI: Organization workflows"
7
8
  * - Approved runs (success) / Rejected/expired runs (failure)
8
9
  *
10
+ * `postWorkflowModificationCheck` and `postGlobalWorkflowsSkippedCheck` are
11
+ * interface-backed (the `CheckStatusPoster` contract in `@kici-dev/engine`) and
12
+ * post on their own check names so neither overwrites the security-hold check.
13
+ *
9
14
  * Reuses the Octokit infrastructure from auth.ts via createInstallationOctokit.
10
15
  * Uses a fixed check name per category so that subsequent updates (approve/reject)
11
16
  * can find and update the existing check run.
@@ -21,7 +26,7 @@ import type { WorkflowModification } from '../../security/workflow-diff.js';
21
26
  */
22
27
  export declare class GitHubCheckStatusPoster implements CheckStatusPoster {
23
28
  private readonly getOctokit;
24
- readonly provider: "github";
29
+ readonly provider: 'github';
25
30
  constructor(getOctokit: (credentials: unknown) => Octokit);
26
31
  postCheckStatus(repoIdentifier: string, commitSha: string, status: CheckStatus, title: string, summary: string, credentials: unknown): Promise<void>;
27
32
  /**
@@ -31,5 +36,16 @@ export declare class GitHubCheckStatusPoster implements CheckStatusPoster {
31
36
  * conflict with the security hold check. Always posted as neutral/completed.
32
37
  */
33
38
  postWorkflowModificationCheck(repoIdentifier: string, commitSha: string, modifications: WorkflowModification[], credentials: unknown): Promise<void>;
39
+ /**
40
+ * Post the informational check recording that the org's global workflows were
41
+ * skipped because the trust policy held or rejected the event.
42
+ *
43
+ * Uses a separate check name ("KiCI: Organization workflows") so it never
44
+ * overwrites the security-hold check: that one is a single named run per
45
+ * commit which the hold posts as pending and approve / reject later complete,
46
+ * so writing this notice onto it would resolve the hold's check to neutral
47
+ * while the run is still held. Always posted as neutral/completed.
48
+ */
49
+ postGlobalWorkflowsSkippedCheck(repoIdentifier: string, commitSha: string, summary: string, credentials: unknown): Promise<void>;
34
50
  }
35
51
  //# sourceMappingURL=check-status-poster.d.ts.map
@@ -15,7 +15,7 @@ import { type GitHubAppConfig } from './auth.js';
15
15
  */
16
16
  export declare class GitHubContributorResolver implements ContributorResolver {
17
17
  private readonly config;
18
- readonly provider: "github";
18
+ readonly provider: 'github';
19
19
  constructor(config: GitHubAppConfig);
20
20
  /**
21
21
  * Resolve a contributor's permission level on a GitHub repository.
@@ -17,7 +17,7 @@ import { type GitHubAppConfig } from './auth.js';
17
17
  */
18
18
  export declare class GitHubLockFileFetcher implements LockFileFetcher {
19
19
  private readonly config;
20
- readonly provider: "github";
20
+ readonly provider: 'github';
21
21
  constructor(config: GitHubAppConfig);
22
22
  /**
23
23
  * Fetch the lock file from a GitHub repository at a specific ref.
@@ -12,7 +12,7 @@ import type { WebhookNormalizer, SimulatedEvent, AccessCacheInvalidation } from
12
12
  * Headers are expected lowercase (Hono normalizes them).
13
13
  */
14
14
  export declare class GitHubWebhookNormalizer implements WebhookNormalizer {
15
- readonly provider: "github";
15
+ readonly provider: 'github';
16
16
  /**
17
17
  * Extract routing key from GitHub webhook headers.
18
18
  *
@@ -12,7 +12,7 @@ import type { RepoUrlBuilder } from '@kici-dev/engine';
12
12
  * repoIdentifier is expected in "owner/repo" format.
13
13
  */
14
14
  export declare class GitHubRepoUrlBuilder implements RepoUrlBuilder {
15
- readonly provider: "github";
15
+ readonly provider: 'github';
16
16
  /**
17
17
  * Build the HTTPS clone URL for a GitHub repository.
18
18
  *
@@ -29,5 +29,6 @@ export { LocalRepoUrlBuilder } from './repo-url-builder.js';
29
29
  export declare function createLocalProviderBundle(opts: {
30
30
  repoBasePath: string;
31
31
  cloneUrlBase?: string;
32
+ inPlace?: boolean;
32
33
  }): ProviderBundle;
33
34
  //# sourceMappingURL=index.d.ts.map
@@ -12,6 +12,7 @@ import { z } from 'zod';
12
12
  export declare const LocalSourceConfigSchema: z.ZodObject<{
13
13
  repoBasePath: z.ZodString;
14
14
  cloneUrlBase: z.ZodOptional<z.ZodString>;
15
+ inPlace: z.ZodOptional<z.ZodBoolean>;
15
16
  }, z.core.$strict>;
16
17
  export type LocalSourceConfig = z.infer<typeof LocalSourceConfigSchema>;
17
18
  //# sourceMappingURL=local-source-config.d.ts.map
@@ -14,7 +14,7 @@ import type { LockFileFetcher, LockFile } from '@kici-dev/engine';
14
14
  */
15
15
  export declare class LocalLockFileFetcher implements LockFileFetcher {
16
16
  private readonly repoBasePath;
17
- readonly provider: "local";
17
+ readonly provider: 'local';
18
18
  /**
19
19
  * @param repoBasePath - Base directory for the repo(s). When repoIdentifier
20
20
  * starts with 'file://', it is stripped and used as-is. Otherwise
@@ -17,7 +17,7 @@ import type { WebhookNormalizer, SimulatedEvent, AccessCacheInvalidation } from
17
17
  * (e.g., {ref: 'refs/heads/master', repository: {full_name: 'test/repo'}}).
18
18
  */
19
19
  export declare class LocalWebhookNormalizer implements WebhookNormalizer {
20
- readonly provider: "local";
20
+ readonly provider: 'local';
21
21
  /**
22
22
  * Extract routing key from the local-source webhook headers.
23
23
  *
@@ -16,7 +16,7 @@ import type { RepoUrlBuilder } from '@kici-dev/engine';
16
16
  export declare class LocalRepoUrlBuilder implements RepoUrlBuilder {
17
17
  private readonly repoBasePath;
18
18
  private readonly cloneUrlBase?;
19
- readonly provider: "local";
19
+ readonly provider: 'local';
20
20
  /**
21
21
  * @param repoBasePath - Base directory where test repos live on disk
22
22
  * @param cloneUrlBase - Optional URL base for clone operations (e.g. git://host/path).
@@ -8,12 +8,13 @@
8
8
  * `commits[].{added,modified,removed}` arrays in the push payload, so we
9
9
  * extract them via JSONPath from the already-delivered webhook body.
10
10
  *
11
- * For PR events we return an empty list: the upstream trigger matcher treats
12
- * empty changed-files as "match any path", which is the safest default when
13
- * we don't have per-PR diff data. A follow-up can add an optional REST
14
- * fetcher if source authors want PR path filtering.
11
+ * For PR events we report `unavailable`: no per-commit diff is present in the
12
+ * webhook body, so the upstream trigger matcher matches path filters
13
+ * conservatively (the workflow runs) instead of silently never matching. A
14
+ * follow-up can add an optional REST fetcher if source authors want exact PR
15
+ * path filtering.
15
16
  */
16
- import type { ChangedFilesFetcher } from '@kici-dev/engine';
17
+ import type { ChangedFilesFetcher, ChangedFilesResult } from '@kici-dev/engine';
17
18
  import { type UniversalGitConfig } from './config.js';
18
19
  /**
19
20
  * Universal-git implementation of ChangedFilesFetcher.
@@ -22,7 +23,7 @@ import { type UniversalGitConfig } from './config.js';
22
23
  * expanded `payloadPaths` + `eventMapping`.
23
24
  */
24
25
  export declare class UniversalGitChangedFilesFetcher implements ChangedFilesFetcher {
25
- readonly provider: "generic";
26
+ readonly provider: 'generic';
26
27
  private readonly paths;
27
28
  private readonly eventMapping;
28
29
  constructor(params: {
@@ -36,7 +37,7 @@ export declare class UniversalGitChangedFilesFetcher implements ChangedFilesFetc
36
37
  * @param payload The webhook body the forge delivered.
37
38
  * @param _credentials Unused — no REST call is made.
38
39
  */
39
- getChangedFiles(_repoIdentifier: string, eventType: string, payload: unknown, _credentials: unknown): Promise<string[]>;
40
+ getChangedFiles(_repoIdentifier: string, eventType: string, payload: unknown, _credentials: unknown): Promise<ChangedFilesResult>;
40
41
  private classifyEvent;
41
42
  }
42
43
  //# sourceMappingURL=changed-files.d.ts.map
@@ -42,7 +42,7 @@ export interface UniversalGitAuth extends ProviderGitAuth {
42
42
  */
43
43
  export declare class UniversalGitCloneTokenProvider implements CloneTokenProvider {
44
44
  private readonly params;
45
- readonly provider: "generic";
45
+ readonly provider: 'generic';
46
46
  constructor(params: {
47
47
  orgId: string;
48
48
  sourceId: string;
@@ -22,9 +22,9 @@ export declare const UniversalGitPreset: z.ZodEnum<{
22
22
  custom: "custom";
23
23
  forgejo: "forgejo";
24
24
  gitea: "gitea";
25
- gogs: "gogs";
26
- "gitlab-repo": "gitlab-repo";
27
25
  "github-repo": "github-repo";
26
+ "gitlab-repo": "gitlab-repo";
27
+ gogs: "gogs";
28
28
  }>;
29
29
  export type UniversalGitPreset = z.infer<typeof UniversalGitPreset>;
30
30
  /**
@@ -101,9 +101,9 @@ export declare const UniversalGitConfigSchema: z.ZodObject<{
101
101
  custom: "custom";
102
102
  forgejo: "forgejo";
103
103
  gitea: "gitea";
104
- gogs: "gogs";
105
- "gitlab-repo": "gitlab-repo";
106
104
  "github-repo": "github-repo";
105
+ "gitlab-repo": "gitlab-repo";
106
+ gogs: "gogs";
107
107
  }>;
108
108
  gitUrlTemplate: z.ZodString;
109
109
  credentialRef: z.ZodObject<{
@@ -24,6 +24,7 @@
24
24
  import type { ProviderBundle } from '../../provider-registry.js';
25
25
  import type { GenericWebhookSource } from '../../db/types.js';
26
26
  import type { SecretResolver } from '../../secrets/secret-resolver.js';
27
+ import type { ClusterSettingsReader } from '../../cluster/cluster-settings-reader.js';
27
28
  import { type UniversalGitConfig } from './config.js';
28
29
  export { UniversalGitWebhookNormalizer } from './normalizer.js';
29
30
  export { UniversalGitLockFileFetcher, LockFileTooLargeError } from './lock-file.js';
@@ -51,5 +52,8 @@ export declare function parseSourceGitConfig(raw: string | Record<string, unknow
51
52
  * generic webhook, not a universal-git source) — callers can rely on this
52
53
  * to differentiate the two shapes without re-parsing the row.
53
54
  */
54
- export declare function createUniversalGitProviderBundle(source: Pick<GenericWebhookSource, 'id' | 'customer_id' | 'routing_key' | 'git_config'>, secretResolver: SecretResolver): ProviderBundle | null;
55
+ export declare function createUniversalGitProviderBundle(source: Pick<GenericWebhookSource, 'id' | 'customer_id' | 'routing_key' | 'git_config'>, secretResolver: SecretResolver, opts?: {
56
+ clusterSettings?: ClusterSettingsReader;
57
+ lockFileMaxBytes?: number;
58
+ }): ProviderBundle | null;
55
59
  //# sourceMappingURL=index.d.ts.map
@@ -30,6 +30,7 @@
30
30
  */
31
31
  import type { LockFileFetcher, LockFile } from '@kici-dev/engine';
32
32
  import type { SecretResolver } from '../../secrets/secret-resolver.js';
33
+ import type { ClusterSettingsReader } from '../../cluster/cluster-settings-reader.js';
33
34
  import type { UniversalGitConfig } from './config.js';
34
35
  /**
35
36
  * Typed error for the 5 MiB cap. Callers can differentiate this from
@@ -49,13 +50,17 @@ export declare class LockFileTooLargeError extends Error {
49
50
  */
50
51
  export declare class UniversalGitLockFileFetcher implements LockFileFetcher {
51
52
  private readonly params;
52
- readonly provider: "generic";
53
+ readonly provider: 'generic';
53
54
  private readonly repoUrlBuilder;
54
55
  constructor(params: {
55
56
  orgId: string;
56
57
  sourceId: string;
57
58
  config: UniversalGitConfig;
58
59
  secretResolver: SecretResolver;
60
+ /** Fleet-wide settings reader; overrides the lock-file cap per fetch. */
61
+ clusterSettings?: ClusterSettingsReader;
62
+ /** Cluster default cap (bytes) when no cluster_settings override is set. */
63
+ lockFileMaxBytes?: number;
59
64
  });
60
65
  /**
61
66
  * Shallow-clone the source repo at `ref` into a private tempdir, read
@@ -22,7 +22,7 @@ import { type UniversalGitConfig } from './config.js';
22
22
  * registered `generic_webhook_sources` row with a non-null `git_config`.
23
23
  */
24
24
  export declare class UniversalGitWebhookNormalizer implements WebhookNormalizer {
25
- readonly provider: "generic";
25
+ readonly provider: 'generic';
26
26
  private readonly routingKey;
27
27
  private readonly paths;
28
28
  private readonly eventMapping;
@@ -18,7 +18,7 @@ import type { RepoUrlBuilder } from '@kici-dev/engine';
18
18
  */
19
19
  export declare class UniversalGitRepoUrlBuilder implements RepoUrlBuilder {
20
20
  private readonly gitUrlTemplate;
21
- readonly provider: "generic";
21
+ readonly provider: 'generic';
22
22
  constructor(gitUrlTemplate: string);
23
23
  /**
24
24
  * Build the clone URL by substituting placeholders in the template with
@@ -1,7 +1,71 @@
1
1
  import { type Kysely } from 'kysely';
2
+ import { type LabelMatcher } from '@kici-dev/engine';
2
3
  import type { Database } from '../db/types.js';
3
4
  import type { ExecutionTracker } from '../reporting/execution-tracker.js';
5
+ import type { CheckRunReporter } from '../reporting/check-run-reporter.js';
6
+ import type { CheckRunTrackingStore } from '../reporting/check-run-tracking-store.js';
7
+ import type { ClusterSettingsReader } from '../cluster/cluster-settings-reader.js';
8
+ import type { LogStorage } from '../reporting/log-storage.js';
4
9
  import { JobQueue } from './job-queue.js';
10
+ /**
11
+ * Optional cleanup dependencies + retention knobs. Present in platform/hybrid
12
+ * mode (the only wiring site, `orchestrator-core`, always supplies them); the
13
+ * retention sweeps and Platform status-forwarding run only when this is set.
14
+ */
15
+ export interface CleanupExtras {
16
+ db: Kysely<Database>;
17
+ executionTracker: ExecutionTracker;
18
+ /**
19
+ * Resolves each expired job's check run to a terminal conclusion.
20
+ *
21
+ * Required for correctness, not decoration: this sweep settles a job by
22
+ * writing `execution_jobs` directly rather than through
23
+ * `ExecutionTracker.onJobStatus`, so the tracker's terminal-job hook — the
24
+ * funnel a tracker-driven terminal status reaches the check-run reporter
25
+ * through — never fires here. Absent, the check run created at trigger match
26
+ * stays `queued` on the commit forever, which no branch-protection rule
27
+ * requiring it can ever be satisfied by.
28
+ */
29
+ checkRunReporter?: Pick<CheckRunReporter, 'updateJobStatus'>;
30
+ /** Terminal dispatch_queue row retention (days); 0 disables. Default 30. */
31
+ dispatchQueueTtlDays?: number;
32
+ /** Step-log object retention (days); 0 disables. Default 90. */
33
+ stepLogTtlDays?: number;
34
+ /** Store for `check_run_tracking`; the retention sweep runs only when wired. */
35
+ checkRunTrackingStore?: CheckRunTrackingStore;
36
+ /** Live cluster-settings reader; absent ⇒ the config default is used as-is. */
37
+ clusterSettings?: ClusterSettingsReader;
38
+ /** `check_run_tracking` row retention (days); 0 disables. Default 7. */
39
+ checkRunTrackingTtlDays?: number;
40
+ /** The orchestrator's log storage — the S3 sweep runs only when S3-backed. */
41
+ logStorage?: LogStorage;
42
+ /** True when `logStorage` is the S3 backend (the filesystem backend is
43
+ * customer-managed, so its lifecycle stays the operator's concern). */
44
+ logStorageIsS3?: boolean;
45
+ /**
46
+ * Whether ANYTHING could ever have run a job with these selectors — a
47
+ * registered agent (regardless of capacity) or a scaler backend able to spawn
48
+ * one.
49
+ *
50
+ * Read once per expired job to split the two reasons a queued job never ran:
51
+ * nothing in the fleet matched its `runsOn` (`unroutable` — a label/fleet
52
+ * problem an operator has to fix) versus something matched but never produced
53
+ * a usable agent (`timed_out_stale` — a capacity or provisioning problem).
54
+ * Both halves are load-bearing: a scaler-managed pool at zero has no
55
+ * registered agent yet still routes perfectly well, so asking only the agent
56
+ * registry would report every failed spawn as a bad `runsOn`.
57
+ *
58
+ * Asked at expiry rather than at dispatch so a label satisfied moments later
59
+ * by an autoscaled agent is not mislabelled unroutable. Absent → every expiry
60
+ * stays `timed_out_stale`, the behaviour before the split existed.
61
+ *
62
+ * The predicate is allowed to answer "routable" conservatively (the scaler
63
+ * half matches exact labels only, so a pattern-only `runsOn` reads routable on
64
+ * a scaler-configured orchestrator). That costs precision on the status, never
65
+ * safety: the job is terminal either way and the run fails either way.
66
+ */
67
+ canRouteLabels?: (requiredLabels: string[], requiredPatterns: LabelMatcher[], excludeLabels: string[], excludePatterns: LabelMatcher[]) => boolean;
68
+ }
5
69
  /**
6
70
  * Run a single cleanup pass: remove expired dedup_cache entries and
7
71
  * mark expired dispatch_queue entries.
@@ -18,12 +82,12 @@ import { JobQueue } from './job-queue.js';
18
82
  */
19
83
  export declare function runCleanup(dedup: {
20
84
  cleanup(): Promise<number>;
21
- }, queue: JobQueue, extras?: {
22
- db: Kysely<Database>;
23
- executionTracker: ExecutionTracker;
24
- }): Promise<{
85
+ }, queue: JobQueue, extras?: CleanupExtras): Promise<{
25
86
  dedupDeleted: number;
26
87
  queueExpired: number;
88
+ dispatchRowsPruned: number;
89
+ logObjectsPruned: number;
90
+ checkRunRowsPruned: number;
27
91
  }>;
28
92
  /**
29
93
  * Build a per-tick handler for the queue-cleanup scheduled job.
@@ -34,8 +98,5 @@ export declare function runCleanup(dedup: {
34
98
  */
35
99
  export declare function createCleanupHandler(dedup: {
36
100
  cleanup(): Promise<number>;
37
- }, queue: JobQueue, extras?: {
38
- db: Kysely<Database>;
39
- executionTracker: ExecutionTracker;
40
- }): () => Promise<void>;
101
+ }, queue: JobQueue, extras?: CleanupExtras): () => Promise<void>;
41
102
  //# sourceMappingURL=cleanup.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import { type Kysely } from 'kysely';
2
2
  import { type LabelMatcher, type ResourceRequest } from '@kici-dev/engine';
3
3
  import type { Database } from '../db/types.js';
4
+ import type { ClusterSettingsReader } from '../cluster/cluster-settings-reader.js';
4
5
  /** Info about an expired dispatch_queue entry, returned by markExpired(). */
5
6
  export interface ExpiredJobInfo {
6
7
  /** dispatch_queue row ID */
@@ -9,6 +10,16 @@ export interface ExpiredJobInfo {
9
10
  jobName: string;
10
11
  /** Most recent scaler spawn-failure detail, if any was recorded. */
11
12
  lastProvisioningError: string | null;
13
+ /**
14
+ * The job's routing selectors, carried so the expiry sweep can ask whether
15
+ * any agent could ever have run it. A job that expires with NO matching agent
16
+ * is `unroutable` (a fleet/label problem); one whose agent existed but never
17
+ * freed up is `timed_out_stale` (a capacity problem).
18
+ */
19
+ runsOnLabels: string[];
20
+ runsOnPatterns: LabelMatcher[];
21
+ excludeLabels: string[];
22
+ excludePatterns: LabelMatcher[];
12
23
  }
13
24
  /**
14
25
  * Point-in-time breakdown of dispatch_queue depth used for Prometheus gauges
@@ -167,8 +178,12 @@ export interface QueuedJob {
167
178
  */
168
179
  export declare class JobQueue {
169
180
  private readonly db;
170
- private readonly maxDepth;
181
+ /** Cluster-wide fallback for queue_max_depth when cluster_settings is null. */
182
+ private readonly defaultMaxDepth;
171
183
  private readonly defaultTimeoutMs;
184
+ private readonly clusterSettings?;
185
+ /** Per-job (per-org) queue-timeout resolver; falls back to defaultTimeoutMs. */
186
+ private readonly getQueueTimeoutMs?;
172
187
  /** 1-second TTL cache for pending depth count to avoid extra SELECT COUNT per enqueue. */
173
188
  private depthCache;
174
189
  /**
@@ -181,9 +196,16 @@ export declare class JobQueue {
181
196
  constructor(db: Kysely<Database>, options: {
182
197
  maxDepth: number;
183
198
  defaultTimeoutMs: number;
199
+ clusterSettings?: ClusterSettingsReader;
200
+ getQueueTimeoutMs?: (job: {
201
+ jobConfig?: Record<string, unknown>;
202
+ }) => Promise<number>;
184
203
  });
185
204
  /**
186
- * Enqueue a job. Checks depth first, rejects with 'queue full' if >= maxDepth.
205
+ * Enqueue a job. Checks depth first, rejects with 'queue full' if >= the
206
+ * fleet-wide `queue_max_depth` (cluster_settings, falling back to the config
207
+ * default). The per-job timeout resolves through the per-org
208
+ * `queue_timeout_ms` override.
187
209
  * @returns The generated job ID.
188
210
  */
189
211
  enqueue(job: QueuedJobInput): Promise<string>;
@@ -269,17 +291,38 @@ export declare class JobQueue {
269
291
  /**
270
292
  * Insert a job directly with status='dispatched' (bypasses the queue).
271
293
  * Used when an agent is immediately available and the job doesn't need to wait.
272
- * @returns The generated job ID.
294
+ *
295
+ * `agentId` is the durable owner, written here for the same reason
296
+ * {@link markDispatched} writes it on the queue-drain path: this row is
297
+ * dispatched the moment it is inserted, so it never passes through
298
+ * `markDispatched` and would otherwise carry a NULL owner for its whole life.
299
+ * A coordinator that never saw the dispatch resolves ownership from this
300
+ * column alone, so omitting it here would make {@link hasAgentOwnedJob} answer
301
+ * "not owned" for every directly-dispatched job after a failover.
302
+ *
303
+ * Idempotent on the primary key: a reroute re-dispatch reuses a preassigned
304
+ * jobId, so a concurrent reroute from a sibling coordinator (or a duplicate
305
+ * delivery) may target a row this instance already wrote. ON CONFLICT (id) DO
306
+ * NOTHING makes that a no-op instead of a dispatch_queue_pkey error; the
307
+ * returned `inserted` flag tells the caller whether a fresh row was created so
308
+ * it can avoid double-dispatching an already-present job. The conflicting row
309
+ * keeps the owner the winning writer recorded.
310
+ *
311
+ * @returns The job ID and whether a new row was inserted (false = row already existed).
273
312
  */
274
- insertDispatched(job: QueuedJobInput): Promise<string>;
313
+ insertDispatched(job: QueuedJobInput, agentId: string): Promise<{
314
+ id: string;
315
+ inserted: boolean;
316
+ }>;
275
317
  /**
276
- * Mark a job as dispatched.
318
+ * Mark a job as dispatched and record the agent it went to.
277
319
  *
278
- * Note: agentId is not persisted in the dispatch_queue table.
279
- * The dispatcher tracks agent-to-job mappings in memory (agentJobs Map).
280
- * The dispatch_queue is a transient routing table, not the execution record.
320
+ * `agent_id` is the durable owner: the dispatcher also tracks agent-to-job
321
+ * mappings in memory (agentJobs Map), but that map is per-coordinator, so a
322
+ * coordinator that never saw the dispatch has to read the owner back from the
323
+ * row to answer an ownership question.
281
324
  */
282
- markDispatched(jobId: string, _agentId: string): Promise<void>;
325
+ markDispatched(jobId: string, agentId: string): Promise<void>;
283
326
  /**
284
327
  * Mark a job as failed.
285
328
  *
@@ -329,6 +372,23 @@ export declare class JobQueue {
329
372
  * @returns Number of affected rows.
330
373
  */
331
374
  cancelByRunId(runId: string): Promise<number>;
375
+ /**
376
+ * Delete terminal dispatch_queue rows older than `retentionDays`.
377
+ *
378
+ * `dispatch_queue` is operational dispatch state; the durable run history
379
+ * lives in the cold-stored execution_runs/jobs/steps tables, so a terminal
380
+ * ({@link DispatchQueueStatus.Completed}/{@link DispatchQueueStatus.Failed}/
381
+ * {@link DispatchQueueStatus.Expired}) row has no archival value once it ages
382
+ * out. Non-terminal rows ({@link DispatchQueueStatus.Pending}/
383
+ * {@link DispatchQueueStatus.Dispatched}/{@link DispatchQueueStatus.Recovering})
384
+ * are never pruned — a still-active run keeps every one of its rows. Both the
385
+ * terminal-status filter and the age cutoff must hold for a row to be deleted.
386
+ *
387
+ * `retentionDays <= 0` disables pruning (returns 0 without a query).
388
+ *
389
+ * @returns Number of rows deleted.
390
+ */
391
+ pruneTerminalDispatchRows(retentionDays: number): Promise<number>;
332
392
  /**
333
393
  * Get the current number of pending jobs.
334
394
  * Uses a 1-second TTL cache to avoid extra SELECT COUNT per enqueue.
@@ -455,11 +515,12 @@ export declare class JobQueue {
455
515
  */
456
516
  getFullJobById(jobId: string): Promise<QueuedJob | null>;
457
517
  /**
458
- * Mark a job as dispatched only if it is still in 'recovering' state.
518
+ * Mark a job as dispatched only if it is still in 'recovering' state, and
519
+ * record `agentId` as the durable owner of the reclaimed job.
459
520
  * Used when an agent reconnects and claims a recovering job.
460
521
  * @returns true if the update affected a row (job was still recovering).
461
522
  */
462
- markDispatchedIfRecovering(jobId: string): Promise<boolean>;
523
+ markDispatchedIfRecovering(jobId: string, agentId: string): Promise<boolean>;
463
524
  /**
464
525
  * Get a single job by ID.
465
526
  * Used to look up runId during recovery timer setup.
@@ -471,10 +532,11 @@ export declare class JobQueue {
471
532
  } | null>;
472
533
  /**
473
534
  * HA-safe ownership check. Returns true if the DB shows that
474
- * `agentId` previously held `jobId` according to any of:
535
+ * `agentId` holds or previously held `jobId` according to any of:
475
536
  *
476
- * - `status='dispatched'` AND the registry-managed bookkeeping
477
- * records the agent assignment (caller-side `agentJobs` map),
537
+ * - `status='dispatched'` AND `agent_id = <agent>` — the live
538
+ * owner of an in-flight job, readable by any coordinator
539
+ * including one that never saw the dispatch,
478
540
  * - `status='recovering'` AND `recovery_agent_id = <agent>` (so a
479
541
  * replacement coord still recognises in-flight chunks), OR
480
542
  * - the row is already terminal (`completed` / `failed` /
@@ -495,11 +557,29 @@ export declare class JobQueue {
495
557
  id: string;
496
558
  runId: string;
497
559
  status: DispatchQueueStatus;
560
+ agentId: string | null;
498
561
  }>>;
562
+ /**
563
+ * Shared builder for the non-expired pending rows, oldest-first
564
+ * (`created_at ASC` — the same FIFO ordering as `dequeueForLabels` /
565
+ * `markExpired`). Read-only: no `FOR UPDATE`, no claim. Used by both the
566
+ * unbounded `getPendingJobs` drain and the capped `listPending` re-drive.
567
+ */
568
+ private pendingOldestFirstQuery;
499
569
  /**
500
570
  * Get all pending jobs in FIFO order (for queue drain on agent connect).
501
571
  */
502
572
  getPendingJobs(): Promise<QueuedJob[]>;
573
+ /**
574
+ * Read-only oldest-first listing of pending jobs, capped at `limit`.
575
+ *
576
+ * Powers the scaler capacity-freed re-drive (`Dispatcher.retryPendingScaleRequests`):
577
+ * when a scaler agent frees capacity, the oldest jobs that previously got an
578
+ * `at-capacity` verdict are the ones re-offered to `requestScale`. Unlike
579
+ * `dequeueForLabels`, this neither claims nor locks rows — it is a pure read;
580
+ * the re-drive re-runs the normal scale path, which reserves capacity itself.
581
+ */
582
+ listPending(limit: number): Promise<QueuedJob[]>;
503
583
  /**
504
584
  * Convert a DB row to a QueuedJob object.
505
585
  * Handles both auto-parsed JSONB arrays (from pg driver) and JSON strings (from tests).
@@ -25,10 +25,10 @@ import type { Database } from '../db/types.js';
25
25
  */
26
26
  export declare const OrchestratorScheduledJobName: z.ZodEnum<{
27
27
  cleanup: "cleanup";
28
- "orphan-secret-cleanup": "orphan-secret-cleanup";
29
- "token-cleanup": "token-cleanup";
30
28
  "cold-store-archive": "cold-store-archive";
31
29
  "cold-store-purge": "cold-store-purge";
30
+ "orphan-secret-cleanup": "orphan-secret-cleanup";
31
+ "token-cleanup": "token-cleanup";
32
32
  }>;
33
33
  export type OrchestratorScheduledJobName = z.infer<typeof OrchestratorScheduledJobName>;
34
34
  /** Access-log action for a manually triggered off-cadence tick. */
@@ -151,7 +151,7 @@ export declare class RegistrationIndex {
151
151
  *
152
152
  * Event type -> trigger type mapping:
153
153
  * - 'kici_event' -> 'kici_event'
154
- * - 'workflow_complete' -> 'workflow_complete' or 'lifecycle'
154
+ * - 'workflow_complete' -> 'workflow_complete', 'lifecycle', or 'workflows_failed_batch'
155
155
  * - 'job_complete' -> 'job_complete' or 'lifecycle'
156
156
  * - 'generic_webhook' -> 'generic_webhook'
157
157
  * - 'schedule' -> 'schedule'