Skip to content

fix(sqlite): attribute result-column limit to columns instead of data… - #6388

Closed
ahmed-husssain wants to merge 1 commit into
morluto:mainfrom
ahmed-husssain:fix/sqlite-column-limit-attribution
Closed

ahmed-husssain wants to merge 1 commit into
morluto:mainfrom
ahmed-husssain:fix/sqlite-column-limit-attribution

Conversation

@ahmed-husssain

@ahmed-husssain ahmed-husssain commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #6292.
When inspecting an SQLite table with more selected columns than SQLite's result-column limit (SQLITE_MAX_COLUMN), the engine returns SQLITE_ERROR with message "too many columns in result set". The worker previously fell back to format classification on path, reporting healthy databases as invalid.

Attribute result-column limits to column-selection in readRows so the error identifies columns as the failing argument and preserves the SQLite reason.

Problem and expected behavior

  • Smallest trigger: inspect_sqlite_database with >2,000 columns (e.g. columns: Array(2001).fill("email")).
  • Violated invariant: Rejections must attribute failures to the argument requiring correction (columns), preserve the engine's reason, and avoid classifying healthy database files as invalid/malformed.
  • Expected behavior: Rejection targets path: ["columns"] with reason: "invalid_format" and message "too many columns in result set". Malformed files continue reporting format error on path.

Change and scope

  • In src/sqlite/SqliteDatabaseInspection.ts: catch "too many columns in result set" in readRows and throw SqliteInspectionFailure("column-selection", message).
  • Reuses the existing "column-selection" protocol and error mapping in SqliteDatabaseWorkerExecution.ts (rejectedArgument["column-selection"] = "columns").
  • Contribution scope: not applicable (ordinary bug fix within existing SQLite provider boundary).

Contract and boundary impact

  • Semantic owner and earliest changed stage: SqliteDatabaseInspection.ts (query preparation / execution).

  • Contribution scope fit and linked maintainer decision: not applicable.

  • CLI and MCP/tool-catalog contract: Unchanged schema. Identifies columns rather than path as the invalid argument when result-column limits are exceeded.

  • Provider, bridge, target-format, or platform compatibility: Standard SQLite result-column limit behavior.

  • Evidence, artifact, provenance, or reconstruction contract: Database files remain read-only and unmutated.

  • Read existing files or captured data.

  • Launch or attach to a process.

  • Inject instrumentation or run scripts/code.

  • Change process memory, registers, files, or configuration.

  • Contact network services.

  • Recover protected code or work around protections.

  • Documentation or usability only; no target interaction.

  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:

    • tests/boundary/sqlite/sqliteDatabaseInspection.test.ts: asserts inspectSqliteDatabaseSnapshot throws SqliteInspectionFailure with reason: "column-selection" when result-column limits are exceeded.
    • tests/acceptance/sqliteDatabaseCli.test.ts: verifies MCP tool response reports path: ["columns"] on >2000 columns while genuine malformed control files report path: ["path"].
  • Base reproduction: Base revision threw raw ERR_SQLITE_ERROR and returned Selected SQLite database is invalid (too many columns in result set) targeting path: ["path"].

  • User-visible CLI/MCP output:

    {
      "error": {
        "code": "invalid_request",
        "category": "invalid_input",
        "retryable": false,
        "details": {
          "issues": [
            {
              "path": ["columns"],
              "reason": "invalid_format",
              "message": "too many columns in result set"
            }
          ]
        }
      }
    }
  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • node node_modules/vitest/vitest.mjs run tests/boundary/sqlite/sqliteDatabaseInspection.test.ts — PASS (25 passed, 1 skipped)
  • node node_modules/vitest/vitest.mjs run tests/acceptance/sqliteDatabaseCli.test.ts -t "attributes SQLite result-column limits" — PASS (1 passed, 14 skipped)
  • npx oxfmt --check src/sqlite/SqliteDatabaseInspection.ts tests/acceptance/sqliteDatabaseCli.test.ts tests/boundary/sqlite/sqliteDatabaseInspection.test.ts — PASS (all matched files formatted)
  • npm run check:fast — PASS (Turbo typecheck and oxlint clean)

Compatibility, safety, and release

  • Breaking changes or migration steps: None.
  • Real Hopper/Ghidra, browser, or OS coverage: SQLite inspection provider on Node.js runtime.
  • Package or release metadata impact: None.
  • Security, privacy, process, or containment review: Read-only query execution in ephemeral snapshot worker; no mutation or credential exposure.

Author readiness

Human owner: @ahmed-husssain

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 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-23T11:40:26.779878Z 6fd3b23 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.

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain.

Summary

Attributes SQLite result-column limits to columns instead of marking the database file invalid.

  • SQLite column-limit errors now point to the selected columns.

Reviews (3) · Last reviewed commit: "fix(sqlite): attribute result-column lim..." · Reviewed by Greptile

@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: c33514550d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/sqlite/SqliteDatabaseInspection.ts Outdated
}
} catch (cause: unknown) {
const message = cause instanceof Error ? cause.message : String(cause);
if (message.includes("too many columns in result 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 Match the result-column diagnostic exactly

When a VIRTUAL generated column calls an unavailable deterministic function whose quoted name contains this text (for example, "too many columns in result set"(id)), SQLite raises unknown function: too many columns in result set(). This substring check intercepts that ordinary generated-column failure before columnEvaluationFailure, so CLI/MCP now rejects columns as malformed and drops the existing readable-column remediation; only classify the exact native result-limit error, ideally also checking SQLITE_ERROR or the configured column limit.

AGENTS.md reference: AGENTS.md:L31-L31

Useful? React with 👍 / 👎.

…base format

When inspecting a SQLite table with more selected columns than SQLite's result-column limit, the engine returns SQLITE_ERROR with message 'too many columns in result set'. The worker previously fell back to format classification on path, reporting healthy databases as invalid.

Match the SQLite error code and diagnostic message exactly in readRows to attribute result-column limits to column-selection without misclassifying virtual generated columns calling functions named like the error message. Gate the acceptance test on SQLITE_NATIVE_LIMITS_AVAILABLE for Node.js 22 compatibility where native limits are unsupported.

Fixes morluto#6292
@ahmed-husssain
ahmed-husssain force-pushed the fix/sqlite-column-limit-attribution branch from 1889624 to 6fd3b23 Compare October 23, 2026 11:37

@baron baron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AI-assisted review confirms that the new exact-match guard fixes the earlier generated-function false positive, but the main failure family remains wrong at SqliteDatabaseInspection.ts:607–613.

A readable one-column database selected 2,000 times succeeds; 2,001 valid repeated selections hit the native result-column limit. This head emits column-selection, which the worker consumer projects as invalid_request/invalid_format on columns. The file and names are not malformed: capacity is exhausted. The new tests pin the wrong format classification and omit the effective limit/selected count.

Carry a typed capacity reason from the actual connection limit through the strict worker protocol, with observed counts and smaller/split-projection recovery. Preserve genuine unknown-column/input failures and caller repetitions. #6327 already implements this structural alternative; coordinate rather than merge both.

Inspector and real-worker probes confirmed the boundary; public error consequences were source-traced, not a local full CLI/MCP run. Unrelated GDB CI failures were retained, not treated as flakes. No blind rerun recommended before correcting semantics.

@morluto morluto added bug Something isn't working provider: sqlite Analysis provider / engine: sqlite labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working provider: sqlite Analysis provider / engine: sqlite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] SQLite result-column limits report a healthy database as malformed

3 participants