Files
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

59 lines
2.1 KiB
Python

from django.conf import settings
from django.core.cache import BaseCache, caches
import hanzo_insights
from insights.caching.tasks_redis_cache import TASKS_DEDICATED_CACHE_ALIAS
from insights.redis import get_async_client, get_client
# Evaluated once at run creation and pinned onto TaskRun.state["use_dedicated_stream"] so the
# SSE reader and the temporal worker always agree for a run's life (no split-brain on flag
# propagation or pod restarts).
TASKS_DEDICATED_REDIS_STREAMS_FLAG = "tasks-dedicated-redis-streams"
def evaluate_dedicated_stream_flag(*, organization_id: str, distinct_id: str) -> bool:
# Gated on TASKS_REDIS_URL so the deciding process only opts a run into the dedicated
# instance if it can itself reach it — a misconfigured pod fails safe to shared.
if not settings.TASKS_REDIS_URL:
return False
try:
return bool(
hanzo_insights.feature_enabled(
TASKS_DEDICATED_REDIS_STREAMS_FLAG,
distinct_id=distinct_id,
groups={"organization": organization_id},
group_properties={"organization": {"id": organization_id}},
only_evaluate_locally=False,
send_feature_flag_events=False,
)
)
except Exception:
return False
def run_uses_dedicated_stream(state: dict | None) -> bool:
# Defaults to shared so runs created before this rollout stay on the shared instance.
return bool((state or {}).get("use_dedicated_stream", False))
def _tasks_stream_redis_url(use_dedicated: bool) -> str:
dedicated = settings.TASKS_REDIS_URL
if dedicated and use_dedicated:
return dedicated
return settings.REDIS_URL
def get_tasks_stream_redis_async(use_dedicated: bool = False):
return get_async_client(_tasks_stream_redis_url(use_dedicated))
def get_tasks_stream_redis_sync(use_dedicated: bool = False):
return get_client(_tasks_stream_redis_url(use_dedicated))
def get_tasks_cache() -> BaseCache:
if settings.TASKS_REDIS_URL and TASKS_DEDICATED_CACHE_ALIAS in settings.CACHES:
return caches[TASKS_DEDICATED_CACHE_ALIAS]
return caches["default"]