@kici-dev/orchestrator 0.17.0 → 0.19.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 (592) hide show
  1. package/dist/agent/agent-version.d.ts +12 -21
  2. package/dist/agent/dispatcher.d.ts +283 -437
  3. package/dist/agent/host-roster-reaper.d.ts +8 -10
  4. package/dist/agent/host-roster.d.ts +77 -100
  5. package/dist/agent/ownership-refusal.d.ts +3 -5
  6. package/dist/agent/ownership-tracker.d.ts +42 -76
  7. package/dist/agent/registry.d.ts +137 -230
  8. package/dist/agent/token-store.d.ts +34 -77
  9. package/dist/agent-packaging/availability.d.ts +6 -9
  10. package/dist/agent-packaging/download.d.ts +6 -9
  11. package/dist/agent-packaging/install-closure.d.ts +9 -12
  12. package/dist/agent-packaging/node-binary.d.ts +6 -10
  13. package/dist/agent-packaging/node-runtime-members.d.ts +3 -5
  14. package/dist/agent-packaging/refresh.d.ts +12 -16
  15. package/dist/agent-packaging/store.d.ts +5 -6
  16. package/dist/agent-packaging/upload.d.ts +3 -4
  17. package/dist/app.d.ts +0 -3
  18. package/dist/approvals/apply-decision.d.ts +35 -52
  19. package/dist/approvals/approval-resolver.d.ts +11 -23
  20. package/dist/approvals/held-run-release-wiring.d.ts +14 -21
  21. package/dist/approvals/independent-wiring.d.ts +13 -20
  22. package/dist/approvals/resume-router.d.ts +1 -1
  23. package/dist/approvals/step-approval-bridge.d.ts +11 -21
  24. package/dist/approvals/triggerer-subject.d.ts +8 -10
  25. package/dist/artifacts/artifact-store.d.ts +55 -95
  26. package/dist/artifacts/failure-messages.d.ts +15 -20
  27. package/dist/audit/access-log.d.ts +27 -45
  28. package/dist/audit/sampling-rate-limiter.d.ts +11 -23
  29. package/dist/cache/agent-job-failed-error.d.ts +2 -3
  30. package/dist/cache/build-coordinator.d.ts +5 -28
  31. package/dist/cache/cache-upload-settle.d.ts +11 -11
  32. package/dist/cache/dep-cache.d.ts +32 -60
  33. package/dist/cache/dispatch-cache-ref-tracker.d.ts +15 -23
  34. package/dist/cache/global-eval-round-cache.d.ts +33 -41
  35. package/dist/cache/pending-builds.d.ts +2 -6
  36. package/dist/cache/pending-dynamics.d.ts +2 -7
  37. package/dist/cache/pending-global-evals.d.ts +9 -12
  38. package/dist/cache/pending-inits.d.ts +11 -22
  39. package/dist/cache/pending-precursor-db-watcher.d.ts +24 -32
  40. package/dist/cache/pending-tracker.d.ts +17 -45
  41. package/dist/cache/precursor-result.d.ts +17 -30
  42. package/dist/cache/source-cache.d.ts +36 -65
  43. package/dist/cache/user-cache.d.ts +21 -25
  44. package/dist/cancel/cancel-held-run.d.ts +13 -16
  45. package/dist/cancel/cancel-route-answer.d.ts +1 -2
  46. package/dist/cancel/cancel-run.d.ts +26 -50
  47. package/dist/cancel/dashboard-cancel-handler.d.ts +2 -2
  48. package/dist/cancel/peer-job-cancel.d.ts +11 -14
  49. package/dist/cancel/sweep-stuck-cancelling.d.ts +9 -13
  50. package/dist/cli/api-client.d.ts +25 -76
  51. package/dist/cli/commands/access-log.d.ts +4 -24
  52. package/dist/cli/commands/agent-package.d.ts +7 -15
  53. package/dist/cli/commands/agent-service/agent-env.d.ts +3 -6
  54. package/dist/cli/commands/agent-service/index.d.ts +4 -10
  55. package/dist/cli/commands/agent-service/install.d.ts +4 -11
  56. package/dist/cli/commands/agent-service/status.d.ts +4 -9
  57. package/dist/cli/commands/agent-service/upgrade.d.ts +4 -16
  58. package/dist/cli/commands/agent.d.ts +12 -25
  59. package/dist/cli/commands/api-key.d.ts +5 -12
  60. package/dist/cli/commands/attestations-list.d.ts +7 -17
  61. package/dist/cli/commands/attestations-retry.d.ts +5 -11
  62. package/dist/cli/commands/attestations-reverify.d.ts +4 -5
  63. package/dist/cli/commands/attestations.d.ts +3 -8
  64. package/dist/cli/commands/audit.d.ts +1 -5
  65. package/dist/cli/commands/backend.d.ts +2 -11
  66. package/dist/cli/commands/check-run.d.ts +7 -18
  67. package/dist/cli/commands/cluster-name.d.ts +5 -12
  68. package/dist/cli/commands/cluster-settings.d.ts +28 -53
  69. package/dist/cli/commands/cold-store.d.ts +7 -15
  70. package/dist/cli/commands/config.d.ts +9 -20
  71. package/dist/cli/commands/context.d.ts +8 -20
  72. package/dist/cli/commands/dashboard-encryption-key.d.ts +9 -14
  73. package/dist/cli/commands/db-backup.d.ts +17 -32
  74. package/dist/cli/commands/db.d.ts +3 -4
  75. package/dist/cli/commands/debug-bundle.d.ts +3 -10
  76. package/dist/cli/commands/diagnose.d.ts +3 -14
  77. package/dist/cli/commands/event-dlq.d.ts +4 -12
  78. package/dist/cli/commands/event-log.d.ts +2 -20
  79. package/dist/cli/commands/execution.d.ts +3 -9
  80. package/dist/cli/commands/firecracker/index.d.ts +3 -6
  81. package/dist/cli/commands/held-run.d.ts +23 -37
  82. package/dist/cli/commands/host.d.ts +4 -11
  83. package/dist/cli/commands/inspect-bundle.d.ts +3 -11
  84. package/dist/cli/commands/local-hook.d.ts +2 -10
  85. package/dist/cli/commands/local-trigger.d.ts +2 -2
  86. package/dist/cli/commands/orchestrator-service/drain.d.ts +3 -6
  87. package/dist/cli/commands/orchestrator-service/index.d.ts +6 -14
  88. package/dist/cli/commands/orchestrator-service/install-env.d.ts +25 -49
  89. package/dist/cli/commands/orchestrator-service/install.d.ts +2 -5
  90. package/dist/cli/commands/orchestrator-service/status.d.ts +10 -22
  91. package/dist/cli/commands/orchestrator-service/upgrade.d.ts +6 -15
  92. package/dist/cli/commands/org-settings.d.ts +5 -11
  93. package/dist/cli/commands/peer.d.ts +5 -10
  94. package/dist/cli/commands/queue.d.ts +3 -9
  95. package/dist/cli/commands/registration.d.ts +4 -8
  96. package/dist/cli/commands/remote-source.d.ts +6 -12
  97. package/dist/cli/commands/rotate.d.ts +1 -5
  98. package/dist/cli/commands/runs.d.ts +1 -30
  99. package/dist/cli/commands/scaler.d.ts +5 -12
  100. package/dist/cli/commands/secret.d.ts +1 -9
  101. package/dist/cli/commands/service-health.d.ts +5 -10
  102. package/dist/cli/commands/shared/admin-cli-access-log.d.ts +10 -19
  103. package/dist/cli/commands/shared/bare-metal-binary-check.d.ts +86 -0
  104. package/dist/cli/commands/shared/cli-action.d.ts +1 -4
  105. package/dist/cli/commands/shared/confirm.d.ts +5 -10
  106. package/dist/cli/commands/shared/db.d.ts +1 -12
  107. package/dist/cli/commands/shared/env-file-mode.d.ts +6 -9
  108. package/dist/cli/commands/shared/secret-input.d.ts +7 -21
  109. package/dist/cli/commands/shared/service-verbs.d.ts +6 -12
  110. package/dist/cli/commands/shared/unbound-context-warning.d.ts +2 -4
  111. package/dist/cli/commands/shared/upgrade-hooks.d.ts +7 -16
  112. package/dist/cli/commands/shared/upgrade-safety.d.ts +20 -31
  113. package/dist/cli/commands/shared/versioned-upgrade.d.ts +83 -161
  114. package/dist/cli/commands/signing-key.d.ts +4 -9
  115. package/dist/cli/commands/source-manifest.d.ts +11 -14
  116. package/dist/cli/commands/source.d.ts +7 -32
  117. package/dist/cli/commands/token.d.ts +4 -15
  118. package/dist/cli/commands/trust-policy.d.ts +35 -88
  119. package/dist/cli/commands/variable.d.ts +3 -5
  120. package/dist/cli/commands/workflow.d.ts +3 -24
  121. package/dist/cli/join.d.ts +3 -6
  122. package/dist/cli/kici-admin.d.ts +11 -29
  123. package/dist/cli/lazy-deps/cache.d.ts +1 -14
  124. package/dist/cli/lazy-deps/downloader.d.ts +4 -27
  125. package/dist/cli/lazy-deps/registry.d.ts +5 -25
  126. package/dist/cli/local-github-ingress-url.d.ts +5 -7
  127. package/dist/cli/loopback-callback.d.ts +6 -7
  128. package/dist/cli/open-browser.d.ts +4 -8
  129. package/dist/cli/root-option-routing.d.ts +17 -29
  130. package/dist/cli/service/backup-timer.d.ts +16 -39
  131. package/dist/cli/service/compose-path.d.ts +3 -7
  132. package/dist/cli/service/compose.d.ts +12 -30
  133. package/dist/cli/service/deploy-env.d.ts +6 -18
  134. package/dist/cli/service/entrypoint.d.ts +14 -25
  135. package/dist/cli/service/env-assignment.d.ts +6 -17
  136. package/dist/cli/service/image-digests.d.ts +6 -15
  137. package/dist/cli/service/index.d.ts +2 -18
  138. package/dist/cli/service/instance/index-file.d.ts +9 -16
  139. package/dist/cli/service/instance/manifest.d.ts +60 -60
  140. package/dist/cli/service/instance/resolve.d.ts +32 -68
  141. package/dist/cli/service/instance/types.d.ts +12 -29
  142. package/dist/cli/service/launchd.d.ts +29 -60
  143. package/dist/cli/service/platform-detect.d.ts +13 -68
  144. package/dist/cli/service/privilege.d.ts +12 -25
  145. package/dist/cli/service/shutdown-grace.d.ts +11 -20
  146. package/dist/cli/service/systemd.d.ts +7 -20
  147. package/dist/cli/service/types.d.ts +63 -114
  148. package/dist/cli/service/windows-acl.d.ts +14 -21
  149. package/dist/cli/service/windows-env-file.d.ts +10 -28
  150. package/dist/cli/service/windows.d.ts +15 -31
  151. package/dist/cli/webhook-url-notes.d.ts +4 -6
  152. package/dist/cli/wizard/agent-wizard.d.ts +3 -14
  153. package/dist/cli/wizard/orchestrator-wizard.d.ts +12 -37
  154. package/dist/cli/wizard/prompts.d.ts +6 -16
  155. package/dist/cli.js +8207 -10128
  156. package/dist/cluster/cluster-identity.d.ts +20 -32
  157. package/dist/cluster/cluster-settings-reader.d.ts +50 -77
  158. package/dist/cluster/coordinator-credential.d.ts +4 -5
  159. package/dist/cluster/coordinator.d.ts +76 -148
  160. package/dist/cluster/health-api.d.ts +2 -10
  161. package/dist/cluster/index.d.ts +1 -6
  162. package/dist/cluster/instance-heartbeat.d.ts +26 -42
  163. package/dist/cluster/join-client.d.ts +4 -7
  164. package/dist/cluster/join-handler.d.ts +3 -7
  165. package/dist/cluster/join-token.d.ts +13 -27
  166. package/dist/cluster/leader-gated-scheduler.d.ts +8 -17
  167. package/dist/cluster/orphan-recovery.d.ts +13 -35
  168. package/dist/cluster/peer-auth-coordinator.d.ts +2 -8
  169. package/dist/cluster/peer-client.d.ts +46 -76
  170. package/dist/cluster/peer-credentials.d.ts +24 -70
  171. package/dist/cluster/peer-crypto.d.ts +5 -26
  172. package/dist/cluster/peer-forget.d.ts +3 -3
  173. package/dist/cluster/peer-handler.d.ts +47 -71
  174. package/dist/cluster/peer-registry.d.ts +37 -106
  175. package/dist/cluster/plan-headroom-store.d.ts +4 -6
  176. package/dist/cluster/raft-state.d.ts +4 -13
  177. package/dist/cluster/raft.d.ts +18 -53
  178. package/dist/cluster/reconcile-identity.d.ts +8 -11
  179. package/dist/cluster/rerouted-job-guard.d.ts +7 -11
  180. package/dist/cluster/verified-issuer.d.ts +2 -3
  181. package/dist/cluster/worker-cluster-settings.d.ts +7 -10
  182. package/dist/cluster/worker-eviction.d.ts +16 -26
  183. package/dist/cold-store/load-access-log-range.d.ts +15 -31
  184. package/dist/cold-store/load-event-log-range.d.ts +13 -27
  185. package/dist/cold-store/load-secret-audit-log-range.d.ts +8 -12
  186. package/dist/cold-store/orchestrator-cold-store.d.ts +8 -28
  187. package/dist/cold-store/tables/access-log.d.ts +12 -14
  188. package/dist/cold-store/tables/event-log.d.ts +4 -8
  189. package/dist/cold-store/tables/execution-runs.d.ts +6 -11
  190. package/dist/cold-store/tables/secret-audit-log.d.ts +5 -12
  191. package/dist/concurrency/dispatch-next-queued.d.ts +13 -25
  192. package/dist/concurrency/queue-manager.d.ts +22 -54
  193. package/dist/concurrency/waiters.d.ts +15 -31
  194. package/dist/config/encryption.d.ts +0 -2
  195. package/dist/config/loader.d.ts +0 -1
  196. package/dist/config/reload.d.ts +0 -6
  197. package/dist/config/resolver.d.ts +0 -4
  198. package/dist/config/shared-store.d.ts +0 -2
  199. package/dist/config/types.d.ts +0 -3
  200. package/dist/content-requirements-cache.d.ts +0 -1
  201. package/dist/contexts/context-store.d.ts +0 -2
  202. package/dist/contexts/held-runs.d.ts +0 -2
  203. package/dist/contexts/variable-store.d.ts +0 -2
  204. package/dist/dashboard/attestation-filters.d.ts +13 -18
  205. package/dist/dashboard/handler.d.ts +145 -307
  206. package/dist/db/client.d.ts +2 -6
  207. package/dist/db/deferred-index-build.d.ts +8 -10
  208. package/dist/db/deferred-indexes.d.ts +15 -22
  209. package/dist/db/migration-provider.d.ts +2 -4
  210. package/dist/db/migration-test-harness.d.ts +26 -44
  211. package/dist/db/migrations/001_initial.d.ts +1 -4
  212. package/dist/db/migrations/002_config_versions_key_version.d.ts +5 -8
  213. package/dist/db/migrations/003_access_log.d.ts +10 -15
  214. package/dist/db/migrations/004_rename_bundle_to_source.d.ts +7 -9
  215. package/dist/db/migrations/005_cold_store_chunk_counter.d.ts +4 -10
  216. package/dist/db/migrations/006_runs_jobs_steps_archived_at.d.ts +9 -29
  217. package/dist/db/migrations/007_audit_logs_archived_at.d.ts +11 -30
  218. package/dist/db/migrations/008_event_log_archived_at.d.ts +14 -29
  219. package/dist/db/migrations/009_access_log_trigram.d.ts +4 -8
  220. package/dist/db/migrations/010_cold_store_chunks.d.ts +16 -26
  221. package/dist/db/migrations/011_drop_source_secrets_notify.d.ts +6 -14
  222. package/dist/db/migrations/012_peer_credentials_active_uniq.d.ts +9 -14
  223. package/dist/db/migrations/013_execution_log_bytes.d.ts +5 -13
  224. package/dist/db/migrations/014_kici_events_lease_retry.d.ts +14 -27
  225. package/dist/db/migrations/015_org_settings_customer_scoped.d.ts +12 -17
  226. package/dist/db/migrations/016_org_settings_allow_http_npm.d.ts +4 -6
  227. package/dist/db/migrations/019_generic_sources_change_notify.d.ts +13 -17
  228. package/dist/db/migrations/020_org_settings_dashboard_write_policy.d.ts +5 -8
  229. package/dist/db/migrations/021_check_run_tracking.d.ts +5 -17
  230. package/dist/db/migrations/022_scaler_manager_state.d.ts +10 -20
  231. package/dist/db/migrations/023_dispatch_queue_recovery_deadline.d.ts +7 -18
  232. package/dist/db/migrations/024_dispatch_queue_provisioning_error.d.ts +5 -11
  233. package/dist/db/migrations/025_init_failure.d.ts +5 -9
  234. package/dist/db/migrations/027_workflow_timeout.d.ts +5 -13
  235. package/dist/db/migrations/029_dispatch_queue_attempts.d.ts +4 -10
  236. package/dist/db/migrations/030_held_runs_env_set_null.d.ts +5 -6
  237. package/dist/db/migrations/031_dispatch_queue_ack_deadline.d.ts +6 -12
  238. package/dist/db/migrations/033_org_settings_approval.d.ts +7 -10
  239. package/dist/db/migrations/034_held_runs_generalize.d.ts +10 -18
  240. package/dist/db/migrations/035_pending_workflow_contexts.d.ts +4 -5
  241. package/dist/db/migrations/037_generic_sources_provider_type_local.d.ts +5 -6
  242. package/dist/db/migrations/038_remote_sources.d.ts +5 -7
  243. package/dist/db/migrations/045_host_properties.d.ts +5 -9
  244. package/dist/db/migrations/046_join_token_consumed_by_instance.d.ts +5 -10
  245. package/dist/db/migrations/048_host_reboot_pending.d.ts +6 -12
  246. package/dist/db/migrations/049_held_runs_payload.d.ts +3 -8
  247. package/dist/db/migrations/050_sources_slug.d.ts +4 -5
  248. package/dist/db/migrations/051_binding_host_pattern.d.ts +7 -10
  249. package/dist/db/migrations/052_host_reach_metadata.d.ts +8 -11
  250. package/dist/db/migrations/053_agent_token_single_use.d.ts +6 -10
  251. package/dist/db/migrations/054_local_working_tree.d.ts +4 -6
  252. package/dist/db/migrations/055_agent_token_mandatory_labels.d.ts +6 -11
  253. package/dist/db/migrations/056_execution_jobs_environments.d.ts +4 -11
  254. package/dist/db/migrations/064_execution_jobs_skipped_environments.d.ts +6 -9
  255. package/dist/db/migrations/065_pending_attestations.d.ts +9 -12
  256. package/dist/db/migrations/066_pending_attestations_rejected.d.ts +4 -7
  257. package/dist/db/migrations/068_request_idempotency.d.ts +7 -9
  258. package/dist/db/migrations/069_reroute_tunables.d.ts +6 -14
  259. package/dist/db/migrations/071_batch_accumulation.d.ts +8 -16
  260. package/dist/db/migrations/072_dispatch_queue_run_id_index.d.ts +3 -9
  261. package/dist/db/migrations/074_normalize_zero_concurrency_limit.d.ts +4 -7
  262. package/dist/db/migrations/076_artifacts.d.ts +7 -8
  263. package/dist/db/migrations/078_org_settings_backup_staleness.d.ts +3 -6
  264. package/dist/db/migrations/079_org_settings_scaler_spawn_timeout.d.ts +4 -8
  265. package/dist/db/migrations/080_cluster_settings.d.ts +6 -10
  266. package/dist/db/migrations/081_org_settings_queue_timeout.d.ts +7 -11
  267. package/dist/db/migrations/082_host_s3_reachable.d.ts +5 -10
  268. package/dist/db/migrations/083_org_settings_artifact_caps.d.ts +6 -8
  269. package/dist/db/migrations/084_orchestrator_signing_keys.d.ts +8 -13
  270. package/dist/db/migrations/085_cluster_settings_reroute_flap_grace_ms.d.ts +4 -5
  271. package/dist/db/migrations/086_cluster_settings_max_fanout_hosts.d.ts +3 -3
  272. package/dist/db/migrations/087_cluster_settings_event_router_rate_limit.d.ts +5 -3
  273. package/dist/db/migrations/088_cluster_settings_cache_max_tarball_bytes.d.ts +3 -3
  274. package/dist/db/migrations/089_cluster_settings_cache_ttl_days.d.ts +3 -5
  275. package/dist/db/migrations/090_cluster_settings_concurrency_wait_timeout_ms.d.ts +3 -6
  276. package/dist/db/migrations/091_cluster_settings_agent_token_ttl_ms.d.ts +3 -6
  277. package/dist/db/migrations/092_cluster_settings_version.d.ts +5 -9
  278. package/dist/db/migrations/094_dashboard_encryption_keys.d.ts +9 -14
  279. package/dist/db/migrations/095_dashboard_write_policy_tristate.d.ts +2 -6
  280. package/dist/db/migrations/099_cluster_settings_dashboard_verified_issuer.d.ts +8 -11
  281. package/dist/db/migrations/101_contexts_hold_expiry_drop_default.d.ts +9 -15
  282. package/dist/db/migrations/102_dispatch_queue_agent_id.d.ts +6 -11
  283. package/dist/db/migrations/103_cluster_settings_ownership_db_check_timeout_ms.d.ts +6 -12
  284. package/dist/db/migrations/104_check_run_terminal_sent.d.ts +8 -14
  285. package/dist/db/migrations/105_org_trust_policy.d.ts +5 -7
  286. package/dist/db/migrations/106_cluster_settings_check_run_tracking_ttl_days.d.ts +4 -12
  287. package/dist/db/migrations/107_check_run_tracking_updated_at_index.d.ts +8 -14
  288. package/dist/db/migrations/113_execution_runs_workflow_repo_index.d.ts +10 -19
  289. package/dist/db/migrations/115_global_workflows_cluster_switch.d.ts +2 -3
  290. package/dist/db/migrations/121_org_settings_allow_untrusted_dockerfile_builds.d.ts +7 -8
  291. package/dist/db/migrations/122_host_roster_scaler_managed.d.ts +9 -16
  292. package/dist/db/migrations/123_workflow_registrations_default_branch.d.ts +8 -16
  293. package/dist/db/migrations/125_org_trust_directory.d.ts +13 -21
  294. package/dist/db/migrations/126_held_runs_posted_pending_check.d.ts +10 -16
  295. package/dist/db/migrations/127_org_trust_policy_approval_expiry_seconds.d.ts +8 -16
  296. package/dist/db/migrations/128_execution_runs_global_eval_round.d.ts +6 -11
  297. package/dist/db/migrations/129_execution_runs_dispatch_routing_key.d.ts +8 -11
  298. package/dist/db/migrations/130_scaler_provision_outcomes.d.ts +13 -20
  299. package/dist/db/migrations/131_execution_jobs_git_credentials.d.ts +12 -22
  300. package/dist/db/migrations/132_execution_runs_trigger_event.d.ts +6 -16
  301. package/dist/db/migrations/133_dispatch_queue_source_tar_digest.d.ts +6 -9
  302. package/dist/db/migrations/140_dispatch_queue_canonical_labels.d.ts +22 -40
  303. package/dist/db/migrations/143_execution_jobs_precursor_result.d.ts +9 -18
  304. package/dist/db/migrations/144_execution_runs_registration_window.d.ts +12 -20
  305. package/dist/db/migrations/147_sealed_job_secrets.d.ts +5 -9
  306. package/dist/db/migrations/148_cluster_settings_sealed_secrets_retry_backoff_ms.d.ts +7 -13
  307. package/dist/db/migrations/150_execution_runs_status_epoch.d.ts +6 -11
  308. package/dist/db/migrations/152_org_settings_cache_upload_settle_timeout.d.ts +5 -8
  309. package/dist/db/migrations/157_host_roster_identity_source.d.ts +9 -13
  310. package/dist/db/migrations/159_org_id_widen_to_source_width.d.ts +5 -0
  311. package/dist/db/migrator.d.ts +17 -25
  312. package/dist/db/notify-listener.d.ts +8 -11
  313. package/dist/db/repos/dashboard-encryption-keys-repo.d.ts +9 -10
  314. package/dist/db/synthetic-job-ids.d.ts +6 -8
  315. package/dist/db/types.d.ts +531 -1058
  316. package/dist/deployment/deployment-identity.d.ts +42 -60
  317. package/dist/diagnostics/bundle-reader.d.ts +3 -15
  318. package/dist/diagnostics/bundle-writer.d.ts +5 -12
  319. package/dist/diagnostics/checks/agents.d.ts +1 -7
  320. package/dist/diagnostics/checks/backup.d.ts +7 -10
  321. package/dist/diagnostics/checks/certs.d.ts +1 -6
  322. package/dist/diagnostics/checks/config.d.ts +2 -5
  323. package/dist/diagnostics/checks/db.d.ts +1 -1
  324. package/dist/diagnostics/checks/disk.d.ts +1 -6
  325. package/dist/diagnostics/checks/firecracker-network.d.ts +3 -3
  326. package/dist/diagnostics/checks/index.d.ts +0 -6
  327. package/dist/diagnostics/checks/retention.d.ts +3 -6
  328. package/dist/diagnostics/checks/scaler.d.ts +3 -7
  329. package/dist/diagnostics/checks/ws.d.ts +1 -6
  330. package/dist/diagnostics/fleet-collector.d.ts +11 -14
  331. package/dist/diagnostics/fleet-constants.d.ts +1 -3
  332. package/dist/diagnostics/fleet-selection.d.ts +3 -7
  333. package/dist/diagnostics/fleet-topology.d.ts +2 -6
  334. package/dist/diagnostics/fleet-wiring.d.ts +6 -12
  335. package/dist/diagnostics/index.d.ts +0 -5
  336. package/dist/diagnostics/runner.d.ts +4 -8
  337. package/dist/diagnostics/types.d.ts +10 -21
  338. package/dist/drain/drain-controller.d.ts +16 -22
  339. package/dist/entry-helpers.d.ts +0 -2
  340. package/dist/events/circuit-breaker.d.ts +0 -3
  341. package/dist/events/event-router.d.ts +1 -2
  342. package/dist/events/event-store.d.ts +0 -9
  343. package/dist/events/trust-store.d.ts +0 -3
  344. package/dist/events/types.d.ts +0 -9
  345. package/dist/firecracker/host-network.d.ts +24 -30
  346. package/dist/firecracker/net-interfaces.d.ts +4 -7
  347. package/dist/helpers/rate-limiter.d.ts +0 -1
  348. package/dist/index.js +240 -482
  349. package/dist/metrics/agent-metrics-aggregator.d.ts +24 -67
  350. package/dist/metrics/metrics-reporter.d.ts +4 -13
  351. package/dist/metrics/prometheus.d.ts +47 -81
  352. package/dist/orchestrator-core.d.ts +3 -7
  353. package/dist/pipeline/content-filter.d.ts +20 -30
  354. package/dist/pipeline/cross-source-tally.d.ts +7 -8
  355. package/dist/pipeline/decorating-secret-resolver.d.ts +4 -8
  356. package/dist/pipeline/degraded-reason.d.ts +3 -4
  357. package/dist/pipeline/direct-ingress-deps.d.ts +15 -24
  358. package/dist/pipeline/dispatch-matched-workflow.d.ts +290 -526
  359. package/dist/pipeline/flatten-lock-steps.d.ts +4 -6
  360. package/dist/pipeline/global-dispatch-identity.d.ts +5 -10
  361. package/dist/pipeline/global-eval-round.d.ts +62 -156
  362. package/dist/pipeline/global-round-hold.d.ts +5 -7
  363. package/dist/pipeline/held-context-data.d.ts +5 -8
  364. package/dist/pipeline/held-round-registrations.d.ts +8 -11
  365. package/dist/pipeline/install-gate.d.ts +15 -25
  366. package/dist/pipeline/install-secrets-resolver.d.ts +24 -34
  367. package/dist/pipeline/internal-event-pipeline.d.ts +45 -62
  368. package/dist/pipeline/invoke-gate.d.ts +27 -40
  369. package/dist/pipeline/job-contexts.d.ts +19 -36
  370. package/dist/pipeline/manual-schedule.d.ts +7 -13
  371. package/dist/pipeline/needs-scheduler.d.ts +29 -46
  372. package/dist/pipeline/pending-workflow-context.d.ts +14 -28
  373. package/dist/pipeline/process-webhook.d.ts +88 -123
  374. package/dist/pipeline/processor.d.ts +209 -355
  375. package/dist/pipeline/remote-source-store.d.ts +5 -8
  376. package/dist/pipeline/request-idempotency.d.ts +10 -13
  377. package/dist/pipeline/rerun-global.d.ts +6 -7
  378. package/dist/pipeline/rerun-inputs.d.ts +23 -37
  379. package/dist/pipeline/rerun.d.ts +34 -57
  380. package/dist/pipeline/resolve-sandbox-grant.d.ts +5 -10
  381. package/dist/pipeline/resume-workflow.d.ts +28 -34
  382. package/dist/pipeline/route-or-dispatch-jobs.d.ts +19 -30
  383. package/dist/pipeline/run-event-context.d.ts +16 -21
  384. package/dist/pipeline/sandbox-allowlist-reader.d.ts +7 -11
  385. package/dist/pipeline/security-hold-check.d.ts +56 -80
  386. package/dist/pipeline/test-pipeline.d.ts +20 -46
  387. package/dist/pipeline/unbound-job-context.d.ts +6 -9
  388. package/dist/pipeline/undispatched-hold-checks.d.ts +4 -6
  389. package/dist/pipeline/wave-scheduler.d.ts +15 -22
  390. package/dist/pipeline/webhook-payload-store.d.ts +3 -10
  391. package/dist/pipeline/workflow-lock-at-sha.d.ts +14 -20
  392. package/dist/policy/dashboard-write-policy.d.ts +1 -1
  393. package/dist/provider-registry.d.ts +0 -19
  394. package/dist/providers/generic/index.d.ts +0 -2
  395. package/dist/providers/generic/normalizer.d.ts +0 -1
  396. package/dist/providers/generic/verification.d.ts +0 -8
  397. package/dist/providers/github/auth.d.ts +0 -1
  398. package/dist/providers/github/changed-files.d.ts +2 -1
  399. package/dist/providers/github/file-contents.d.ts +0 -4
  400. package/dist/providers/github/lock-file.d.ts +0 -4
  401. package/dist/providers/github/normalizer.d.ts +1 -9
  402. package/dist/providers/local/index.d.ts +1 -2
  403. package/dist/providers/local/lock-file-fetcher.d.ts +0 -4
  404. package/dist/providers/local/normalizer.d.ts +0 -10
  405. package/dist/providers/local/repo-url-builder.d.ts +0 -2
  406. package/dist/providers/universal-git/clone-token.d.ts +0 -2
  407. package/dist/providers/universal-git/lock-file.d.ts +0 -2
  408. package/dist/providers/universal-git/normalizer.d.ts +0 -2
  409. package/dist/queue/bootstrap.d.ts +3 -15
  410. package/dist/queue/cleanup.d.ts +29 -50
  411. package/dist/queue/depth-refresher.d.ts +21 -39
  412. package/dist/queue/job-queue.d.ts +112 -163
  413. package/dist/queue/retention.d.ts +23 -36
  414. package/dist/queue/scheduled-job.d.ts +17 -39
  415. package/dist/queue/terminalize-unroutable.d.ts +16 -18
  416. package/dist/queue/unroutable-probe.d.ts +15 -22
  417. package/dist/registration/extractor.d.ts +0 -6
  418. package/dist/registration/registration-index.d.ts +0 -6
  419. package/dist/registration/registration-store.d.ts +0 -9
  420. package/dist/reporting/agent-failure-category.d.ts +3 -5
  421. package/dist/reporting/check-run-reporter.d.ts +142 -316
  422. package/dist/reporting/check-run-summary.d.ts +16 -35
  423. package/dist/reporting/check-run-tracking-store.d.ts +54 -107
  424. package/dist/reporting/execution-tracker.d.ts +356 -526
  425. package/dist/reporting/fs-log-storage.d.ts +31 -33
  426. package/dist/reporting/job-check-run-completion.d.ts +14 -22
  427. package/dist/reporting/log-chunk-sink.d.ts +11 -16
  428. package/dist/reporting/log-pull-handler.d.ts +4 -13
  429. package/dist/reporting/log-retention.d.ts +3 -4
  430. package/dist/reporting/log-storage.d.ts +24 -52
  431. package/dist/reporting/log-writer.d.ts +28 -56
  432. package/dist/reporting/peer-log-normalize.d.ts +4 -8
  433. package/dist/reporting/run-aggregator.d.ts +6 -11
  434. package/dist/reporting/run-summary-fields.d.ts +5 -8
  435. package/dist/reporting/s3-log-storage.d.ts +31 -50
  436. package/dist/reporting/step-display-order.d.ts +11 -21
  437. package/dist/reporting/step-log-buffer.d.ts +7 -28
  438. package/dist/reporting/step-log-reader.d.ts +11 -19
  439. package/dist/routes/admin-access-log.d.ts +4 -6
  440. package/dist/routes/admin-auth.d.ts +17 -38
  441. package/dist/routes/admin-backends.d.ts +3 -14
  442. package/dist/routes/admin-cluster-name.d.ts +13 -21
  443. package/dist/routes/admin-cluster-settings.d.ts +6 -9
  444. package/dist/routes/admin-config.d.ts +7 -19
  445. package/dist/routes/admin-contexts.d.ts +6 -13
  446. package/dist/routes/admin-db.d.ts +5 -10
  447. package/dist/routes/admin-event-dlq.d.ts +3 -5
  448. package/dist/routes/admin-event-inspect.d.ts +3 -4
  449. package/dist/routes/admin-event-log.d.ts +3 -7
  450. package/dist/routes/admin-events.d.ts +16 -30
  451. package/dist/routes/admin-held-runs.d.ts +52 -76
  452. package/dist/routes/admin-maintenance.d.ts +3 -6
  453. package/dist/routes/admin-orchestrator-drain.d.ts +0 -2
  454. package/dist/routes/admin-org-settings.d.ts +8 -14
  455. package/dist/routes/admin-peer-forget.d.ts +0 -1
  456. package/dist/routes/admin-queue-execution.d.ts +3 -3
  457. package/dist/routes/admin-registrations.d.ts +3 -12
  458. package/dist/routes/admin-runs.d.ts +16 -29
  459. package/dist/routes/admin-scaler-orphans.d.ts +4 -4
  460. package/dist/routes/admin-scaler-reload.d.ts +5 -8
  461. package/dist/routes/admin-scheduled-jobs.d.ts +3 -4
  462. package/dist/routes/admin-sources.d.ts +20 -29
  463. package/dist/routes/admin-trust-policy.d.ts +31 -48
  464. package/dist/routes/admin.d.ts +67 -94
  465. package/dist/routes/caller-identity.d.ts +5 -12
  466. package/dist/routes/capabilities.d.ts +8 -13
  467. package/dist/routes/diagnostics.d.ts +2 -10
  468. package/dist/routes/fleet.d.ts +1 -2
  469. package/dist/routes/github-webhook.d.ts +2 -5
  470. package/dist/routes/health.d.ts +6 -19
  471. package/dist/routes/provenance-oidc.d.ts +3 -3
  472. package/dist/routes/uploads.d.ts +5 -11
  473. package/dist/routes/webhooks.d.ts +2 -24
  474. package/dist/scaler/agent-binary-location.d.ts +77 -0
  475. package/dist/scaler/agent-fit.d.ts +2 -2
  476. package/dist/scaler/backend-factory.d.ts +10 -18
  477. package/dist/scaler/bare-metal-backend.d.ts +30 -46
  478. package/dist/scaler/claim-store.d.ts +20 -43
  479. package/dist/scaler/config.d.ts +10 -37
  480. package/dist/scaler/container-backend.d.ts +22 -35
  481. package/dist/scaler/container-hostconfig.d.ts +19 -16
  482. package/dist/scaler/container-routing.d.ts +10 -13
  483. package/dist/scaler/disk-guard.d.ts +2 -3
  484. package/dist/scaler/event-backend.d.ts +33 -58
  485. package/dist/scaler/event-provision-reaper.d.ts +61 -84
  486. package/dist/scaler/failure-tracker.d.ts +6 -13
  487. package/dist/scaler/file-tail.d.ts +6 -19
  488. package/dist/scaler/firecracker-api.d.ts +19 -63
  489. package/dist/scaler/firecracker-backend.d.ts +142 -258
  490. package/dist/scaler/host-access.d.ts +7 -10
  491. package/dist/scaler/index.d.ts +3 -6
  492. package/dist/scaler/ip-allocator.d.ts +30 -82
  493. package/dist/scaler/label-matcher.d.ts +14 -35
  494. package/dist/scaler/log-forwarder.d.ts +6 -25
  495. package/dist/scaler/machine-ledger.d.ts +39 -86
  496. package/dist/scaler/manager.d.ts +517 -787
  497. package/dist/scaler/pending-scale-sweeper.d.ts +8 -11
  498. package/dist/scaler/reap-orphans.d.ts +8 -12
  499. package/dist/scaler/resolve-container-auth.d.ts +12 -21
  500. package/dist/scaler/scaler-events.d.ts +2 -5
  501. package/dist/scaler/scaler-state-store.d.ts +127 -189
  502. package/dist/scaler/spawn-errors.d.ts +1 -4
  503. package/dist/scaler/startup-orphan-sweep.d.ts +3 -4
  504. package/dist/scaler/startup-tools-check.d.ts +21 -0
  505. package/dist/scaler/types.d.ts +142 -255
  506. package/dist/scaler/vm-job-bindings.d.ts +5 -9
  507. package/dist/scaler/warm-pool.d.ts +49 -93
  508. package/dist/secrets/audit-logger.d.ts +0 -3
  509. package/dist/secrets/backend-health.d.ts +0 -9
  510. package/dist/secrets/backend-registry.d.ts +0 -9
  511. package/dist/secrets/cleanup.d.ts +0 -1
  512. package/dist/secrets/config.d.ts +0 -3
  513. package/dist/secrets/ephemeral-keys.d.ts +0 -3
  514. package/dist/secrets/pg-secret-store.d.ts +0 -3
  515. package/dist/secrets/rbac.d.ts +0 -6
  516. package/dist/secrets/secret-output-store.d.ts +0 -6
  517. package/dist/secrets/secret-resolver.d.ts +2 -6
  518. package/dist/secrets/token-manager.d.ts +0 -4
  519. package/dist/secrets/vault-secret-store.d.ts +0 -13
  520. package/dist/security/comment-handler.d.ts +0 -2
  521. package/dist/security/workflow-diff.d.ts +1 -1
  522. package/dist/server.js +8628 -13569
  523. package/dist/sources/source-manager.d.ts +0 -3
  524. package/dist/sources/source-store.d.ts +0 -9
  525. package/dist/sources/source-validator.d.ts +0 -3
  526. package/dist/stale-detector/all-terminal-runs.d.ts +8 -11
  527. package/dist/stale-detector/gate-deadline-detector.d.ts +14 -19
  528. package/dist/stale-detector/reboot-deadline-sweep.d.ts +7 -11
  529. package/dist/stale-detector/stale-dispatch-candidates.d.ts +13 -20
  530. package/dist/stale-detector/stale-run-detector.d.ts +74 -121
  531. package/dist/stale-detector/workflow-deadline-detector.d.ts +15 -43
  532. package/dist/standalone.js +7670 -12402
  533. package/dist/storage/blob-routes.d.ts +10 -19
  534. package/dist/storage/filesystem.d.ts +19 -29
  535. package/dist/storage/index.d.ts +2 -10
  536. package/dist/storage/key-discriminator.d.ts +8 -10
  537. package/dist/storage/loopback-guard.d.ts +27 -45
  538. package/dist/storage/s3.d.ts +25 -52
  539. package/dist/storage/sign-url.d.ts +7 -22
  540. package/dist/storage/types.d.ts +44 -70
  541. package/dist/webhook/event-log.d.ts +0 -2
  542. package/dist/webhook/generic-sources.d.ts +0 -21
  543. package/dist/webhook/ingest-admission.d.ts +0 -1
  544. package/dist/webhook/relay-buffer.d.ts +2 -2
  545. package/dist/webhook/verify-inbound.d.ts +0 -1
  546. package/dist/worker/in-memory-execution-tracker.d.ts +9 -31
  547. package/dist/worker/in-memory-job-queue.d.ts +32 -72
  548. package/dist/worker/peer-outbox.d.ts +5 -8
  549. package/dist/worker/reroute-dispatch.d.ts +4 -6
  550. package/dist/worker/static-agent-token-store.d.ts +6 -27
  551. package/dist/worker/worker-outbox-relay.d.ts +2 -2
  552. package/dist/worker/worker-status.d.ts +3 -20
  553. package/dist/ws/agent-api-registry.d.ts +8 -27
  554. package/dist/ws/agent-handler.d.ts +63 -110
  555. package/dist/ws/agent-heartbeat.d.ts +5 -12
  556. package/dist/ws/bringup-api.d.ts +31 -38
  557. package/dist/ws/dashboard-backends-handler.d.ts +12 -22
  558. package/dist/ws/dashboard-context-handler.d.ts +37 -80
  559. package/dist/ws/dashboard-diagnostics-handler.d.ts +8 -25
  560. package/dist/ws/dashboard-dispatch-guard.d.ts +3 -4
  561. package/dist/ws/dashboard-fleet-handler.d.ts +9 -13
  562. package/dist/ws/dashboard-fleet-write-handler.d.ts +7 -21
  563. package/dist/ws/dashboard-global-workflows-handler.d.ts +22 -44
  564. package/dist/ws/dashboard-registrations-handler.d.ts +10 -27
  565. package/dist/ws/dashboard-run-state-handler.d.ts +10 -13
  566. package/dist/ws/event-buffer.d.ts +3 -6
  567. package/dist/ws/execution-status-frame.d.ts +9 -11
  568. package/dist/ws/failure-messages.d.ts +9 -14
  569. package/dist/ws/fleet-agent-collector.d.ts +6 -12
  570. package/dist/ws/fleet-runs-on-all.d.ts +1 -6
  571. package/dist/ws/git-credential-relay.d.ts +12 -20
  572. package/dist/ws/inventory-api.d.ts +4 -5
  573. package/dist/ws/job-status-forward-frame.d.ts +30 -0
  574. package/dist/ws/observer-registry.d.ts +14 -59
  575. package/dist/ws/outbound-frame-guard.d.ts +4 -0
  576. package/dist/ws/ownership-gate.d.ts +1 -1
  577. package/dist/ws/platform-client.d.ts +32 -31
  578. package/dist/ws/replay-chunker.d.ts +7 -10
  579. package/dist/ws/server-options.d.ts +5 -9
  580. package/dist/ws/test-relay-handlers.d.ts +45 -59
  581. package/dist/ws/test-run-log-cursor.d.ts +18 -0
  582. package/installer-image-digests.json +3 -3
  583. package/package.json +6 -5
  584. package/sbom.spdx.json +53 -53
  585. package/dist/__test-helpers__/fake-scaler-state-store.d.ts +0 -24
  586. package/dist/__test-helpers__/mock-db-query.d.ts +0 -129
  587. package/dist/__test-helpers__/mock-db.d.ts +0 -134
  588. package/dist/__test-helpers__/mock-ws.d.ts +0 -13
  589. package/dist/__test-helpers__/peer-mutual-auth.d.ts +0 -42
  590. package/dist/__test-helpers__/scratch-db.d.ts +0 -16
  591. package/dist/__test-helpers__/test-db.d.ts +0 -34
  592. package/dist/pipeline/dispatch-matched-workflow.test-helpers.d.ts +0 -121
