saliacoel commited on
Commit
21580a5
·
verified ·
1 Parent(s): aa2cfbb

Upload 3 files

Browse files
salia_backblaze.py CHANGED
@@ -1,6 +1,11 @@
1
- """Single-file ComfyUI Backblaze B2 image and batch nodes, version 1.5.1.
2
 
3
  INSTALL
 
 
 
 
 
4
  Put this file in ComfyUI/custom_nodes/ and restart ComfyUI.
5
  Uses Python's standard library plus ComfyUI's numpy, Pillow and torch.
6
 
@@ -121,11 +126,21 @@ _UPLOAD_RETRY_WINDOW = 15 * 60
121
  _UPLOAD_FINAL_BUDGET = 120
122
  _CLEANUP_RETRY_WINDOW = 60
123
  _UPLOAD_MARKER = "salia-upload-id"
124
- _USER_AGENT = "salia-backblaze/2.2"
 
 
125
 
126
  _LOG = logging.getLogger(__name__)
127
 
128
 
 
 
 
 
 
 
 
 
129
  class _AnyType(str):
130
  # Also supports older ComfyUI versions that compare socket type strings.
131
  def __ne__(self, other):
@@ -323,7 +338,8 @@ def _upload_timeout(deadline, operation_timeout=_UPLOAD_IO_TIMEOUT):
323
 
324
  class _RequestTrace:
325
  """No headers or full URLs in diagnostics; they may contain credentials."""
326
- def __init__(self, url, total=0):
 
327
  parsed = urlsplit(url)
328
  match = re.search(r"/(b2_[A-Za-z0-9_]+)(?:/|$)", parsed.path)
329
  self.operation = match.group(1) if match else "download_file"
@@ -344,16 +360,16 @@ class _RequestTrace:
344
  now = time.monotonic()
345
  percent = 100.0 * self.bytes_sent / self.total
346
  if percent >= self._next_percent or now - self._last_progress >= 15:
347
- _LOG.warning("[Backblaze] Upload sent %.1f / %.1f MiB (%.0f%%); %.1fs elapsed%s",
348
- self.bytes_sent / (1024 * 1024), self.total / (1024 * 1024),
349
  percent, now - self.started,
350
  "; waiting for server confirmation." if self.bytes_sent == self.total else ".")
351
  self._next_percent = (int(percent) // 10 + 1) * 10
352
  self._last_progress = now
353
 
354
  def context(self):
355
- result = "{} | host={} | phase={} | {:.1f}s".format(
356
- self.operation, self.host, self.phase, time.monotonic() - self.started)
357
  if self.is_upload:
358
  result += " | sent={:.2f}/{:.2f} MiB (local socket; unconfirmed)".format(
359
  self.bytes_sent / (1024 * 1024), self.total / (1024 * 1024))
@@ -397,7 +413,7 @@ class _UploadRetryPolicy:
397
  expired = error.status == 401 and error.code in ("expired_auth_token", "bad_auth_token")
398
  upload_unauthorized = error.status == 401 and stage == "b2_upload_file"
399
  if self.final or not (expired or upload_unauthorized or error.retryable):
400
- _LOG.error("[Backblaze] %s failed: %s", stage, error)
401
  if self.final:
402
  _LOG.error("[Backblaze] Final upload attempt failed; stopping retries.")
403
  return False
@@ -422,8 +438,8 @@ class _UploadRetryPolicy:
422
  # Never retry earlier than an explicit server Retry-After, even if that
423
  # postpones the final attempt beyond the normal retry window.
424
  wait = max(min(delay, remaining), retry_after)
425
- _LOG.warning("[Backblaze] %s failed: %s | %s | next %sattempt in %.1fs; %.1fs left in retry window.",
426
- stage, error, action,
427
  "FINAL " if wait >= remaining else "", wait, remaining)
428
  if wait > 0:
429
  _wait(wait)
@@ -537,6 +553,7 @@ class _B2Client:
537
  # Set only while holding lock inside upload(); shared by all API calls
538
  # so nested authorization/endpoint retries cannot multiply the budget.
539
  self._request_deadline = None
 
540
 
541
  def _redact(self, message):
542
  message = str(message)
@@ -554,12 +571,12 @@ class _B2Client:
554
  if headers.get("Authorization"):
555
  self._secrets.add(headers["Authorization"])
556
  deadline = self._request_deadline
557
- trace = _RequestTrace(url, len(data) if data is not None else 0)
558
  if deadline is not None and data is not None:
559
  headers["Content-Length"] = str(len(data))
560
  data = _DeadlineBody(data, deadline, trace)
561
  request = Request(url, data=data, headers=headers, method=method)
562
- _LOG.warning("[Backblaze] %s -> %s", trace.operation, trace.host)
563
  try:
564
  if deadline is None:
565
  trace.phase = "opening connection / sending request"
@@ -571,8 +588,8 @@ class _B2Client:
571
  with open_request(request, timeout=timeout) as response:
572
  trace.phase = "reading response body"
573
  result = _read_response(response, deadline), response.headers
574
- _LOG.warning("[Backblaze] %s: HTTP %s in %.1fs.",
575
- trace.operation, response.status, time.monotonic() - trace.started)
576
  return result
577
  except HTTPError as error:
578
  trace.phase = "reading HTTP error response"
@@ -795,10 +812,23 @@ class _B2Client:
795
  finally:
796
  self._request_deadline = None
797
 
 
 
 
 
 
 
 
 
 
 
798
  def upload(self, filename, data, content_type="image/png"):
799
  with self.lock:
 
800
  checksum = hashlib.sha1(data).hexdigest()
801
  policy = _UploadRetryPolicy()
 
 
802
  operation_id = uuid.uuid4().hex
803
  snapshot = None
804
  _LOG.warning("[Backblaze] Destination: %s/%s | retry policy: 5 setup/upload attempts (setup failures count), then 20/30/40/... seconds; fresh URL before every file transfer.",
@@ -813,22 +843,28 @@ class _B2Client:
813
  while True:
814
  throw_exception_if_processing_interrupted()
815
  self._request_deadline = policy.begin()
816
- _LOG.warning("[Backblaze] %s (%.1f MiB), elapsed %.0fs / %ss retry window.",
 
817
  policy.label(), len(data) / (1024 * 1024),
818
  time.monotonic() - policy.started, _UPLOAD_RETRY_WINDOW)
819
  stage = "upload_setup"
820
  try:
 
821
  self.ensure_bucket()
822
  self._check_overwrite_permissions()
823
  if snapshot is None:
824
  snapshot = self._list_exact_versions(filename)
825
  stage = "b2_get_upload_url"
 
826
  target = self._authorized_request("b2_get_upload_url", {"bucketId": self.bucket_id})
827
  if not isinstance(target, dict) or not all(
828
  isinstance(target.get(key), str) and target[key]
829
  for key in ("authorizationToken", "uploadUrl")):
830
  raise _B2Error(502, "invalid_upload_target", "Backblaze returned an incomplete upload destination.")
831
  self._secrets.add(target["authorizationToken"])
 
 
 
832
  stage = "b2_upload_file"
833
  raw, _ = self._http("POST", target["uploadUrl"], {
834
  "Authorization": target["authorizationToken"],
@@ -848,14 +884,15 @@ class _B2Client:
848
  if (receipt.get("contentSha1") != checksum or receipt.get("fileName") != filename
849
  or not isinstance(receipt.get("fileId"), str) or not receipt["fileId"]):
850
  raise _B2Error(502, "invalid_receipt", "Backblaze upload receipt did not confirm the exact filename, file ID and checksum.")
851
- _LOG.warning("[Backblaze] Upload confirmed by server SHA-1 receipt in %.1fs.",
852
- time.monotonic() - policy.started)
853
  break
854
  except _B2Error as error:
855
  if not policy.retry(stage, error):
856
  raise
857
  finally:
858
  self._request_deadline = None
 
859
  return self._finish_overwrite(filename, receipt, snapshot, operation_id)
860
 
861
  def download(self, filename):
@@ -951,6 +988,7 @@ class Init_Backblaze(_NetworkNode):
951
  }
952
 
953
  def execute(self, bucket_name, master_key_ID, master_key, in_gate=None):
 
954
  if not all(isinstance(value, str) and value.strip() for value in (bucket_name, master_key_ID, master_key)):
955
  raise ValueError("Enter bucket_name, master_key_ID and master_key in Init_Backblaze.")
956
  bucket_name, master_key_ID, master_key = (value.strip() for value in (bucket_name, master_key_ID, master_key))
@@ -992,6 +1030,7 @@ class Upload_BackBlaze_Img(_NetworkNode):
992
  }
993
 
994
  def execute(self, filename, image, in_gate=None):
 
995
  if filename == "INVALID":
996
  return ("SKIPPED: INVALID image pair; nothing uploaded.",)
997
  try:
@@ -1018,6 +1057,7 @@ class Download_BackBlaze_Img(_NetworkNode):
1018
  }
1019
 
1020
  def execute(self, filename, in_gate=None):
 
1021
  data, _ = _shared_client().download(_png_name(filename))
1022
  return (_png_to_image(data),)
1023
 
@@ -1038,6 +1078,7 @@ class Upload_BackBlaze_VID(_NetworkNode):
1038
  }
1039
 
1040
  def execute(self, filename, images, in_gate=None):
 
1041
  if filename == "INVALID":
1042
  return ("SKIPPED: INVALID image pair; nothing uploaded.",)
1043
  recovery_path = None
@@ -1078,6 +1119,7 @@ class Upload_BackBlaze_Retry(_NetworkNode):
1078
  }
1079
 
1080
  def execute(self, filename, local_zip, in_gate=None):
 
1081
  if filename == "INVALID":
1082
  return ("SKIPPED: INVALID image pair; nothing uploaded.",)
1083
  try:
@@ -1110,6 +1152,7 @@ class Download_BackBlaze_VID(_NetworkNode):
1110
  }
1111
 
1112
  def execute(self, filename, in_gate=None):
 
1113
  data, _ = _shared_client().download(_zip_name(filename))
1114
  return (_zip_to_images(data),)
1115
 
@@ -1124,3 +1167,11 @@ NODE_CLASS_MAPPINGS = {
1124
  }
1125
 
1126
  NODE_DISPLAY_NAME_MAPPINGS = {name: name for name in NODE_CLASS_MAPPINGS}
 
 
 
 
 
 
 
 
 
1
+ """Single-file ComfyUI Backblaze B2 image and batch nodes, version 1.5.2 (retry-fix-3).
2
 
