detectkit 0.66.5__tar.gz → 0.67.1__tar.gz

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 (173) hide show
  1. {detectkit-0.66.5/detectkit.egg-info → detectkit-0.67.1}/PKG-INFO +1 -1
  2. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/__init__.py +1 -1
  3. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/orchestrator/_recovery.py +87 -25
  4. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/rules/alerting.md +9 -0
  5. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/rules/cli.md +8 -4
  6. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/config/metric_config.py +41 -0
  7. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/orchestration/task_manager/_alert_step.py +2 -4
  8. detectkit-0.67.1/detectkit/ui/assets/ui.js +557 -0
  9. {detectkit-0.66.5 → detectkit-0.67.1/detectkit.egg-info}/PKG-INFO +1 -1
  10. detectkit-0.66.5/detectkit/ui/assets/ui.js +0 -551
  11. {detectkit-0.66.5 → detectkit-0.67.1}/LICENSE +0 -0
  12. {detectkit-0.66.5 → detectkit-0.67.1}/MANIFEST.in +0 -0
  13. {detectkit-0.66.5 → detectkit-0.67.1}/README.md +0 -0
  14. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/__init__.py +0 -0
  15. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/__init__.py +0 -0
  16. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/base.py +0 -0
  17. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/branding.py +0 -0
  18. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/discord.py +0 -0
  19. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/email.py +0 -0
  20. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/factory.py +0 -0
  21. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/googlechat.py +0 -0
  22. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/mattermost.py +0 -0
  23. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/ntfy.py +0 -0
  24. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/slack.py +0 -0
  25. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/teams.py +0 -0
  26. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/telegram.py +0 -0
  27. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/channels/webhook.py +0 -0
  28. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/orchestrator/__init__.py +0 -0
  29. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/orchestrator/_base.py +0 -0
  30. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/orchestrator/_cooldown.py +0 -0
  31. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/orchestrator/_decision.py +0 -0
  32. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/orchestrator/_dispatch.py +0 -0
  33. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/orchestrator/_replay.py +0 -0
  34. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/orchestrator/_types.py +0 -0
  35. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/alerting/orchestrator/orchestrator.py +0 -0
  36. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/__init__.py +0 -0
  37. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/_base.py +0 -0
  38. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/_types.py +0 -0
  39. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/autotuner.py +0 -0
  40. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/axis_spec.py +0 -0
  41. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/config_emitter.py +0 -0
  42. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/crossval.py +0 -0
  43. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/detector_select.py +0 -0
  44. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/distribution.py +0 -0
  45. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/grid_search.py +0 -0
  46. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/labels.py +0 -0
  47. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/result.py +0 -0
  48. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/runner.py +0 -0
  49. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/scoring.py +0 -0
  50. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/seasonality_search.py +0 -0
  51. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/settings.py +0 -0
  52. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/autotune/window_select.py +0 -0
  53. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/__init__.py +0 -0
  54. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/_output.py +0 -0
  55. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/CLAUDE.section.md +0 -0
  56. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/rules/autotune.md +0 -0
  57. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/rules/detectors.md +0 -0
  58. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/rules/metrics.md +0 -0
  59. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/rules/overview.md +0 -0
  60. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/rules/project.md +0 -0
  61. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/skills/dtk-autotune/SKILL.md +0 -0
  62. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/skills/dtk-feedback/SKILL.md +0 -0
  63. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/skills/dtk-new-metric/SKILL.md +0 -0
  64. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/skills/dtk-setup-project/SKILL.md +0 -0
  65. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/assets/claude/skills/dtk-tune/SKILL.md +0 -0
  66. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/commands/__init__.py +0 -0
  67. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/commands/autotune.py +0 -0
  68. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/commands/clean.py +0 -0
  69. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/commands/init.py +0 -0
  70. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/commands/init_claude.py +0 -0
  71. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/commands/mcp.py +0 -0
  72. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/commands/osi.py +0 -0
  73. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/commands/run.py +0 -0
  74. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/commands/test_alert.py +0 -0
  75. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/commands/tune.py +0 -0
  76. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/commands/ui.py +0 -0
  77. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/commands/unlock.py +0 -0
  78. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/cli/main.py +0 -0
  79. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/config/__init__.py +0 -0
  80. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/config/metric_io.py +0 -0
  81. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/config/profile.py +0 -0
  82. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/config/project_config.py +0 -0
  83. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/config/validator.py +0 -0
  84. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/core/__init__.py +0 -0
  85. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/core/interval.py +0 -0
  86. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/core/models.py +0 -0
  87. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/__init__.py +0 -0
  88. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/_sql_manager.py +0 -0
  89. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/bigquery_manager.py +0 -0
  90. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/clickhouse_manager.py +0 -0
  91. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/duckdb_manager.py +0 -0
  92. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/internal_tables/__init__.py +0 -0
  93. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/internal_tables/_alert_states.py +0 -0
  94. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/internal_tables/_autotune_runs.py +0 -0
  95. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/internal_tables/_base.py +0 -0
  96. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/internal_tables/_datapoints.py +0 -0
  97. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/internal_tables/_detections.py +0 -0
  98. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/internal_tables/_maintenance.py +0 -0
  99. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/internal_tables/_metrics.py +0 -0
  100. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/internal_tables/_schema.py +0 -0
  101. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/internal_tables/_tasks.py +0 -0
  102. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/internal_tables/manager.py +0 -0
  103. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/manager.py +0 -0
  104. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/mysql_manager.py +0 -0
  105. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/postgres_manager.py +0 -0
  106. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/snowflake_manager.py +0 -0
  107. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/source_manager.py +0 -0
  108. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/database/tables.py +0 -0
  109. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/detectors/__init__.py +0 -0
  110. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/detectors/base.py +0 -0
  111. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/detectors/factory.py +0 -0
  112. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/detectors/seasonality.py +0 -0
  113. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/detectors/statistical/__init__.py +0 -0
  114. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/detectors/statistical/_windowed.py +0 -0
  115. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/detectors/statistical/autoreg.py +0 -0
  116. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/detectors/statistical/iqr.py +0 -0
  117. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/detectors/statistical/mad.py +0 -0
  118. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/detectors/statistical/manual_bounds.py +0 -0
  119. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/detectors/statistical/zscore.py +0 -0
  120. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/loaders/__init__.py +0 -0
  121. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/loaders/errors.py +0 -0
  122. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/loaders/metric_loader.py +0 -0
  123. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/loaders/query_template.py +0 -0
  124. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/mcp/__init__.py +0 -0
  125. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/mcp/context.py +0 -0
  126. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/mcp/errors.py +0 -0
  127. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/mcp/serialize.py +0 -0
  128. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/mcp/server.py +0 -0
  129. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/mcp/tools.py +0 -0
  130. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/orchestration/__init__.py +0 -0
  131. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/orchestration/error_dispatch.py +0 -0
  132. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/orchestration/task_manager/__init__.py +0 -0
  133. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/orchestration/task_manager/_base.py +0 -0
  134. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/orchestration/task_manager/_detect_step.py +0 -0
  135. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/orchestration/task_manager/_load_step.py +0 -0
  136. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/orchestration/task_manager/_types.py +0 -0
  137. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/orchestration/task_manager/manager.py +0 -0
  138. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/reporting/__init__.py +0 -0
  139. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/reporting/assets/report.js +0 -0
  140. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/reporting/builder.py +0 -0
  141. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/reporting/html_report.py +0 -0
  142. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/semantic/__init__.py +0 -0
  143. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/semantic/errors.py +0 -0
  144. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/semantic/exporter.py +0 -0
  145. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/semantic/importer.py +0 -0
  146. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/semantic/osi_model.py +0 -0
  147. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/semantic/query_gen.py +0 -0
  148. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/tuning/__init__.py +0 -0
  149. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/tuning/assets/tune.js +0 -0
  150. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/tuning/config_writer.py +0 -0
  151. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/tuning/html.py +0 -0
  152. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/tuning/payload.py +0 -0
  153. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/tuning/server.py +0 -0
  154. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/ui/__init__.py +0 -0
  155. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/ui/html.py +0 -0
  156. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/ui/jobs.py +0 -0
  157. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/ui/metric_files.py +0 -0
  158. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/ui/overview.py +0 -0
  159. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/ui/server.py +0 -0
  160. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/utils/__init__.py +0 -0
  161. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/utils/datetime_utils.py +0 -0
  162. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/utils/env_interpolation.py +0 -0
  163. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/utils/json_utils.py +0 -0
  164. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit/utils/stats.py +0 -0
  165. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit.egg-info/SOURCES.txt +0 -0
  166. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit.egg-info/dependency_links.txt +0 -0
  167. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit.egg-info/entry_points.txt +0 -0
  168. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit.egg-info/requires.txt +0 -0
  169. {detectkit-0.66.5 → detectkit-0.67.1}/detectkit.egg-info/top_level.txt +0 -0
  170. {detectkit-0.66.5 → detectkit-0.67.1}/pyproject.toml +0 -0
  171. {detectkit-0.66.5 → detectkit-0.67.1}/requirements.txt +0 -0
  172. {detectkit-0.66.5 → detectkit-0.67.1}/setup.cfg +0 -0
  173. {detectkit-0.66.5 → detectkit-0.67.1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: detectkit
3
- Version: 0.66.5
3
+ Version: 0.67.1
4
4
  Summary: Metric monitoring with automatic anomaly detection
5
5
  Author: detectkit team
6
6
  License: MIT
@@ -4,7 +4,7 @@ detectk - Anomaly Detection for Time-Series Metrics
4
4
  A Python library for data analysts and engineers to monitor metrics with automatic anomaly detection.
5
5
  """
6
6
 
7
- __version__ = "0.66.5"
7
+ __version__ = "0.67.1"
8
8
 
9
9
  from detectkit.core.interval import Interval
10
10
  from detectkit.core.models import ColumnDefinition, TableModel
@@ -177,28 +177,48 @@ class _RecoveryMixin(_OrchestratorBase):
177
177
  # ``detections`` is oldest→newest, so the latest point lives at [-1].
178
178
  latest = detections[-1]
179
179
 
180
- # Prefer the latest CI so the message reflects the *current* interval.
181
- # Fall back to the last anomalous point only if the latest row has no
182
- # CI (e.g. missing-data / insufficient-data placeholders).
183
- recovery_ci_lower = latest.confidence_lower
184
- recovery_ci_upper = latest.confidence_upper
185
- recovery_detector_name = latest.detector_name
186
- recovery_detector_params = latest.detector_params
187
-
188
- if recovery_ci_lower is None or recovery_ci_upper is None:
189
- last_anomalous = next((d for d in reversed(detections) if d.is_anomaly), None)
190
- if last_anomalous:
191
- recovery_detector_name = last_anomalous.detector_name
192
- recovery_detector_params = last_anomalous.detector_params
193
- recovery_ci_lower = last_anomalous.confidence_lower
194
- recovery_ci_upper = last_anomalous.confidence_upper
195
-
196
180
  # Reconstruct the just-ended incident so the recovery message can say how
197
- # long it lasted (symmetric with the anomaly alert's onset/duration).
198
- incident_count, onset_ts, capped = self._resolve_incident(
181
+ # long it lasted (symmetric with the anomaly alert's onset/duration) and
182
+ # WHICH detector fired it.
183
+ incident_count, onset_ts, capped, firing = self._resolve_incident(
199
184
  latest.timestamp, records=incident_records
200
185
  )
201
186
 
187
+ # Render the band of the detector that actually fired. Using ``latest``
188
+ # verbatim picked whichever detector_id sorted last at the latest
189
+ # timestamp (``get_recent_detections`` orders by detector_id), so a
190
+ # multi-detector metric could clear with a band belonging to a detector
191
+ # that had nothing to do with the alert — e.g. a manual_bounds floor's
192
+ # ">= 30.00" where the MAD band that fired was "[249.34, 418.61]".
193
+ source = self._recovery_source(detections, firing)
194
+
195
+ recovery_ci_lower = source.confidence_lower
196
+ recovery_ci_upper = source.confidence_upper
197
+ recovery_detector_name = source.detector_name
198
+ recovery_detector_params = source.detector_params
199
+
200
+ if recovery_ci_lower is None and recovery_ci_upper is None:
201
+ # The chosen row carries no band at all (missing-data /
202
+ # insufficient-data placeholder): prefer the same detector's most
203
+ # recent banded row, then the last anomalous row of any detector.
204
+ # A ONE-SIDED band (manual_bounds with only ``lower_bound``) is not
205
+ # "no band" — ``expected_range`` renders it as ">= lo" — so it must
206
+ # not trip this fallback and inherit another detector's numbers.
207
+ fallback = next(
208
+ (
209
+ d
210
+ for d in reversed(detections)
211
+ if d.detector_id == source.detector_id
212
+ and (d.confidence_lower is not None or d.confidence_upper is not None)
213
+ ),
214
+ None,
215
+ ) or next((d for d in reversed(detections) if d.is_anomaly), None)
216
+ if fallback is not None:
217
+ recovery_detector_name = fallback.detector_name
218
+ recovery_detector_params = fallback.detector_params
219
+ recovery_ci_lower = fallback.confidence_lower
220
+ recovery_ci_upper = fallback.confidence_upper
221
+
202
222
  return AlertData(
203
223
  metric_name=self.metric_name,
204
224
  timestamp=latest.timestamp,
@@ -237,16 +257,52 @@ class _RecoveryMixin(_OrchestratorBase):
237
257
  loading_delay_seconds=self.loading_delay_seconds or None,
238
258
  )
239
259
 
260
+ @staticmethod
261
+ def _recovery_source(
262
+ detections: list[DetectionRecord],
263
+ firing: DetectionRecord | None,
264
+ ) -> DetectionRecord:
265
+ """Pick the record whose band/name/params the recovery message renders.
266
+
267
+ Resolves a target DETECTOR first, then renders that detector's freshest
268
+ row — so the message reads "the detector that fired is back inside its
269
+ band" with the band of the *current* interval:
270
+
271
+ 1. target = the incident's firing detector; with no incident to walk
272
+ (direct-API caller with no DB) = the newest anomalous record in the
273
+ window, which is the best available proxy for "what fired";
274
+ 2. render that detector's row at the latest (now-clean) point, else its
275
+ most recent row in the window, else the target row itself (a
276
+ retuned/removed detector id that no longer scores);
277
+ 3. ``detections[-1]`` verbatim when there is nothing to anchor on —
278
+ which is also what a single-detector metric resolves to, so those
279
+ render exactly as before.
280
+ """
281
+ latest = detections[-1]
282
+ target = firing or next((d for d in reversed(detections) if d.is_anomaly), None)
283
+ if target is None:
284
+ return latest
285
+ same = [d for d in detections if d.detector_id == target.detector_id]
286
+ if not same:
287
+ return target
288
+ at_latest = next((d for d in same if d.timestamp == latest.timestamp), None)
289
+ return at_latest if at_latest is not None else same[-1]
290
+
240
291
  def _resolve_incident(
241
292
  self, cleared_ts: Any, records: list[DetectionRecord] | None = None
242
- ) -> tuple[int, Any, bool]:
293
+ ) -> tuple[int, Any, bool, DetectionRecord | None]:
243
294
  """Find the anomalous run that just ended before the recovery point.
244
295
 
245
296
  Walks back from *cleared_ts* (the latest, now-clean point): skips the
246
297
  clean tail, then counts the contiguous direction-aware quorum run using
247
298
  the same logic that fired the alert. Returns ``(length, onset_timestamp,
248
- capped)`` — ``(0, None, False)`` when no run can be reconstructed, so the
249
- recovery message just omits the incident duration.
299
+ capped, firing_record)`` — ``(0, None, False, None)`` when no run can be
300
+ reconstructed, so the recovery message just omits the incident duration.
301
+
302
+ ``firing_record`` is the primary (highest-severity, deterministically
303
+ tie-broken) record of the quorum at the incident's LAST point — the
304
+ detector that was driving the alert when it cleared — so the recovery
305
+ message can name it instead of an unrelated detector.
250
306
  """
251
307
  step = np.timedelta64(self.interval.seconds, "s")
252
308
  # ``records`` lets a pure caller (alert replay) supply the in-memory
@@ -254,7 +310,7 @@ class _RecoveryMixin(_OrchestratorBase):
254
310
  # incident is resolved from ``_dtk_detections`` as before.
255
311
  if records is None:
256
312
  if not self.internal:
257
- return 0, None, False
313
+ return 0, None, False, None
258
314
  if isinstance(cleared_ts, np.datetime64):
259
315
  last_point = cleared_ts.astype("datetime64[ms]").astype(datetime)
260
316
  else:
@@ -266,7 +322,7 @@ class _RecoveryMixin(_OrchestratorBase):
266
322
  )
267
323
  records = hydrate_detection_records(rows)
268
324
  if not records:
269
- return 0, None, False
325
+ return 0, None, False, None
270
326
 
271
327
  by_time = self._group_by_timestamp(records)
272
328
  timestamps_sorted = sorted(by_time.keys(), reverse=True)
@@ -276,6 +332,7 @@ class _RecoveryMixin(_OrchestratorBase):
276
332
  count = 0
277
333
  onset: Any = None
278
334
  prev: np.datetime64 | None = None
335
+ firing: DetectionRecord | None = None
279
336
  for ts in timestamps_sorted:
280
337
  anomalies = [d for d in by_time[ts] if d.is_anomaly]
281
338
  # ``_quorum_at`` lives in _DecisionMixin; both mixins compose into
@@ -289,6 +346,11 @@ class _RecoveryMixin(_OrchestratorBase):
289
346
  started = True
290
347
  if self.conditions.direction == "same":
291
348
  locked = direction
349
+ # The incident's last point — its primary record is the detector
350
+ # that was driving the alert when it cleared. ``_primary_record``
351
+ # lives in _DecisionMixin; both mixins compose into
352
+ # AlertOrchestrator so the call resolves at runtime.
353
+ firing = self._primary_record(quorum)
292
354
  count = 1
293
355
  onset = ts
294
356
  prev = ts
@@ -302,6 +364,6 @@ class _RecoveryMixin(_OrchestratorBase):
302
364
  prev = ts
303
365
 
304
366
  if count == 0:
305
- return 0, None, False
367
+ return 0, None, False, None
306
368
  capped = count >= STREAK_LOOKBACK_POINTS
307
- return count, onset, capped
369
+ return count, onset, capped, firing
@@ -157,6 +157,11 @@ does not block recovery (the original condition no longer holds). Independent of
157
157
  `alert_cooldown` (recovery always sends once per incident). Default body is
158
158
  alert-centric (`🟢 Alert cleared: <metric>`).
159
159
 
160
+ On a **multi-detector** metric the recovery message reports the detector that
161
+ actually fired the incident — its name, params and `Expected` range at the
162
+ recovered point — so a metric pairing a MAD band with a `manual_bounds` floor
163
+ clears with the same detector's numbers it fired with.
164
+
160
165
  ## No-data alerts
161
166
 
162
167
  ```yaml
@@ -182,6 +187,10 @@ suppress_until: "2026-04-11 18:00:00" # UTC; default null
182
187
 
183
188
  Load and detect keep running; only alerting is paused until that time, then it
184
189
  auto-resumes (no second edit needed). For permanent off, use `enabled: false`.
190
+ Accepts `"YYYY-MM-DD HH:MM:SS"`, `"YYYY-MM-DD HH:MM"`, the ISO `T` form, or a
191
+ bare `"YYYY-MM-DD"` (midnight UTC) — validated when the config loads, so a
192
+ typo is refused up front instead of failing the metric at alert time. Also a
193
+ field in the `dtk ui` Builder's alerting section.
185
194
 
186
195
  ## Mentions
187
196
 
@@ -258,10 +258,13 @@ exactly as if typed into a terminal.
258
258
 
259
259
  The cockpit header has a **New metric** button, and every metric row an
260
260
  **Edit** action; both open an editor overlay with **two tabs sharing one
261
- draft**: **Builder** — a structured form over the whole config (basics,
261
+ draft**: **Builder** — a structured form over the whole config (basics —
262
+ including both `profile` and the hybrid-mode `source_profile` as pickers —,
262
263
  schedule/loading, seasonality, minimal detector rows with type + 1-2 key
263
264
  params — fine-tuning belongs in `dtk tune` —, alerting with a channel
264
- multi-select seeded from `profiles.yml` channel names, `ai_context`; SQL in
265
+ multi-select seeded from `profiles.yml` channel names, plus `suppress_until`
266
+ and (under Advanced) `timezone` / `links` / `cooldown_reset_on_recovery`,
267
+ `ai_context`; SQL in
265
268
  a syntax-highlighted pane, `query_file` paths read-only; a **From OSI**
266
269
  sub-tab compiles a pasted OSI semantic-model metric through the same code
267
270
  path as `dtk osi import`) — and **YAML**, the raw text, kept for whole-config
@@ -270,8 +273,9 @@ validates server-side first and blocks the switch on error; leaving an
270
273
  edited Builder re-emits the YAML. A debounced live-validation chip re-checks
271
274
  the draft while typing — showing the Builder's friendly checks while the
272
275
  YAML tab still mirrors the form, and a one-line `field — reason` summary of
273
- server errors otherwise. Keys the form doesn't model (`autotune:`, custom
274
- templates, unknown detector types/params, a multi-entry alerting list)
276
+ server errors otherwise. Keys the form doesn't model (`autotune:`, `tables:`,
277
+ custom `template_*` bodies, unknown detector types/params, a multi-entry
278
+ alerting list)
275
279
  round-trip verbatim, listed under "Preserved fields". Create writes
276
280
  `metrics/[<folder>/]<name>.yml`; after a create, a **next-steps strip**
277
281
  offers **Load & detect** (`dtk run --steps load,detect` for just that metric
@@ -125,6 +125,33 @@ class QueryColumnsConfig(BaseModel):
125
125
  )
126
126
 
127
127
 
128
+ #: Accepted ``suppress_until`` spellings. The date-only form means midnight UTC —
129
+ #: it is what the docs' own examples use, so it must not be a runtime crash.
130
+ _SUPPRESS_UNTIL_FORMATS = ("%Y-%m-%d %H:%M:%S", "%Y-%m-%dT%H:%M:%S", "%Y-%m-%d %H:%M", "%Y-%m-%d")
131
+
132
+
133
+ def parse_suppress_until(value: str) -> datetime:
134
+ """Parse an ``alerting.suppress_until`` value into a naive UTC datetime.
135
+
136
+ The single seam shared by :class:`AlertConfig`'s validator (fail at config
137
+ load / at a UI save) and the alert step (decide whether to skip).
138
+
139
+ :param value: The configured deadline string.
140
+ :return: The deadline as a naive UTC datetime.
141
+ :raises ValueError: If the value matches none of the accepted formats.
142
+ """
143
+ text = value.strip()
144
+ for fmt in _SUPPRESS_UNTIL_FORMATS:
145
+ try:
146
+ return datetime.strptime(text, fmt)
147
+ except ValueError:
148
+ continue
149
+ raise ValueError(
150
+ f"suppress_until must be a UTC datetime like '2026-04-11 18:00:00' "
151
+ f"or a date like '2026-04-11' (got {value!r})"
152
+ )
153
+
154
+
128
155
  class AlertConfig(BaseModel):
129
156
  """
