本文へ移動
cccskills
無料GitHub で公開日本語紹介

fix-slow-queries

Paperclipの遅いPostgreSQLクエリを調査・修正し、ローカルで速度と結果の一致を検証して、テストを通したプルリクエストにまとめます。

原文原文の説明を見る

Diagnose and fix slow Paperclip PostgreSQL queries using Cloud and Neon evidence, local reproduction, performance and result comparisons, regression tests, and a PR with passing checks. Use for costly queries, repeated database work, or slow requests with a suspected database cause.

インストール方法を見る

こんなときに便利

  • DBが原因と思われる応答遅延の調査
  • 頻繁に実行されるクエリの負荷削減
  • 修正前後の速度と結果を比較したいとき
  • 検証済みの性能改善をレビューに出すとき

日本語での紹介

できること

Paperclipで遅いPostgreSQLクエリを見つけ、測定に基づく修正とプルリクエストの作成まで進めます。CloudとNeonの統計から負荷の大きい処理を絞り、呼び出し元や実行計画を調査します。実際のPostgreSQLと合成データで遅さを再現し、修正前後の速度だけでなく、返される値や順序、権限範囲が保たれるかも比較します。

こんなときに便利

データベースが原因と思われる応答遅延や、繰り返し実行されるクエリの負荷を調べたい開発者向けです。修正の根拠、再発防止テスト、最新コミットのチェック結果をそろえてレビューに出したい場合に適しています。

使い方の例

  • 「この遅いリクエストの原因がSQLにあるか調査して」
  • 「負荷の高いクエリを再現し、結果を変えずに改善してPRにまとめて」

注意点

対象環境の調査権限、ソースコード、ローカルで使うPostgreSQLが必要です。原則としてデータベースの構造変更を避け、必要な場合は大規模データで所要時間も測ります。マージ、デプロイ、本番データベースの変更は別途許可が必要です。ローカルでの高速化だけでは、本番の応答改善を確認した扱いにはなりません。

この紹介文は、公開されている SKILL.md をもとに AI(OpenAI Codex)が作成しました。正確な仕様は下の原文を確認してください。

含まれるファイル(4)

  • SKILL.md11.1 KB
  • agents/openai.yaml128 B
  • references/cloud-discovery.md6.7 KB
  • references/local-proof.md10.5 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Fix Slow Queries

Deliver a measured improvement with preserved behavior and a reviewable PR whose latest commit passes checks. A list of suspicious SQL or an unverified rewrite is an intermediate result. Respect a narrower request for diagnosis only.

1. Establish the target and finish line

  • Resolve the reported URL, environment, company/workspace, deployed revision, owning repository, and local checkout. Read its AGENTS.md and scoped rules. Paperclip and the private paperclip-cloud control plane have different rules.
  • Work in a dedicated branch/worktree. Reuse suitable existing work; keep the checkout running a live server out of branch switching and benchmark setup.
  • Select a bounded batch, usually the top two or three query families. Record deferred candidates so discovery does not turn into an unbounded rewrite.
  • The finish line is: reproducible baseline, faster treatment, output/behavior proof, relevant regression coverage, and green checks on each final PR head. A concrete access or infrastructure blocker must be reported as incomplete.

2. Find the actual database and rank the work

Read Cloud discovery when starting from a hosted workspace. Follow the chain from Paperclip Cloud fleet admin to the stack's Neon project, branch, endpoint, database, and runtime role. Record the corresponding application deployment and time window. Do not reuse IDs from a previous run.

Capture query text/fingerprint, calls, total execution time, mean time, rows, and available I/O, temporary-file, and lock-wait evidence. Rank both expensive individual calls and frequent work with high aggregate cost. Group variants by their actual caller; do not add unrelated query means into an endpoint latency.

Keep three claims separate:

ClaimEvidence needed
SQL is expensiveQuery statistics and a reproducible execution plan
The database path dominates a slow requestCorrelated SQL, connection wait, and application timings
More database capacity would helpResource/queue pressure in the same window and a capacity-specific experiment

Cumulative query statistics are not a recent-window trace. Capture reset times or two snapshots and calculate deltas. A large database-time total alone does not justify resizing Neon. Application CPU headroom also does not rule out a busy Node main thread.

3. Trace each candidate to its behavior

Use rg on distinctive SQL fragments, table names, JSON keys, and predicates. Trace the full path: route or scheduler → service → generated SQL → indexes. Record frequency, fan-out, page limits, redaction, authorization, and any second query the caller performs. Compare the deployed implementation with local code.