3
  INSTALL
4
+ Build retry-fix-3. Replace previous copies of this node module; do not keep
5
+ renamed copies registering the same nodes. Fully restart the ComfyUI backend.
6
+ At execution, ACTIVE build=retry-fix-3 prints the actual module file path.
7
+ All setup/upload attempts and HTTP calls log their attempt label. Retries
8
+ run sequentially; other URLs are not tried silently in the background.
9
  Put this file in ComfyUI/custom_nodes/ and restart ComfyUI.
10
  Uses Python's standard library plus ComfyUI's numpy, Pillow and torch.
11
 
 
126
  _UPLOAD_FINAL_BUDGET = 120
127
  _CLEANUP_RETRY_WINDOW = 60
128
  _UPLOAD_MARKER = "salia-upload-id"
129
+ _USER_AGENT = "salia-backblaze/2.3"
130
+
131
+ _B2_RETRY_BUILD = "retry-fix-3"
132
 
133
  _LOG = logging.getLogger(__name__)
134
 
135
 
136
+ def _log_active_code(context):
137
+ """Identify the code that is executing, including duplicate/stale installs."""
138
+ path = globals().get("__file__")
139
+ path = os.path.abspath(path) if isinstance(path, str) else "<module file unavailable>"
140
+ _LOG.warning("[Backblaze] ACTIVE build=%s | context=%s | module=%s | file=%s",
141
+ _B2_RETRY_BUILD, context, __name__, path)
142
+
143
+
144
  class _AnyType(str):
145
  # Also supports older ComfyUI versions that compare socket type strings.
146
  def __ne__(self, other):
 
338
 
339
  class _RequestTrace:
340
  """No headers or full URLs in diagnostics; they may contain credentials."""
341
+ def __init__(self, url, total=0, attempt=None):
342
+ self.attempt = attempt or "API request"
343
  parsed = urlsplit(url)
344
  match = re.search(r"/(b2_[A-Za-z0-9_]+)(?:/|$)", parsed.path)
345
  self.operation = match.group(1) if match else "download_file"
 
360
  now = time.monotonic()
361
  percent = 100.0 * self.bytes_sent / self.total
362
  if percent >= self._next_percent or now - self._last_progress >= 15:
363
+ _LOG.warning("[Backblaze] %s | Upload sent %.1f / %.1f MiB (%.0f%%); %.1fs elapsed%s",
364
+ self.attempt, self.bytes_sent / (1024 * 1024), self.total / (1024 * 1024),
365
  percent, now - self.started,
366
  "; waiting for server confirmation." if self.bytes_sent == self.total else ".")
