Skip to content

Guard against SELECT * on wide datasets; count size-rule catches in replay - #31

Open
nickklos10 wants to merge 1 commit into
mainfrom
feat/guard-wide-select-star
Open

nickklos10 wants to merge 1 commit into
mainfrom
feat/guard-wide-select-star

Conversation

@nickklos10

Copy link
Copy Markdown
Owner

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

  • Guard rule for wide SELECT *. The guard denies SELECT * or t.* read directly from a cached dataset that has more than --max-star-columns columns. The default is 20, and 0 turns 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.
  • One reply for both size rules. When the star rule and --max-rows both fail, the agent gets a single reply covering both, so it can fix the query in one retry.
  • Rule on by default. Existing --guard hooks pick up the rule with no reinstall, because the flag defaults to 20.
  • Accurate replay summary. 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

…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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants