← Back to Pull requests

[BugFix] Return 400 for an empty SQL cursor (#5983) #5992

Closed
unknown closed this pull request without merging on Nov 30, 2026 01:24 UTC
View on GitHub
unknown unknown commented on Nov 26, 2026 10:52 UTC
Author

Description


A request with an empty cursor (POST _plugins/_sql or POST _plugins/_sql/close with {"cursor": ""}) returned HTTP 500 and StringIndexOutOfBoundsException. This is a bad request, so it should return 400.

RestSqlAction.isLegacyCursor called cursor.substring(0, 1) without checking for an empty string. Both endpoints are handled by RestSqlAction, and an empty cursor never reached a meaningful legacy or v2 engine path because it crashed first.

This change:

  • Rejects an empty or blank cursor in SqlRequestFactory with IllegalArgumentException("Cursor is empty or invalid"), which RestSqlAction already maps to HTTP 400 on both /_plugins/_sql and /_plugins/_sql/close.

  • Makes isLegacyCursor skip empty cursors so substring(0, 1) cannot throw if an empty cursor is constructed some other way.
  • Related Issues


    Resolves #5983

    Check List


  • New functionality includes testing.

  • - Unit tests in SqlRequestFactoryTest (valid, empty, and blank cursors) and RestSqlActionTest (empty cursor is a 400, isLegacyCursor does not throw on empty or null and still detects legacy vs v2 cursors).
    - Integration tests in CursorIT for POST _plugins/_sql and POST _plugins/_sql/close with {"cursor": ""}, asserting HTTP 400 and the error details.
  • New functionality has been documented.

  • - [ ] New functionality has javadoc added.
    - [ ] New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.

  • API changes companion pull request created.

  • Commits are signed per the DCO using --signoff or -s.

  • Public documentation issue/PR created.
  • Tested locally with ./gradlew :legacy:spotlessCheck :integ-test:spotlessCheck :legacy:test (1534 tests, 0 failures, 26 skipped) and ./gradlew :integ-test:integTest -Dtests.class="org.opensearch.sql.legacy.CursorIT" -Dtests.method="emptyCursor*" -DignorePrometheus (both new tests passed).

    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
    For more information on following Developer Certificate of Origin and signing off your commits, please check here.

    Diff: 317 lines (+237 / -80) across 3 files Reviewer: Swiddis Review duration: 5191m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 317 lines diff across 3 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.345
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #5992"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.4% (MEDIUM) · Higher = larger blast radius
    45.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.9% · Safe to merge
    17.9%