shivaam commented on code in PR #69295:
URL: https://github.com/apache/airflow/pull/69295#discussion_r3569501855


##########
task-sdk/src/airflow/sdk/coordinators/node/coordinator.py:
##########
@@ -45,6 +46,34 @@
 
 BUNDLE_FILENAME = "bundle.mjs"
 METADATA_FILENAME = "airflow-metadata.yaml"
+EMBEDDED_METADATA_MARKER = b"//# airflowMetadata="
+# Metadata sits on the bundle's first line; a bounded read is enough.
+EMBEDDED_METADATA_HEAD_BYTES = 1 << 20
+
+
+def _read_embedded_metadata(bundle_path: pathlib.Path) -> dict[str, Any] | 
None:
+    """
+    Read the manifest ``airflow-ts-pack`` embeds in the bundle itself.
+
+    The packer prepends the ``airflow-metadata.yaml`` content as a leading
+    ``//# airflowMetadata=<base64>`` line comment, keeping bundle and metadata
+    a single artifact. Returns ``None`` when the bundle has no such marker.
+    """
+    try:
+        with bundle_path.open("rb") as bundle_file:
+            head = bundle_file.read(EMBEDDED_METADATA_HEAD_BYTES)
+    except OSError as exc:
+        raise ValueError(f"cannot read {bundle_path.name}: {exc}") from exc
+
+    if not head.startswith(EMBEDDED_METADATA_MARKER):
+        return None
+
+    payload = head[len(EMBEDDED_METADATA_MARKER) :].split(b"\n", 1)[0].strip()
+    try:
+        decoded = base64.b64decode(payload, validate=True)
+    except ValueError as exc:
+        raise ValueError(f"cannot parse embedded airflow metadata: {exc}") 
from exc

Review Comment:
   The packer should also check the size before writing the bundle. That 
prevents this bad experience and users can catch such issues at deploy time



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