:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(tasks): speed up resumed task log loading (#73092)
Alessandro Pogliaghib2103fba59ec
diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.pyindex 2e583a2dbea0..a427210a1cb2 100644--- a/products/tasks/backend/facade/api.py+++ b/products/tasks/backend/facade/api.py@@ -18,6 +18,7 @@ Functions that bridge to those heavy surfaces import them lazily inside the funcimport reimport loggingfrom collections.abc import Iterable, Sequence+from concurrent.futures import ThreadPoolExecutorfrom datetime import datetime, timedeltafrom typing import Any, Literalfrom urllib.parse import urlparse@@ -69,6 +70,8 @@ from . import contractslogger = logging.getLogger(__name__)+_TASK_LOG_READ_EXECUTOR = ThreadPoolExecutor(max_workers=8, thread_name_prefix="task-log-read")+# --- Enum re-exports ---# Value types (not ORM models), safe to expose. External callers compare against the# string-valued ``.status`` / ``.environment`` / ``.origin_product`` fields on the DTOs.@@ -2581,9 +2584,17 @@ def read_task_run_logs(run_id: str | UUID, task_id: str | UUID, team_id: int) ->if run is None:return None+ resume_chain = run.get_resume_chain()+ chunks: Iterable[str]+ if len(resume_chain) == 1:+ chunks = [object_storage.read(resume_chain[0].log_url, missing_ok=True) or ""]+ else:+ chunks = _TASK_LOG_READ_EXECUTOR.map(+ lambda ancestor: object_storage.read(ancestor.log_url, missing_ok=True) or "", resume_chain+ )+parts: list[str] = []- for ancestor in run.get_resume_chain():- chunk = object_storage.read(ancestor.log_url, missing_ok=True) or ""+ for chunk in chunks:if chunk:if not chunk.endswith("\n"):chunk = chunk + "\n"diff --git a/products/tasks/backend/presentation/views/api.py b/products/tasks/backend/presentation/views/api.pyindex 443977c04515..5a7e15b3cbe5 100644--- a/products/tasks/backend/presentation/views/api.py+++ b/products/tasks/backend/presentation/views/api.py@@ -143,7 +143,7 @@ TASK_RUN_ARTIFACT_UPLOAD_EXPIRATION_SECONDS = 60 * 60TASK_RUN_ARTIFACT_UPLOAD_FORM_OVERHEAD_BYTES = 64 * 1024-SESSION_LOG_PAGE_MAX_BYTES = 2 * 1024 * 1024+SESSION_LOG_PAGE_MAX_BYTES = 16 * 1024 * 1024SESSION_LOG_PAGE_ENVELOPE_BYTES = 2