Automated Rollback Triggers On Anomaly Detection 标志

Automated Rollback Triggers On Anomaly Detection

社区
HimanshuJ16
automated-rollback-triggers-on-anomaly-detection

交易算法部署后立即使用,监控部署后的运行状况指标,并在出现部署缺陷时自动回滚,同时防止状态反复切换和回滚循环。不适用于策略表现不佳的情况。

Add to TypingMind

概览

发布者HimanshuJ16
代码仓库Algo-Trading-Skills
技能名称automated-rollback-triggers-on-anomaly-detection
星标数
50
复刻数
7
附带文件
5
许可协议Apache-2.0
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 5 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 HimanshuJ16 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Automated Rollback Triggers On Anomaly Detection AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/automated-rollback-triggers-on-anomaly-detection
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HimanshuJ16/Algo-Trading-Skills.git /tmp/Algo-Trading-Skills
mkdir -p .claude/skills
cp -r /tmp/Algo-Trading-Skills/skills/automated-rollback-triggers-on-anomaly-detection .claude/skills/automated-rollback-triggers-on-anomaly-detection
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Automated Rollback Triggers On Anomaly Detection,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Automated Rollback Triggers On Anomaly Detection。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Automated Rollback Triggers On Anomaly Detection 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

When to Use

Use this skill within your CI/CD pipeline immediately following a deployment of a trading algorithm (e.g., during a Canary Release or Blue/Green deployment). In algorithmic trading, milliseconds of malfunction can cause catastrophic financial damage.

This self-healing engine continuously monitors post-deployment telemetry (technical metrics like latency/errors and trading metrics like order reject rates) and, if a metric breaches its safety threshold for a confirmed number of consecutive samples, fires an automated rollback trigger that minimizes Mean Time to Recovery (MTTR).

When NOT to Use

Do not wire automated rollback as the primary control loop for market-data alerts or strategy underperformance — those are human/postmortem signals, not deployment-defect signals. Automated rollback is appropriate only when a deployment temporally correlates with the anomaly onset (a deployment-correlated rollback gate). For non-deployment anomalies (e.g. a venue-wide outage), rollback cannot help and may itself cause harm by reverting to a version that lacks the current degradation handling.

Prerequisites

  • Python 3.10+
  • A telemetry aggregator (e.g., Prometheus, Datadog) capable of supplying real-time DeploymentHealthMetrics per deployment version.
  • Integration with a CI/CD controller (e.g., Kubernetes, ArgoCD, GitHub Actions, Jenkins) to execute the rollback script when should_rollback == True.
  • A "last known good" version retained in a standby/draining state (Blue/Green) so rollback is a traffic reroute, not a re-provision.
  • Pre-deployed, objective rollback thresholds agreed before the deployment begins — never improvised mid-deploy.
  • A poller that fails loudly. A metric the backend did not return, a scrape that timed out, or a non-finite value must abort the health gate and escalate — never be substituted with the last good sample or a zero.

Workflow

  1. Configure (pre-deploy): Define the RollbackThresholdConfig — per-metric thresholds plus the safety policy: consecutive_failures_required (default 2), rollback_cooldown_seconds (default 300), and max_rollbacks_per_deployment (default 1). Call engine.reset() at the start of each new deployment.
  2. Deploy: The new algorithm version v2.1 is deployed; the previous version v2.0 is kept warm in standby.
  3. Monitor: The AutomatedRollbackEngine receives a DeploymentHealthMetrics snapshot each poll interval (e.g. every 5–10s) during a defined burn-in window (typically the first 5–15 minutes post-deploy). Build every snapshot from a fresh, complete scrape: DeploymentHealthMetrics rejects NaN/Inf at construction, and a scrape that returns no series must be handled by the poller as an evaluation failure, not passed on as a healthy sample.
  4. Detect: For each snapshot, the engine compares metrics against the thresholds and records any breach as a structured Anomaly with a severity (order_reject_rate and http_5xx are CRITICAL; latency_ms is WARNING).
  5. Confirm (flapping guard): A breach only advances a consecutive-failure streak. A rollback is recommended only once the streak reaches consecutive_failures_required — a single transient spike does NOT roll back a healthy deployment.
  6. Decide: The engine returns a RollbackDecision:
    • HEALTHY — no breaches; streak resets.
    • CONFIRMING — breach detected but not yet confirmed.
    • ROLLBACK — confirmed; the CI/CD controller reverts to v2.0.
    • SUPPRESSED — breach detected but action withheld (see Decision Points).
  7. Act: On ROLLBACK, the CI/CD controller reroutes traffic to the previous version. The engine records the rollback, starts the cooldown, and clears the streak. Breaches seen during the cooldown are detected and logged but do not advance the streak — samples taken while traffic is still rerouting say nothing about the version under test, so the next automatic rollback must earn a fresh confirmation streak once the cooldown expires.
  8. Escalate: If the per-deployment rollback cap is reached and anomalies persist, the engine suppresses further automatic action and escalates to a human on-call (the rollback may be masking a deeper defect, or the anomaly is a real signal).

Full procedure: see references/workflows.md. Standards reference: see references/standards.md. Printable pre-flight checklist: see assets/checklist.md.

