Skip to content

execute_ppl_query tool returns success even when query execution fails #10701

@goyamegh

Description

@goyamegh

Bug Description

The execute_ppl_query assistant action in the Explore plugin always returns success: true even when the PPL query execution fails on the UI. This creates a misleading response for tools/agents that rely on the execution status.

Steps to Reproduce

  1. Use the execute_ppl_query assistant action with an invalid PPL query
  2. Observe that the tool returns {"success": true, "executed": true, "message": "Query updated and executed"}
  3. Check the UI - the query actually failed with an error

Expected Behavior

The tool should return success: false when the query execution fails, along with the actual error message.

Current Code Issue

In src/plugins/explore/public/components/query_panel/actions/ppl_execute_query_action.tsx, the handler immediately returns success after dispatching the action:

dispatch(loadQueryActionCreator(services, setEditorTextWithQuery, args.query));

return {
  success: true,  // ❌ Always returns true
  executed: true,
  query: args.query,
  message: 'Query updated and executed',
};

Proposed Solution

The handler should wait for the query execution to complete and check the actual execution status:

handler: async (args: any) => {
  try {
    const shouldExecute = args.autoExecute !== false;

    if (shouldExecute) {
      // Wait for the query execution to complete
      const result = await dispatch(loadQueryActionCreator(services, setEditorTextWithQuery, args.query));
      
      // Check if execution was successful
      const state = getState();
      const queryStatus = selectQueryStatus(state); // Need to implement selector
      
      if (queryStatus.status === 'failed') {
        return {
          success: false,
          error: queryStatus.error || 'Query execution failed',
          query: args.query,
        };
      }

      return {
        success: true,
        executed: true,
        query: args.query,
        message: 'Query updated and executed',
      };
    } else {
      // Just update the editor without executing
      setEditorTextWithQuery(args.query);
      return {
        success: true,
        executed: false,
        query: args.query,
        message: 'Query updated',
      };
    }
  } catch (error) {
    return {
      success: false,
      error: error instanceof Error ? error.message : 'Unknown error',
      query: args.query,
    };
  }
}

Additional Changes Needed

  1. Add query status selector: Create a selector to get the current query execution status from the Redux state
  2. Make loadQueryActionCreator return a result: Modify the action creator to return execution results
  3. Update error handling: Ensure proper error propagation from the query execution layer

Impact

This bug affects any external tools or agents that rely on the execute_ppl_query action to determine if a query executed successfully. Currently, they cannot distinguish between successful and failed executions.

Files to Modify

  • src/plugins/explore/public/components/query_panel/actions/ppl_execute_query_action.tsx
  • src/plugins/explore/public/application/utils/state_management/actions/query_editor/load_query/load_query.ts
  • Add query status selectors in the state management layer

Environment

  • OpenSearch Dashboards version: Latest main branch
  • Plugin: Explore plugin
  • Component: Assistant actions / PPL query execution

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions