SkillSpector icon indicating copy to clipboard operation
SkillSpector copied to clipboard

[Feature] Bound the cost of an LLM scan: --max-llm-calls / --llm-token-budget, and --estimate before spending

Open Mark2Mac opened this issue 4 months ago • 2 comments

Summary

There is currently no way to bound what an LLM-backed scan will spend before starting it. skillspector scan --llm either completes or does not, and the cost is only knowable afterwards — if at all. I would like a cap that is enforced during the scan, plus a way to see the projected cost before committing to it.

Motivation

Unlike an API-key provider with a prepaid balance, the CLI providers (claude_cli, codex_cli, gemini_cli) draw on the user's personal subscription. There is no per-scan meter, no spending alert, and no natural stopping point — the cost surfaces later as consumed quota.

That asymmetry matters for how SkillSpector gets adopted. A scanner that might cost an unknown amount is one users run rarely and reluctantly; a scanner that can be told "spend at most N calls on this" is one they can wire into a pre-install gate or a timer.

Concretely: I disabled the LLM stage entirely in my automation, not because it lacked value — it caught a natural-language exfiltration skill that the static stage scored 0 findings on — but because I could not bound what an unattended run would cost. The static-only stage I fell back to is precisely the one blind to that attack class. A cap would have let me keep the layer that works.

Scan cost also scales with the unit, not with the user's intent: pointing --changed at a marketplace containing hundreds of skills is one command, and there is no signal beforehand that it is three orders of magnitude more expensive than the last one.

Proposed change

Two independent pieces; the first is the useful half if only one lands.

1. A hard cap, enforced mid-scan

--max-llm-calls N        stop issuing LLM calls after N
--llm-token-budget N     stop after N total tokens (needs #242)

Plus env equivalents (SKILLSPECTOR_MAX_LLM_CALLS, SKILLSPECTOR_LLM_TOKEN_BUDGET) so timers and CI can set them without rewriting the command.

2. A projection, before spending

--estimate               report planned LLM call count and exit without calling

Even a crude count — analyzer slots × eligible components — is enough to distinguish "4 calls" from "400" and is what makes the cap easy to choose.

Behaviour when the cap is hit

This is the part I would ask for care on, because there is a trap adjacent to it that this project already knows about.

A scan stopped by its budget must not be reportable as complete. #290 covers the analogous failure — a deep scan reporting SAFE when the provider was unavailable — and a budget cap creates a second, more frequent path to the same wrong conclusion: an unfinished scan that looks clean because the LLM stage never reached the risky component.

Suggested: mark the report explicitly, e.g. metadata.llm_budget_exhausted: true alongside the existing llm_available / llm_calls_attempted, and have the risk assessment refuse to assert a clean verdict on an unfinished scan. A non-zero exit code for "stopped early" would let CI distinguish it from "finished, nothing found".

Whether the cap should be per-scan or per-skill in recursive mode is a real design question I do not have a strong view on. Per-skill avoids one large skill starving the rest; per-scan is what a user's wallet actually cares about.

Related

  • #242 (expose token usage in JSON) is a prerequisite for the token-budget variant. The call-count cap does not depend on it and could ship first.
  • #290 (deep scan reports SAFE when provider unavailable) is the failure mode this must not reproduce.
  • #295 is a concrete case of cost being unbounded and invisible: 4 attempted LLM calls consumed 3h09m of CPU on my machine, and llm_calls_attempted: 4 in the report was accurate while saying nothing about what had actually been spent.

Mark2Mac avatar Jul 22 '26 10:07 Mark2Mac

I would like to take this issue

jayanth922 avatar Jul 23 '26 01:07 jayanth922

@jayanth922 sorry for the long silence — yes, please go ahead if you are still interested.

Still unimplemented as of main at 1b87593: there is no --max-llm-calls, --llm-token-budget or --estimate on scan, and nothing in src/skillspector/ counts calls against a ceiling.

One pointer that may save you time: _shared_limiter() in src/skillspector/llm_analyzer_base.py is now the single process-wide chokepoint every analyzer's LLM call passes through, across threads and event loops. A call counter and a hard stop belong there rather than in each analyzer, and that code already knows how to make callers wait. The part that needs design thought is what a scan should report when it stops early: a bounded scan that silently looks like a complete one would be worse than no bound at all, so it should land in the inspection ledger as a declared limitation, the way coverage limitations are recorded in inspection_ledger.py.

Happy to review a PR.

Mark2Mac avatar Aug 31 '26 09:08 Mark2Mac