Decision Points

  • Market-open / fast-market window: set DeploymentHealthMetrics.market_open_volatility = True for samples that overlap a known volatile window. The engine detects and logs the anomaly but suppresses rollback and does not advance the confirmation streak — the anomaly may be a genuine market event rather than a deployment defect.
  • Confirmation first, then the cap, then the cooldown: the confirmation streak is evaluated before either loop guard, in every mode, so a single transient spike is never rolled back or escalated. Once an anomaly is confirmed, the cap decides whether it becomes a rollback or a page — at the default max_rollbacks_per_deployment = 1 the confirmed breach after the one allowed rollback escalates immediately (CRITICAL log) instead of waiting out the cooldown, because an early page beats a quiet cooldown. The cooldown binds only while rollback budget remains. Both guards return SUPPRESSED; read rollbacks_issued and remaining_cooldown_s on the result to tell them apart.
  • Detection-only mode: set max_rollbacks_per_deployment = 0 to run the engine as a detector that never auto-rolls back (manual-approval mode for high-risk namespaces). Confirmation still applies — the first breach returns CONFIRMING and only a confirmed anomaly escalates, so a transient spike does not page the on-call engineer.
  • Threshold vs. baseline comparison: the reference engine uses absolute threshold comparison (the THRESHOLD strategy). For tighter false-positive control on noisy strategies, adopt the PREVIOUS or CANARY_BASELINE strategies described in references/standards.md.

Common Pitfalls

  • Ignoring Trading Metrics: Monitoring only CPU and Memory while failing to monitor financial metrics like runaway order rates or exchange reject rates.
  • Rolling Back on a Single Transient Spike (Flapping): Triggering an irreversible rollback from one bad sample. A single latency spike during market-open volatility is not a deployment defect. Always require consecutive confirmation (consecutive_failures_required >= 2).
  • Rollback Loops: rollback → redeploy → still flagged → rollback, cascading until the system thrashes itself. Enforce a cooldown and a hard per-deployment rollback cap; escalate to a human once the cap is hit.
  • The Anomaly Is a Real Signal: a genuine market move (fast market, venue outage) can spike rejects and latency across both versions. Rolling back cannot fix a market event and may revert to a version that handles the current regime worse. Suppress during market-open volatility and confirm temporal correlation with the deployment.
  • Rollback Itself Causes Harm: reverting mid-flight can drop in-flight order state, desync caches, or break forward/backward-compatible schema assumptions. Ensure message/cache formats and schema migrations are rollback-safe before relying on automated rollback.
  • Flaky Thresholds: thresholds set too tight relative to normal market-open volatility, causing false-positive rollbacks. Calibrate thresholds against historical drawdowns and the prior version's baseline.
  • Trusting a Frozen Feed: the gate can only judge the samples it is handed. A poller that repeats the last good sample when a scrape fails, or that defaults a missing series to 0, holds the engine at HEALTHY for the entire burn-in window while a defective version keeps trading. Absence of a signal is not a healthy signal — treat a missing or stale sample as an evaluation failure and escalate.
  • NaN Defeats Every Comparison: under IEEE 754 every ordered comparison against NaN is false, so a NaN latency reads as within threshold and a NaN or Inf threshold silently disables that metric for the whole deployment. This is not hypothetical: Prometheus transfers NaN/Inf as quoted JSON strings, which float() parses happily, and a reject-rate ratio over a window with no orders is 0/0. The dataclasses reject non-finite values at construction; do not strip that guard to "keep the pipeline running".

Verification

  • Confirm the engine tracks both technical (latency, 5xx) AND trading (order reject rate) metrics, with severity classification.
  • Confirm that a single breach returns RollbackDecision.CONFIRMING, not ROLLBACK (flapping guard).
  • Confirm that consecutive_failures_required consecutive breaches return ROLLBACK, increment rollbacks_issued, and start the cooldown.
  • Confirm a second rollback within the cooldown returns SUPPRESSED.
  • Confirm that once max_rollbacks_per_deployment is reached, further confirmed breaches return SUPPRESSED (escalation).
  • Confirm market_open_volatility=True suppresses rollback and does not advance the streak.
  • Confirm breaches suppressed by an active cooldown do not advance the streak, so the first breach after the cooldown expires returns CONFIRMING, not ROLLBACK.
  • Confirm detection-only mode (max_rollbacks_per_deployment = 0) still confirms first: a single breach returns CONFIRMING, and only a confirmed anomaly escalates.
  • Confirm invalid config/metrics raise ValueError — negative latency, rates outside [0, 1], and any NaN/Inf threshold or observation.
  • Run python -m unittest discover -s skills/automated-rollback-triggers-on-anomaly-detection/scripts.

Related Skills

  • canary-releases-for-strategy-code-changes
  • blue-green-deployment-for-live-strategy-updates
  • model-versioning-and-rollback
  • data-quality-monitoring-dashboard

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Automated Rollback Triggers On Anomaly Detection AI 技能有什么作用?

交易算法部署后立即使用,监控部署后的运行状况指标,并在出现部署缺陷时自动回滚,同时防止状态反复切换和回滚循环。不适用于策略表现不佳的情况。

为什么在 TypingMind 中使用 Automated Rollback Triggers On Anomaly Detection?

因为您只需安装一次,就能搭配任何模型使用。Automated Rollback Triggers On Anomaly Detection 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Automated Rollback Triggers On Anomaly Detection?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/automated-rollback-triggers-on-anomaly-detection。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Automated Rollback Triggers On Anomaly Detection?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Automated Rollback Triggers On Anomaly Detection 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Automated Rollback Triggers On Anomaly Detection 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Automated Rollback Triggers On Anomaly Detection AI 技能免费吗?

是的。HimanshuJ16 已在 GitHub 上根据 Apache-2.0 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