Skip to content

feat: hold dbt run, build and show over the BigQuery scan limit until allowed - #24

Open
hkaltai wants to merge 18 commits into
mainfrom
feat/cost-gate
Open

hkaltai wants to merge 18 commits into
mainfrom
feat/cost-gate

Conversation

@hkaltai

@hkaltai hkaltai commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the cost gate. Before dbt run, dbt build or dbt show executes, the plugin calls dbt_cost_estimate. If the estimated BigQuery scan is over the limit, the command is held until the user allows it. An on-demand estimate command is also available.

This branch includes the shared foundation for the dbt Power User features (local branch feat/pu-mods-foundation). Those commits drop out of the diff once the foundation lands in main.

Merge order: the altimate-code PR (AltimateAI/altimate-code#1732) first, because this plugin calls the CLI tool it adds.

Test plan

  • hooks/features/cost.test.tsx covers the gate (held over the limit, allowed under it, and on-demand estimates)

Demo video (hosted)

P-05.mp4 — watch on Notion (Altimate workspace; recorded from the approved head of this PR).

🤖 Generated with Claude Code

hkaltai and others added 11 commits November 13, 2026 16:31
Each feature gets its own file under hooks/features/, called by name from
features/index.ts in a fixed order: its own hooks, the session and turn
events, its band line and its tool-call phases. One tool.call hook
(tool-chain.ts) runs Bash and file handling in fixed phases: bashRewrite,
bashGate, the call, bashAfter, editAfter, readOrEditAfter. The status line
is built from parts (status-line.ts). runTool moves to altimate-cli.ts with
a `write` option that goes through the CLI with --allow-write.
dbt-command.ts finds the dbt invocations in a shell command line. New
userConfig fields: maxScanBytes, healthBlocksPush, healthConfigPath,
commentsPollSeconds, commentsInContext.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… allowed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s built

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…commands that set their own target

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Subshells after keywords, case patterns, process substitution, arrays,
arithmetic and function definitions parse again; quotes in a heredoc inside
a substitution are text; a function or case pattern named dbt is not an
invocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and, skip more commands that change context

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… dbt calls before it

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@hkaltai

hkaltai commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Review-loop results (independent claude + codex reviews, then three fix-gate rounds)

Finding Reply
A compound command over the limit consumed /allow-scan without running (MAJOR) Fixed. The whole command is estimated, then the allowance is decided once and spent in one state update.
/allow-scan was a blanket allowance not tied to what the user saw (MAJOR) Fixed. It only applies when something is held, is set against the hold it read, and only the same command spends it. Another over-limit command is held anew and clears it.
--target, --vars, --project-dir, defer state, cd and similar were ignored (MAJOR) Fixed by an allow-list. A scanning call is estimated only with a plain launcher, nothing on the line before it but other dbt calls, and known-safe flags. The line must have no $ or backtick expansion and at most 20 dbt calls. Anything else runs as before with one "no estimate" line. This replaced regex deny-lists that kept missing shell forms.
Line continuation broke --inline SQL parsing (MAJOR) Fixed.
Concurrent calls could both spend one allowance (MAJOR) Fixed by taking the grant inside one state update. The engine retries it as a compare-and-set.
Rounded estimate compared against the limit (MAJOR) Fixed. The gate compares the tool's maxBytes upper bound.
Status line kept "held" after a hold cleared (MINOR) Fixed.
Context notes keyed by command could mix up or leak (MINOR) Reduced to one latest note per command, replaced on every gate pass and cleared on session start. Two concurrent identical commands may share or miss a note, which only affects a context line.
Up to N × 120 s blocking for N models (MINOR) Fixed with one shared deadline per command.
/allow-scan with a non-dbt command in between did not clear the hold (MODERATE) Not changed, on purpose. The hold lasts until it is allowed or a later dbt command is not held, as documented in CostState. A test pins it.
Broken header comment, stale comments (NIT) Fixed.
No dedupe of repeated estimates, unlike lineage.tsx (NIT) Not done. Two estimates of the same model cost one dry run each. Follow-up if it matters.

The allow-list rules from the last gate round, $ and backtick rejection and the invocation cap, got no fourth external re-gate. The review-loop cap of two re-runs was spent. They are covered by tests only.

Tests: claude plugin test ./plugins/altimate-code (232 pass), claude plugin validate --strict . passes, bash tests/*.sh all pass. claude plugin validate --strict ./plugins/altimate-code still reports 4 warnings, all type errors in hooks/lineage.test.tsx (the AbovePrompt props' isCollapsed). Those are in an untouched file and predate this change.

hkaltai and others added 4 commits November 13, 2026 21:21
…n linear time

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…t --inline, say what the scan limit covers

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…n limit covers

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@hkaltai

hkaltai commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Final review round (independent Codex and Claude reviewers, then a fresh attack-the-fix pass on the fixes). Findings and outcome:

  • Repeated --inline estimated from the first one (MAJOR): fixed. The last one is used, as dbt reads it, for both --inline x and --inline=x. Tests added.
  • Unestimated variant (+model, --full-refresh) cleared a hold (MAJOR): fixed. Only a command that was estimated under the limit ends a hold. Test added; the older test that relied on the old behaviour now uses an estimated command.
  • Whole-project runs are never held (MAJOR/documentation): they have no single target to dry run, so they stay unestimated by design. maxScanBytes text now says which commands are covered.
  • Stale comments on the hold's lifetime (MINOR): updated.
  • Daemon keeps running after the plugin's deadline (MAJOR): lives in the altimate-code daemon (shared foundation), not in this plugin; follow-up there.
  • Compound command where one part is estimated clears the hold (MINOR): left as the stated rule (any estimate under the limit ends a hold); noted.
  • Time budget equals adapter start timeout; unsupported verdict is sticky for a session; self-approving /allow-scan (comments, confidence ≤ 0.7): noted, not changed.

Verdict of the attack-the-fix pass on the fixes: APPROVE. 238 plugin tests pass.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@hkaltai
hkaltai marked this pull request as ready for review November 14, 2026 03:41
@hkaltai

hkaltai commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

review-loop: APPROVED at 185f903 (last fix: the value after --inline is the query, not another option; test added)

@kilo-code-bot

kilo-code-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/features/cost.tsx 171 The new up to … branch formats the upper bound but never compares it to the limit's formatted size, so an upper bound in the same 0.1-unit bucket as the limit still reads up to 10.0 GiB (≈ 10.0 GiB estimated) would be scanned, over the 10.0 GiB limit.
Files Reviewed (2 files)
  • plugins/altimate-code/hooks/features/cost.tsx - 1 issue
  • plugins/altimate-code/hooks/features/cost.test.tsx - no issues

Fix these issues in Kilo Cloud

Previous Review Summaries (2 snapshots, latest commit 582f9f8)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 582f9f8)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2
Issue Details (click to expand)

WARNING

File Line Issue
plugins/altimate-code/hooks/features/cost.tsx 133 Clearing held on an unsupported verdict leaves the scan held ≈ ... status part set for the rest of the session: the band clears, but setStatusPart is only reset by an under-limit estimate or at session start.

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/features/cost.tsx 167 The just over wording only fires when the rounded display happens to equal formatBytes(limitBytes); the display is the point estimate while the decision is on the upper bound, so a display rounded below the limit (or formatted differently by the tool) still yields a self-contradictory refusal.
plugins/altimate-code/hooks/features/cost.test.tsx 235 The new test uses the exact fixture of the test at line 217; fold the exact deny assertion into that test instead of keeping two identical setups.
Files Reviewed (3 files)
  • plugins/altimate-code/.claude-plugin/plugin.json - no issues
  • plugins/altimate-code/hooks/features/cost.tsx - 2 issues
  • plugins/altimate-code/hooks/features/cost.test.tsx - 1 issue

Fix these issues in Kilo Cloud

Previous review (commit 185f903)

Status: 5 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 5
Issue Details (click to expand)

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/features/cost.tsx 166 The refusal can show the rounded size equal to the limit ('~10.0 GiB would be scanned, over the 10.0 GiB limit'), because the check uses the unrounded upper bound.
plugins/altimate-code/hooks/features/cost.tsx 126 One 'no estimate' context line is pushed per dbt call, uncapped; the 4000-call test shows 4000 lines reaching Claude's context for one command.
plugins/altimate-code/hooks/features/cost.tsx 116 The unsupportedAdapter early return skips the hold-clearing block, so a hold recorded before that verdict stays set for the session and /allow-scan can never spend it.
plugins/altimate-code/hooks/features/cost.tsx 141 The estimate bookkeeping duplicates rememberEstimate (line 340); call it instead.
plugins/altimate-code/.claude-plugin/plugin.json 28 maxScanBytes help says a run after 'another command' is not estimated, but a run after another dbt call is estimated (dbt deps && dbt run -s orders).
Files Reviewed (21 files)
  • plugins/altimate-code/.claude-plugin/plugin.json - 1 issue
  • plugins/altimate-code/hooks/altimate-cli.ts - no issues
  • plugins/altimate-code/hooks/dbt-command.ts - no issues
  • plugins/altimate-code/hooks/dbt-command.test.ts - no issues
  • plugins/altimate-code/hooks/features/index.ts - no issues
  • plugins/altimate-code/hooks/features/cost.tsx - 4 issues
  • plugins/altimate-code/hooks/features/cost.test.tsx - no issues
  • plugins/altimate-code/hooks/features/comments.tsx - no issues
  • plugins/altimate-code/hooks/features/cte-profile.tsx - no issues
  • plugins/altimate-code/hooks/features/defer.tsx - no issues
  • plugins/altimate-code/hooks/features/docs.tsx - no issues
  • plugins/altimate-code/hooks/features/health.tsx - no issues
  • plugins/altimate-code/hooks/features/runs.tsx - no issues
  • plugins/altimate-code/hooks/features/sql-graph.tsx - no issues
  • plugins/altimate-code/hooks/features/to-model.tsx - no issues
  • plugins/altimate-code/hooks/integrations.tsx - no issues
  • plugins/altimate-code/hooks/lineage.tsx - no issues
  • plugins/altimate-code/hooks/status-line.ts - no issues
  • plugins/altimate-code/hooks/tool-chain.ts - no issues
  • plugins/altimate-code/hooks/tool-chain.test.ts - no issues
  • plugins/altimate-code/types/index.d.ts - no issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash-1017 · Input: 52.1K · Output: 12.9K · Cached: 373.5K

…r command, and word a just-over scan as over

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… of a scan whose estimate is under the limit

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
// as not over the limit when the scan is just past it.
const scanned =
worst.point <= limitBytes
? `up to ${formatBytes(worst.bytes)} (≈ ${worst.display} estimated)`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: The new up to … branch can still print the limit twice.

formatBytes(worst.bytes) is never compared to the limit, so when the upper bound and the limit format into the same 0.1-unit bucket the refusal reads as not over the limit again. With limitBytes = 10 * GIB, point = 10 * GIB and maxBytes = 10 * GIB + 30 * 1024 ** 2, formatBytes(worst.bytes) is 10.0 GiB, so the deny becomes up to 10.0 GiB (≈ 10.0 GiB estimated) would be scanned, over the 10.0 GiB limit. Guard this branch the way the next one guards the display, e.g. fall back to the point display (or just over) when formatBytes(worst.bytes) === formatBytes(limitBytes).

@hkaltai

hkaltai commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

review-loop: APPROVED at 7cc430a

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.

1 participant