@kici-dev/orchestrator 0.5.0 → 0.6.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 (149) hide show
  1. package/dist/__test-helpers__/fake-scaler-state-store.d.ts +24 -0
  2. package/dist/__test-helpers__/mock-db-query.d.ts +130 -0
  3. package/dist/__test-helpers__/mock-db.d.ts +23 -0
  4. package/dist/agent/dispatcher.d.ts +81 -13
  5. package/dist/agent/host-roster.d.ts +37 -5
  6. package/dist/agent/registry.d.ts +2 -0
  7. package/dist/app.d.ts +33 -6
  8. package/dist/approvals/apply-decision.d.ts +67 -19
  9. package/dist/approvals/held-run-release-wiring.d.ts +45 -0
  10. package/dist/approvals/independent-wiring.d.ts +55 -0
  11. package/dist/approvals/resume-router.d.ts +9 -0
  12. package/dist/approvals/triggerer-subject.d.ts +37 -0
  13. package/dist/cache/dep-cache.d.ts +54 -10
  14. package/dist/cache/global-eval-round-cache.d.ts +7 -0
  15. package/dist/cli/api-client.d.ts +18 -0
  16. package/dist/cli/commands/cluster-settings.d.ts +11 -0
  17. package/dist/cli/commands/diagnose.d.ts +6 -0
  18. package/dist/cli/commands/held-run.d.ts +58 -0
  19. package/dist/cli/commands/trust-policy.d.ts +117 -12
  20. package/dist/cli/kici-admin.d.ts +10 -0
  21. package/dist/cli.js +2272 -1025
  22. package/dist/cluster/cluster-identity.d.ts +3 -3
  23. package/dist/cluster/cluster-settings-reader.d.ts +7 -1
  24. package/dist/cluster/coordinator.d.ts +44 -0
  25. package/dist/cluster/index.d.ts +4 -0
  26. package/dist/cluster/peer-handler.d.ts +19 -0
  27. package/dist/cluster/peer-registry.d.ts +17 -0
  28. package/dist/cluster/plan-headroom-store.d.ts +26 -0
  29. package/dist/cluster/worker-eviction.d.ts +69 -0
  30. package/dist/cold-store/load-event-log-range.d.ts +10 -3
  31. package/dist/cold-store/load-secret-audit-log-range.d.ts +4 -3
  32. package/dist/cold-store/tables/secret-audit-log.d.ts +4 -3
  33. package/dist/config.d.ts +21 -21
  34. package/dist/contexts/held-runs.d.ts +123 -16
  35. package/dist/contexts/protection/aggregate.d.ts +3 -2
  36. package/dist/contexts/protection/branch-gate.d.ts +15 -0
  37. package/dist/contexts/protection/concurrency-gate.d.ts +8 -2
  38. package/dist/contexts/protection/pipeline.d.ts +18 -0
  39. package/dist/contexts/release-queued-holds.d.ts +35 -0
  40. package/dist/dashboard/attestation-filters.d.ts +8 -0
  41. package/dist/dashboard/handler.d.ts +6 -24
  42. package/dist/db/migrations/116_org_plan_headroom.d.ts +4 -0
  43. package/dist/db/migrations/117_invoke_gate_proxy_jobs.d.ts +4 -0
  44. package/dist/db/migrations/118_invoke_gate_scheduling.d.ts +4 -0
  45. package/dist/db/migrations/119_scaler_ha_ownership.d.ts +4 -0
  46. package/dist/db/migrations/120_cluster_settings_scaler_reaper.d.ts +4 -0
  47. package/dist/db/migrations/121_org_settings_allow_untrusted_dockerfile_builds.d.ts +19 -0
  48. package/dist/db/migrations/122_host_roster_scaler_managed.d.ts +25 -0
  49. package/dist/db/migrations/123_workflow_registrations_default_branch.d.ts +24 -0
  50. package/dist/db/migrations/124_cluster_settings_provision_backoff.d.ts +4 -0
  51. package/dist/db/migrations/125_org_trust_directory.d.ts +30 -0
  52. package/dist/db/migrations/126_held_runs_posted_pending_check.d.ts +28 -0
  53. package/dist/db/migrations/127_org_trust_policy_approval_expiry_seconds.d.ts +26 -0
  54. package/dist/db/migrations/128_execution_runs_global_eval_round.d.ts +23 -0
  55. package/dist/db/migrations/129_execution_runs_dispatch_routing_key.d.ts +24 -0
  56. package/dist/db/migrations/130_scaler_provision_outcomes.d.ts +32 -0
  57. package/dist/db/types.d.ts +368 -10
  58. package/dist/entry-helpers.d.ts +28 -0
  59. package/dist/events/event-emitter.d.ts +22 -0
  60. package/dist/events/event-router.d.ts +87 -1
  61. package/dist/events/types.d.ts +2 -23
  62. package/dist/git/credential-broker.d.ts +94 -0
  63. package/dist/git/inherited-secret.d.ts +24 -0
  64. package/dist/git/installation-token.d.ts +38 -0
  65. package/dist/git/job-context.d.ts +13 -0
  66. package/dist/index.js +324 -84
  67. package/dist/metrics/agent-metrics-aggregator.d.ts +2 -2
  68. package/dist/metrics/prometheus.d.ts +111 -3
  69. package/dist/oidc/oidc-mint-registration.d.ts +7 -3
  70. package/dist/orchestrator-core.d.ts +79 -23
  71. package/dist/pipeline/direct-ingress-deps.d.ts +100 -0
  72. package/dist/pipeline/dispatch-matched-workflow.d.ts +302 -31
  73. package/dist/pipeline/global-eval-round.d.ts +14 -0
  74. package/dist/pipeline/internal-event-pipeline.d.ts +140 -0
  75. package/dist/pipeline/invoke-gate.d.ts +164 -0
  76. package/dist/pipeline/needs-scheduler.d.ts +13 -0
  77. package/dist/pipeline/process-webhook.d.ts +119 -31
  78. package/dist/pipeline/processor.d.ts +226 -21
  79. package/dist/pipeline/rerun.d.ts +21 -0
  80. package/dist/pipeline/resume-workflow.d.ts +40 -7
  81. package/dist/pipeline/route-or-dispatch-jobs.d.ts +9 -0
  82. package/dist/pipeline/security-hold-check.d.ts +217 -0
  83. package/dist/pipeline/undispatched-hold-checks.d.ts +23 -0
  84. package/dist/policy/dashboard-write-policy-listener.d.ts +62 -0
  85. package/dist/policy/dashboard-write-policy.d.ts +14 -0
  86. package/dist/provider-registry.d.ts +10 -2
  87. package/dist/providers/github/check-status-poster.d.ts +11 -0
  88. package/dist/providers/github/index.d.ts +0 -2
  89. package/dist/providers/github/normalizer.d.ts +3 -2
  90. package/dist/providers/local/normalizer.d.ts +3 -5
  91. package/dist/providers/universal-git/index.d.ts +11 -2
  92. package/dist/queue/job-queue.d.ts +43 -1
  93. package/dist/registration/extractor.d.ts +3 -3
  94. package/dist/registration/registration-index.d.ts +7 -0
  95. package/dist/registration/registration-store.d.ts +22 -0
  96. package/dist/reporting/check-run-reporter.d.ts +94 -1
  97. package/dist/reporting/check-run-summary.d.ts +25 -1
  98. package/dist/reporting/execution-tracker.d.ts +207 -2
  99. package/dist/reporting/run-aggregator.d.ts +4 -14
  100. package/dist/reporting/step-display-order.d.ts +43 -0
  101. package/dist/routes/admin-held-runs.d.ts +142 -0
  102. package/dist/routes/admin-trust-policy.d.ts +34 -6
  103. package/dist/routes/admin.d.ts +9 -0
  104. package/dist/scaler/backend-factory.d.ts +55 -0
  105. package/dist/scaler/bare-metal-backend.d.ts +43 -5
  106. package/dist/scaler/claim-store.d.ts +119 -0
  107. package/dist/scaler/config.d.ts +4 -0
  108. package/dist/scaler/container-backend.d.ts +18 -4
  109. package/dist/scaler/container-routing.d.ts +23 -0
  110. package/dist/scaler/container-spawn.d.ts +28 -0
  111. package/dist/scaler/event-backend.d.ts +124 -0
  112. package/dist/scaler/event-provision-reaper.d.ts +350 -0
  113. package/dist/scaler/failure-tracker.d.ts +1 -1
  114. package/dist/scaler/firecracker-backend.d.ts +33 -6
  115. package/dist/scaler/index.d.ts +11 -1
  116. package/dist/scaler/label-matcher.d.ts +4 -3
  117. package/dist/scaler/manager.d.ts +899 -72
  118. package/dist/scaler/resolve-container-auth.d.ts +45 -0
  119. package/dist/scaler/scaler-events.d.ts +11 -0
  120. package/dist/scaler/scaler-state-store.d.ts +294 -10
  121. package/dist/scaler/types.d.ts +131 -13
  122. package/dist/scaler/warm-pool.d.ts +132 -29
  123. package/dist/security/comment-handler.d.ts +50 -11
  124. package/dist/security/identity-link.d.ts +60 -0
  125. package/dist/security/lock-source.d.ts +11 -13
  126. package/dist/security/reduced-privilege-note.d.ts +59 -0
  127. package/dist/security/trust-directory-store.d.ts +233 -0
  128. package/dist/security/trust-policy-gate.d.ts +94 -59
  129. package/dist/security/trust-policy-store.d.ts +3 -0
  130. package/dist/security/trust-resolver.d.ts +14 -98
  131. package/dist/server.d.ts +11 -1
  132. package/dist/server.js +17671 -7350
  133. package/dist/stale-detector/gate-deadline-detector.d.ts +52 -0
  134. package/dist/stale-detector/stale-run-detector.d.ts +61 -3
  135. package/dist/standalone.js +24238 -13822
  136. package/dist/worker/in-memory-job-queue.d.ts +1 -1
  137. package/dist/ws/agent-handler.d.ts +28 -4
  138. package/dist/ws/dashboard-context-handler.d.ts +28 -4
  139. package/dist/ws/dashboard-global-workflows-handler.d.ts +6 -0
  140. package/dist/ws/failure-messages.d.ts +2 -0
  141. package/dist/ws/git-credential-relay.d.ts +39 -0
  142. package/dist/ws/oidc-token-relay.d.ts +6 -11
  143. package/dist/ws/platform-client.d.ts +54 -9
  144. package/installer-image-digests.json +3 -3
  145. package/package.json +24 -19
  146. package/sbom.spdx.json +864 -822
  147. package/dist/approvals/team-membership-lookup.d.ts +0 -13
  148. package/dist/providers/github/contributor-resolver.d.ts +0 -30
  149. package/dist/security/contributor-cache.d.ts +0 -83
