Skip to content

feat(analyst): sql_check predicate_effect reports what each filter removes - #1446

Open
anandgupta42 wants to merge 28 commits into
feat/analyst-harness-dab-2026-10from
feat/analyst-v10-probe
Open

anandgupta42 wants to merge 28 commits into
feat/analyst-harness-dab-2026-10from
feat/analyst-v10-probe

Conversation

@anandgupta42

@anandgupta42 anandgupta42 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Why. The analyst prompt tells the model that "a filter that removes nothing usually means the wrong column", but there was no cheap, deterministic way to check what a filter clause actually does at the population it is applied to. In practice the model either skipped the check or guessed.

What changed. sql_check gains an opt-in check: "predicate_effect". The caller supplies an explicit read-only population (base_sql: a SELECT or a bare table reference) and one to eight boolean predicates. The tool runs a single aggregate probe

SELECT COUNT(*) AS total,
       COUNT(*) FILTER (WHERE (p1)) AS keep_1, …,
       COUNT(*) FILTER (WHERE (p1) AND (p2) …) AS keep_all
FROM (base_sql) t

and reports rows kept and removed per predicate plus the combined count. A predicate that removes no rows is flagged (this predicate removes no rows at this population), as is one that removes every row; a NULL predicate value counts as not kept and the output says so; an empty population and a LIMITed SELECT population are called out.

Bounded by design: no rewriting of the caller's own WHERE clause (predicates are validated as bare expressions through the existing read-only validator with the connection's dialect); SQLite, DuckDB and Postgres only; a catalog row estimate above max_rows_scanned (default 5,000,000) for a bare table refuses with a suggestion to narrow the population, and an unknown estimate is stated rather than silently proceeding; query timeouts return skipped: timeout instead of failing the caller; all supplied SQL goes through the sql_execute permission request before workspace routing. Strict-schema clients' ""/[]/0 fillers are treated as absent. Function calls that can change state outside the read-only transaction are refused as classes rather than by name: every pg_* call is denied unless it is a known pure read (type/size/catalog inspection, pg_get_*, stat getters other than pg_stat_reset*, LSN and snapshot reads, privilege checks), and every lo_*/lowrite/loread, dblink*, checkpoint/force_checkpoint, sequence, set_config, extension-load and file-write call is denied, so a new server-control, WAL, replication, statistics-reset or large-object function cannot slip through one name at a time. Was: a fixed list of individual function names → now: deny-by-default classes with a pure-read allowlist (eight pure reads are covered by positive tests).

The analyst prompt's existing "every clause must bite" sentence now points at the check and says a vacuous filter is a reason to profile an alternative column, not to invent an exclusion.

