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


##########
providers/common/ai/src/airflow/providers/common/ai/operators/agent.py:
##########
@@ -91,28 +159,60 @@ def __init__(
         self.enable_tool_logging = enable_tool_logging
         self.agent_params = agent_params or {}
 
+        self.enable_hitl_review = enable_hitl_review
+        self.max_hitl_iterations = max_hitl_iterations
+        self.hitl_timeout = hitl_timeout
+        self.hitl_poll_interval = hitl_poll_interval
+
+        if self.enable_hitl_review and not AIRFLOW_V_3_1_PLUS:
+            raise AirflowOptionalProviderFeatureException(
+                "Human in the loop functionality needs Airflow 3.1+."
+            )
+
     @cached_property
     def llm_hook(self) -> PydanticAIHook:
         """Return PydanticAIHook for the configured LLM connection."""
         return PydanticAIHook(llm_conn_id=self.llm_conn_id, 
model_id=self.model_id)
 
-    def execute(self, context: Context) -> Any:
+    def _build_agent(self) -> Agent[None, Any]:
+        """Build and return a pydantic-ai Agent from the operator's config."""
         extra_kwargs = dict(self.agent_params)
         if self.toolsets:
             if self.enable_tool_logging:
                 extra_kwargs["toolsets"] = 
wrap_toolsets_for_logging(self.toolsets, self.log)
             else:
                 extra_kwargs["toolsets"] = self.toolsets
-        agent: Agent[None, Any] = self.llm_hook.create_agent(
+        return self.llm_hook.create_agent(
             output_type=self.output_type,
             instructions=self.system_prompt,
             **extra_kwargs,
         )
 
+    def execute(self, context: Context) -> Any:
+        agent = self._build_agent()
         result = agent.run_sync(self.prompt)
         log_run_summary(self.log, result)
         output = result.output
 
+        if self.enable_hitl_review:
+            return self.run_hitl_review(  # type: ignore[misc]

Review Comment:
   Without HITL, structured output goes through `model_dump()` and returns a 
`dict`. With HITL, `run_hitl_review` returns `str` (via `_to_string`). So 
toggling `enable_hitl_review` on a structured-output agent changes the return 
type from `dict` to `str`, which would break downstream tasks that index into 
the result.
   
   Worth either deserializing back to a dict when `output_type` is a 
`BaseModel`, or documenting this as expected behavior.



##########
providers/common/ai/src/airflow/providers/common/ai/plugins/www/src/components/NoSession.tsx:
##########
@@ -0,0 +1,71 @@
+/*!
+ * 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.
+ */
+
+import { Box, Code, Text } from "@chakra-ui/react";
+import type { FC } from "react";
+
+export const NoSession: FC = () => {
+  return (
+    <Box
+      alignItems="center"
+      bg="bg"
+      color="fg"
+      display="flex"
+      h="100%"
+      justifyContent="center"
+      minH="100vh"
+      p={5}
+    >
+      <Box
+        bg="bg.subtle"
+        borderRadius="xl"
+        borderWidth="1px"
+        maxW="440px"
+        p={10}
+        textAlign="center"
+      >
+        <Text fontSize="4xl" mb={4}>
+          &#x1F4AC;
+        </Text>
+        <Text as="h2" fontSize="lg" fontWeight="semibold" mb={2}>
+          No Active HITL Review Session
+        </Text>
+        <Text color="fg.muted" fontSize="sm" lineHeight="tall" mb={5}>
+          This task does not have an active HITL review session right now. The 
chat window appears
+          when the task is running with <Code 
fontSize="xs">enable_hitl_review=True</Code>.
+        </Text>
+        <Box
+          bg="bg.subtle"
+          borderRadius="lg"
+          borderWidth="1px"
+          color="fg.muted"
+          fontSize="xs"
+          lineHeight="tall"
+          p={3}
+        >
+          <Text as="span" opacity={0.8}>
+            &#x25CF;
+          </Text>{" "}
+          If the task is currently running, the session may still be 
initialising. Checking

Review Comment:
   Now that the component no longer polls (good, that was the right call), this 
text is a bit misleading. The `useSession` hook handles the polling, not this 
component. Maybe just say "The session may still be initialising." and drop the 
"Checking periodically" part.



##########
providers/common/ai/src/airflow/providers/common/ai/plugins/www/src/components/ChatPage.tsx:
##########
@@ -0,0 +1,352 @@
+/*!
+ * 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.
+ */
+
+import {
+  Badge,
+  Box,
+  Button,
+  Flex,
+  HStack,
+  Heading,
+  Spinner,
+  Text,
+  Textarea,
+  VStack,
+} from "@chakra-ui/react";
+import {
+  type FC,
+  type KeyboardEvent,
+  useCallback,
+  useEffect,
+  useRef,
+  useState,
+} from "react";
+
+import { MessageBubble } from "src/components/MessageBubble";
+import { NoSession } from "src/components/NoSession";
+import { useSession } from "src/hooks/useSession";
+import { toaster } from "src/toaster";
+
+interface ChatPageProps {
+  dagId: string;
+  runId: string;
+  taskId: string;
+  mapIndex: number;
+}
+
+type ConfirmAction = "approve" | "reject" | null;
+
+const STATUS_BADGE: Record<
+  string,
+  { colorPalette: "green" | "red" | "yellow" | "blue"; label: string }
+> = {
+  pending_review: { colorPalette: "yellow", label: "Pending Review" },
+  approved: { colorPalette: "green", label: "Approved" },
+  rejected: { colorPalette: "red", label: "Rejected" },
+  changes_requested: { colorPalette: "blue", label: "Regenerating..." },
+  max_iterations_exceeded: { colorPalette: "red", label: "Max iterations 
exceeded" },
+  timeout_exceeded: { colorPalette: "red", label: "Timeout exceeded" },
+};
+
+export const ChatPage: FC<ChatPageProps> = ({ dagId, runId, taskId, mapIndex 
}) => {
+  const { session, loading, error, sendFeedback, approve, reject } = 
useSession(
+    dagId,
+    runId,
+    taskId,
+    mapIndex,
+  );
+
+  const [feedbackText, setFeedbackText] = useState("");
+  const [confirmAction, setConfirmAction] = useState<ConfirmAction>(null);
+  const [isSending, setIsSending] = useState(false);
+  const chatRef = useRef<HTMLDivElement>(null);
+  const textareaRef = useRef<HTMLTextAreaElement>(null);
+  const prevConvLenRef = useRef(0);
+
+  useEffect(() => {
+    if (!session?.conversation || !chatRef.current) return;
+    const len = session.conversation.length;
+    if (len > prevConvLenRef.current) {
+      chatRef.current.scrollTop = chatRef.current.scrollHeight;
+    }
+    prevConvLenRef.current = len;
+  }, [session?.conversation]);
+
+  const autoResize = useCallback(() => {
+    const ta = textareaRef.current;
+    if (ta) {
+      ta.style.height = "auto";
+      ta.style.height = `${ta.scrollHeight}px`;
+    }
+  }, []);
+
+  const handleSend = useCallback(async () => {
+    const text = feedbackText.trim();
+    if (!text || isSending) return;
+    setIsSending(true);
+    try {
+      await sendFeedback(text);
+      setFeedbackText("");
+      toaster.create({ title: "Feedback sent", type: "success", duration: 4000 
});
+    } catch (err) {
+      toaster.create({
+        title: err instanceof Error ? err.message : "Error",
+        type: "error",
+        duration: 5000,
+      });
+    } finally {
+      setIsSending(false);
+    }
+  }, [feedbackText, sendFeedback, isSending]);
+
+  const handleKeyDown = useCallback(
+    (e: KeyboardEvent) => {
+      if (e.ctrlKey && e.key === "Enter") {
+        void handleSend();
+      }
+    },
+    [handleSend],
+  );
+
+  const execConfirm = useCallback(async () => {
+    const action = confirmAction;
+    setConfirmAction(null);
+    if (!action || isSending) return;
+    setIsSending(true);
+    try {
+      if (action === "approve") {
+        await approve();
+        toaster.create({ title: "Approved", type: "success", duration: 4000 });
+      } else if (action === "reject") {
+        await reject();
+        toaster.create({ title: "Rejected", type: "success", duration: 4000 });
+      }
+    } catch (err) {
+      toaster.create({
+        title: err instanceof Error ? err.message : "Error",
+        type: "error",
+        duration: 5000,
+      });
+    } finally {
+      setIsSending(false);
+    }
+  }, [confirmAction, approve, reject, isSending]);
+
+  if (loading) {
+    return (
+      <Flex
+        align="center"
+        bg="bg"
+        color="fg"
+        flexDirection="column"
+        h="100vh"
+        justify="center"
+        p={5}
+      >
+        <Box
+          bg="bg.subtle"
+          borderRadius="xl"
+          borderWidth="1px"
+          maxW="440px"
+          p={12}
+          textAlign="center"
+        >
+          <Spinner colorPalette="brand" mb={4} size="lg" />
+          <Heading size="md">Connecting to session</Heading>
+          <Text color="fg.muted" fontSize="sm" mt={2}>
+            Looking up the HITL review session for this task...
+          </Text>
+        </Box>
+      </Flex>
+    );
+  }
+
+  if (!session) {
+    return <NoSession />;
+  }
+
+  const isTerminal =

Review Comment:
   This is the same 5-condition check as `isTerminal` in `useSession.ts`. If a 
new terminal status gets added, both need updating. A shared 
`isTerminalStatus()` helper in `types/feedback.ts` would prevent them drifting 
apart.



##########
providers/common/ai/src/airflow/providers/common/ai/mixins/hitl_review.py:
##########
@@ -0,0 +1,275 @@
+# 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.
+from __future__ import annotations
+
+import logging
+import time
+from datetime import timedelta
+from typing import TYPE_CHECKING, Any, Protocol
+
+from pydantic import BaseModel
+
+from airflow.providers.common.ai.exceptions import HITLMaxIterationsError
+from airflow.providers.common.ai.utils.hitl_review import (
+    XCOM_AGENT_OUTPUT_PREFIX,
+    XCOM_AGENT_SESSION,
+    XCOM_HUMAN_ACTION,
+    AgentSessionData,
+    HumanActionData,
+    SessionStatus,
+)
+
+log = logging.getLogger(__name__)
+
+if TYPE_CHECKING:
+    from airflow.sdk import Context
+
+
+class HITLReviewProtocol(Protocol):
+    """Attributes that the host operator must provide."""
+
+    enable_hitl_review: bool
+    max_hitl_iterations: int
+    hitl_timeout: timedelta | None
+    hitl_poll_interval: float
+    prompt: str
+    task_id: str
+    log: Any
+
+
+class HITLReviewMixin:
+    """
+    Mixin that drives an iterative HITL review loop inside ``execute()``.
+
+    After the operator generates its first output, the mixin:
+
+    1. Pushes session metadata and the first agent output to XCom.
+    2. Polls the human action XCom (``airflow_hitl_review_human_action``) at 
``hitl_poll_interval`` seconds.
+    3. When a human sets action to ``changes_requested`` (via the plugin API),
+       calls :meth:`regenerate_with_feedback` and pushes the new agent output.
+    4. When a human sets action to ``approved``, returns the output.
+    5. When a human sets action to ``rejected``, raises a `HITLRejectException`
+
+    The loop stops after ``hitl_timeout`` or ``max_hitl_iterations``.
+
+    **Max iterations:** ``iteration`` counts outputs shown to the reviewer
+    (1 = initial, 2 = first regeneration, etc.). When the reviewer requests
+    changes at ``iteration >= max_hitl_iterations``, the mixin raises
+    ``HITLMaxIterationsError`` without calling the LLM. With
+    ``max_hitl_iterations=5``, the reviewer can request changes at most 4
+    times (iterations 1–4); the fifth output is the last chance to approve or
+    reject.
+
+    All agent outputs and human feedback are persisted as iteration-keyed
+    XCom entries (``airflow_hitl_review_agent_output_1``, 
``airflow_hitl_review_human_feedback_1``, etc.)
+    for full auditability.
+
+    Operators using this mixin must set:
+
+    - ``enable_hitl_review`` (``bool``)
+    - ``hitl_timeout`` (``timedelta | None``)
+    - ``hitl_poll_interval`` (``float``, seconds)
+    - ``prompt`` (``str``)
+
+    And must implement: meth:`regenerate_with_feedback`.
+    """
+
+    def run_hitl_review(
+        self: HITLReviewProtocol,
+        context: Context,
+        output: Any,
+        *,
+        message_history: Any = None,
+    ) -> str:
+        """
+        Execute the full HITL review loop.
+
+        :param context: Airflow task context.
+        :param output: Initial LLM output (str or BaseModel).
+        :param message_history: Provider-specific conversation state (e.g.
+            pydantic-ai ``list[ModelMessage]``).  Passed to
+            :meth:`regenerate_with_feedback` on each iteration.
+        :returns: The final approved output as a string.
+        :raises HITLMaxIterationsError: When max iterations reached without 
approval.
+        :raises HITLRejectException: When the reviewer rejects the output.
+        :raises HITLTimeoutError: When hitl_timeout elapses with no response.
+        """
+        output_str = self._to_string(output)  # type: ignore[attr-defined]
+        ti = context["task_instance"]
+
+        session = AgentSessionData(
+            status=SessionStatus.PENDING_REVIEW,
+            iteration=1,
+            max_iterations=self.max_hitl_iterations,
+            prompt=self.prompt,
+            current_output=output_str,
+        )
+
+        ti.xcom_push(key=XCOM_AGENT_SESSION, 
value=session.model_dump(mode="json"))
+        ti.xcom_push(key=f"{XCOM_AGENT_OUTPUT_PREFIX}1", value=output_str)
+
+        self.log.info(
+            "Feedback session created for %s/%s/%s (poll every %ds).",
+            ti.dag_id,
+            ti.run_id,
+            ti.task_id,
+            self.hitl_poll_interval,
+        )
+
+        deadline = time.monotonic() + self.hitl_timeout.total_seconds() if 
self.hitl_timeout else None
+
+        return self._poll_loop(  # type: ignore[attr-defined]
+            ti=ti,
+            session=session,
+            message_history=message_history,
+            deadline=deadline,
+        )
+
+    def _poll_loop(
+        self: HITLReviewProtocol,
+        *,
+        ti: Any,
+        session: AgentSessionData,
+        message_history: Any,
+        deadline: float | None,
+    ) -> str:
+        """
+        Block until the session reaches a terminal state.
+
+        This loops until the human approves, rejects, or the timeout/max 
iterations is reached.
+        """
+        from airflow.providers.standard.exceptions import (
+            HITLRejectException,
+            HITLTimeoutError,
+        )
+
+        last_seen_iteration = 0
+        first_poll = True
+
+        while True:
+            if deadline is not None and time.monotonic() > deadline:
+                _session_timeout = AgentSessionData(
+                    status=SessionStatus.TIMEOUT_EXCEEDED,
+                    iteration=session.iteration,
+                    max_iterations=session.max_iterations,
+                    prompt=session.prompt,
+                    current_output=session.current_output,
+                )
+                ti.xcom_push(key=XCOM_AGENT_SESSION, 
value=_session_timeout.model_dump(mode="json"))
+                raise HITLTimeoutError("Task exceeded timeout.")
+
+            if not first_poll:
+                time.sleep(self.hitl_poll_interval)
+            first_poll = False
+
+            try:
+                action_raw = ti.xcom_pull(
+                    key=XCOM_HUMAN_ACTION, task_ids=ti.task_id, 
map_indexes=ti.map_index
+                )
+            except Exception:
+                self.log.warning("Failed to pull XCom", exc_info=True)
+                continue
+
+            if action_raw is None:
+                # Human action may take some time to propagate; it must be 
performed in the UI,
+                # after which the plugin updates XCom with this 
XCOM_HUMAN_ACTION. Until then,
+                # continue looping.
+                continue
+
+            try:
+                if isinstance(action_raw, str):
+                    action = HumanActionData.model_validate_json(action_raw)
+                else:
+                    action = HumanActionData.model_validate(action_raw)
+            except Exception:
+                self.log.warning("Malformed human action XCom: %r", action_raw)
+                continue
+
+            if action.iteration <= last_seen_iteration:
+                continue
+
+            last_seen_iteration = action.iteration
+
+            if action.action == "approve":
+                self.log.info("Output approved at iteration %d.", 
session.iteration)
+                return session.current_output
+
+            if action.action == "reject":
+                raise HITLRejectException(f"Output rejected at iteration 
{session.iteration}.")
+
+            if action.action == "changes_requested":
+                feedback_text = action.feedback or ""
+                if not feedback_text:

Review Comment:
   Empty feedback with `changes_requested` silently returns the current output 
(acts as an approve). This could surprise reviewers who click "Request Changes" 
but forget to type anything.
   
   Consider validating non-empty feedback in the plugin's `submit_feedback` 
endpoint (return 400) so this branch is never reached.



##########
providers/common/ai/src/airflow/providers/common/ai/plugins/www/src/components/ChatPage.tsx:
##########
@@ -0,0 +1,352 @@
+/*!
+ * 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.
+ */
+
+import {
+  Badge,
+  Box,
+  Button,
+  Flex,
+  HStack,
+  Heading,
+  Spinner,
+  Text,
+  Textarea,
+  VStack,
+} from "@chakra-ui/react";
+import {
+  type FC,
+  type KeyboardEvent,
+  useCallback,
+  useEffect,
+  useRef,
+  useState,
+} from "react";
+
+import { MessageBubble } from "src/components/MessageBubble";
+import { NoSession } from "src/components/NoSession";
+import { useSession } from "src/hooks/useSession";
+import { toaster } from "src/toaster";
+
+interface ChatPageProps {
+  dagId: string;
+  runId: string;
+  taskId: string;
+  mapIndex: number;
+}
+
+type ConfirmAction = "approve" | "reject" | null;
+
+const STATUS_BADGE: Record<
+  string,
+  { colorPalette: "green" | "red" | "yellow" | "blue"; label: string }
+> = {
+  pending_review: { colorPalette: "yellow", label: "Pending Review" },
+  approved: { colorPalette: "green", label: "Approved" },
+  rejected: { colorPalette: "red", label: "Rejected" },
+  changes_requested: { colorPalette: "blue", label: "Regenerating..." },
+  max_iterations_exceeded: { colorPalette: "red", label: "Max iterations 
exceeded" },
+  timeout_exceeded: { colorPalette: "red", label: "Timeout exceeded" },
+};
+
+export const ChatPage: FC<ChatPageProps> = ({ dagId, runId, taskId, mapIndex 
}) => {
+  const { session, loading, error, sendFeedback, approve, reject } = 
useSession(
+    dagId,
+    runId,
+    taskId,
+    mapIndex,
+  );
+
+  const [feedbackText, setFeedbackText] = useState("");
+  const [confirmAction, setConfirmAction] = useState<ConfirmAction>(null);
+  const [isSending, setIsSending] = useState(false);
+  const chatRef = useRef<HTMLDivElement>(null);
+  const textareaRef = useRef<HTMLTextAreaElement>(null);
+  const prevConvLenRef = useRef(0);
+
+  useEffect(() => {
+    if (!session?.conversation || !chatRef.current) return;
+    const len = session.conversation.length;
+    if (len > prevConvLenRef.current) {
+      chatRef.current.scrollTop = chatRef.current.scrollHeight;
+    }
+    prevConvLenRef.current = len;
+  }, [session?.conversation]);
+
+  const autoResize = useCallback(() => {
+    const ta = textareaRef.current;
+    if (ta) {
+      ta.style.height = "auto";
+      ta.style.height = `${ta.scrollHeight}px`;
+    }
+  }, []);
+
+  const handleSend = useCallback(async () => {
+    const text = feedbackText.trim();
+    if (!text || isSending) return;
+    setIsSending(true);
+    try {
+      await sendFeedback(text);
+      setFeedbackText("");
+      toaster.create({ title: "Feedback sent", type: "success", duration: 4000 
});
+    } catch (err) {
+      toaster.create({
+        title: err instanceof Error ? err.message : "Error",
+        type: "error",
+        duration: 5000,
+      });
+    } finally {
+      setIsSending(false);
+    }
+  }, [feedbackText, sendFeedback, isSending]);
+
+  const handleKeyDown = useCallback(
+    (e: KeyboardEvent) => {
+      if (e.ctrlKey && e.key === "Enter") {
+        void handleSend();
+      }
+    },
+    [handleSend],
+  );
+
+  const execConfirm = useCallback(async () => {
+    const action = confirmAction;
+    setConfirmAction(null);
+    if (!action || isSending) return;
+    setIsSending(true);
+    try {
+      if (action === "approve") {
+        await approve();
+        toaster.create({ title: "Approved", type: "success", duration: 4000 });
+      } else if (action === "reject") {
+        await reject();
+        toaster.create({ title: "Rejected", type: "success", duration: 4000 });
+      }
+    } catch (err) {
+      toaster.create({
+        title: err instanceof Error ? err.message : "Error",
+        type: "error",
+        duration: 5000,
+      });
+    } finally {
+      setIsSending(false);
+    }
+  }, [confirmAction, approve, reject, isSending]);
+
+  if (loading) {
+    return (
+      <Flex
+        align="center"
+        bg="bg"
+        color="fg"
+        flexDirection="column"
+        h="100vh"
+        justify="center"
+        p={5}
+      >
+        <Box
+          bg="bg.subtle"
+          borderRadius="xl"
+          borderWidth="1px"
+          maxW="440px"
+          p={12}
+          textAlign="center"
+        >
+          <Spinner colorPalette="brand" mb={4} size="lg" />
+          <Heading size="md">Connecting to session</Heading>
+          <Text color="fg.muted" fontSize="sm" mt={2}>
+            Looking up the HITL review session for this task...
+          </Text>
+        </Box>
+      </Flex>
+    );
+  }
+
+  if (!session) {
+    return <NoSession />;
+  }
+
+  const isTerminal =
+    session.status === "approved" ||
+    session.status === "rejected" ||
+    session.status === "max_iterations_exceeded" ||
+    session.status === "timeout_exceeded" ||
+    session.task_completed;
+  const canAct = session.status === "pending_review" && 
!session.task_completed;
+  const badge = STATUS_BADGE[session.status] ?? STATUS_BADGE["pending_review"];
+
+  return (
+    <Box
+      bg="bg"
+      color="fg"
+      display="flex"
+      flexDirection="column"
+      h="100vh"
+      maxW="860px"
+      mx="auto"
+    >
+      <Box borderBottomWidth="1px" px={5} py={4}>
+        <Heading size="sm">HITL Review</Heading>
+        <HStack flexWrap="wrap" fontSize="sm" gap={3} mt={1} color="fg.muted">
+          <Text as="span">
+            <Text as="b">Task:</Text> {session.task_id}
+          </Text>
+          <Text as="span">
+            <Text as="b">DAG:</Text> {session.dag_id}
+          </Text>
+          <Text as="span">
+            <Text as="b">Iteration:</Text> 
{session.iteration}/{session.max_iterations}
+          </Text>
+          <Badge colorPalette={badge.colorPalette} fontSize="2xs" px={2} 
py={0.5} borderRadius="full">
+            {badge.label}
+          </Badge>
+        </HStack>
+      </Box>
+
+      {error && (
+        <Box
+          bg="red.subtle"
+          color="red.fg"
+          px={5}
+          py={3}
+          borderBottomWidth="1px"
+          borderColor="red.emphasized"
+          fontSize="sm"
+          fontWeight="medium"
+        >
+          {error}
+        </Box>
+      )}
+
+      <Box flex={1} overflowY="auto" p={5} display="flex" 
flexDirection="column" gap={3} ref={chatRef}>
+        {session.conversation.map((entry) => (
+          <MessageBubble key={`${entry.role}-${entry.iteration}`} 
entry={entry} />

Review Comment:
   This key isn't guaranteed unique. A normal conversation has `assistant-1` 
then `human-1` (fine), but if the conversation list ever has two entries with 
the same role+iteration, React's reconciler will get confused.
   
   Safest fix: include the array index, e.g. `` 
key={`${entry.role}-${entry.iteration}-${idx}`} ``



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