Repository navigation
loom code describe stops at --limit and --max-usd and prints what it spent - #1807
Merged
Merged
Conversation
…at it spent `--limit N` bounded nothing a run had already queued: the stop flag was read once at the top of each file and chunk coroutine, before it waited on its semaphore, and every coroutine had started before the first description landed. Over 3 files of 10 pending chunks, `--limit 5 --concurrency 8` made 30 provider calls. The command also printed no usage: provider clients report to a cost accumulator that the command never bound. A description is now admitted after it holds its concurrency slot, and the count of calls started moves with the check, so at most N calls start. Each description runs under its own accumulator and the run sums them into its last line: chunks described, already described and remaining, input, output and embedding tokens, and dollars from the price table, or the unpriced model's name. `--max-usd` reserves the dearest description so far for each call in flight and for the next one, runs the first description alone to learn that cost, and refuses a description model without a price. A stopped run still reads every selected file, as every run did before, to count what is left. The CLI help snapshot is regenerated under Python 3.12: `--limit` has new help text and `--max-usd` is added. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2891b08. Configure here.
…ne reports a cost The cap reserves the cost of the dearest description so far for each call in flight. That cost is 0 until a description reports usage, and the serial wait ended at the first settle whether or not it reported any: after a first call that failed, every waiting call was admitted against a reservation of 0. With concurrency 8 and a cap of 2.5 descriptions' price, 9 calls were made and 8 paid for. The wait now holds while a call is in flight and no description has a cost, so the same run makes 3 calls and pays for 2. Also: - the operator page states the overshoot as one difference for each dearer call in flight, and that an embedding provider reporting no usage makes the dollars a lower bound; - an unlisted embedding model of a provider that reports usage is refused before the first call, not after one paid description; - `--limit` and `--max-usd` refuse values below 0; - `settle` takes the accumulator by its type. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
loom code describe --limit stops at its limit and prints what it spentloom code describe stops at --limit and --max-usd and prints what it spent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Related: #1679
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
loom code describe --limit Nnow starts at most N description calls, and the command ends with one line that counts the chunks described, already described and remaining, the tokens used and their price. A new--max-usdflag stops the run before a call that would take its spend past a dollar cap. Both flags refuse a value below 0.Why
An operator who built the description layer for a set of repositories could not cap the run and saw no figure for what it cost. Three things were checked in the source:
--limitbounded nothing that the run had already queued. The stop flag was read once, at the top of each file and chunk coroutine, before the coroutine waited on its semaphore.asyncio.gatherstarts every coroutine before the first description lands, so all of them were past the check when the flag was set. With 3 files of 10 pending chunks,--limit 5 --concurrency 8made 30 provider calls.describe complete: N chunksand nothing about usage. The provider clients report tokens and dollars to a cost accumulator, and the command never bound one, so the figures were dropped.context_sourceisllm. This was already true; the change adds a test for it.The fix admits a description after it holds its concurrency slot. The count of calls started moves in the same step as the check, with no
awaitbetween them, so concurrent chunks cannot pass the bound together. The limit counts calls started, not descriptions stored: a call whose reply is dropped still spent tokens.Each description runs under its own accumulator (
cost_accumulator.isolated_op), and the run sums them. The last line reads, for example:Dollars come from the server's price table and cover the description calls and the re-embedding. When a model that reported usage has no price, the line names it and gives tokens only. The Gemini and OpenAI-compatible embedders report no usage, so with them the line prints
0 embedding tokensand the dollars are a lower bound; the operator page says so.--max-usd Dreserves the cost of the dearest description so far for each call in flight and for the next one, and stops when the spend plus those reservations would pass D. That reservation is 0 until a description reports a cost, so descriptions run one at a time until one does: a first call that fails or reports no usage leaves the run serial instead of admitting every waiting call against a reservation of 0. A stricter bound from list prices was considered and left out: for a model with hidden reasoning the worst case of one call is the reply cap plus the full reasoning reserve, many times what a description costs, so the run would stop long before the cap. The cost of that choice is stated in the docs: a call that costs more than every description before it can take the run past D by that difference, once for each such call in flight.The flag exits 2 before any call when the price table lacks the description model, or lacks the embedding model and its provider reports usage (OpenAI, Bedrock). For an embedding provider that reports no usage the cap covers the description calls only. A run still stops once any call reports usage on a model without a price.
Scope and risk
loom code describeonly:server/cli/code_maintenance.pyand its parser inserver/cli/code.py. The ingest pass and the description prompt are unchanged.cli.code.describespan gainscurrent,remaining,input_tokens,output_tokensandcost_usdcounters.Compatibility, rollout and rollback
--max-usdadded (default 0, no cap);--limitkeeps its name and default and now holds. Both refuse a value below 0, which--limitaccepted before (a negative limit bounded nothing).Tests
Run locally on Python 3.12 with
LOOM_ENV_FILE=set empty:tests/unit/test_code_describe_bounds.pyandtests/unit/test_code_description_provider_guard.py, loaded and run withunittest: 20 tests pass. The 12 new tests use a provider double that counts its calls and reports usage the way a provider client does: the limit holds across file boundaries with 8 calls in flight, a dropped reply still counts toward the limit, the summary equals the provider's counted tokens and their table price,--max-usdstops before the call that would pass it, it stays serial after a first call that fails, its overshoot with 3 dearer calls in flight is within 3 differences, it refuses an unpriced description model and an unpriced embedding model of a usage-reporting provider, it stops on usage reported by an unpriced model of another provider, an unpriced model prints tokens only, a rerun describes nothing, a rerun after a limit describes only the rest, and the parser refuses--limit -1and--max-usd -1.test_max_usd_stays_serial_until_a_description_has_a_costfailed before the fix it covers with(9, 8) != (3, 1)(calls, most in flight).test_loom_code_describe_leaves_a_marked_chunk_alone(tests/unit/test_code_embed_exclude.py), called from a snippet: passes.tests/unit/test_cli_surface_snapshot.py, called from a snippet withLOOM_UPDATE_CLI_SNAPSHOT=1, regenerated the CLI snapshots; a second call without it passes.ruff format --check,ruff check, the function-length gate, the secret gate and every generator--checkthatmake lintruns pass on the head.server/llm/vertex_auth.py, from an untypedgoogle.authin the local environment; none in a changed file.tests/unit/test_public_copy.py, called from a snippet: pass.Not run locally: the full unit suite, the integration suite, the Biome lint. Nothing was run against a real ClickHouse or a real provider.
Measurement, with an in-memory index of 3 files of 10 pending chunks, concurrency 8, and a provider double that reports 1000 input and 50 output tokens per call. One description and its re-embedding cost $0.0012 at the doubles' prices. "Before" is
mainfor the first row and the first pushed head of this pull request for the rows about the cap:--limit 5describe complete: 30 chunks--max-usdat 2.5 descriptions' price--max-usdat 4.5 descriptions' price, later calls cost $0.0032--max-usdwith an unlisted embedding model that reports usage--limit -1main, 0 calls andstopped at --limit -1on the first pushed headargument --limit: must be 0 or more0 described, 30 current, 0 remainingAI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. Checked by running the before and after measurement above, the focused tests and the gates listed under Tests.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/cli.mdand the CLI snapshots.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code
Note
Low Risk
Scope is the optional
loom code describeoperator path only; no API or ingest changes, though operators should expect a new completion line format.Overview
loom code describenow honors--limitand adds--max-usd, and finishes with a one-line spend summary instead of only a chunk count.The concurrency bug is fixed: description work is admitted after taking the semaphore, with limit and dollar checks and the “started” counter done in one step (no
awaitbetween check and increment), so parallel chunk tasks cannot blow past--limitthe way the old earlystopflag allowed.Each description runs under
cost_accumulator.isolated_op(); a new_DescribeRuntracks described vs already-described vs remaining chunks, LLM and embedding tokens, and priced USD (or token-only when a model has no table entry).--max-usdrefuses unpriced models up front (exit 2), reserves spend from the costliest call seen so far for in-flight work, and can serialize the first capped calls until a real cost is known.CLI parsing gains
_count/_dollarsvalidators; docs and CLI snapshots document the new flag and summary format. Unit tests cover limits, caps, unpriced models, and resume behavior.Reviewed by Cursor Bugbot for commit a232dd9. Bugbot is set up for automated code reviews on this repo. Configure here.