计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
snowflake-cost-leak-hunter【效率与协作】Audit and analyze Snowflake warehouse, serverless, Adaptive, storage, transfer, and AI cost evidence with a typed ledger that prevents double counting and exposes freshness, attribution, control, and invoice boundaries. Use when a Snowflake bill increased, a team needs chargeback/showback evidence, credits appear unexplained, or an operator asks whic…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: snowflake-cost-leak-hunter description: >- Audit and analyze Snowflake warehouse, serverless, Adaptive, storage, transfer, and AI cost evidence with a typed ledger that prevents double counting and exposes freshness, attribution, control, and invoice boundaries. Use when a Snowflake bill increased, a team needs chargeback/showback evidence, credits appear unexplained, or an operator asks which usage merits investigation. Trigger with "Snowflake bill increased", "find idle Snowflake credits", "Snowflake cost attribution", or "untagged Snowflake spend". Do not use to mutate cost controls or claim savings. allowed-tools: Read, Write, Bash(python3:*) argument-hint: "[evidence-json-or-output-directory]" model: inherit effort: high version: 3.16.0 license: MIT author: Jeremy Longshore jeremy@intentsolutions.io tags:
Produce a read-only, evidence-first Snowflake cost investigation. The deterministic
analyzer emits a typed ledger whose total, attribution, context, estimate, and
invoice-only roles cannot silently collapse into one savings claim.
Problem: Cost views answer different questions, arrive at different times, and do not equal invoice truth. Generic advice easily turns observed credits into unsupported prices or promised savings.
Outcome: A reproducible review packet that identifies what the supplied evidence confirms, what was estimated from an approved rate, what remains at risk, and what is unknown.
SNOWFLAKE.ACCOUNT_USAGE surfaces.Write only to create
new local evidence/report files; never use it to alter Snowflake configuration.ACCOUNTADMIN. Use a role already authorized to read the needed
SNOWFLAKE.ACCOUNT_USAGE views. Visibility differs by database role and account
configuration; report missing access rather than escalating privileges.execution_context.observed_at, never
the later CLI completion timestamp. A quiet source with no recent activity is not
thereby stale.estimated until reconciled to the billing statement.Read references/attribution-and-staleness.md before collecting evidence. Read references/warehouse-and-idle-evidence.md for the bounded SQL surfaces. If controls are requested, read references/controls-boundaries.md, but return a review packet only. For Adaptive, storage, transfer, AI, surface-denominator, and typed-ledger rules, read references/cost-ledger-and-surfaces.md.
For a live, model-neutral collection, use the shared read-only collector with an existing Snowflake CLI profile:
python3 "${CLAUDE_SKILL_DIR}/scripts/collect_snowflake_evidence.py" \
--surface cost --connection <approved-readonly-profile> \
--window-start <YYYY-MM-DDTHH:MM:SSZ> \
--window-end <YYYY-MM-DDTHH:MM:SSZ> \
--output /tmp/snowflake-cost-collector.json
Map the baseline receipt's warehouse, query, load, and generic metering datasets into
the analyzer schema. The legacy input key serverless_usage means generic
METERING_HISTORY; public labels use metering:<SERVICE_TYPE>. Preserve every receipt
field and reject out-of-window rows, cap uncertainty, missing integrity fields, and
unscoped fingerprints. A self-checksum proves local consistency, not Snowflake origin.
Collect needed supplemental cost-* surfaces with the same bounded collector and put
each complete receipt under supplemental_receipts.<surface_inventory_name>. Follow
the surface contract for the exact dataset
keys, hashes, latency cutoffs, privacy rules, and unavailable-surface behavior.
Capture:
[window_start, window_end);If the user supplies only an invoice total, state that the audit can explain usage but cannot reconcile the invoice without the corresponding usage statement and contract rates.
Have the operator run the smallest read probes with the approved connection and provide the sanitized results. This skill does not expose the Snowflake CLI namespace. A representative probe is:
SELECT MAX(end_time) AS max_end_time
FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY
WHERE start_time >= :window_start
AND start_time < :window_end;
Probe QUERY_ATTRIBUTION_HISTORY separately because its availability, latency, and
coverage differ. If either probe fails, preserve the exact sanitized error, name the
missing surface, and stop that branch. Do not propose granting broad imported
privileges automatically.
Use the queries and field definitions in
references/warehouse-and-idle-evidence.md.
Export only the normalized fields accepted by
scripts/analyze_cost_evidence.py; exclude raw SQL text and credentials.
The input accepts baseline warehouse/query/load/metering arrays; supplemental Adaptive, storage, transfer, AI, monitor, and budget evidence; optional invoice rows; and user-supplied credit rates. Read the surface contract for the exact keys and overlap rules. Inventory assertions without matching receipts block completeness.
Record each source's maximum activity timestamp only as descriptive context; it does not prove freshness, and an absent source is not zero usage. Apply the reference's identity-disclosure contract. Never export raw users, tags, query text, notification addresses, contract numbers, credentials, or connection values.
Print the canonical bundle digest in a trusted local terminal and record it separately from the bundle. Never trust a digest copied from inside the evidence itself:
python3 "${CLAUDE_SKILL_DIR}/scripts/analyze_cost_evidence.py" \
--input cost-evidence.json --print-input-sha256
Then pass that separately recorded value back to the analyzer. Live receipts older than one hour are rejected as stale transport evidence; recollect rather than relaxing the bound.
python3 "${CLAUDE_SKILL_DIR}/scripts/analyze_cost_evidence.py" \
--input cost-evidence.json \
--trusted-input-sha256 <recorded-sha256:hex-digest> \
--json-out cost-analysis.json \
--markdown-out cost-analysis.md
The script validates non-negative numeric evidence, sums with decimal arithmetic, and
keeps total, attribution, context, estimate, and invoice-only ledger roles
separate. Their additive and overlap rules are defined in the surface contract.
It does not apply magnitude thresholds, infer a price, or recommend a warehouse size.
Daily average storage snapshots must remain per day or use an explicitly labeled
average/byte-day calculation; summing multiple daily snapshots and labeling the result
bytes is invalid.
When query fingerprints have both attributed credits and elapsed time, it also emits
a non-dominance cost/latency Pareto view. A Pareto point is a comparison aid, not a
proof that a workload should move warehouses. Right-sizing is only a bounded review
proposal when the operator supplies the current size, explicit candidate sizes,
maximum size steps, measurement window, success criteria, and approver; never infer a
target size from credits or queue time.
For each ranked opportunity, record:
Examples of competing explanations include intentionally warm warehouses, SLA-driven capacity, untagged shared-service queries, or usage outside the attribution view's coverage. Do not label those cases waste without workload-owner confirmation.
Follow references/output-contract.md. Lead with the window and coverage, not a sensational savings number. A valid packet contains:
review required;Return cost-analysis.json and cost-analysis.md in the user's chosen working
directory, plus the exact analyzer command used. The JSON is the machine-readable
receipt; Markdown is the human review packet. Both must contain the analysis window,
source freshness, confirmed observations, estimated amounts, at-risk opportunities,
warnings, and non-claims. Do not write runtime output into the skill directory.
Stop and return a bounded partial result when:
| Condition | Meaning | Required response |
|---|---|---|
| Approved role cannot read a required view | Coverage unavailable | Preserve the sanitized error, name the missing surface, and stop that branch without changing grants. |
| Requested end exceeds the fixed source-specific settled cutoff | Recent evidence may be incomplete | Return a partial result; do not enlarge the cutoff from a caller-supplied latency or maximum activity timestamp. |
| Attributed-query credits are NULL | Idle/unattributed calculation is unsupported for that row | Emit COST_ADAPTIVE_ATTRIBUTION_GAP; exclude the row from that calculation and do not substitute zero. |
| Generic AI or warehouse total and detailed attribution both exist | The evidence can overlap by design | Retain one additive total and attach AI Functions detail only beneath an account/window-aligned AI_SERVICES row from METERING_HISTORY; do not assert equality because that parent also covers Cortex Analyst. Otherwise keep the relationship unknown. |
| Storage or transfer evidence has bytes but no contract billing model | Operational context is present without price evidence | Keep bytes as context; do not infer currency or invoice amounts. |
| No applicable contract rate | Currency cannot be defended | Report credits only; do not substitute a public price. |
| Analyzer rejects evidence | Malformed timestamp, negative/non-finite number, or incompatible shape | Correct the input from source evidence; never coerce it into a plausible value. |
| User requests mutation | New authority and impact review are required | Return a proposed change packet and stop before execution. |
Collect the two warehouse surfaces over the same UTC window. The analyzer may report
42.5 confirmed warehouse compute credits and 11.2 credits at risk for idle-time review. It must not call all 11.2 credits waste or convert them to dollars without a
supplied rate.
Aggregate QUERY_ATTRIBUTION_HISTORY by the existing tag. Report tagged and untagged
credits, the view's maximum timestamp, and exclusions such as idle, serverless, storage,
and cloud-services cost. Missing tags are an at-risk attribution gap, not proof of
unowned spend.
Do not create or alter a monitor. Audit current warehouse evidence, explain the warehouse-only coverage and suspension caveats from references/controls-boundaries.md, and return a reviewable control proposal requiring explicit authorization.
scripts/analyze_cost_evidence.py — deterministic
validator, classifier, and renderer.