367
  self._next_percent = (int(percent) // 10 + 1) * 10
368
  self._last_progress = now
369
 
370
  def context(self):
371
+ result = "{} | {} | host={} | phase={} | {:.1f}s".format(
372
+ self.attempt, self.operation, self.host, self.phase, time.monotonic() - self.started)
373
  if self.is_upload:
374
  result += " | sent={:.2f}/{:.2f} MiB (local socket; unconfirmed)".format(
375
  self.bytes_sent / (1024 * 1024), self.total / (1024 * 1024))
 
413
  expired = error.status == 401 and error.code in ("expired_auth_token", "bad_auth_token")
414
  upload_unauthorized = error.status == 401 and stage == "b2_upload_file"
415
  if self.final or not (expired or upload_unauthorized or error.retryable):
416
+ _LOG.error("[Backblaze] %s | %s failed: %s", self.label(), stage, error)
417
  if self.final:
418
  _LOG.error("[Backblaze] Final upload attempt failed; stopping retries.")
419
  return False
 
438
  # Never retry earlier than an explicit server Retry-After, even if that
439
  # postpones the final attempt beyond the normal retry window.
440
  wait = max(min(delay, remaining), retry_after)
441
+ _LOG.warning("[Backblaze] %s | %s failed: %s | %s | next %sattempt in %.1fs; %.1fs left in retry window.",
442
+ self.label(), stage, error, action,
443
  "FINAL " if wait >= remaining else "", wait, remaining)
444
  if wait > 0:
445
  _wait(wait)
 
553
  # Set only while holding lock inside upload(); shared by all API calls
554
  # so nested authorization/endpoint retries cannot multiply the budget.
555
  self._request_deadline = None
556
+ self._request_attempt = None
557
 
558
  def _redact(self, message):
559
  message = str(message)
 
571
  if headers.get("Authorization"):
572
  self._secrets.add(headers["Authorization"])
573
  deadline = self._request_deadline
574
+ trace = _RequestTrace(url, len(data) if data is not None else 0, self._request_attempt)
575
  if deadline is not None and data is not None:
576
  headers["Content-Length"] = str(len(data))
577
  data = _DeadlineBody(data, deadline, trace)
578
  request = Request(url, data=data, headers=headers, method=method)
579
+ _LOG.warning("[Backblaze] %s | REQUEST %s -> %s", trace.attempt, trace.operation, trace.host)
580
  try:
581
  if deadline is None:
582
  trace.phase = "opening connection / sending request"
 
588
  with open_request(request, timeout=timeout) as response:
589
  trace.phase = "reading response body"
590
  result = _read_response(response, deadline), response.headers
591
+ _LOG.warning("[Backblaze] %s | %s: HTTP %s in %.1fs.",
592
+ trace.attempt, trace.operation, response.status, time.monotonic() - trace.started)
593
  return result
594
  except HTTPError as error:
595
  trace.phase = "reading HTTP error response"
 
812
  finally:
813
  self._request_deadline = None
814
 
815
+ def _log_upload_target(self, target, count, previous):
816
+ # A stable digest distinguishes exact targets without exposing URL paths
817
+ # or tokens. Backblaze can legitimately return the same URL again.
818
+ url = target["uploadUrl"]
819
+ parsed = urlsplit(url)
820
+ tag = hashlib.sha256(url.encode("utf-8")).hexdigest()[:12]
821
+ _LOG.warning("[Backblaze] %s | Upload URL received #%d | host=%s | target=%s%s",
822
+ self._request_attempt, count, parsed.hostname, tag,
823
+ " | same URL as previous request" if url == previous else "")
824
+
825
  def upload(self, filename, data, content_type="image/png"):
826
  with self.lock:
827
+ _log_active_code("file upload")
828
  checksum = hashlib.sha1(data).hexdigest()
829
  policy = _UploadRetryPolicy()
830
+ issued_targets = 0
831
+ previous_target = None
832
  operation_id = uuid.uuid4().hex
833
  snapshot = None
834
  _LOG.warning("[Backblaze] Destination: %s/%s | retry policy: 5 setup/upload attempts (setup failures count), then 20/30/40/... seconds; fresh URL before every file transfer.",
 
843
  while True:
844
  throw_exception_if_processing_interrupted()
845
  self._request_deadline = policy.begin()
846
+ self._request_attempt = policy.label()
847
+ _LOG.warning("[Backblaze] %s (%.1f MiB), elapsed %.0fs / %ss retry window | START (sequential).",
848
  policy.label(), len(data) / (1024 * 1024),
849
  time.monotonic() - policy.started, _UPLOAD_RETRY_WINDOW)
850
  stage = "upload_setup"
851
  try:
852
+ _LOG.warning("[Backblaze] %s | Preparing authorization and bucket.", self._request_attempt)
853
  self.ensure_bucket()
854
  self._check_overwrite_permissions()
855
  if snapshot is None:
856
  snapshot = self._list_exact_versions(filename)
857
  stage = "b2_get_upload_url"
858
+ _LOG.warning("[Backblaze] %s | Requesting fresh upload URL.", self._request_attempt)
859
  target = self._authorized_request("b2_get_upload_url", {"bucketId": self.bucket_id})
860
  if not isinstance(target, dict) or not all(
861
  isinstance(target.get(key), str) and target[key]
862
  for key in ("authorizationToken", "uploadUrl")):
863
  raise _B2Error(502, "invalid_upload_target", "Backblaze returned an incomplete upload destination.")
864
  self._secrets.add(target["authorizationToken"])
865
+ issued_targets += 1
866
+ self._log_upload_target(target, issued_targets, previous_target)
867
+ previous_target = target["uploadUrl"]
868
  stage = "b2_upload_file"
869
  raw, _ = self._http("POST", target["uploadUrl"], {
870
  "Authorization": target["authorizationToken"],
 
884
  if (receipt.get("contentSha1") != checksum or receipt.get("fileName") != filename
885
  or not isinstance(receipt.get("fileId"), str) or not receipt["fileId"]):
886
  raise _B2Error(502, "invalid_receipt", "Backblaze upload receipt did not confirm the exact filename, file ID and checksum.")
887
+ _LOG.warning("[Backblaze] %s | Upload confirmed by server SHA-1 receipt in %.1fs.",
888
+ self._request_attempt, time.monotonic() - policy.started)
889
  break
890
  except _B2Error as error:
891
  if not policy.retry(stage, error):
892
  raise
893
  finally:
894
  self._request_deadline = None
895
+ self._request_attempt = None
896
  return self._finish_overwrite(filename, receipt, snapshot, operation_id)
897
 
898
  def download(self, filename):
 
988
  }
989
 
990
  def execute(self, bucket_name, master_key_ID, master_key, in_gate=None):
991
+ _log_active_code("Init_Backblaze")
992
  if not all(isinstance(value, str) and value.strip() for value in (bucket_name, master_key_ID, master_key)):
993
  raise ValueError("Enter bucket_name, master_key_ID and master_key in Init_Backblaze.")
994
  bucket_name, master_key_ID, master_key = (value.strip() for value in (bucket_name, master_key_ID, master_key))
 
1030
  }
1031
 
1032
  def execute(self, filename, image, in_gate=None):
1033
+ _log_active_code("Upload_BackBlaze_Img")
1034
  if filename == "INVALID":
1035
  return ("SKIPPED: INVALID image pair; nothing uploaded.",)
1036
  try:
 
1057
  }
1058
 
1059
  def execute(self, filename, in_gate=None):
1060
+ _log_active_code("Download_BackBlaze_Img")
1061
  data, _ = _shared_client().download(_png_name(filename))
1062
  return (_png_to_image(data),)
1063
 
 
1078
  }
1079
 
1080
  def execute(self, filename, images, in_gate=None):
1081
+ _log_active_code("Upload_BackBlaze_VID")
1082
  if filename == "INVALID":
1083
  return ("SKIPPED: INVALID image pair; nothing uploaded.",)
1084
  recovery_path = None
 
1119
  }
1120
 
1121
  def execute(self, filename, local_zip, in_gate=None):
1122
+ _log_active_code("Upload_BackBlaze_Retry")
1123
  if filename == "INVALID":
1124
  return ("SKIPPED: INVALID image pair; nothing uploaded.",)
1125
  try:
 
1152
  }
1153
 
1154
  def execute(self, filename, in_gate=None):
1155
+ _log_active_code("Download_BackBlaze_VID")
1156
  data, _ = _shared_client().download(_zip_name(filename))
1157
  return (_zip_to_images(data),)
1158
 
 
1167
  }
1168
 
1169
  NODE_DISPLAY_NAME_MAPPINGS = {name: name for name in NODE_CLASS_MAPPINGS}