State a falsifiable cause and the contract the fix must preserve. Typical causes include casts on indexed columns, repeated detoasting of large JSON, broad candidate scans, unbounded result sets, duplicate reads, and unnecessary polling. Use plans and caller evidence to choose among them.

Inspect existing indexes and recent related fixes before adding another index. For advisory locks, identify the caller, key, transaction duration, and wait chain first. Preserve checkout, leases, ownership, recovery, and no-replay rules; removing a lock or polling loop is not a query optimization by itself.

4. Reproduce the baseline locally

Read Local proof before building or changing the benchmark. Use disposable real PostgreSQL and synthetic data with representative row counts, selectivity, and payload sizes. Record the PostgreSQL version and any difference from the hosted server.

Pin the pre-fix commit. Capture the complete SQL and parameters the real service generates, including projections, joins, ordering, limits, and relevant imported query helpers. Prove the baseline exhibits the suspected cost before editing. If it does not, improve the fixture or revise the hypothesis.

Save baseline results, timings, and EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON). Define the performance acceptance criterion for this fixture before measuring the treatment. Avoid a brittle universal millisecond threshold.

5. Implement and prove both kinds of green

Make the smallest change supported by the measurements. Author the fix on our branch from source and evidence. Related community reports can supply leads; respect any instruction to keep the implementation independent of their code.

Run baseline and treatment against equivalent fixtures under the same settings:

  • Performance: use warmups and repeated samples, report medians and spread, and examine plan/buffer changes. Alternate order or repeat in reverse order when caching could explain the gain. Report neutral or slower paths honestly.
  • Correctness: compare every returned SQL column and the externally visible behavior. Preserve ordering, duplicates, nulls, tenant scope, and redaction. A faster wrong result fails even when row counts match.

When intentionally bounding history, compare query speed at the same result limit separately from the contract change. Test default/max limits and older record access. Do not call truncated output equivalent to the former full list.

Reject or revise the change if either proof fails. Keep the reproducible harness with the source where repository conventions allow it; keep bulky evidence out of git. Exhaust viable query/caller changes and existing indexes before proposing an exceptional migration. Document the serious reason and why migration-free alternatives are insufficient. Do not add startup scripts, boot-time DDL, or recurring backfills to bypass the migration constraint.

If a migration remains necessary, follow the database migration rules and the production-size timing procedure in Local proof. Measure the complete migration, including index builds, backfills, and lock waits. First optimize a migration exceeding the roughly one-to-two-minute budget; if it cannot be brought within an acceptable duration, flag it for human review with the measured timings and alternatives before presenting it as deployable.

6. Verify the blast radius

Choose checks from the caller graph and affected contracts, not only the edited function. Relevant cases from this workflow include:

ChangeRegression evidence
UUID/JSON joinsCanonical, uppercase, malformed, missing and non-string IDs; native/legacy precedence; company scope
JSON projectionsScalar/array/object/null inputs, text conversion, all fields, redaction
History boundsService and route callers, UI/API defaults, older deep links, empty recent history, retry and navigation races
Ownership/recovery readsRetained processes, active leases, blocked replay, workspace failure, receipts and delivery
Polling/cachingIdle work reduction, committed-change wakes, missed events, restart/sleep recovery, fresh destructive checks

Use real database tests for SQL semantics. Exercise assembled services/routes and actual UI components when those are affected. Update query mocks when the builder shape changes; a broken mock is not evidence that runtime SQL is wrong.

Run focused checks first, then the owning repository's required pre-PR checks. For this repo, consult AGENTS.md for typecheck, full tests, build, and conditional map/token/migration gates. Capture command, commit, exit status, and log location. Do not call an interrupted suite a pass. Preserve its partial evidence and state what completed locally versus on the final commit in CI.

7. Create the PR and carry it through checks

Use prepare-paperclip-pr for public Paperclip changes, check-pr for feedback, and prcheckloop for checks. Follow the owning repository's workflow instead when the fix belongs in paperclip-cloud.

  • Use the full PR template. Include cause, contract, benchmark command, baseline revision, fixture, before/after timings, equality evidence, regression results, and remaining risks. Label synthetic local timings as local SQL measurements. For an exceptional migration, include its justification, production-size fixture, complete duration, blocking time, optimization attempts, and any human decision still needed. Query speedup does not establish acceptable migration cost.
  • Split independent fixes into independently reviewable PRs; disclose actual dependencies. Attach every created PR to the current chat/task where supported.
  • After each push, refresh the head SHA. Address actionable reviews and failures, rerun affected local proof, and wait for fresh review and all expected checks on that SHA. Follow this repo's Greptile 5/5/no-unresolved-findings requirement.
  • Distinguish code failures from runner shutdowns or external outages. Rerun a demonstrated transient failure once. Cancel obsolete runs only after verifying they belong to this work and an older head; never terminate unrelated jobs.
  • Do not finish with "CI pending." Continue the loop within its repair bounds, or report the exact blocker, check URL, attempts, and next action. An empty check list, an old review score, or a draft-only subset of checks is not green.

