Repository navigation
feat: hold dbt run, build and show over the BigQuery scan limit until allowed - #24
Conversation
… 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>
…commands that set their own target Co-Authored-By: Claude Sonnet 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>
Review-loop results (independent claude + codex reviews, then three fix-gate rounds)
The allow-list rules from the last gate round, Tests: |
…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>
|
Final review round (independent Codex and Claude reviewers, then a fresh attack-the-fix pass on the fixes). Findings and outcome:
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>
|
review-loop: APPROVED at 185f903 (last fix: the value after |
Code Review SummaryStatus: 6 Issues Found | Recommendation: Address before merge Incremental review of Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (3 files)
Fix these issues in Kilo Cloud Previous Review Summaries (6 snapshots, latest commit 68dd49a)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 68dd49a)Status: 8 Issues Found | Recommendation: Address before merge Incremental review of Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (2 files)
Notes: no tests were run (read-only review mode). Reviewed against Previous review (commit 033826b)Status: 6 Issues Found | Recommendation: Address before merge Incremental review of Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (7 files)
Notes: no tests were run (read-only review mode). Carried items were re-verified against current code; the earlier Fix these issues in Kilo Cloud Previous review (commit 893781c)Status: 7 Issues Found | Recommendation: Address before merge Incremental review of Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (2 files)
Notes: no tests were run (read-only review mode); the changed tests' behaviour on the parent commit was traced by hand. Reviewed against Fix these issues in Kilo Cloud Previous review (commit 805787c)Status: 6 Issues Found | Recommendation: Address before merge Incremental review of Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (2 files)
Notes: no tests were run (read-only review mode); the new test's behaviour on the parent commit was traced by hand. Reviewed against Fix these issues in Kilo Cloud Previous review (commit 5e4731e)Status: 5 Issues Found | Recommendation: Address before merge Incremental review of Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (2 files)
Notes: no tests were run (read-only review mode); behaviour on the parent commit and the concurrency path in the new Fix these issues in Kilo Cloud Previous review (commit b1d39f9)Status: 11 Issues Found | Recommendation: Address before merge Incremental review of Overview
Issue Details (click to expand)SUGGESTION
[Snapshot truncated.] Additional previous summary content was truncated to keep this comment within platform limits. Reviewed by deepseek-v4.1-flash-1017 · Input: 86K · Output: 22.1K · Cached: 716K |
…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)` |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Fixed in 499c071: the "up to" wording is used only when the upper bound formats differently from the limit; otherwise the refusal reads "just over ". Regression test added with your numbers (10 GiB point, upper bound 10 GiB + 30 MiB).
|
review-loop: APPROVED at 7cc430a |
…ion to run in Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| * is given up on and the call runs. A gate that must hold the call therefore bounds its own check well inside | ||
| * this and returns `{ deny }` when the check runs out of time. | ||
| */ | ||
| export const PHASE_TIMEOUT_MS = 5_000 |
There was a problem hiding this comment.
WARNING: This deadline can silently skip the cost gate this PR adds.
installToolChain runs the whole gate phase under within($, PHASE_TIMEOUT_MS, work) (line 136), so a dbt run/build/show whose BigQuery estimate takes more than 5 s is passed through with no hold, and the timeout is only logged at debug level. The cost gate budgets ESTIMATE_BUDGET_MS = 120 s for exactly this case (cost.tsx:22-23, "The adapter may have to start (dbt deps, a parse) for the first estimate"), so the first estimate of a session can easily be cut off and the hold never happens.
bounded also does not stop the work it gives up on: when the estimate finishes later, bashGate keeps running and still calls update/setStatusPart (cost.tsx:144-166), so a held state and the scan held ≈ … part can be recorded for a command that already ran.
Bound the gate phase by the gate's own budget (or have the cost gate bound its check well inside 5 s and deny when it runs out, as the comment above asks), and ignore writes from a phase that timed out.
There was a problem hiding this comment.
Not changed. The premise does not hold: the gate does not run the estimate inside the 5 s phase. bashGate waits at most GATE_WAIT_MS (4 s) for it and, when it is not in, denies the command with "still being estimated … run the same command again" while the estimate carries on on its own 120 s budget and the retry uses its answer. So a slow first estimate refuses the command rather than letting it through. The late write of a held state after the answer arrives is intended: it is what the retry reads, and the hold is keyed to the command text that was refused, not to one that ran.
| expect(await featureBandLines($, {} as any)).toEqual([]) | ||
| expect(await featuresBashRewrite($, bash)).toBe('dbt run -s a') | ||
| expect(await featuresBashGate($, bash)).toBeNull() | ||
| expect(await featuresBashAfter($, bash, {} as any)).toEqual([]) |
There was a problem hiding this comment.
WARNING: This expectation cannot hold with the mocked CLI.
featuresBashGate runs the built cost feature: process.run answers exitCode: 1 with empty stdout (line 48), so estimate returns { kind: 'none', reason: 'altimate-code gave no estimate' } and the gate pushes cost · no estimate for a: … into notes before returning null (cost.tsx:126 and 193-197). featuresBashAfter then returns that line, so this gets one note instead of []. Drop the assertion, or expect the note.
There was a problem hiding this comment.
Not changed. The assertion passes as written: with that mock the gate's note is dropped when the command is refused or cleared, and featuresBashAfter returns [] (the test runs green in the suite). The premise that a note survives here does not hold for this path.
| /** | ||
| * The tool needs write permission (it starts the dbt adapter, or changes something): the call goes | ||
| * through the CLI with `--allow-write`, since the plugin's MCP server runs read-only. runTool asks | ||
| * nobody: a caller sets it only once the user has said yes to this write (README, "How it works", |
There was a problem hiding this comment.
SUGGESTION: This invariant does not hold for the caller that sets write.
cost.tsx:338 calls runTool($, 'dbt_cost_estimate', args, { write: true, until }) from the automatic gate and from /scan-cost, with no approval, and the estimate does start the adapter (cost.tsx:22). So "a caller sets it only once the user has said yes to this write" is false for the code in this PR. Either say that a read-only tool that only needs the adapter may pass --allow-write without asking, or have the gate ask before it estimates.
There was a problem hiding this comment.
Fixed in the next push: the write comment now says a caller sets it either after the user agreed to the write, or for a tool that only reads and needs the adapter started, as the cost gate's estimate does.
…hen it cannot re-estimate A gate that outlasts the tool chain's 5 s phase lets the command run unchecked. The gate now waits 4 s, refuses the command while an estimate is still running (the estimate carries on and the next try uses it), and a command held earlier stays held when its estimate cannot be made again. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… estimate's budget starts after the wait Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| } | ||
| const began = await $.clock.now() | ||
| // The wait is short (the user is looking at the screen); the estimate's own budget starts when the wait ends, at the latest. | ||
| const started = await startWhenIdle($, { model: target }, began + GATE_WAIT_MS, () => undefined, one => one) |
There was a problem hiding this comment.
SUGGESTION: The new give-up path is not covered by any test.
The point of this commit is that /scan-cost stops waiting after GATE_WAIT_MS instead of staying silent for ESTIMATE_BUDGET_MS, but nothing asserts it: the 'No estimate: another estimate is still running in this project' text (line 128) appears in no test, and both /scan-cost queue tests release the hold before the wait expires (cost.test.tsx:881 releases at 1.5 s, cost.test.tsx:898 at 0.5 s of a 4 s bound). With the fake clock one more test is cheap (hold another model's estimate, advance 4_001 ms, expect that text), and without it a return to the long budget would pass the suite silently.
There was a problem hiding this comment.
Fixed in 9029264: new test 'a /cd away and back does not forget the estimate still running in the project' holds one /scan-cost, advances 4_001 ms on the fake clock and expects the 'another estimate is still running in this project' text, so a return to the long budget fails the suite.
…t, so coming back does not start a second one Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| begin: (started: { answer: Promise<Answer>; settled: Promise<undefined> }) => T, | ||
| ): Promise<T | null> { | ||
| const dir = (await $.session.cwd().catch(() => seenDir)) ?? null | ||
| const running = () => [...active].filter(([, d]) => d === dir).map(([p]) => p) |
There was a problem hiding this comment.
SUGGESTION: Keying the queue on the exact cwd lets a second estimate start in the same dbt project.
active is now filtered by string equality with $.session.cwd() and the /cd branch no longer clears it. A cd into a subdirectory of the same dbt project (cd models), or another spelling of the same directory, changes the string, so running() is empty and the next dbt run starts a second dbt_cost_estimate while the first adapter process is still running in that project — exactly the collision the comment in estimateWithin (line 593) says this queue exists to prevent ("Each estimate may start the adapter (dbt deps), and two at once in one project collide"). If the second estimate then fails on that collision it returns kind: 'none', and the gate lets an over-limit scan run with only a "no estimate" note. The same string identity is conservative for invalidation (a subdirectory is treated as another project), but here it is permissive. Group by the project root ($.session.root(), which the plugin already reads) rather than cwd, or treat a recorded dir at or under the current one as the same project.
There was a problem hiding this comment.
Declined: the queue is keyed on the session directory on purpose, the same identity the gate uses to invalidate on a /cd (cost.tsx:196-204, seenDir). The engine exposes no project-root resolution for a subdirectory, and a cd into a subdirectory of the project is already treated as another project everywhere else in this feature, so this is a documented limitation of that contract rather than a defect to fix here. If both estimates collide, the second returns kind 'none' and the existing no-estimate path applies.
| const first = $.command.run({ command: 'scan-cost', args: 'orders' } as any) | ||
| await clock.advance(500) | ||
| // Another project is not held back by it. | ||
| options.cwd = '/elsewhere/project-b' |
There was a problem hiding this comment.
SUGGESTION: No gate pass happens in this test, so the active.clear() removal it is named after is not pinned.
The /cd handling being changed is gate's branch (cost.tsx:192-198), and only a Bash call reaches it; here the cwd changes between two /scan-cost commands, so gate never runs and putting active.clear() back inside that branch leaves this test green. (The other half does pin the new per-project filter — on the parent it blocks in the active wait.) Add one Bash pass while options.cwd is '/elsewhere/project-b', e.g. await $.tool.call(bash('ls')): with active.clear() restored, again would then start a third estimate and started would be ['orders', 'b', 'c'].
There was a problem hiding this comment.
Fixed in 5e4731e: the test now makes a Bash pass in the other project and then asks for an estimate back in the first project, which fails if active.clear() is restored in the /cd branch.
…ait, so it never starts beside that project's running one Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| expect(started).toEqual(['orders', 'b']) | ||
| release() | ||
| await inB | ||
| await queued |
There was a problem hiding this comment.
SUGGESTION: The half of the test name that says the queued estimate runs under the project now in use is not pinned.
After release() the test only awaits queued, and $.command.run resolves with a text either way, so an implementation that gives up for the queued caller on the /cd (startWhenIdle returning null, cost.tsx:128 reporting "another estimate is still running in this project") passes every assertion here unchanged: started stays ['orders', 'b'] at 1214 and await queued still resolves. Only the "must not start beside b" half fails on the parent commit.
Assert the outcome after the release, e.g. expect(started).toEqual(['orders', 'b', 'c']), or expect(((await queued) as any).text).toContain('c would scan 2.0 GiB'), so a regression that hands the user no estimate is caught too.
There was a problem hiding this comment.
Fixed in 5e4731e: the test now asserts the queued /scan-cost runs after the release (started is orders, b, c and the reply contains 'c would scan 2.0 GiB').
| ): Promise<T | null> { | ||
| // The project is read again after each wait: a /cd meanwhile moves the check to the project now in use. | ||
| let dir: string | null = null | ||
| let running: Promise<undefined>[] = [] |
There was a problem hiding this comment.
SUGGESTION: running (and the here copy at 384) do not need function scope.
running is assigned and read only inside one iteration, so hoisting it above the loop makes it read as state carried from one iteration to the next, which it is not. here only duplicates the let dir value (both are string | null, so filter(([, d]) => d === dir) compiles the same). Keep dir outside since it is used after the break at 390, and declare const running = [...active].filter(([, d]) => d === dir).map(([p]) => p) inside the loop.
There was a problem hiding this comment.
Fixed in 5e4731e: running is now declared inside the loop and the here copy is gone (startWhenIdle in cost.tsx).
saravmajestic
left a comment
There was a problem hiding this comment.
Re-approving. My earlier "fix before merging" note is resolved: startWhenIdle runs one estimate per project at a time (gate and /scan-cost alike), so two adapter starts (dbt deps) no longer overlap. The two latest commits track running estimates by project and re-read the project after each wait, so a /cd no longer starts a second estimate beside one still running there. Handling lowerBound, holding a command only when the floor is already over the limit, is right too, and so is voiding answers through the generation counter when the project changes mid-estimate.
Heads-up: 9cfa4e36 edits hooks/features/index.test.ts (the test engine and the "with every feature a stub" test), which #34 rewrites, and git merge-tree of the two conflicts in that file. The earlier head merged cleanly. Since #34 merges first, dropping these edits or resolving them onto #34's version should do it.
Also, as #34 notes, this PR's note on every dbt command breaks #27's exact-context assertions in runs.test.tsx when both are merged; that needs sorting in one of their test files before the second one lands.
…/cd while the gate waits refuses the command Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
review-loop: APPROVED at b1d39f9 (reviewers: gpt-6-astra high, gpt-6.1-sol high) |
| const label = target.model ?? 'the inline query' | ||
| const answer = await estimateWithin($, target.model ? { model: target.model } : { sql: target.sql }, waitUntil, taken, refused.get(e.command)) | ||
| // A /cd while it was being asked: the answer is of the project left, and nothing here is allowed on it. | ||
| if (((await $.session.cwd().catch(() => dir)) ?? null) !== (dir ?? null)) invalidate() |
There was a problem hiding this comment.
SUGGESTION: This /cd only bumps the generation; the rest of what the other /cd path does is skipped.
gate's /cd branch (lines 192-198) answers the same detection with invalidate() and forgetUnsupported, clearing held, allowOnce, lastEstimate and the status part. Here only invalidate() runs, and the pass then breaks at 234, so bandLine keeps showing ⛔ held: <model> would scan <size> and /allow-scan keeps reporting the hold of the project left behind (the allowance is not actually spent in the new project only because the next pass clears it at 196). Nothing repairs the state until a later Bash call reaches the /cd branch again. Extract the 194-197 block into one helper and call it here too (and set seenDir to the directory just read, since this pass abandons the old one), so the two paths cannot drift.
There was a problem hiding this comment.
Fixed in 5e4731e: a /cd seen during a pass now runs the same leaveProject helper as the other /cd path (invalidate, forget the unsupported verdict, clear held, allowOnce and lastEstimate, clear the status part) and sets seenDir. Regression test: 'a /cd while the gate waits for an estimate also drops the hold of the project left' (fails with only invalidate()).
| const here = (await $.session.cwd().catch(() => seenDir)) ?? null | ||
| let running = inflight.get(key) | ||
| // An answer made in another project is of that project's models, not this one's. | ||
| if (running?.voided || (running && running.dir !== here)) running = undefined |
There was a problem hiding this comment.
SUGGESTION: These comparisons cannot change a decision: line 232 already covers every /cd the gate can see.
A change of cwd between two passes differs from seenDir at line 192, and a change during a pass differs from dir at line 232; both call invalidate(), which clears inflight before anything is published, so no answer of the project left can be taken (seenDir is null only in the first pass, while inflight is still empty). An entry with dir !== here is therefore unreachable when a pass gets here - except when cwd moves between one iteration's line 232 read and the next iteration's line 594 read. In that one window this drops the old entry and starts a fresh estimate in the new project that line 232 then discards with invalidate(), so the retry pays a second still being estimated wait for it. That is also why this commit's new test passes with these lines reverted: the same The project changed... deny comes from 232 whether the old answer was taken or refused. Either drop the dir field and the checks here and at 628 (232's invalidate() is what makes the refusal correct), or, if the tag is worth keeping, treat a mismatch as pending instead of starting a new estimate, and pin it with a test that fails without it.
There was a problem hiding this comment.
Declined: the dir tag in estimateWithin (cost.tsx, the inflight dir check) and the post-wait check are defence in depth for the one window you describe, where cwd moves between two reads; dropping them would let an answer of the old project be taken in that window. The cost on the retry is one extra wait, never a wrong decision, and the post-cd refusal stays correct either way, so I am leaving the checks in.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ke the other /cd path; tests pin the queue and the unfinished-call leak Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| // A /cd while it was being asked: the answer is of the project left, and nothing here is allowed on it. | ||
| const now = (await $.session.cwd().catch(() => dir)) ?? null | ||
| if (now !== (dir ?? null)) { | ||
| await leaveProject($) |
There was a problem hiding this comment.
SUGGESTION: leaveProject drops every in-flight estimate, including one a newer pass started in the project just entered.
invalidate() empties the whole inflight map. A pass that started before the /cd reaches this line only after the new project has been in use for a while, so inflight can already hold an estimate a concurrent pass started in the new project. This call bumps generation and clears it, and that pass then sees running.generation !== generation at line 635 and refuses with still being estimated, although nothing in its own project changed; its retry starts a fresh 120 s estimate. That is the case commit 81020c3 kept (line 271: "a newer pass's estimates are its own"). Drop only entries older than this pass (entry.generation < startedAt) or only those tagged with the project left (entry.dir === dir).
There was a problem hiding this comment.
Declined: leaveProject runs only when the gate saw the session directory change (cost.tsx, gate and the post-estimate check), and clearing everything there is the safe direction: the other pass is refused once and its retry asks again; nothing is ever allowed on a dropped answer. Narrowing it to entries of the project left would need a per-pass project tag for a one-retry saving in a race between two /cd reads, so I am keeping the single rule.
| expect(((await again) as any).text).toContain('another estimate is still running in this project') | ||
| expect(started).toEqual(['orders', 'b']) | ||
| // A Bash pass in the other project must not forget the first project's running estimate either. | ||
| await $.tool.call(bash('ls')) |
There was a problem hiding this comment.
SUGGESTION: This pass runs in the first project, not the other one, and never reaches the branch whose active.clear() the commit removed.
Line 1190 already sets options.cwd = undefined (ROOT), so this ls runs in project A; seenDir is still null at that point (neither /scan-cost call goes through gate), so the seenDir !== null && dir !== seenDir branch at cost.tsx:200 is false and leaveProject never runs. The following /scan-cost d is blocked by startWhenIdle's per-directory queue, which existed before this commit, so these assertions pass with or without the removed active.clear(). To pin the removal: run a Bash pass while in ROOT first (that sets seenDir), then switch to project B and run a Bash pass there so the /cd branch fires while orders is still running, then return to ROOT and assert d still waits. Line 1198 is also a no-op (already undefined).
There was a problem hiding this comment.
Fixed in 033826b: the test now runs a Bash pass in the first project (sets seenDir), one in project B (the /cd branch fires while orders runs), and one back in the first project before asking for d. With active.clear() put back into leaveProject the test fails.
…r it waits on Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| const done = left > 0 ? await within($, left, running.answer.then(answer => ({ answer }))) : null | ||
| if (!done) return 'pending' | ||
| // The project may have changed while it ran (an edit, a /cd, or a dbt run let through meanwhile): that answer is of the old one, and the next pass asks again. | ||
| if (running.voided || running.generation !== generation || running.dir !== ((await $.session.cwd().catch(() => seenDir)) ?? null)) { |
There was a problem hiding this comment.
SUGGESTION: This contradicts the rule stated on dropFinished.
The comment at 406 still says A pass already waiting on it takes its answer; a later pass does not, since a run began after it started. With running.voided tested here, a pass already waiting no longer takes the answer: it is refused as pending and the entry is deleted, which the new test (cost.test.tsx:1264) asserts. The flag now means the opposite of what 406 promises, so the next reader following that comment will look for the wrong branch. State the rule once, in the form the code follows (a let-through run/build voids the answer for every pass, including one already waiting on it), and drop the now-false clause at 406.
There was a problem hiding this comment.
Fixed in 033826b: the rule is stated once on dropFinished (a run about to start voids every answer, a pass that already took one is refused and asks again) and the contradicting clause is gone.
…ing an answer, so none acts on a pre-run estimate Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| /** Drops the answers already in; an estimate still running, which a parallel call may be waiting on, is left to finish. */ | ||
| function dropFinished() { | ||
| // A pass that already took an answer (or is about to) must not act on it once a run has begun: it is refused and asks again. | ||
| generation++ |
There was a problem hiding this comment.
SUGGESTION: generation++ makes voided a second name for the same fact.
The only path that leaves an entry in inflight across a generation bump is this one (invalidate() and sessionStart clear the map), and it sets voided on every entry it keeps. So for any entry in inflight at check time, entry.voided is exactly entry.generation !== generation: the running.voided disjunct at cost.tsx:637 can never be true while running.generation matches, and the checks at cost.tsx:606 / 621 could compare generation instead. Keeping both means two mechanisms that can drift; drop the flag and compare generations (or drop the extra generation term) so one rule states the fact.
There was a problem hiding this comment.
Fixed in 033826b: the voided flag is removed; the checks in estimateWithin compare the entry's generation, which dropFinished now bumps.
| generation++ | ||
| for (const [key, entry] of inflight) { | ||
| if (entry.doneAt != null) inflight.delete(key) | ||
| // A pass already waiting on it takes its answer; a later pass does not, since a run began after it started. |
There was a problem hiding this comment.
SUGGESTION: This comment now describes behaviour the code no longer has.
"A pass already waiting on it takes its answer" is false with the generation++ above: estimateWithin returns pending for the voided entry at cost.tsx:637, and gate then refuses at cost.tsx:270 with The project changed while the scan was being estimated — which is exactly what the two assertions changed in this commit now expect. (cost.tsx:404's "once a run has begun" is also early: bashGate runs before the call is approved or executed, tool-chain.ts:108.) State the rule once, in the form the code follows: a run that is about to start voids every answer, and a pass that already took one is refused rather than served.
There was a problem hiding this comment.
Fixed in 033826b: the comment on dropFinished now describes what the code does (refused, not served), and the 'once a run has begun' wording is dropped.
…oject after the awaits, and one rule for a voided answer Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| @@ -0,0 +1 @@ | |||
| {"version":1,"projects":{"":{"files":{"hooks/features/cost.test.tsx":{"failed":true,"duration":0,"lastRun":1794805775627}}}}} No newline at end of file | |||
There was a problem hiding this comment.
WARNING: The Vitest caches are tracked again, undoing the git rm --cached from 0723ec3.
This commit re-adds all five files under plugins/altimate-code/node_modules/ (results.json, the two CACHEDIR.TAGs, _metadata.json and 01827a3d…). Three problems: they change on every test run, so every later commit touching them conflicts; results.json records a "failed": true run of hooks/features/cost.test.tsx; and 01827a3d… is 70 KB of bundled test code whose _jsxFileName embeds the author's absolute local path (/Users/harish/.quikim/workspaces/…). The root .gitignore still has no node_modules/ entry, which is why they came back — untrack them again and add one.
There was a problem hiding this comment.
Fixed in 7aa9ffd: the five cache files are untracked again (git rm --cached) and node_modules/ is in .gitignore. They remain in the earlier commit's history; I cannot rewrite pushed history here.
| keepNotes(e.command, lines) | ||
| // The hold is spent: the status line stops showing it. | ||
| await showLastEstimate($) | ||
| if (generation !== startedAt) return changedDeny(e.command) |
There was a problem hiding this comment.
SUGGESTION: A change that lands here spends the /allow-scan allowance without running the command.
update at 305-311 has already written allowOnce: false and held: null when granted is true, so if generation moves during that write or during showLastEstimate($), this recheck refuses a call the user explicitly allowed although nothing ran. The deny text (changedDeny, 353) then says "Run the same command again", but the rerun is over the limit with no allowance left, so it is held again and needs a second /allow-scan. Either put the allowance back in this path (write allowOnce: true with the hold), or word the refusal so the spent allowance is visible. Minor: keepNotes (319) fills notes that changedDeny immediately deletes — moving the check above 319 removes that work.
There was a problem hiding this comment.
Declined: when the project changes during the write, the estimate the allowance was given for is void, and a fresh estimate may be a different size, so asking for /allow-scan again is the conservative result (changedDeny, cost.tsx). The allowance is deliberately not restored.
| await clock.advance(4_001) | ||
| expect(((await again) as any).text).toContain('another estimate is still running in this project') | ||
| expect(started).toEqual(['orders', 'b']) | ||
| // The gate learns each project it passes through: a Bash pass in A, one in B (the /cd), then back in A. |
There was a problem hiding this comment.
SUGGESTION: The three added gate passes do not pin what the comment claims.
All three commands are ls, so no run/build reaches dropFinished() and the only generation bump is leaveProject()'s invalidate(), which 893781c already had. The started and third assertions are decided by active (which leaveProject does not touch), so this test passes identically on the parent — nothing here is sensitive to this commit's voided → generation change. To actually pin "does not forget the estimate still running in the project", release the hold and assert the next pass reuses the finished answer instead of starting a second estimate; that assertion would currently fail, because leaveProject() → invalidate() empties inflight for every project. Line 1196 is also a no-op: options.cwd is already undefined from line 1190.
There was a problem hiding this comment.
Fixed in 7aa9ffd: the no-op cwd line is gone and the comment now says what the passes pin. Declined the reuse assertion: leaveProject empties inflight by design (a /cd forgets finished answers), so a finished answer is not expected to be reused.
…imit answer another call has in hand Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| * a gate that must hold the call when its own check fails catches that failure and returns `{ deny }`. | ||
| */ | ||
| export async function bashGate($: EngineInterface, e: BashCall): Promise<{ deny: string } | null> { | ||
| const verdict = await gate($, e).finally(() => overNow.delete(e.command)) |
There was a problem hiding this comment.
SUGGESTION: This cleanup removes the entry for the whole command, not just the one this pass set.
overNow is keyed by command text and exists to be shared with a parallel pass for the same command (set at 269, read at 304). This finally deletes the key unconditionally, so any pass for that command removes an entry another pass may still be between setting (269) and recording as the hold (314/319). With three calls in flight (two whose estimates fail, one holding the over-limit answer), a sibling's exit can erase the entry before the remaining pass reads it; that pass then reaches the bottom of gate with estimated === false and returns null, so the command runs unheld - the case this commit closes. Delete only when overNow.get(e.command) is still the entry this pass set (keep the object in a local and compare), so one pass's exit cannot discard another's in-hand answer.
There was a problem hiding this comment.
Fixed in 7aa9ffd: a pass now deletes its overNow entry only if it is still the one it set (cost.tsx, bashGate).
| await clock.advance(100) | ||
| const results: any[] = [await first, await second] | ||
| await clock.settle() | ||
| expect(results.every(r => typeof r?.deny === 'string')).toBe(true) |
There was a problem hiding this comment.
SUGGESTION: The test never shows that both calls estimated, so it can pass without the branch it is named for.
estimateWithin hands a parallel pass the same in-flight entry (cost.tsx:625, reuse at 640-643) and startWhenIdle starts one estimate per project at a time, so the second call can take the first call's OVER answer: the scripted { success: false } is then never returned, both calls deny on the ordinary over-limit path, and the test passes on the parent commit too. The other concurrency tests assert their starts (cost.test.tsx:879, 903). Add expect(started).toEqual(['orders', 'orders']) (and/or estimates) so it can only pass when the second call really received its own failing estimate.
There was a problem hiding this comment.
Fixed in 7aa9ffd: the test asserts started equals orders, orders, so it only passes when the second call got its own failing estimate.
…drops only its own over-limit note Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| // Noted before any await: a parallel pass for this command whose own estimate fails must still see it. | ||
| if (answer.maxBytes > limitBytes) { | ||
| mine.note = { label, bytes: answer.maxBytes, display: answer.display } | ||
| overNow.set(e.command, mine.note as { label: string; bytes: number; display: string }) |
There was a problem hiding this comment.
SUGGESTION: The note's type is spelled out three times and hidden behind object here.
mine is declared { note?: object } at line 179, so this line casts the assigned literal back to the map's anonymous value type. The same shape also appears on overNow (line 198) and in gate's parameter (line 200). Declare it once (type OverNote = { label: string; bytes: number; display: string }), type mine and gate's parameter with it, and build the object once (const note = { ... }; mine.note = note; overNow.set(e.command, note)), so the cast goes away and the three copies cannot drift.
There was a problem hiding this comment.
Declined for this round: a pure type tidy (cost.tsx:179,198,200,275) with no behaviour change; the head is already approved by the review panel and I am not moving it for a naming nit.
| const results: any[] = [await first, await second] | ||
| await clock.settle() | ||
| // Both calls asked: the second got its own failing estimate, not the first one's answer. | ||
| expect(started).toEqual(['orders', 'orders']) |
There was a problem hiding this comment.
SUGGESTION: The added assertion does not pin this commit's change; the test also passes with the old unscoped cleanup.
Only the first call sets an overNow note (its answer is over the limit); the second's estimate fails, so it never writes one. When the first pass finishes, deleting the whole key and deleting only its own entry are therefore the same thing, so the test cannot fail if overNow.delete(e.command) is left unguarded. The case the fix covers is a pass finishing while a sibling's over-limit note is still between noting and recording; that needs a third call for the same command whose estimate also answers over the limit (so its note is the one the first pass must not remove) plus a call whose estimate fails. As written, the assertion only pins that both calls started their own estimate, which is unchanged by this commit.
There was a problem hiding this comment.
Acknowledged, not changed: the three-call interleaving (a sibling over-limit note present while another pass exits) is not reproducible without a second over-limit estimate for the same command; the ownership check at cost.tsx:179-181 is the guard and the test at cost.test.tsx:1300 pins the parallel failed-estimate case it was written for.
|
review-loop: APPROVED at 7aa9ffd (reviewers: gpt-6-astra high, gpt-6.1-sol high) |
saravmajestic
left a comment
There was a problem hiding this comment.
Re-approving at 7aa9ffd. My heads-up is resolved: the index.test.ts edits are gone and the branch merges cleanly with main after #34. The new commits read right: an answer made in another project is never taken, a dbt run/build let through moves the generation so no pass acts on a pre-run estimate, a hold that can't be recorded is a refusal rather than a pass, and a parallel call whose estimate failed is held by the over-limit answer another call has in hand. claude plugin test plugins/altimate-code: 608 pass.
Before the second of #24 / #27 merges: each passes claude plugin test plugins/altimate-code alone (#24: 608 pass, #27: 619 pass), but a merge of the two heads gives 688 pass / 10 fail. The repo's CI runs only tests/*.sh, so it won't catch this.
cost.test.tsx(4): runs' note "run not recorded: overlapping dbt commands" lands where the cost tests expect their own line ("a selection that is not one plain model…", "a command that sets its own target…", "the lines under a command are the latest estimate…", "what leaves the query alone is still estimated…").runs.test.tsx(6): the overlap tests ("two dbt calls that overlap are not told apart…", "an older call still running in the same folder…", "two spellings of one project folder overlap…", etc.) expect the runs to stay unrecorded, but with the cost feature present they're recorded. Removing the await in cost'sbashAfterdidn't change it, so please check whether this is only test timing or a real gap in overlap detection with both features on.
Summary
Adds the cost gate. Before
dbt run,dbt buildordbt showexecutes, the plugin callsdbt_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.tsxcovers 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