@@ -0,0 +1,52 @@
1
+ /**
2
+ * GateDeadlineDetector: periodic DB scanner enforcing an invoke gate's own
3
+ * job-level `timeout`.
4
+ *
5
+ * A gate runs no steps on an agent, so the agent-side job timeout can never fire
6
+ * for it. Instead the orchestrator owns the gate deadline: this scanner finds
7
+ * non-terminal `gate` jobs whose `timeout_ms` has elapsed since the gate began
8
+ * summoning and fails each one. Failing the gate drives its downstream `needs`
9
+ * cascade through the normal job-status path; the summoned source-repo runs are
10
+ * the repos' own runs and are left untouched.
11
+ *
12
+ * The gate's timeout clock is `ready_at` (when the needs scheduler released it to
13
+ * summon), falling back to `created_at` for a root gate that never carried a
14
+ * `ready_at`.
15
+ */
16
+ import { type Kysely } from 'kysely';
17
+ import type { Database } from '../db/types.js';
18
+ import type { ExecutionTracker } from '../reporting/execution-tracker.js';
19
+ /**
20
+ * Recency window for the deadline-bounded scan, mirroring the workflow deadline
21
+ * detector: a gate stays in scope while its deadline lapsed within this window,
22
+ * which keeps long-timeout gates enforced while skipping ancient history.
23
+ */
24
+ export declare const GATE_DEADLINE_RECENCY_WINDOW_MS: number;
25
+ export interface GateDeadlineDetectorDeps {
26
+ db: Kysely<Database>;
27
+ /** Used to fail an overdue gate through the canonical job-status path. */
28
+ executionTracker: Pick<ExecutionTracker, 'onJobStatus'>;
29
+ /** How often to scan in ms (reuses the stale-detector interval). */
30
+ scanIntervalMs: number;
31
+ }
32
+ export declare class GateDeadlineDetector {
33
+ private readonly db;
34
+ private readonly executionTracker;
35
+ private readonly scanIntervalMs;
36
+ private interval;
37
+ constructor(deps: GateDeadlineDetectorDeps);
38
+ /** Start the detector: an immediate crash-recovery scan, then periodic scans. */
39
+ start(): Promise<void>;
40
+ stop(): void;
41
+ /** Find non-terminal gates past their timeout and fail each one. */
42
+ scan(): Promise<void>;
43
+ /**
44
+ * Build the SELECT for overdue gates. Extracted so a unit test can compile the
45
+ * exact predicate set (Kysely `.compile()`) without a live database. A gate is
46
+ * overdue when `coalesce(ready_at, created_at) + timeout_ms` is in the past;
47
+ * the recency bound keeps the scan off ancient history each tick.
48
+ */
49
+ private buildOverdueQuery;
50
+ private failOverdueGate;
51
+ }
52
+ //# sourceMappingURL=gate-deadline-detector.d.ts.map
@@ -22,6 +22,7 @@ import type { CheckRunReporter } from '../reporting/check-run-reporter.js';
22
22
  import type { ScalerManager } from '../scaler/manager.js';