@@ -5,12 +5,9 @@ import type { ResolvedContainerSpawn } from '../scaler/types.js';
5
5
  import { type ScalerAgentView } from '../scaler/agent-fit.js';
6
6
  import type { ResourceRequest } from '@kici-dev/engine';
7
7
  /**
8
- * Why a freed agent's queue drain claimed nothing.
9
- *
10
- * Named rather than inlined because the value travels: it is the `reason`
11
- * field of the drain-declined log line and the assertion subject of the tests
12
- * that pin each exit. The five members are the five ways
13
- * `Dispatcher.drainForAgent` can return without a dispatch.
8
+ * Why a freed agent's queue drain claimed nothing: one member per way
9
+ * `Dispatcher.drainForAgent` returns without a dispatch. Named because the value
10
+ * travels: it is the drain-declined log line's `reason` and the tests' subject.
14
11
  */
15
12
  export declare enum AgentDrainDecline {
16
13
  /** The agent id is not in the in-memory registry (already disconnected). */
@@ -25,30 +22,22 @@ export declare enum AgentDrainDecline {
25
22
  NoMatchingJob = "no-matching-job"
26
23
  }
27
24
  /**
28
- * Default per-pass cap on how many pending jobs a capacity-freed re-drive
29
- * re-offers to the scaler. Bounds the burst so a single free event cannot storm
30
- * the scaler; the per-backend spawn semaphore bounds actual provisioning, and a
31
- * job that gets `at-capacity` again stays pending for the next tick.
25
+ * Default per-pass cap on pending jobs a capacity-freed re-drive re-offers, so
26
+ * one free event cannot storm the scaler. The per-backend spawn semaphore bounds
27
+ * provisioning; a job that gets `at-capacity` again stays pending for the next tick.
32
28
  */
33
29
  export declare const DEFAULT_REDRIVE_BATCH = 10;
34
- /**
35
- * Metrics interface for dispatch operations.
36
- * Allows the dispatcher to update Prometheus counters without
37
- * directly importing the metrics module (dependency injection).
38
- */
30
+ /** Dispatch metrics, injected so the dispatcher does not import the metrics module. */
39
31
  export interface DispatchMetrics {
40
- /** Increment the jobs dispatched counter by status. */
41
32
  incJobsDispatched(status: 'dispatched' | 'queued' | 'rejected'): void;
42
- /** Set the queue depth gauge. */
43
33
  setQueueDepth(depth: number): void;
44
34
  /** Record `count` pending jobs re-driven through the scaler by `trigger`. */
45
35
  incScalerRedispatch(trigger: ScalerRedispatchTrigger, count: number): void;
46
36
  }
47
37
  /**
48
- * Narrow slice of `HostRosterStore` the dispatcher needs for the host-restart
49
- * flow. Kept as an interface so the dispatcher doesn't import the full store
50
- * (which pulls in engine label matchers) and to make the reboot logic testable
51
- * with a tiny in-memory stub.
38
+ * Slice of `HostRosterStore` for the host-restart flow: an interface so the
39
+ * dispatcher avoids importing the full store (it pulls in engine label matchers)
40
+ * and the reboot logic is testable with an in-memory stub.
52
41
  */
53
42
  export interface HostRosterRebootStore {
54
43
  /** True when the host's reboot-pending deadline is still in the future. */
@@ -57,13 +46,10 @@ export interface HostRosterRebootStore {
57
46
  clearRebootPending(agentId: string): Promise<void>;
58
47
  }
59
48
  /**
60
- * Result of a dispatch attempt.
61
- *
62
- * `duplicate` = the dispatch_queue row for a preassigned (rerouted) jobId
63
- * already existed, so nothing was dispatched here (the claimed agent slot is
64
- * released and onDispatch is NOT called). The reroute caller should treat the
65
- * job as already handled. Only reachable on a reroute re-dispatch — first-
66
- * dispatch paths use a fresh UUID that can never collide.
49
+ * `duplicate`: the dispatch_queue row for a preassigned (rerouted) jobId already
50
+ * existed, so the claimed slot is released, onDispatch is NOT called, and the
51
+ * reroute caller treats the job as handled. Only a reroute re-dispatch reaches
52
+ * it; first dispatch uses a fresh UUID that cannot collide.
67
53
  *
68
54
  * `queued` also answers a direct dispatch refused because the job's run has
69
55
  * stopped: the queue row is recorded `expired` and the job cancelled, the
@@ -86,6 +72,17 @@ type DispatchResult = {
86
72
  status: 'rejected';
87
73
  reason: string;
88
74
  };
75
+ /**
76
+ * The job's container spawn, from what dispatch already resolved on `jobConfig`:
77
+ * `container` from the lock, `containerRegistryAuth` orchestrator-side. Nothing
78
+ * is re-resolved — a second resolution is a second chance to disagree.
79
+ *
80
+ * A job that BUILDS its image (`container.dockerfile`) carries no `image`, so this
81
+ * returns `undefined` and no per-job-image spawn happens. Load bearing: the image
82
+ * does not exist until an agent clones and builds it, so an ordinary agent must
83
+ * run the job and nest the container. Exported so `dispatcher.test.ts` pins this
84
+ * routing decision.
85
+ */
89
86
  export declare function containerSpawnFor(jobConfig: Record<string, unknown> | undefined): {
90
87
  image: string;
91
88
  authconfig?: {
@@ -104,6 +101,14 @@ export interface DispatchRefusal {
104
101
  }
105
102
  /** The callback that sends a dispatched job to its agent. */
106
103
  export type OnDispatch = (agentId: string, job: QueuedJob) => void | DispatchRefusal | Promise<void | DispatchRefusal>;
104
+ /**
105
+ * Dispatch coordinator: routes jobs to label-matching agents, falling back to the
106
+ * persistent queue, and handles agent connect, disconnect and job completion.
107
+ *
108
+ * It never touches WebSocket connections: the caller (orchestrator-core.ts or worker-core.ts)
109
+ * provides an onDispatch that looks up the agent's WS in the registry and sends
110
+ * the job.dispatch message.
111
+ */
107
112
  export declare class Dispatcher {
108
113
  private readonly registry;
109
114
  private readonly queue;
@@ -113,142 +118,120 @@ export declare class Dispatcher {
113
118
  /** See the constructor dep of the same name. */
114
119
  private readonly scalerAgentView?;
115
120
  /**
116
- * Single-flight guard for `retryPendingScaleRequests`. The capacity-freed
117
- * hook and the leader-gated sweep can both fire concurrently; this prevents
118
- * two re-drives from double-offering the same pending jobs to the scaler in
119
- * the same tick.
121
+ * Single-flight guard for `retryPendingScaleRequests`: the capacity-freed hook
122
+ * and the leader-gated sweep can fire concurrently and must not double-offer
123
+ * the same pending jobs to the scaler in one tick.
120
124
  */
121
125
  private redriveInFlight;
122
126
  /**
123
- * Single-flight guard for `redrivePendingToConnectedAgents`. The per-coord
124
- * safety-net tick must not overlap itself, so a slow re-drive can't be
125
- * re-entered by the next interval fire and double-scan the same pending rows.
127
+ * Single-flight guard for `redrivePendingToConnectedAgents`: the next interval
128
+ * fire must not re-enter a slow re-drive and double-scan the same pending rows.
126
129
  */
127
130
  private pendingRedriveInFlight;
128
- /**
129
- * Tracks which jobs are dispatched to which agents.
130
- * Used for marking jobs as failed on agent disconnect.
131
- */
131
+ /** agentId -> dispatched jobIds, for failing jobs on agent disconnect. */
132
132
  private readonly agentJobs;
133
133
  /** Reverse map: jobId -> agentId, for cancel-run lookups. */
134
134
  private readonly jobToAgent;
135
135
  /**
136
- * jobId -> runId for currently-tracked jobs. Populated alongside
137
- * `jobToAgent`/`agentJobs` at dispatch time and cleared with them, so the
138
- * provenance token relay can resolve a job's runId from the dispatcher's own
139
- * state (`resolveOwnedJob`) rather than trusting an agent-asserted value.
136
+ * jobId -> runId, kept and cleared with `jobToAgent`/`agentJobs`, so the
137
+ * provenance token relay resolves a job's runId from dispatcher state
138
+ * (`resolveOwnedJob`) rather than trusting an agent-asserted value.
140
139
  */
141
140
  private readonly jobRunIds;
142
141
  /**
143
- * Grace window for recently completed jobs.
144
- * Allows late messages (log.chunk, step.status) to be accepted for a short
145
- * period after job completion, preventing false ownership violations.
142
+ * Grace window for recently completed jobs: late messages (log.chunk,
143
+ * step.status) are accepted briefly after completion, not flagged as
144
+ * ownership violations.
146
145
  */
147
146
  private readonly completedJobs;
148
- /** Cap on completedJobs map to prevent unbounded growth. */
147
+ /** Bounds completedJobs growth. */
149
148
  private static readonly COMPLETED_JOBS_CAP;
150
- /** Grace window duration in milliseconds (30 seconds). */
151
149
  private static readonly GRACE_WINDOW_MS;
152
- /** Interval for cleaning up expired grace window entries (10 seconds). */
153
150
  private static readonly GRACE_CLEANUP_INTERVAL_MS;
154
- /** Timer for periodic grace cleanup. */
155
151
  private graceCleanupTimer;
156
- /** Max reconnection delay from agent config, used to derive grace period. */
152
+ /** From agent config; derives the recovery grace period. */
157
153
  private readonly maxReconnectDelayMs;
158
154
  /**
159
- * Callback fired when a job reaches a permanent dispatch-side failure:
160
- * recovery window expired, re-dispatch attempts exhausted, or a
161
- * scaler-managed agent was destroyed mid-execution. The receiver marks
162
- * the execution-tracker job failed with the given reason.
155
+ * Fired on a permanent dispatch-side failure (recovery window expired,
156
+ * re-dispatch attempts exhausted, or a scaler-managed agent destroyed
157
+ * mid-execution); the receiver marks the execution-tracker job failed.
163
158
  */
164
159
  private readonly onJobFailedPermanently?;
165
- /** Callback when a job enters recovery (starts timer). */
166
160
  private readonly onRecoveryStarted?;
167
161
  /** Fallback ack deadline when no getAckTimeoutMs dep is wired (tests). */
168
162
  private static readonly DEFAULT_ACK_TIMEOUT_MS;
169
163
  /**
170
- * Pending dispatch acknowledgments: armed when a job.dispatch is sent,
171
- * resolved by job.ack / job.reject / job.status running / disconnect
172
- * triage. On expiry the dispatch is treated as lost: requeue + disconnect.
164
+ * Pending dispatch acks: armed when a job.dispatch is sent, resolved by
165
+ * job.ack / job.reject / job.status running / disconnect triage. On expiry the
166
+ * dispatch is lost: requeue + disconnect.
173
167
  */
174
168
  private readonly pendingAcks;
175
169
  /**
176
- * Acks that arrived before their pending-ack entry was armed (the agent
177
- * answered faster than the orchestrator could resolve the timeout + stamp
178
- * the deadline). Keyed by jobId -> the agent that acked. Consumed by
179
- * `armAckDeadline`, which then skips arming.
170
+ * jobId -> acking agent, for acks that beat their pending-ack entry (the agent
171
+ * answered before the timeout was resolved and the deadline stamped).
172
+ * `armAckDeadline` consumes it and skips arming.
180
173
  */
181
174
  private readonly earlyAcks;
182
- /** Resolve the per-job ack deadline (per-org override / cluster default). */
175
+ /** Per-job ack deadline (per-org override / cluster default). */
183
176
  private readonly getAckTimeoutMs;
184
177
  /** Cancel + disconnect an agent whose dispatch ack deadline expired. */
185
178
  private readonly onAckTimeout?;
186
179
  /**
187
- * Jobs that have reached agent-side execution (a `job.status: running`
188
- * arrived). Disconnect triage treats never-started jobs as safely
189
- * re-dispatchable; started jobs on destroyed agents fail fast.
180
+ * Jobs whose `job.status: running` arrived. Disconnect triage re-dispatches
181
+ * never-started jobs; started jobs on destroyed agents fail fast.
190
182
  */
191
183
  private readonly startedJobs;
192
184
  /**
193
- * Per-job recovery timers for jobs in 'recovering' state.
194
- * When an agent disconnects with in-flight jobs, each job gets a timer.
195
- * If the agent reconnects before the timer fires, the timer is cancelled.
185
+ * Recovery timers for 'recovering' jobs: each in-flight job of a disconnected
186
+ * agent gets one, cancelled if the agent reconnects before it fires.
196
187
  */
197
188
  private readonly recoveringJobs;
198
- /** Grace period = 2x max reconnection delay. */
199
189
  private get gracePeriodMs();
200
- /** Host roster store for the reboot-pending gate; undefined ⇒ flow inert. */
190
+ /** For the reboot-pending gate; undefined ⇒ flow inert. */
201
191
  private readonly rosterStore?;
202
- /** Coordinator drain predicate; when true, new jobs queue Pending instead of
203
- * dispatching. Defaults to never-draining. */
192
+ /** When true, new jobs queue Pending instead of dispatching. Defaults to never. */
204
193
  private readonly isDraining;
205
- /** Whether another coordinator is live. Defaults to none (a single node). */
194
+ /** Defaults to none (a single node). */
206
195
  private readonly hasPeerCoordinators;
207
196
  constructor(deps: {
208
197
  registry: AgentRegistry;
209
198
  queue: JobQueue;
210
199
  metrics: DispatchMetrics;
211
200
  onDispatch: OnDispatch;
212
- /** Optional hook called when no agent matches the job's labels.
213
- * When set, receives the per-job `resources` so the scaler can apply
214
- * per-scaler / per-orchestrator / per-machine caps before spawning. */
201
+ /** Called when no agent matches; gets the per-job `resources` so the scaler
202
+ * applies per-scaler / per-orchestrator / per-machine caps before spawning. */
215
203
  onNoMatchingAgent?: (labels: string[], jobId: string, runId: string, excludeLabels: string[], resources?: ResourceRequest, orgId?: string,
216
204
  /**
217
- * The job's own container image plus registry credentials, already
218
- * resolved at dispatch. Present means the backend spawns THAT image with
219
- * the KiCI runtime injected instead of the pool's fixed agent image.
205
+ * The job's own image plus registry credentials, resolved at dispatch.
206
+ * Present: the backend spawns THAT image with the KiCI runtime injected
207
+ * instead of the pool's fixed agent image.
220
208
  */
221
209
  containerSpawn?: ResolvedContainerSpawn) => Promise<ScaleResult>;
222
210
  /**
223
- * What the scaler knows about an agent it started
224
- * (`ScalerManager.agentView`), or undefined for one it did not. It feeds
225
- * `canAgentRunJob`: the job the agent was started for, whether it runs in
226
- * that job's image, and a warm agent's fixed shape. Absent when no scaler
227
- * is configured; the predicate then judges every agent on its own
228
- * registration.
211
+ * What the scaler knows about an agent it started (`ScalerManager.agentView`),
212
+ * undefined for others. Feeds `canAgentRunJob`: the job the agent was started
213
+ * for, whether it runs in that job's image, a warm agent's fixed shape. Absent
214
+ * with no scaler; every agent is then judged on its own registration.
229
215
  */
230
216
  scalerAgentView?: (agentId: string) => ScalerAgentView | undefined;
231
- /** Max reconnection delay from agent config (default 60s). Used to derive grace period. */
217
+ /** From agent config (default 60s); derives the grace period. */
232
218
  maxReconnectDelayMs?: number;
233
- /** Callback fired when a job is permanently failed before/outside agent execution. */
219
+ /** Fired when a job is permanently failed before/outside agent execution. */
234
220
  onJobFailedPermanently?: (agentId: string, jobId: string, runId: string, reason: string) => void;
235
- /** Callback when a job enters recovery (starts timer). */
221
+ /** Fired when a job enters recovery (its timer starts). */
236
222
  onRecoveryStarted?: (agentId: string, jobId: string) => void;
237
- /** Resolve the per-job dispatch-ack deadline (ms). Defaults to 10s. */
223
+ /** Per-job dispatch-ack deadline (ms). Defaults to 10s. */
238
224
  getAckTimeoutMs?: (job: QueuedJob) => Promise<number>;
239
225
  /** Cancel + disconnect an agent whose dispatch ack deadline expired. */
240
226
  onAckTimeout?: (agentId: string, jobId: string, runId: string) => void;
241
227
  /**
242
- * Host roster store, used for the workflow-level host-restart flow: gate the
243
- * pinned-drain off for a reboot-pending agent, and treat a reboot-pending
244
- * agent's disconnect as the expected reboot (complete its in-flight job
245
- * success rather than starting the recovery-fail timer). Omitted ⇒ the
246
- * reboot-pending behavior is inert (every host reads not-pending).
228
+ * For the host-restart flow: no pinned drain to a reboot-pending agent, and
229
+ * its disconnect is the expected reboot (in-flight job completes success, no
230
+ * recovery-fail timer). Omitted ⇒ inert (every host reads not-pending).
247
231
  */
248
232
  rosterStore?: HostRosterRebootStore;
249
- /** Coordinator drain predicate. When true, dispatch() enqueues new jobs as
250
- * Pending and onAgentAvailable() claims nothing — jobs already on agents
251
- * finish. Defaults to never-draining. */
233
+ /** When true, dispatch() enqueues new jobs Pending and onAgentAvailable()
234
+ * claims nothing; jobs already on agents finish. Defaults to never. */
252
235
  isDraining?: () => boolean;
253
236
  /**
254
237
  * Whether another coordinator is live: connected, or disconnected for less
@@ -261,365 +244,272 @@ export declare class Dispatcher {
261
244
  /** Runs with the ids of the jobs each disconnect triage failed; see {@link setDisconnectCleanup}. */
262
245
  private disconnectCleanup?;
263
246
  /**
264
- * Install what runs with the ids of the jobs a disconnect triage failed. The
265
- * agent WebSocket handler installs the release of their in-memory waiters
266
- * (pending builds, inits, dynamic evaluations, global eval rounds). It runs
267
- * inside {@link onAgentDisconnect}, so a path that drops an agent without
268
- * waiting for its socket (heartbeat timeout, ack timeout, token revocation)
269
- * reaches it too.
247
+ * The agent WS handler installs the release of the failed jobs' in-memory
248
+ * waiters (pending builds, inits, dynamic evaluations, global eval rounds). It
249
+ * runs inside {@link onAgentDisconnect}, so paths that drop an agent without
250
+ * its socket closing (heartbeat timeout, ack timeout, token revocation) reach it.
270
251
  */
271
252
  setDisconnectCleanup(cleanup: (failedJobIds: string[]) => void): void;
272
- /**
273
- * Dispatch a job to a matching agent, or queue it if none available.
274
- *
275
- * Flow:
276
- * 1. Find available agents matching job's runsOnLabels.
277
- * 2. If agent found: increment activeJobs, call onDispatch, return 'dispatched'.
278
- * 3. If no agent: enqueue in queue, return 'queued'.
279
- * 4. If queue full: return 'rejected'.
280
- */
253
+ /** Dispatch a job to a matching agent, or queue it; 'rejected' when the queue is full. */
281
254
  dispatch(job: QueuedJobInput): Promise<DispatchResult>;
282
255
  /**
283
- * Re-drive the scaler for jobs still pending after an `at-capacity` verdict.
284
- *
285
- * Called by the capacity-freed hook (`ScalerManager.onCapacityFreed`) and the
286
- * leader-gated `PendingScaleSweeper`. Lists the oldest pending jobs (FIFO
287
- * fairness — the longest-waiting burst victim gets the freed slot first) and
288
- * re-runs the SAME `onNoMatchingAgent` → `requestScale` path used at dispatch
289
- * time, so the re-drive inherits the per-backend spawn semaphore and cap
290
- * accounting. A job that returns `at-capacity` again just stays pending for
291
- * the next free/sweep tick — no retry state, no backoff bookkeeping.
256
+ * Re-drive the scaler for jobs still pending after `at-capacity`, from the
257
+ * capacity-freed hook (`ScalerManager.onCapacityFreed`) and the leader-gated
258
+ * `PendingScaleSweeper`. Oldest first (FIFO: the longest-waiting burst victim
259
+ * gets the freed slot), through the SAME `onNoMatchingAgent` → `requestScale`
260
+ * path as dispatch, so it inherits the spawn semaphore and cap accounting. A
261
+ * job that gets `at-capacity` again stays pending for the next tick — no retry
262
+ * state, no backoff.
292
263
  *
293
- * Single-flight: a second call while one is in flight returns 0, so an
294
- * overlapping hook+sweep cannot double-offer the same jobs. Bounded by
295
- * `maxJobs` so one free event cannot storm the scaler.
296
- *
297
- * A job whose sealed secrets this coordinator cannot open is never scaled
298
- * for: it is settled instead ({@link settleUnopenablePending}).
264
+ * Single-flight (an overlapping call returns 0, so hook+sweep never double-offer)
265
+ * and bounded by `maxJobs`. A job whose sealed secrets this coordinator cannot
266
+ * open is settled instead ({@link settleUnopenablePending}).
299
267
  *
300
268
  * @returns the number of jobs that entered `spawning`.
301
269
  */
302
270
  retryPendingScaleRequests(maxJobs?: number, trigger?: ScalerRedispatchTrigger): Promise<number>;
303
271
  /**
304
- * Re-offer ONE pending job to the scaler: a worker's spawn-retry backoff ending.
305
- *
306
- * Outside the batch's single-flight on purpose: a wake-up that lands during a
307
- * batch pass would otherwise be dropped, and a worker runs no pending-scale
308
- * sweep to pick it up. The worker's per-job attempt gate is what keeps this
309
- * from starting a second spawn for the same job.
272
+ * Re-offer ONE pending job to the scaler when a worker's spawn-retry backoff
273
+ * ends. Outside the batch single-flight on purpose: a wake-up during a batch
274
+ * pass would be dropped, and a worker runs no pending-scale sweep. The worker's
275
+ * per-job attempt gate prevents a second spawn for the same job.
310
276
  *
311
277
  * @returns true when a spawn started.
312
278
  */
313
279
  redrivePendingJob(jobId: string): Promise<boolean>;
314
280
  /**
315
- * Offer one pending job to the scaler through the same `onNoMatchingAgent` →
316
- * `requestScale` path a dispatch uses, or settle it when its sealed secrets
317
- * cannot be opened here.
281
+ * Offer one pending job via the dispatch scale path, or settle it when its
282
+ * sealed secrets cannot be opened here.
318
283
  */
319
284
  private offerPendingToScaler;
320
285
  /**
321
- * Release the slot claimed for a direct dispatch the queue refused because
322
- * the job's run has stopped. Nothing is sent to the agent. The queue already
323
- * recorded the row `expired` and cancelled the job, so the job reads as a
324
- * queued job of the run that the cancel expired, and the caller tracks it
325
- * under `queued` exactly as it would that one.
286
+ * Release the slot of a direct dispatch the queue refused because the run has
287
+ * stopped; nothing is sent. The queue already recorded the row `expired` and
288
+ * cancelled the job, so it reads as a queued job the cancel expired, and the
289
+ * caller tracks it under `queued` the same way.
326
290
  */
327
291
  private refuseStoppedRunDispatch;
328
292
  /**
329
- * Dispatch a host-fanout pinned child. The job targets exactly
330
- * `job.pinnedAgentId`: if that agent is locally connected, satisfies the
331
- * runsOn/exclude/mandatory gate, and has capacity, dispatch immediately;
332
- * otherwise queue it WITH the pin so the pin-aware drain delivers it when the
333
- * agent frees up or (re)connects. A pinned job never falls through to a
334
- * different agent.
293
+ * Dispatch a host-fanout pinned child to exactly `job.pinnedAgentId` when it is
294
+ * locally connected, passes the runsOn/exclude/mandatory gate and has capacity;
295
+ * otherwise queue it WITH the pin for the pin-aware drain when the agent frees
296
+ * up or (re)connects. Never falls through to a different agent.
335
297
  */
336
298
  private dispatchPinned;
337
299
  /**
338
- * Eagerly dispatch a specific bound job to a freshly-registered
339
- * scaler-managed agent.
300
+ * Eagerly dispatch the job the scaler bound at spawn time to a freshly
301
+ * registered scaler-managed agent (the agent-handler calls it right after
302
+ * registration). Atomically claims it (still pending, labels still satisfied),
303
+ * marks it dispatched and sends it.
340
304
  *
341
- * Called by the agent-handler immediately after a scaler-managed agent
342
- * registers, when the scaler had bound a queued jobId to that agent at
343
- * spawn time. Atomically claims the job from the queue (validating it's
344
- * still pending and the agent's labels still satisfy it), marks it
345
- * dispatched, and sends it to the agent.
346
- *
347
- * Returns true only when the job was sent to the agent. False when nothing
348
- * was claimed (the bound job was already claimed elsewhere, expired, or the
349
- * agent isn't registered, is full or the coordinator is draining), and also
350
- * when the claimed job was not sent: its dispatch was refused and it failed,
351
- * or this coordinator could not open its sealed secrets. The caller falls
352
- * back to the generic onAgentAvailable() drain in every false case.
305
+ * True only when sent. False when nothing was claimed (claimed elsewhere,
306
+ * expired, agent unregistered or full, coordinator draining) or the claimed
307
+ * job was not sent (refused and failed, or sealed secrets this coordinator
308
+ * cannot open). On false the caller falls back to the onAgentAvailable() drain.
353
309
  */
354
310
  dispatchBoundJob(agentId: string, jobId: string): Promise<boolean>;
355
311
  /** {@link dispatchBoundJob}, reporting whether the job was claimed apart from whether it was sent. */
356
312
  private claimBoundJob;
357
313
  /**
358
- * Try draining the queue for a specific agent.
359
- * Called when an agent registers or completes a job.
360
- *
361
- * Dequeues matching jobs from the queue while the agent has capacity,
362
- * calling onDispatch for each.
363
- */
364
- /**
365
- * Drop agents whose reboot-pending flag is set from a candidate list. Used by
366
- * the label-routed dispatch path so a post-restart job is never sent to a host
367
- * that is about to reboot. No-op when no roster store is wired.
314
+ * Drop reboot-pending agents, so label-routed dispatch never sends a
315
+ * post-restart job to a host about to reboot. No-op with no roster store.
368
316
  */
369
317
  private filterRebootPending;
370
318
  /**
371
- * Drop the agents that cannot run this job (`canAgentRunJob`). Sibling of
372
- * {@link filterRebootPending}: both remove candidates `findAvailable` matched
373
- * on labels but that are unusable for a reason labels cannot express.
374
- *
375
- * The reasons: an agent started inside another job's image, a container job
376
- * on an agent that reports no container runtime, a warm agent of another
377
- * shape. Dropping the candidate here is what sends the job down the ordinary
378
- * `onNoMatchingAgent` scale path.
379
- *
380
- * `jobId` is the job's queue id when it has one: it is how the agent started
381
- * for the job recognizes it.
319
+ * Drop the agents that cannot run this job (`canAgentRunJob`): like
320
+ * {@link filterRebootPending}, a reason labels cannot express (started inside
321
+ * another job's image, no container runtime for a container job, a warm agent
322
+ * of another shape). Dropping them sends the job down the `onNoMatchingAgent`
323
+ * scale path. `jobId` (the queue id, when any) is how the agent started for
324
+ * the job recognizes it.
382
325
  */
383
326
  private filterUnservableAgents;
384
327
  /** The registration facts, and the scaler's record, `canAgentRunJob` judges an agent on. */
385
328
  private fitAgentFor;
386
329
  /**
387
- * The fit question for one job: its queue id, the shape it declares, and
388
- * what its `container:` asks of the agent's host.
330
+ * The fit question for one job: queue id, declared shape, and what its
331
+ * `container:` asks of the host.
389
332
  *
390
- * The shape comes from `jobConfig.resources` when the typed `resources`
391
- * mirror is absent, because the mirror is optional and several dispatch paths
392
- * never fill it — a job reaching {@link dispatch} straight off the webhook
393
- * pipeline or off a worker's reroute handler carries its declaration in
394
- * `jobConfig` alone. Reading only the mirror there reports a job that
395
- * declares nothing, which admits it onto a pre-spawned agent of some other
396
- * size — the exact mismatch this gate exists to refuse.
333
+ * The shape falls back to `jobConfig.resources` because the typed `resources`
334
+ * mirror is optional and several paths never fill it: a job reaching {@link dispatch}
335
+ * off the webhook pipeline or a worker's reroute handler declares in
336
+ * `jobConfig` alone. Reading only the mirror admits it onto a pre-spawned agent
337
+ * of another size — the mismatch this gate exists to refuse.
397
338
  */
398
339
  private agentFitFor;
399
340
  /**
400
- * The queue-drain half of {@link filterUnservableAgents}: a per-job
401
- * predicate for one agent, or undefined when this agent needs no check.
402
- *
403
- * Undefined is the common answer for an agent that runs any job: the
404
- * predicate could only ever say yes, and returning one would cost the drain
405
- * its single-statement fast path for nothing.
341
+ * The queue-drain half of {@link filterUnservableAgents}: a per-job predicate
342
+ * for one agent, or undefined for an agent that runs any job — a predicate
343
+ * that only says yes would cost the drain its single-statement fast path.
406
344
  */
407
345
  private agentFitFilterFor;
408
346
  /**
409
- * Release a reboot-pending host on its real reconnect (down-then-up). Clears
410
- * the persisted flag so the very next `onAgentAvailable` drain dispatches the
411
- * held post-restart job. Call this ONLY from the (re-)register path — a fresh
412
- * connection after the box rebooted — never from a still-connected drain
413
- * trigger (job completion / agent.status), which must keep the gate closed.
347
+ * Clear a reboot-pending host's flag on its real (down-then-up) reconnect, so
348
+ * the next `onAgentAvailable` drain dispatches the held post-restart job. Call
349
+ * ONLY from the (re-)register path, never from a still-connected drain trigger
350
+ * (job completion / agent.status), which must keep the gate closed.
414
351
  */
415
352
  releaseRebootPending(agentId: string): Promise<void>;
416
- onAgentAvailable(agentId: string): Promise<void>;
417
353
  /**
418
- * Claim at most one queued job for a freed agent.
419
- *
420
- * Returns the reason nothing was dispatched, or null when a job was.
354
+ * Try draining the queue for a specific agent. Called when an agent registers,
355
+ * completes a job or reports `agent.status`; claims at most one queued job per
356
+ * call ({@link drainForAgent}).
421
357
  */
358
+ onAgentAvailable(agentId: string): Promise<void>;
359
+ /** Claim at most one queued job for a freed agent; null when one was dispatched. */
422
360
  private drainForAgent;
423
361
  /** {@link deliver} inside the job's own request context, restored for a queue-drained job. */
424
362
  private deliverInRequestContext;
425
363
  /**
426
- * Hand a tracked job to `onDispatch`. Returns false when the job was not sent:
427
- * either the callback refused it, and the job is failed permanently since the
428
- * refusal is a fact about the job and another agent would refuse it too; or
429
- * this coordinator cannot open its sealed secrets, and the job is put back so
430
- * a coordinator holding the key can take it, or failed when none can
431
- * ({@link releaseUnopenableDispatch}).
364
+ * Hand a tracked job to `onDispatch`. False when not sent: the callback
365
+ * refused it (failed permanently — the refusal is a fact about the job, so
366
+ * another agent would refuse it too), or this coordinator cannot open its
367
+ * sealed secrets (put back for a key holder, or failed when none can:
368
+ * {@link releaseUnopenableDispatch}).
432
369
  */
433
370
  private deliver;
434
371
  /**
435
- * Handle a claimed job whose sealed secrets this coordinator cannot open: it
436
- * was sealed with a master key this coordinator does not hold.
372
+ * Handle a claimed job sealed with a master key this coordinator does not hold.
437
373
  *
438
- * With another coordinator live this is not a permanent refusal: during a
439
- * rolling master-key rotation that peer may already hold the new key, and if
440
- * it does, its own drains can take the job. The row returns to pending,
441
- * spending one dispatch attempt and recording the reason as the job's
374
+ * With a peer live it is not permanent: mid rolling master-key rotation the
375
+ * peer may hold the new key and its drains can take the job. The row returns
376
+ * to pending, spending one dispatch attempt and recording the reason as the
442
377
  * provisioning error (what an expiry reports), and this coordinator stops
443
- * offering the job for the sealed-secrets back-off. Once the back-off lapses
444
- * its drains and periodic re-drives offer the job again like any other, so a
445
- * job no coordinator can open is claimed again and fails with the reason once
446
- * {@link MAX_DISPATCH_ATTEMPTS} is reached. With no other coordinator live
447
- * nobody can open it, so it fails at once.
378
+ * offering it for the sealed-secrets back-off. After that, drains and re-drives
379
+ * offer it again, so a job no coordinator opens fails with the reason at
380
+ * {@link MAX_DISPATCH_ATTEMPTS}. With no peer live it fails at once.
448
381
  *
449
- * `agentId` is the agent the job was claimed for, or undefined when a re-drive
450
- * claimed it for no agent ({@link settleUnopenablePending}).
382
+ * `agentId` is undefined when a re-drive claimed it for no agent
383
+ * ({@link settleUnopenablePending}).
451
384
  */
452
385
  private releaseUnopenableDispatch;
453
386
  /**
454
- * Settle a pending job whose sealed secrets this coordinator cannot open,
455
- * found by a re-drive that would otherwise scale for it.
456
- *
457
- * Scaling for the job is wrong twice over. The registry credentials of a
458
- * private image are sealed with the job's other secrets, so a spawn of that
459
- * image pulls without them and fails before any agent registers: the job is
460
- * never claimed, never spends an attempt, and every re-drive spawns again.
461
- * And any agent a spawn does start is one this coordinator would hand the job
462
- * back from. So the job is claimed by id for no agent and gets the decision a
463
- * drain that claimed it would give it ({@link releaseUnopenableDispatch}). A
464
- * claim lost to another coordinator, or refused inside the back-off, leaves
465
- * the job alone.
387
+ * Settle a pending job with unopenable sealed secrets that a re-drive would
388
+ * otherwise scale for. Scaling is wrong twice: a private image's registry
389
+ * credentials are sealed with the other secrets, so its spawn pulls without
390
+ * them and fails before any agent registers (never claimed, no attempt spent,
391
+ * every re-drive spawns again); and any agent a spawn starts would get the job
392
+ * handed back. So it is claimed by id for no agent and decided as a drain
393
+ * would ({@link releaseUnopenableDispatch}). A claim lost to another
394
+ * coordinator, or refused inside the back-off, leaves the job alone.
466
395
  */
467
396
  private settleUnopenablePending;
468
- /**
469
- * Undo the dispatch accounting of a refused job and fail it with the refusal
470
- * reason. `agentId` is undefined for a job claimed for no agent.
471
- */
397
+ /** Undo a refused job's accounting and fail it; `agentId` undefined = claimed for no agent. */
472
398
  private failRefusedDispatch;
473
399
  /** Free the slot and tracking a claim took on its agent; a claim for no agent took none. */
474
400
  private releaseClaimAccounting;
475
401
  /**
476
- * Release the slot and tracking `jobId` holds on `agentId`, if the job is
477
- * still tracked there. Returns false when another path (a refusal, a
478
- * put-back, a disconnect) already took it.
402
+ * Release the slot and tracking `jobId` holds on `agentId`; false when another
403
+ * path (a refusal, a put-back, a disconnect) already took it.
479
404
  */
480
405
  private releaseTrackedClaim;
481
406
  /**
482
- * Hand a job this coordinator just claimed from the queue to `agentId`,
483
- * whose slot the claim took. A query that fails before the job is sent
484
- * returns the claim ({@link returnUndeliveredClaim}) and rethrows, so the
485
- * agent is not left holding a slot for a job it never received.
407
+ * Hand a just-claimed job to `agentId`, whose slot the claim took. A query
408
+ * failing before the send returns the claim ({@link returnUndeliveredClaim})
409
+ * and rethrows, so the agent holds no slot for a job it never received.
486
410
  *
487
411
  * @returns whether the job was sent.
488
412
  */
489
413
  private sendClaimedJob;
490
414
  /**
491
- * Put back a job a queue claim took but did not send: a query failed between
492
- * the claim and the send. The agent's slot (and the job's tracking, once
493
- * taken) is released so the agent takes work again, and the row returns to
494
- * pending without spending a dispatch attempt, since no agent saw it. The
495
- * next drain or the pending re-drive offers it again. A job a refusal or a
496
- * disconnect already took is left to that path. If the put-back fails too,
497
- * the row stays dispatched with no ack deadline and the stale-dispatch scan
498
- * reaps it.
415
+ * Put back a claimed job a query failure kept from being sent. The slot (and
416
+ * tracking, once taken) is released, and the row returns to pending without
417
+ * spending an attempt, since no agent saw it; the next drain or pending
418
+ * re-drive offers it again. A job a refusal or disconnect already took is left
419
+ * to that path. If the put-back fails too, the row stays dispatched with no ack
420
+ * deadline and the stale-dispatch scan reaps it.
499
421
  */
500
422
  private returnUndeliveredClaim;
501
- /** Record that a job began executing on its agent. */
502
423
  markJobStarted(jobId: string): void;
503
424
  /**
504
- * The agent accepted `jobId` (a `job.ack`, or the `running` status that stands
505
- * in for a lost one). Drop a busy hold that already ran out: a job accepted
506
- * while it sits on the entry was dispatched after it expired, into a free
507
- * slot, so the agent's job count is not stuck and its next teardown-window
508
- * rejection must not spend an attempt. A hold still in force is kept — see
509
- * {@link AgentRegistry.clearExpiredBusyHold}.
425
+ * The agent accepted `jobId` (`job.ack`, or `running` standing in for a lost
426
+ * one). An expired busy hold is dropped: the job was dispatched after it ran
427
+ * out, into a free slot, so the job count is not stuck and the next
428
+ * teardown-window rejection must not spend an attempt. A hold still in force
429
+ * is kept — see {@link AgentRegistry.clearExpiredBusyHold}.
510
430
  */
511
431
  private noteJobAccepted;
512
432
  /**
513
433
  * Arm the ack deadline for a just-sent dispatch (timer + persisted row).
514
- *
515
- * Resolving the timeout and persisting the deadline both touch the DB, so
516
- * a fast agent's job.ack can arrive before this method registers its
517
- * in-memory entry. `earlyAcks` records such an ack so this method skips
518
- * arming entirely instead of starting a timer that has nothing to resolve
519
- * it (which would expire a dispatch the agent actually accepted).
434
+ * Resolving the timeout and persisting both touch the DB, so a fast job.ack can
435
+ * beat the in-memory entry; `earlyAcks` records it and arming is skipped, since
436
+ * a timer with nothing to resolve it would expire an accepted dispatch.
520
437
  */
521
438
  private armAckDeadline;
522
- /**
523
- * Consume a recorded early ack for `jobId` from `agentId`. Returns true if
524
- * one was pending (and removes it).
525
- */
439
+ /** Consume a recorded early ack for `jobId` from `agentId`; true if one was pending. */
526
440
  private consumeEarlyAck;
527
441
  /** Clear a pending ack (answered or otherwise settled). Idempotent. */
528
442
  private resolvePendingAck;
529
- /** Handle an explicit dispatch acknowledgment (`job.ack`) from an agent. */
443
+ /** Handle a `job.ack` from an agent. */
530
444
  onJobAcked(agentId: string, jobId: string): void;
531
445
  /**
532
- * The ack deadline expired: the dispatch is lost. Untrack the job, then
533
- * remove the unresponsive agent from the registry BEFORE requeueing, so the
534
- * redispatch cannot land the job back on the very agent we are tearing down.
535
- * The job is already untracked when the WS close fires, so the disconnect
536
- * triage finds nothing to double-handle.
446
+ * The ack deadline expired: the dispatch is lost. The job is untracked and the
447
+ * agent removed from the registry BEFORE the requeue, so the redispatch cannot
448
+ * land it back on the agent being torn down, and the later WS-close triage
449
+ * finds nothing to double-handle.
537
450
  */
538
451
  private handleAckExpiry;
539
452
  /**
540
- * Drop an agent that did not acknowledge a dispatch. Its other in-flight jobs
541
- * (a multi-slot agent may run more than the one that timed out) go through
542
- * {@link onAgentDisconnect}, which reads the registration before its first
543
- * await to tell a scaler-managed agent from a static one, so the triage
544
- * starts first. The unregister right after removes the agent from routing at
545
- * once, so a redispatch cannot re-select it while the triage awaits.
453
+ * Drop an agent that did not ack a dispatch. Its other in-flight jobs (a
454
+ * multi-slot agent) go through {@link onAgentDisconnect}, which reads the
455
+ * registration before its first await to tell scaler-managed from static, so
456
+ * the triage starts first; the unregister right after removes the agent from
457
+ * routing so a redispatch cannot re-select it while the triage awaits.
546
458
  */
547
459
  private dropUnacknowledgingAgent;
548
- /**
549
- * Handle an explicit dispatch rejection (`job.reject`) from an agent.
550
- * Undoes the dispatch accounting and requeues the job for another agent.
551
- */
460
+ /** Handle a `job.reject`: undo the dispatch accounting and requeue for another agent. */
552
461
  onJobRejected(agentId: string, jobId: string, reason: string): Promise<void>;
553
- /** Remove a job from all per-agent in-memory tracking. */
554
462
  private untrackJob;
555
463
  /**
556
- * Requeue a dispatched job for re-delivery, or fail it permanently when
557
- * its attempt budget is exhausted. Returns the outcome so disconnect
558
- * triage can surface failed job IDs to the caller. `countAttempt: false`
559
- * requeues without spending the budget (a busy rejection).
464
+ * Requeue a dispatched job, or fail it once its attempt budget is exhausted;
465
+ * the outcome lets disconnect triage surface failed job IDs. `countAttempt:
466
+ * false` spends no budget (a busy rejection).
560
467
  */
561
468
  private requeueOrFail;
562
469
  /**
563
- * The half of {@link requeueOrFail} that runs once the row has been flipped:
564
- * fail the job when its attempt budget is exhausted, otherwise re-dispatch.
565
- *
566
- * Split out so the ack-expiry paths can drive it from the attempt count their
567
- * own guarded requeue (`requeueIfAwaitingAck`) returned, instead of flipping
568
- * the row a second time.
470
+ * The post-flip half of {@link requeueOrFail}: fail on an exhausted budget,
471
+ * else re-dispatch. Split out so ack expiry drives it from its guarded
472
+ * requeue's (`requeueIfAwaitingAck`) attempt count without flipping the row twice.
569
473
  */
570
474
  private finishRequeue;
571
475
  /**
572
- * Try to deliver a requeued pending job: prefer an idle matching agent
573
- * (atomic claim via dispatchBoundJob), otherwise consult the scaler so a
574
- * fresh agent is spawned bound to this job.
476
+ * Deliver a requeued pending job: an idle matching agent (atomic claim via
477
+ * dispatchBoundJob), else the scaler spawns a fresh agent bound to it.
575
478
  */
576
479
  private redispatch;
577
480
  /**
578
- * Safety-net re-drive: deliver every pending job that a currently-connected,
579
- * idle, matching agent could take, through the same atomic claim the drain
580
- * uses (`dispatchBoundJob` → `dequeueById`).
581
- *
582
- * Runs per-coordinator and is NOT leader-gated: each coordinator drains the
583
- * shared queue onto its OWN connected agents, and the atomic claim guarantees
584
- * at most one agent (on any coordinator) wins each job, so concurrent ticks
585
- * cannot double-dispatch.
481
+ * Safety-net re-drive: deliver each pending job a connected, idle, matching
482
+ * agent could take, through the drain's atomic claim (`dispatchBoundJob` →
483
+ * `dequeueById`).
586
484
  *
587
- * It closes the requeue re-drive gap. A job requeued by `handleAckExpiry` /
588
- * `onJobRejected` / the leader ack sweep gets exactly one delivery attempt —
589
- * `redispatch`'s single `findAvailable` + `dispatchBoundJob`. An idle matching
590
- * agent whose own drain trigger (registration / completion / status) already
591
- * fired before the requeue has no further trigger, so if that one attempt
592
- * transiently misses the agent — the agent is momentarily at capacity while an
593
- * in-flight drain holds its eagerly-claimed slot, or the agent is connected to
594
- * a different coordinator than the one that ran the expiry — the requeued
595
- * pending job would otherwise sit undelivered until it expired. This tick
596
- * re-attempts delivery onto connected agents so the miss recovers on the next
597
- * sweep.
485
+ * Per-coordinator, NOT leader-gated: each coordinator drains the shared queue
486
+ * onto its OWN agents, and the atomic claim lets at most one agent (on any
487
+ * coordinator) win each job, so concurrent ticks cannot double-dispatch.
598
488
  *
599
- * It never consults the scaler (that is `retryPendingScaleRequests`) and never
600
- * spawns: it only places jobs onto agents already connected here.
489
+ * It closes the requeue gap: a job requeued by `handleAckExpiry` /
490
+ * `onJobRejected` / the leader ack sweep gets one delivery attempt
491
+ * (`redispatch`'s `findAvailable` + `dispatchBoundJob`), and an idle agent whose
492
+ * drain trigger fired before the requeue gets no other. If that attempt misses
493
+ * (the agent momentarily at capacity while a drain holds its eagerly claimed
494
+ * slot, or connected to another coordinator than the one that ran the expiry),
495
+ * the job would sit until it expired; this tick recovers it on the next sweep.
601
496
  *
602
- * Returns the number of jobs sent. A job it claims but does not send (its
603
- * dispatch refused, or its sealed secrets unopenable here) is not counted.
497
+ * Never consults the scaler (that is `retryPendingScaleRequests`) or spawns.
604
498
  *
605
- * A failure propagates to the caller rather than being swallowed here — the
606
- * per-coord interval wrapper is the single error-log site, matching the
607
- * sibling recovery/ack sweeps that share its cadence. The `finally` only
608
- * releases the single-flight guard.
499
+ * Returns the jobs sent; a claimed job not sent (refused, or sealed secrets
500
+ * unopenable here) is not counted. Failures propagate: the per-coord interval
501
+ * wrapper is the single error-log site, like the sibling recovery/ack sweeps
502
+ * on its cadence. The `finally` only releases the single-flight guard.
609
503
  */
610
504
  redrivePendingToConnectedAgents(maxJobs?: number): Promise<number>;
611
505
  /**
612
- * Pick a connected agent that may take a pending job, or null. A pinned
613
- * host-fanout child may run ONLY on its pinned agent — and `dequeueById`
614
- * ignores the pin — so a pinned job is routed to its own agent and never
615
- * offered to `findAvailable`, which would mis-deliver it to any label match.
506
+ * Pick a connected agent for a pending job, or null. A pinned host-fanout child
507
+ * runs ONLY on its pinned agent and `dequeueById` ignores the pin, so it never
508
+ * goes to `findAvailable`, which would mis-deliver it to any label match.
616
509
  *
617
- * Reboot-pending gate: a host whose `restart` job just completed is still
618
- * connected but about to reboot, so its held post-restart job must NOT be
619
- * re-driven into the about-to-die box. This is the safety-net re-drive's
620
- * counterpart of the same gate in `dispatch()` / `dispatchPinned` /
621
- * `drainForAgent`; without it this path re-drives the held job onto the
622
- * reboot-pending host and defeats the hold.
510
+ * Reboot-pending gate: the safety-net counterpart of the gate in `dispatch()` /
511
+ * `dispatchPinned` / `drainForAgent`; without it this path re-drives the held
512
+ * post-restart job onto the about-to-reboot host and defeats the hold.
623
513
  */
624
514
  private selectConnectedTargetForPending;
625
515
  /**
@@ -627,160 +517,116 @@ export declare class Dispatcher {
627
517
  * immediately failing jobs, giving the agent a grace period to reconnect.
628
518
  * If no in-flight jobs, performs a clean disconnect.
629
519
  *
630
- * Returns empty array (no immediately failed jobs -- failures happen
631
- * asynchronously when recovery timers expire).
520
+ * Returns the started jobs a scaler-managed agent's disconnect failed outright;
521
+ * otherwise empty (failures happen asynchronously when recovery timers expire).
632
522
  */
633
523
  onAgentDisconnect(agentId: string): Promise<string[]>;
634
524
  /**
635
- * Reboot-pending agent disconnected: complete its in-flight started job(s) as
636
- * success (the restart job, which already reported success, may already be
637
- * terminal — `markCompleted` is a no-op / guarded in that case). Never starts
638
- * a recovery timer. Untracks the jobs so the reconnect does not reconcile a
639
- * phantom in-flight set.
525
+ * Complete a reboot-pending agent's in-flight started jobs as success (the
526
+ * restart job may already be terminal; `markCompleted` is guarded then). No
527
+ * recovery timer. Untracked so the reconnect reconciles no phantom in-flight set.
640
528
  */
641
529
  private completeInFlightForReboot;
642
- /** Drop grace-window entries owned by an agent. */
643
530
  private cleanupGraceEntriesForAgent;
644
- /**
645
- * Scaler-managed agent disconnected: requeue never-started jobs, fail
646
- * started ones. Returns the permanently failed job IDs.
647
- */
531
+ /** Scaler-managed disconnect: requeue never-started jobs, fail started ones (returned). */
648
532
  private triageScalerManagedDisconnect;
649
533
  /**
650
- * Static agent disconnected: start per-job recovery timers (the agent
651
- * may reconnect and reclaim). Always returns [] — failures happen
652
- * asynchronously when recovery timers expire.
534
+ * Static disconnect: per-job recovery timers (the agent may reconnect and
535
+ * reclaim). Always returns []; failures happen when the timers expire.
653
536
  */
654
537
  private startRecoveryForDisconnect;
655
538
  /**
656
- * Called when an agent completes a job (success or failure).
657
- * Decrements active jobs and moves the job to the grace window
658
- * (instead of immediately removing it) so that late messages
659
- * (e.g. final log chunks) are still accepted.
539
+ * An agent finished a job (success or failure). The job moves to the grace
540
+ * window rather than being removed, so late messages (final log chunks) are
541
+ * still accepted.
660
542
  */
661
543
  onJobComplete(agentId: string, jobId: string): void;
662
544
  /**
663
- * Check if a job is owned by the given agent.
664
- * Returns true if the job is actively dispatched to the agent,
665
- * in recovery (agent disconnected but within grace period),
666
- * or in the grace window (completed within the last 30 seconds).
545
+ * True if the job is dispatched to the agent, recovering (disconnected within
546
+ * the grace period), or in the grace window (completed in the last 30 seconds).
667
547
  */
668
548
  isJobOwnedByAgent(agentId: string, jobId: string): boolean;
669
- /**
670
- * Resolve which agent a dispatched job was sent to.
671
- * Used by the cancel-run API. Returns null if the job is not tracked (e.g. already completed).
672
- */
549
+ /** For the cancel-run API; null once the job is untracked (e.g. completed). */
673
550
  getAgentIdForJob(jobId: string): string | null;
674
551
  /** The jobs of `runId` this dispatcher currently tracks to an agent. */
675
552
  getTrackedJobIdsForRun(runId: string): string[];
676
- /**
677
- * Start periodic cleanup of expired grace window entries.
678
- * Should be called during server startup.
679
- */
553
+ /** Start periodic cleanup of expired grace window entries; call at server startup. */
680
554
  startGraceCleanup(): void;
681
- /**
682
- * Stop periodic grace cleanup.
683
- * Should be called during server shutdown.
684
- */
555
+ /** Call at server shutdown. */
685
556
  stopGraceCleanup(): void;
686
557
  /**
687
- * Claim a recovering job back for a reconnected agent.
688
- * Cancels the recovery timer and returns true if the job was in recovery
689
- * for this agent. Returns false if the job is not recovering or belongs
690
- * to a different agent.
558
+ * Claim a recovering job back for a reconnected agent, cancelling its timer;
559
+ * false if it is not recovering or belongs to a different agent.
691
560
  */
692
561
  claimRecovery(jobId: string, agentId: string): boolean;
693
562
  /**
694
- * Full reconciliation of a recovering job for a reconnected agent.
695
- * Claims the recovery timer, transitions DB status back to dispatched,
696
- * and restores in-memory tracking. Returns true if reconciled.
563
+ * Reconcile a recovering job for a reconnected agent: claim the timer, move
564
+ * the DB row back to dispatched, restore in-memory tracking.
697
565
  */
698
566
  reconcileRecovery(jobId: string, agentId: string): Promise<boolean>;
699
- /**
700
- * Get recovery info for a job (for structured logging).
701
- */
567
+ /** For structured logging. */
702
568
  getRecoveryInfo(jobId: string): {
703
569
  disconnectedAt: number;
704
570
  agentId: string;
705
571
  } | null;
706
- /**
707
- * Get all recovering job IDs for a specific agent.
708
- * Used during reconnection reconciliation.
709
- */
572
+ /** For reconnection reconciliation. */
710
573
  getRecoveringJobsForAgent(agentId: string): string[];
711
574
  /**
712
- * Restore a reconciled job into the dispatcher's in-memory tracking.
713
- * Called when an agent reconnects and claims a recovering job. A
714
- * reconnecting agent reporting the job in-flight means it had started,
715
- * so mark it started for disconnect triage.
575
+ * Restore a job a reconnected agent claimed from recovery. The agent reports
576
+ * it in-flight, so it had started: marked started for disconnect triage.
716
577
  */
717
578
  restoreJobForAgent(agentId: string, jobId: string, runId?: string): void;
718
579
  /**
719
- * Start a recovery timer for a job found in 'dispatched' state on startup.
720
- * Called by server.ts/standalone.ts to create recovery timers for jobs
721
- * from a previous orchestrator instance.
580
+ * Start a recovery timer for a job found 'dispatched' at startup. Called by
581
+ * orchestrator-core.ts for jobs from a previous orchestrator instance.
722
582
  */
723
583
  startRecoveryTimer(jobId: string, agentId: string, runId: string): Promise<void>;
724
584
  /**
725
- * Rebuild the in-memory `recoveringJobs` Map from persisted
726
- * `dispatch_queue` rows after a coord boot / Raft leader switch.
727
- *
728
- * For each `status='recovering'` row:
729
- * - if `recovery_deadline` is in the future, recreate a setTimeout
730
- * with the remaining window so the local sweep still fires.
731
- * - if the deadline is already in the past, leave the row alone —
732
- * the leader-gated `sweepExpiredRecoveries()` will pick it up on
733
- * its next tick (which avoids two coords racing to mark the same
734
- * job failed during recovery).
735
- * - rows with NULL deadline (pre-migration recovering jobs) are
736
- * fast-failed by the sweep on its first run.
585
+ * Rebuild `recoveringJobs` from `dispatch_queue` after a coord boot / Raft
586
+ * leader switch. Per `status='recovering'` row:
587
+ * - future `recovery_deadline`: re-arm a timer for the remaining window.
588
+ * - past deadline: left to the leader-gated `sweepExpiredRecoveries()`, so
589
+ * two coords never race to mark the same job failed.
590
+ * - NULL deadline (pre-migration recovering jobs): the sweep fast-fails it
591
+ * on its first run.
737
592
  */
738
593
  recoverState(): Promise<void>;
739
594
  /**
740
- * Leader-gated sweep: requeue every `dispatched` row whose ack deadline
741
- * passed while no coord was watching (owning coord crashed before its
742
- * in-memory timer fired). Requeue is atomic (WHERE status='dispatched'),
743
- * so racing coords cannot double-requeue.
595
+ * Leader-gated sweep: requeue `dispatched` rows whose ack deadline passed
596
+ * unwatched (the owning coord crashed before its timer fired). The requeue is
597
+ * atomic (WHERE status='dispatched'), so racing coords cannot double-requeue.
744
598
  */
745
599
  sweepExpiredAckDeadlines(): Promise<number>;
746
600
  /**
747
- * Leader-gated sweep: mark every `recovering` row whose
748
- * `recovery_deadline < now` as `failed` and fire the per-job
749
- * `onJobFailedPermanently` hook. Intended to run on the Raft leader at a
750
- * fixed interval so jobs whose owning coord crashed mid-recovery
751
- * still reach a terminal state.
752
- *
753
- * Safe to call on non-leaders (idempotent due to the WHERE clause)
754
- * but skipping the call on followers avoids redundant DB updates.
601
+ * Leader-gated sweep: fail `recovering` rows with `recovery_deadline < now`
602
+ * and fire `onJobFailedPermanently`, so jobs whose owning coord crashed
603
+ * mid-recovery still reach a terminal state. Runs on the Raft leader at a
604
+ * fixed interval; idempotent on followers (WHERE clause), skipped there to
605
+ * avoid redundant DB updates.
755
606
  */
756
607
  sweepExpiredRecoveries(): Promise<number>;
757
- /**
758
- * Stop all recovery timers. Called during graceful shutdown.
759
- */
608
+ /** Called during graceful shutdown. */
760
609
  stopRecoveryTimers(): void;
761
610
  /**
762
- * Handle recovery timer expiry for a single job.
763
- * Extracted so that both onAgentDisconnect and startRecoveryTimer share the same logic,
764
- * and the caller can `.catch()` to prevent unhandled rejections in setTimeout.
611
+ * Recovery timer expiry for one job, shared by onAgentDisconnect and
612
+ * startRecoveryTimer; callers `.catch()` it to avoid unhandled rejections in
613
+ * setTimeout.
765
614
  */
766
615
  private handleRecoveryExpiry;
767
- /** Remove expired entries from the completedJobs grace window map. */
768
616
  private cleanupExpiredGraceEntries;
769
617
  private trackJobForAgent;
770
618
  /**
771
- * Verify `agentId` currently owns `jobId`; if so, return the job's runId from
772
- * the dispatcher's own tracking. Used by the provenance token relay so the
773
- * orchestrator binds a minted token to a job the agent actually owns — the
774
- * agent never asserts a runId. Returns `undefined` when the agent does not
775
- * own the job (or the runId is no longer tracked).
619
+ * The runId of `jobId` from dispatcher tracking, if `agentId` currently owns
620
+ * it; else `undefined` (also when the runId is no longer tracked). The
621
+ * provenance token relay binds a minted token to a job the agent actually
622
+ * owns — the agent never asserts a runId.
776
623
  */
777
624
  resolveOwnedJob(agentId: string, jobId: string): {
778
625
  runId: string;
779
626
  } | undefined;
780
627
  /**
781
- * Cancel a queued job (mark as failed in the dispatch queue).
782
- * Used by the coordinator to clean up local fallback entries when a peer
783
- * accepts the rerouted job.
628
+ * Mark a queued job failed: the coordinator cleans up its local fallback
629
+ * entry once a peer accepts the rerouted job.
784
630
  */
785
631
  cancelQueuedJob(jobId: string, reason: string): Promise<void>;
786
632
  private updateQueueDepthMetric;