1170
+
1171
+ # Keep saved workflow node IDs; expose the build in the node picker.
1172
+ NODE_DISPLAY_NAME_MAPPINGS = {
1173
+ name: label + " [retry-fix-3]"
1174
+ for name, label in NODE_DISPLAY_NAME_MAPPINGS.items()
1175
+ }
1176
+ _LOG.warning("[Backblaze] LOADED build=%s | file=%s | node IDs=%s",
1177
+ _B2_RETRY_BUILD, os.path.abspath(__file__), ", ".join(NODE_CLASS_MAPPINGS))
salia_backblaze_atlas_special.py CHANGED
@@ -1,6 +1,11 @@
1
  """Standalone ComfyUI atlas-to-Backblaze node: salia_backblaze_atlas_special.
2
 
3
  INSTALL
 
 
 
 
 
4
  Put THIS file in ComfyUI/custom_nodes/ and restart ComfyUI.
5
  It registers only salia_backblaze_atlas_special. It can coexist with your
6
  existing Backblaze nodes. No Init node or other custom-node file is needed.
@@ -155,11 +160,21 @@ _UPLOAD_RETRY_WINDOW = 15 * 60
155
  _UPLOAD_FINAL_BUDGET = 120
156
 
157
 
158
- _USER_AGENT = "salia-backblaze/2.2"
 
 
159
 
160
  _LOG = logging.getLogger(__name__)
161
 
162
 
 
 
 
 
 
 
 
 
163
  class _AnyType(str):
164
  # Also supports older ComfyUI versions that compare socket type strings.
165
  def __ne__(self, other):
@@ -282,7 +297,8 @@ def _upload_timeout(deadline, operation_timeout=_UPLOAD_IO_TIMEOUT):
282
 
283
  class _RequestTrace:
284
  """No headers or full URLs in diagnostics; they may contain credentials."""
285
- def __init__(self, url, total=0):
 
286
  parsed = urlsplit(url)
287
  match = re.search(r"/(b2_[A-Za-z0-9_]+)(?:/|$)", parsed.path)
288
  self.operation = match.group(1) if match else "download_file"
@@ -303,16 +319,16 @@ class _RequestTrace:
303
  now = time.monotonic()
304
  percent = 100.0 * self.bytes_sent / self.total
305
  if percent >= self._next_percent or now - self._last_progress >= 15:
306
- _LOG.warning("[Backblaze] Upload sent %.1f / %.1f MiB (%.0f%%); %.1fs elapsed%s",
307
- self.bytes_sent / (1024 * 1024), self.total / (1024 * 1024),
308
  percent, now - self.started,
309
  "; waiting for server confirmation." if self.bytes_sent == self.total else ".")
310
  self._next_percent = (int(percent) // 10 + 1) * 10
311
  self._last_progress = now
312
 
313
  def context(self):
314
- result = "{} | host={} | phase={} | {:.1f}s".format(
315
- self.operation, self.host, self.phase, time.monotonic() - self.started)
316
  if self.is_upload:
317
  result += " | sent={:.2f}/{:.2f} MiB (local socket; unconfirmed)".format(
318
  self.bytes_sent / (1024 * 1024), self.total / (1024 * 1024))
@@ -356,7 +372,7 @@ class _UploadRetryPolicy:
356
  expired = error.status == 401 and error.code in ("expired_auth_token", "bad_auth_token")
357
  upload_unauthorized = error.status == 401 and stage == "b2_upload_file"
358
  if self.final or not (expired or upload_unauthorized or error.retryable):
359
- _LOG.error("[Backblaze] %s failed: %s", stage, error)
360
  if self.final:
361
  _LOG.error("[Backblaze] Final upload attempt failed; stopping retries.")
362
  return False
@@ -381,8 +397,8 @@ class _UploadRetryPolicy:
381
  # Never retry earlier than an explicit server Retry-After, even if that
382
  # postpones the final attempt beyond the normal retry window.
383
  wait = max(min(delay, remaining), retry_after)
384
- _LOG.warning("[Backblaze] %s failed: %s | %s | next %sattempt in %.1fs; %.1fs left in retry window.",
385
- stage, error, action,
386
  "FINAL " if wait >= remaining else "", wait, remaining)
387
  if wait > 0:
388
  _wait(wait)
@@ -496,6 +512,7 @@ class _B2Client:
496
  # Set only while holding lock inside upload(); shared by all API calls
497
  # so nested authorization/endpoint retries cannot multiply the budget.
498
  self._request_deadline = None
 
499
 
500
  def _redact(self, message):
501
  message = str(message)
@@ -513,12 +530,12 @@ class _B2Client:
513
  if headers.get("Authorization"):
514
  self._secrets.add(headers["Authorization"])
515
  deadline = self._request_deadline
516
- trace = _RequestTrace(url, len(data) if data is not None else 0)
517
  if deadline is not None and data is not None:
518
  headers["Content-Length"] = str(len(data))
519
  data = _DeadlineBody(data, deadline, trace)
520
  request = Request(url, data=data, headers=headers, method=method)
521
- _LOG.warning("[Backblaze] %s -> %s", trace.operation, trace.host)
522
  try:
523
  if deadline is None:
524
  trace.phase = "opening connection / sending request"
@@ -530,8 +547,8 @@ class _B2Client:
530
  with open_request(request, timeout=timeout) as response:
531
  trace.phase = "reading response body"
532
  result = _read_response(response, deadline), response.headers
533
- _LOG.warning("[Backblaze] %s: HTTP %s in %.1fs.",
534
- trace.operation, response.status, time.monotonic() - trace.started)
535
  return result
536
  except HTTPError as error:
537
  trace.phase = "reading HTTP error response"
@@ -665,10 +682,23 @@ class _B2Client:
665
  return
666
  raise ValueError("Bucket {!r} was not found. Enter an existing B2 bucket name.".format(self.bucket_name))
667
 
 
 
 
 
 
 
 
 
 
 
668
  def upload(self, filename, data, content_type="image/png"):
669
  with self.lock:
 
670
  checksum = hashlib.sha1(data).hexdigest()
671
  policy = _UploadRetryPolicy()
 
 
672
  _LOG.warning("[Backblaze] Destination: %s/%s | retry policy: 5 setup/upload attempts (setup failures count), then 20/30/40/... seconds; fresh URL before every file transfer.",
673
  self.bucket_name, filename)
674
  _LOG.warning("[Backblaze] Timeouts: connect/TLS=%ss, send/read operation=%ss; "
@@ -681,19 +711,25 @@ class _B2Client:
681
  while True:
682
  throw_exception_if_processing_interrupted()
683
  self._request_deadline = policy.begin()
684
- _LOG.warning("[Backblaze] %s (%.1f MiB), elapsed %.0fs / %ss retry window.",
 
685
  policy.label(), len(data) / (1024 * 1024),
686
  time.monotonic() - policy.started, _UPLOAD_RETRY_WINDOW)
687
  stage = "upload_setup"
688
  try:
 
689
  self.ensure_bucket()
690
  stage = "b2_get_upload_url"
 
691
  target = self._authorized_request("b2_get_upload_url", {"bucketId": self.bucket_id})
692
  if not isinstance(target, dict) or not all(
693
  isinstance(target.get(key), str) and target[key]
694
  for key in ("authorizationToken", "uploadUrl")):
695
  raise _B2Error(502, "invalid_upload_target", "Backblaze returned an incomplete upload destination.")
696
  self._secrets.add(target["authorizationToken"])
 
 
 
697
  stage = "b2_upload_file"
698
  raw, _ = self._http("POST", target["uploadUrl"], {
699
  "Authorization": target["authorizationToken"],
@@ -711,14 +747,15 @@ class _B2Client:
711
  raise _B2Error(0, "invalid_receipt", "Upload response was not an object.")
712
  if receipt.get("contentSha1") != checksum:
713
  raise RuntimeError("Backblaze upload receipt did not confirm the file checksum.")
714
- _LOG.warning("[Backblaze] Upload confirmed by server SHA-1 receipt in %.1fs.",
715
- time.monotonic() - policy.started)
716
  return
717
  except _B2Error as error:
718
  if not policy.retry(stage, error):
719
  raise
720
  finally:
721
  self._request_deadline = None
 
722
 
723
  def download(self, filename):
724
  with self.lock:
@@ -1124,6 +1161,7 @@ class salia_backblaze_atlas_special(_NetworkNode):
1124
  }
1125
 
1126
  def execute(self, filename, images, key_id, api_key, bucket_name, in_gate=None):
 
1127
  recovery_path = None
1128
  try:
1129
  if not all(isinstance(value, str) and value.strip() for value in (key_id, api_key, bucket_name)):
@@ -1158,3 +1196,11 @@ NODE_CLASS_MAPPINGS = {
1158
  NODE_DISPLAY_NAME_MAPPINGS = {
1159
  "salia_backblaze_atlas_special": "salia_backblaze_atlas_special",
1160
  }
 
 
 
 
 
 
 
 
 
1
  """Standalone ComfyUI atlas-to-Backblaze node: salia_backblaze_atlas_special.
