Backpressure Drop Degrade Policyのロゴ

Backpressure Drop Degrade Policy

コミュニティ
HimanshuJ16
backpressure-drop-degrade-policy

有界ティックバッファが長時間にわたって容量上限に達し、キューライブラリのブロッキングという既定動作に任せず、ストリームごとに破棄、サンプリング、縮退のポリシーを選ぶ必要がある場合に使用します。一時的な急増についてはtick-buffering-burst-handlingを参照してください。

Add to TypingMind

概要

公開者HimanshuJ16
リポジトリAlgo-Trading-Skills
スキル名backpressure-drop-degrade-policy
スター
50
フォーク
7
同梱ファイル
5
ライセンスApache-2.0
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 5個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    HimanshuJ16がGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Backpressure Drop Degrade Policy」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/backpressure-drop-degrade-policy
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

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/backpressure-drop-degrade-policy .claude/skills/backpressure-drop-degrade-policy
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでBackpressure Drop Degrade Policyを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にBackpressure Drop Degrade Policyを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Backpressure Drop Degrade Policyは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

When to Use

Invoke this once tick-buffering-burst-handling has established bounded buffers — this skill defines what happens when a buffer is persistently at capacity, i.e., sustained backpressure rather than a momentary burst. Every real-time trading system eventually falls behind producers; the difference between a robust system and a fragile one is whether that moment is handled by a deliberate, chosen policy or by whatever the underlying queue/library happens to do by default (often "block the producer" — the worst outcome, since it propagates the slowdown back to the WebSocket read loop).

When NOT to Use

  • For momentary bursts. A short spike that a bounded buffer absorbs is a buffering problem, not a policy problem — see tick-buffering-burst-handling.
  • When the consumer is merely slow-to-start. Fix the consumer or scale it out before deciding what to throw away; a drop policy applied to a fixable bottleneck permanently degrades data quality to paper over a solvable issue.
  • As a substitute for capacity planning. If a stream is always at its watermark, the policy is masking undersized infrastructure — see capacity-planning-for-symbol-universe-growth.
  • For order/execution acknowledgements. Those are not a droppable telemetry stream; reconciliation, not sampling, is the correct response to falling behind.

Prerequisites

  • Bounded buffers already in place (see tick-buffering-burst-handling)
  • A per-data-type criticality classification: which data can be dropped, sampled, or degraded, and which cannot

The Caller's Contract

handle_full() returns a BackpressureDecision. Check decision.accepted.

A NEVER_DROP stream at capacity returns accepted=False with the item in decision.rejected_item — the manager cannot store it for you and will not pretend it did. Treating that return as "handled" silently discards risk-critical data, which is precisely the failure this skill exists to prevent. Wire on_never_drop_overflow to your emergency path, or set strict_never_drop=True to raise.

Workflow

  1. Classify each data stream by what backpressure response is acceptable:
    • Drop-oldest: for streams where only the latest state matters (e.g., latest LTP for a position-monitoring display) — safe to discard stale ticks in favor of the newest.
    • Sample/throttle: for streams feeding non-critical downstream consumers (e.g., a dashboard chart) — admit 1 of every N items under load, leaving the existing backlog intact. Throttling admission is not the same as flushing the buffer: discarding half the queue on every overflow destroys far more data than the load actually requires.
    • Degrade to lower-resolution data: for streams that can fall back to a coarser representation (e.g., tick-level to 1-second OHLC) under sustained load.
    • Never drop: for streams tied directly to risk decisions (e.g., position/margin updates feeding the kill-switch). If they cannot keep up, that is a system health emergency requiring an alert and an explicit rejection the caller must handle — not a quiet policy application.
  2. Declare every stream's policy explicitly. An undeclared stream raises UnknownStreamError by default rather than falling back to a drop policy — a mistyped risk-stream name must not silently become a data-loss path.
  3. Call observe() on every push, not just on overflow. handle_full() alone cannot warn you early, because by the time it runs the queue is already full — for a NEVER_DROP stream that is already too late.
  4. Never let a "never drop" stream share a queue/thread pool with a "safe to drop" stream — resource contention means the safe-to-drop stream's load can degrade the never-drop stream's latency. Isolate by criticality tier, mirroring the tier separation in multi-broker-rate-limit-handling.
  5. Emit an explicit alert (not just a log line) when any "never drop" stream approaches capacity. Pass a real out-of-band alert_fn; the default only writes a log warning.
  6. Record, per backpressure event, which policy fired and what was dropped/degraded/throttled, so post-session review can assess whether the chosen policies matched what actually happened.