Base. Stacked on feat/analyst-harness-dab-2026-10 (#1441); the diff shown here is only this feature.

Behaviour deltas. sql_check accepts one new check value and two new fields (base_sql, predicates, plus max_rows_scanned); other checks and every other tool are unchanged. One sentence of the analyst prompt is extended. No other agent is affected.

How did you verify your code works?

Unit/integration, real in-memory SQLite and DuckDB engines, run outside any sandbox:

  • test/altimate/sql-check-predicate-effect.test.ts (new): zero-removal and all-removal flags, NULL semantics, empty population, nine predicates rejected, a write inside a predicate rejected before execution, unsupported dialect, combined count equals a direct WHERE p1 AND p2 count, estimate guard (known/unknown/zero cap), strict-schema fillers, view shadowing, mixed-case schema.
  • test/altimate/sql-check-postgres.test.ts (new): Postgres probe shape, to_regclass/reltuples guard, unknown-estimate path (driver mocked; no live Postgres).
  • Permission: sql_execute denied → no query runs.
  • Prompt-contract assertion updated.

Results: 86 pass / 0 fail across the four touched test files; bun run typecheck clean; bun run script/upstream/analyze.ts --markers --base main --strict passes (all edits in Altimate-owned files). An independent review of the first commit (approve-with-changes) drove the second commit's follow-ups.

Not run: live Postgres; HTTP/browser journeys do not apply (tool-only change).

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code


Note

High Risk
Expands SQL execution and permission paths with catalog-driven validation and read-only transaction semantics; mistakes could block legitimate probes or still miss implicit server-side rewrites noted in the PR limitations.

Overview
Adds sql_check predicate_effect: given a read-only population (base_sql) and up to eight boolean predicates, it runs one aggregate probe and reports rows kept/removed per filter, combined AND counts, and warnings for vacuous or all-removing predicates (NULL = not kept).

Safety and drivers. Predicate/population SQL is validated with stricter read-only rules (deny-by-default side-effect pg_* / dblink / lo_* classes, pure-function allowlist, Postgres catalog checks for custom operators/functions/casts). All sql_check warehouse calls now use readOnly: true across SQLite/DuckDB/Postgres; DuckDB/SQLite helpers wrap execution in rolled-back READ ONLY / query_only, and Postgres forwards bind parameters in read-only paths. Bare-table probes respect max_rows_scanned (estimate skip, bounded materialization on local engines).

Other. Permission ask evaluates every pattern before prompting so a later deny cannot be bypassed. Analyst prompt points analysts at predicate_effect for “filter removes nothing” cases.

Reviewed by Cursor Bugbot for commit 388d088. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Adds a predicate_effect check to sql_check so analysts can see what each filter predicate actually removes from a population.

The check takes a read-only population (base_sql) and up to eight boolean predicates, runs a single aggregate probe, and reports rows kept and removed per predicate plus the combined AND count. Vacuous or all-removing predicates are flagged, NULL counts as not kept, empty populations are reported as such, and blank predicate entries are reported as skipped in their original position.

Details

  • Bounded to SQLite, DuckDB, and Postgres. Only built-in pure functions are allowed in predicates and populations: the check resolves every referenced operator, function, and explicit cast target against the catalog on Postgres and DuckDB, refusing any user-defined definition plus backend-signalling, server-control, dblink, large-object, checkpoint, and file-write calls before any SQL runs. CTE declarations, their column lists, FILTER/OVER/WITHIN GROUP/USING clauses, and wildcard projections are accepted as such.
  • The combined probe is authorized in the exact shape it executes, so a sql_execute deny rule scoped to the population–predicate join matches before any SQL runs; every permission pattern is evaluated before any approval prompt, so a later explicit deny cannot be bypassed by approving an earlier pattern.
  • Local engines enforce the probe read-only: a scoped query_only pragma for SQLite; a rolled-back READ ONLY transaction for DuckDB, guarded with a txid_current probe so an active caller transaction is refused rather than aborted. DuckDB's query() is denied because it executes the SQL in its string argument.
  • Bare-table populations are refused when the catalog row estimate exceeds max_rows_scanned (default 5,000,000) and return skipped: "estimate"; unknown estimates are reported without failing the call. Postgres runs the catalog guard and aggregate in one statement, and SQLite and DuckDB run the estimate and aggregate on one population bounded to max_rows_scanned + 1 rows, so a concurrent peer cannot swap the relation between guard and scan.
  • Query timeouts return skipped: timeout, but rethrow when they carry stateLost: true so the caller gets the lost-session disclosure.
  • The analyst prompt now points at the check and says a vacuous filter is a reason to profile an alternative column, not to invent an exclusion. This branch also brings in the feat/analyst-harness-dab-2026-10 base.

Written for commit 388d088. Summary will update on new commits.

View guided diff Turn on auto-fix

Known limitations

predicate_effect validates the population and predicate SQL textually and against the server catalog: function names (pg_proc, duckdb_functions()), operator names (pg_operator) and explicit cast targets (pg_type) must resolve to built-in definitions, and the probe itself is authorized as a whole before execution. It cannot see definitions the text does not name: an implicit cast selected by a user-defined operand type (a user-defined type with an implicit cast to a built-in type whose conversion function has side effects), or any server-side rewrite such as rules, policies or generated columns. Under BEGIN READ ONLY those can still run if the connected role can reach them. Mitigations: run the analyst role without access to such definitions, or do not enable predicate_effect on databases that define user-defined types with implicit casts.

anandgupta42 and others added 2 commits October 12, 2026 12:54
…removes

Analysts are told that a filter which removes nothing usually means the wrong
column, but there was no cheap way to verify it. `sql_check` gains an opt-in
`predicate_effect` check: given an explicit read-only population (`base_sql`,
a SELECT or a table reference) and one to eight boolean predicates, it runs a
single aggregate probe

    SELECT COUNT(*), COUNT(*) FILTER (WHERE p1), …, COUNT(*) FILTER (WHERE p1 AND …)

and reports rows kept and removed per predicate plus the combined count,
flagging `this predicate removes no rows at this population`. NULL counts as
not kept and the output says so; an empty population is reported as such.

- No rewriting of the caller's WHERE clause; predicates are validated as bare
  expressions through the existing read-only validator and the connection's
  dialect, and all supplied SQL goes through the `sql_execute` permission
  request before routing.
- Bounded: SQLite, DuckDB and Postgres only; a catalog row estimate above
  `max_rows_scanned` (default 5,000,000) for a bare table refuses with a
  suggestion to narrow the population; query timeouts return
  `skipped: timeout` instead of failing the caller.
- Analyst prompt: the existing "every clause must bite" sentence points at the
  check and says a vacuous filter is a reason to profile an alternative
  column, not to invent an exclusion.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…uts and all-row removal

Review follow-ups to the predicate-effect probe:

- When the catalog row estimate is unknown (views, SQLite without ANALYZE,
  unanalysed or partitioned Postgres tables, ambiguous relations) the output
  says `row_estimate: unknown — probe runs under the query timeout` instead
  of proceeding silently.
- Strict-schema fillers (`max_rows_scanned: 0`, blank predicates, empty
  `base_sql`) are treated as absent and produce the tool's own message, never
  a raw schema validation dump.
- A predicate that removes every row is flagged; counts over a `LIMIT`ed
  SELECT population say so.
- Postgres branch covered by tests (probe shape, `to_regclass`/`reltuples`
  guard, unknown-estimate path).
- The analyst prompt sentence ends with a period.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7ffe064d-4205-4754-b6a5-a817fcd053f2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T05:14:22.895857Z 388d088 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
            20 sessions behind this PR            

  CODEX HELPERS (20) — no commits
  (unattributed usage) · 8m.......2,725,142 tokens
  (unattributed usage) · 5m.......1,714,750 tokens
  (unattributed usage) · 55s........335,922 tokens
  (unattributed usage) · 6m.......2,486,747 tokens
  (unattributed usage) · 5m.......1,796,759 tokens
  (unattributed usage) · 3m.........720,051 tokens
  (unattributed usage) · 2m.........838,914 tokens
  (unattributed usage) · 4m.......1,295,474 tokens
  (unattributed usage) · 2m.........842,488 tokens
  (unattributed usage) · 7m.......3,181,004 tokens
  (unattributed usage) · 1m.........429,520 tokens
  (unattributed usage) · 2m.........667,093 tokens
  (unattributed usage) · 1m.........273,391 tokens
  (unattributed usage) · 3m.......1,115,285 tokens
  (unattributed usage) · 2m.......1,010,597 tokens
  (unattributed usage) · 1m.........573,229 tokens
  (unattributed usage) · 7m.......3,258,401 tokens
  (unattributed usage) · 2m.........948,477 tokens
  (unattributed usage) · 2m.........992,777 tokens
  (unattributed usage) · 1m.........517,613 tokens
--------------------------------------------------
TOTAL unpriced...................25,723,634 tokens
  counted: 20 sessions
  cache served 95% of input tokens
  full receipts + session ids: section below
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -
full receipts (20 sessions)
session id scope turns time tokens in / out cached
codex bf2d1d70 no commits 1 8m 77k / 13k 97%
codex e64a7d03 no commits 1 5m 68k / 10k 96%
codex 713bc962 no commits 1 55s 23k / 1.5k 93%
codex 566ad48a no commits 1 6m 66k / 10k 97%
codex 7c07411a no commits 1 5m 77k / 12k 96%
codex ccf47896 no commits 1 3m 64k / 2.6k 91%
codex ceb2694a no commits 1 2m 46k / 5.2k 94%
codex 442e2da6 no commits 1 4m 74k / 10k 94%
codex c9f2f13a no commits 1 2m 40k / 4.3k 95%
codex f644a3ae no commits 1 7m 114k / 13k 96%
codex e591dbc3 no commits 1 1m 43k / 1.8k 90%
codex 9686d19b no commits 1 2m 58k / 5.5k 91%
codex 7a6f0c75 no commits 1 1m 29k / 1.8k 89%
codex bafa5b46 no commits 1 3m 55k / 6k 95%
codex 66d75c2e no commits 1 2m 76k / 3.7k 92%
codex 97fb3d8c no commits 1 1m 51k / 2.3k 91%
codex 3f4dee57 no commits 1 7m 109k / 14k 97%
codex 9ae87189 no commits 1 2m 87k / 4.2k 91%
codex 0377aa8e no commits 1 2m 61k / 4.8k 94%
codex 01792805 no commits 1 1m 41k / 2.9k 92%

codex · bf2d1d70

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 19:43:21 UTC · 8m 56s     
            (unattributed usage) 100%             
         cache served 97% of input tokens         

(unattributed usage)......2,725,142 tok  (0 calls)
exec.............................0 tok  (24 calls)
followup_task.....................0 tok  (3 calls)
send_message......................0 tok  (6 calls)
spawn_agent.......................0 tok  (3 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL................................2,725,142 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · e64a7d03

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 19:43:47 UTC · 5m 58s     
            (unattributed usage) 100%             
         cache served 96% of input tokens         

(unattributed usage)......1,714,750 tok  (0 calls)
exec.............................0 tok  (19 calls)
send_message......................0 tok  (9 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL................................1,714,750 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · 713bc962

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
      Codex · Oct 12 2026 19:43:56 UTC · 55s      
            (unattributed usage) 100%             
         cache served 93% of input tokens         

(unattributed usage)........335,922 tok  (0 calls)
exec..............................0 tok  (6 calls)
send_message......................0 tok  (2 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL..................................335,922 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · 566ad48a

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 19:44:00 UTC · 6m 35s     
            (unattributed usage) 100%             
         cache served 97% of input tokens         

(unattributed usage)......2,486,747 tok  (0 calls)
exec.............................0 tok  (22 calls)
send_message.....................0 tok  (12 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL................................2,486,747 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · 7c07411a

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 20:08:16 UTC · 5m 23s     
            (unattributed usage) 100%             
         cache served 96% of input tokens         

(unattributed usage)......1,796,759 tok  (0 calls)
exec.............................0 tok  (21 calls)
followup_task......................0 tok  (1 call)
send_message......................0 tok  (2 calls)
spawn_agent.......................0 tok  (2 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL................................1,796,759 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · ccf47896

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 20:08:39 UTC · 3m 35s     
            (unattributed usage) 100%             
         cache served 91% of input tokens         

(unattributed usage)........720,051 tok  (0 calls)
exec.............................0 tok  (12 calls)
send_message......................0 tok  (3 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL..................................720,051 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · ceb2694a

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 20:09:01 UTC · 2m 24s     
            (unattributed usage) 100%             
         cache served 94% of input tokens         

(unattributed usage)........838,914 tok  (0 calls)
exec..............................0 tok  (9 calls)
send_message......................0 tok  (5 calls)
wait_agent.........................0 tok  (1 call)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL..................................838,914 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · 442e2da6

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 20:35:57 UTC · 4m 55s     
            (unattributed usage) 100%             
         cache served 94% of input tokens         

(unattributed usage)......1,295,474 tok  (0 calls)
exec.............................0 tok  (19 calls)
followup_task......................0 tok  (1 call)
send_message......................0 tok  (2 calls)
spawn_agent........................0 tok  (1 call)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL................................1,295,474 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · c9f2f13a

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 20:36:21 UTC · 2m 44s     
            (unattributed usage) 100%             
         cache served 95% of input tokens         

(unattributed usage)........842,488 tok  (0 calls)
exec.............................0 tok  (12 calls)
send_message......................0 tok  (5 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL..................................842,488 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · f644a3ae

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 20:57:23 UTC · 7m 20s     
            (unattributed usage) 100%             
         cache served 96% of input tokens         

(unattributed usage)......3,181,004 tok  (0 calls)
exec.............................0 tok  (29 calls)
list_agents........................0 tok  (1 call)
send_message......................0 tok  (2 calls)
spawn_agent.......................0 tok  (3 calls)
wait_agent.........................0 tok  (1 call)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL................................3,181,004 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · e591dbc3

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 20:57:44 UTC · 1m 03s     
            (unattributed usage) 100%             
         cache served 90% of input tokens         

(unattributed usage)........429,520 tok  (0 calls)
exec..............................0 tok  (6 calls)
send_message......................0 tok  (3 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL..................................429,520 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · 9686d19b

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 20:58:30 UTC · 2m 34s     
            (unattributed usage) 100%             
         cache served 91% of input tokens         

(unattributed usage)........667,093 tok  (0 calls)
exec..............................0 tok  (8 calls)
send_message......................0 tok  (3 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL..................................667,093 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · 7a6f0c75

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 21:01:09 UTC · 1m 24s     
            (unattributed usage) 100%             
         cache served 89% of input tokens         

(unattributed usage)........273,391 tok  (0 calls)
exec..............................0 tok  (5 calls)
send_message.......................0 tok  (1 call)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL..................................273,391 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · bafa5b46

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 21:21:23 UTC · 3m 24s     
            (unattributed usage) 100%             
         cache served 95% of input tokens         

(unattributed usage)......1,115,285 tok  (0 calls)
exec.............................0 tok  (15 calls)
followup_task......................0 tok  (1 call)
spawn_agent.......................0 tok  (2 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL................................1,115,285 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · 66d75c2e

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 21:21:46 UTC · 2m 48s     
            (unattributed usage) 100%             
         cache served 92% of input tokens         

(unattributed usage)......1,010,597 tok  (0 calls)
exec.............................0 tok  (10 calls)
send_message......................0 tok  (4 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL................................1,010,597 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · 97fb3d8c

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 21:21:51 UTC · 1m 10s     
            (unattributed usage) 100%             
         cache served 91% of input tokens         

(unattributed usage)........573,229 tok  (0 calls)
exec..............................0 tok  (7 calls)
send_message......................0 tok  (3 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL..................................573,229 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · 3f4dee57

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 23:08:06 UTC · 7m 41s     
            (unattributed usage) 100%             
         cache served 97% of input tokens         

(unattributed usage)......3,258,401 tok  (0 calls)
exec.............................0 tok  (29 calls)
list_agents........................0 tok  (1 call)
send_message......................0 tok  (4 calls)
spawn_agent.......................0 tok  (3 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL................................3,258,401 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · 9ae87189

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 23:08:35 UTC · 2m 16s     
            (unattributed usage) 100%             
         cache served 91% of input tokens         

(unattributed usage)........948,477 tok  (0 calls)
exec..............................0 tok  (9 calls)
send_message......................0 tok  (4 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL..................................948,477 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · 0377aa8e

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 23:08:42 UTC · 2m 28s     
            (unattributed usage) 100%             
         cache served 94% of input tokens         

(unattributed usage)........992,777 tok  (0 calls)
exec.............................0 tok  (12 calls)
send_message......................0 tok  (4 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL..................................992,777 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

codex · 01792805

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “# AGENTS.md instructions<INSTRUCTIONS># Resea…” 
    Codex · Oct 12 2026 23:13:35 UTC · 1m 56s     
            (unattributed usage) 100%             
         cache served 92% of input tokens         

(unattributed usage)........517,613 tok  (0 calls)
exec..............................0 tok  (7 calls)
send_message......................0 tok  (3 calls)

caveat: Codex request envelopes did not reconcile — request-level pricing disabled
--------------------------------------------------
TOTAL..................................517,613 tok
no price table matched
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

Generated by aireceipts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52f0e5ed74

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/altimate/tools/sql-check.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
…nd keeps caller positions

Independent-review follow-ups:

- A bare-table population is wrapped under the table's own name, so a
  predicate copied from the caller's WHERE clause (`orders.kind = 'a'`)
  works; SELECT populations keep the `t` alias and the description says so.
- The limited-population note fires only for a top-level `LIMIT`,
  `FETCH FIRST … ROWS ONLY` or `TOP` on the population statement, not for a
  LIMIT inside a subquery.
- Blank predicate entries are reported as skipped at their original
  position, so predicate numbers match the caller's array.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25baadb1c2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
Comment thread packages/opencode/src/altimate/tools/sql-check.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 25baadb. Configure here.

Comment thread packages/opencode/src/altimate/tools/sql-check.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/opencode/src/altimate/tools/sql-check.ts
Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
Comment thread packages/opencode/src/altimate/tools/sql-check.ts
anandgupta42 and others added 2 commits October 12, 2026 14:10
… in predicates and populations

A review finding of the highest severity tier: on PostgreSQL connections
allowed to signal other backends, `pg_terminate_backend(pid)` or
`pg_cancel_backend(pid)` passes the read-only validator as a boolean
expression. The shared validator now blocks backend-signalling calls
(including escaped function names and CR-comment variants) before any
query runs; harmless literals, comments, column names and scalar
expressions remain accepted.

Tests: `rejects backend-signaling predicate <case> before query execution`
and the population variant (14 cases).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9b84ed5e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
…trol and dblink functions

Three review findings of the highest severity tier, each with red-first
tests:

- The probe executes with the connector's read-only mode, so a
  user-defined function that writes cannot be reached through a predicate.
- `pg_promote` and `pg_reload_conf` are denied in predicates and
  populations.
- `dblink_send_query`, `dblink_connect` and `dblink_connect_u` are denied in
  predicates and populations.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3fa390c878

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/opencode/src/altimate/tools/sql-check.ts
@kilo-code-bot

kilo-code-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

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

SUGGESTION

File Line Issue
packages/opencode/src/altimate/tools/sql-check.ts 31 PURE_PREDICATE_FUNCTIONS omits SQLite/DuckDB pure date built-ins (strftime, julianday, unixepoch) and the bare ARRAY(…) constructor, so legitimate predicate_effect predicates are refused on two of three supported dialects
Files Reviewed (4 files)
  • packages/opencode/src/altimate/tools/sql-check.ts - 1 issue
  • packages/opencode/src/altimate/tools/sql-result-format.ts
  • packages/opencode/test/altimate/tools/sql-check.test.ts
  • packages/opencode/test/altimate/tools/sql-result-format.test.ts
Previous Review Summaries (7 snapshots, latest commit 214e47e)

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

Previous review (commit 214e47e)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/opencode/src/altimate/tools/sql-check.ts
  • packages/opencode/test/altimate/tools/sql-check.test.ts

Previous review (commit 9ae7d77)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • packages/drivers/src/local-engine-child-source.ts
  • packages/opencode/src/altimate/tools/sql-check.ts
  • packages/opencode/test/altimate/sql-check-postgres.test.ts

Previous review (commit 5a69583)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/opencode/src/altimate/tools/sql-check.ts 23 ls_\w*dir whitelists PostgreSQL filesystem-directory-listing functions (pg_ls_dir, pg_ls_logdir, pg_ls_waldir, pg_ls_archive_statusdir, pg_ls_tmpdir), leaking server filesystem paths and contradicting the stated "file functions denied" design.

SUGGESTION

File Line Issue
packages/opencode/src/altimate/tools/sql-check.ts 25 lo_creat is redundant with lo_\w*; likewise indexes_size with \w*_size and get_userbyid with get_\w*.
Files Reviewed (2 files)
  • packages/opencode/src/altimate/tools/sql-check.ts - 2 issues
  • packages/opencode/test/altimate/sql-check-postgres.test.ts - 0 issues

Fix these issues in Kilo Cloud

Previous review (commit c9cfe17)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/opencode/src/altimate/tools/sql-check.ts 190 lo_import_with_oid and lo_creat remain callable large-object write functions not matched by the denylist.
Files Reviewed (2 files)
  • packages/opencode/src/altimate/tools/sql-check.ts - 1 issue
  • packages/opencode/test/altimate/sql-check-postgres.test.ts - 0 issues

Fix these issues in Kilo Cloud

Previous review (commit 2f824cf)

Status: 6 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/opencode/src/altimate/tools/sql-check.ts 190 lo_from_bytea is missing from the large-object write denylist.
packages/opencode/src/altimate/tools/sql-check.ts 249 PostgreSQL parent-table estimates omit inherited child rows scanned by the probe.
packages/opencode/src/altimate/tools/sql-check.ts 286 SQLite partial-index statistics can understate a full table's scanned rows.
packages/opencode/src/altimate/tools/sql-check.ts 386 Timeout handling discards a local engine's in-memory or session-state loss warning.
packages/opencode/src/altimate/tools/sql-check.ts 224 A subquery or CTE LIMIT that bounds the population receives no caveat.

SUGGESTION

File Line Issue
packages/opencode/src/altimate/tools/sql-check.ts 331 The unconditional readOnly: true makes the Postgres-only readOnly spread redundant.
Files Reviewed (2 files)
  • packages/opencode/src/altimate/tools/sql-check.ts - 6 issues
  • packages/opencode/test/altimate/sql-check-postgres.test.ts - 0 issues

Fix these issues in Kilo Cloud

Previous review (commit 8e56751)

Status: 4 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/opencode/src/altimate/tools/sql-check.ts 249 PostgreSQL parent-table estimates omit inherited child rows scanned by the probe.
packages/opencode/src/altimate/tools/sql-check.ts 286 SQLite partial-index statistics can understate a full table's scanned rows.
packages/opencode/src/altimate/tools/sql-check.ts 385 Timeout handling discards a local engine's in-memory or session-state loss warning.
packages/opencode/src/altimate/tools/sql-check.ts 224 A subquery or CTE LIMIT that bounds the population receives no caveat.
Files Reviewed (8 files)
  • packages/drivers/src/duckdb.ts - 0 issues
  • packages/drivers/src/local-engine-child-source.ts - 0 issues
  • packages/drivers/src/sqlite.ts - 0 issues
  • packages/drivers/src/types.ts - 0 issues
  • packages/opencode/src/altimate/tools/sql-check.ts - 4 issues carried forward
  • packages/opencode/src/permission/next.ts - 0 issues
  • packages/opencode/test/altimate/sql-check-postgres.test.ts - 0 issues
  • packages/opencode/test/altimate/sql-check-predicate-effect.test.ts - 0 issues

Fix these issues in Kilo Cloud

The three prior critical findings are fixed at the current HEAD. No new inline findings were raised; existing comments were not duplicated. Review based on source and existing tests only; no code or tests were executed.

Previous review (commit 3fa390c)

Status: 7 Issues Found | Recommendation: Address before merge

Overview

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

CRITICAL

File Line Issue
packages/opencode/src/altimate/tools/sql-check.ts 622 A permission prompt for the population can skip a later denied predicate pattern.
packages/opencode/src/altimate/tools/sql-check.ts 190 dblink() can execute remote writes outside the local read-only transaction.
packages/opencode/src/altimate/tools/sql-check.ts 316 pg_try_advisory_lock() can persist a session-level lock on a pooled connection.

WARNING

File Line Issue
packages/opencode/src/altimate/tools/sql-check.ts 249 PostgreSQL parent-table estimates omit inherited child rows scanned by the probe.
packages/opencode/src/altimate/tools/sql-check.ts 286 SQLite partial-index statistics can understate a full table's scanned rows.
packages/opencode/src/altimate/tools/sql-check.ts 385 Timeout handling discards a local engine's in-memory or session-state loss warning.
packages/opencode/src/altimate/tools/sql-check.ts 224 A subquery or CTE LIMIT that bounds the population receives no caveat.
Files Reviewed (6 files)
  • packages/opencode/src/altimate/prompts/analyst.txt - 0 issues
  • packages/opencode/src/altimate/tools/sql-check.ts - 7 issues
  • packages/opencode/src/altimate/tools/sql-tokenize.ts - 0 issues
  • packages/opencode/test/agent/analyst-data-explorer.test.ts - 0 issues
  • packages/opencode/test/altimate/sql-check-postgres.test.ts - 0 issues
  • packages/opencode/test/altimate/sql-check-predicate-effect.test.ts - 0 issues

Fix these issues in Kilo Cloud

Review based on source and existing tests only; no code or tests were executed. Earlier active review comments were not duplicated.


Reviewed by deepseek-pro-latest · Input: 69.6K · Output: 62.7K · Cached: 1M

Review guidance: REVIEW.md from base branch feat/analyst-harness-dab-2026-10

Comment thread packages/opencode/src/altimate/tools/sql-check.ts
Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
Comment thread packages/opencode/src/altimate/tools/sql-check.ts
Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
Comment thread packages/opencode/src/altimate/tools/sql-check.ts
Comment thread packages/opencode/src/altimate/tools/sql-check.ts
…_effect`

- Read-only classification: deny `pg_logical_emit_message` (its
  non-transactional form is written to WAL immediately and survives the
  rollback), bare `dblink` (the synchronous form runs its string argument on a
  remote connection outside the local read-only transaction) and every
  `pg_advisory_lock` / `pg_try_advisory_lock` / `pg_advisory_xact_lock` variant
  (session-level locks survive ROLLBACK and the session returns to the pool).
  Applies to the population and to every predicate; case-insensitive and
  schema-qualified spellings covered.
- Permission: `PermissionNext.ask` evaluated patterns in order and returned a
  prompt on the first `ask`, so a later pattern with an explicit `deny` would
  execute once the earlier one was approved. It now evaluates every pattern
  before publishing the approval request (`upstream_fix`).
- Local engines honour `readOnly`: SQLite runs the probe under a scoped
  `query_only` pragma restored afterwards; DuckDB runs it in a READ ONLY
  transaction that is rolled back, and refuses to start one while the caller
  has its own transaction open rather than aborting it. Previously the flag was
  silently ignored on both engines.
- Regression tests for each denied function family, for the deny-before-prompt
  ordering, and for SQLite/DuckDB read-only enforcement (hidden sequence writes
  in a view and in a predicate subquery, pragma restoration after failure, and
  the active-transaction refusal).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 8 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
anandgupta42 and others added 2 commits October 12, 2026 16:28
…te_effect

pg_advisory_unlock, pg_advisory_unlock_shared and pg_advisory_unlock_all release session-level locks held by the pooled connection, and a read-only rollback does not undo that. The denylist now covers every pg_advisory_* / pg_try_advisory_* function; regression cases added for the three unlock variants.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… the predicate_effect branch

Resolves the conflict in `packages/drivers/src/duckdb.ts` by keeping the shared-engine generation tracking from the base and this branch's `readOnly` flag on the engine call.
@cursor

cursor Bot commented Oct 13, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 962a10f7-5127-45e8-8bfa-0981b2640611)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9fce7bad1e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
…s in read-only `sql_check` sources

The denylist named individual dblink functions, so `dblink_open`/`dblink_fetch`/`dblink_close` (a remote data-modifying cursor whose close commits) passed, and it omitted `pg_wal_replay_pause`/`pg_wal_replay_resume`, which change recovery state on a standby and are not undone by rollback. The list now matches `dblink\w*` and `pg_wal_replay_\w*`. Tests: dblink cursor open/fetch/close (incl. a data-modifying CTE), and both WAL replay controls, each rejected before query execution in plain, schema-qualified and commented spellings.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@cursor

cursor Bot commented Oct 13, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 724a32c4-b274-4bd6-bad5-6b51aa6d6aca)

@github-actions

Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

@cursor

cursor Bot commented Oct 13, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 4f9e1f33-a9eb-4008-b191-5cc1bc244621)

@github-actions

Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d41c01214

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
@cursor

cursor Bot commented Oct 13, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 5dd3daaa-d4bd-4b44-a88d-0c50392ab734)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b4953d4bc3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/altimate/tools/sql-check.ts
Comment thread packages/opencode/src/altimate/tools/sql-check.ts
…and guards the PostgreSQL estimate atomically

- Predicates may call only functions in a fixed allowlist of built-in pure functions (the earlier `PURE_PG_FUNCTIONS` names plus ordinary scalar built-ins); every other call, including schema-qualified and user-defined wrappers such as `emit_wrapper(id)` or DuckDB `postgres_execute(...)`, is refused before any SQL runs with the function named. The side-effect denylist stays as a second check. Applies to PostgreSQL, SQLite and DuckDB alike. Identifier handling preserves quoted names and folds only ASCII case.
- Bare-table PostgreSQL probes run the `pg_class`/`to_regclass` estimate and the aggregate in one statement, with the estimate condition gating population rows, so two pool clients can no longer see different relations (temporary tables, `search_path`) between the guard and the scan; an exceeded estimate returns `skipped: "estimate"` without a population scan.
- tests: wrapper, qualified, quoted and pg-prefixed calls refused on every dialect; scalar built-ins, casts and boolean grouping accepted; single-statement estimate guard, exceeded estimate gated, unknown estimate vs empty population, CTE name collisions.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@cursor

cursor Bot commented Oct 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 03b94af4-0da4-4b25-ab22-f37e5ab1158d)

@cursor

cursor Bot commented Oct 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 1e7e0c5d-2782-4999-9be7-cdb265db29b6)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5df7cfa97f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
Comment thread packages/opencode/src/altimate/tools/sql-check.ts
Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
Comment thread packages/opencode/src/altimate/tools/sql-check.ts
Comment thread packages/opencode/src/altimate/tools/sql-check.ts
anandgupta42 and others added 2 commits October 13, 2026 21:12
…inst the catalog and bounds local populations in one statement

- The built-in pure-function allowlist now applies to the population SQL as well as the predicates, on every dialect, so a DuckDB `postgres_execute(...)` or a PostgreSQL wrapper population is refused before any SQL runs.
- PostgreSQL: before the probe, one read-only `pg_operator` query and one `pg_proc` query (bound `ANY($1)` arrays) cover every operator and function name referenced by the population and predicates, including implicit operators behind `LIKE`/`IN`/`BETWEEN`/`IS DISTINCT FROM` and the `!=` alias; any definition outside `pg_catalog` refuses the probe with the name. DuckDB checks `duckdb_functions()` for non-internal macros the same way; SQLite has no SQL-level function catalog (commented).
- SQLite and DuckDB run the estimate and the aggregate on one population bounded to `cap + 1` rows in a single statement, so a concurrent peer cannot swap the relation between the guard and the scan; an exceeded bound returns `skipped: "estimate"`. PostgreSQL keeps its atomic catalog-estimate gate.
- Allowlist gains the SQLite/DuckDB date built-ins (`strftime`, `julianday`, `unixepoch`, `datetime`, `timediff`) and the bare `array` constructor.
- Drivers: the PostgreSQL connector forwards bind parameters on both the regular and byte-limited read paths; it previously dropped them.
- tests: wrapper and remote-execute populations refused per dialect; user-defined operator/overload/macro refused and built-in-only accepted after read-only catalog queries; implicit operators and trailing-sign splits resolved; SQLite/DuckDB single-statement bound with exceeded skip; date built-ins accepted; PostgreSQL bind forwarding on both read paths.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@cursor

cursor Bot commented Oct 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 1f333a9d-d168-4824-bbd1-d1ded7aece80)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ff8f08159

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/altimate/tools/sql-check.ts
Comment thread packages/opencode/src/altimate/tools/sql-check.ts
Comment thread packages/opencode/test/altimate/sql-check-postgres.test.ts
Comment thread packages/opencode/src/altimate/tools/sql-check.ts Outdated
anandgupta42 and others added 2 commits October 13, 2026 21:41
… the catalog; repairs the PostgreSQL test fixture

- Explicit casts (`x::type`, `CAST(x AS type)`) in populations and predicates are resolved against `pg_catalog.pg_type` with the same read-only bound catalog query; a target type outside `pg_catalog` refuses the probe before any SQL runs. Casts selected by a user-defined SOURCE type cannot be seen textually; the code comment and PR body disclose that.
- CTE declarations and their column lists are no longer mistaken for function calls, so the advertised `WITH population(id) AS (...) SELECT ...` form is accepted; projection, qualified and `count(*)` wildcards (including `DISTINCT ON`) are excluded from the operator catalog check while multiplication is still checked.
- `sql-check-postgres.test.ts` had been left outside the previous round's verification and was red on the branch: its fixture now answers the `pg_operator`/`pg_proc`/`pg_type` catalog queries (seedable), preserves bind arguments, and the unsafe-function cases assert the pure-function refusal with no population or probe SQL executed.
- tests: custom cast targets refused before the probe (predicate and population, `::` and `CAST`, qualified/quoted/array/typmod, Unicode-escaped), built-in casts accepted, CTE column lists accepted, wildcard populations accepted beside a seeded custom `*`, multiplication still checked; fixture controls for an ordinary population, seeded catalog rows and bind preservation.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…' into feat/analyst-v10-probe

# Conflicts:
#	packages/drivers/test/postgres-readonly.test.ts
@cursor

cursor Bot commented Oct 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: f9b32441-10a3-4c79-b947-9417a97410b7)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 902ac47d4e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/altimate/tools/sql-check.ts
Comment thread packages/opencode/src/altimate/tools/sql-check.ts
Comment thread packages/opencode/src/altimate/tools/sql-check.ts
Comment thread packages/opencode/test/altimate/sql-check-predicate-effect.test.ts Outdated
anandgupta42 and others added 2 commits October 13, 2026 22:05
…cepts FILTER/OVER clauses

- Permission rules are matched per pattern, so a `sql_execute` deny rule scoped to a column-and-table combination (`*secret_col*FROM*sensitive_table*`) matched neither the population nor the predicate on its own although the probe joins them. The tool now also asks for the combined probe in the shape it executes (`SELECT COUNT(*) FILTER (WHERE <predicate>) … FROM (<population>) AS t`), so such a rule denies before any SQL runs.
- `FILTER (…)`, `OVER (…)`, `WITHIN GROUP (…)`, `USING (…)` and similar clause introducers are no longer mistaken for function calls, so valid aggregate and window populations are accepted while unknown functions are still refused.
- The permission regression tests use the package `it.instance`/`TestInstance` fixture instead of a manual `Instance.provide`/`dispose` lifecycle.
- tests: combined-probe deny before SQL and a non-matching control; FILTER/OVER population accepted and `filterx(id)` refused.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@cursor

cursor Bot commented Oct 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 46ddc0cc-cfbf-4256-ae1f-b3836f664323)

@github-actions

Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

3 similar comments
@github-actions

Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

@github-actions

Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

@github-actions

Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 388d088b96

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +969 to +973
// Text cannot determine whether a cast's source column has a user-defined type.
const typeNames = queries.map((sql) => postgresCasts(sql).map((target) => target.name))
const types = [...new Set(typeNames.flat())]
if (types.length) {
const [type] = await run(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Validate the conversion function for explicit casts

When a PostgreSQL source column has a user-defined type with an explicit cast to a built-in target such as custom_col::boolean, this records only boolean and therefore finds no non-pg_catalog target type. PostgreSQL casts can execute the function stored in pg_cast.castfunc, so a conversion function can still invoke dblink_send_query or another nontransactional side effect for every row. Fresh evidence after the prior explicit-cast fix is that the current catalog query validates only the target type name, not the source type or resolved cast function; resolve the cast through pg_cast and require its implementation to be trusted. PostgreSQL pg_cast documentation

Useful? React with 👍 / 👎.

Comment on lines +935 to +936
const queries = [population, ...predicates]
const functionNames = queries.map((sql) => pureFunctions(sql, dialect))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Inspect functions hidden behind PostgreSQL views

When base_sql is SELECT * FROM reporting_view and that view's defining query calls a side-effecting wrapper or dblink_send_query, pureFunctions sees no call in the submitted text, so the catalog checks pass and the view body executes during the probe despite the local read-only transaction. PostgreSQL runs a view's defining query whenever the view is referenced. Fresh evidence after the wrapper fix is that the new validation only maps pureFunctions over caller-supplied SQL and performs no pg_rewrite or view-definition lookup; referenced views must be expanded and validated, or probes must use credentials incapable of those effects. PostgreSQL CREATE VIEW documentation

Useful? React with 👍 / 👎.

)

// Predicate probes and their populations accept only these pure functions; keep this list flat and sorted.
const PURE_PREDICATE_FUNCTIONS = new Set([

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Permit standard built-in window functions

When a valid population uses a standard window function, for example SELECT *, row_number() OVER (PARTITION BY account_id ORDER BY created_at) AS rn FROM orders, function validation rejects row_number because the allowlist contains aggregate functions such as count and accepts the OVER clause but omits the actual general-purpose window functions. This prevents predicate_effect from checking common ranked or deduplicated populations on both PostgreSQL and DuckDB; add trusted built-ins such as row_number, rank, dense_rank, lag, and lead to the dialect-aware allowlist. PostgreSQL window-function documentation, DuckDB window-function documentation

Useful? React with 👍 / 👎.

Comment on lines +847 to +850
const bare =
/^(?:"(?:[^"]|"")+"|[A-Za-z_][A-Za-z0-9_$]*)(?:\s*\.\s*(?:"(?:[^"]|"")+"|[A-Za-z_][A-Za-z0-9_$]*)){0,2}$/.test(
sql.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.

P2 Badge Accept SQLite's supported bare-table quoting forms

When a SQLite table is supplied as a bare reference using SQLite-native quoting, such as [order details] or `order details`, this regex does not recognize it as a table and instead passes the identifier alone to readSql, which rejects it for not being a SELECT. SQLite explicitly supports both square brackets and grave accents for quoted identifiers, and the tokenizer already recognizes those forms, so the bare-table parser and alias extraction should accept them for the SQLite dialect. SQLite identifier-quoting documentation

Useful? React with 👍 / 👎.

Comment on lines +887 to +888
if (!/^\s*\(/.test(functions.slice(match.index + match[0].length))) continue
if (declarations.has(match.index)) continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exclude derived-table column aliases from call validation

When a valid population supplies a column list for a derived table, such as SELECT id FROM (VALUES (1), (2)) AS v(id), this scan treats v( as a function call and rejects it because only CTE declaration positions are excluded. DuckDB explicitly supports this alias-column syntax, including (VALUES (2), (4)) _(x), and PostgreSQL supports the same derived-table form; record derived-table and table-function alias lists as declarations rather than requiring their aliases to appear in the function allowlist. DuckDB FROM-clause documentation

Useful? React with 👍 / 👎.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant