diff --git a/contracts/OMN-20674.yaml b/contracts/OMN-20674.yaml new file mode 100644 index 0000000000..b3851640d9 --- /dev/null +++ b/contracts/OMN-20674.yaml @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +--- +schema_version: "1.0.0" +ticket_id: "OMN-20674" +title: "Host the morning friction sweep orchestrator with a deployment overlay" +summary: "Host the morning friction sweep as an unregistered omnimarket node: contract with declared bus topics, golden chain, error chain, decision parity against transcripts recorded from the original workflow, and a strict deployment overlay for every brief, path, lane and bound. The caller switch and the deletion of the original entry points are separate steps in the operator tooling repository." +is_seam_ticket: false +interface_change: false +interfaces_touched: [] +requirements: + - id: "req-friction-node" + statement: "Host the friction sweep as a contract, a declarative node and a Definition-B handler whose topics are declared in the contract." + acceptance: + - id: "AC1" + statement: "AC1: the tool is a contract.yaml, a declarative node and a handler with the canonical definition-B signature, and its topics are declared in the contract" +evidence_requirements: + - kind: "tests" + description: "AC1: golden chain, decision parity against the recorded original transcripts, error chain, overlay and phase gateway pass." + command: "uv run pytest tests/nodes/node_morning_friction_sweep_orchestrator/test_golden_chain_morning_friction_sweep_orchestrator.py -q -p no:randomly" +emergency_bypass: + enabled: false + justification: "" + follow_up_ticket_id: "" +dod_evidence: + - id: "dod-omn20674-ac1-golden-chain" + description: "AC1: golden chain and decision parity pass." + source: "manual" + checks: + - check_type: "test_passes" + check_value: "uv run pytest tests/nodes/node_morning_friction_sweep_orchestrator/test_golden_chain_morning_friction_sweep_orchestrator.py -q -p no:randomly" + cwd: "${OMNI_HOME}/omnimarket" + binds_ac: ["AC1"] diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/__init__.py b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/__init__.py new file mode 100644 index 0000000000..cc71d562af --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/__init__.py @@ -0,0 +1,25 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Canonical morning friction sweep orchestration.""" + +from .handlers.handler_morning_friction_sweep import ( + DELEGATION_REASON_RE, + OVERLAY_ENV, + HandlerMorningFrictionSweep, + MorningFrictionSweepConfigurationError, + delegation_problem, + load_friction_overlay, + premise_audit_problem, +) +from .node import NodeMorningFrictionSweepOrchestrator + +__all__ = [ + "DELEGATION_REASON_RE", + "OVERLAY_ENV", + "HandlerMorningFrictionSweep", + "MorningFrictionSweepConfigurationError", + "NodeMorningFrictionSweepOrchestrator", + "delegation_problem", + "load_friction_overlay", + "premise_audit_problem", +] diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/contract.yaml b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/contract.yaml new file mode 100644 index 0000000000..170a95474b --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/contract.yaml @@ -0,0 +1,75 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +name: node_morning_friction_sweep_orchestrator +contract_version: {major: 1, minor: 0, patch: 0} +node_type: orchestrator +node_version: {major: 1, minor: 0, patch: 0} +lifecycle: experimental +description: > + Guarded morning friction sweep: same-date idempotency precheck, five + concurrent sources, synthesis, adjudication, then report and watermark. + Phase execution reuses the canonical delegation orchestrator and infra + request-response wiring. The deployment's briefs, paths, lanes and bounds + come from an overlay; the node holds none of them. +input_model: + name: ModelMorningFrictionSweepRequest + module: omnimarket.nodes.node_morning_friction_sweep_orchestrator.models.model_morning_friction_sweep +output_model: + name: ModelMorningFrictionSweepResult + module: omnimarket.nodes.node_morning_friction_sweep_orchestrator.models.model_morning_friction_sweep +handler: + module: omnimarket.nodes.node_morning_friction_sweep_orchestrator.handlers.handler_morning_friction_sweep + class: HandlerMorningFrictionSweep +handler_routing: + routing_strategy: operation_match + handlers: + - operation: morning_friction_sweep + handler: + name: HandlerMorningFrictionSweep + module: omnimarket.nodes.node_morning_friction_sweep_orchestrator.handlers.handler_morning_friction_sweep + input_model: omnimarket.nodes.node_morning_friction_sweep_orchestrator.models.model_morning_friction_sweep.ModelMorningFrictionSweepRequest + output_model: omnimarket.nodes.node_morning_friction_sweep_orchestrator.models.model_morning_friction_sweep.ModelMorningFrictionSweepResult +terminal_event: onex.evt.omnimarket.morning-friction-sweep-completed.v1 +terminal_events: + success: onex.evt.omnimarket.morning-friction-sweep-completed.v1 + failure: onex.evt.omnimarket.morning-friction-sweep-failed.v1 +descriptor: + node_archetype: orchestrator + purity: impure + idempotent: false + timeout_ms: 18000000 + runtime_profiles: [effects] +env_dependencies: + ONEX_ENVIRONMENT: {required: true, description: Explicit runtime environment for canonical bus wiring.} + OMNIMARKET_MORNING_FRICTION_SWEEP_OVERLAY: {required: false, description: Path to the deployment overlay.yaml; when unset the first node_morning_friction_sweep_orchestrator/overlay.yaml under ONEX_SKILL_OVERLAY_ROOTS is used, and a run with neither refuses to start.} +event_bus: + subscribe_topics: + - onex.cmd.omnimarket.morning-friction-sweep-start.v1 + publish_topics: + - onex.evt.omnimarket.morning-friction-sweep-completed.v1 + - onex.evt.omnimarket.morning-friction-sweep-failed.v1 + - onex.cmd.omnibase-infra.delegation-request.v1 + request_response: + instances: + - name: friction_phase + request_topic: onex.cmd.omnibase-infra.delegation-request.v1 + reply_topics: + completed: onex.evt.omnibase-infra.delegation-completed.v1 + failed: onex.evt.omnibase-infra.delegation-failed.v1 + correlation: {location: body, field: correlation_id} + timeout_seconds: 7200 + consumer_group_mode: per_instance +runtime_dispatch: + # The host scheduler (CLI dispatcher) is this node's producer; declared so it is not inferred from subscribe_topics[0]. + command_topic: onex.cmd.omnimarket.morning-friction-sweep-start.v1 + +# Explicit SINK declaration (contract topic graph closure): no node contract +# subscribes to these; the host scheduler that started the run reads the terminal. +externally_consumed_topics: + - onex.evt.omnimarket.morning-friction-sweep-completed.v1 + - onex.evt.omnimarket.morning-friction-sweep-failed.v1 + +metadata: + ticket: OMN-20674 + phase_order: [Precheck, Scan, Synthesize, Adjudicate, Report] + transport_type: kafka diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/handlers/__init__.py b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/handlers/__init__.py new file mode 100644 index 0000000000..b4b17ef9d5 --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/handlers/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Morning friction sweep handlers.""" diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/handlers/handler_friction_phase_bus.py b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/handlers/handler_friction_phase_bus.py new file mode 100644 index 0000000000..e457d768ce --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/handlers/handler_friction_phase_bus.py @@ -0,0 +1,144 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Use the canonical delegation request-response wiring for friction sweep phases. + +No model HTTP clients, subprocess executors, or consumer implementation here. +The infra runtime owns publishing, correlation matching, and bounded replies. +""" + +from __future__ import annotations + +import asyncio +import json +import os +from importlib.resources import files +from typing import cast +from uuid import uuid5 + +import yaml +from omnibase_core.models.contracts.subcontracts import ModelRequestResponseConfig +from omnibase_core.models.delegation.wire import ModelDelegationRequest +from omnibase_core.models.events.model_event_envelope import ModelEventEnvelope +from omnibase_core.protocols.event_bus.protocol_event_bus_publisher import ( + ProtocolEventBusPublisher, +) +from pydantic import BaseModel, JsonValue + +from ..models import model_friction_phase_results as results +from ..models.model_morning_friction_sweep import ( + ModelFrictionPhaseRequest, + ModelMorningFrictionSweepRequest, +) +from ..protocols.protocol_friction_rpc import ProtocolFrictionRpc + +PACKAGE = "omnimarket.nodes.node_morning_friction_sweep_orchestrator" +INSTANCE = "friction_phase" + +RESULT_TYPES: dict[str, type[BaseModel]] = { + "friction-precheck": results.ModelFrictionPrecheck, + "friction-scan": results.ModelFrictionScan, + "friction-source-linear": results.ModelFrictionSource, + "friction-source-checkpoints": results.ModelFrictionSource, + "friction-source-ci": results.ModelFrictionSource, + "friction-source-guards": results.ModelFrictionSource, + "friction-synthesize": results.ModelFrictionSynthesis, + "friction-adjudicate": results.ModelFrictionAdjudication, + "friction-report": results.ModelFrictionReport, +} + + +class HandlerFrictionPhaseBus: + """A phase gateway using infra's existing RPC service and delegation topics.""" + + def __init__( + self, + event_bus: ProtocolEventBusPublisher | None = None, + rpc: ProtocolFrictionRpc | None = None, + ) -> None: + self._rpc = rpc + self._event_bus = event_bus + self._lock = asyncio.Lock() + self._instance: dict[str, JsonValue] | None = None + + def _request_response(self) -> dict[str, JsonValue]: + contract = yaml.safe_load(files(PACKAGE).joinpath("contract.yaml").read_text()) + return cast(dict[str, JsonValue], contract["event_bus"]["request_response"]) + + def _declared_instance(self) -> dict[str, JsonValue]: + if self._instance is None: + instances = cast( + list[dict[str, JsonValue]], self._request_response()["instances"] + ) + self._instance = next(i for i in instances if i["name"] == INSTANCE) + return self._instance + + async def _wiring(self) -> ProtocolFrictionRpc: + async with self._lock: + if self._rpc is None: + if self._event_bus is None: + raise ValueError("friction sweep requires the runtime event_bus") + from omnibase_infra.runtime.request_response_wiring import ( + RequestResponseWiring, + ) + + wiring = RequestResponseWiring( + self._event_bus, + environment=os.environ["ONEX_ENVIRONMENT"], + app_name="morning-friction-sweep", + ) + await wiring.wire_request_response( + ModelRequestResponseConfig.model_validate(self._request_response()) + ) + self._rpc = wiring + return self._rpc + + async def run( + self, + run: ModelMorningFrictionSweepRequest, + phase: ModelFrictionPhaseRequest, + ) -> dict[str, JsonValue] | None: + instance = self._declared_instance() + timeout = int(cast(int, instance["timeout_seconds"])) + correlation = uuid5(run.correlation_id, phase.label) + command = ModelDelegationRequest( + correlation_id=correlation, + tenant_id=run.tenant_id, + emitted_at=run.emitted_at, + prompt=phase.prompt, + task_type="agent_delegation", + max_tokens=8192, + requested_timeout_seconds=timeout, + context_pack=json.dumps( + {"phase": phase.phase, "model": phase.model, "effort": phase.effort} + ), + response_format={"type": "json_object"}, + response_contract=cast(dict[str, object], phase.schema_definition), + ) + envelope = ModelEventEnvelope[ModelDelegationRequest]( + payload=command, + correlation_id=correlation, + tenant_id=run.tenant_id, + event_type=str(instance["request_topic"]), + envelope_timestamp=run.emitted_at, + ) + wiring = await self._wiring() + response = await wiring.send_request( + INSTANCE, envelope.model_dump(mode="json"), timeout_seconds=timeout + ) + payload = response.get("payload", response) + if not isinstance(payload, dict): + raise ValueError("friction phase terminal payload must be an object") + if str(payload.get("correlation_id")) != str(correlation): + raise ValueError("friction phase terminal correlation does not match") + if payload.get("tenant_id", run.tenant_id) != run.tenant_id: + raise ValueError("friction phase terminal tenant does not match") + content = payload.get("content") + if not isinstance(content, str): + raise ValueError("friction phase terminal contains no content") + decoded = json.loads(content) + if decoded is None: + return None + if not isinstance(decoded, dict): + raise ValueError("friction phase result must be an object") + RESULT_TYPES[phase.label].model_validate(decoded) + return cast(dict[str, JsonValue], decoded) diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/handlers/handler_morning_friction_sweep.py b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/handlers/handler_morning_friction_sweep.py new file mode 100644 index 0000000000..24aa2efb93 --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/handlers/handler_morning_friction_sweep.py @@ -0,0 +1,462 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Definition-B friction sweep: typed command in, typed terminal out. + +Guards the run (same-date idempotency precheck, delegation evidence, premise +audit), fans out the five concurrent sources, then synthesizes, adjudicates +and reports. Phase work crosses the injected bus gateway; the deployment's +briefs, paths, lanes and bounds arrive through a strict overlay, and the phase +schemas are packaged with the node. +""" + +from __future__ import annotations + +import asyncio +import copy +import json +import os +import re +from datetime import UTC, datetime +from importlib.resources import files +from pathlib import Path +from typing import cast + +import yaml +from omnibase_core.protocols.event_bus.protocol_event_bus_publisher import ( + ProtocolEventBusPublisher, +) +from pydantic import JsonValue, ValidationError + +from ..models.model_friction_overlay import ModelFrictionOverlay +from ..models.model_friction_phase_results import ( + ModelFrictionAdjudication, + ModelFrictionPrecheck, + ModelFrictionPrecheckUnavailable, + ModelFrictionReport, + ModelFrictionScan, + ModelFrictionSource, + ModelFrictionSynthesis, +) +from ..models.model_morning_friction_sweep import ( + ModelFrictionPhaseRequest, + ModelMorningFrictionSweepRequest, + ModelMorningFrictionSweepResult, +) +from ..protocols.protocol_friction_phase_gateway import ProtocolFrictionPhaseGateway + +PACKAGE = "omnimarket.nodes.node_morning_friction_sweep_orchestrator" +NODE_NAME = "node_morning_friction_sweep_orchestrator" +OVERLAY_ENV = "OMNIMARKET_MORNING_FRICTION_SWEEP_OVERLAY" +ROOTS_ENV = "ONEX_SKILL_OVERLAY_ROOTS" +DELEGATION_REASON_RE = re.compile(r"^(route-refused:\S+|route-unavailable:\S+)$") +SOURCE_LABELS = ( + "friction-source-linear", + "friction-source-checkpoints", + "friction-source-ci", + "friction-source-guards", +) +DELEGATED_LABELS = ("friction-synthesize", "friction-adjudicate", "friction-report") +SCHEMA_NAMES = { + "friction-precheck": "PRECHECK", + "friction-scan": "SCAN", + "friction-synthesize": "SYNTHESIZE", + "friction-adjudicate": "ADJUDICATE", + "friction-report": "REPORT", +} +ISO_SECONDS = re.compile(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z") + + +class MorningFrictionSweepConfigurationError(ValueError): + """Missing or invalid deployment overlay.""" + + +def load_friction_overlay() -> ModelFrictionOverlay: + """Read the explicit pointer, otherwise the first existing overlay in root order. + + The node cannot run without its overlay: an absent one is a hard stop, never + a run against empty briefs. An explicit pointer never falls through. + """ + if OVERLAY_ENV in os.environ: + pointer = os.environ[OVERLAY_ENV] + if not pointer: + raise MorningFrictionSweepConfigurationError( + f"{OVERLAY_ENV}: empty overlay pointer" + ) + path: Path | None = Path(pointer) + source = OVERLAY_ENV + else: + path = None + source = ROOTS_ENV + for root in os.environ.get(ROOTS_ENV, "").split(os.pathsep): + if not root: + continue + candidate = Path(root) / NODE_NAME / "overlay.yaml" + if candidate.exists(): + path = candidate + break + if path is None: + raise MorningFrictionSweepConfigurationError( + f"no friction sweep overlay: set {OVERLAY_ENV} to an overlay.yaml, or " + f"put {NODE_NAME}/overlay.yaml under a root in {ROOTS_ENV}" + ) + try: + raw = yaml.safe_load(path.read_text(encoding="utf-8")) + if not isinstance(raw, dict): + raise ValueError("overlay must be a mapping") + briefs = path.parent / str(raw.get("briefs", "")) + if not raw.get("briefs") or not briefs.is_file(): + raise ValueError("overlay briefs file is not readable") + return ModelFrictionOverlay.from_documents( + {k: v for k, v in raw.items() if k != "briefs"}, + briefs.read_text(encoding="utf-8"), + ) + except (OSError, UnicodeError, yaml.YAMLError, ValueError, TypeError) as exc: + raise MorningFrictionSweepConfigurationError( + f"{source}: invalid friction sweep overlay: {exc}" + ) from None + + +def _integer(value: JsonValue) -> bool: + return type(value) is int and value >= 0 + + +def delegation_problem(cell: JsonValue) -> str | None: + """Delegation receipt rule: zero delegation needs a typed route reason.""" + if not isinstance(cell, dict): + return "missing or invalid cell" + count = cell.get("delegated") + if not _integer(count): + return "invalid delegated count" + runs = cell.get("runs") + if not isinstance(runs, list) or not all( + isinstance(r, str) and r and not re.search(r"\s", r) for r in runs + ): + return "invalid run ids" + reason = cell.get("reason") + if not isinstance(reason, str): + return "missing or invalid reason" + if cast(int, count) > 0: + if not runs: + return "delegated steps have no runs" + if reason: + return "delegated steps require an empty reason" + else: + if runs: + return "zero delegated count requires empty runs" + if not DELEGATION_REASON_RE.fullmatch(reason): + return "zero delegation reason refused" + return None + + +def premise_audit_problem(cell: JsonValue, control_lanes: list[str]) -> str | None: + """Measurement guard: complete coverage and every cited positive control.""" + if not isinstance(cell, dict): + return "missing or invalid audit" + landed = cell.get("rule_landed_at") + evidence = cell.get("rule_evidence") + reason = cell.get("reason") + if not all(isinstance(v, str) for v in (landed, evidence, reason)): + return "invalid audit evidence" + eligible = cell.get("eligible_terminal_rows") + controls = cell.get("positive_controls") + unreadable = cell.get("unreadable_sources") + if ( + not _integer(eligible) + or not isinstance(controls, list) + or not isinstance(unreadable, list) + or not all(isinstance(s, str) and s.strip() for s in unreadable) + ): + return "invalid audit coverage" + for control in controls: + if ( + not isinstance(control, dict) + or control.get("lane") not in control_lanes + or not _integer(control.get("terminal_rows")) + or not isinstance(control.get("evidence"), str) + ): + return "invalid positive controls" + falsified = cell.get("falsified_terminal_rows") + if cell.get("status") == "UNKNOWN": + if falsified is None and isinstance(reason, str) and reason.strip(): + return None + return "UNKNOWN must explain missing evidence and cannot report a count" + if cell.get("status") != "MEASURED": + return "invalid audit status" + try: + if ( + not isinstance(landed, str) + or not ISO_SECONDS.fullmatch(landed) + or datetime.fromisoformat(landed) + .astimezone(UTC) + .strftime("%Y-%m-%dT%H:%M:%SZ") + != landed + or not isinstance(evidence, str) + or not evidence.strip() + ): + return "rule landing lacks timestamp or citation" + except ValueError: + return "rule landing lacks timestamp or citation" + if eligible == 0 or unreadable or reason != "": + return "measurement lacks complete nonempty coverage" + if ( + not _integer(falsified) + or not isinstance(falsified, int) + or not isinstance(eligible, int) + or falsified > eligible + ): + return "invalid falsified count" + if len(controls) != len(control_lanes) or any( + sum( + 1 + for c in controls + if isinstance(c, dict) + and c.get("lane") == lane + and isinstance(c.get("terminal_rows"), int) + and cast(int, c["terminal_rows"]) > 0 + and isinstance(c.get("evidence"), str) + and cast(str, c["evidence"]).strip() + ) + != 1 + for lane in control_lanes + ): + return "all cited positive controls are required" + return None + + +class HandlerMorningFrictionSweep: + """Coordinate the existing delegation pipeline, preserving the sweep's gates.""" + + def __init__( + self, + event_bus: ProtocolEventBusPublisher | None, + gateway: ProtocolFrictionPhaseGateway | None = None, + overlay: ModelFrictionOverlay | None = None, + ) -> None: + from .handler_friction_phase_bus import HandlerFrictionPhaseBus + + self.overlay = overlay or load_friction_overlay() + self.gateway = gateway or HandlerFrictionPhaseBus(event_bus) + self.schemas = cast( + dict[str, dict[str, JsonValue]], + json.loads( + files(PACKAGE).joinpath("models/phase_schemas.json").read_text() + ), + ) + + async def handle( + self, request: ModelMorningFrictionSweepRequest + ) -> ModelMorningFrictionSweepResult: + slots = self._slots(request) + violations: list[str] = [] + + async def call(label: str) -> dict[str, JsonValue] | None: + result = await self.gateway.run( + request, + ModelFrictionPhaseRequest( + label=label, + phase=self._phase(label), + model="opus" if label in DELEGATED_LABELS else "sonnet", + effort="medium" if label == "friction-precheck" else "high", + prompt=self._render(self.overlay.templates[label], slots), + schema_definition=self._schema(label), + ), + ) + if label in DELEGATED_LABELS: + if not isinstance(result, dict): + raise ValueError( + f"delegation cell refused: {label}: " + "missing or invalid cell (absent phase result)" + ) + problem = delegation_problem(result.get("delegation")) + if problem: + violations.append(f"{label}: {problem}") + return result + + # A dead or unavailable precheck never suppresses the sweep. + raw: dict[str, JsonValue] | None = None + precheck_failure: dict[str, str] = {} + if not request.force: + try: + raw = await call("friction-precheck") + except Exception as exc: + precheck_failure = { + "failure_type": type(exc).__name__, + "failure_reason": str(exc), + } + pre: ModelFrictionPrecheck | None = None + if raw and raw.get("verdict"): + try: + pre = ModelFrictionPrecheck.model_validate(raw) + except ValidationError as exc: + precheck_failure = { + "failure_type": type(exc).__name__, + "failure_reason": "precheck result off its schema", + } + precheck_agents = 0 if request.force else 1 + if pre is not None and pre.verdict != "run": + return ModelMorningFrictionSweepResult( + correlation_id=request.correlation_id, + tenant_id=request.tenant_id, + date=request.date, + dry_run=request.dry_run, + force=request.force, + short_circuited=pre.verdict, + precheck=pre, + precheck_agents=precheck_agents, + expensive_agents_spawned=0, + report=self.overlay.values["kb_prefix"] + slots["report_path"], + state=self.overlay.values["kb_prefix"] + slots["state_path"], + ) + raw_scan, *raw_sources = await asyncio.gather( + call("friction-scan"), *(call(label) for label in SOURCE_LABELS) + ) + scan = ModelFrictionScan.model_validate(raw_scan) + sources = [ModelFrictionSource.model_validate(s) for s in raw_sources] + slots["scan_handoff"] = scan.handoff_path + slots["synthesis_inputs"] = " ".join( + "'" + path.replace("'", "'\\''") + "'" + for path in [scan.handoff_path, *(s.handoff_path for s in sources)] + ) + slots["source_summary"] = "\n".join( + f" {s.source_id} (verdict {s.verdict}, freshness {s.freshness}): " + f"{s.handoff_path}" + for s in sources + ) + synthesized_raw = await call("friction-synthesize") + if synthesized_raw is None or not isinstance( + synthesized_raw.get("handoff_path"), str + ): + raise ValueError("synthesis handoff is missing") + slots["synthesis_handoff"] = cast(str, synthesized_raw["handoff_path"]) + unknown = synthesized_raw.get("sources_unknown") + if not isinstance(unknown, list) or not all( + isinstance(v, str) for v in unknown + ): + raise ValueError("synthesis sources_unknown is invalid") + slots["sources_unknown"] = "; ".join(cast(list[str], unknown)) or "none" + adjudicated_raw = await call("friction-adjudicate") + if adjudicated_raw is None or not isinstance( + adjudicated_raw.get("handoff_path"), str + ): + raise ValueError("adjudication handoff is missing") + slots["adjudication_handoff"] = cast(str, adjudicated_raw["handoff_path"]) + reported_raw = await call("friction-report") + problem = premise_audit_problem( + reported_raw.get("premise_audit") if reported_raw else None, + self.overlay.lists["premise_control_lanes"], + ) + if problem: + raise ValueError(f"premise audit refused: {problem}") + if violations: + raise ValueError("delegation cell refused: " + "; ".join(violations)) + synthesis = ModelFrictionSynthesis.model_validate(synthesized_raw) + adjudication = ModelFrictionAdjudication.model_validate(adjudicated_raw) + reported = ModelFrictionReport.model_validate(reported_raw) + return ModelMorningFrictionSweepResult( + correlation_id=request.correlation_id, + tenant_id=request.tenant_id, + date=request.date, + dry_run=request.dry_run, + force=request.force, + short_circuited=None, + precheck=pre + or ModelFrictionPrecheckUnavailable( + bypassed="args.force=true" + if request.force + else "unavailable — fell through to a full run", + **precheck_failure, + ), + precheck_agents=precheck_agents, + report=reported.report_path, + state=reported.state_path, + commit=reported.commit_sha, + premise_audit=reported.premise_audit, + window=slots["window"], + scan=scan, + sources=sources, + sources_unknown=synthesis.sources_unknown, + synthesis=synthesis, + root_causes=synthesis.root_causes, + pickups=synthesis.pickups, + adjudication=adjudication, + agents=precheck_agents + 8, + ) + + @staticmethod + def _phase(label: str) -> str: + if label == "friction-precheck": + return "Precheck" + if label == "friction-scan" or label.startswith("friction-source-"): + return "Scan" + return label.removeprefix("friction-").capitalize() + + def _schema(self, label: str) -> dict[str, JsonValue]: + name = "SOURCE" if label.startswith("friction-source-") else SCHEMA_NAMES[label] + schema = copy.deepcopy(self.schemas[name]) + if name == "REPORT": + lane = cast( + dict[str, JsonValue], + cast( + dict[str, JsonValue], + cast( + dict[str, JsonValue], + cast( + dict[str, JsonValue], + cast(dict[str, JsonValue], schema["properties"])[ + "premise_audit" + ], + )["properties"], + )["positive_controls"], + )["items"], + ) + cast( + dict[str, JsonValue], + cast(dict[str, JsonValue], lane["properties"])["lane"], + )["enum"] = cast( + list[JsonValue], list(self.overlay.lists["premise_control_lanes"]) + ) + return schema + + @staticmethod + def _render(text: str, values: dict[str, str]) -> str: + def replace(match: re.Match[str]) -> str: + key = match[1] + if key not in values: + raise ValueError(f"unknown friction prompt field: {key}") + return values[key] + + # Replace in one pass: substitutions can contain literal shell syntax. + return re.sub(r"@@(\w+)@@", replace, text) + + def _slots(self, request: ModelMorningFrictionSweepRequest) -> dict[str, str]: + day = request.date + prior = request.window_start + overlay = self.overlay + slots = { + **{k: self._render(v, {"date": day}) for k, v in overlay.values.items()}, + "run_date": day, + "window": ( + f"[{prior}T00:00:00Z, {day}T00:00:00Z) — the previous UTC day, {prior}" + ), + "lookback_hours": f"{request.lookback_hours:g}", + "dry_run": str(request.dry_run).lower(), + "phase_stems": ", ".join(f"'{s}'" for s in overlay.lists["phase_stems"]), + "ci_repos": ", ".join(overlay.lists["ci_repos"]), + "adjudication_mode": overlay.texts[ + "adjudication_dry" if request.dry_run else "adjudication_live" + ], + "report_mode": overlay.texts[ + "report_dry" if request.dry_run else "report_live" + ], + "fences": ( + "FENCES (standing, from args.fences — do not touch these):\n- " + + "\n- ".join(request.fences) + + "\n" + if request.fences + else "FENCES: none passed for this run. Before filing or commenting on " + "any ticket, still check for an active lane already owning that " + "friction (open PR, in-flight ledger CLAIM without TERMINAL) and " + "leave it alone if one exists — record it as known-in-flight instead.\n" + ), + } + return slots diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/metadata.yaml b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/metadata.yaml new file mode 100644 index 0000000000..d9a99e97cc --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/metadata.yaml @@ -0,0 +1,32 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +name: node_morning_friction_sweep_orchestrator +version: 0.1.0 +description: "Operator morning friction sweep orchestrator - same-date idempotency precheck, five concurrent friction sources, synthesis, adjudication, report and watermark - with the deployment briefs supplied by an overlay." +omnibase_core_compat: '>=0.47.31,<0.48.0' +entry_points: + onex.nodes: + node_morning_friction_sweep_orchestrator: omnimarket.nodes.node_morning_friction_sweep_orchestrator +capabilities: + standalone: false + full_runtime: true + requires_network: true + requires_repo: false + requires_secrets: false + requires_docker: false + side_effect_class: read_write +dependencies: +- PyYAML>=6.0.3 +- omnibase_infra +license: MIT +authors: +- OmniNode Team +tags: +- orchestrator +- operator +- morning +- friction +- overlay +pack: operator_tooling +display_name: Morning Friction Sweep Orchestrator +node_role: orchestrator diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/__init__.py b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/__init__.py new file mode 100644 index 0000000000..3c0abbabd4 --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/__init__.py @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Morning friction sweep command, phase and terminal models.""" + +from .model_friction_overlay import ModelFrictionOverlay +from .model_friction_phase_results import ( + ModelFrictionAdjudication, + ModelFrictionDelegation, + ModelFrictionPrecheck, + ModelFrictionPrecheckUnavailable, + ModelFrictionPremiseAudit, + ModelFrictionReport, + ModelFrictionScan, + ModelFrictionSource, + ModelFrictionSynthesis, +) +from .model_morning_friction_sweep import ( + ModelFrictionPhaseRequest, + ModelMorningFrictionSweepRequest, + ModelMorningFrictionSweepResult, +) + +__all__ = [ + "ModelFrictionAdjudication", + "ModelFrictionDelegation", + "ModelFrictionOverlay", + "ModelFrictionPhaseRequest", + "ModelFrictionPrecheck", + "ModelFrictionPrecheckUnavailable", + "ModelFrictionPremiseAudit", + "ModelFrictionReport", + "ModelFrictionScan", + "ModelFrictionSource", + "ModelFrictionSynthesis", + "ModelMorningFrictionSweepRequest", + "ModelMorningFrictionSweepResult", +] diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/model_friction_overlay.py b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/model_friction_overlay.py new file mode 100644 index 0000000000..d1013b90ca --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/model_friction_overlay.py @@ -0,0 +1,113 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""The deployment half of the morning friction sweep: briefs, paths and bounds. + +The node holds the method (phase order, idempotency verdicts, delegation +evidence and premise-audit rules, bus wiring). Everything that names a +deployment's workspace, repositories, report locations, lanes, tickets or +tooling arrives in this overlay. +""" + +from __future__ import annotations + +import re + +from pydantic import BaseModel, ConfigDict + +REQUIRED_TEMPLATES = ( + "friction-precheck", + "friction-scan", + "friction-source-linear", + "friction-source-checkpoints", + "friction-source-ci", + "friction-source-guards", + "friction-synthesize", + "friction-adjudicate", + "friction-report", +) +REQUIRED_VALUES = ( + "state_path", + "report_path", + "ledger_path", + "kb_prefix", + "kb_branch", + "worktree_ticket", + "watermark_tool", + "watermark_schema_version", + "peer_claim_minutes", + "pr_watcher_max_age_minutes", + "linear_comments_max_age_hours", + "occurrence_comment_ceiling", + "checkpoints_max_age_hours", + "ci_lookback_max_age_hours", + "guard_logs_max_age_hours", +) +REQUIRED_TEXTS = ( + "adjudication_dry", + "adjudication_live", + "report_dry", + "report_live", +) +REQUIRED_LISTS = ("phase_stems", "ci_repos", "premise_control_lanes") +TEMPLATE_BLOCK = re.compile(r"\n(.*?)\n", re.S) + + +class ModelFrictionOverlay(BaseModel): + """Validated deployment overlay; built by the loader, never by the node.""" + + model_config = ConfigDict(extra="forbid", frozen=True) + templates: dict[str, str] + values: dict[str, str] + texts: dict[str, str] + lists: dict[str, list[str]] + + @classmethod + def from_documents(cls, overlay: object, briefs: str) -> ModelFrictionOverlay: + """Validate the parsed overlay mapping and the briefs text.""" + if not isinstance(overlay, dict): + raise ValueError("overlay must be a mapping") + unknown = set(overlay) - {"briefs", "values", "texts", *REQUIRED_LISTS} + if unknown: + raise ValueError( + "overlay unknown keys: " + ", ".join(sorted(map(str, unknown))) + ) + templates = dict(TEMPLATE_BLOCK.findall(briefs)) + absent = [name for name in REQUIRED_TEMPLATES if name not in templates] + if absent: + raise ValueError("briefs missing templates: " + ", ".join(absent)) + extra = set(templates) - set(REQUIRED_TEMPLATES) + if extra: + raise ValueError("briefs unknown templates: " + ", ".join(sorted(extra))) + lists: dict[str, list[str]] = {} + for key in REQUIRED_LISTS: + raw = overlay.get(key) + if ( + not isinstance(raw, list) + or not raw + or not all(isinstance(v, str) and v.strip() for v in raw) + ): + raise ValueError(f"overlay {key} must be a nonempty list of strings") + lists[key] = list(raw) + return cls( + templates=templates, + values=_exact_strings(overlay.get("values"), REQUIRED_VALUES, "value"), + texts=_exact_strings(overlay.get("texts"), REQUIRED_TEXTS, "text"), + lists=lists, + ) + + +def _exact_strings(raw: object, required: tuple[str, ...], noun: str) -> dict[str, str]: + if not isinstance(raw, dict): + raise ValueError(f"overlay {noun}s must be a mapping") + missing = [key for key in required if key not in raw] + if missing: + raise ValueError(f"overlay missing {noun}s: " + ", ".join(missing)) + extra = set(raw) - set(required) + if extra: + raise ValueError( + f"overlay unknown {noun}s: " + ", ".join(sorted(map(str, extra))) + ) + for key, item in raw.items(): + if not isinstance(item, str): + raise ValueError(f"overlay {noun} {key} must be a string") + return {str(k): str(v) for k, v in raw.items()} diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/model_friction_phase_results.py b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/model_friction_phase_results.py new file mode 100644 index 0000000000..d5efff4344 --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/model_friction_phase_results.py @@ -0,0 +1,102 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Typed results of the friction sweep phases; no untyped agent payload crosses the handler.""" + +from typing import Literal + +from pydantic import BaseModel, ConfigDict + + +class _Phase(BaseModel): + model_config = ConfigDict(extra="forbid", frozen=True) + + +class ModelFrictionDelegation(_Phase): + delegated: int + runs: list[str] + reason: str + + +class ModelFrictionPrecheck(_Phase): + date: str + clock_utc: str + verdict: Literal["already-delivered", "peer-owned", "run"] + evidence: str + reason: str + state_last_run_date: str | None = None + checks_failed: list[str] | None = None + + +class ModelFrictionPrecheckUnavailable(_Phase): + """Force or an unavailable precheck: the original bypass explanation.""" + + bypassed: str + failure_type: str | None = None + failure_reason: str | None = None + + +class ModelFrictionScan(_Phase): + handoff_path: str + sources_read: list[str] + candidate_count: float + unreadable_sources: list[str] + ledger_rows: list[str] + + +class ModelFrictionSource(_Phase): + handoff_path: str + source_id: str + verdict: str + freshness: str + candidate_count: float + unreadable: list[str] + positive_controls: list[str] | None = None + ledger_rows: list[str] + + +class ModelFrictionSynthesis(_Phase): + handoff_path: str + candidate_count: float + root_causes: list[str] + sources_unknown: list[str] + pickups: list[str] + ledger_rows: list[str] + delegation: ModelFrictionDelegation + + +class ModelFrictionAdjudication(_Phase): + handoff_path: str + filed: list[str] + commented: list[str] + known: list[str] + first_occurrence: list[str] + escalated: list[str] + ledger_rows: list[str] + delegation: ModelFrictionDelegation + + +class ModelFrictionPositiveControl(_Phase): + lane: str + terminal_rows: int + evidence: str + + +class ModelFrictionPremiseAudit(_Phase): + status: Literal["MEASURED", "UNKNOWN"] + rule_landed_at: str + rule_evidence: str + eligible_terminal_rows: int + falsified_terminal_rows: int | None + positive_controls: list[ModelFrictionPositiveControl] + unreadable_sources: list[str] + reason: str + + +class ModelFrictionReport(_Phase): + report_path: str + state_path: str + commit_sha: str + watermark_summary: str + ledger_rows: list[str] + premise_audit: ModelFrictionPremiseAudit + delegation: ModelFrictionDelegation diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/model_morning_friction_sweep.py b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/model_morning_friction_sweep.py new file mode 100644 index 0000000000..31ea7c872d --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/model_morning_friction_sweep.py @@ -0,0 +1,88 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Command, phase request and terminal event of the morning friction sweep.""" + +from datetime import date as calendar_date +from datetime import datetime, timedelta +from uuid import UUID + +from pydantic import BaseModel, ConfigDict, Field, JsonValue, field_validator + +from .model_friction_phase_results import ( + ModelFrictionAdjudication, + ModelFrictionPrecheck, + ModelFrictionPrecheckUnavailable, + ModelFrictionPremiseAudit, + ModelFrictionScan, + ModelFrictionSource, + ModelFrictionSynthesis, +) + +SOURCE_LABELS = ( + "friction-source-linear", + "friction-source-checkpoints", + "friction-source-ci", + "friction-source-guards", +) + + +class ModelMorningFrictionSweepRequest(BaseModel): + """A scheduled or deliberately forced friction sweep.""" + + model_config = ConfigDict(extra="forbid", frozen=True, populate_by_name=True) + correlation_id: UUID + emitted_at: datetime + tenant_id: str + date: str + dry_run: bool = Field(default=False, alias="dryRun") + force: bool = False + lookback_hours: float = Field(default=24, alias="lookbackHours", gt=0) + fences: list[str] = Field(default_factory=list) + + @field_validator("date") + @classmethod + def valid_day(cls, value: str) -> str: + if calendar_date.fromisoformat(value).isoformat() != value: + raise ValueError("date must be a real YYYY-MM-DD date") + return value + + @property + def window_start(self) -> str: + return (calendar_date.fromisoformat(self.date) - timedelta(days=1)).isoformat() + + +class ModelFrictionPhaseRequest(BaseModel): + label: str + phase: str + model: str + effort: str + prompt: str + schema_definition: dict[str, JsonValue] + + +class ModelMorningFrictionSweepResult(BaseModel): + """Delivered report, or the zero-expensive-agent short circuit.""" + + model_config = ConfigDict(extra="forbid", frozen=True) + correlation_id: UUID + tenant_id: str + date: str + dry_run: bool + force: bool + short_circuited: str | None + precheck: ModelFrictionPrecheck | ModelFrictionPrecheckUnavailable + precheck_agents: int + report: str + state: str + expensive_agents_spawned: int | None = None + premise_audit: ModelFrictionPremiseAudit | None = None + commit: str | None = None + window: str | None = None + scan: ModelFrictionScan | None = None + sources: list[ModelFrictionSource] | None = None + sources_unknown: list[str] | None = None + synthesis: ModelFrictionSynthesis | None = None + root_causes: list[str] | None = None + pickups: list[str] | None = None + adjudication: ModelFrictionAdjudication | None = None + agents: int | None = None diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/phase_schemas.json b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/phase_schemas.json new file mode 100644 index 0000000000..4ba119a0f6 --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/models/phase_schemas.json @@ -0,0 +1,396 @@ +{ + "PRECHECK": { + "type": "object", + "required": [ + "date", + "clock_utc", + "verdict", + "evidence", + "reason" + ], + "properties": { + "date": { + "type": "string" + }, + "clock_utc": { + "type": "string" + }, + "verdict": { + "type": "string", + "enum": [ + "already-delivered", + "peer-owned", + "run" + ] + }, + "evidence": { + "type": "string" + }, + "reason": { + "type": "string" + }, + "state_last_run_date": { + "type": "string" + }, + "checks_failed": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "SCAN": { + "type": "object", + "required": [ + "handoff_path", + "sources_read", + "candidate_count", + "unreadable_sources", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "sources_read": { + "type": "array", + "items": { + "type": "string" + } + }, + "candidate_count": { + "type": "number" + }, + "unreadable_sources": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "SOURCE": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "SYNTHESIZE": { + "type": "object", + "required": [ + "handoff_path", + "candidate_count", + "root_causes", + "sources_unknown", + "pickups", + "ledger_rows", + "delegation" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "root_causes": { + "type": "array", + "items": { + "type": "string" + } + }, + "sources_unknown": { + "type": "array", + "items": { + "type": "string" + } + }, + "pickups": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + }, + "ADJUDICATE": { + "type": "object", + "required": [ + "handoff_path", + "filed", + "commented", + "known", + "first_occurrence", + "escalated", + "ledger_rows", + "delegation" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "filed": { + "type": "array", + "items": { + "type": "string" + } + }, + "commented": { + "type": "array", + "items": { + "type": "string" + } + }, + "known": { + "type": "array", + "items": { + "type": "string" + } + }, + "first_occurrence": { + "type": "array", + "items": { + "type": "string" + } + }, + "escalated": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + }, + "REPORT": { + "type": "object", + "required": [ + "report_path", + "state_path", + "commit_sha", + "watermark_summary", + "ledger_rows", + "premise_audit", + "delegation" + ], + "properties": { + "report_path": { + "type": "string" + }, + "state_path": { + "type": "string" + }, + "commit_sha": { + "type": "string" + }, + "watermark_summary": { + "type": "string" + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "premise_audit": { + "type": "object", + "required": [ + "status", + "rule_landed_at", + "rule_evidence", + "eligible_terminal_rows", + "falsified_terminal_rows", + "positive_controls", + "unreadable_sources", + "reason" + ], + "properties": { + "status": { + "type": "string", + "enum": [ + "MEASURED", + "UNKNOWN" + ] + }, + "rule_landed_at": { + "type": "string" + }, + "rule_evidence": { + "type": "string" + }, + "eligible_terminal_rows": { + "type": "integer", + "minimum": 0 + }, + "falsified_terminal_rows": { + "type": [ + "integer", + "null" + ], + "minimum": 0 + }, + "positive_controls": { + "type": "array", + "items": { + "type": "object", + "required": [ + "lane", + "terminal_rows", + "evidence" + ], + "properties": { + "lane": { + "type": "string" + }, + "terminal_rows": { + "type": "integer", + "minimum": 0 + }, + "evidence": { + "type": "string" + } + } + } + }, + "unreadable_sources": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } +} diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/node.py b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/node.py new file mode 100644 index 0000000000..59092495d8 --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/node.py @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Declarative orchestrator: all behavior is in the contract and its handler.""" + +from omnibase_core.nodes.node_orchestrator import NodeOrchestrator + + +class NodeMorningFrictionSweepOrchestrator(NodeOrchestrator): + """Guarded morning friction sweep: precheck, sources, synthesis, report.""" diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/protocols/__init__.py b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/protocols/__init__.py new file mode 100644 index 0000000000..8bcad3e1f5 --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/protocols/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Bus RPC boundary protocols of the morning friction sweep node.""" diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/protocols/protocol_friction_phase_gateway.py b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/protocols/protocol_friction_phase_gateway.py new file mode 100644 index 0000000000..ca24bf6699 --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/protocols/protocol_friction_phase_gateway.py @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Bus RPC boundary; the orchestrator never starts a model process.""" + +from typing import Protocol + +from pydantic import JsonValue + +from ..models.model_morning_friction_sweep import ( + ModelFrictionPhaseRequest, + ModelMorningFrictionSweepRequest, +) + + +class ProtocolFrictionPhaseGateway(Protocol): + async def run( + self, run: ModelMorningFrictionSweepRequest, phase: ModelFrictionPhaseRequest + ) -> dict[str, JsonValue] | None: ... diff --git a/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/protocols/protocol_friction_rpc.py b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/protocols/protocol_friction_rpc.py new file mode 100644 index 0000000000..5f75ac0592 --- /dev/null +++ b/src/omnimarket/nodes/node_morning_friction_sweep_orchestrator/protocols/protocol_friction_rpc.py @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Interface of the existing infra RequestResponseWiring; broker ownership stays there.""" + +from typing import Protocol + + +class ProtocolFrictionRpc(Protocol): + async def send_request( + self, + instance_name: str, + payload: dict[str, object], + timeout_seconds: int | None = None, + ) -> dict[str, object]: ... diff --git a/tests/nodes/node_morning_friction_sweep_orchestrator/__init__.py b/tests/nodes/node_morning_friction_sweep_orchestrator/__init__.py new file mode 100644 index 0000000000..64f06c497f --- /dev/null +++ b/tests/nodes/node_morning_friction_sweep_orchestrator/__init__.py @@ -0,0 +1,2 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT diff --git a/tests/nodes/node_morning_friction_sweep_orchestrator/fixtures/decision_parity.json b/tests/nodes/node_morning_friction_sweep_orchestrator/fixtures/decision_parity.json new file mode 100644 index 0000000000..12d3a1c399 --- /dev/null +++ b/tests/nodes/node_morning_friction_sweep_orchestrator/fixtures/decision_parity.json @@ -0,0 +1,3624 @@ +{ + "legacy_source_sha256": "fc513b4c6249529f38f8b3d33625d6afe0a2e27b26c7772c2ba9aaecc816ff3b", + "cases": [ + { + "name": "full", + "args": { + "date": "2026-08-29" + }, + "responses": { + "friction-precheck": { + "date": "2026-08-29", + "clock_utc": "2026-08-29T15:47:00Z", + "verdict": "run", + "evidence": "", + "reason": "dry-read stub" + }, + "friction-scan": { + "handoff_path": "/tmp/dry-read-friction-scan.json", + "sources_read": [ + "a" + ], + "candidate_count": 1, + "unreadable_sources": [], + "ledger_rows": [] + }, + "friction-source-linear": { + "handoff_path": "/tmp/dry-read-friction-source-linear.json", + "source_id": "linear", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "linear: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-source-checkpoints": { + "handoff_path": "/tmp/dry-read-friction-source-checkpoints.json", + "source_id": "checkpoints", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "checkpoints: stub over-bound artifact" + ], + "positive_controls": [ + "checkpoints: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-source-ci": { + "handoff_path": "/tmp/dry-read-friction-source-ci.json", + "source_id": "ci", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "ci: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-source-guards": { + "handoff_path": "/tmp/dry-read-friction-source-guards.json", + "source_id": "guards", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "guards: stub over-bound artifact" + ], + "positive_controls": [ + "guards: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-synthesize": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-synthesize.json", + "candidate_count": 2, + "root_causes": [ + "stub cause — 2 occurrences across 2 fingerprints" + ], + "sources_unknown": [ + "checkpoints: stub over-bound", + "guards: stub no-timestamp" + ], + "pickups": [ + "1. stub cause — lanes_blocked=2 recurrence=2 — unticketed" + ], + "ledger_rows": [] + }, + "friction-adjudicate": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-adjudicate.json", + "filed": [], + "commented": [], + "known": [], + "first_occurrence": [], + "escalated": [], + "ledger_rows": [] + }, + "friction-report": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "report_path": "/tmp/dry-read-friction-report.md", + "state_path": "/tmp/dry-read-friction-state.json", + "commit_sha": "deadbeefcafe", + "watermark_summary": "stub", + "ledger_rows": [], + "premise_audit": { + "status": "UNKNOWN", + "rule_landed_at": "", + "rule_evidence": "", + "eligible_terminal_rows": 0, + "falsified_terminal_rows": null, + "positive_controls": [], + "unreadable_sources": [ + "dry-read stub" + ], + "reason": "dry read has no ledger" + } + } + }, + "value": { + "date": "2026-08-29", + "dryRun": false, + "force": false, + "short_circuited": null, + "precheck": { + "date": "2026-08-29", + "clock_utc": "2026-08-29T15:47:00Z", + "verdict": "run", + "evidence": "", + "reason": "dry-read stub" + }, + "precheck_agents": 1, + "report": "/tmp/dry-read-friction-report.md", + "premise_audit": { + "status": "UNKNOWN", + "rule_landed_at": "", + "rule_evidence": "", + "eligible_terminal_rows": 0, + "falsified_terminal_rows": null, + "positive_controls": [], + "unreadable_sources": [ + "dry-read stub" + ], + "reason": "dry read has no ledger" + }, + "state": "/tmp/dry-read-friction-state.json", + "commit": "deadbeefcafe", + "window": "[2026-08-28T00:00:00Z, 2026-08-29T00:00:00Z) — the previous UTC day, 2026-08-28", + "scan": { + "handoff_path": "/tmp/dry-read-friction-scan.json", + "sources_read": [ + "a" + ], + "candidate_count": 1, + "unreadable_sources": [], + "ledger_rows": [] + }, + "sources": [ + { + "handoff_path": "/tmp/dry-read-friction-source-linear.json", + "source_id": "linear", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "linear: stub control, 3 rows" + ], + "ledger_rows": [] + }, + { + "handoff_path": "/tmp/dry-read-friction-source-checkpoints.json", + "source_id": "checkpoints", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "checkpoints: stub over-bound artifact" + ], + "positive_controls": [ + "checkpoints: stub control, 3 rows" + ], + "ledger_rows": [] + }, + { + "handoff_path": "/tmp/dry-read-friction-source-ci.json", + "source_id": "ci", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "ci: stub control, 3 rows" + ], + "ledger_rows": [] + }, + { + "handoff_path": "/tmp/dry-read-friction-source-guards.json", + "source_id": "guards", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "guards: stub over-bound artifact" + ], + "positive_controls": [ + "guards: stub control, 3 rows" + ], + "ledger_rows": [] + } + ], + "sources_unknown": [ + "checkpoints: stub over-bound", + "guards: stub no-timestamp" + ], + "synthesis": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-synthesize.json", + "candidate_count": 2, + "root_causes": [ + "stub cause — 2 occurrences across 2 fingerprints" + ], + "sources_unknown": [ + "checkpoints: stub over-bound", + "guards: stub no-timestamp" + ], + "pickups": [ + "1. stub cause — lanes_blocked=2 recurrence=2 — unticketed" + ], + "ledger_rows": [] + }, + "root_causes": [ + "stub cause — 2 occurrences across 2 fingerprints" + ], + "pickups": [ + "1. stub cause — lanes_blocked=2 recurrence=2 — unticketed" + ], + "adjudication": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-adjudicate.json", + "filed": [], + "commented": [], + "known": [], + "first_occurrence": [], + "escalated": [], + "ledger_rows": [] + }, + "agents": 9 + }, + "calls": [ + { + "label": "friction-precheck", + "phase": "Precheck", + "model": "sonnet", + "effort": "medium", + "schema": { + "type": "object", + "required": [ + "date", + "clock_utc", + "verdict", + "evidence", + "reason" + ], + "properties": { + "date": { + "type": "string" + }, + "clock_utc": { + "type": "string" + }, + "verdict": { + "type": "string", + "enum": [ + "already-delivered", + "peer-owned", + "run" + ] + }, + "evidence": { + "type": "string" + }, + "reason": { + "type": "string" + }, + "state_last_run_date": { + "type": "string" + }, + "checks_failed": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-scan", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "sources_read", + "candidate_count", + "unreadable_sources", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "sources_read": { + "type": "array", + "items": { + "type": "string" + } + }, + "candidate_count": { + "type": "number" + }, + "unreadable_sources": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-linear", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-checkpoints", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-ci", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-guards", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-synthesize", + "phase": "Synthesize", + "model": "opus", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "candidate_count", + "root_causes", + "sources_unknown", + "pickups", + "ledger_rows", + "delegation" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "root_causes": { + "type": "array", + "items": { + "type": "string" + } + }, + "sources_unknown": { + "type": "array", + "items": { + "type": "string" + } + }, + "pickups": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } + }, + { + "label": "friction-adjudicate", + "phase": "Adjudicate", + "model": "opus", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "filed", + "commented", + "known", + "first_occurrence", + "escalated", + "ledger_rows", + "delegation" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "filed": { + "type": "array", + "items": { + "type": "string" + } + }, + "commented": { + "type": "array", + "items": { + "type": "string" + } + }, + "known": { + "type": "array", + "items": { + "type": "string" + } + }, + "first_occurrence": { + "type": "array", + "items": { + "type": "string" + } + }, + "escalated": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } + }, + { + "label": "friction-report", + "phase": "Report", + "model": "opus", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "report_path", + "state_path", + "commit_sha", + "watermark_summary", + "ledger_rows", + "premise_audit", + "delegation" + ], + "properties": { + "report_path": { + "type": "string" + }, + "state_path": { + "type": "string" + }, + "commit_sha": { + "type": "string" + }, + "watermark_summary": { + "type": "string" + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "premise_audit": { + "type": "object", + "required": [ + "status", + "rule_landed_at", + "rule_evidence", + "eligible_terminal_rows", + "falsified_terminal_rows", + "positive_controls", + "unreadable_sources", + "reason" + ], + "properties": { + "status": { + "type": "string", + "enum": [ + "MEASURED", + "UNKNOWN" + ] + }, + "rule_landed_at": { + "type": "string" + }, + "rule_evidence": { + "type": "string" + }, + "eligible_terminal_rows": { + "type": "integer", + "minimum": 0 + }, + "falsified_terminal_rows": { + "type": [ + "integer", + "null" + ], + "minimum": 0 + }, + "positive_controls": { + "type": "array", + "items": { + "type": "object", + "required": [ + "lane", + "terminal_rows", + "evidence" + ], + "properties": { + "lane": { + "type": "string", + "enum": [ + "control-lane-a", + "control-lane-b", + "control-lane-c" + ] + }, + "terminal_rows": { + "type": "integer", + "minimum": 0 + }, + "evidence": { + "type": "string" + } + } + } + }, + "unreadable_sources": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } + } + ], + "precheckVerdict": "run" + }, + { + "name": "delivered", + "args": { + "date": "2026-08-29" + }, + "responses": { + "friction-precheck": { + "date": "2026-08-29", + "clock_utc": "2026-08-29T15:47:00Z", + "verdict": "already-delivered", + "evidence": "d425b1c4f0000000000000000000000000000000", + "reason": "dry-read stub" + } + }, + "value": { + "date": "2026-08-29", + "dryRun": false, + "force": false, + "short_circuited": "already-delivered", + "precheck": { + "date": "2026-08-29", + "clock_utc": "2026-08-29T15:47:00Z", + "verdict": "already-delivered", + "evidence": "d425b1c4f0000000000000000000000000000000", + "reason": "dry-read stub" + }, + "expensive_agents_spawned": 0, + "precheck_agents": 1, + "report": "$KB/reports/2026-08-29-friction.md", + "state": "$KB/reports/friction-state.json" + }, + "calls": [ + { + "label": "friction-precheck", + "phase": "Precheck", + "model": "sonnet", + "effort": "medium", + "schema": { + "type": "object", + "required": [ + "date", + "clock_utc", + "verdict", + "evidence", + "reason" + ], + "properties": { + "date": { + "type": "string" + }, + "clock_utc": { + "type": "string" + }, + "verdict": { + "type": "string", + "enum": [ + "already-delivered", + "peer-owned", + "run" + ] + }, + "evidence": { + "type": "string" + }, + "reason": { + "type": "string" + }, + "state_last_run_date": { + "type": "string" + }, + "checks_failed": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + ], + "precheckVerdict": "already-delivered" + }, + { + "name": "owned", + "args": { + "date": "2026-08-29" + }, + "responses": { + "friction-precheck": { + "date": "2026-08-29", + "clock_utc": "2026-08-29T15:47:00Z", + "verdict": "peer-owned", + "evidence": "2026-08-29T15:45:00Z lane friction-scan", + "reason": "dry-read stub" + } + }, + "value": { + "date": "2026-08-29", + "dryRun": false, + "force": false, + "short_circuited": "peer-owned", + "precheck": { + "date": "2026-08-29", + "clock_utc": "2026-08-29T15:47:00Z", + "verdict": "peer-owned", + "evidence": "2026-08-29T15:45:00Z lane friction-scan", + "reason": "dry-read stub" + }, + "expensive_agents_spawned": 0, + "precheck_agents": 1, + "report": "$KB/reports/2026-08-29-friction.md", + "state": "$KB/reports/friction-state.json" + }, + "calls": [ + { + "label": "friction-precheck", + "phase": "Precheck", + "model": "sonnet", + "effort": "medium", + "schema": { + "type": "object", + "required": [ + "date", + "clock_utc", + "verdict", + "evidence", + "reason" + ], + "properties": { + "date": { + "type": "string" + }, + "clock_utc": { + "type": "string" + }, + "verdict": { + "type": "string", + "enum": [ + "already-delivered", + "peer-owned", + "run" + ] + }, + "evidence": { + "type": "string" + }, + "reason": { + "type": "string" + }, + "state_last_run_date": { + "type": "string" + }, + "checks_failed": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + ], + "precheckVerdict": "peer-owned" + }, + { + "name": "unknown", + "args": { + "date": "2026-08-29" + }, + "responses": { + "friction-precheck": null, + "friction-scan": { + "handoff_path": "/tmp/dry-read-friction-scan.json", + "sources_read": [ + "a" + ], + "candidate_count": 1, + "unreadable_sources": [], + "ledger_rows": [] + }, + "friction-source-linear": { + "handoff_path": "/tmp/dry-read-friction-source-linear.json", + "source_id": "linear", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "linear: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-source-checkpoints": { + "handoff_path": "/tmp/dry-read-friction-source-checkpoints.json", + "source_id": "checkpoints", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "checkpoints: stub over-bound artifact" + ], + "positive_controls": [ + "checkpoints: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-source-ci": { + "handoff_path": "/tmp/dry-read-friction-source-ci.json", + "source_id": "ci", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "ci: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-source-guards": { + "handoff_path": "/tmp/dry-read-friction-source-guards.json", + "source_id": "guards", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "guards: stub over-bound artifact" + ], + "positive_controls": [ + "guards: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-synthesize": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-synthesize.json", + "candidate_count": 2, + "root_causes": [ + "stub cause — 2 occurrences across 2 fingerprints" + ], + "sources_unknown": [ + "checkpoints: stub over-bound", + "guards: stub no-timestamp" + ], + "pickups": [ + "1. stub cause — lanes_blocked=2 recurrence=2 — unticketed" + ], + "ledger_rows": [] + }, + "friction-adjudicate": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-adjudicate.json", + "filed": [], + "commented": [], + "known": [], + "first_occurrence": [], + "escalated": [], + "ledger_rows": [] + }, + "friction-report": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "report_path": "/tmp/dry-read-friction-report.md", + "state_path": "/tmp/dry-read-friction-state.json", + "commit_sha": "deadbeefcafe", + "watermark_summary": "stub", + "ledger_rows": [], + "premise_audit": { + "status": "UNKNOWN", + "rule_landed_at": "", + "rule_evidence": "", + "eligible_terminal_rows": 0, + "falsified_terminal_rows": null, + "positive_controls": [], + "unreadable_sources": [ + "dry-read stub" + ], + "reason": "dry read has no ledger" + } + } + }, + "value": { + "date": "2026-08-29", + "dryRun": false, + "force": false, + "short_circuited": null, + "precheck": { + "bypassed": "unavailable — fell through to a full run" + }, + "precheck_agents": 1, + "report": "/tmp/dry-read-friction-report.md", + "premise_audit": { + "status": "UNKNOWN", + "rule_landed_at": "", + "rule_evidence": "", + "eligible_terminal_rows": 0, + "falsified_terminal_rows": null, + "positive_controls": [], + "unreadable_sources": [ + "dry-read stub" + ], + "reason": "dry read has no ledger" + }, + "state": "/tmp/dry-read-friction-state.json", + "commit": "deadbeefcafe", + "window": "[2026-08-28T00:00:00Z, 2026-08-29T00:00:00Z) — the previous UTC day, 2026-08-28", + "scan": { + "handoff_path": "/tmp/dry-read-friction-scan.json", + "sources_read": [ + "a" + ], + "candidate_count": 1, + "unreadable_sources": [], + "ledger_rows": [] + }, + "sources": [ + { + "handoff_path": "/tmp/dry-read-friction-source-linear.json", + "source_id": "linear", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "linear: stub control, 3 rows" + ], + "ledger_rows": [] + }, + { + "handoff_path": "/tmp/dry-read-friction-source-checkpoints.json", + "source_id": "checkpoints", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "checkpoints: stub over-bound artifact" + ], + "positive_controls": [ + "checkpoints: stub control, 3 rows" + ], + "ledger_rows": [] + }, + { + "handoff_path": "/tmp/dry-read-friction-source-ci.json", + "source_id": "ci", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "ci: stub control, 3 rows" + ], + "ledger_rows": [] + }, + { + "handoff_path": "/tmp/dry-read-friction-source-guards.json", + "source_id": "guards", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "guards: stub over-bound artifact" + ], + "positive_controls": [ + "guards: stub control, 3 rows" + ], + "ledger_rows": [] + } + ], + "sources_unknown": [ + "checkpoints: stub over-bound", + "guards: stub no-timestamp" + ], + "synthesis": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-synthesize.json", + "candidate_count": 2, + "root_causes": [ + "stub cause — 2 occurrences across 2 fingerprints" + ], + "sources_unknown": [ + "checkpoints: stub over-bound", + "guards: stub no-timestamp" + ], + "pickups": [ + "1. stub cause — lanes_blocked=2 recurrence=2 — unticketed" + ], + "ledger_rows": [] + }, + "root_causes": [ + "stub cause — 2 occurrences across 2 fingerprints" + ], + "pickups": [ + "1. stub cause — lanes_blocked=2 recurrence=2 — unticketed" + ], + "adjudication": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-adjudicate.json", + "filed": [], + "commented": [], + "known": [], + "first_occurrence": [], + "escalated": [], + "ledger_rows": [] + }, + "agents": 9 + }, + "calls": [ + { + "label": "friction-precheck", + "phase": "Precheck", + "model": "sonnet", + "effort": "medium", + "schema": { + "type": "object", + "required": [ + "date", + "clock_utc", + "verdict", + "evidence", + "reason" + ], + "properties": { + "date": { + "type": "string" + }, + "clock_utc": { + "type": "string" + }, + "verdict": { + "type": "string", + "enum": [ + "already-delivered", + "peer-owned", + "run" + ] + }, + "evidence": { + "type": "string" + }, + "reason": { + "type": "string" + }, + "state_last_run_date": { + "type": "string" + }, + "checks_failed": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-scan", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "sources_read", + "candidate_count", + "unreadable_sources", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "sources_read": { + "type": "array", + "items": { + "type": "string" + } + }, + "candidate_count": { + "type": "number" + }, + "unreadable_sources": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-linear", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-checkpoints", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-ci", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-guards", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-synthesize", + "phase": "Synthesize", + "model": "opus", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "candidate_count", + "root_causes", + "sources_unknown", + "pickups", + "ledger_rows", + "delegation" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "root_causes": { + "type": "array", + "items": { + "type": "string" + } + }, + "sources_unknown": { + "type": "array", + "items": { + "type": "string" + } + }, + "pickups": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } + }, + { + "label": "friction-adjudicate", + "phase": "Adjudicate", + "model": "opus", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "filed", + "commented", + "known", + "first_occurrence", + "escalated", + "ledger_rows", + "delegation" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "filed": { + "type": "array", + "items": { + "type": "string" + } + }, + "commented": { + "type": "array", + "items": { + "type": "string" + } + }, + "known": { + "type": "array", + "items": { + "type": "string" + } + }, + "first_occurrence": { + "type": "array", + "items": { + "type": "string" + } + }, + "escalated": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } + }, + { + "label": "friction-report", + "phase": "Report", + "model": "opus", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "report_path", + "state_path", + "commit_sha", + "watermark_summary", + "ledger_rows", + "premise_audit", + "delegation" + ], + "properties": { + "report_path": { + "type": "string" + }, + "state_path": { + "type": "string" + }, + "commit_sha": { + "type": "string" + }, + "watermark_summary": { + "type": "string" + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "premise_audit": { + "type": "object", + "required": [ + "status", + "rule_landed_at", + "rule_evidence", + "eligible_terminal_rows", + "falsified_terminal_rows", + "positive_controls", + "unreadable_sources", + "reason" + ], + "properties": { + "status": { + "type": "string", + "enum": [ + "MEASURED", + "UNKNOWN" + ] + }, + "rule_landed_at": { + "type": "string" + }, + "rule_evidence": { + "type": "string" + }, + "eligible_terminal_rows": { + "type": "integer", + "minimum": 0 + }, + "falsified_terminal_rows": { + "type": [ + "integer", + "null" + ], + "minimum": 0 + }, + "positive_controls": { + "type": "array", + "items": { + "type": "object", + "required": [ + "lane", + "terminal_rows", + "evidence" + ], + "properties": { + "lane": { + "type": "string", + "enum": [ + "control-lane-a", + "control-lane-b", + "control-lane-c" + ] + }, + "terminal_rows": { + "type": "integer", + "minimum": 0 + }, + "evidence": { + "type": "string" + } + } + } + }, + "unreadable_sources": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } + } + ], + "precheckNull": true + }, + { + "name": "forced", + "args": { + "date": "2026-08-29", + "force": true + }, + "responses": { + "friction-scan": { + "handoff_path": "/tmp/dry-read-friction-scan.json", + "sources_read": [ + "a" + ], + "candidate_count": 1, + "unreadable_sources": [], + "ledger_rows": [] + }, + "friction-source-linear": { + "handoff_path": "/tmp/dry-read-friction-source-linear.json", + "source_id": "linear", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "linear: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-source-checkpoints": { + "handoff_path": "/tmp/dry-read-friction-source-checkpoints.json", + "source_id": "checkpoints", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "checkpoints: stub over-bound artifact" + ], + "positive_controls": [ + "checkpoints: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-source-ci": { + "handoff_path": "/tmp/dry-read-friction-source-ci.json", + "source_id": "ci", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "ci: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-source-guards": { + "handoff_path": "/tmp/dry-read-friction-source-guards.json", + "source_id": "guards", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "guards: stub over-bound artifact" + ], + "positive_controls": [ + "guards: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-synthesize": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-synthesize.json", + "candidate_count": 2, + "root_causes": [ + "stub cause — 2 occurrences across 2 fingerprints" + ], + "sources_unknown": [ + "checkpoints: stub over-bound", + "guards: stub no-timestamp" + ], + "pickups": [ + "1. stub cause — lanes_blocked=2 recurrence=2 — unticketed" + ], + "ledger_rows": [] + }, + "friction-adjudicate": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-adjudicate.json", + "filed": [], + "commented": [], + "known": [], + "first_occurrence": [], + "escalated": [], + "ledger_rows": [] + }, + "friction-report": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "report_path": "/tmp/dry-read-friction-report.md", + "state_path": "/tmp/dry-read-friction-state.json", + "commit_sha": "deadbeefcafe", + "watermark_summary": "stub", + "ledger_rows": [], + "premise_audit": { + "status": "UNKNOWN", + "rule_landed_at": "", + "rule_evidence": "", + "eligible_terminal_rows": 0, + "falsified_terminal_rows": null, + "positive_controls": [], + "unreadable_sources": [ + "dry-read stub" + ], + "reason": "dry read has no ledger" + } + } + }, + "value": { + "date": "2026-08-29", + "dryRun": false, + "force": true, + "short_circuited": null, + "precheck": { + "bypassed": "args.force=true" + }, + "precheck_agents": 0, + "report": "/tmp/dry-read-friction-report.md", + "premise_audit": { + "status": "UNKNOWN", + "rule_landed_at": "", + "rule_evidence": "", + "eligible_terminal_rows": 0, + "falsified_terminal_rows": null, + "positive_controls": [], + "unreadable_sources": [ + "dry-read stub" + ], + "reason": "dry read has no ledger" + }, + "state": "/tmp/dry-read-friction-state.json", + "commit": "deadbeefcafe", + "window": "[2026-08-28T00:00:00Z, 2026-08-29T00:00:00Z) — the previous UTC day, 2026-08-28", + "scan": { + "handoff_path": "/tmp/dry-read-friction-scan.json", + "sources_read": [ + "a" + ], + "candidate_count": 1, + "unreadable_sources": [], + "ledger_rows": [] + }, + "sources": [ + { + "handoff_path": "/tmp/dry-read-friction-source-linear.json", + "source_id": "linear", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "linear: stub control, 3 rows" + ], + "ledger_rows": [] + }, + { + "handoff_path": "/tmp/dry-read-friction-source-checkpoints.json", + "source_id": "checkpoints", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "checkpoints: stub over-bound artifact" + ], + "positive_controls": [ + "checkpoints: stub control, 3 rows" + ], + "ledger_rows": [] + }, + { + "handoff_path": "/tmp/dry-read-friction-source-ci.json", + "source_id": "ci", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "ci: stub control, 3 rows" + ], + "ledger_rows": [] + }, + { + "handoff_path": "/tmp/dry-read-friction-source-guards.json", + "source_id": "guards", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "guards: stub over-bound artifact" + ], + "positive_controls": [ + "guards: stub control, 3 rows" + ], + "ledger_rows": [] + } + ], + "sources_unknown": [ + "checkpoints: stub over-bound", + "guards: stub no-timestamp" + ], + "synthesis": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-synthesize.json", + "candidate_count": 2, + "root_causes": [ + "stub cause — 2 occurrences across 2 fingerprints" + ], + "sources_unknown": [ + "checkpoints: stub over-bound", + "guards: stub no-timestamp" + ], + "pickups": [ + "1. stub cause — lanes_blocked=2 recurrence=2 — unticketed" + ], + "ledger_rows": [] + }, + "root_causes": [ + "stub cause — 2 occurrences across 2 fingerprints" + ], + "pickups": [ + "1. stub cause — lanes_blocked=2 recurrence=2 — unticketed" + ], + "adjudication": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-adjudicate.json", + "filed": [], + "commented": [], + "known": [], + "first_occurrence": [], + "escalated": [], + "ledger_rows": [] + }, + "agents": 8 + }, + "calls": [ + { + "label": "friction-scan", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "sources_read", + "candidate_count", + "unreadable_sources", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "sources_read": { + "type": "array", + "items": { + "type": "string" + } + }, + "candidate_count": { + "type": "number" + }, + "unreadable_sources": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-linear", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-checkpoints", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-ci", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-guards", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-synthesize", + "phase": "Synthesize", + "model": "opus", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "candidate_count", + "root_causes", + "sources_unknown", + "pickups", + "ledger_rows", + "delegation" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "root_causes": { + "type": "array", + "items": { + "type": "string" + } + }, + "sources_unknown": { + "type": "array", + "items": { + "type": "string" + } + }, + "pickups": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } + }, + { + "label": "friction-adjudicate", + "phase": "Adjudicate", + "model": "opus", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "filed", + "commented", + "known", + "first_occurrence", + "escalated", + "ledger_rows", + "delegation" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "filed": { + "type": "array", + "items": { + "type": "string" + } + }, + "commented": { + "type": "array", + "items": { + "type": "string" + } + }, + "known": { + "type": "array", + "items": { + "type": "string" + } + }, + "first_occurrence": { + "type": "array", + "items": { + "type": "string" + } + }, + "escalated": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } + }, + { + "label": "friction-report", + "phase": "Report", + "model": "opus", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "report_path", + "state_path", + "commit_sha", + "watermark_summary", + "ledger_rows", + "premise_audit", + "delegation" + ], + "properties": { + "report_path": { + "type": "string" + }, + "state_path": { + "type": "string" + }, + "commit_sha": { + "type": "string" + }, + "watermark_summary": { + "type": "string" + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "premise_audit": { + "type": "object", + "required": [ + "status", + "rule_landed_at", + "rule_evidence", + "eligible_terminal_rows", + "falsified_terminal_rows", + "positive_controls", + "unreadable_sources", + "reason" + ], + "properties": { + "status": { + "type": "string", + "enum": [ + "MEASURED", + "UNKNOWN" + ] + }, + "rule_landed_at": { + "type": "string" + }, + "rule_evidence": { + "type": "string" + }, + "eligible_terminal_rows": { + "type": "integer", + "minimum": 0 + }, + "falsified_terminal_rows": { + "type": [ + "integer", + "null" + ], + "minimum": 0 + }, + "positive_controls": { + "type": "array", + "items": { + "type": "object", + "required": [ + "lane", + "terminal_rows", + "evidence" + ], + "properties": { + "lane": { + "type": "string", + "enum": [ + "control-lane-a", + "control-lane-b", + "control-lane-c" + ] + }, + "terminal_rows": { + "type": "integer", + "minimum": 0 + }, + "evidence": { + "type": "string" + } + } + } + }, + "unreadable_sources": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } + } + ], + "precheckVerdict": "already-delivered" + }, + { + "name": "dry", + "args": { + "date": "2026-08-29", + "dryRun": true, + "lookbackHours": 72, + "fences": [ + "OMN-123: held", + "surface: protected" + ] + }, + "responses": { + "friction-precheck": { + "date": "2026-08-29", + "clock_utc": "2026-08-29T15:47:00Z", + "verdict": "run", + "evidence": "", + "reason": "dry-read stub" + }, + "friction-scan": { + "handoff_path": "/tmp/dry-read-friction-scan.json", + "sources_read": [ + "a" + ], + "candidate_count": 1, + "unreadable_sources": [], + "ledger_rows": [] + }, + "friction-source-linear": { + "handoff_path": "/tmp/dry-read-friction-source-linear.json", + "source_id": "linear", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "linear: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-source-checkpoints": { + "handoff_path": "/tmp/dry-read-friction-source-checkpoints.json", + "source_id": "checkpoints", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "checkpoints: stub over-bound artifact" + ], + "positive_controls": [ + "checkpoints: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-source-ci": { + "handoff_path": "/tmp/dry-read-friction-source-ci.json", + "source_id": "ci", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "ci: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-source-guards": { + "handoff_path": "/tmp/dry-read-friction-source-guards.json", + "source_id": "guards", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "guards: stub over-bound artifact" + ], + "positive_controls": [ + "guards: stub control, 3 rows" + ], + "ledger_rows": [] + }, + "friction-synthesize": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-synthesize.json", + "candidate_count": 2, + "root_causes": [ + "stub cause — 2 occurrences across 2 fingerprints" + ], + "sources_unknown": [ + "checkpoints: stub over-bound", + "guards: stub no-timestamp" + ], + "pickups": [ + "1. stub cause — lanes_blocked=2 recurrence=2 — unticketed" + ], + "ledger_rows": [] + }, + "friction-adjudicate": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-adjudicate.json", + "filed": [], + "commented": [], + "known": [], + "first_occurrence": [], + "escalated": [], + "ledger_rows": [] + }, + "friction-report": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "report_path": "/tmp/dry-read-friction-report.md", + "state_path": "/tmp/dry-read-friction-state.json", + "commit_sha": "deadbeefcafe", + "watermark_summary": "stub", + "ledger_rows": [], + "premise_audit": { + "status": "UNKNOWN", + "rule_landed_at": "", + "rule_evidence": "", + "eligible_terminal_rows": 0, + "falsified_terminal_rows": null, + "positive_controls": [], + "unreadable_sources": [ + "dry-read stub" + ], + "reason": "dry read has no ledger" + } + } + }, + "value": { + "date": "2026-08-29", + "dryRun": true, + "force": false, + "short_circuited": null, + "precheck": { + "date": "2026-08-29", + "clock_utc": "2026-08-29T15:47:00Z", + "verdict": "run", + "evidence": "", + "reason": "dry-read stub" + }, + "precheck_agents": 1, + "report": "/tmp/dry-read-friction-report.md", + "premise_audit": { + "status": "UNKNOWN", + "rule_landed_at": "", + "rule_evidence": "", + "eligible_terminal_rows": 0, + "falsified_terminal_rows": null, + "positive_controls": [], + "unreadable_sources": [ + "dry-read stub" + ], + "reason": "dry read has no ledger" + }, + "state": "/tmp/dry-read-friction-state.json", + "commit": "deadbeefcafe", + "window": "[2026-08-28T00:00:00Z, 2026-08-29T00:00:00Z) — the previous UTC day, 2026-08-28", + "scan": { + "handoff_path": "/tmp/dry-read-friction-scan.json", + "sources_read": [ + "a" + ], + "candidate_count": 1, + "unreadable_sources": [], + "ledger_rows": [] + }, + "sources": [ + { + "handoff_path": "/tmp/dry-read-friction-source-linear.json", + "source_id": "linear", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "linear: stub control, 3 rows" + ], + "ledger_rows": [] + }, + { + "handoff_path": "/tmp/dry-read-friction-source-checkpoints.json", + "source_id": "checkpoints", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "checkpoints: stub over-bound artifact" + ], + "positive_controls": [ + "checkpoints: stub control, 3 rows" + ], + "ledger_rows": [] + }, + { + "handoff_path": "/tmp/dry-read-friction-source-ci.json", + "source_id": "ci", + "verdict": "READ", + "freshness": "stub: 2h against a 48h bound", + "candidate_count": 1, + "unreadable": [], + "positive_controls": [ + "ci: stub control, 3 rows" + ], + "ledger_rows": [] + }, + { + "handoff_path": "/tmp/dry-read-friction-source-guards.json", + "source_id": "guards", + "verdict": "UNKNOWN", + "freshness": "stub: 264h against a 48h bound", + "candidate_count": 0, + "unreadable": [ + "guards: stub over-bound artifact" + ], + "positive_controls": [ + "guards: stub control, 3 rows" + ], + "ledger_rows": [] + } + ], + "sources_unknown": [ + "checkpoints: stub over-bound", + "guards: stub no-timestamp" + ], + "synthesis": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-synthesize.json", + "candidate_count": 2, + "root_causes": [ + "stub cause — 2 occurrences across 2 fingerprints" + ], + "sources_unknown": [ + "checkpoints: stub over-bound", + "guards: stub no-timestamp" + ], + "pickups": [ + "1. stub cause — lanes_blocked=2 recurrence=2 — unticketed" + ], + "ledger_rows": [] + }, + "root_causes": [ + "stub cause — 2 occurrences across 2 fingerprints" + ], + "pickups": [ + "1. stub cause — lanes_blocked=2 recurrence=2 — unticketed" + ], + "adjudication": { + "delegation": { + "delegated": 1, + "runs": [ + "dry-read" + ], + "reason": "" + }, + "handoff_path": "/tmp/dry-read-friction-adjudicate.json", + "filed": [], + "commented": [], + "known": [], + "first_occurrence": [], + "escalated": [], + "ledger_rows": [] + }, + "agents": 9 + }, + "calls": [ + { + "label": "friction-precheck", + "phase": "Precheck", + "model": "sonnet", + "effort": "medium", + "schema": { + "type": "object", + "required": [ + "date", + "clock_utc", + "verdict", + "evidence", + "reason" + ], + "properties": { + "date": { + "type": "string" + }, + "clock_utc": { + "type": "string" + }, + "verdict": { + "type": "string", + "enum": [ + "already-delivered", + "peer-owned", + "run" + ] + }, + "evidence": { + "type": "string" + }, + "reason": { + "type": "string" + }, + "state_last_run_date": { + "type": "string" + }, + "checks_failed": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-scan", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "sources_read", + "candidate_count", + "unreadable_sources", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "sources_read": { + "type": "array", + "items": { + "type": "string" + } + }, + "candidate_count": { + "type": "number" + }, + "unreadable_sources": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-linear", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-checkpoints", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-ci", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-source-guards", + "phase": "Scan", + "model": "sonnet", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "source_id", + "verdict", + "freshness", + "candidate_count", + "unreadable", + "ledger_rows" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "verdict": { + "type": "string" + }, + "freshness": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "unreadable": { + "type": "array", + "items": { + "type": "string" + } + }, + "positive_controls": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + { + "label": "friction-synthesize", + "phase": "Synthesize", + "model": "opus", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "candidate_count", + "root_causes", + "sources_unknown", + "pickups", + "ledger_rows", + "delegation" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "candidate_count": { + "type": "number" + }, + "root_causes": { + "type": "array", + "items": { + "type": "string" + } + }, + "sources_unknown": { + "type": "array", + "items": { + "type": "string" + } + }, + "pickups": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } + }, + { + "label": "friction-adjudicate", + "phase": "Adjudicate", + "model": "opus", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "handoff_path", + "filed", + "commented", + "known", + "first_occurrence", + "escalated", + "ledger_rows", + "delegation" + ], + "properties": { + "handoff_path": { + "type": "string" + }, + "filed": { + "type": "array", + "items": { + "type": "string" + } + }, + "commented": { + "type": "array", + "items": { + "type": "string" + } + }, + "known": { + "type": "array", + "items": { + "type": "string" + } + }, + "first_occurrence": { + "type": "array", + "items": { + "type": "string" + } + }, + "escalated": { + "type": "array", + "items": { + "type": "string" + } + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } + }, + { + "label": "friction-report", + "phase": "Report", + "model": "opus", + "effort": "high", + "schema": { + "type": "object", + "required": [ + "report_path", + "state_path", + "commit_sha", + "watermark_summary", + "ledger_rows", + "premise_audit", + "delegation" + ], + "properties": { + "report_path": { + "type": "string" + }, + "state_path": { + "type": "string" + }, + "commit_sha": { + "type": "string" + }, + "watermark_summary": { + "type": "string" + }, + "ledger_rows": { + "type": "array", + "items": { + "type": "string" + } + }, + "premise_audit": { + "type": "object", + "required": [ + "status", + "rule_landed_at", + "rule_evidence", + "eligible_terminal_rows", + "falsified_terminal_rows", + "positive_controls", + "unreadable_sources", + "reason" + ], + "properties": { + "status": { + "type": "string", + "enum": [ + "MEASURED", + "UNKNOWN" + ] + }, + "rule_landed_at": { + "type": "string" + }, + "rule_evidence": { + "type": "string" + }, + "eligible_terminal_rows": { + "type": "integer", + "minimum": 0 + }, + "falsified_terminal_rows": { + "type": [ + "integer", + "null" + ], + "minimum": 0 + }, + "positive_controls": { + "type": "array", + "items": { + "type": "object", + "required": [ + "lane", + "terminal_rows", + "evidence" + ], + "properties": { + "lane": { + "type": "string", + "enum": [ + "control-lane-a", + "control-lane-b", + "control-lane-c" + ] + }, + "terminal_rows": { + "type": "integer", + "minimum": 0 + }, + "evidence": { + "type": "string" + } + } + } + }, + "unreadable_sources": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + }, + "delegation": { + "type": "object", + "required": [ + "delegated", + "runs", + "reason" + ], + "properties": { + "delegated": { + "type": "integer", + "minimum": 0 + }, + "runs": { + "type": "array", + "items": { + "type": "string" + } + }, + "reason": { + "type": "string" + } + } + } + } + } + } + ], + "precheckVerdict": "run" + } + ] +} diff --git a/tests/nodes/node_morning_friction_sweep_orchestrator/fixtures/overlay/node_morning_friction_sweep_orchestrator/briefs.md b/tests/nodes/node_morning_friction_sweep_orchestrator/fixtures/overlay/node_morning_friction_sweep_orchestrator/briefs.md new file mode 100644 index 0000000000..98c677edda --- /dev/null +++ b/tests/nodes/node_morning_friction_sweep_orchestrator/fixtures/overlay/node_morning_friction_sweep_orchestrator/briefs.md @@ -0,0 +1,29 @@ + +PRECHECK @@run_date@@ state @@state_path@@ stems @@phase_stems@@ peer window @@peer_claim_minutes@@ + + +RUN @@run_date@@ window @@window@@ state @@kb_prefix@@@@state_path@@ ledger @@ledger_path@@ @@fences@@ lookback @@lookback_hours@@ tool @@watermark_tool@@ v@@watermark_schema_version@@ watcher bound @@pr_watcher_max_age_minutes@@m + + +RUN @@run_date@@ window @@window@@ state @@kb_prefix@@@@state_path@@ ledger @@ledger_path@@ @@fences@@ linear bound @@linear_comments_max_age_hours@@ ceiling @@occurrence_comment_ceiling@@ + + +RUN @@run_date@@ window @@window@@ state @@kb_prefix@@@@state_path@@ ledger @@ledger_path@@ @@fences@@ checkpoints bound @@checkpoints_max_age_hours@@ + + +RUN @@run_date@@ window @@window@@ state @@kb_prefix@@@@state_path@@ ledger @@ledger_path@@ @@fences@@ ci bound @@ci_lookback_max_age_hours@@ repos @@ci_repos@@ + + +RUN @@run_date@@ window @@window@@ state @@kb_prefix@@@@state_path@@ ledger @@ledger_path@@ @@fences@@ guards bound @@guard_logs_max_age_hours@@ + + +RUN @@run_date@@ window @@window@@ state @@kb_prefix@@@@state_path@@ ledger @@ledger_path@@ @@fences@@ +scan @@scan_handoff@@ inputs @@synthesis_inputs@@ +@@source_summary@@ + + +RUN @@run_date@@ window @@window@@ state @@kb_prefix@@@@state_path@@ ledger @@ledger_path@@ @@fences@@ @@adjudication_mode@@ synthesis @@synthesis_handoff@@ unknown @@sources_unknown@@ dry_run=@@dry_run@@ + + +RUN @@run_date@@ window @@window@@ state @@kb_prefix@@@@state_path@@ ledger @@ledger_path@@ @@fences@@ @@report_mode@@ report @@report_path@@ branch @@kb_branch@@ worktree @@worktree_ticket@@ adjudication @@adjudication_handoff@@ synthesis @@synthesis_handoff@@ + diff --git a/tests/nodes/node_morning_friction_sweep_orchestrator/fixtures/overlay/node_morning_friction_sweep_orchestrator/overlay.yaml b/tests/nodes/node_morning_friction_sweep_orchestrator/fixtures/overlay/node_morning_friction_sweep_orchestrator/overlay.yaml new file mode 100644 index 0000000000..9f2e43b401 --- /dev/null +++ b/tests/nodes/node_morning_friction_sweep_orchestrator/fixtures/overlay/node_morning_friction_sweep_orchestrator/overlay.yaml @@ -0,0 +1,33 @@ +# Public test overlay of node_morning_friction_sweep_orchestrator: synthetic briefs, paths and bounds. +briefs: briefs.md +values: + state_path: reports/friction-state.json + report_path: reports/@@date@@-friction.md + ledger_path: tracking/LEDGER.md + kb_prefix: $KB/ + kb_branch: automation/friction-@@date@@ + watermark_tool: tools/watermark.py + watermark_schema_version: '2' + peer_claim_minutes: '90' + pr_watcher_max_age_minutes: '8' + worktree_ticket: friction-@@date@@ + linear_comments_max_age_hours: '48' + occurrence_comment_ceiling: '3' + checkpoints_max_age_hours: '48' + ci_lookback_max_age_hours: '48' + guard_logs_max_age_hours: '48' +texts: + adjudication_dry: DRY RUN, no ticket mutation. + adjudication_live: LIVE, ticket mutation authorized. + report_dry: DRY report. + report_live: LIVE report. +phase_stems: +- stem-scan +- stem-report +ci_repos: +- repo_a +- repo_b +premise_control_lanes: +- control-lane-a +- control-lane-b +- control-lane-c diff --git a/tests/nodes/node_morning_friction_sweep_orchestrator/helpers.py b/tests/nodes/node_morning_friction_sweep_orchestrator/helpers.py new file mode 100644 index 0000000000..7970f77ebc --- /dev/null +++ b/tests/nodes/node_morning_friction_sweep_orchestrator/helpers.py @@ -0,0 +1,177 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Shared fixtures: the public test overlay, a recorded phase gateway, a request builder.""" + +from __future__ import annotations + +import os +from pathlib import Path + +from pydantic import JsonValue + +from omnimarket.nodes.node_morning_friction_sweep_orchestrator.handlers.handler_morning_friction_sweep import ( + OVERLAY_ENV, + load_friction_overlay, +) +from omnimarket.nodes.node_morning_friction_sweep_orchestrator.models import ( + ModelFrictionOverlay, + ModelFrictionPhaseRequest, + ModelMorningFrictionSweepRequest, +) + +NODE = "node_morning_friction_sweep_orchestrator" +OVERLAY_ROOT = Path(__file__).parent / "fixtures" / "overlay" +OVERLAY_FILE = OVERLAY_ROOT / NODE / "overlay.yaml" +DELEGATION: dict[str, JsonValue] = {"delegated": 1, "runs": ["fixture"], "reason": ""} + + +def public_overlay() -> ModelFrictionOverlay: + """Load the public test overlay through the production loader.""" + previous = os.environ.get(OVERLAY_ENV) + os.environ[OVERLAY_ENV] = str(OVERLAY_FILE) + try: + return load_friction_overlay() + finally: + if previous is None: + del os.environ[OVERLAY_ENV] + else: + os.environ[OVERLAY_ENV] = previous + + +def stub_result(label: str) -> dict[str, JsonValue] | None: + """A schema-valid recorded phase result carrying a valid delegation cell.""" + if label == "friction-precheck": + return { + "date": "2026-08-29", + "clock_utc": "2026-08-29T15:47:00Z", + "verdict": "run", + "evidence": "", + "reason": "fixture", + } + if label == "friction-scan": + return { + "handoff_path": "/tmp/scan.json", + "sources_read": ["a"], + "candidate_count": 1, + "unreadable_sources": [], + "ledger_rows": [], + } + if label.startswith("friction-source-"): + return { + "handoff_path": f"/tmp/{label}.json", + "source_id": label.removeprefix("friction-source-"), + "verdict": "READ", + "freshness": "fixture", + "candidate_count": 1, + "unreadable": [], + "ledger_rows": [], + } + if label == "friction-synthesize": + return { + "handoff_path": "/tmp/synthesis.json", + "candidate_count": 1, + "root_causes": ["cause"], + "sources_unknown": [], + "pickups": ["pickup"], + "ledger_rows": [], + "delegation": DELEGATION, + } + if label == "friction-adjudicate": + return { + "handoff_path": "/tmp/adjudication.json", + "filed": [], + "commented": [], + "known": [], + "first_occurrence": [], + "escalated": [], + "ledger_rows": [], + "delegation": DELEGATION, + } + return { + "report_path": "/tmp/report.md", + "state_path": "/tmp/state.json", + "commit_sha": "deadbeef", + "watermark_summary": "fixture", + "ledger_rows": [], + "premise_audit": { + "status": "UNKNOWN", + "rule_landed_at": "", + "rule_evidence": "", + "eligible_terminal_rows": 0, + "falsified_terminal_rows": None, + "positive_controls": [], + "unreadable_sources": ["fixture"], + "reason": "fixture has no ledger", + }, + "delegation": DELEGATION, + } + + +class FixtureGateway: + """Recorded agent results; exercises orchestration without any agent.""" + + def __init__(self, responses: dict[str, JsonValue] | None = None) -> None: + self.responses = responses + self.calls: list[dict[str, JsonValue]] = [] + self.prompts: dict[str, str] = {} + self.fail_precheck = False + self.active = 0 + self.peak = 0 + + async def run( + self, run: ModelMorningFrictionSweepRequest, phase: ModelFrictionPhaseRequest + ) -> dict[str, JsonValue] | None: + self.prompts[phase.label] = phase.prompt + self.calls.append( + { + "label": phase.label, + "phase": phase.phase, + "model": phase.model, + "effort": phase.effort, + "schema": phase.schema_definition, + } + ) + if phase.label == "friction-precheck" and self.fail_precheck: + raise TimeoutError("dead precheck agent") + if phase.phase == "Scan": + import asyncio + + self.active += 1 + self.peak = max(self.peak, self.active) + await asyncio.sleep(0) + self.active -= 1 + if self.responses is not None: + value = self.responses[phase.label] + return value if isinstance(value, dict) or value is None else None + return stub_result(phase.label) + + +class PhaseEvidenceGateway(FixtureGateway): + """Replaces one phase's delegation cell.""" + + def __init__(self, label: str, cell: JsonValue) -> None: + super().__init__() + self.label = label + self.cell = cell + + async def run( + self, run: ModelMorningFrictionSweepRequest, phase: ModelFrictionPhaseRequest + ) -> dict[str, JsonValue] | None: + result = await super().run(run, phase) + if phase.label == self.label and result is not None: + result["delegation"] = self.cell + return result + + +def request( + args: dict[str, JsonValue] | None = None, +) -> ModelMorningFrictionSweepRequest: + return ModelMorningFrictionSweepRequest.model_validate( + { + "date": "2026-08-29", + "correlation_id": "12345678-1234-5678-1234-567812345678", + "emitted_at": "2026-10-06T22:19:12Z", + "tenant_id": "tenant-a", + **(args or {}), + } + ) diff --git a/tests/nodes/node_morning_friction_sweep_orchestrator/test_bus_cycle.py b/tests/nodes/node_morning_friction_sweep_orchestrator/test_bus_cycle.py new file mode 100644 index 0000000000..48a943eaa7 --- /dev/null +++ b/tests/nodes/node_morning_friction_sweep_orchestrator/test_bus_cycle.py @@ -0,0 +1,260 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""One full friction sweep cycle over the canonical in-memory bus, no injected gateway. + +The start command is published on the contract's declared topic, the contract is +wired through the runtime's auto-wiring from its path, the handler builds its own +bus phase gateway, every phase rides the declared delegation request/reply topics, +and the terminal lands on the declared completed topic. Two stand-ins: the +delegation consumer, which answers each request with a recorded phase result, and +the infra request/reply wiring, whose Kafka consumer is replaced by an in-memory +correlation matcher on the same bus (the real wiring needs a broker). +""" + +from __future__ import annotations + +import asyncio +import json +from importlib.resources import files +from pathlib import Path +from typing import cast +from uuid import UUID, uuid5 + +import pytest +import yaml +from omnibase_core.event_bus.event_bus_inmemory import EventBusInmemory +from omnibase_core.models.contracts.subcontracts import ModelRequestResponseConfig +from omnibase_core.models.delegation.wire import ModelDelegationRequest +from omnibase_core.models.event_bus.model_event_message import ModelEventMessage +from omnibase_core.models.events.model_event_envelope import ModelEventEnvelope +from omnibase_infra.protocols import ProtocolEventBusLike +from omnibase_infra.runtime.auto_wiring import ( + subscribe_wired_contract_topics, + wire_from_manifest, +) +from omnibase_infra.runtime.auto_wiring.discovery import discover_contracts_from_paths +from omnibase_infra.runtime.message_dispatch_engine import MessageDispatchEngine +from omnibase_infra.runtime.service_dispatch_result_applier import DispatchResultApplier + +from omnimarket.nodes.node_morning_friction_sweep_orchestrator.handlers.handler_morning_friction_sweep import ( + OVERLAY_ENV, +) +from omnimarket.nodes.node_morning_friction_sweep_orchestrator.models import ( + ModelMorningFrictionSweepRequest, + ModelMorningFrictionSweepResult, +) + +from .helpers import NODE, OVERLAY_FILE, request, stub_result + +CORRELATION = UUID("12345678-1234-5678-1234-567812345678") + +PACKAGE = f"omnimarket.nodes.{NODE}" + + +class InMemoryRequestResponse: + """Correlation matching on the in-memory bus, in place of the Kafka consumer.""" + + def __init__(self, event_bus: EventBusInmemory, **_: object) -> None: + self.bus = event_bus + self.pending: dict[str, asyncio.Future[dict[str, object]]] = {} + self.instances: dict[str, str] = {} + + async def wire_request_response(self, config: ModelRequestResponseConfig) -> None: + for instance in config.instances: + self.instances[instance.name] = instance.request_topic + for reply in ( + instance.reply_topics.completed, + instance.reply_topics.failed, + ): + await self.bus.subscribe( + reply, + group_id=f"rr-{instance.name}-{reply}", + on_message=self._on_reply, + ) + + async def _on_reply(self, message: ModelEventMessage) -> None: + body = json.loads(message.value) + pending = self.pending.pop(str(body["correlation_id"]), None) + if pending is not None: + pending.set_result(body) + + async def send_request( + self, + instance_name: str, + payload: dict[str, object], + timeout_seconds: int | None = None, + ) -> dict[str, object]: + correlation = str(payload["correlation_id"]) + future: asyncio.Future[dict[str, object]] = ( + asyncio.get_running_loop().create_future() + ) + self.pending[correlation] = future + await self.bus.publish( + self.instances[instance_name], + correlation.encode(), + json.dumps(payload).encode(), + ) + return await asyncio.wait_for(future, timeout=timeout_seconds) + + +LABELS = { + uuid5(CORRELATION, label): label + for label in ( + "friction-precheck", + "friction-scan", + "friction-source-linear", + "friction-source-checkpoints", + "friction-source-ci", + "friction-source-guards", + "friction-synthesize", + "friction-adjudicate", + "friction-report", + ) +} + + +COMPLETED = "onex.evt.omnimarket.morning-friction-sweep-completed.v1" +FAILED = "onex.evt.omnimarket.morning-friction-sweep-failed.v1" +START = "onex.cmd.omnimarket.morning-friction-sweep-start.v1" + + +async def drive( + bad_phase: str | None, +) -> tuple[list[ModelMorningFrictionSweepResult], list[bytes], list[str]]: + """Publish one start command; return completed terminals, failed terminals, phases asked.""" + contract_file = files(PACKAGE).joinpath("contract.yaml") + contract = yaml.safe_load(contract_file.read_text()) + start = contract["event_bus"]["subscribe_topics"][0] + assert start == START + instance = contract["event_bus"]["request_response"]["instances"][0] + bus = EventBusInmemory(environment="dev", group="friction-cycle") + await bus.start() + asked: list[str] = [] + completed: list[ModelMorningFrictionSweepResult] = [] + failed: list[bytes] = [] + settled = asyncio.Event() + + async def delegation_consumer(message: ModelEventMessage) -> None: + envelope = ModelEventEnvelope[ModelDelegationRequest].model_validate_json( + message.value + ) + phase = json.loads(envelope.payload.context_pack or "{}").get("phase", "") + asked.append(phase) + label = LABELS[envelope.payload.correlation_id] + result = stub_result(label) + if phase == bad_phase and result is not None: + result["delegation"] = {"delegated": 1, "runs": [], "reason": ""} + reply = { + "correlation_id": str(envelope.correlation_id), + "tenant_id": envelope.payload.tenant_id, + "content": json.dumps(result), + } + await bus.publish( + instance["reply_topics"]["completed"], + str(envelope.correlation_id).encode(), + json.dumps(reply).encode(), + ) + + async def on_completed(message: ModelEventMessage) -> None: + completed.append( + ModelEventEnvelope[ModelMorningFrictionSweepResult] + .model_validate_json(message.value) + .payload + ) + settled.set() + + async def on_failed(message: ModelEventMessage) -> None: + failed.append(message.value) + settled.set() + + stops = [ + await bus.subscribe( + instance["request_topic"], + group_id="friction-cycle-delegation", + on_message=delegation_consumer, + ), + await bus.subscribe( + COMPLETED, group_id="friction-cycle-ok", on_message=on_completed + ), + await bus.subscribe( + FAILED, group_id="friction-cycle-err", on_message=on_failed + ), + ] + manifest = discover_contracts_from_paths([Path(str(contract_file))]) + assert manifest.total_discovered == 1 + assert not manifest.errors + engine = MessageDispatchEngine() + appliers = { + manifest.contracts[0].name: DispatchResultApplier( + cast(ProtocolEventBusLike, bus), + output_topic=contract["terminal_event"], + allowed_output_topics=contract["event_bus"]["publish_topics"], + ) + } + report = await wire_from_manifest( + manifest, + engine, + bus, + subscribe_immediately=False, + result_appliers_by_contract=appliers, + materialized_explicit_dependencies={ + "HandlerMorningFrictionSweep": {"event_bus": bus} + }, + ) + engine.freeze() + attached = await subscribe_wired_contract_topics( + manifest, report, engine, bus, result_appliers_by_contract=appliers + ) + assert start in attached[manifest.contracts[0].name] + command = request({"force": True}) + envelope = ModelEventEnvelope[ModelMorningFrictionSweepRequest]( + payload=command, + correlation_id=command.correlation_id, + tenant_id=command.tenant_id, + event_type=start, + envelope_timestamp=command.emitted_at, + ) + await bus.publish( + start, str(command.correlation_id).encode(), envelope.model_dump_json().encode() + ) + await asyncio.wait_for(settled.wait(), timeout=30) + for stop in stops: + await stop() + await bus.close() + return completed, failed, asked + + +@pytest.fixture +def bus_environment(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv(OVERLAY_ENV, str(OVERLAY_FILE)) + monkeypatch.setenv("ONEX_ENVIRONMENT", "dev") + monkeypatch.setattr( + "omnibase_infra.runtime.request_response_wiring.RequestResponseWiring", + InMemoryRequestResponse, + ) + + +@pytest.mark.usefixtures("bus_environment") +def test_one_friction_sweep_cycle_over_the_bus() -> None: + completed, failed, asked = asyncio.run(drive(None)) + assert failed == [] + assert len(completed) == 1 + terminal = completed[0] + assert terminal.correlation_id == CORRELATION + assert terminal.short_circuited is None + assert terminal.agents == 8 + assert terminal.report == "/tmp/report.md" + # Force skips the precheck; five concurrent sources, then the three serial phases. + assert sorted(asked[:5]) == ["Scan"] * 5 + assert asked[5:] == ["Synthesize", "Adjudicate", "Report"] + + +@pytest.mark.usefixtures("bus_environment") +@pytest.mark.parametrize("bad_phase", ["Synthesize", "Adjudicate", "Report"]) +def test_invalid_delegation_evidence_over_the_bus_terminates_as_failed( + bad_phase: str, +) -> None: + completed, failed, _asked = asyncio.run(drive(bad_phase)) + assert completed == [] + assert len(failed) == 1 + assert b"delegation cell refused" in failed[0] diff --git a/tests/nodes/node_morning_friction_sweep_orchestrator/test_error_chain_morning_friction_sweep_orchestrator.py b/tests/nodes/node_morning_friction_sweep_orchestrator/test_error_chain_morning_friction_sweep_orchestrator.py new file mode 100644 index 0000000000..bcc4e2b2f7 --- /dev/null +++ b/tests/nodes/node_morning_friction_sweep_orchestrator/test_error_chain_morning_friction_sweep_orchestrator.py @@ -0,0 +1,226 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Error chain: bad evidence stops the sweep; the precheck fails open.""" + +from __future__ import annotations + +import asyncio + +import pytest +from pydantic import JsonValue + +from omnimarket.nodes.node_morning_friction_sweep_orchestrator.handlers.handler_morning_friction_sweep import ( + HandlerMorningFrictionSweep, + delegation_problem, + premise_audit_problem, +) +from omnimarket.nodes.node_morning_friction_sweep_orchestrator.models import ( + ModelFrictionPhaseRequest, + ModelMorningFrictionSweepRequest, +) + +from .helpers import FixtureGateway, PhaseEvidenceGateway, public_overlay, request + +LANES = ["control-lane-a", "control-lane-b", "control-lane-c"] +DELEGATED = ["friction-synthesize", "friction-adjudicate", "friction-report"] + + +def _handler(gateway: FixtureGateway) -> HandlerMorningFrictionSweep: + return HandlerMorningFrictionSweep(None, gateway, public_overlay()) + + +@pytest.mark.parametrize( + ("cell", "problem"), + [ + (None, "missing or invalid cell"), + ({"delegated": 0, "runs": [], "reason": ""}, "zero delegation reason refused"), + ({"delegated": 1, "runs": [], "reason": ""}, "delegated steps have no runs"), + ({"delegated": 1, "runs": [" "], "reason": ""}, "invalid run ids"), + ({"delegated": 1, "runs": ["stub run"], "reason": ""}, "invalid run ids"), + ( + {"delegated": 1, "runs": ["run-1"], "reason": "x"}, + "delegated steps require an empty reason", + ), + ( + {"delegated": 0, "runs": ["stub-run"], "reason": "route-refused:503"}, + "zero delegated count requires empty runs", + ), + ({"delegated": 1, "runs": ["run-1"], "reason": ""}, None), + ({"delegated": 0, "runs": [], "reason": "route-refused:unavailable"}, None), + ({"delegated": 0, "runs": [], "reason": "route-unavailable:run-1"}, None), + ( + {"delegated": True, "runs": ["run-1"], "reason": ""}, + "invalid delegated count", + ), + ], +) +def test_delegation_cells(cell: JsonValue, problem: str | None) -> None: + assert delegation_problem(cell) == problem + + +@pytest.mark.parametrize("label", DELEGATED) +@pytest.mark.parametrize( + "cell", + [ + None, + {"delegated": 1, "runs": [], "reason": ""}, + {"delegated": 0, "runs": [], "reason": ""}, + ], +) +def test_invalid_delegation_evidence_fails_the_sweep( + label: str, cell: JsonValue +) -> None: + gateway = PhaseEvidenceGateway(label, cell) + with pytest.raises(ValueError, match="delegation cell refused"): + asyncio.run(_handler(gateway).handle(request({"force": True}))) + + +def test_an_absent_phase_result_stops_dependent_work() -> None: + class Absent(FixtureGateway): + async def run( + self, + run: ModelMorningFrictionSweepRequest, + phase: ModelFrictionPhaseRequest, + ) -> dict[str, JsonValue] | None: + result = await super().run(run, phase) + return None if phase.label == "friction-synthesize" else result + + gateway = Absent() + with pytest.raises(ValueError, match="absent phase result"): + asyncio.run(_handler(gateway).handle(request({"force": True}))) + assert "friction-adjudicate" not in [c["label"] for c in gateway.calls] + + +@pytest.mark.parametrize( + "cell", + [ + {"delegated": 1, "runs": ["run-1"], "reason": ""}, + {"delegated": 0, "runs": [], "reason": "route-refused:timeout"}, + ], +) +def test_recorded_delegation_evidence_completes_the_sweep(cell: JsonValue) -> None: + gateway = PhaseEvidenceGateway("friction-synthesize", cell) + result = asyncio.run(_handler(gateway).handle(request({"force": True}))) + assert result.synthesis is not None + assert result.synthesis.delegation.model_dump() == cell + + +def _measured(**change: JsonValue) -> dict[str, JsonValue]: + controls: list[JsonValue] = [ + {"lane": lane, "terminal_rows": 2, "evidence": "row"} for lane in LANES + ] + cell: dict[str, JsonValue] = { + "status": "MEASURED", + "rule_landed_at": "2026-09-15T10:00:00Z", + "rule_evidence": "ledger row", + "eligible_terminal_rows": 10, + "falsified_terminal_rows": 1, + "positive_controls": controls, + "unreadable_sources": [], + "reason": "", + } + cell.update(change) + return cell + + +@pytest.mark.parametrize( + ("change", "problem"), + [ + ({}, None), + ({"eligible_terminal_rows": 0}, "measurement lacks complete nonempty coverage"), + ( + {"unreadable_sources": ["ledger archive"]}, + "measurement lacks complete nonempty coverage", + ), + ({"falsified_terminal_rows": 11}, "invalid falsified count"), + ({"rule_landed_at": "2026-09-15"}, "rule landing lacks timestamp or citation"), + ({"rule_evidence": " "}, "rule landing lacks timestamp or citation"), + ({"positive_controls": []}, "all cited positive controls are required"), + ( + { + "positive_controls": [ + {"lane": "other", "terminal_rows": 1, "evidence": "e"} + ] + }, + "invalid positive controls", + ), + ({"status": "GUESS"}, "invalid audit status"), + ( + { + "status": "UNKNOWN", + "falsified_terminal_rows": None, + "reason": "no ledger", + }, + None, + ), + ( + {"status": "UNKNOWN", "falsified_terminal_rows": 3, "reason": "no ledger"}, + "UNKNOWN must explain missing evidence and cannot report a count", + ), + ], +) +def test_premise_audit_cells(change: dict[str, JsonValue], problem: str | None) -> None: + assert premise_audit_problem(_measured(**change), LANES) == problem + + +def test_a_missing_premise_audit_is_refused() -> None: + assert premise_audit_problem(None, LANES) == "missing or invalid audit" + + +def test_a_refused_premise_audit_fails_the_sweep() -> None: + class Unmeasured(FixtureGateway): + async def run( + self, + run: ModelMorningFrictionSweepRequest, + phase: ModelFrictionPhaseRequest, + ) -> dict[str, JsonValue] | None: + result = await super().run(run, phase) + if phase.label == "friction-report" and result is not None: + result["premise_audit"] = _measured(eligible_terminal_rows=0) + return result + + with pytest.raises(ValueError, match="premise audit refused"): + asyncio.run(_handler(Unmeasured()).handle(request({"force": True}))) + + +def test_dead_precheck_falls_through_to_full_run() -> None: + gateway = FixtureGateway() + gateway.fail_precheck = True + result = asyncio.run(_handler(gateway).handle(request())) + assert result.short_circuited is None + assert result.agents == 9 + assert result.precheck.model_dump(mode="json") == { + "bypassed": "unavailable — fell through to a full run", + "failure_type": "TimeoutError", + "failure_reason": "dead precheck agent", + } + + +def test_a_precheck_off_its_schema_falls_through_to_full_run() -> None: + class Garbled(FixtureGateway): + async def run( + self, + run: ModelMorningFrictionSweepRequest, + phase: ModelFrictionPhaseRequest, + ) -> dict[str, JsonValue] | None: + result = await super().run(run, phase) + if phase.label == "friction-precheck" and result is not None: + result["verdict"] = "maybe" + return result + + result = asyncio.run(_handler(Garbled()).handle(request())) + assert result.short_circuited is None + assert result.precheck_agents == 1 + + +def test_a_missing_prompt_field_is_refused_not_rendered_blank() -> None: + overlay = public_overlay() + broken = overlay.model_copy( + update={"templates": {**overlay.templates, "friction-scan": "uses @@nope@@"}} + ) + with pytest.raises(ValueError, match="unknown friction prompt field: nope"): + asyncio.run( + HandlerMorningFrictionSweep(None, FixtureGateway(), broken).handle( + request({"force": True}) + ) + ) diff --git a/tests/nodes/node_morning_friction_sweep_orchestrator/test_golden_chain_morning_friction_sweep_orchestrator.py b/tests/nodes/node_morning_friction_sweep_orchestrator/test_golden_chain_morning_friction_sweep_orchestrator.py new file mode 100644 index 0000000000..a2e6a663c7 --- /dev/null +++ b/tests/nodes/node_morning_friction_sweep_orchestrator/test_golden_chain_morning_friction_sweep_orchestrator.py @@ -0,0 +1,160 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""Golden chain: the packaged contract resolves, its handler runs a typed request to a typed terminal. + +Decision parity: six transcripts recorded from the original workflow (fresh run, +already delivered, peer owned, unavailable precheck, force, dry run) produce the +same terminal, the same phase order and the same model/effort/schema routing. +""" + +from __future__ import annotations + +import asyncio +import importlib +import inspect +import json +from importlib.resources import files +from pathlib import Path +from typing import cast + +import pytest +import yaml +from pydantic import JsonValue + +from omnimarket.nodes.node_morning_friction_sweep_orchestrator.models import ( + ModelMorningFrictionSweepRequest, + ModelMorningFrictionSweepResult, +) + +from .helpers import NODE, FixtureGateway, public_overlay, request + +CASES = json.loads( + (Path(__file__).parent / "fixtures" / "decision_parity.json").read_text() +)["cases"] +PACKAGE = f"omnimarket.nodes.{NODE}" +LABELS = [ + "friction-precheck", + "friction-scan", + "friction-source-linear", + "friction-source-checkpoints", + "friction-source-ci", + "friction-source-guards", + "friction-synthesize", + "friction-adjudicate", + "friction-report", +] + + +def _contract() -> dict[str, JsonValue]: + return cast( + dict[str, JsonValue], + yaml.safe_load(files(PACKAGE).joinpath("contract.yaml").read_text()), + ) + + +def _handler_type() -> type: + return cast( + type, + importlib.import_module( + f"{PACKAGE}.handlers.handler_morning_friction_sweep" + ).HandlerMorningFrictionSweep, + ) + + +def test_golden_chain_morning_friction_sweep_orchestrator() -> None: + contract = _contract() + assert contract["name"] == NODE + assert contract["node_type"] == "orchestrator" + routing = cast(dict[str, JsonValue], contract["handler_routing"]) + assert routing["routing_strategy"] == "operation_match" + entries = cast(list[dict[str, JsonValue]], routing["handlers"]) + assert [entry["operation"] for entry in entries] == ["morning_friction_sweep"] + entry = entries[0] + handler_ref = cast(dict[str, str], entry["handler"]) + handler_type = getattr( + importlib.import_module(handler_ref["module"]), handler_ref["name"] + ) + input_module, _, input_name = str(entry["input_model"]).rpartition(".") + output_module, _, output_name = str(entry["output_model"]).rpartition(".") + request_type = getattr(importlib.import_module(input_module), input_name) + result_type = getattr(importlib.import_module(output_module), output_name) + assert request_type is ModelMorningFrictionSweepRequest + assert result_type is ModelMorningFrictionSweepResult + # Definition-B: one typed request in, one typed result out. + assert inspect.iscoroutinefunction(handler_type.handle) + assert list(inspect.signature(handler_type.handle).parameters) == [ + "self", + "request", + ] + gateway = FixtureGateway() + result = asyncio.run( + handler_type(None, gateway, public_overlay()).handle(request()) + ) + assert isinstance(result, result_type) + assert [call["label"] for call in gateway.calls] == LABELS + assert result.agents == 9 + assert result.short_circuited is None + + +def test_contract_declares_every_topic_and_the_terminal() -> None: + contract = _contract() + bus = cast(dict[str, JsonValue], contract["event_bus"]) + subscribed = cast(list[str], bus["subscribe_topics"]) + published = cast(list[str], bus["publish_topics"]) + terminals = cast(dict[str, str], contract["terminal_events"]) + assert subscribed == ["onex.cmd.omnimarket.morning-friction-sweep-start.v1"] + assert terminals == { + "success": "onex.evt.omnimarket.morning-friction-sweep-completed.v1", + "failure": "onex.evt.omnimarket.morning-friction-sweep-failed.v1", + } + assert contract["terminal_event"] == terminals["success"] + runtime_dispatch = cast(dict[str, str], contract["runtime_dispatch"]) + assert runtime_dispatch["command_topic"] == subscribed[0] + assert contract["externally_consumed_topics"] == [ + terminals["success"], + terminals["failure"], + ] + assert terminals["success"] in published + assert terminals["failure"] in published + instance = cast( + list[dict[str, JsonValue]], + cast(dict[str, JsonValue], bus["request_response"])["instances"], + )[0] + assert instance["request_topic"] in published + assert set(cast(dict[str, str], instance["reply_topics"])) == { + "completed", + "failed", + } + + +@pytest.mark.parametrize("case", CASES, ids=lambda c: str(c["name"])) +def test_original_workflow_decision_parity(case: dict[str, JsonValue]) -> None: + gateway = FixtureGateway(cast(dict[str, JsonValue], case["responses"])) + result = asyncio.run( + _handler_type()(None, gateway, public_overlay()).handle( + request(cast(dict[str, JsonValue], case["args"])) + ) + ) + dumped = result.model_dump( + mode="json", exclude={"correlation_id", "tenant_id"}, exclude_unset=True + ) + dumped["dryRun"] = dumped.pop("dry_run") + assert dumped == case["value"] + assert gateway.calls == case["calls"] + assert gateway.peak == (5 if result.short_circuited is None else 0) + + +@pytest.mark.parametrize("verdict", ["already-delivered", "peer-owned"]) +def test_a_same_date_precheck_verdict_spawns_zero_expensive_agents( + verdict: str, +) -> None: + case = next(c for c in CASES if c.get("precheckVerdict") == verdict) + gateway = FixtureGateway(cast(dict[str, JsonValue], case["responses"])) + result = asyncio.run( + _handler_type()(None, gateway, public_overlay()).handle( + request(cast(dict[str, JsonValue], case["args"])) + ) + ) + assert result.short_circuited == verdict + assert result.expensive_agents_spawned == 0 + assert [c["label"] for c in gateway.calls] == ["friction-precheck"] diff --git a/tests/nodes/node_morning_friction_sweep_orchestrator/test_overlay.py b/tests/nodes/node_morning_friction_sweep_orchestrator/test_overlay.py new file mode 100644 index 0000000000..faec5c5ff1 --- /dev/null +++ b/tests/nodes/node_morning_friction_sweep_orchestrator/test_overlay.py @@ -0,0 +1,207 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""The private half of the friction sweep arrives only through a strict overlay.""" + +from __future__ import annotations + +import asyncio +import os +import re +import shutil +from importlib.resources import files +from pathlib import Path + +import pytest +import yaml + +from omnimarket.nodes.node_morning_friction_sweep_orchestrator.handlers.handler_morning_friction_sweep import ( + OVERLAY_ENV, + HandlerMorningFrictionSweep, + MorningFrictionSweepConfigurationError, + load_friction_overlay, +) + +from .helpers import ( + NODE, + OVERLAY_FILE, + OVERLAY_ROOT, + FixtureGateway, + public_overlay, + request, +) + +PACKAGE = f"omnimarket.nodes.{NODE}" + + +@pytest.fixture(autouse=True) +def clear_overlay_env(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.delenv(OVERLAY_ENV, raising=False) + monkeypatch.delenv("ONEX_SKILL_OVERLAY_ROOTS", raising=False) + + +def _copy_overlay(tmp_path: Path) -> Path: + target = tmp_path / "copy" / NODE + shutil.copytree(OVERLAY_ROOT / NODE, target) + return target + + +def _rewrite(overlay: Path, change: dict[str, object]) -> None: + raw = yaml.safe_load(overlay.read_text(encoding="utf-8")) + raw.update(change) + overlay.write_text(yaml.safe_dump(raw), encoding="utf-8") + + +def test_no_overlay_is_a_hard_stop() -> None: + with pytest.raises(MorningFrictionSweepConfigurationError, match=OVERLAY_ENV): + load_friction_overlay() + + +def test_pointer_wins_over_roots( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + other = _copy_overlay(tmp_path) + _rewrite(other / "overlay.yaml", {"ci_repos": ["other_repo"]}) + monkeypatch.setenv(OVERLAY_ENV, str(OVERLAY_FILE)) + monkeypatch.setenv("ONEX_SKILL_OVERLAY_ROOTS", str(other.parent)) + assert load_friction_overlay().lists["ci_repos"] == ["repo_a", "repo_b"] + + +def test_roots_use_the_first_existing_overlay( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + other = _copy_overlay(tmp_path) + _rewrite(other / "overlay.yaml", {"ci_repos": ["other_repo"]}) + monkeypatch.setenv( + "ONEX_SKILL_OVERLAY_ROOTS", + os.pathsep.join( + ("", str(tmp_path / "missing"), str(other.parent), str(OVERLAY_ROOT)) + ), + ) + assert load_friction_overlay().lists["ci_repos"] == ["other_repo"] + + +@pytest.mark.parametrize("pointer", ["", "/nonexistent/overlay.yaml"]) +def test_an_explicit_bad_pointer_never_falls_through( + pointer: str, monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setenv(OVERLAY_ENV, pointer) + monkeypatch.setenv("ONEX_SKILL_OVERLAY_ROOTS", str(OVERLAY_ROOT)) + with pytest.raises(MorningFrictionSweepConfigurationError, match=OVERLAY_ENV): + load_friction_overlay() + + +@pytest.mark.parametrize( + ("change", "fragment"), + [ + ({"unexpected": 1}, "unknown"), + ({"values": {"state_path": "x"}}, "missing value"), + ({"texts": {"report_dry": "x"}}, "missing text"), + ({"briefs": "absent.md"}, "briefs"), + ({"ci_repos": "not-a-list"}, "ci_repos"), + ({"premise_control_lanes": []}, "premise_control_lanes"), + ], +) +def test_an_invalid_overlay_is_refused( + change: dict[str, object], + fragment: str, + tmp_path: Path, + monkeypatch: pytest.MonkeyPatch, +) -> None: + copied = _copy_overlay(tmp_path) + _rewrite(copied / "overlay.yaml", change) + monkeypatch.setenv(OVERLAY_ENV, str(copied / "overlay.yaml")) + with pytest.raises(MorningFrictionSweepConfigurationError, match=fragment): + load_friction_overlay() + + +@pytest.mark.parametrize("label", ["friction-report", "friction-source-ci"]) +def test_an_overlay_missing_a_required_template_is_refused( + label: str, tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + copied = _copy_overlay(tmp_path) + briefs = copied / "briefs.md" + briefs.write_text( + re.sub( + rf".*?\n", + "", + briefs.read_text(encoding="utf-8"), + flags=re.S, + ), + encoding="utf-8", + ) + monkeypatch.setenv(OVERLAY_ENV, str(copied / "overlay.yaml")) + with pytest.raises(MorningFrictionSweepConfigurationError, match=label): + load_friction_overlay() + + +def test_rendered_prompts_carry_the_overlay_values() -> None: + gateway = FixtureGateway() + asyncio.run( + HandlerMorningFrictionSweep(None, gateway, public_overlay()).handle( + request({"dryRun": True, "lookbackHours": 72, "fences": ["held: x"]}) + ) + ) + scan = gateway.prompts["friction-scan"] + assert "reports/friction-state.json" in scan + assert "lookback 72" in scan + assert "- held: x" in scan + assert ( + "window [2026-08-28T00:00:00Z, 2026-08-29T00:00:00Z) — the previous UTC day, 2026-08-28" + in scan + ) + assert "repo_a, repo_b" in gateway.prompts["friction-source-ci"] + assert "'stem-scan', 'stem-report'" in gateway.prompts["friction-precheck"] + assert "DRY RUN, no ticket mutation." in gateway.prompts["friction-adjudicate"] + assert "dry_run=true" in gateway.prompts["friction-adjudicate"] + assert "DRY report." in gateway.prompts["friction-report"] + assert "automation/friction-2026-08-29" in gateway.prompts["friction-report"] + assert "reports/2026-08-29-friction.md" in gateway.prompts["friction-report"] + assert "/tmp/synthesis.json" in gateway.prompts["friction-adjudicate"] + assert "@@" not in "".join(gateway.prompts.values()) + + +def test_a_live_run_names_the_live_modes() -> None: + gateway = FixtureGateway() + asyncio.run( + HandlerMorningFrictionSweep(None, gateway, public_overlay()).handle( + request({"force": True}) + ) + ) + assert "LIVE, ticket mutation authorized." in gateway.prompts["friction-adjudicate"] + assert "LIVE report." in gateway.prompts["friction-report"] + assert "FENCES: none passed for this run." in gateway.prompts["friction-scan"] + + +def test_the_report_schema_names_the_overlay_control_lanes() -> None: + gateway = FixtureGateway() + asyncio.run( + HandlerMorningFrictionSweep(None, gateway, public_overlay()).handle( + request({"force": True}) + ) + ) + report = next(c for c in gateway.calls if c["label"] == "friction-report") + schema = str(report["schema"]) + assert "control-lane-a" in schema + assert "control-lane-c" in schema + + +def test_the_node_package_holds_no_private_identity() -> None: + """The public node names no private repository, workspace, lane or path.""" + forbidden = ( + "knowledge-base-internal", + "omni_home", + "omnibase_internal", + "OMNI_HOME", + "beta/tracking", + "ROLLING_WORK_LEDGER", + "omn16831", + ) + root = Path(str(files(PACKAGE))) + offenders = [ + f"{path.relative_to(root)}: {word}" + for path in sorted(root.rglob("*")) + if path.is_file() and path.suffix in {".py", ".yaml", ".json", ".md"} + for word in forbidden + if word in path.read_text(encoding="utf-8") + ] + assert offenders == [] diff --git a/tests/nodes/node_morning_friction_sweep_orchestrator/test_phase_bus.py b/tests/nodes/node_morning_friction_sweep_orchestrator/test_phase_bus.py new file mode 100644 index 0000000000..c2cc2dc3ce --- /dev/null +++ b/tests/nodes/node_morning_friction_sweep_orchestrator/test_phase_bus.py @@ -0,0 +1,134 @@ +# SPDX-FileCopyrightText: 2026 OmniNode.ai Inc. +# SPDX-License-Identifier: MIT +"""The phase gateway rides the canonical delegation request/reply wiring.""" + +from __future__ import annotations + +import asyncio +import json +from typing import cast + +import pytest +from omnibase_core.event_bus.event_bus_inmemory import EventBusInmemory +from omnibase_core.models.delegation.wire import ModelDelegationRequest +from omnibase_core.models.events.model_event_envelope import ModelEventEnvelope +from omnibase_core.models.resolver.model_handler_resolver_context import ( + ModelHandlerResolverContext, +) +from omnibase_core.services.service_handler_resolver import ServiceHandlerResolver + +from omnimarket.nodes.node_morning_friction_sweep_orchestrator.handlers.handler_friction_phase_bus import ( + HandlerFrictionPhaseBus, +) +from omnimarket.nodes.node_morning_friction_sweep_orchestrator.handlers.handler_morning_friction_sweep import ( + OVERLAY_ENV, + HandlerMorningFrictionSweep, +) +from omnimarket.nodes.node_morning_friction_sweep_orchestrator.models import ( + ModelFrictionPhaseRequest, +) + +from .helpers import NODE, OVERLAY_FILE, request, stub_result + + +class Rpc: + def __init__(self, content: str, tenant: str = "tenant-a") -> None: + self.calls: list[dict[str, object]] = [] + self.instances: list[str] = [] + self.content = content + self.tenant = tenant + + async def send_request( + self, + instance_name: str, + payload: dict[str, object], + timeout_seconds: int | None = None, + ) -> dict[str, object]: + self.calls.append(payload) + self.instances.append(instance_name) + envelope = ModelEventEnvelope[ModelDelegationRequest].model_validate(payload) + assert envelope.payload.task_type == "agent_delegation" + assert envelope.payload.tenant_id == "tenant-a" + assert timeout_seconds == 7200 + return { + "payload": { + "correlation_id": str(envelope.correlation_id), + "tenant_id": self.tenant, + "content": self.content, + } + } + + +def _phase(label: str = "friction-scan") -> ModelFrictionPhaseRequest: + return ModelFrictionPhaseRequest( + label=label, + phase="Scan", + model="sonnet", + effort="high", + prompt="fixture", + schema_definition={"type": "object"}, + ) + + +def test_phase_gateway_uses_canonical_delegation_rpc() -> None: + rpc = Rpc(json.dumps(stub_result("friction-scan"))) + result = asyncio.run(HandlerFrictionPhaseBus(rpc=rpc).run(request(), _phase())) + assert result is not None + assert result["handoff_path"] == "/tmp/scan.json" + assert rpc.instances == ["friction_phase"] + envelope = ModelEventEnvelope[ModelDelegationRequest].model_validate(rpc.calls[0]) + assert envelope.event_type == "onex.cmd.omnibase-infra.delegation-request.v1" + assert json.loads(envelope.payload.context_pack or "{}") == { + "phase": "Scan", + "model": "sonnet", + "effort": "high", + } + + +def test_a_null_phase_result_is_returned_as_absent() -> None: + assert ( + asyncio.run(HandlerFrictionPhaseBus(rpc=Rpc("null")).run(request(), _phase())) + is None + ) + + +def test_a_reply_for_another_tenant_is_refused() -> None: + gateway = HandlerFrictionPhaseBus( + rpc=Rpc(json.dumps(stub_result("friction-scan")), tenant="tenant-b") + ) + with pytest.raises(ValueError, match="tenant does not match"): + asyncio.run(gateway.run(request(), _phase())) + + +def test_a_non_object_phase_result_is_refused() -> None: + with pytest.raises(ValueError, match="must be an object"): + asyncio.run(HandlerFrictionPhaseBus(rpc=Rpc("[1]")).run(request(), _phase())) + + +def test_a_phase_result_off_its_typed_schema_is_refused() -> None: + gateway = HandlerFrictionPhaseBus(rpc=Rpc(json.dumps({"handoff_path": 1}))) + with pytest.raises(ValueError, match="validation error"): + asyncio.run(gateway.run(request(), _phase())) + + +def test_a_run_without_the_runtime_bus_is_refused() -> None: + with pytest.raises(ValueError, match="runtime event_bus"): + asyncio.run(HandlerFrictionPhaseBus().run(request(), _phase())) + + +def test_kernel_injects_the_bus(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv(OVERLAY_ENV, str(OVERLAY_FILE)) + bus = EventBusInmemory(environment="dev", group="friction-proof") + context = ModelHandlerResolverContext( + handler_cls=HandlerMorningFrictionSweep, + handler_module=HandlerMorningFrictionSweep.__module__, + handler_name="HandlerMorningFrictionSweep", + contract_name=NODE, + node_name=NODE, + event_bus=bus, + ) + resolution = ServiceHandlerResolver().resolve(context) + assert isinstance(resolution.handler_instance, HandlerMorningFrictionSweep) + gateway = resolution.handler_instance.gateway + assert isinstance(gateway, HandlerFrictionPhaseBus) + assert cast(object, gateway._event_bus) is bus diff --git a/tests/test_market_node_runtime_dogfood.py b/tests/test_market_node_runtime_dogfood.py index 244fc885f3..7a23a2104b 100644 --- a/tests/test_market_node_runtime_dogfood.py +++ b/tests/test_market_node_runtime_dogfood.py @@ -86,6 +86,11 @@ # overlay, so it has no onex.nodes entry point until the registration # hand-over (nodes-to-market plan step B). "node_morning_ground_state_orchestrator", + # OMN-20674: hosted from the operator tooling repository, whose copy is + # still registered; its briefs, paths and lanes arrive through a deployment + # overlay, so it has no onex.nodes entry point until the registration + # hand-over (nodes-to-market plan step B). + "node_morning_friction_sweep_orchestrator", # OMN-19970: the dev seed runs from `onex seed` against the store or broker # it names; it publishes fixture terminals but subscribes to no topic and # has no onex.nodes entry point.