The Orchestrator now writes the slot v2 (contract C1) the OPC Gateway reads:
one entry per (server, address) with a names[] list, so an address read by N
pipelines is read once and written to N collections (fixes "one name per
address", where the second model's scouter discarded everything).
- O1: load connectors (opc_ua, Active) and connector_tags (Read, Active) in
parallel with the current loads. Queries are optional in the input with
defaults in code (D9); empty or missing collections load nothing. The loads
sit behind workflow.patched('SIENTIAPDE-1974-tag-database'), so a run in
flight during a deploy replays without them.
- O2: gather_read_tags groups by (server, address). A read tag with tag_id
resolves address/connector from connector_tags and the server from connectors
(RF3); without tag_id it keeps server_id + tag_address + opc-servers (RF4),
so every environment without a tag database keeps collecting (P4).
- O3/SC1: resolve_tag_names is the single source of tag names for both the
scouter's model_tags and the slot's names[].
- O4: build_tag_config emits server_id/name/url/server_uri/use_security/
subscription_period_ms + tags{frequency, active_read, names}; no certificate
paths (the gateway takes the certificate from MinIO). frequency = lowest
among pipelines; subscription period = connector value, else min/2 as before;
active_read off unless a pipeline enables it (lowest cycle_multiple, D3).
- O5: process_slots splits by address (names of an address never split) and
notifies, once per run, unknown tag_id, missing/inactive connector and
unknown opc-servers server_id.
- O6: create_slot_config writes only new or changed slots; the slot is built
in a stable order, so unchanged pipelines do not make the gateway
re-subscribe (and the "Inserted slots" report stops firing every run).
- O7: unit tests for multi-name, repeated address, unknown tag_id, inactive
connector, mixed tags, server-name clash, active_read, slot division,
stability, SC1 and the replay path (184 tests).
- O8: README documents the slot v2 contract and the new optional inputs.
- test_email.test_close: count only the instance under test; an Email left by
another test can be garbage-collected (Email.__del__ -> close) while the
patch is active, which the new tests' allocation pattern exposed.
Dry run with the dev data (scouter-sin-approx): the v2 slot is equivalent to
the current v1 slot as seen by the gateway's parse_slot (same server, addresses,
collections, names, frequency and subscription period).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8.0 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project
SIENTIA DataOps Orchestrator — a Temporal.io workflow application for pipeline orchestration, real-time alerting, and scheduled reporting on the SIENTIA platform. Python 3.11+, package name orchestrator.
Commands
Install deps:
pip install -r requirements.txt
pip install -r requirements-dev.txt # ruff, mypy, bandit, pytest, pytest-cov, pytest-asyncio
Run the worker locally (activates venv, loads .env, runs python -m orchestrator.worker.worker):
./run_local.sh
Tests:
pytest tests/ --cov=orchestrator --cov-report=html # full suite with coverage
pytest tests/orchestrator/activities/test_mongo_db.py # single file
pytest tests/orchestrator/activities/test_mongo_db.py::TestClass::test_name # single test
./run_coverage.sh # runs pytest w/ coverage, opens htmlcov/index.html
Lint/format/type/security (run individually — validate.sh referenced by README no longer exists in the repo, so don't rely on it):
ruff format --check orchestrator/ tests/
ruff check orchestrator/ tests/
mypy orchestrator/
bandit -r orchestrator/ -ll
# autofix
ruff format orchestrator/ tests/
ruff check --fix orchestrator/ tests/
CI quality gate (.github/workflows/quality-gate.yml) calls the shared reusable workflow Aignosi/github_workflow_templates/.github/workflows/dataops-module-quality-gate.yml on PRs to main — it's the source of truth for what must pass, not a local script.
Architecture
Layering
orchestrator/worker/worker.py— entrypoint (python -m orchestrator.worker.worker). Builds a singleActivitiesinstance, connects to Temporal, starts Prometheus (HTTP_METRICS_PORT) and Temporal SDK metrics (HTTP_SDK_METRICS_PORT) servers, then runs threeWorkers concurrently viaasyncio.gather, each on its own task queue:orchestrator-queue,alerts-queue,reports-queue.prepare_worker.pyderives the queue name from the workflow class name (camel_to_snake) and reads per-queue concurrency/poller tuning from env vars prefixed with the workflow name (e.g.ORCHESTRATOR_MAX_CONCURRENT_ACTIVITIES).orchestrator/workflows/— Temporal workflow definitions:orchestrator.py(pipeline/slot/schedule orchestration),alerts.py(real-time ERROR notifications),reports.py(scheduled all-level reports).alerts.pyandreports.pyboth delegate to the same two subworkflows inworkflows/subworkflows/:load_notification_package.py(load notifications + receiver configs from Mongo, incremental via Redis timestamp) andprocess_notifications.py(build HTML email, send, log to Postgres). The difference between alerts and reports is which filter activity they call (filter_notification_alertsvsfilter_notification_reports) and their base data filter (level: ERRORby default vs all levels) —load_notification_package.py's_compute_query_time_filtercan widen either beyond that default to the union of active receiver groups' ownlevels(SIENTIAPDE-2011); the ERROR-only default only holds when no active group narrows further. Receiver groups also support amodel_idsallow-list (SIENTIAPDE-2149), independent of the pre-existingignore_models_iddeny-list — both apply together (AND) when a group configures both, andmodel_idsfollows the same union-at-query-time / precise-per-group-slice split aslevels.load_latest_data's Mongo query is capped atNOTIFICATION_QUEUE_BATCH_SIZEdocuments per run (default0, meaning unlimited — unchanged from pre-SIENTIAPDE-2013 behavior unless a deployment opts in), sorted bytimestampascending so a capped run always returns the oldest pending batch first (SIENTIAPDE-2013) — a hard cap with no drain loop, since the incremental Redis cursor picks up any remainder on the next run.orchestrator/activities/activities.py—Activitiesis a single class combining every activity mixin via multiple inheritance:TemporalManager, SlotManager, Formatters, MongoDB, Email, Postgres(Postgres comes fromsientia_do.temporal.activities.postgres, the externalsientia-dataops-librarydependency). One instance is constructed inworker.pyand its bound methods are handed to eachWorkeras the activity list — activities are plain methods on this shared object, not separate classes. Each mixin's__init__takes its own config dict plus sharedlogger,notification_handler,metrics_controller.Activities.shutdown()closes every mixin's connections.orchestrator/utils/—connectors_config.pybuilds each config dict from env vars (Temporal/Redis/MongoDB/Postgres/Email);email_builder.pyrenders Jinja2 templates (utils/templates/email_template.html,general_template.html);orchestrator_functions.pytransforms pipeline documents into pipeline-type-specific configs (scouter,pi_web_api_scouter,predictions_batch,minimal_retrain,drift,simple_metrics) and builds the OPC slot v2 the gateway reads (gather_read_tags/build_tag_config, contract C1: one entry per address with anames[]list, tags resolved through the tag database when they carry atag_id; see the README section "OPC slots").resolve_tag_namesis the single source of tag names for both the scouter'smodel_tagsand the slot'snames(SIENTIAPDE-1974 SC1);converters.pyhandles Temporal schedule frequency parsing.
Temporal-specific conventions (all workflow/activity files follow this)
- Every workflow and activity-consuming module wraps non-deterministic/side-effecting imports in
with workflow.unsafe.imports_passed_through(): ...right afterfrom temporalio import workflow, because Temporal's sandbox restricts what workflow code can import directly. When adding a new workflow file, follow the existing pattern (seeorchestrator/workflows/orchestrator.py,orchestrator/activities/activities.py) rather than importing at module top level. - Workflows are registered with
@workflow.defn(name='...'); therunmethod is@workflow.run. Activity calls from within a workflow go throughworkflow.start_local_activity_method/workflow.execute_activity_methodreferencingActivities.<method>(the class method, not an instance) with aretry_policyfromsientia_do.temporal.policies. - Task queue isolation is deliberate: don't move activities between the orchestrator/alerts/reports worker activity lists without checking which queue actually needs them — each list in
worker.pyis scoped to what that workflow (+ its subworkflows) calls. - Namespaces: Temporal schedules span two namespaces,
scouterandlaborious(TEMPORAL_SCOUTER_NAMESPACE/TEMPORAL_LABORIOUS_NAMESPACE), handled insideTemporalManager.
External dependency
sientia-dataops-library (pinned via requirements.txt as a git dependency, currently @1.8.2) supplies sientia_do.observability.logger, sientia_do.observability.metrics_controller, sientia_do.notifications.handlers, sientia_do.temporal.policies, and sientia_do.temporal.activities.postgres.Postgres. It is a separate Aignosi repo — its version bump is a deliberate, explicit change, not incidental.
Tests
tests/ mirrors orchestrator/ (tests/orchestrator/activities/, tests/orchestrator/utils/, tests/orchestrator/workflows/...). Async tests use pytest-asyncio; coverage targets the orchestrator package. When testing Temporal workflows, follow the existing pattern in tests/orchestrator/workflows/test_orchestrator.py / test_alerts.py / test_reports.py (using Temporal's test env / activity mocking) rather than hitting real Temporal/Mongo/Redis/Postgres.
Ruff config notes (pyproject.toml)
Single quotes enforced by formatter. Notably ignored lint rules with reasons already documented inline: B023 (closures over loop vars needed for schedule-action assembly), BLE001 (blind except needed so activities can always notify on any error), N802/N806 (Temporal decorators/variables don't follow standard naming), S105/S106 (false-positive hardcoded-password matches).