kaxil commented on code in PR #74334: URL: https://github.com/apache/airflow/pull/74334#discussion_r4211780158
########## providers/common/ai/src/airflow/providers/common/ai/plugins/www/src/model-api.ts: ########## @@ -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 type { UsageInfo } from "src/types/model"; + +function getApiBase(): string { + if (typeof document === "undefined") return "/api/v2"; + const baseHref = document.querySelector("head > base")?.getAttribute("href") ?? ""; + const baseUrl = new URL(baseHref, globalThis.location.origin); + const basePath = baseUrl.pathname.replace(/\/$/, "") || ""; + return basePath ? `${basePath}/api/v2` : "/api/v2"; +} + +const API_BASE = getApiBase(); + +// Namespaced to match airflow.providers.common.ai.utils.logging.MODEL_NAME_XCOM_KEY -- +// avoids colliding with a user's own "model_name" XCom. +const MODEL_NAME_XCOM_KEY = "__AIRFLOW__COMMON_AI_MODEL_NAME__"; + +/** Read one XCom entry; returns `null` when the task hasn't pushed that key (404). */ +async function fetchXComValue<T>( + dagId: string, + runId: string, + taskId: string, + mapIndex: number, + key: string, +): Promise<T | null> { + const path = + `${API_BASE}/dags/${encodeURIComponent(dagId)}` + + `/dagRuns/${encodeURIComponent(runId)}` + + `/taskInstances/${encodeURIComponent(taskId)}` + + `/xcomEntries/${encodeURIComponent(key)}`; + const res = await fetch(`${path}?map_index=${mapIndex}&deserialize=true`, { Review Comment: With a custom XCom backend that offloads values (e.g. common.io with `xcom_objectstorage_threshold = 0`), this reads the stored reference instead of the value. The public endpoint reads the DB row and only runs `stringify()`, never the backend's `deserialize_value`, so the tab would show the `s3://...` path as the model name, and `usage` comes back as a string so every stat box reads `undefined`. Core already handles this for its own metadata: `skipmixin_key` and operator extra links are written straight to the DB, bypassing the backend (`_xcom_push_to_db` in task_runner.py). Do we want these keys to go the same way? The catch is that path is private, so it would mean either importing `XCom._set_xcom_in_db` from the provider or a small public core hook for metadata XComs, which wouldn't reach 3.4 anyway. If that's not worth it now, a line in the docs about reference-storing backends, plus a guard so the stat boxes don't render `undefined` when `usage` isn't an object, would cover it. -- 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]