Thanking contributors and closing their PRs requires explicit authorization. When authorized, explain which report our verified PR covers, acknowledge any uncovered scope, and leave unrelated PRs open. This skill does not itself grant permission to comment, close, merge, deploy, resize, or mutate a hosted database.

Constraints

  • your solution should not require a migration script to be run unless there is a serious reason - in almost all cases a migration script is a non starter
  • similarly you should not add some new boot script - e.g. dont' work around migration scripts by running the migration on every boot
  • if you add migrations, you should also have a sense on the time it will take on a large paperclip instance with thousands of tasks. the best option is to test on a clone of a production-size database and time it. if you don't have that you should make one. migrations that take an unacceptably large time to run (e.g. more than 1 or 2 minutes) must be flagged - first try to optimize the migration and then flag for a human if that's impossible

8. Hand off the evidence

Report each PR URL and final head, measured gains and neutral paths, correctness comparison, completed local checks, latest-head CI/review status, and limitations. If working from a Paperclip issue, attach evidence/work products using the repository's artifact workflow. Keep private identifiers and tenant data out of public PRs. State whether anything was deployed.

If rollout is authorized, verify the deployed revision and compare a fresh, comparable query-statistics window and request timing. Until then, production latency improvement remains unverified even when local SQL is much faster.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

add-product-e2e-eval

無料日本語概要

Paperclipで実際のブラウザからサーバー、データベースまで通すE2E評価を追加・拡張し、操作結果や証拠を既存のレポートで確認できるようにするスキル。

  • 一連の利用操作の評価を追加したいとき
  • テスト用データと判定条件の更新
  • 評価レポートに画像や成果物を載せたいとき
paperclipai/paperclip10.2万2026年10月15日 更新

add-runner-eval

無料日本語概要

Paperclip Runnerの動作評価に、判定条件や実行対象、レポート用データを追加・拡張し、根拠と実行履歴を残して検証するスキル。

  • Runnerの動作評価を追加したいとき
  • 正常・不正な証拠で判定を検証
  • 実行対象リストと継続評価の更新
paperclipai/paperclip10.2万2026年10月15日 更新

agent-browser

無料日本語概要

実際のブラウザでWebページやアプリを操作し、表示や動作を検証します。画面の撮影、簡単なフォーム入力、エラーや通信の記録を通じて、不具合の再現と確認を支援します。

  • UI変更後の画面を確認したいとき
  • JavaScript描画の内容を読みたいとき
  • 画面の不具合とエラーを再現したいとき
paperclipai/paperclip10.2万2026年10月15日 更新

agentmail

無料日本語概要

Paperclipで割り当てられたAgentMailの受信箱を使い、メールに紐づく依頼の確認、新規送信、返信、配信状況の確認までを扱うスキルです。

  • 担当タスクに紐づくメールを確認したいとき
  • 割り当てられた受信箱から新規送信
  • 会話内の特定メッセージへの返信
paperclipai/paperclip10.2万2026年10月15日 更新

check-pr

無料日本語概要

GitHub・GitLab・Perforceの変更を対象に、レビュー指摘、CIの失敗、説明文の不足を確認し、対応事項の整理から依頼に応じた修正まで支援するスキル。

  • 変更を提出する前に点検したいとき
  • 失敗したチェックと修正事項の確認
  • 人とボットのレビュー指摘の整理
paperclipai/paperclip10.2万2026年10月15日 更新

company-creator

無料日本語概要

目的に合うAIエージェントの役割や指揮系統、仕事の受け渡しを整理し、新規の構想や既存リポジトリから仕様に沿った会社・チームのパッケージを作るスキル。

  • 構想からエージェント会社を作りたいとき
  • リポジトリをチーム構成にまとめたいとき
  • 役割分担と仕事の受け渡しの設計
paperclipai/paperclip10.2万2026年10月15日 更新

paperclipai のスキルをすべて見る

このスキルの問題を報告する