kaxil commented on code in PR #76157: URL: https://github.com/apache/airflow/pull/76157#discussion_r4666506030
########## providers/databricks/docs/operators/genie_operator.rst: ########## @@ -0,0 +1,97 @@ + .. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + .. http://www.apache.org/licenses/LICENSE-2.0 + + .. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + + + +.. _howto/operator:DatabricksGenieOperator: + +Ask a Databricks Genie space +============================ + +Use :class:`~airflow.providers.databricks.operators.genie.DatabricksGenieOperator` to ask a Genie space +one question as a standalone task. The operator returns the same bounded result as +:ref:`DatabricksGenieHook <howto/databricks-genie>` through XCom: the space, conversation and message +IDs, the message status, the text answer, generated queries and capped query results. + +.. exampleinclude:: /../../databricks/tests/system/databricks/example_databricks_genie.py + :language: python + :start-after: [START howto_operator_databricks_genie] + :end-before: [END howto_operator_databricks_genie] + +By default the operator starts a new conversation. Set ``conversation_id`` to ask a follow-up in an +existing conversation. The operator never deletes or cancels conversations, so a conversation you +supply stays yours. + +Set ``deferrable=True`` to release the worker while Genie works. The trigger only reads the message +status; the worker fetches the answer and query results when the task resumes, so the trigger event +never carries Genie output. + +.. exampleinclude:: /../../databricks/tests/system/databricks/example_databricks_genie.py + :language: python + :start-after: [START howto_operator_databricks_genie_deferrable] + :end-before: [END howto_operator_databricks_genie_deferrable] + +``timeout`` limits how long one try waits for the answer. Timing out does not cancel the message. + +Durable execution +----------------- + +On Airflow 3.3 and later the operator is durable by default. It stores the conversation and message +IDs in the :doc:`task state store <apache-airflow:core-concepts/task-state-store>` before it waits, so +a retry after a worker crash, a timeout or a failed trigger reconnects to the same message instead of +asking again. See :doc:`apache-airflow:core-concepts/resumable-tasks` for how resumable tasks work. +On retry the operator checks the stored message: + +* A message that is still running is awaited again. +* A completed message returns its answer without asking again. +* A message that failed, was cancelled or whose result expired is asked again in a new message. +* A stored message that no longer exists (Genie answers 404), or that was asked for a different + space, conversation or question, is asked again. + +Genie may also answer 403 for a message that does not exist, so it does not reveal which resources +are there. The operator treats only 404 as a missing message, so a stored message that Genie hides +behind a 403 fails the try instead of being asked again. Retrying or clearing the task fails the same +way, because the stored IDs stay in the task state for that DAG run. First check that the connection +can still read the Genie space and fix its permissions if it cannot. If access is fine, the stored +message is gone. To recover that DAG run, either set ``conversation_id`` and ``message_id`` to attach Review Comment: On 3.4 and later a task clear discards the task state unless "keep task state" is ticked (`keep_task_state` defaults to `False`), so a default clear asks the question again instead of failing the same way. The unconfirmed-submission case below has the same gap, which I missed earlier: `AirflowFailException` skips retries, so the next try is a clear, and a default clear drops the marker too and asks Genie a second time with no refusal. Setting `message_id` in the Dag also sticks for every later run, which then returns this old answer without asking. Could both sections say what a default clear does, and show a run-scoped form like `message_id="{{ params.genie_message_id }}"` for attaching? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