2
 
3
  INSTALL
4
+ Build retry-fix-3. Replace previous copies of this node module; do not keep
5
+ renamed copies registering the same nodes. Fully restart the ComfyUI backend.
6
+ At execution, ACTIVE build=retry-fix-3 prints the actual module file path.
7
+ All setup/upload attempts and HTTP calls log their attempt label. Retries
8
+ run sequentially; other URLs are not tried silently in the background.
9
  Put THIS file in ComfyUI/custom_nodes/ and restart ComfyUI.
10
  It registers only salia_backblaze_atlas_special. It can coexist with your
11
  existing Backblaze nodes. No Init node or other custom-node file is needed.
 
160
  _UPLOAD_FINAL_BUDGET = 120
161
 
162
 
163
+ _USER_AGENT = "salia-backblaze/2.3"
164
+
165
+ _B2_RETRY_BUILD = "retry-fix-3"
166
 
167
  _LOG = logging.getLogger(__name__)
168
 
169
 
170
+ def _log_active_code(context):
171
+ """Identify the code that is executing, including duplicate/stale installs."""
172
+ path = globals().get("__file__")
173
+ path = os.path.abspath(path) if isinstance(path, str) else "<module file unavailable>"
174
+ _LOG.warning("[Backblaze] ACTIVE build=%s | context=%s | module=%s | file=%s",
175
+ _B2_RETRY_BUILD, context, __name__, path)
176
+
177
+
178
  class _AnyType(str):
179
  # Also supports older ComfyUI versions that compare socket type strings.
180
  def __ne__(self, other):
 
297
 
298
  class _RequestTrace:
299
  """No headers or full URLs in diagnostics; they may contain credentials."""
300
+ def __init__(self, url, total=0, attempt=None):
301
+ self.attempt = attempt or "API request"
302
  parsed = urlsplit(url)
303
  match = re.search(r"/(b2_[A-Za-z0-9_]+)(?:/|$)", parsed.path)
304
  self.operation = match.group(1) if match else "download_file"
 
319
  now = time.monotonic()
320
  percent = 100.0 * self.bytes_sent / self.total
321
  if percent >= self._next_percent or now - self._last_progress >= 15:
322
+ _LOG.warning("[Backblaze] %s | Upload sent %.1f / %.1f MiB (%.0f%%); %.1fs elapsed%s",
323
+ self.attempt, self.bytes_sent / (1024 * 1024), self.total / (1024 * 1024),
324
  percent, now - self.started,
325
  "; waiting for server confirmation." if self.bytes_sent == self.total else ".")