Full step-by-step procedure with broker-specific detail: see references/workflows.md. Broker/framework coverage table for this skill: see references/standards.md. Printable pre-flight checklist: see assets/checklist.md.

Common Pitfalls

  • Ignoring the return value. If handle_full() returns "nothing to do" for both a successful drop-oldest and a rejected risk item, the caller cannot distinguish them and the risk item is lost. Check accepted.
  • A bounded deque is already an implicit policy. collections.deque(maxlen=N) silently discards from the opposite end when you append to a full deque — Python documents this. If you append directly, you have chosen drop-oldest by accident. Route pushes through the manager.
  • Compound queue operations are not atomic. deque guarantees individual appends and pops are thread-safe, but reading len(queue) and then popping that many times races with a concurrent consumer and raises IndexError: pop from an empty deque — crashing the producer thread, which is usually the WebSocket read loop. Guard every pop.
  • Defaulting an unknown stream. Applying a "safe to drop" policy to a risk-relevant stream, usually because position/margin updates were lumped in with general market data or a stream name was mistyped.
  • Flushing the backlog in the name of "sampling." Discarding a fixed fraction of the queue per overflow event is a different, far more destructive behavior than reducing update frequency.
  • Silent degradation with no alerting — a system that quietly downgrades from tick-level to OHLC-level processing may be technically "working" while producing materially different signals than the strategy was validated against, and nobody notices until live performance diverges from backtest.
  • Zero-filling missing tick fields. Substituting 0.0 for an absent price corrupts every OHLC bar built from it. Reject the tick instead.
  • Misleading telemetry. A drop rate computed against overflow events rather than total pushes reads near 100% under load and tells you nothing; a rate of 0.0 when nothing was observed reads as healthy when it means "no data".
  • Treating backpressure policy as a one-time decision rather than something to revisit as strategies and data volumes change.

Verification

  • Run python -m unittest discover -s skills/backpressure-drop-degrade-policy/scripts — 100% pass rate (38 tests).
  • Under sustained simulated overload (replay at multiples of peak historical tick rate), confirm risk-critical streams return accepted=False and trigger the defined alert rather than silently discarding.
  • Confirm an undeclared stream name raises UnknownStreamError instead of being assigned a drop policy.
  • Confirm the overflow path does not raise when a consumer drains the queue concurrently.
  • Confirm dashboard/non-critical streams throttle admission while leaving the existing backlog intact.
  • Confirm get_metrics_summary() reports drop rates against observed pushes, and None (not 0.0) when nothing was observed.

Related Skills

  • producer-consumer-tick-pipeline
  • tick-buffering-burst-handling
  • kill-switch-and-drawdown-circuit-breakers
  • graceful-degradation-priority-during-partial-outage
  • capacity-planning-for-symbol-universe-growth

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Backpressure Drop Degrade Policy」では何ができますか?

有界ティックバッファが長時間にわたって容量上限に達し、キューライブラリのブロッキングという既定動作に任せず、ストリームごとに破棄、サンプリング、縮退のポリシーを選ぶ必要がある場合に使用します。一時的な急増についてはtick-buffering-burst-handlingを参照してください。

TypingMindでBackpressure Drop Degrade Policyを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Backpressure Drop Degrade Policyはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにBackpressure Drop Degrade Policyをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/backpressure-drop-degrade-policyを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Backpressure Drop Degrade Policyを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Backpressure Drop Degrade Policyで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもBackpressure Drop Degrade Policyを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Backpressure Drop Degrade Policy」は無料ですか?

はい。HimanshuJ16がApache-2.0ライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