{
  "name": "LAB 10 - Trade Fair Lead Processing - Inspectable",
  "nodes": [
    {
      "parameters": {
        "content": "# LAB 10: Messekontakt sauber nachbereiten\n\n**Buyer:** Vertriebsleitung / Sales Operations\n\n**Problem:** Badge, Visitenkarte und Gespr\u00e4chsnotizen m\u00fcssen nach der Messe konsolidiert, erg\u00e4nzt und ins CRM vorbereitet werden. Consent und Dubletten sind oft unklar.\n\n**Result:** Ein strukturierter CRM-Entwurf mit fehlenden Angaben, Dublettenhinweis und freizugebendem Follow-up.\n\nInput \u2192 contract \u2192 idempotency \u2192 context \u2192 deterministic rules \u2192 exception \u2192 human decision \u2192 draft.",
        "width": 840,
        "height": 300,
        "color": 2
      },
      "id": "e6edf058-e7ed-41eb-a8ed-f37ee9edf511",
      "name": "Note 01 - Business Flow",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1240,
        -720
      ]
    },
    {
      "parameters": {
        "content": "# Contract and evidence\n\n- Six synthetic cases: happy, review, stop, duplicate, dependency failure and invalid payload.\n- Source references stay attached to findings.\n- Missing critical facts are never inferred.\n- Correlation and idempotency keys are created before any adapter boundary.",
        "width": 840,
        "height": 300,
        "color": 4
      },
      "id": "98055139-9705-4fa6-a605-4e1395054c80",
      "name": "Note 02 - Contract & Evidence",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -300,
        -720
      ]
    },
    {
      "parameters": {
        "content": "# Reliability controls\n\n- Atomic claim is represented by a deterministic test double.\n- Duplicate delivery returns the previous outcome.\n- Only transient failures enter a bounded retry envelope.\n- Retry budget: 3 attempts; no unbounded loop.\n- Invalid data enters a redacted repair queue.",
        "width": 840,
        "height": 300,
        "color": 3
      },
      "id": "85f28ef1-84f2-4d5e-a3f2-8bcb82f28a38",
      "name": "Note 03 - Reliability Controls",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        660,
        -720
      ]
    },
    {
      "parameters": {
        "content": "# Domain guardrails\n\nContext: CRM Dubletten- und Consent-Pr\u00fcfung (mocked adapter).\n\nThe workflow classifies each case as review-ready, review-required or stopped. Domain rules\u2014not an LLM prompt\u2014own the stop decision.",
        "width": 840,
        "height": 300,
        "color": 5
      },
      "id": "a8376dbb-a737-4c28-aa37-70e1a9376f4e",
      "name": "Note 04 - Domain Guardrails",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1640,
        -720
      ]
    },
    {
      "parameters": {
        "content": "# Human-controlled decision\n\nOwner: Sales Operations.\n\nApprove, reject or request information. The approval is version-bound. The external adapter is visible but disabled; every test run reports zero external writes.",
        "width": 840,
        "height": 300,
        "color": 6
      },
      "id": "75ab03b8-76ab-454b-a7ab-06de78ab0871",
      "name": "Note 05 - Human Boundary",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2640,
        -720
      ]
    },
    {
      "parameters": {
        "content": "# Test matrix\n\n1. Nominal input reaches review-ready.\n2. Recoverable deviation explains its evidence.\n3. Critical ambiguity stops.\n4. Replay is idempotent.\n5. Dependency outage schedules bounded retry.\n6. Invalid contract is redacted and quarantined.\n\nStatus: Synthetic Demo \u00b7 Built and testable \u00b7 not customer validated.",
        "width": 900,
        "height": 340,
        "color": 7
      },
      "id": "127eb200-137e-4393-a47e-b526157eb6b9",
      "name": "Note 06 - Test Matrix",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        3640,
        -720
      ]
    },
    {
      "parameters": {},
      "id": "84d4a084-85d4-4217-a6d4-a3aa87d4a53d",
      "name": "Manual Test Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1240,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const fixtures = [{\"id\":\"qualified-lead\",\"label\":\"Kontakt vollst\u00e4ndig\",\"kind\":\"happy\",\"input\":{\"eventId\":\"LEAD-DEMO-10001\",\"badge\":{\"company\":\"Muster Automation GmbH\",\"name\":\"Lena Beispiel\",\"role\":\"Leitung Produktion\",\"email\":\"lena.beispiel@example.invalid\"},\"notes\":\"Interesse an Service-Triage f\u00fcr drei Werke. R\u00fcckruf in KW 35 vereinbart.\",\"interest\":\"Machine Service Triage\",\"consent\":{\"followUp\":true,\"source\":\"Gespr\u00e4chsnotiz\"},\"existingContact\":false}},{\"id\":\"possible-duplicate\",\"label\":\"M\u00f6gliche Dublette\",\"kind\":\"edge\",\"input\":{\"eventId\":\"LEAD-DEMO-10002\",\"badge\":{\"company\":\"DemoForm AG\",\"name\":\"Kai Muster\",\"role\":\"Service Operations\",\"email\":\"kai.muster@example.invalid\"},\"notes\":\"Ersatzteilprozess besprochen.\",\"interest\":\"Spare Parts Inquiry\",\"consent\":{\"followUp\":true,\"source\":\"Badge-Scan\"},\"existingContact\":{\"id\":\"CRM-4481\",\"similarity\":0.91}}},{\"id\":\"no-consent\",\"label\":\"Follow-up unklar\",\"kind\":\"error\",\"input\":{\"eventId\":\"LEAD-DEMO-10003\",\"badge\":{\"company\":\"Fiktiv Maschinenbau KG\",\"name\":\"Robin Test\",\"role\":null,\"email\":\"robin.test@example.invalid\"},\"notes\":\"Kurzes Gespr\u00e4ch am Stand.\",\"interest\":null,\"consent\":{\"followUp\":null,\"source\":null},\"existingContact\":false}},{\"id\":\"qualified-lead-replay\",\"label\":\"Doppelte Zustellung\",\"kind\":\"duplicate\",\"input\":{\"eventId\":\"LEAD-DEMO-10001\",\"badge\":{\"company\":\"Muster Automation GmbH\",\"name\":\"Lena Beispiel\",\"role\":\"Leitung Produktion\",\"email\":\"lena.beispiel@example.invalid\"},\"notes\":\"Interesse an Service-Triage f\u00fcr drei Werke. R\u00fcckruf in KW 35 vereinbart.\",\"interest\":\"Machine Service Triage\",\"consent\":{\"followUp\":true,\"source\":\"Gespr\u00e4chsnotiz\"},\"existingContact\":false}},{\"id\":\"qualified-lead-dependency\",\"label\":\"Tempor\u00e4rer Adapterfehler\",\"kind\":\"dependency\",\"input\":{\"eventId\":\"LEAD-DEMO-10001-DEP\",\"badge\":{\"company\":\"Muster Automation GmbH\",\"name\":\"Lena Beispiel\",\"role\":\"Leitung Produktion\",\"email\":\"lena.beispiel@example.invalid\"},\"notes\":\"Interesse an Service-Triage f\u00fcr drei Werke. R\u00fcckruf in KW 35 vereinbart.\",\"interest\":\"Machine Service Triage\",\"consent\":{\"followUp\":true,\"source\":\"Gespr\u00e4chsnotiz\"},\"existingContact\":false,\"adapterAvailable\":false,\"retryAttempt\":1}},{\"id\":\"qualified-lead-invalid\",\"label\":\"Ung\u00fcltiger Eingangsvertrag\",\"kind\":\"invalid\",\"input\":{\"eventId\":null,\"badge\":{\"company\":\"Muster Automation GmbH\",\"name\":\"Lena Beispiel\",\"role\":\"Leitung Produktion\",\"email\":\"lena.beispiel@example.invalid\"},\"notes\":\"Interesse an Service-Triage f\u00fcr drei Werke. R\u00fcckruf in KW 35 vereinbart.\",\"interest\":\"Machine Service Triage\",\"consent\":{\"followUp\":true,\"source\":\"Gespr\u00e4chsnotiz\"},\"existingContact\":false}}];\nreturn fixtures.map((fixture) => ({ json: { workflowId: 'trade-fair-lead', evidenceType: 'Synthetic Demo', ...fixture } }));"
      },
      "id": "f0c34559-efc3-43c6-aec3-4233edc340a0",
      "name": "Load 6 Synthetic Test Cases",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1020,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item, index) => ({ json: {\n  workflowId: item.json.workflowId,\n  workflowTitle: \"Trade Fair Lead Processing\",\n  implementationStatus: 'Built and testable',\n  adapterStatus: 'Mocked adapter',\n  evidenceType: item.json.evidenceType,\n  scenario: item.json.id,\n  scenarioLabel: item.json.label,\n  fixtureKind: item.json.kind,\n  sourceType: \"Badge + Visitenkarte + Gespr\u00e4chsnotiz\",\n  sourceInput: item.json.input,\n  correlationId: item.json.input?.eventId ?? `INVALID-LEAD-${String(index + 1).padStart(2, '0')}`,\n  idempotencyKey: item.json.input?.eventId ?? null,\n  retry: { attempt: Number(item.json.input?.retryAttempt ?? 0), maxAttempts: 3, policy: 'transient_only' },\n  adapter: { name: \"CRM Dubletten- und Consent-Pr\u00fcfung\", mode: 'mock', available: item.json.kind !== 'dependency', writesPerformed: 0 },\n  processing: [],\n  audit: [{ state: 'INPUT_RECEIVED', detail: item.json.id, at: '2026-08-13T12:00:00.000Z' }]\n} }));"
      },
      "id": "29384bef-2838-4a5c-ab38-4f152a384d82",
      "name": "Normalize Intake Envelope",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -800,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => {\n  const missing = [];\n  if (!item.json.sourceInput || typeof item.json.sourceInput !== 'object') missing.push('sourceInput');\n  if (!item.json.sourceInput?.eventId) missing.push('eventId');\n  return { json: { ...item.json, validation: { valid: missing.length === 0, missing, schema: 'LEAD_INTAKE_V1' }, audit: [...item.json.audit, { state: 'CONTRACT_VALIDATED', detail: missing.length ? missing.join(',') : 'valid', at: '2026-08-13T12:00:10.000Z' }] } };\n});"
      },
      "id": "c2f2c362-c3f2-44f5-a0f2-c03cc1f2c1cf",
      "name": "Validate Required Contract",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -580,
        0
      ]
    },
    {
      "parameters": {
        "mode": "expression",
        "numberOutputs": 2,
        "output": "={{ $json.validation.valid ? 0 : 1 }}"
      },
      "id": "7af4e98e-7bf4-4b21-a8f4-e66879f4e7fb",
      "name": "Route Contract Status",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        -360,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, status: 'INVALID_INPUT', errorClass: 'business_validation', retryable: false, exceptions: [{ code: 'INVALID_CONTRACT', severity: 'stop', message: `Missing: ${item.json.validation.missing.join(', ')}` }], externalWritePerformed: false } }));"
      },
      "id": "5913e89c-5a13-4a2f-ab13-ebc25c13ed55",
      "name": "Classify Validation Error",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -100,
        500
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, sourceInput: { redacted: true, sourceType: item.json.sourceType }, redaction: { applied: true, retained: ['correlationId', 'scenario', 'errorClass'] } } }));"
      },
      "id": "861b23a3-851b-4210-a81b-26c9871b2536",
      "name": "Redact Invalid Payload",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        140,
        500
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, audit: [...item.json.audit, { state: 'MANUAL_DATA_REPAIR', detail: 'invalid_contract', at: '2026-08-13T12:00:20.000Z' }] } }));"
      },
      "id": "10d0b075-0fd0-4ee2-aed0-ad4f0dd0abbc",
      "name": "Audit Validation Failure",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        380,
        500
      ]
    },
    {
      "parameters": {},
      "id": "4112e60e-4212-47a1-af12-e2e84012e47b",
      "name": "Terminal - Manual Data Repair",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        620,
        500
      ]
    },
    {
      "parameters": {
        "jsCode": "const claimed = new Set();\nreturn items.map((item) => {\n  const key = item.json.idempotencyKey;\n  const duplicate = item.json.fixtureKind === 'duplicate' || claimed.has(key);\n  if (!duplicate) claimed.add(key);\n  return { json: { ...item.json, idempotency: { key, claimed: !duplicate, duplicate, store: 'atomic_test_double' }, audit: [...item.json.audit, { state: duplicate ? 'DUPLICATE_DETECTED' : 'IDEMPOTENCY_CLAIMED', detail: key, at: '2026-08-13T12:00:30.000Z' }] } };\n});"
      },
      "id": "d49ee8b6-d59e-4a49-a29e-e590d39ee723",
      "name": "Claim Idempotency Key [MOCK]",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -100,
        0
      ]
    },
    {
      "parameters": {
        "mode": "expression",
        "numberOutputs": 2,
        "output": "={{ $json.idempotency.duplicate ? 1 : 0 }}"
      },
      "id": "f7c92f63-f6c9-4dd0-a9c9-3289f8c930f6",
      "name": "Route Replay Status",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        140,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, status: 'DUPLICATE_REPLAY', previousOutcome: { status: 'READY_FOR_REVIEW', reference: item.json.idempotencyKey }, externalWritePerformed: false } }));"
      },
      "id": "4497ed9c-4597-4f2f-a697-f0c24797f255",
      "name": "Load Previous Outcome [MOCK]",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        380,
        280
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, audit: [...item.json.audit, { state: 'REPLAY_SAFE_RETURN', detail: 'no_second_processing', at: '2026-08-13T12:00:40.000Z' }] } }));"
      },
      "id": "6dd2ed67-6cd2-4bd4-afd2-f08d6ed2eefa",
      "name": "Audit Duplicate Delivery",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        620,
        280
      ]
    },
    {
      "parameters": {},
      "id": "e3978b14-e497-4ca7-a597-8e3ae6978fcd",
      "name": "Terminal - Replay Safe",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        860,
        280
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, contextLookup: { source: \"CRM Dubletten- und Consent-Pr\u00fcfung\", status: item.json.adapter.available ? 'available' : 'unavailable', synthetic: true }, audit: [...item.json.audit, { state: 'CONTEXT_LOOKUP', detail: item.json.adapter.available ? 'ok' : '503_test_double', at: '2026-08-13T12:00:50.000Z' }] } }));"
      },
      "id": "1462ca73-1362-48e0-a662-cd991562cc06",
      "name": "Load CRM Dubletten- und Consent-Pr\u00fcfung [MOCK]",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        380,
        0
      ]
    },
    {
      "parameters": {
        "mode": "expression",
        "numberOutputs": 2,
        "output": "={{ $json.adapter.available ? 0 : 1 }}"
      },
      "id": "5e426811-5d42-467e-ac42-64eb5b426358",
      "name": "Route Dependency Health",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        620,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, status: 'DEPENDENCY_UNAVAILABLE', errorClass: 'external_transient', retryable: true, retry: { ...item.json.retry, attempt: item.json.retry.attempt || 1 }, externalWritePerformed: false } }));"
      },
      "id": "7f127690-8012-4823-a112-79b682127b49",
      "name": "Classify Transient Dependency Failure",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        860,
        500
      ]
    },
    {
      "parameters": {
        "mode": "expression",
        "numberOutputs": 2,
        "output": "={{ $json.retry.retryable === false || $json.retry.attempt >= $json.retry.maxAttempts ? 1 : 0 }}"
      },
      "id": "d55519e6-d655-4b79-a355-16c0d4551853",
      "name": "Route Retry Budget",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        1100,
        500
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, retry: { ...item.json.retry, nextAttempt: item.json.retry.attempt + 1, backoffSeconds: Math.min(60, 2 ** item.json.retry.attempt) + 1, jitterPolicy: 'deterministic_test_value' } } }));"
      },
      "id": "5cfbff70-5dfc-4103-aefc-02965ffc0429",
      "name": "Plan Backoff + Jitter",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1340,
        420
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, retryEnvelope: { correlationId: item.json.correlationId, idempotencyKey: item.json.idempotencyKey, nextAttempt: item.json.retry.nextAttempt, payloadRedacted: true }, audit: [...item.json.audit, { state: 'RETRY_SCHEDULED', detail: `attempt_${item.json.retry.nextAttempt}`, at: '2026-08-13T12:01:00.000Z' }] } }));"
      },
      "id": "a778f7bd-a678-462a-a578-f497a478f304",
      "name": "Persist Retry Envelope [MOCK]",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1580,
        420
      ]
    },
    {
      "parameters": {},
      "id": "ab9de78f-aa9d-45fc-ad9d-eab5ac9de922",
      "name": "Terminal - Bounded Retry Queue",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1820,
        420
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, status: 'TERMINAL_DEPENDENCY_FAILURE', incident: { severity: 'high', correlationId: item.json.correlationId, errorClass: item.json.errorClass, payloadIncluded: false }, externalWritePerformed: false } }));"
      },
      "id": "d5f0f49a-d6f0-462d-a3f0-f174d4f0f307",
      "name": "Build Redacted Technical Incident",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1340,
        620
      ]
    },
    {
      "parameters": {},
      "id": "34a59f2b-33a5-4d98-a6a5-a25135a5a0be",
      "name": "Terminal - Operator Action",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1580,
        620
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, processing: [...(item.json.processing ?? []), { order: 1, step: \"Badge und Notizen konsolidieren\", status: 'completed', sourceBound: true }], audit: [...item.json.audit, { state: 'DOMAIN_STAGE_1', detail: \"Badge und Notizen konsolidieren\", at: '2026-08-13T12:00:00.000Z' }] } }));"
      },
      "id": "08f4e726-09f4-48b9-a6f4-e40007f4e593",
      "name": "Badge und Notizen konsolidieren",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        860,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, processing: [...(item.json.processing ?? []), { order: 2, step: \"Firma und Kontakt normalisieren\", status: 'completed', sourceBound: true }], audit: [...item.json.audit, { state: 'DOMAIN_STAGE_2', detail: \"Firma und Kontakt normalisieren\", at: '2026-08-13T12:01:00.000Z' }] } }));"
      },
      "id": "65d10c57-64d1-4ac4-a7d1-0f7d66d10dea",
      "name": "Firma und Kontakt normalisieren",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1100,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, processing: [...(item.json.processing ?? []), { order: 3, step: \"CRM-Dublette suchen [MOCK]\", status: 'completed', sourceBound: true }], audit: [...item.json.audit, { state: 'DOMAIN_STAGE_3', detail: \"CRM-Dublette suchen [MOCK]\", at: '2026-08-13T12:02:00.000Z' }] } }));"
      },
      "id": "6f2feee8-702f-407b-a12f-f20e722ff3a1",
      "name": "CRM-Dublette suchen [MOCK]",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1340,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, processing: [...(item.json.processing ?? []), { order: 4, step: \"Consent und Follow-up-Eignung pr\u00fcfen\", status: 'completed', sourceBound: true }], audit: [...item.json.audit, { state: 'DOMAIN_STAGE_4', detail: \"Consent und Follow-up-Eignung pr\u00fcfen\", at: '2026-08-13T12:03:00.000Z' }] } }));"
      },
      "id": "554c7191-544c-4ffe-a34c-6e6b524c6cd8",
      "name": "Consent und Follow-up-Eignung pr\u00fcfen",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1580,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => {\n  const input = item.json.sourceInput ?? {};\n  const issues = [];\n  const signals = [];\n  const issue = (code, severity, message, evidence = []) => ({ code, severity, message, evidence });\n  \nif (input.consent?.followUp !== true) issues.push(issue('FOLLOW_UP_CONSENT_UNCLEAR', 'stop', 'Ohne dokumentierte Kontaktfreigabe wird kein Follow-up vorbereitet.'));\nif (input.existingContact) issues.push(issue('POSSIBLE_DUPLICATE', 'review', 'M\u00f6gliche CRM-Dublette muss zusammengef\u00fchrt oder verworfen werden.', [input.existingContact.id]));\nif (!input.interest || !input.badge?.role) issues.push(issue('QUALIFICATION_INCOMPLETE', 'review', 'Interesse oder Rolle fehlt.'));\n  const status = issues.some((entry) => entry.severity === 'stop')\n    ? 'STOPPED_FOR_REVIEW'\n    : issues.some((entry) => entry.severity === 'review')\n      ? 'REVIEW_REQUIRED'\n      : 'READY_FOR_REVIEW';\n  return { json: {\n    ...item.json,\n    decision: { status, derivedBy: 'deterministic_guardrails', humanRequired: true },\n    exceptions: issues,\n    signals,\n    audit: [...item.json.audit, { state: 'GUARDRAILS_EVALUATED', detail: status, at: '2026-08-13T12:05:00.000Z' }]\n  } };\n});"
      },
      "id": "06655ec6-0765-4059-a465-5ba005655d33",
      "name": "Evaluate Deterministic Guardrails",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1820,
        0
      ]
    },
    {
      "parameters": {
        "mode": "expression",
        "numberOutputs": 3,
        "output": "={{ ({ READY_FOR_REVIEW: 0, REVIEW_REQUIRED: 1, STOPPED_FOR_REVIEW: 2 })[$json.decision.status] ?? 2 }}"
      },
      "id": "c7031fee-c803-4181-a503-1cc8c6031e5b",
      "name": "Route Business Outcome",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        2060,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, route: 'ready', reviewMessage: 'Pr\u00fcfung vollst\u00e4ndig; fachliche Freigabe bleibt erforderlich.' } }));"
      },
      "id": "500bb297-4f0b-4104-a20b-b5bd510bb42a",
      "name": "Prepare Review-Ready Candidate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2300,
        -180
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, route: 'review', reviewMessage: 'Abweichung mit Quelle und empfohlener R\u00fcckfrage vorbereitet.' } }));"
      },
      "id": "ffae4409-feae-4276-adae-40e3fcae3f50",
      "name": "Explain Review Exceptions",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2300,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, route: 'stopped', reviewMessage: 'Kritischer Stop: keine automatische Fortsetzung.' } }));"
      },
      "id": "baac6a00-bbac-4b93-acac-6d26bdac6eb9",
      "name": "Quarantine Critical Case",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2300,
        180
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, humanDecision: { state: 'pending', owner: \"Sales Operations\", allowed: ['approve', 'reject', 'request_information'], approvalVersion: `${item.json.correlationId}:v1` }, externalWritePerformed: false, audit: [...item.json.audit, { state: 'HUMAN_REVIEW_PENDING', detail: item.json.decision.status, at: '2026-08-13T12:06:00.000Z' }] } }));"
      },
      "id": "ef938a95-ee93-4902-ad93-876fec9385dc",
      "name": "Human Decision Required",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2560,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, preparedOutput: { target: \"CRM Lead Draft\", mode: 'draft_only', sourceEvent: item.json.correlationId, status: item.json.decision.status, exceptionCodes: item.json.exceptions.map((entry) => entry.code), approvalVersion: item.json.humanDecision.approvalVersion }, adapter: { ...item.json.adapter, writesPerformed: 0 } } }));"
      },
      "id": "8cfa6de7-8bfa-4c54-aefa-710d8dfa6f7a",
      "name": "Build CRM Lead Draft Draft",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2800,
        0
      ]
    },
    {
      "parameters": {
        "mode": "expression",
        "numberOutputs": 3,
        "output": "={{ ({ pending: 0, approved: 1, rejected: 2 })[$json.humanDecision.state] ?? 0 }}"
      },
      "id": "bea679e5-bda6-4852-aca6-76bfbba6752c",
      "name": "Route Human Decision",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        3040,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, terminalState: 'PENDING_HUMAN_REVIEW', queue: { owner: item.json.humanDecision.owner, synthetic: true }, externalWritePerformed: false } }));"
      },
      "id": "4be47341-4ae4-41ae-a9e4-701b48e46e88",
      "name": "Queue for Owner Review [MOCK]",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3280,
        -160
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://example.invalid/test-adapter",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "={{ $json.idempotencyKey }}"
            }
          ]
        },
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "application/json",
        "body": "={{ JSON.stringify($json.preparedOutput) }}",
        "options": {
          "timeout": 5000
        }
      },
      "id": "51eb4fc2-52eb-4155-afeb-4c9c50eb4e2f",
      "name": "[DISABLED] CRM Lead Draft Test Adapter",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        3280,
        0
      ],
      "disabled": true,
      "onError": "stopWorkflow",
      "notes": "Intentionally disabled. Assign a test credential and test endpoint only in a future approved integration goal."
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, terminalState: 'REJECTED_BY_HUMAN', preparedOutput: null, externalWritePerformed: false } }));"
      },
      "id": "3024d266-3124-43f9-ae24-cf402f24d0d3",
      "name": "Close Rejected Draft",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3280,
        160
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, externalWritePerformed: false, adapter: { ...item.json.adapter, writesPerformed: 0 }, audit: [...item.json.audit, { state: item.json.terminalState ?? 'ADAPTER_DRY_RUN', detail: 'zero_external_writes', at: '2026-08-13T12:07:00.000Z' }] } }));"
      },
      "id": "7cff5f3a-7dff-40cd-aaff-5c147bff5da7",
      "name": "Append Final Audit Event [MOCK]",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3540,
        0
      ]
    },
    {
      "parameters": {},
      "id": "7eb7f57f-7db7-43ec-a0b7-f8a57fb7f712",
      "name": "Terminal - Inspectable Review Package",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        3800,
        0
      ]
    }
  ],
  "connections": {
    "Manual Test Start": {
      "main": [
        [
          {
            "node": "Load 6 Synthetic Test Cases",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load 6 Synthetic Test Cases": {
      "main": [
        [
          {
            "node": "Normalize Intake Envelope",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Intake Envelope": {
      "main": [
        [
          {
            "node": "Validate Required Contract",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Required Contract": {
      "main": [
        [
          {
            "node": "Route Contract Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Contract Status": {
      "main": [
        [
          {
            "node": "Claim Idempotency Key [MOCK]",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Classify Validation Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify Validation Error": {
      "main": [
        [
          {
            "node": "Redact Invalid Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Redact Invalid Payload": {
      "main": [
        [
          {
            "node": "Audit Validation Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Audit Validation Failure": {
      "main": [
        [
          {
            "node": "Terminal - Manual Data Repair",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claim Idempotency Key [MOCK]": {
      "main": [
        [
          {
            "node": "Route Replay Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Replay Status": {
      "main": [
        [
          {
            "node": "Load CRM Dubletten- und Consent-Pr\u00fcfung [MOCK]",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Load Previous Outcome [MOCK]",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load Previous Outcome [MOCK]": {
      "main": [
        [
          {
            "node": "Audit Duplicate Delivery",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Audit Duplicate Delivery": {
      "main": [
        [
          {
            "node": "Terminal - Replay Safe",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load CRM Dubletten- und Consent-Pr\u00fcfung [MOCK]": {
      "main": [
        [
          {
            "node": "Route Dependency Health",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Dependency Health": {
      "main": [
        [
          {
            "node": "Badge und Notizen konsolidieren",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Classify Transient Dependency Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify Transient Dependency Failure": {
      "main": [
        [
          {
            "node": "Route Retry Budget",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Retry Budget": {
      "main": [
        [
          {
            "node": "Plan Backoff + Jitter",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Build Redacted Technical Incident",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Plan Backoff + Jitter": {
      "main": [
        [
          {
            "node": "Persist Retry Envelope [MOCK]",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Persist Retry Envelope [MOCK]": {
      "main": [
        [
          {
            "node": "Terminal - Bounded Retry Queue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Redacted Technical Incident": {
      "main": [
        [
          {
            "node": "Terminal - Operator Action",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Badge und Notizen konsolidieren": {
      "main": [
        [
          {
            "node": "Firma und Kontakt normalisieren",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Firma und Kontakt normalisieren": {
      "main": [
        [
          {
            "node": "CRM-Dublette suchen [MOCK]",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM-Dublette suchen [MOCK]": {
      "main": [
        [
          {
            "node": "Consent und Follow-up-Eignung pr\u00fcfen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Consent und Follow-up-Eignung pr\u00fcfen": {
      "main": [
        [
          {
            "node": "Evaluate Deterministic Guardrails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Evaluate Deterministic Guardrails": {
      "main": [
        [
          {
            "node": "Route Business Outcome",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Business Outcome": {
      "main": [
        [
          {
            "node": "Prepare Review-Ready Candidate",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Explain Review Exceptions",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Quarantine Critical Case",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Review-Ready Candidate": {
      "main": [
        [
          {
            "node": "Human Decision Required",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Explain Review Exceptions": {
      "main": [
        [
          {
            "node": "Human Decision Required",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Quarantine Critical Case": {
      "main": [
        [
          {
            "node": "Human Decision Required",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Human Decision Required": {
      "main": [
        [
          {
            "node": "Build CRM Lead Draft Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build CRM Lead Draft Draft": {
      "main": [
        [
          {
            "node": "Route Human Decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Human Decision": {
      "main": [
        [
          {
            "node": "Queue for Owner Review [MOCK]",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "[DISABLED] CRM Lead Draft Test Adapter",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Close Rejected Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Queue for Owner Review [MOCK]": {
      "main": [
        [
          {
            "node": "Append Final Audit Event [MOCK]",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "[DISABLED] CRM Lead Draft Test Adapter": {
      "main": [
        [
          {
            "node": "Append Final Audit Event [MOCK]",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Close Rejected Draft": {
      "main": [
        [
          {
            "node": "Append Final Audit Event [MOCK]",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append Final Audit Event [MOCK]": {
      "main": [
        [
          {
            "node": "Terminal - Inspectable Review Package",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true,
    "executionTimeout": 300
  },
  "versionId": "178b72df-168b-414c-a98b-7605188b7472",
  "meta": {
    "templateCredsSetupCompleted": false,
    "syntheticOnly": true,
    "portfolioProof": "inspectable-v2"
  },
  "tags": []
}