kaxil commented on code in PR #77198:
URL: https://github.com/apache/airflow/pull/77198#discussion_r4619446474


##########
providers/common/ai/src/airflow/providers/common/ai/plugins/hitl_review.py:
##########
@@ -135,20 +140,20 @@ def _read_xcom_by_prefix(
                 include_node_regions=False,
             )
             entity = read.column_descriptions[0]["entity"]
-            query = read.with_only_columns(entity.key, 
entity.value).where(entity.key.like(f"{prefix}%"))
+            query = read.where(entity.key.like(f"{prefix}%"))
         else:
-            query = select(XComModel.key, XComModel.value).where(
+            query = select(XComModel).where(
                 XComModel.dag_id == dag_id,
                 XComModel.run_id == run_id,
                 XComModel.task_id == task_id,
                 XComModel.map_index == map_index,
                 XComModel.key.like(f"{prefix}%"),
             )
         result: dict[int, Any] = {}
-        for key, value in session.execute(query).all():
-            suffix = key[len(prefix) :]
+        for row in session.scalars(query):
+            suffix = row.key[len(prefix) :]
             if suffix.isdigit():
-                result[int(suffix)] = value
+                result[int(suffix)] = _load_xcom_value(row)

Review Comment:
   The feedback endpoint stores the reviewer's text as-is, and this now reads 
it back through the backend. With `XComObjectStorageBackend`, feedback that is 
a URL under `xcom_objectstorage_path` (say another Dag's XCom file) gets opened 
with the API server's storage credentials and returned in `conversation`, while 
the permission check only covered this Dag, so the new docs line about 
plugin-written values coming back unchanged doesn't hold for feedback. Can the 
plugin write feedback in a shape the backend never resolves (e.g. a 
`{"feedback": ...}` dict unwrapped on read)?



##########
providers/common/ai/tests/unit/common/ai/plugins/test_hitl_review.py:
##########
@@ -1736,6 +1737,126 @@ def test_reject_returns_session(self, test_client):
         assert response.json()["status"] == "rejected"
 
 
+class _ReferenceXComBackend(BaseXCom):
+    """Keep values outside the metadata database and store a reference there, 
as object-storage backends do."""
+
+    stored: dict[str, Any] = {}
+
+    @staticmethod
+    def deserialize_value(result) -> Any:
+        value = BaseXCom.deserialize_value(result)
+        if isinstance(value, str):
+            return _ReferenceXComBackend.stored.get(value, value)
+        return value
+
+
+class _LoadValueReferenceXComBackend(BaseXCom):
+    """Resolve the same references through ``load_value`` only, as 
``store_value`` backends do."""
+
+    @classmethod
+    def load_value(cls, stored) -> Any:
+        value = super().load_value(stored)
+        if isinstance(value, str):
+            return _ReferenceXComBackend.stored.get(value, value)
+        return value
+
+
+class TestReferenceStoringXComBackend:
+    """Review XComs a custom backend stored as references are read through the 
backend."""
+
+    PARAMS = {"dag_id": TEST_DAG_ID, "run_id": TEST_RUN_ID, "task_id": 
TEST_TASK_ID}
+
+    @pytest.fixture(
+        autouse=True,
+        params=[
+            pytest.param(_ReferenceXComBackend, id="deserialize_value"),
+            pytest.param(
+                _LoadValueReferenceXComBackend,
+                id="load_value",
+                marks=pytest.mark.skipif(
+                    not hasattr(BaseXCom, "load_value"), reason="This Airflow 
version has no load_value hook"
+                ),
+            ),
+        ],
+    )
+    def setup(self, request, monkeypatch, dag_maker, session):
+        
monkeypatch.setattr("airflow.providers.common.ai.plugins.hitl_review.XCom", 
request.param)

Review Comment:
   The plugin on main has no `XCom` attribute, so this `setattr` raises 
`AttributeError` during setup there, and the `deserialize_value` cases error 
instead of failing with the `AgentSessionData` validation error. Passing 
`raising=False` would make them fail for the real reason.



-- 
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]

Reply via email to