130
157
  Alert configuration for a metric.
@@ -232,6 +259,20 @@ class AlertConfig(BaseModel):
232
259
  "dashboard_url (e.g. {'Runbook': 'https://...', 'Grafana': 'https://...'}).",
233
260
  )
234
261
 
262
+ @field_validator("suppress_until")
263
+ @classmethod
264
+ def validate_suppress_until(cls, v: str | None) -> str | None:
265
+ """The suppression deadline must parse, at config load, into a UTC datetime.
266
+
267
+ It used to be an unvalidated string that the alert step parsed with a strict
268
+ ``strptime`` — so a typo (or the date-only form the docs themselves showed)
269
+ raised mid-run and failed the metric instead of being caught at load/save.
270
+ """
271
+ if v is None:
272
+ return v
273
+ parse_suppress_until(v)
274
+ return v
275
+
235
276
  @field_validator("consecutive_anomalies")
236
277
  @classmethod
237
278
  def validate_consecutive(cls, v: int) -> int:
@@ -2,12 +2,10 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from datetime import datetime
6
-
7
5
  import click
8
6
 
9
7
  from detectkit.alerting.orchestrator import AlertConditions, AlertOrchestrator
10
- from detectkit.config.metric_config import MetricConfig
8
+ from detectkit.config.metric_config import MetricConfig, parse_suppress_until
11
9
  from detectkit.orchestration.task_manager._base import _TaskManagerBase
12
10
  from detectkit.orchestration.task_manager._types import make_alert_config_id
13
11
  from detectkit.utils.datetime_utils import now_utc_naive
@@ -48,7 +46,7 @@ class _AlertStepMixin(_TaskManagerBase):
48
46
  )
49
47
 
50
48
  if alerting_config.suppress_until:
51
- suppress_dt = datetime.strptime(alerting_config.suppress_until, "%Y-%m-%d %H:%M:%S")
49
+ suppress_dt = parse_suppress_until(alerting_config.suppress_until)
52
50
  if now_utc_naive() < suppress_dt:
53
51
  click.echo(
54
52
  f" │ Alerts suppressed until " f"{alerting_config.suppress_until} UTC"