Skip to content

fix(server): accept curation preview SQL that ends in a comment - #741

Merged
kstonekuan merged 1 commit into
Hebbian-Robotics:mainfrom
hoangchunghien:fix/curation-preview-trailing-comment
Oct 28, 2026
Merged

kstonekuan merged 1 commit into
Hebbian-Robotics:mainfrom
hoangchunghien:fix/curation-preview-trailing-comment

Conversation

@hoangchunghien

@hoangchunghien hoangchunghien commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #738.

Preview wraps the caller's SQL in subqueries (DESCRIBE, the LIMIT projection, the count, SUMMARIZE). Two endings broke the wrapper:

  • SELECT 1 AS value -- end: the line comment swallowed the wrapper's closing parenthesis.
  • SELECT 1 AS value; -- end (and ; /* end */): _stripped_sql_or_refuse only drops a semicolon at the very end of the string, so this one stayed inside the subquery.

The fix is a small _subquery_body step at the top of run_preview. It finds the terminator the way the SDK does in src/hflow/curation.py (the last token DuckDB does not classify as a comment, by UTF-8 byte offset), and ends the body on a new line when the SQL ends in a comment. SQL without a trailing comment is passed through unchanged, so the sql returned for ordinary queries is the same as before. Report, pin and saved queries are untouched: they do not wrap the SQL, and they keep the user's text as written.

Tests in packages/hflow-server/tests/test_server_curation_preview.py:

  • the issue's two queries, plus ; /* end */ and a trailing newline, return the same rows and count as SELECT 1 AS value, with and without stats: true
  • 'a; -- not a comment /* nor this */ tiếng Việt;' inside a string literal comes back intact
  • SELECT 1 AS value; SELECT 2 -- end is still refused as not a single SELECT
  • the returned sql for a query without a comment is unchanged

9 of the 11 new tests fail on main and pass with the fix; the other two (the multi-statement refusal and the unchanged sql) are guards that pass either way. uv sync --locked, ruff check --fix, ruff format and ty check are clean. The full suite has 2586 passed, 8 skipped and 1 failure, tests/test_lerobot_converter.py::test_success_label_omitted_when_source_has_no_outcome_feature, which also fails in a full run on main at 7d202bc and passes on its own. It looks order-dependent (connection has an unfinished result from execute(), DuckDB 2), not related to this change.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Preview wraps the caller's SQL in subqueries. A trailing line comment
swallowed the wrapper's closing parenthesis, and a semicolon followed by a
comment was not removed, so both returned a 400 that report accepts.

Find the terminator the way the SDK does (the last non-comment DuckDB
token, by UTF-8 byte offset), and end the body on a new line when it ends
in a comment. SQL without a trailing comment is passed through unchanged,
and semicolons or comment markers inside strings keep their meaning.

Fixes Hebbian-Robotics#738
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Fixes preview queries that end in comments by removing a trailing statement terminator and adding a newline before wrapping the query.

  • Curation previews accept SQL that ends in a comment.

Reviews (1) · Last reviewed commit: "fix(server): accept curation preview SQL..." · Reviewed by Greptile

@kstonekuan kstonekuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix. Ruff, ty, and the full suite pass (2,548 passed); reverting the fix fails nine regression cases. Please leave the starter pool for newcomers next time. I’d welcome a real-corpus test run and a report of what breaks or feels awkward.

@kstonekuan
kstonekuan merged commit 82c4cc7 into Hebbian-Robotics:main Oct 28, 2026
5 checks passed
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.

Curation preview rejects queries ending in a line comment

2 participants