23
23
  import type { Dispatcher } from '../agent/dispatcher.js';
24
24
  import type { AgentRegistry } from '../agent/registry.js';
25
+ import { type ResolveCheckStatusPoster } from '../pipeline/security-hold-check.js';
25
26
  import type { HeldRunStore, ReleaseSignal } from '../contexts/held-runs.js';
26
27
  import type { StepApprovalBridge } from '../approvals/step-approval-bridge.js';
27
28
  import type { AccessLogWriter } from '../audit/access-log.js';
@@ -60,8 +61,32 @@ export interface StaleRunDetectorDeps {
60
61
  * set, wait-timer workflow holds are not auto-released.
61
62
  */
62
63
  onWorkflowRelease?: (signal: ReleaseSignal) => Promise<void>;
64
+ /**
65
+ * Resume a released JOB-scoped hold by re-dispatching the job. A job-scoped
66
+ * wait-timer hold has a pending job context, not a pending workflow context,
67
+ * so it cannot go through `onWorkflowRelease`.
68
+ */
69
+ onJobRelease?: (signal: ReleaseSignal) => Promise<void>;
70
+ /**
71
+ * Resolve a context by name, for the queued-concurrency sweep — it needs each
72
+ * group's configured `concurrency_limit` to know how many holds a freed slot
73
+ * lets through. `ContextStore.matchContext`.
74
+ */
75
+ matchContext?: (orgId: string, name: string) => Promise<{
76
+ concurrency_limit: number | null;
77
+ } | null>;
63
78
  /** Access-log writer for the orchestrator audit stream. Optional -- if not set, expiry audit rows (`held_run.expire`) are skipped. */
64
79
  accessLogWriter?: AccessLogWriter;
80
+ /**
81
+ * Resolve the check poster of the provider bundle serving a routing key, so an
82
+ * expiring security hold's `KiCI Security` check can be completed. A function
83
+ * rather than the registry itself because the registry instance is replaced
84
+ * when sources are (re)loaded, and this detector outlives that.
85
+ *
86
+ * Optional -- if not set, an expiring security hold's check is left alone,
87
+ * which is the pre-existing behaviour rather than a wrong one.
88
+ */
89
+ resolveCheckStatusPoster?: ResolveCheckStatusPoster;
65
90
  }