326
  self._next_percent = (int(percent) // 10 + 1) * 10
327
  self._last_progress = now
328
 
329
  def context(self):
330
+ result = "{} | {} | host={} | phase={} | {:.1f}s".format(
331
+ self.attempt, self.operation, self.host, self.phase, time.monotonic() - self.started)
332
  if self.is_upload:
333
  result += " | sent={:.2f}/{:.2f} MiB (local socket; unconfirmed)".format(
334
  self.bytes_sent / (1024 * 1024), self.total / (1024 * 1024))
 
372
  expired = error.status == 401 and error.code in ("expired_auth_token", "bad_auth_token")
373
  upload_unauthorized = error.status == 401 and stage == "b2_upload_file"
374
  if self.final or not (expired or upload_unauthorized or error.retryable):
375
+ _LOG.error("[Backblaze] %s | %s failed: %s", self.label(), stage, error)
376
  if self.final:
377
  _LOG.error("[Backblaze] Final upload attempt failed; stopping retries.")
378
  return False
 
397
  # Never retry earlier than an explicit server Retry-After, even if that
398
  # postpones the final attempt beyond the normal retry window.
399
  wait = max(min(delay, remaining), retry_after)
400
+ _LOG.warning("[Backblaze] %s | %s failed: %s | %s | next %sattempt in %.1fs; %.1fs left in retry window.",
401
+ self.label(), stage, error, action,
402
  "FINAL " if wait >= remaining else "", wait, remaining)
403
  if wait > 0:
404
  _wait(wait)
 
512
  # Set only while holding lock inside upload(); shared by all API calls
513
  # so nested authorization/endpoint retries cannot multiply the budget.
514
  self._request_deadline = None
515
+ self._request_attempt = None
516
 
517
  def _redact(self, message):
518
  message = str(message)
 
530
  if headers.get("Authorization"):
531
  self._secrets.add(headers["Authorization"])
532
  deadline = self._request_deadline
533
+ trace = _RequestTrace(url, len(data) if data is not None else 0, self._request_attempt)
534
  if deadline is not None and data is not None:
535
  headers["Content-Length"] = str(len(data))
536
  data = _DeadlineBody(data, deadline, trace)
537
  request = Request(url, data=data, headers=headers, method=method)
538
+ _LOG.warning("[Backblaze] %s | REQUEST %s -> %s", trace.attempt, trace.operation, trace.host)
539
  try:
540
  if deadline is None:
541
  trace.phase = "opening connection / sending request"
 
547
  with open_request(request, timeout=timeout) as response:
548
  trace.phase = "reading response body"
549
  result = _read_response(response, deadline), response.headers
550
+ _LOG.warning("[Backblaze] %s | %s: HTTP %s in %.1fs.",
551
+ trace.attempt, trace.operation, response.status, time.monotonic() - trace.started)
552
  return result
553
  except HTTPError as error:
554
  trace.phase = "reading HTTP error response"
 
682
  return
683
  raise ValueError("Bucket {!r} was not found. Enter an existing B2 bucket name.".format(self.bucket_name))
684
 
685
+ def _log_upload_target(self, target, count, previous):
686
+ # A stable digest distinguishes exact targets without exposing URL paths
687
+ # or tokens. Backblaze can legitimately return the same URL again.
688
+ url = target["uploadUrl"]
689
+ parsed = urlsplit(url)
690
+ tag = hashlib.sha256(url.encode("utf-8")).hexdigest()[:12]
691
+ _LOG.warning("[Backblaze] %s | Upload URL received #%d | host=%s | target=%s%s",
692
+ self._request_attempt, count, parsed.hostname, tag,
693
+ " | same URL as previous request" if url == previous else "")
694
+
695
  def upload(self, filename, data, content_type="image/png"):
696
  with self.lock:
697
+ _log_active_code("file upload")
698
  checksum = hashlib.sha1(data).hexdigest()
699
  policy = _UploadRetryPolicy()
700
+ issued_targets = 0
701
+ previous_target = None
702
  _LOG.warning("[Backblaze] Destination: %s/%s | retry policy: 5 setup/upload attempts (setup failures count), then 20/30/40/... seconds; fresh URL before every file transfer.",
703
  self.bucket_name, filename)
704
  _LOG.warning("[Backblaze] Timeouts: connect/TLS=%ss, send/read operation=%ss; "
 
711
  while True:
712
  throw_exception_if_processing_interrupted()
713
  self._request_deadline = policy.begin()
714
+ self._request_attempt = policy.label()
715
+ _LOG.warning("[Backblaze] %s (%.1f MiB), elapsed %.0fs / %ss retry window | START (sequential).",
716
  policy.label(), len(data) / (1024 * 1024),
717
  time.monotonic() - policy.started, _UPLOAD_RETRY_WINDOW)
718
  stage = "upload_setup"
719
  try:
720
+ _LOG.warning("[Backblaze] %s | Preparing authorization and bucket.", self._request_attempt)
721
  self.ensure_bucket()
722
  stage = "b2_get_upload_url"
723
+ _LOG.warning("[Backblaze] %s | Requesting fresh upload URL.", self._request_attempt)
724
  target = self._authorized_request("b2_get_upload_url", {"bucketId": self.bucket_id})
725
  if not isinstance(target, dict) or not all(
726
  isinstance(target.get(key), str) and target[key]
727
  for key in ("authorizationToken", "uploadUrl")):
728
  raise _B2Error(502, "invalid_upload_target", "Backblaze returned an incomplete upload destination.")
729
  self._secrets.add(target["authorizationToken"])
730
+ issued_targets += 1
731
+ self._log_upload_target(target, issued_targets, previous_target)
732
+ previous_target = target["uploadUrl"]
733
  stage = "b2_upload_file"
734
  raw, _ = self._http("POST", target["uploadUrl"], {
735
  "Authorization": target["authorizationToken"],
 
747
  raise _B2Error(0, "invalid_receipt", "Upload response was not an object.")
748
  if receipt.get("contentSha1") != checksum:
749
  raise RuntimeError("Backblaze upload receipt did not confirm the file checksum.")
750
+ _LOG.warning("[Backblaze] %s | Upload confirmed by server SHA-1 receipt in %.1fs.",
751
+ self._request_attempt, time.monotonic() - policy.started)
752
  return
753
  except _B2Error as error:
754
  if not policy.retry(stage, error):
755
  raise
756
  finally:
757
  self._request_deadline = None
758
+ self._request_attempt = None
759
 
760
  def download(self, filename):
761
  with self.lock:
 
1161
  }
1162
 
1163
  def execute(self, filename, images, key_id, api_key, bucket_name, in_gate=None):
1164
+ _log_active_code("salia_backblaze_atlas_special")
1165
  recovery_path = None
1166
  try:
1167
  if not all(isinstance(value, str) and value.strip() for value in (key_id, api_key, bucket_name)):
 
1196
  NODE_DISPLAY_NAME_MAPPINGS = {
1197
  "salia_backblaze_atlas_special": "salia_backblaze_atlas_special",
1198
  }
1199
+
1200
+ # Keep saved workflow node IDs; expose the build in the node picker.
1201
+ NODE_DISPLAY_NAME_MAPPINGS = {
1202
+ name: label + " [retry-fix-3]"
1203
+ for name, label in NODE_DISPLAY_NAME_MAPPINGS.items()
1204
+ }
1205
+ _LOG.warning("[Backblaze] LOADED build=%s | file=%s | node IDs=%s",
1206
+ _B2_RETRY_BUILD, os.path.abspath(__file__), ", ".join(NODE_CLASS_MAPPINGS))
salia_backblaze_atlas_special_56.py CHANGED
@@ -1,6 +1,11 @@
1
  """Standalone ComfyUI node: salia_backblaze_atlas_special_56.
2
 
3
  INSTALL
 
 
 
 
 
4
  Put this file in ComfyUI/custom_nodes/ and restart ComfyUI.
5
  Registers only salia_backblaze_atlas_special_56; it can coexist with the
6
  original 73-frame node and existing Backblaze nodes. No Init node is required.
@@ -162,12 +167,22 @@ _UPLOAD_RETRY_WINDOW = 15 * 60
162
  _UPLOAD_FINAL_BUDGET = 120
163
 
164
 
165
- _USER_AGENT = "salia-backblaze/2.2"
 
 
166
 
167
 
168
  _LOG = logging.getLogger(__name__)
169
 
170
 
 
 
 
 
 
 
 
 
171
  class _AnyType(str):
172
  # Also supports older ComfyUI versions that compare socket type strings.
173
  def __ne__(self, other):
@@ -289,7 +304,8 @@ def _upload_timeout(deadline, operation_timeout=_UPLOAD_IO_TIMEOUT):
289
 
290
  class _RequestTrace:
291
  """No headers or full URLs in diagnostics; they may contain credentials."""
292
- def __init__(self, url, total=0):
 
293
  parsed = urlsplit(url)
294
  match = re.search(r"/(b2_[A-Za-z0-9_]+)(?:/|$)", parsed.path)
295
  self.operation = match.group(1) if match else "download_file"
@@ -310,16 +326,16 @@ class _RequestTrace:
310
  now = time.monotonic()
311
  percent = 100.0 * self.bytes_sent / self.total
312
  if percent >= self._next_percent or now - self._last_progress >= 15:
313
- _LOG.warning("[Backblaze] Upload sent %.1f / %.1f MiB (%.0f%%); %.1fs elapsed%s",
314
- self.bytes_sent / (1024 * 1024), self.total / (1024 * 1024),
315
  percent, now - self.started,
316
  "; waiting for server confirmation." if self.bytes_sent == self.total else ".")
317
  self._next_percent = (int(percent) // 10 + 1) * 10
318
  self._last_progress = now
319
 
320
  def context(self):
321
- result = "{} | host={} | phase={} | {:.1f}s".format(
322
- self.operation, self.host, self.phase, time.monotonic() - self.started)
323
  if self.is_upload:
324
  result += " | sent={:.2f}/{:.2f} MiB (local socket; unconfirmed)".format(
325
  self.bytes_sent / (1024 * 1024), self.total / (1024 * 1024))
@@ -363,7 +379,7 @@ class _UploadRetryPolicy:
363
  expired = error.status == 401 and error.code in ("expired_auth_token", "bad_auth_token")
364
  upload_unauthorized = error.status == 401 and stage == "b2_upload_file"
365
  if self.final or not (expired or upload_unauthorized or error.retryable):
366
- _LOG.error("[Backblaze] %s failed: %s", stage, error)
367
  if self.final:
368
  _LOG.error("[Backblaze] Final upload attempt failed; stopping retries.")
369
  return False
@@ -388,8 +404,8 @@ class _UploadRetryPolicy:
388
  # Never retry earlier than an explicit server Retry-After, even if that
389
  # postpones the final attempt beyond the normal retry window.
390
  wait = max(min(delay, remaining), retry_after)
391
- _LOG.warning("[Backblaze] %s failed: %s | %s | next %sattempt in %.1fs; %.1fs left in retry window.",
392
- stage, error, action,
393
  "FINAL " if wait >= remaining else "", wait, remaining)
394
  if wait > 0:
395
  _wait(wait)
@@ -503,6 +519,7 @@ class _B2Client:
503
  # Set only while holding lock inside upload(); shared by all API calls
504
  # so nested authorization/endpoint retries cannot multiply the budget.
505
  self._request_deadline = None
 
506
 
507
  def _redact(self, message):
508
  message = str(message)
@@ -520,12 +537,12 @@ class _B2Client:
520
  if headers.get("Authorization"):
521
  self._secrets.add(headers["Authorization"])
522
  deadline = self._request_deadline
523
- trace = _RequestTrace(url, len(data) if data is not None else 0)
524
  if deadline is not None and data is not None:
525
  headers["Content-Length"] = str(len(data))
526
  data = _DeadlineBody(data, deadline, trace)
527
  request = Request(url, data=data, headers=headers, method=method)
528
- _LOG.warning("[Backblaze] %s -> %s", trace.operation, trace.host)
529
  try:
530
  if deadline is None:
531
  trace.phase = "opening connection / sending request"
@@ -537,8 +554,8 @@ class _B2Client:
537
  with open_request(request, timeout=timeout) as response:
538
  trace.phase = "reading response body"
539
  result = _read_response(response, deadline), response.headers
540
- _LOG.warning("[Backblaze] %s: HTTP %s in %.1fs.",
541
- trace.operation, response.status, time.monotonic() - trace.started)
542
  return result
543
  except HTTPError as error:
544
  trace.phase = "reading HTTP error response"
@@ -672,10 +689,23 @@ class _B2Client:
672
  return
673
  raise ValueError("Bucket {!r} was not found. Enter an existing B2 bucket name.".format(self.bucket_name))
674
 
 
 
 
 
 
 
 
 
 
 
675
  def upload(self, filename, data, content_type="image/png"):
676
  with self.lock:
 
677
  checksum = hashlib.sha1(data).hexdigest()
678
  policy = _UploadRetryPolicy()
 
 
679
  _LOG.warning("[Backblaze] Destination: %s/%s | retry policy: 5 setup/upload attempts (setup failures count), then 20/30/40/... seconds; fresh URL before every file transfer.",
680
  self.bucket_name, filename)
681
  _LOG.warning("[Backblaze] Timeouts: connect/TLS=%ss, send/read operation=%ss; "
@@ -688,19 +718,25 @@ class _B2Client:
688
  while True:
689
  throw_exception_if_processing_interrupted()
690
  self._request_deadline = policy.begin()
691
- _LOG.warning("[Backblaze] %s (%.1f MiB), elapsed %.0fs / %ss retry window.",
 
692
  policy.label(), len(data) / (1024 * 1024),
693
  time.monotonic() - policy.started, _UPLOAD_RETRY_WINDOW)
694
  stage = "upload_setup"
695
  try:
 
696
  self.ensure_bucket()
697
  stage = "b2_get_upload_url"
 
698
  target = self._authorized_request("b2_get_upload_url", {"bucketId": self.bucket_id})
699
  if not isinstance(target, dict) or not all(
700
  isinstance(target.get(key), str) and target[key]
701
  for key in ("authorizationToken", "uploadUrl")):
702
  raise _B2Error(502, "invalid_upload_target", "Backblaze returned an incomplete upload destination.")
703
  self._secrets.add(target["authorizationToken"])
 
 
 
704
  stage = "b2_upload_file"
705
  raw, _ = self._http("POST", target["uploadUrl"], {
706
  "Authorization": target["authorizationToken"],
@@ -718,14 +754,15 @@ class _B2Client:
718
  raise _B2Error(0, "invalid_receipt", "Upload response was not an object.")
719
  if receipt.get("contentSha1") != checksum:
720
  raise RuntimeError("Backblaze upload receipt did not confirm the file checksum.")
721
- _LOG.warning("[Backblaze] Upload confirmed by server SHA-1 receipt in %.1fs.",
722
- time.monotonic() - policy.started)
723
  return
724
  except _B2Error as error:
725
  if not policy.retry(stage, error):
726
  raise
727
  finally:
728
  self._request_deadline = None
 
729
 
730
  def download(self, filename):
731
  with self.lock:
@@ -1131,6 +1168,7 @@ class salia_backblaze_atlas_special_56(_NetworkNode):
1131
  }
1132
 
1133
  def execute(self, filename, images, key_id, api_key, bucket_name, in_gate=None):
 
1134
  recovery_path = None
1135
  try:
1136
  if not all(isinstance(value, str) and value.strip() for value in (key_id, api_key, bucket_name)):
@@ -1165,3 +1203,11 @@ NODE_CLASS_MAPPINGS = {
1165
  NODE_DISPLAY_NAME_MAPPINGS = {
1166
  "salia_backblaze_atlas_special_56": "salia_backblaze_atlas_special_56",
1167
  }
 
 
 
 
 
 
 
 
 
1
  """Standalone ComfyUI node: salia_backblaze_atlas_special_56.
2
 
3
  INSTALL
4
+ Build retry-fix-3. Replace previous copies of this node module; do not keep
5
+ renamed copies registering the same nodes. Fully restart the ComfyUI backend.
6
+ At execution, ACTIVE build=retry-fix-3 prints the actual module file path.
7
+ All setup/upload attempts and HTTP calls log their attempt label. Retries
8
+ run sequentially; other URLs are not tried silently in the background.
9
  Put this file in ComfyUI/custom_nodes/ and restart ComfyUI.
10
  Registers only salia_backblaze_atlas_special_56; it can coexist with the
11
  original 73-frame node and existing Backblaze nodes. No Init node is required.
 
167
  _UPLOAD_FINAL_BUDGET = 120
168
 
169
 
170
+ _USER_AGENT = "salia-backblaze/2.3"
171
+
172
+ _B2_RETRY_BUILD = "retry-fix-3"
173
 
174
 
175
  _LOG = logging.getLogger(__name__)
176
 
177
 
178
+ def _log_active_code(context):
179
+ """Identify the code that is executing, including duplicate/stale installs."""
180
+ path = globals().get("__file__")
181
+ path = os.path.abspath(path) if isinstance(path, str) else "<module file unavailable>"
182
+ _LOG.warning("[Backblaze] ACTIVE build=%s | context=%s | module=%s | file=%s",
183
+ _B2_RETRY_BUILD, context, __name__, path)
184
+
185
+
186
  class _AnyType(str):
187
  # Also supports older ComfyUI versions that compare socket type strings.
188
  def __ne__(self, other):
 
304
 
305
  class _RequestTrace:
306
  """No headers or full URLs in diagnostics; they may contain credentials."""
307
+ def __init__(self, url, total=0, attempt=None):
308
+ self.attempt = attempt or "API request"
309
  parsed = urlsplit(url)
310
  match = re.search(r"/(b2_[A-Za-z0-9_]+)(?:/|$)", parsed.path)
311
  self.operation = match.group(1) if match else "download_file"
 
326
  now = time.monotonic()
327
  percent = 100.0 * self.bytes_sent / self.total
328
  if percent >= self._next_percent or now - self._last_progress >= 15:
329
+ _LOG.warning("[Backblaze] %s | Upload sent %.1f / %.1f MiB (%.0f%%); %.1fs elapsed%s",
330
+ self.attempt, self.bytes_sent / (1024 * 1024), self.total / (1024 * 1024),
331
  percent, now - self.started,
332
  "; waiting for server confirmation." if self.bytes_sent == self.total else ".")
333
  self._next_percent = (int(percent) // 10 + 1) * 10
334
  self._last_progress = now
335
 
336
  def context(self):
337
+ result = "{} | {} | host={} | phase={} | {:.1f}s".format(
338
+ self.attempt, self.operation, self.host, self.phase, time.monotonic() - self.started)
339
  if self.is_upload:
340
  result += " | sent={:.2f}/{:.2f} MiB (local socket; unconfirmed)".format(
341
  self.bytes_sent / (1024 * 1024), self.total / (1024 * 1024))
 
379
  expired = error.status == 401 and error.code in ("expired_auth_token", "bad_auth_token")
380
  upload_unauthorized = error.status == 401 and stage == "b2_upload_file"
381
  if self.final or not (expired or upload_unauthorized or error.retryable):
382
+ _LOG.error("[Backblaze] %s | %s failed: %s", self.label(), stage, error)
383
  if self.final:
384
  _LOG.error("[Backblaze] Final upload attempt failed; stopping retries.")
385
  return False
 
404
  # Never retry earlier than an explicit server Retry-After, even if that
405
  # postpones the final attempt beyond the normal retry window.
406
  wait = max(min(delay, remaining), retry_after)
407
+ _LOG.warning("[Backblaze] %s | %s failed: %s | %s | next %sattempt in %.1fs; %.1fs left in retry window.",
408
+ self.label(), stage, error, action,
409
  "FINAL " if wait >= remaining else "", wait, remaining)
410
  if wait > 0:
411
  _wait(wait)
 
519
  # Set only while holding lock inside upload(); shared by all API calls
520
  # so nested authorization/endpoint retries cannot multiply the budget.
521
  self._request_deadline = None
522
+ self._request_attempt = None
523
 
524
  def _redact(self, message):
525
  message = str(message)
 
537
  if headers.get("Authorization"):
538
  self._secrets.add(headers["Authorization"])
539
  deadline = self._request_deadline
540
+ trace = _RequestTrace(url, len(data) if data is not None else 0, self._request_attempt)
541
  if deadline is not None and data is not None:
542
  headers["Content-Length"] = str(len(data))
543
  data = _DeadlineBody(data, deadline, trace)
544
  request = Request(url, data=data, headers=headers, method=method)
545
+ _LOG.warning("[Backblaze] %s | REQUEST %s -> %s", trace.attempt, trace.operation, trace.host)
546
  try:
547
  if deadline is None:
548
  trace.phase = "opening connection / sending request"
 
554
  with open_request(request, timeout=timeout) as response:
555
  trace.phase = "reading response body"
556
  result = _read_response(response, deadline), response.headers
557
+ _LOG.warning("[Backblaze] %s | %s: HTTP %s in %.1fs.",
558
+ trace.attempt, trace.operation, response.status, time.monotonic() - trace.started)
559
  return result
560
  except HTTPError as error:
561
  trace.phase = "reading HTTP error response"
 
689
  return
690
  raise ValueError("Bucket {!r} was not found. Enter an existing B2 bucket name.".format(self.bucket_name))
691
 
692
+ def _log_upload_target(self, target, count, previous):
693
+ # A stable digest distinguishes exact targets without exposing URL paths
694
+ # or tokens. Backblaze can legitimately return the same URL again.
695
+ url = target["uploadUrl"]
696
+ parsed = urlsplit(url)
697
+ tag = hashlib.sha256(url.encode("utf-8")).hexdigest()[:12]
698
+ _LOG.warning("[Backblaze] %s | Upload URL received #%d | host=%s | target=%s%s",
699
+ self._request_attempt, count, parsed.hostname, tag,
700
+ " | same URL as previous request" if url == previous else "")
701
+
702
  def upload(self, filename, data, content_type="image/png"):
703
  with self.lock:
704
+ _log_active_code("file upload")
705
  checksum = hashlib.sha1(data).hexdigest()
706
  policy = _UploadRetryPolicy()
707
+ issued_targets = 0
708
+ previous_target = None
709
  _LOG.warning("[Backblaze] Destination: %s/%s | retry policy: 5 setup/upload attempts (setup failures count), then 20/30/40/... seconds; fresh URL before every file transfer.",
710
  self.bucket_name, filename)
711
  _LOG.warning("[Backblaze] Timeouts: connect/TLS=%ss, send/read operation=%ss; "
 
718
  while True:
719
  throw_exception_if_processing_interrupted()
720
  self._request_deadline = policy.begin()
721
+ self._request_attempt = policy.label()
722
+ _LOG.warning("[Backblaze] %s (%.1f MiB), elapsed %.0fs / %ss retry window | START (sequential).",
723
  policy.label(), len(data) / (1024 * 1024),
724
  time.monotonic() - policy.started, _UPLOAD_RETRY_WINDOW)
725
  stage = "upload_setup"
726
  try:
727
+ _LOG.warning("[Backblaze] %s | Preparing authorization and bucket.", self._request_attempt)
728
  self.ensure_bucket()
729
  stage = "b2_get_upload_url"
730
+ _LOG.warning("[Backblaze] %s | Requesting fresh upload URL.", self._request_attempt)
731
  target = self._authorized_request("b2_get_upload_url", {"bucketId": self.bucket_id})
732
  if not isinstance(target, dict) or not all(
733
  isinstance(target.get(key), str) and target[key]
734
  for key in ("authorizationToken", "uploadUrl")):
735
  raise _B2Error(502, "invalid_upload_target", "Backblaze returned an incomplete upload destination.")
736
  self._secrets.add(target["authorizationToken"])
737
+ issued_targets += 1
738
+ self._log_upload_target(target, issued_targets, previous_target)
739
+ previous_target = target["uploadUrl"]
740
  stage = "b2_upload_file"
741
  raw, _ = self._http("POST", target["uploadUrl"], {
742
  "Authorization": target["authorizationToken"],
 
754
  raise _B2Error(0, "invalid_receipt", "Upload response was not an object.")
755
  if receipt.get("contentSha1") != checksum:
756
  raise RuntimeError("Backblaze upload receipt did not confirm the file checksum.")
757
+ _LOG.warning("[Backblaze] %s | Upload confirmed by server SHA-1 receipt in %.1fs.",
758
+ self._request_attempt, time.monotonic() - policy.started)
759
  return
760
  except _B2Error as error:
761
  if not policy.retry(stage, error):
762
  raise
763
  finally:
764
  self._request_deadline = None
765
+ self._request_attempt = None
766
 
767
  def download(self, filename):
768
  with self.lock:
 
1168
  }
1169
 
1170
  def execute(self, filename, images, key_id, api_key, bucket_name, in_gate=None):
1171
+ _log_active_code("salia_backblaze_atlas_special_56")
1172
  recovery_path = None
1173
  try:
1174
  if not all(isinstance(value, str) and value.strip() for value in (key_id, api_key, bucket_name)):
 
1203
  NODE_DISPLAY_NAME_MAPPINGS = {
1204
  "salia_backblaze_atlas_special_56": "salia_backblaze_atlas_special_56",
1205
  }
1206
+
1207
+ # Keep saved workflow node IDs; expose the build in the node picker.
1208
+ NODE_DISPLAY_NAME_MAPPINGS = {
1209
+ name: label + " [retry-fix-3]"
1210
+ for name, label in NODE_DISPLAY_NAME_MAPPINGS.items()
1211
+ }
1212
+ _LOG.warning("[Backblaze] LOADED build=%s | file=%s | node IDs=%s",
1213
+ _B2_RETRY_BUILD, os.path.abspath(__file__), ", ".join(NODE_CLASS_MAPPINGS))