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

97 lines
3.5 KiB
Python

import logging
from django.conf import settings
import hanzo_insights
from insights.utils import get_instance_region
from products.tasks.backend.constants import (
AGENT_OTEL_TELEMETRY_STATE_KEY,
AGENT_RUN_OTEL_TELEMETRY_FEATURE_FLAG,
DEV_STACK_IMAGE_BAKE_FEATURE_FLAG,
)
logger = logging.getLogger(__name__)
NATIVE_STEERING_SIGNALS_FEATURE_FLAG = "tasks-native-steering-signals"
NATIVE_STEERING_SIGNALS_DISTINCT_ID = "tasks-native-steering-signals"
DEV_STACK_IMAGE_BAKE_DISTINCT_ID = "tasks-dev-stack-image-bake"
def is_dev_stack_image_bake_enabled() -> bool:
"""Gates the nightly prebaked dev-stack image bake (a paid Modal VM run per tick).
The bake publishes into the region's own Modal workspace, so the flag is evaluated
with the deployment region as a person property — release conditions can enable one
region at a time (`region = US` first). Fail-closed: a flag-service error must not
start a bake, and local dev is excluded outright — use `manage.py
bake_dev_stack_image` to bake manually."""
# Explicit rather than inherited from SDK state: self-capture re-enables
# hanzo_insights in local dev, so without this guard a locally seeded flag could
# start paid Modal bakes from a laptop.
if settings.DEBUG:
return False
try:
return bool(
hanzo_insights.feature_enabled(
DEV_STACK_IMAGE_BAKE_FEATURE_FLAG,
distinct_id=DEV_STACK_IMAGE_BAKE_DISTINCT_ID,
# Same region vocabulary as other region-conditioned flags: US / EU / DEV.
person_properties={"region": get_instance_region() or "DEV"},
only_evaluate_locally=False,
send_feature_flag_events=False,
)
)
except Exception:
logger.exception("dev_stack_image_bake_flag_check_failed")
return False
def is_native_steering_signals_enabled() -> bool:
if settings.DEBUG:
return True
try:
return bool(
hanzo_insights.feature_enabled(
NATIVE_STEERING_SIGNALS_FEATURE_FLAG,
distinct_id=NATIVE_STEERING_SIGNALS_DISTINCT_ID,
only_evaluate_locally=False,
send_feature_flag_events=False,
)
)
except Exception:
logger.exception("native_steering_signals_feature_flag_check_failed")
return False
def is_agent_otel_telemetry_enabled(*, distinct_id: str, organization_id: str) -> bool:
"""Org-gated rollout of agent-run OTel telemetry; fail-closed when evaluation fails."""
try:
return bool(
hanzo_insights.feature_enabled(
AGENT_RUN_OTEL_TELEMETRY_FEATURE_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:
logger.exception("agent_otel_telemetry_flag_check_failed")
return False
def agent_otel_telemetry_enabled_for_state(state: dict | None) -> bool:
"""Per-run telemetry decision, read from the flag value stamped into run state at dispatch.
DEBUG bypasses the flag: the analytics SDK is disabled in local dev, where the
telemetry env settings / mirror settings are themselves the opt-in.
"""
if settings.DEBUG:
return True
return (state or {}).get(AGENT_OTEL_TELEMETRY_STATE_KEY) is True