Cross-Node-Type Validation (fault injection): the Conformance Suite's fail-safe-behavior mechanism
engine/conformance.py injects faults into a Node Type's connector and transformation slots and checks its fail-safe handling.
The Conformance Suite has three testable properties:
| Property | How it is checked |
|---|---|
| Schema conformance | Mechanically, by validate_node_type_definition. |
| Idempotent event handling | Mechanically, by TriggerQueue.enqueue's ON CONFLICT DO NOTHING. |
| Fail-safe behavior | Here, in a node-type-agnostic way. |
A Node Type's System Connector and Data Transformation Layer are both swappable registry entries. This module plugs a fault-injecting mock in their place and asserts that the Node Type's own Try/Catch, Activity Log and Mandatory-Human Status handling responds correctly.
run_fault_tolerant_ingestion (below) composes already-pluggable pieces: log_try_catch_task from engine/task_activity_log.py. This is the same composition that dispatch_claimed_entry in engine/trigger_queue.py uses (see trigger-dispatch-queue.md). The generalized conformance suite for third-party-contributed Node Types (see node-type-conformance-suite.md) reuses this exact mechanism rather than inventing a second one.
The five canonical faults
- Target system unreachable. The unresponsive-service, retry-then-give-up path.
- Malformed or incomplete raw data. It is flagged rather than silently guessed at.
- No matching transformation rule. It routes to the mandatory
GENERIC_TRANSFORMfallback. - Retry exhaustion. A terminal, logged, safe state, never a partial or inconsistent write.
- A
PeerListenerbound to a non-private address. This doesn't fit the module's fetch/ingest shape, because it isn't a System Connector or Data Transformation Layer fault. It is checked directly at construction time instead:PeerListenerinengine/communication_interface.py, covered bytests/test_communication_interface.pyrather than throughrun_fault_tolerant_ingestion.
How the faults relate to Try/Catch:
- Try/Catch's module docstring treats (1) and (4) as the same underlying mechanism. Exhausting the unresponsive-service retry budget is fault (4)'s terminal state.
- (3) never touches Try/Catch's failure vocabulary at all. An unregistered
source_typeis handled entirely insideTransformationRegistry.transform, with no exception involved.
1. Swap the System Connector slot: FaultInjectingConnector
from engine.conformance import FaultInjectingConnector
from engine.opcua_sidecar import SidecarError
def _always_unreachable():
raise SidecarError("sidecar unreachable")
connector = FaultInjectingConnector(poll_fn=_always_unreachable)
FaultInjectingConnector is a real SystemConnector. It implements test_connection() in the same fail-safe-and-report way every connector type must. Its poll() runs whatever poll_fn a test supplies:
| To simulate | Have poll_fn |
|---|---|
| Fault (1) or (4) | Raise. |
| Fault (2) | Return a well-formed but incomplete dict. |
| Fault (3) | Return valid data. The Data Transformation Layer is the thing under test, not the connector. |
2. Run it through run_fault_tolerant_ingestion
from engine.conformance import run_fault_tolerant_ingestion
from engine.task_activity_log import TaskRunContext
from engine.try_catch import RetryPolicy
context = TaskRunContext(
node_type="MES",
node_instance_id="mes-line-3",
trigger="order_release",
task_type="conformance-ingestion",
)
result = run_fault_tolerant_ingestion(
activity_log,
context,
fetch=connector.poll, # the System Connector slot
ingest=lambda raw: ingestion.ingest( # the Data Transformation Layer + identity-resolution slot
"mes-opcua", raw, trigger_type="order_release", trigger_id=uuid.uuid4()
),
retry=RetryPolicy(max_attempts=3),
)
What happens to a failing fetch
fetch's transport-level exceptions translate to UnresponsiveServiceFailure, Try/Catch's unresponsive-service vocabulary. DEFAULT_UNRESPONSIVE_EXCEPTIONS defaults to (httpx.HTTPError, SidecarError), the two that Kindred's built connector types actually raise.
Exhausting the retry budget lands on Outcome.GAVE_UP. ingest never runs when fetch never produces a record for it to run against, so nothing it would have written (an envelope, an identity record, a Trigger) exists either. That is the "never a partial/inconsistent write" that fault (4) calls for, for free.
Other exception types
A connector type that raises something other than httpx.HTTPError or SidecarError doesn't need an edit to this module. Pass its own exception type through unresponsive_exceptions:
run_fault_tolerant_ingestion(..., unresponsive_exceptions=(MyDbConnector.TransportError,))
Any other exception ingest raises is a genuine bug, not part of this fault list's vocabulary (the same stance engine/try_catch.py takes). It still gets one terminal, logged ActivityLogEntry before propagating.
3. Flag malformed or incomplete data: event_schema
Fault (2) is handled one layer down, in ingest_and_enqueue in engine/ingestion_pipeline.py (threaded through MesIngestion.ingest and ErpIngestion.ingest), not in conformance.py itself. Passing event_schema is what a Node Type's ingest() call opts into:
(order_release,) = [e for e in mes_node_type.event_types if e.name == "OrderRelease"]
ingestion.ingest(
"mes-opcua",
raw,
trigger_type="order_release",
trigger_id=uuid.uuid4(),
event_schema=order_release.fields, # engine/node_type.py's EventTypeDefinition.fields
)
What flagging does
If the resulting canonical event fails event_schema, the envelope's top-level status is overridden to FLAGGED_STATUS (engine/envelope.py). event_fields keeps whatever the transform actually produced, unchanged.
This split matters. Flagging is an administrative signal about the event as a whole, not a correction to its domain data. A canonical event that fails validation only because, say, order_id is missing must not also erase a real status value like "blocked" that happened to ride along in the same record.
Identity resolution and enqueue still run normally on a flagged event. A missing identity field already routes through the inferred, Mandatory-Human-Pending branch. That is exactly the fail-safe backstop malformed data needs, not a second, separately invented one.
Schema validity
event_schema is trusted to already be a valid JSON Schema. validate_node_type_definition (engine/node_type.py) runs check_schema on every declared event type's fields fragment at Node Type Agreement registration time, the same check it runs on config_schema. A broken schema fragment therefore fails closed there, rather than crashing ingestion the first time a real record hits it.
4. No matching rule: nothing to inject
Fault (3) needs no fault-injecting connector or schema at all. It needs just an unregistered source_type against a Node Type's real, already configured TransformationRegistry:
run_fault_tolerant_ingestion(
activity_log,
context,
fetch=lambda: raw_record,
ingest=lambda raw: ingestion.ingest(
"never-registered", raw, trigger_type="order_release", trigger_id=uuid.uuid4()
),
)
# result.outcome == Outcome.SUCCEEDED, result.attempts == 1 - GENERIC_TRANSFORM passed it through
PLC/Generic Device: Try/Catch + Activity Log, no Mandatory-Human Status
PLC/Generic Device has no identity-resolution or Trigger-enqueue pipeline of its own (its tests cover classification only). Its ingest closure is just lambda raw: registry.transform(source_type, raw), with no *Ingestion object behind it.
run_fault_tolerant_ingestion still gives it real Try/Catch and Activity Log coverage over its connector and transform slots. Fault (2) for this Node Type is checked by validating the transform's own output against its declared schema directly (jsonschema.validate). There is no envelope to carry a flagged status, so a schema mismatch is itself the signal a downstream caller detects.
Pitfalls
event_schemais opt-in peringest()call, not automatic. Omitting it skips the malformed-data check entirely. A Node Type gets fault (2) coverage only where it passes its own schema in.- Don't overwrite
event_fields's status when flagging.envelope.statusandevent_fields["status"]look like the same field but serve different purposes. The top-level status isingest_and_enqueue's administrative signal, andevent_fieldsis the transform's real output. Computing a flagged status separately, rather than mutatingcanonicalin place, is what keeps a genuine domain value from being silently destroyed by an unrelated field's failure. - The compiled JSON Schema validator is cached per distinct schema (
_compiled_validator, keyed by a sorted-keys JSON serialization). Passing a schema that is structurally identical but a different dict object still hits the cache. Passing genuinely different schemas grows it, bounded at 256 entries. run_fault_tolerant_ingestionnever callsqueue.mark_doneormark_dead_lettered. Unlikedispatch_claimed_entry, notrigger_queuerow is involved. This function is a conformance-test and direct-call harness, not the production dispatch path. That path isrun_trigger_dispatch_loopinengine/node_runtime.py(seenode-runtime.md).
Release: v0.11.0