66
91
  export declare class StaleRunDetector {
67
92
  private readonly db;
@@ -79,13 +104,38 @@ export declare class StaleRunDetector {
79
104
  private readonly stepApprovalBridge?;
80
105
  private readonly failRun?;
81
106
  private readonly onWorkflowRelease?;
107
+ private readonly onJobRelease?;
108
+ private readonly matchContext?;
82
109
  private readonly accessLogWriter?;
110
+ private readonly resolveCheckStatusPoster?;
83
111
  private interval;
84
112
  constructor(deps: StaleRunDetectorDeps);
85
113
  /**
86
- * Release workflow install-gate wait-timer holds whose timer has elapsed.
87
- * Runs BEFORE `expireOverdueHolds` so a wait hold resumes the workflow rather
88
- * than being failed by the expire-and-fail sweep.
114
+ * Release queued concurrency holds whose group now has a free slot.
115
+ *
116
+ * A context's concurrency gate returns `queue` when its limit is met, holding
117
+ * the job. Nothing released those holds: they sat pending until the expiry
118
+ * sweep marked them expired and their jobs never ran. This is the release
119
+ * half.
120
+ *
121
+ * Driven from the periodic scan rather than from job completion: the
122
+ * completion callback is constructed before the dispatcher, coordinator and
123
+ * context store exist, so wiring it there would mean threading four refs
124
+ * through a hot path. The cost is up to one scan interval of latency before a
125
+ * freed slot is reused, which for a throughput control is an acceptable
126
+ * trade — and every release still re-checks the limit, so the bound is never
127
+ * exceeded regardless of when the sweep runs.
128
+ */
129
+ private releaseFreedConcurrencyHolds;
130
+ /**
131
+ * Release wait-timer holds whose timer has elapsed, at ANY scope, and route
132
+ * each to the resume path its shape requires: a workflow install-gate hold
133
+ * rebuilds its workflow dispatch context, a job-scoped hold re-dispatches the
134
+ * one job it held.
135
+ *
136
+ * Runs BEFORE `expireOverdueHolds` so a wait hold resumes rather than being
137
+ * failed by the expire-and-fail sweep — that sweep is not scope-filtered, so
138
+ * the ordering is load-bearing.
89
139
  */
90
140
  private releaseDueWaitHolds;
91
141
  /**
@@ -93,6 +143,14 @@ export declare class StaleRunDetector {
93
143
  * bulk status flip: step-scoped holds notify the waiting agent (which fails
94
144
  * the step), job/workflow-scoped holds fail the whole run. Then the bulk
95
145
  * `expireOverdue()` flips every overdue row to `expired`.
146
+ *
147
+ * Every overdue row's id is excluded from the security check's contention
148
+ * query for the whole loop, because `expireOverdue()` has not run yet: each
149
+ * of them is still `pending` in the database while its siblings are being
150
+ * routed, and without the exclusion a commit whose two holds both expired
151
+ * would see each hold refuse on account of the other and leave the check
152
+ * pending forever. The commits already settled are tracked so one sweep
153
+ * writes each shared check once.
96
154
  */
97
155
  private expireOverdueHolds;
98
156
  /**