Repository navigation
Guard against SELECT * on wide datasets; count size-rule catches in replay - #31
Open
nickklos10 wants to merge 1 commit into
Open
nickklos10 wants to merge 1 commit into
nickklos10 wants to merge 1 commit into
Conversation
…eplay The doctor on real Foundry history showed 29 results too large for the context window. All lacked a row cap, but 26 used SELECT * on wide datasets, so a 200-row cap alone would not have shrunk most of them. The guard now denies SELECT * (or t.*) read straight from a cached dataset wider than --max-star-columns (default 20, 0 turns it off) and lists the dataset's columns so the agent names only what it needs. When both size rules fail, one reply covers both. The doctor's replay line counted only schema-check catches, so it read "would stop 0 failures" even when the row cap would have stopped every oversized result. It now counts row-cap and SELECT * catches too, and reports how many successful queries those rules would send back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
In the doctor's report on real Foundry history (85 queries), 29 results were too large for the agent's context window. None had a row cap, but 26 used
SELECT *on wide datasets. Size scales with row count, so even capped at 200 rows about 18 of them would still have overflowed.Changes
SELECT *. The guard deniesSELECT *ort.*read directly from a cached dataset that has more than--max-star-columnscolumns. The default is 20, and0turns the rule off. The reply lists the dataset's columns and asks the agent to name only the ones it needs. Uncached datasets are not judged, since their width is unknown.COUNT(*), named columns and a star over a narrowing subquery are all allowed. Unlike a column denial, which may come from a stale schema, a resend of the same query is denied again.--max-rowsboth fail, the agent gets a single reply covering both, so it can fix the query in one retry.--guardhooks pick up the rule with no reinstall, because the flag defaults to 20.trace doctor's line used to read "would stop 0 failures" even when the row cap would have stopped every oversized result. It now counts catches by the schema check and by the size rules separately, and it reports how many successful queries the size rules would have sent back for a LIMIT or named columns. The Markdown report and the JSON output carry the same numbers.On the real log, the doctor now reports:
would stop 29 failures (0 by schema, 29 by row cap or SELECT *) … 14 successes sent back for a LIMIT or named columns. The star rule fires on 18 of the 29.Verification
ruff check src tests(0.17.1): passes.pytest: 922 passed, 28 skipped. This includes 7 new tests covering the star rule, the combined reply, the hook default and how to disable it, and the replay counts.benchmarks/validate_golds.py: OK.🤖 Generated with Claude Code