Skip to content

fix: expose SQL result truncation and reject duplicate output columns - #331

Open
seyoung4503 wants to merge 1 commit into
fix/codex-failed-case-selectionfrom
fix/sql-result-completeness
Open

seyoung4503 wants to merge 1 commit into
fix/codex-failed-case-selectionfrom
fix/sql-result-completeness

Conversation

@seyoung4503

Copy link
Copy Markdown
Collaborator

SQL tool responses can lose information deterministically: the renderer labels a bounded fetch as total rows, and SQLAlchemy row-to-dict conversion silently overwrites duplicate column names.

Fetch one lookahead row after the unchanged safety decision, retain only the configured budget, and report fetched/displayed counts, fetch/display truncation and whether safety changed the SQL. Counts describe the executed SQL, not source-table cardinality. Detect duplicate result-column names before dict conversion, including empty results, and return an actionable error requiring unique aliases instead of silently losing values. Existing unique aliases execute normally.

Verification: six real MCP stdio regressions failed before implementation. After the fix, the full root suite has 267 passed and 1 skipped; Ruff and diff checks pass. Coverage includes exact boundary, overflow, empty results, display-only truncation, preserved safety SQL cap, duplicate labels and successful retry with unique labels. A model-free replay of the existing local003 query against the read-only benchmark DB through actual MCP confirms fetched_rows=1000, displayed_rows=50 and fetch_truncated=true. Evidence is committed under bench/accuracy/mcp-review-results/deterministic-result-completeness. This demonstrates result fidelity, not a benchmark accuracy increase.

No prompt changes. Based on #326, independently of later prompt experiments. SQLAlchemy duplicate-label validation covers that adapter; other adapters cannot recover columns already collapsed by an upstream JSON API. No merge.

Reuse: existing RunSQL, _render_rows, SqlAlchemyExplorer and actual stdio test fixture. No new production functions; production net +21 lines. Existing display limit is named, not changed. No environment variables or deployment changes.

Principle Result Evidence
Reuse O Existing execution and rendering paths; no new production functions
Cause O Lookahead identifies fetch truncation; duplicate check prevents dict overwrite
Logging O Completion records scope, fetched count and truncation; errors use existing failure path
Error handling O Duplicate columns raise through registry/MCP isError; no silent fallback
Environment N/A No new reads or variables
Comments O Constraints explained without issue-number comments
Verification O Red-before/green-after actual MCP tests; 267 passed, 1 skipped; Ruff/diff clean; no CODE MAP generator exists
Authorization O Branch/PR only
Call path O MCP receipt -> safety -> existing adapter -> validated mappings -> bounded display
Sync/async O Existing to_thread DB worker; one execution implementation
Configuration O Existing row limits retained; lookahead is one-row completeness probe; no deployment changes

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