Skip to content

fix: hands-on findings — real reach in the task band, hardcoded refs, shell edits, older doc gaps, pane follow and fit, package repos, value changes - #44

Open
hkaltai wants to merge 11 commits into
mainfrom
fix/hands-on-findings
Open

hkaltai wants to merge 11 commits into
mainfrom
fix/hands-on-findings

Conversation

@hkaltai

@hkaltai hkaltai commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the plugin behaviour seen in the 19 Nov hands-on testing (rows A, C–I) on dbt Labs' jaffle_shop_duckdb and Tuva Health's public tuva repo. One PR, one commit per round.

Merge order: this was cut from fix/plugin-demo-bugs (#42). #42 merged before this was pushed, so the branch sits on main with #42 in it; nothing else to merge first.

Live checks ran in real Claude Code 2.1.329 sessions (claude --plugin-dir plugins/altimate-code) with altimate-code built from source (fix/tools-demo-bugs), dbt-core 1.12.7 and dbt-duckdb 1.11.1, using the steps in the report's section 5.

A · band said "amount reaches 0 columns in 0 models · ✓ Every downstream model was read" on a compiled project

  • Reproduced on main before fix: /clear keeps comments and health, plugin dbt runs keep the project's manifest, and five demo bugs #42 and on main with fix: /clear keeps comments and health, plugin dbt runs keep the project's manifest, and five demo bugs #42 (cents change in stg_payments.amount, then dbt build): both said 0 columns in 0 models · 2 more may change · ✓ Every downstream model was read, while the per-edit note in the same session said 6 columns in 2 models. So the manifest overwrite was not the cause.
  • Cause: the band reads the task's copy of the manifest, which sat in target/.altimate-lineage/. altimate-code treats the folder above the manifest's folder as the project and reads a seed's CSV header from there. stg_payments does select * from the raw_payments seed. From a copy one folder deeper, the header could not be found, so orders and customers (both select *) came back as may_carry with reason star, and unresolved was empty. The band read that as a real 0 with every model read. The same manifest in target/ traces 6 columns.
  • Fix: the copies now sit in target/ itself (.altimate-manifest-before.<session>.json, .altimate-task-manifest.<session>.json). Copies left in the old folder are still cleaned up. If the reach is 0 while downstream models may pass the column on without naming it (star, natural_join, dynamic_name, row_reference), the band now says "not traced: N downstream models may read it without naming it (select *)" with a lower-bound footer, never "✓ Every downstream model was read".
  • Tests: impact-report.test.ts › "a reach of 0 beside readers that select * is not traced…" uses altimate-code's real answer captured from the live run. task-impact.test.tsx checks that the copy is in target/ and checks the cleanup of both folders.
  • Live: same prompt, PR build: "amount reaches 6 columns in 2 models (6 end columns) · 0 more may change · ✓ Every downstream model was read".

C · ref('stg_orders') replaced by main.stg_orders, and compile & validate still said it matched

  • Cause: compile & validate only compared columns.
  • Fix: it now finds a model, seed, snapshot or source named by its table after FROM/JOIN (bare, schema-qualified or fully quoted). Jinja, comments, strings, CTEs (quoted ones too) and the model itself are skipped. A manifest over 4 MiB (Tuva's is 12.8 MB) is read as a slice of the model's graph, and the slice now also lists every relation: a table taken out of the graph would otherwise be missed. The check becomes a warning: band "hardcoded main.stg_orders: use {{ ref('stg_orders') }} — lineage can't follow it". The dbt check pane lists the table, and Claude's note asks it to put the ref() back unless the person asked for the table.
  • Tests: dbt-mods.test.tsx › "a model, seed or source named by its table…" (spellings and false positives) and "an edit that swaps a ref() for the table it builds is flagged".
  • Live: "⚠ Compile & validate orders · hardcoded main.stg_orders: use {{ ref('stg_orders') }} — lineage can't follow it · 9 columns". The pane says "Compiles and runs, but names main.stg_orders by table".

D · no per-edit impact note when Claude edited through Bash

  • Cause: the note only ran for Edit, Write and MultiEdit.
  • Fix: before a shell command that may write (sed -i, perl -i, a redirect to a .sql, tee, python3/node/…, mv/cp/patch, git apply/checkout/restore), only the time is noted. Nothing is read or run before the command, so it never delays the command or the gates. Afterwards, model files under the project's model paths that changed since then (find -mmin -<minutes the command ran>, then each file's mtime) get the same impact-first note, diffed against the last commit. With show_edit_impact it goes to the transcript, and it always goes to Claude's context. At most 3 files per command.
  • Test: lineage.test.tsx › "a model a shell command rewrites gets the per-edit impact note too…" (a read-only cat gets nothing).
  • Live: with Claude told to edit through a python3 one-liner: "◆ impact-first · stg_payments.amount reaches 6 columns in 2 models" on screen, and "added to Claude's context: lineage for stg_payments.amount (changed by a shell command)".

E · "undocumented order_id, amount" for columns that were already undocumented

  • Cause: every returned column missing from schema.yml was reported as the edit's.
  • Fix: a column counts as the edit's gap only if the model's own select list (its last top-level SELECT, not a CTE's) names it after the edit and did not before (a new, renamed or newly exposed column), and the model's last check did not return it. A gap an edit made stays that edit's on later edits until it is documented. Older gaps don't make the check a warning. They are mentioned once per conversation, quietly ("2 undocumented before this edit"), and the pane marks them "not documented, from before this edit". Compile & validate now reads the file's text from before the edit (editReadsBefore).
  • Tests: dbt-mods.test.tsx › "an undocumented column is the edit's only when…" and "only the columns an edit left undocumented are its gaps…" (second edit: not said again).
  • Live (cents change): "✓ Compile & validate stg_payments · 4 columns · no new gaps with schema.yml · 2 undocumented before this edit".

F · the pane showed the last model read while Claude edited another

  • Cause: the pane followed the edited file only after the edit landed. The edit is held first while its impact lookup runs.
  • Fix: the follow starts as the edit starts, before the lookup and before the edit. A writing shell command's named model is followed as the command starts, and a changed file is followed once it is detected.
  • Test: lineage.test.tsx › "the pane moves to the model being edited as the edit starts…" (the lookup is held, and the pane already shows the model).
  • Live (Read orders → Read customers → Edit orders): the frame before the edit shows "lineage · customers", and the frame with "Update(models/orders.sql)" in progress shows "lineage · orders". The debug log has the follow at 06:13:14.470 and the edit's impact lookup ending at 15.433.

G · at default size the graph ran off the right edge and dashboards weren't visible

  • Fix: until the person picks a view, a graph wider than the pane is drawn as its ends, which fit and include the dashboards. A line says "the whole graph is N columns wide, wider than the pane: ends only · v for the whole graph". Dashboards downstream that the drawing leaves out are named under it ("◆ 3 dashboards downstream: …"). Pressing v shows the whole graph, then cycles as before.
  • Tests: lineage.test.tsx › "a graph wider than the pane opens as its ends…". Tests about the whole graph now press v first.
  • Live (jaffle_shop + 4 marts + 3 exposures, 150 columns): "ENDS ONLY · the whole graph is 124 columns wide…", with "◆ Finance - Monthly Revenue" and "◆ Exec - Weekly KPIs" in the pane.

H · Tuva: compile & validate ran dbt in the package root and failed with "Run dbt deps"

  • Cause: dbt always ran in the folder of the nearest dbt_project.yml, which is the package. Its packages aren't installed there, and its models are disabled there (claims_enabled).
  • Fix: compile & validate looks for a project one or two folders below whose packages.yml/dependencies.yml installs this package by a local path (local: ../). If that project's packages are installed, dbt runs there with the repo's own dbt (its .venv when that project has none) and selects the model by package:<pkg>,<name> (<name>.v<N> for a versioned model). The band says "ran from integration_tests". The doctor counts packages installed there as installed. If dbt still says packages are missing, the result is a one-line "not checked: dbt's packages are not installed in …" note instead of a failure.
  • Tests: dbt-mods.test.tsx › "a package tested from integration_tests is compiled and validated from there…" and "a project whose packages are not installed gets a one-line note…".
  • Live (Tuva, the section 1 prompt, opened at the repo root): "Compile & validate core__medical_claim · 69 columns · … · ran from integration_tests". dbt ran in /…/tuva/integration_tests.

I · "no output column changed: the model-level count stands" after a change to what paid_amount holds

  • Cause: Tuva's core__medical_claim lists its columns in a {% set %} block that the select reads. The select-item diff saw no change.
  • Fix: if no select item changed, the names on the rewritten lines (not comments, and not lines in a WHERE/JOIN/ON/HAVING/QUALIFY clause, even a predicate split over lines) are checked against the manifest. Those the manifest knows as the model's columns are traced as change_type modify: "values change in paid_amount → reaches N columns in M models". If none can be named: "values may change downstream; the model-level count stands" (or "no model reads it downstream" when the count is 0). It never shows 0 columns.
  • Tests: impact-report.test.ts › "a change no select item shows (a value computed in a Jinja block)…". task-impact.test.tsx checks the fallback text.
  • Live (Tuva): "values change in paid_amount → reaches 124 columns in 13 models (44 end columns) · 84 more may change · ⚠ Lower bound: 1 model could not be read".

Review loop

  • Round 1 (gpt-6-astra high, gpt-6.1-sol high): CHANGES_REQUESTED. Fixed with tests: the relation index lost in large-manifest slices; CTE columns taken for model outputs; a gap of this session's edit forgotten on the next edit; the runner losing the repo's .venv dbt; a versioned model's other versions selected from the runner; the shell-edit search window under a long command; comment-only and multi-line predicate changes read as value changes; quoted CTEs flagged.
  • Round 2: CHANGES_REQUESTED. Fixed with tests: the model's output list read with its own parser (a scalar subquery's columns, or an earlier CTE behind select * from <cte>, are not outputs); gap bookkeeping written only by the newest check of the file in this conversation (an older or pre-/clear check ending late erases nothing); from the runner with no manifest there, dbt ls names the file's model and version first; CTEs with a column list; a predicate whose WHERE ends the line before.
  • Round 3: CHANGES_REQUESTED. Fixed with tests: a column the model's list doesn't name, behind a * the SQL can't resolve, is set aside only if the edit left what the * reads unchanged (a select * from <cte> resolves through an alias, a ; and chained select * CTEs); from the runner, dbt ls lists the whole package and the file's own model is used, and nothing runs if dbt lists no model for the file; edit gaps are cleared by /clear; replacement advice keeps a non-latest version (ref('orders', v=1)); value candidates follow the clause at each paren depth across lines, with strings and Jinja blanked; a shell edit in a project below the session folder is found once a dbt project has been seen.
  • Round 4: CHANGES_REQUESTED. Fixed with tests: a select * chain resolves through every CTE it reads, and an unresolved * compares what it reads together with the bodies of the CTEs it names; a UNION's names come from its first branch; replacement advice names another package's model with its package (ref('pkg', 'orders')); value candidates compare the value parts of the SQL (outside filters, joins, grouping and ordering at every depth, with function parentheses tracked), so a changed threshold or a reworded inline comment is not a value change; a shell edit in a project below the session folder is found without waiting for one to be seen.
  • Round 5: CHANGES_REQUESTED. Fixed with tests: a * the SQL can't resolve is fingerprinted with its own list, what it reads and every CTE of the model, so a column added anywhere upstream in the model stays the edit's; * exclude (…) counts as a *; a column no list names (a macro fills it) is set aside only when no Jinja expression or tag changed, and names in {% set %} column lists count as outputs; a bare relation name that two relations share is not flagged.
  • Round 6: CHANGES_REQUESTED. Fixed with tests: a * with a modifier (exclude, replace, …) stays unresolved rather than taking the CTE's list; only the {% set %} lists the model's own select renders count as outputs; the model's own relation takes part in the ambiguity check (and is never advice); the dbt check pane says "no new gaps" rather than "match" when older gaps remain.
  • Round 7 (and the Kilo bot's threads): CHANGES_REQUESTED. Fixed with tests: the Jinja variables a CTE renders carry through select *; a CTE's declared column names are what select * returns; quoted identifiers are masked so a keyword inside one does not end a list; Jinja alternatives ({% if %} select … {% else %} select … {% endif %}) each name outputs; a column no list names is set aside only when every line the edit changed is a named select item; from the runner, dbt ls always gives the file's current model and version (a saved manifest can be stale); a FROM inside a function call (extract(day from x)) is not a relation; a subquery right after FROM keeps the value-candidate levels balanced; no git call when no model file changed; one pass over the relations; one dbt ls JSON-line parser; a test for the projects-below search.
  • Round 8: CHANGES_REQUESTED. Fixed with tests: one conservative rule for a column no list names (behind an unresolved * or from a macro). It counts as from before the edit only when no Jinja expression or tag changed, and every line the edit changed is either a named output's select item or sits in a clause that adds no column (WHERE, GROUP BY, HAVING, QUALIFY, ORDER BY, LIMIT). This replaces the source fingerprints. Quoted CTE names keep their identity.
  • Round 9: CHANGES_REQUESTED. Fixed with tests: when any Jinja expression or tag changed (a flag that turns on a column), only the last check's columns count as having been there before the edit. A changed line counts as one output's select item only when it holds exactly one item and no clause keyword. Only the query's own top-level CTEs are indexed, so one declared inside a subquery does not shadow it.
  • Round 10: CHANGES_REQUESTED. Fixed with tests: a name inside Jinja that may not run ({% if %}, {% for %}) is no evidence that a column was there before the edit. The changed lines come from an ordered line diff, and a changed item line counts only when it sits inside the model's own output list (or a set-block list that list renders) on its side, so lines moved between CTEs keep the column the edit's. From the runner, a failing dbt ls shows dbt's error. A shell edit in a project inside the session's own project is found.

Checks

  • claude plugin test plugins/altimate-code: 1286 pass, 1 fail at the round-10 fix. The failure is the known flake "a dbt call that starts while another call reads its artifact", which also fails on main.
  • The new and changed test files run against the base code (main at e36c74f): the lineage tests for D, F and G fail one by one. impact-report.test.ts, task-impact.test.tsx and dbt-mods.test.tsx don't load on the base, because the functions under test don't exist there.
  • claude plugin validate --strict .: passed. bash tests/*.sh: all 8 pass.
  • CHANGELOG: under [Unreleased]. The version is unchanged.

🤖 Generated with Claude Code

… shell edits, older doc gaps, pane follow and fit, package repos, value changes

- The task's manifest copies sit in target/ itself: altimate-code reads a
  seed's header from the folder above the manifest's, so a copy one folder
  deeper traced nothing through a select * and the band said 0 columns.
  A reach of 0 beside readers that may pass the column on unnamed is "not
  traced", never "every downstream model was read".
- Compile and validate flags a model, seed or source named by its table
  instead of ref() or source().
- A model a shell command rewrites gets the per-edit impact note.
- Only columns an edit made undocumented are its gaps; older ones are said
  once, quietly.
- The lineage pane follows the edited model as the edit starts; a graph
  wider than the pane opens as its ends, with its dashboards named.
- A package repo is compiled and validated from the project below it that
  installs it (integration_tests); missing packages are a one-line note.
- With no select item changed, the band names the columns whose values
  change and their reach, else says values may change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hkaltai
hkaltai marked this pull request as ready for review November 20, 2026 06:31
for (const [id, node] of Object.entries<any>(manifest?.nodes ?? {})) {
if (['model', 'seed', 'snapshot'].includes(node?.resource_type) && typeof node?.name === 'string') add(id, node, `{{ ref('${node.name}') }}`)
}
for (const [id, node] of Object.entries<any>(manifest?.sources ?? {})) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: The hardcoded-relation check goes blind on manifests over 4 MiB

hardcodedRelations can only flag relations present in the manifest it is given, but for a manifest larger than MAX_MANIFEST_BYTES (dbt-mods.tsx:81) compileAndValidate passes the output of MANIFEST_SLICE (dbt-mods.tsx:294). That slice (a) never includes a sources key, so this loop always sees {}, and (b) keeps only the checked node's own parent_map/child_map neighbourhood (keep in MANIFEST_SLICE). A table written by hand instead of ref() is by definition not a parent in the manifest, so its node is normally not in the slice either. On a large project the new warning therefore never fires for the exact case it was added for (swapping {{ ref('x') }} for x), while hardcodedRelations still returns [], which reads as no hardcoded relations rather than not checked. Returning the relation catalogue from the slice (name/package_name/resource_type/relation_name for every model, seed, snapshot and source, plus sources) or reading it separately when the manifest is sliced would keep the check honest.


// An identifier part: double-quoted, backquoted, bracketed or bare.
const PART = String.raw`(?:"[^"]+"|` + '`[^`]+`' + String.raw`|\[[^\]]+\]|[A-Za-z_][\w$]*)`
const RELATION_AFTER = new RegExp(String.raw`\b(?:from|join)\s+(${PART}(?:\s*\.\s*${PART}){0,2})`, 'gi')

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: from inside a function call is read as a relation

RELATION_AFTER matches any from/join word, including the ones inside function arguments: extract(day from orders), trim(both ' ' from customers), substring(name from 1). When the identifier after it happens to equal a model, seed or source name, the edit gets a false hardcoded-relation warning and Claude's note tells it to put the ref() or source() back, i.e. to rewrite valid SQL. Blanking the argument lists of extract/trim/substring-style calls before matching, or requiring the keyword to start a clause, avoids that.

Comment thread plugins/altimate-code/hooks/lineage.tsx Outdated
if (!dirs.length) return null
// Files touched in the last minute, then each one's own time against the command's start.
const listed = await $.process.run(['find', ...dirs, '-name', '*.sql', '-type', 'f', '-mmin', '-1'], { timeoutMs: 10_000 }).catch(() => null)
const top = (await $.process.run(['git', '-C', root, 'rev-parse', '--show-toplevel'], { timeoutMs: 5_000 }).catch(() => null))?.stdout.trim() ?? ''

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: git rev-parse runs even when nothing changed

WRITES matches very common commands (python3, node, cp, mv, tee), so this runs after most shell calls in a dbt session. When find lists nothing the loop below is empty, but this git rev-parse still spawns a process; an early return (e.g. if (!listed?.stdout.trim()) return { root, files: [] }) skips that spawn and makes the empty path explicit. The returned root is also unused by the only caller.

'type_int type_float type_timestamp type_boolean quote_column int integer numeric decimal varchar text float double boolean').split(' '),
)
// A changed line that filters or joins rather than computes a value.
const NOT_A_VALUE = /^\s*(?:where|and|or|on|from|join|left|right|inner|full|cross|group|order|having|limit|qualify|union|\)|\{%-?\s*(?:if|endif|for|endfor|else))\b/i

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 ) alternative can never match

The whole group is followed by a word-boundary assertion, but ) is a non-word character, so the ) branch matches only when the parenthesis is immediately followed by a word character. Lines it was meant to skip, such as ) as total, or ) and status = ..., are followed by whitespace and so are scanned for column names anyway. Put the ) branch (and the Jinja {% branch) outside the word-boundary guard so lines starting with ) are really ignored.

@kilo-code-bot

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

Copy link
Copy Markdown

Code Review Summary

Status: 5 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 1105 Conditional names are only compared with the unconditional before set, so a column inside the same unchanged {% if %}/{% for %} branch is always fresh. On the first check of an incremental model (lastReturned null) every undocumented column is reported as this edit's gap, and editGaps keeps them that way.
plugins/altimate-code/hooks/dbt-mods-core.ts 1033 Item names come from raw SQL, so a trailing --//* */ comment becomes the name (amount -- in cents → cents) and amount is lost; a new amount_cents -- cents item then resolves to a name already in now.names and is filed as pre-existing. Same issue in setBlocks (1125) and onlyNamedItems (1174).
plugins/altimate-code/hooks/dbt-mods-core.ts 1108 old() runs twice per undocumented column and each unnamed column now runs a full O(lines²) LCS (one Uint32Array per line, ~16 MB per call at 2000 lines) plus two whole-text columnlessLines maskings — dozens of times per check on a model like the PR's 69-column Tuva model; past 4M cells every column silently becomes fresh. Hoist the work above old.

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 1021 The vars regex still matches only a bare {{ name }}, so a filtered render ({{ cols | trim }}, {{ cols|join(', ') }}) records no variable, the set-block list names nothing, and every other undocumented column is reported as this edit's fresh gap.
plugins/altimate-code/hooks/dbt-mods.test.tsx 867 show.rows is reassigned to an identical array, so the line is dead and its comment describes a check made elsewhere.
Files Reviewed (5 files)
  • plugins/altimate-code/hooks/dbt-mods-core.ts - 4 issues
  • plugins/altimate-code/hooks/dbt-mods.test.tsx - 1 issue
  • plugins/altimate-code/hooks/dbt-mods.tsx - 0 issues
  • plugins/altimate-code/hooks/lineage.tsx - 0 issues
  • plugins/altimate-code/hooks/lineage.test.tsx - 0 issues

Fix these issues in Kilo Cloud

Previous Review Summaries (7 snapshots, latest commit c89d73d)

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

Previous review (commit c89d73d)

Status: 4 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 1030 Select items are named from raw SQL, so a trailing -- comment becomes the item's name (amount -- in cents → cents) and amount is lost; /* */ loses the name entirely. onlyNamedItems uses the same name, so a new amount_cents -- cents item resolves to cents, which is already in now.names, and the new undocumented column is filed as pre-existing with no gap warning.

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 1078 old() runs twice per undocumented column and each call re-scans both texts with jinjaOf, rebuilds the combined name sets and (for unnamed columns) re-diffs every line and runs columnlessLines twice; hoist all of it above old.
plugins/altimate-code/hooks/dbt-mods-core.ts 1020 The vars regex still matches only a bare {{ name }}, so a filtered render ({{ cols | trim }}, {{ cols|join(', ') }}) records no variable, setBlockNames names nothing, and every other undocumented column is reported as this edit's fresh gap.
plugins/altimate-code/hooks/dbt-mods.test.tsx 860 show.rows is reassigned to the same array it already holds, so the line is dead and its comment describes a check done elsewhere.
Files Reviewed (7 files)
  • plugins/altimate-code/hooks/dbt-mods-core.ts - 3 issues
  • plugins/altimate-code/hooks/dbt-mods.test.tsx - 1 issue
  • plugins/altimate-code/hooks/dbt-mods.tsx - 0 issues
  • plugins/altimate-code/hooks/impact-report.ts - 0 issues
  • plugins/altimate-code/hooks/impact-report.test.ts - 0 issues
  • plugins/altimate-code/hooks/lineage.tsx - 0 issues
  • plugins/altimate-code/hooks/lineage.test.tsx - 0 issues

Resolved since the last review (no longer listed): the {% set %} list a select * CTE renders, the ( right after a clause keyword, Jinja-alternative branches, the duplicated dbt ls JSON-line parser, from inside function calls, the double relation enumeration, ctesOf's unused code, the projects-below test, and the git rev-parse spawn when find lists nothing.

Fix these issues in Kilo Cloud

Previous review (commit 298e866)

Status: 11 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 990 The {% set %} list a select * CTE renders is dropped: inner.vars is not merged, so a column added to that block leaves names, star and the set names all empty and is filed as pre-existing instead of a new gap.
plugins/altimate-code/hooks/impact-report.ts 127 A ( right after a clause keyword (from (, join (, where (, on () is still swallowed, so its ) pops a level that was never pushed and a changed line inside that subquery is read as a value part.
plugins/altimate-code/hooks/dbt-mods-core.ts 961 outputColumns walks back over set operations, but two alternative top-level SELECTs from {% if %}/{% else %} are not joined by one, so a column added in the earlier branch is filed as pre-existing and never warned about.

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 968 vars only matches a bare {{ name }}; a filtered render such as {{ core | trim }} records no variable, so the block is skipped and a newly added column is classified as pre-existing.
plugins/altimate-code/hooks/dbt-mods.test.tsx 826 show.rows is reassigned to the same array it already holds (identical to the value in start()), so the line is dead and its comment describes the check done at line 835.
plugins/altimate-code/hooks/dbt-mods-core.ts 160 listedFiles duplicates the listedNames JSON-line loop and sits under listedNames' JSDoc comment.
plugins/altimate-code/hooks/dbt-mods-core.ts 841 RELATION_AFTER treats from inside extract/trim/substring arguments as a relation, producing a false "use ref()" instruction on valid SQL.
plugins/altimate-code/hooks/dbt-mods-core.ts 867 On a sliced manifest the relations are enumerated twice, and the Array.isArray(manifest?.relations) branch is duplicated; one normalised list and a single pass would be simpler.
plugins/altimate-code/hooks/dbt-mods-core.ts 942 ctesOf returns a masked code companion that no caller reads; only raw is used.
plugins/altimate-code/hooks/lineage.tsx 1175 The projects-below walk (MAX_BASH_PROJECTS) has no test: lineage.test.tsx only exercises the own path, since start() makes the session root a project.
plugins/altimate-code/hooks/lineage.tsx 1184 git rev-parse is spawned for every root (up to five) even when find listed no changed files, on every shell call matching the broad WRITES regex.
Files Reviewed (5 files)
  • plugins/altimate-code/hooks/dbt-mods-core.ts - 7 issues
  • plugins/altimate-code/hooks/dbt-mods.test.tsx - 1 issue
  • plugins/altimate-code/hooks/dbt-mods.tsx - 0 issues
  • plugins/altimate-code/hooks/impact-report.ts - 1 issue
  • plugins/altimate-code/hooks/lineage.tsx - 2 issues

Fix these issues in Kilo Cloud

Previous review (commit 0d142ff)

Status: 8 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
plugins/altimate-code/hooks/impact-report.ts 127 The function-call paren is now balanced, but a ( right after a clause keyword (from (, join (, where (, on () is still swallowed, so its ) pops a level that was never pushed and a changed line inside that subquery is read as a value part.
plugins/altimate-code/hooks/dbt-mods-core.ts 956 outputColumns now walks back over union all, but two alternative top-level SELECTs from {% if %}/{% else %} are not joined by a set operation, so a column added in the earlier branch is filed as pre-existing and never warned about.

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 160 listedFiles duplicates the listedNames JSON-line loop and sits under listedNames' JSDoc comment.
plugins/altimate-code/hooks/dbt-mods-core.ts 838 RELATION_AFTER treats from inside extract/trim/substring arguments as a relation, producing a false "use ref()" instruction on valid SQL.
plugins/altimate-code/hooks/dbt-mods-core.ts 863 On a sliced manifest the relations are enumerated twice, and the Array.isArray(manifest?.relations) branch is duplicated; one normalised list and a single pass would be simpler.
plugins/altimate-code/hooks/dbt-mods-core.ts 937 ctesOf now returns a masked code companion that no caller reads; only raw is used.
plugins/altimate-code/hooks/lineage.tsx 1175 The now-ungated projects-below walk (MAX_BASH_PROJECTS) has no test: lineage.test.tsx only exercises the own path, since start() makes the session root a project.
plugins/altimate-code/hooks/lineage.tsx 1184 git rev-parse is spawned for every root (now up to five) even when find listed no changed files, on every shell call matching the broad WRITES regex.
Files Reviewed (6 files)
  • plugins/altimate-code/hooks/dbt-mods-core.ts - 5 issues
  • plugins/altimate-code/hooks/dbt-mods.test.tsx - 0 issues
  • plugins/altimate-code/hooks/dbt-mods.tsx - 0 issues
  • plugins/altimate-code/hooks/impact-report.test.ts - 0 issues
  • plugins/altimate-code/hooks/impact-report.ts - 1 issue
  • plugins/altimate-code/hooks/lineage.tsx - 2 issues

Fix these issues in Kilo Cloud

Previous review (commit 6ab8041)

Status: 8 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
plugins/altimate-code/hooks/impact-report.ts 122 A ( that directly follows a word is swallowed by the identifier token, so no paren level is pushed while its ) still pops one: the clause state is wrong for the rest of the file (a filter subquery's columns become value candidates, and a later changed select item is dropped).
plugins/altimate-code/hooks/dbt-mods-core.ts 941 outputColumns reads only the last top-level SELECT, so a column added to an earlier union all branch (or the {% if %}/{% else %} branch) is filed as pre-existing and never warned about.
plugins/altimate-code/hooks/dbt-mods-core.ts 949 Only a bare * / t.* item counts as a star, so * exclude (col) / * replace (...) yields empty names with star: false, and every undocumented column is treated as old.

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 838 RELATION_AFTER treats from inside extract/trim/substring arguments as a relation, producing a false "use ref()" instruction on valid SQL.
plugins/altimate-code/hooks/dbt-mods-core.ts 160 listedFiles duplicates the listedNames JSON-line loop and was inserted under listedNames' JSDoc comment.
plugins/altimate-code/hooks/dbt-mods-core.ts 858 On a sliced manifest the relations are enumerated twice, and the Array.isArray(manifest?.relations) branch is duplicated; one normalised list and a single pass would be simpler.
plugins/altimate-code/hooks/lineage.tsx 1184 git rev-parse is spawned for every project even when find listed no changed files, on every shell call matching the broad WRITES regex.
plugins/altimate-code/hooks/lineage.tsx 1175 The new projects-below search (MAX_BASH_PROJECTS) has no test: lineage.test.tsx only exercises the own path, since start() makes the session root a project.
Files Reviewed (6 files)
  • plugins/altimate-code/hooks/dbt-mods-core.ts - 5 issues
  • plugins/altimate-code/hooks/dbt-mods.test.tsx - 0 issues
  • plugins/altimate-code/hooks/dbt-mods.tsx - 0 issues
  • plugins/altimate-code/hooks/impact-report.test.ts - 0 issues
  • plugins/altimate-code/hooks/impact-report.ts - 1 issue
  • plugins/altimate-code/hooks/lineage.tsx - 2 issues

Fix these issues in Kilo Cloud

Previous review (commit a8d0fc1)

Status: 9 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 939 outputColumns reads only the last top-level SELECT, so a column added to an earlier union all branch (or the {% if %}/{% else %} branch) is filed as pre-existing and never warned about.
plugins/altimate-code/hooks/dbt-mods-core.ts 947 Only a bare * / t.* item counts as a star, so * exclude (col) / * replace (...) yields empty names with star: false, and every undocumented column is treated as old.
plugins/altimate-code/hooks/impact-report.ts 125 CLAUSES scans the raw line, so a clause word inside a string literal (such as , 'order' as ...) or inside a filtering subquery poisons carried, either dropping a real value change or inventing one.
plugins/altimate-code/hooks/dbt-mods-core.ts 838 RELATION_AFTER treats from inside extract/trim/substring arguments as a relation, producing a false "use ref()" instruction on valid SQL when a column equals a relation name.
plugins/altimate-code/hooks/dbt-mods.tsx 1571 editGaps is cleared only in startDbtMods; a /clear runs endDbtMods with no session.start after it, so the previous conversation's edit gaps leak into the next conversation.

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 160 listedFiles duplicates the listedNames JSON-line loop and was inserted under listedNames' JSDoc comment.
plugins/altimate-code/hooks/dbt-mods-core.ts 858 On a sliced manifest the relations are enumerated twice, and the Array.isArray(manifest?.relations) branch is duplicated; one normalised list and a single pass would be simpler.
plugins/altimate-code/hooks/lineage.tsx 1179 git rev-parse is spawned even when find listed no changed files, on every shell call matching the broad WRITES regex.
plugins/altimate-code/hooks/impact-report.ts 101 The ) alternative in NOT_A_VALUE cannot match because it is followed by a word-boundary assertion, so lines starting with ) are not skipped.
Files Reviewed (6 files)
  • plugins/altimate-code/hooks/dbt-mods-core.ts - 5 issues
  • plugins/altimate-code/hooks/dbt-mods.test.tsx - 0 issues
  • plugins/altimate-code/hooks/dbt-mods.tsx - 1 issue
  • plugins/altimate-code/hooks/impact-report.test.ts - 0 issues
  • plugins/altimate-code/hooks/impact-report.ts - 2 issues
  • plugins/altimate-code/hooks/lineage.tsx - 1 issue (targeted check; not in this increment)

Fix these issues in Kilo Cloud

Previous review (commit 2f0ac68)

Status: 7 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 824 RELATION_AFTER treats from inside extract/trim/substring arguments as a relation, producing a false "use ref()" instruction on valid SQL when a column name equals a relation name.
plugins/altimate-code/hooks/dbt-mods-core.ts 879 outputColumns keeps only the last top-level SELECT, so a column added to an earlier union all branch (or the {% if %}/{% else %} branch) is treated as "from before this edit" and never warned about; the previous selectItems(sql) saw every scope.
plugins/altimate-code/hooks/impact-report.ts 122 The filtering flag is reset by select/from lines inside a parenthesised predicate (e.g. where x in (\n select ...\n)\n and amount > 0), so a changed filter line becomes a value candidate and the summary claims the column's values change.
plugins/altimate-code/hooks/dbt-mods.tsx 1554 editGaps is cleared only in startDbtMods; a /clear runs endDbtMods with no session.start after it, so the previous conversation's edit gaps leak and are reported as the new conversation's fresh gaps.

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 844 On a sliced manifest the relations are enumerated twice (sources dropped in the first loop, re-filtered in the second) and the Array.isArray(manifest?.relations) branch is duplicated; one normalised relation list and a single pass would be simpler.
plugins/altimate-code/hooks/lineage.tsx 1179 git rev-parse is spawned even when find listed no changed files, on every shell call matching the broad WRITES regex; an early return avoids the extra process.
plugins/altimate-code/hooks/impact-report.ts 100 The ) alternative in NOT_A_VALUE can never match (it is followed by a word-boundary assertion), so lines starting with ) are not skipped as intended.
Files Reviewed (7 files)
  • plugins/altimate-code/hooks/dbt-mods-core.ts - 3 issues
  • plugins/altimate-code/hooks/dbt-mods.test.tsx - 0 issues
  • plugins/altimate-code/hooks/dbt-mods.tsx - 1 issue
  • plugins/altimate-code/hooks/impact-report.test.ts - 0 issues
  • plugins/altimate-code/hooks/impact-report.ts - 2 issues
  • plugins/altimate-code/hooks/lineage.test.tsx - 0 issues
  • plugins/altimate-code/hooks/lineage.tsx - 1 issue

Fix these issues in Kilo Cloud

Previous review (commit ef50c07)

Status: 4 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 846 Hardcoded-relation check is effectively blind when the manifest exceeds 4 MiB: MANIFEST_SLICE has no sources and keeps only the model's own DAG neighbourhood, so relations outside it (which is what a hardcoded table is) are never matched while [] still reads as "none found".

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/dbt-mods-core.ts 824 RELATION_AFTER treats from inside extract/trim/substring arguments as a relation, producing a false "use ref()" instruction on valid SQL when a column name equals a relation name.
plugins/altimate-code/hooks/lineage.tsx 1178 git rev-parse is spawned even when find listed no changed files, on every shell call matching the broad WRITES regex; an early return avoids the extra process.
plugins/altimate-code/hooks/impact-report.ts 97 The ) alternative in NOT_A_VALUE can never match (it is followed by a word-boundary assertion), so lines starting with ) are not skipped as intended.
Files Reviewed (12 files)
  • plugins/altimate-code/CHANGELOG.md - 0 issues
  • plugins/altimate-code/hooks/dbt-mods-core.ts - 2 issues
  • plugins/altimate-code/hooks/dbt-mods.test.tsx - 0 issues
  • plugins/altimate-code/hooks/dbt-mods.tsx - 0 issues
  • plugins/altimate-code/hooks/features/index.ts - 0 issues
  • plugins/altimate-code/hooks/impact-report.test.ts - 0 issues
  • plugins/altimate-code/hooks/impact-report.ts - 1 issue
  • plugins/altimate-code/hooks/lineage.test.tsx - 0 issues
  • plugins/altimate-code/hooks/lineage.tsx - 1 issue
  • plugins/altimate-code/hooks/task-impact.test.tsx - 0 issues
  • plugins/altimate-code/hooks/task-impact.tsx - 0 issues
  • plugins/altimate-code/types/index.d.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash-1017 · Input: 104.7K · Output: 35.9K · Cached: 1.8M

…outputs not CTE columns, edit gaps kept, runner keeps the repo's dbt and the model's version, shell search window, value-change false positives

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
const ch = code[i]!
if (ch === '(') depth++
else if (ch === ')') depth = Math.max(0, depth - 1)
else if (depth === 0 && /[Ss]/.test(ch) && /^select\b/i.test(code.slice(i, i + 7)) && !/\w/.test(code[i - 1] ?? '')) last = i

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Only the final top-level SELECT is read, so earlier union branches lose their outputs

last is overwritten by every top-level select, and selectItems(sql.slice(last, end)) then reads only the last row-producing branch. A model like select id from a union all select id from b (or the usual {% if is_incremental() %} … {% else %} … {% endif %} pair) therefore yields only the last branch's names. When an edit adds a column to an earlier branch, now does not contain it and old() in undocumentedByEdit returns true on !now.has(key), so the edit's own new undocumented column is reported as "not documented, from before this edit" and no gap warning is raised. The previous selectItems(sql) saw every scope, so this is a regression for set-operation and conditional models: collect the items of every top-level SELECT instead of only the last one, which keeps CTE and subquery scopes out without dropping branches.

let filtering = false
const added = now.flatMap(line => {
const clause = CLAUSE.exec(line)?.[1]?.toLowerCase()
if (clause) filtering = FILTERS.has(clause)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: A select/from inside a parenthesised predicate resets the filter state

filtering changes only on a clause word that starts a line and is not tied to parenthesis depth, so a predicate split over lines around a subquery is read as a value change:

where claim_id in (
    select claim_id from other
)
  and paid_amount > 0

The select/from lines set filtering back to false, so editing > 0 makes paid_amount a candidate and the task summary claims its values change. The reverse also happens: a select item that wraps onto left(name, 3) or right(...) starts with a FILTERS word and is dropped. Track paren depth and only let a depth-0 clause keyword (one not followed by () start or end a filter clause.

contextGiven.clear()
oldGapsSaid.clear()
lastReturned.clear()
editGaps.clear()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: editGaps is not cleared when a conversation ends

A /clear runs endDbtMods and no session.start follows it (see features/index.ts), yet only oldGapsSaid and lastReturned are cleared there. The previous conversation's editGaps entry is still passed as ours to undocumentedByEdit, so a column an earlier conversation's edit left undocumented is reported as this edit's fresh gap (band warning and Claude's note) instead of the quiet "from before this edit" mention. Clear editGaps in endDbtMods too (or key it by generation).

for (let i = 0; i < parts.length; i++) known.set(parts.slice(i).join('.'), { relation: parts.slice(i).join('.'), use })
}
// A manifest too big to read here comes as a slice of the model's graph, with every relation listed apart.
const nodes: [string, any][] = Array.isArray(manifest?.relations) ? manifest.relations.map((one: any) => [String(one?.id), one]) : Object.entries<any>(manifest?.nodes ?? {})

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 relations are enumerated twice for a sliced manifest

With manifest.relations present, the first loop visits every entry only to drop sources and the second visits the array again to keep them, repeating the Array.isArray(manifest?.relations) branch; a full manifest reads a third collection. One normalised list (const relations = Array.isArray(manifest?.relations) ? manifest.relations : [...Object.values(manifest?.nodes ?? {}), ...Object.values(manifest?.sources ?? {})]) followed by a single pass that picks the ref() or source() wording by resource_type visits each relation once and removes the duplicated guard.

… the newest check only, the runner asks dbt ls for the file's version, CTE column lists, predicates split over lines

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
*/
export function outputColumns(sql: string, depth = 0): { names: Set<string>; star: boolean } | null {
const code = masked(sql)
const select = topLevel(code, 'select', 0, true)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Only the last top-level SELECT is read, so union and if/else branches lose their columns

topLevel(code, 'select', 0, true) keeps only the final top-level select, so select id from a union all select id, amount from b (and the common incremental {% if is_incremental() %} / {% else %} pair) yields only the last branch's names. When an edit adds a column to an earlier branch, now in undocumentedByEdit does not contain it, old() returns true on !now.has(key), and the edit's own new undocumented column is filed as 'from before this edit', so no gap warning is raised. The previous selectItems(sql) saw every scope; collect the items of every top-level SELECT instead of only the last one - a depth-0 scan already keeps CTE and subquery lists out.

let star = false
for (const item of topItems(list)) {
const bare = item.replace(/\s+/g, ' ').trim()
if (/^(?:[\w"`]+\.)?\*$/.test(bare)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: A * with a modifier is no longer recognised as a star

Only an item that is exactly * or t.* sets star. * exclude (col) and * replace (x as y) (DuckDB, BigQuery, Snowflake) match neither this check nor the name regexes below, so outputColumns returns empty names with star: false. undocumentedByEdit then trusts that empty set and classifies every returned column as old through !now.has, so a model such as with src as (select id, amount from raw) select * exclude (extra) from src never warns about a newly added undocumented column. The earlier detector treated any top-level * as a star and fell back to selectItems; set star when an item starts with an optionally qualified * unless the item is exactly a plain * (the CTE resolution below handles that case).

const added = now.flatMap(line => {
const opens = CLAUSE.exec(line)?.[1]?.toLowerCase()
const filtering = opens ? FILTERS.has(opens) : carried
const clauses = [...line.matchAll(CLAUSES)].map(one => one[1]!.toLowerCase())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: carried is set by a clause word anywhere on the line, including inside a string literal

CLAUSES scans the raw line, so , 'order' as record_type (or a column literally named order) sets carried to true and every later line without a clause word is treated as a filter and dropped from the value candidates. In a {% set %} column list, for example, the changed line , med.paid_amount / 100 is no longer named and the summary falls back to 'values may change downstream'. The reverse also remains: the scan is not paren-depth aware, so select/from inside where claim_id in (select ... from other) still resets carried, and a change inside that filtering subquery is read as a value change. Strip string literals before splitting the words, and only take clause words at depth 0.

}

/** The node names `dbt ls --output json --output-keys name` printed: one JSON object per line, among dbt's own log lines. */
/** The models `dbt ls --output json --output-keys "name version original_file_path"` lists, each with its file and version. */

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: A second copy of the dbt ls JSON-line parser

listedFiles repeats listedNames' loop (strip ANSI, one line at a time, skip non-{, guarded JSON.parse) with only the field test changed, and it was inserted between listedNames' doc comment and listedNames, so that comment now sits above the wrong function. One helper that parses each JSON line once and returns the node, with listedNames and listedFiles reading the fields they need, removes the duplicate and the misplaced JSDoc.

…the file's model, /clear drops edit gaps, versioned ref advice, depth-aware value candidates, shell edits below the session folder

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
const n = left.get(line) ?? 0
if (n > 0) left.set(line, n - 1)
const changed = !!line && n === 0
for (const token of line.matchAll(/\(|\)|(?<![\w.])(?:[A-Za-z_]\w*\.)?([A-Za-z_]\w*)\b(\s*\()?/g)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: A ( that follows a word is swallowed, so every later line is read at the wrong depth

The identifier branch ends in (\s*\()?, so in (, exists (, max( match as one token (group 2): the ( never reaches the clauses.push above, while the closing ) still runs clauses.pop(). The level's clause is therefore overwritten or popped early:

  • where id in (select id, x from t): the ( after in is swallowed, so select overwrites the level's where instead of opening a subquery level. A changed line inside that filter subquery then names id/x as value candidates and the summary claims their values change - the false positive this rewrite is meant to remove.
  • select (select max(a) from t) as m, amount from t: max( is swallowed and its ) pops the real grouping level, so from stays in force and a later changed amount line is dropped.

Only a bare ( (not directly preceded by an identifier) is pushed. Matching ( separately from the word, or pushing whenever token[2] is set, keeps the depth balanced.

Comment thread plugins/altimate-code/hooks/lineage.tsx Outdated
const base = await $.session.root().catch(() => '.')
const own = await projectRoot($, commandDir(start.command, base), false).catch(() => null)
// Below it only once a dbt project has been seen this session: a session that never touches dbt never walks its folder.
const roots = own ? [own] : projectSeen ? (await projectsBelow($, base).catch(() => [] as string[])).slice(0, MAX_BASH_PROJECTS) : []

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 projects-below search has no test

This branch (and MAX_BASH_PROJECTS) is what makes a shell edit in a project below the session folder get an impact note, but lineage.test.tsx only exercises the own path (start() makes the session root a project), so a wrong root, a note duplicated when two roots overlap, or the cap not being applied would go unnoticed. A test whose session root sits above two projects, with the shell command rewriting a model in the second, would cover it.

hkaltai and others added 2 commits November 20, 2026 12:50
…package-qualified ref advice, value parts compared, shell edits below the session folder

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h every CTE, macro lists compared by their Jinja, set-block column lists, ambiguous relation names left alone

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
continue
}
const word = token[2]?.toLowerCase()
if (word && !token[1] && CLAUSE_WORDS.has(word)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: A ( right after a clause keyword is still swallowed, so its ) pops a level that was never pushed

The new token[3] push below balances a function call such as max(, but this branch continues before reaching it: when a clause word itself is followed by (, the paren is part of the same token and no level is pushed. In from (select ...), join (select ...), on (...) or where (...) the inner select/from then overwrite this level's clause, and the matching ) pops nothing (or an outer level when one is open), so the clause state after the subquery is wrong. A changed line inside a from (/join ( subquery is read as a value part, so its columns are offered as value candidates, and any whose name the manifest also lists among the model's columns is traced as a value change. Push token[3] in this branch too (before continue), as the function-call path does.

for (let at = topLevel(code, 'select'); at >= 0; at = topLevel(code, 'select', at + 6)) selects.push(at)
if (!selects.length) return null
let k = selects.length - 1
while (k > 0 && /\b(?:union|intersect|except|minus)\b/i.test(code.slice(selects[k - 1]!, selects[k]!)) && topLevel(code.slice(selects[k - 1]!, selects[k]!), '(?:union|intersect|except|minus)') >= 0) k--

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: {% if %}/{% else %} branches still yield only the last SELECT's names

Walking back over set operations fixes union all, but two alternative top-level SELECTs ({% if ... %} select ... {% else %} select ... {% endif %}) are not joined by union, so k stays on the last one and only that branch's names are returned. A column added inside the earlier branch is missing from now.names, and undocumentedByEdit then falls through to jinjaOf(before) === jinjaOf(after), which is also true (the edit changed SQL text, not a Jinja tag), so the edit's own new undocumented column is filed as pre-existing and no gap warning is raised. Union the names of top-level SELECTs that no set operation joins, instead of keeping only the last.

if (code[i] === '(') depth++
else if (code[i] === ')') depth--
}
out.set(unquote(match[1]!), { raw: sql.slice(open, i - 1), code: code.slice(open, i - 1) })

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: ctesOf returns a code field that nothing reads

Only raw is used (body.raw in the recursion and one.raw in the source fingerprint; the recursion re-masks it anyway), so the masked code companion is a second full copy of every CTE body with no reader. Dropping it, or returning just the raw body, keeps the same behaviour with less copying.

const dirs = models.map(one => (one === '.' ? root : `${root}/${one}`))
if (!dirs.length) continue
const listed = await $.process.run(['find', ...dirs, '-name', '*.sql', '-type', 'f', '-mmin', `-${minutes}`], { timeoutMs: 10_000 }).catch(() => null)
const top = (await $.process.run(['git', '-C', root, 'rev-parse', '--show-toplevel'], { timeoutMs: 5_000 }).catch(() => null))?.stdout.trim() ?? ''

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: git rev-parse runs even when find listed nothing

With this change roots can hold up to five projects from projectsBelow, and WRITES matches very common commands (python3, node, cp, mv, tee), so each matching shell call spawns up to five git rev-parse processes even when find returned no files (the loop below then does nothing). Return early when listed?.stdout.trim() is empty, or move the git lookup inside the loop so it runs only once a candidate file is found.

Comment thread plugins/altimate-code/hooks/lineage.tsx Outdated
const base = await $.session.root().catch(() => '.')
const own = await projectRoot($, commandDir(start.command, base), false).catch(() => null)
// The walk below it is bounded (2000 folders) and kept for the session.
const roots = own ? [own] : (await projectsBelow($, base).catch(() => [] as string[])).slice(0, MAX_BASH_PROJECTS)

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 now-ungated projects-below walk has no test

Removing the projectSeen gate means this branch runs for every writing shell command in a session whose folder is not a dbt project, not just after one has been seen. lineage.test.tsx only exercises the own path (its start() makes the session root a project), so a wrong root, a duplicate note when two roots overlap, or MAX_BASH_PROJECTS not being applied would go unnoticed. A test whose session root sits above two projects, with the command rewriting a model in the second, would cover it.

…et-block lists, the model in the ambiguity check, the pane's no-new-gaps heading

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
const read = /^\s*((?:"[^"]+"|`[^`]+`|[A-Za-z_]\w*))(?:\s+(?:as\s+)?(?!where\b|group\b|order\b|limit\b|qualify\b|having\b|window\b|union\b)[A-Za-z_]\w*)?\s*(?:;\s*)?(?:$|where\b|group\b|order\b|limit\b|qualify\b|having\b|window\b|union\b)/i.exec(tail)
const body = read ? ctes.get(unquote(read[1]!)) : undefined
const inner = body !== undefined ? outputColumns(body.raw, depth + 1, ctes) : null
if (inner) return { names: new Set([...names, ...inner.names]), star: inner.star, vars, ...(inner.source !== undefined && { source: inner.source }) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: The {% set %} list a select * CTE renders is dropped, so a column added there is missed

inner is parsed from the CTE body, so inner.vars holds the variables that body renders (select {{ cols }}), but this return keeps only the outer level's vars. In {% set cols %}id, amount{% endset %} / with src as (select {{ cols }} from raw) / select * from src, names are inherited from the CTE while vars stays empty, so setBlockNames(after, now.vars) in undocumentedByEdit returns nothing. Adding paid_cents to the block then leaves now.names, nowSet and now.star all empty, so undocumentedByEdit falls back to jinjaOf(before) === jinjaOf(after) - true, because jinjaOf keeps only the {% set %}/{% endset %} tags and not the block's text - and the new column is filed as pre-existing, with no gap warning. Merge it here: vars: new Set([...vars, ...inner.vars]).

const list = code.slice(select + 6, from < 0 || from > end ? end : from).replace(/^\s*(?:distinct|all)\b/i, '')
const names = new Set<string>()
// The Jinja variables the list renders (`{{ cols }}`): their `{% set %}` blocks name outputs.
const vars = new Set([...sql.slice(select + 6, from < 0 || from > end ? end : from).matchAll(/\{\{-?\s*([A-Za-z_]\w*)\s*-?\}\}/g)].map(one => one[1]!))

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: Only a bare {{ name }} is recognised, so a filtered render loses its {% set %} list

The regex requires the whole expression to be one identifier, so {{ core | trim }} (or | join(', '), or any filter on a block-set column list) records no variable. setBlockNames(after, now.vars) then skips that block, and since jinjaOf keeps only the Jinja tags and not the block's text, a column newly added to the block is classified as "from before this edit" and no gap is warned - the false negative this round is meant to remove. Capture the leading identifier and ignore a trailing filter, e.g. /\{\{-?\s*([A-Za-z_]\w*)\b/g.

expect(await pane.find({ type: 'Text', text: ' not documented, from before this edit' })).toBeDefined()
await pane.unmount()
// A check that found only older gaps does not claim the columns match.
show.rows = [{ order_id: 1, amount: 10, status: 'placed', amount_cents: 1000 }]

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: Dead reassignment

This array is identical to the initial show.rows in start() (line 808), so the line changes nothing, and the comment above it describes the assertion that actually depends on the rows set at line 835. Removing it (or setting the rows where they really change) keeps the test honest.

hkaltai and others added 3 commits November 20, 2026 13:22
…red CTE columns, quoted identifiers, Jinja alternatives, named-item edits, runner always asks dbt ls, FROM in function calls, balanced subquery levels, fewer git calls

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (named items or column-less clause lines only, Jinja unchanged), quoted CTE names kept

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… lines only, top-level CTEs only

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
if (/^(?:[\w"`]+\.)?\*\s+\S/.test(bare)) modified = true
continue
}
const name = itemName(sql.slice(select + 6 + lead + a, select + 6 + lead + b))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: A trailing comment is read as the select item's name

itemName is given the raw sql slice here, while the items were split on the masked list. A trailing line comment therefore becomes the name: amount -- in cents is captured as cents by the /[\s)](...)$/ fallback and amount itself is dropped, and amount /* cents */ gets no name at all. Before this change the name was read from the masked text, where comments were already blanked. The lost name defeats the rule added in this PR: onlyNamedItems measures the changed line with itemName too, so a new amount_cents -- cents select item resolves to cents, which outputColumns has already put in now.names, and old() files the new undocumented column as pre-existing (no gap warning). now.names also gains phantom names, which can make an unrelated undocumented column look like it was there before. Pass a comment-blanked slice (quotes kept, which is why the raw text was used) here, at setBlockNames (line 1090) and in onlyNamedItems (line 1117).

// Named nowhere (through a `*` the SQL does not resolve, or a macro): there before only when no Jinja expression or
// tag changed and every line the edit changed either rewrote a named output's select item or sits in a clause that
// adds no column (WHERE, GROUP BY, HAVING, QUALIFY, ORDER BY, LIMIT).
return onlyNamedItems(before!, after!, new Set([...was.names, ...wasSet]), new Set([...now.names, ...nowSet]))

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: File-wide work runs once per undocumented column

old() is called twice for every undocumented column (filter for fresh, then again for old), and each call re-scans both whole texts with jinjaOf, rebuilds the two combined name sets, and - for any column no list names - runs onlyNamedItems, which re-diffs every line and calls columnlessLines twice more. Hoist jinjaOf(before) !== jinjaOf(after), the combined sets and the onlyNamedItems result (or at least its quietBefore/quietAfter sets) above old; a model with dozens of undocumented columns repeats all of it dozens of times per check.

const listEnd = from < 0 || from > next ? next : from
const list = code.slice(select + 6, listEnd)
const lead = /^\s*(?:distinct|all)\b/i.exec(list)?.[0].length ?? 0
for (const one of sql.slice(select + 6, listEnd).matchAll(/\{\{-?\s*([A-Za-z_]\w*)\s*-?\}\}/g)) vars.add(one[1]!)

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: A filtered {{ … }} render records no variable

The regex still matches only a bare {{ name }}, so {{ cols | trim }}, {{ cols|join(', ') }} or {{ env_var('COLS') }} add nothing to vars. setBlockNames then names no columns for that block, now.names/nowSet stay empty, and old() falls through to onlyNamedItems; the changed set-block line is not one of the named outputs, so every other undocumented column of the model is reported as this edit's fresh gap (a warning about columns the edit did not touch). Capture the leading identifier and ignore a trailing filter, e.g. /\{\{-?\s*([A-Za-z_]\w*)\b/g.

…ed diff within output lists, runner ls errors shown, nested projects searched

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
const afterSide = sides(now, nowSet)
// Named in the model's own list after the edit: there before only when that list named it before too (outside
// Jinja that may not run).
if (afterSide.names.has(key) || now.maybe.has(key) || nowSet.maybe.has(key)) return beforeSide.names.has(key)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Conditional names are compared only against the unconditional "before" set

When the after side names the column only inside Jinja that may not run (now.maybe/nowSet.maybe), this returns beforeSide.names.has(key) and never consults was.maybe/wasSet.maybe. So a column that sits in the same unchanged {% if is_incremental() %} … {% else %} … {% endif %} branch on both sides is treated as fresh on any edit. On the first check of a model (lastReturned is null at dbt-mods.tsx:690) every undocumented column of an incremental model is reported as this edit's new gap, and editGaps.set(fileKey, gaps.fresh) (dbt-mods.tsx:692) then keeps them the edit's on later checks, since lastReturned excludes them (dbt-mods.tsx:696). The updated "an undocumented column is the edit's only when…" case encodes exactly this for a whitespace-only edit, which is the false warning that finding E was meant to remove. Return true when was.maybe.has(key) || wasSet.maybe.has(key) too: the same conditional branch named it before.

}
// Where the item's own text starts (past whitespace and masked Jinja tags before it).
const start = select + 6 + lead + a + (/^\s*/.exec(list.slice(lead + a, lead + b))?.[0].length ?? 0)
const name = itemName(sql.slice(start, select + 6 + lead + b))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Item names are read from raw SQL, so a trailing comment becomes the name

itemName gets sql.slice(start, …), which still holds -- and /* */ comments (the items were split on masked code, but the slice is raw). amount -- in cents therefore resolves to cents and amount is lost, and amount /* cents */ gets no name at all. That defeats the rule this PR adds: a new undocumented amount_cents -- cents item resolves to cents, which is already in now.names, so onlyNamedItems treats the changed line as a named item and old() files the new column as pre-existing with no gap warning. The same raw text is passed to itemName in setBlocks (line 1125) and onlyNamedItems (line 1174). Pass a comment-blanked slice (quotes kept, which is why raw text was used) at all three.

if (afterSide.names.has(key) || now.maybe.has(key) || nowSet.maybe.has(key)) return beforeSide.names.has(key)
// Named on neither side (a macro or a `*` fills it): there before only when every line the edit changed is a named
// output's item or a clause that adds no column.
return !was.maybe.has(key) && !wasSet.maybe.has(key) && !beforeSide.names.has(key) && onlyNamedItems(before!, after!, beforeSide, afterSide)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: An O(lines²) diff runs for every undocumented column

old() is evaluated twice per undocumented column (line 1110), and for every column the after list does not name it now runs onlyNamedItems: an LCS over every line of the model with one Uint32Array per line (up to 4M cells and roughly 16 MB allocated per call for a 2000-line model), plus columnlessLines, which masks the whole text twice. A model with dozens of undocumented columns (the PR's Tuva run reported 69) repeats all of it dozens of times per check on the hook's thread, and past the 4M-cell bail (line 1150) every column silently becomes fresh. Hoist the jinjaOf comparison, the combined sides(...) sets and one onlyNamedItems result (or at least its removed/added and quiet sets) above old.

out.spans.push([base + select, base + listEnd])
const list = code.slice(select + 6, listEnd)
const lead = /^\s*(?:distinct|all)\b/i.exec(list)?.[0].length ?? 0
for (const one of sql.slice(select + 6, listEnd).matchAll(/\{\{-?\s*([A-Za-z_]\w*)\s*-?\}\}/g)) out.vars.add(one[1]!)

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: A filtered {{ … }} render still records no variable

The regex matches only a bare {{ name }}, so {{ cols | trim }}, {{ cols|join(', ') }} or {{ env_var('COLS') }} add nothing to vars. setBlocks(after, now.vars) then names no columns for that block, the changed set-block lines sit outside every span, and old() falls through to onlyNamedItems, so every other undocumented column of the model is reported as this edit's fresh gap. Capture the leading identifier and ignore a trailing filter, e.g. /\{\{-?\s*([A-Za-z_]\w*)\b/g.

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