Skip to content

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

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.py
index 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 func
import re
import logging
from collections.abc import Iterable, Sequence
+from concurrent.futures import ThreadPoolExecutor
from datetime import datetime, timedelta
from typing import Any, Literal
from urllib.parse import urlparse
@@ -69,6 +70,8 @@ from . import contracts
logger = 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.py
index 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 * 60
TASK_RUN_ARTIFACT_UPLOAD_FORM_OVERHEAD_BYTES = 64 * 1024
-SESSION_LOG_PAGE_MAX_BYTES = 2 * 1024 * 1024
+SESSION_LOG_PAGE_MAX_BYTES = 16 * 1024 * 1024
SESSION_LOG_PAGE_ENVELOPE_BYTES = 2