RFC-0X · CRM_ORCHESTRATION
DRAFT v2.4PRE-IMPLEMENTATIONOWNER: PIXELGENISYS

Event-Driven Closed-Loop Orchestration Over CRM State

A permissioned middleware tier composing stateless ingestion, graph-contextual retrieval, versioned inference serving, and idempotent transactional write-back under enforced RBAC/ABAC, exactly-once write semantics, and append-only audit provenance. Formal decision boundaries — priority scoring, confidence gating, backoff scheduling — are specified in §07.

INVARIANT-BOUND · NO PROD WRITE PATH PRE-STAGING
00

Problem / Invariant

Define a permissioned event surface sufficient for orchestration, contextual inference, and closed-loop write execution against CRM state, without inducing a shadow system whose read model drifts from source-of-truth under eventual consistency.

HARD INVARIANT

Every mutation path terminates in a scoped service principal under least-privilege policy — enforced via policy-as-code (OPA/Rego) evaluated at the call boundary. No direct schema access. No shared credentials. No per-module carve-outs.

01

Pipeline

DAG-scheduled, four-stage execution per event; span-per-hop distributed tracing via W3C traceparent propagation.

ingest()
→
resolve()
→
infer()
→
execute()
INGEST

Canonical normalization via poll/webhook delivery. Idempotency keys on (entity_id, event_seq) dedupe at-least-once delivery; exactly-once observed only at the write boundary via conditional upsert (optimistic concurrency, version-vector compare-and-swap).

RESOLVE

Entity graph joined against relationship, permission-scope, and historical-state context pre-inference. Coverage gaps propagate as missing-feature imputation, degrading posterior confidence rather than failing silently.

INFER

Feature vectors scored via classification/ranking/regression behind a versioned serving API (see EQ.01–EQ.03). Sub-threshold output is discarded, not defaulted — see confidence gate, EQ.02.

EXECUTE

Transactional write with exponential backoff + decorrelated jitter (EQ.04), dead-letter on retry exhaustion, at-least-once delivery collapsed to exactly-once effect via idempotent upsert.

02

Reference Architecture

CRM
→
GATEWAY
→
ORCHESTRATOR
→
INFERENCE
→
RULE ENGINE
→
CRM
LAYERFUNCTION
L1 CONNECTOAuth2/mTLS service-principal handshake; JSON-Schema contract mapping at gateway boundary.
L2 NORMALIZEETL/ELT — dedup, probabilistic entity resolution (EQ.05), single-customer-record materialization.
L3 INFERVersioned model serving; canary/shadow-gated rollout, statistical rollback trigger on drift.
L4 DOMAINScoped execution contexts per function; bulkhead-isolated blast radius per pipeline.
L5 AUTOMATEECA trigger evaluation, rule DSL, transactional action dispatch with 2PC-style commit/rollback.
L6 GOVERNRBAC/ABAC (policy-as-code), field-level PII masking, append-only audit, synchronous approval-gate middleware.
03

Module Surface

Bounded contexts — independent model, schema, and permission scope per module.

IDMODULESPEC
M01query interfaceNL intent parse → structured CRM read/write call resolution via slot-filling + grounded entity linking.
M02ranking modelWeighted composite scoring (EQ.01); SHAP attribution (EQ.06) surfaced with output for auditability.
M03forecast modelStage-transition survival modeling (EQ.03) over time-series pipeline state.
M04generation pipelineContext-conditioned draft generation, retrieval-grounded (EQ.05), approval-gated by default.
M05summarizationTranscript → structured decision/action-item extraction, embedding-indexed post-session.
M06classificationLogistic intent/urgency classifier (EQ.02 gate) feeding rule-engine routing.
M07entity resolutionCross-source identity resolution via blocking + pairwise similarity (EQ.05) into one canonical node.
M08anomaly detectionBehavioral drift vs. historical baseline; Mahalanobis-distance threshold-alert.
M09routing classifierQueue assignment, SLA-aware priority weighting over expected wait.
M10extraction pipelineDocument parse → structured field extraction → schema validation pre-write.
04

Rule Engine (ECA)

Event–Condition–Action evaluation. Inference without an execution path is telemetry, not automation.

EVENTCONDITIONINFERACTION
lead.createdP(lead) > τ (EQ.01)owner_fit()assign() → task.create()
activity.staleidle_days > Nrisk_score() (EQ.03)notify() → task.create(recovery)
intent.detectedσ(z) ≥ τ (EQ.02)priority_rank()alert(mgr) → task.create(priority)
ticket.createdurgency classifiedroute_target()dispatch(queue) → sla_timer.start()
invoice.duedays_to_due < Ncontext_pull() (EQ.05)draft(reminder) → comm_log.append()

scroll for full condition set →

event
→
features
→
score+rank
→
assign()
→
audit.append()

Transaction boundary: assign → task.create → notify → crm.update commits atomically or rolls back fully under a 2PC-style coordinator — no partial-state writes survive a fault.

07

Formal Specification

Decision boundaries governing inference gating, scoring, retry scheduling, and retrieval — normative for implementation, not illustrative.

EQ.01Composite priority score — M02
\[ P(x) = \sum_{i=1}^{n} w_i \, f_i(x), \quad \sum_{i=1}^{n} w_i = 1 \]
\(f_i\): normalized feature functions (industry_fit, deal_value_norm, activity_recency, intent_score). \(w_i\) fit via gradient-boosted feature importance or fixed domain prior.
EQ.02Confidence gate — execution boundary
\[ \text{execute}(a) \iff \sigma(z) = \frac{1}{1+e^{-z}} \geq \tau, \quad z = \beta^{\top}x + \beta_0 \]
Sub-\(\tau\) output discarded, never defaulted. \(\tau\) tuned per action-risk class; see §06 approval-gate threshold.
EQ.03Deal-risk survival — M03
\[ R(d) = 1 - \prod_{s=1}^{k} \left(1 - p_s\right) \]
\(p_s\): stage-transition failure hazard at pipeline stage \(s\); compounded multiplicatively across the survival path.
EQ.04Retry backoff — decorrelated jitter
\[ t_n = \min\!\big(t_{max},\; t_{base}\cdot 2^{\,n}\big) + U\!\left(0,\, j \cdot t_{base}\cdot 2^{\,n}\right) \]
\(n\): retry index, \(j \in [0,1]\): jitter factor. DLQ on \(n > n_{max}\).
EQ.05ANN retrieval — cosine similarity
\[ \text{sim}(q,d) = \frac{q \cdot d}{\lVert q \rVert \, \lVert d \rVert} \]
Rank by top-\(k\) over the embedding index; grounds M04/M05/M07/entity-resolution context pull.
EQ.06SHAP attribution — M02 explainability
\[ \phi_i = \sum_{S \subseteq F\setminus\{i\}} \frac{|S|!\,(|F|-|S|-1)!}{|F|!}\Big[v(S\cup\{i\}) - v(S)\Big] \]
Shapley-value feature contribution; surfaced with every scored output for audit traceability (§06).
05

I/O Contract

READ SCOPE
  • customer{} / lead{} / contact{}
  • deal{} / pipeline_stage
  • activity{} / task{}
  • comm_history[]
  • ticket{} / product{} / order{}
  • document{}
  • role{} / permission_scope{}
WRITE / MUTATION SCOPE
  • task.create / task.update
  • lead.update / deal.update
  • notification.dispatch
  • assignment.set
  • note.append / activity.append
  • status.transition
  • reminder.schedule / priority.flag
  • audit.append
06

Security Model

RBAC/ABAC
Service-principal scope ⊆ acting user's scope, evaluated as policy-as-code at the API boundary — never the UI layer.
AUDIT LOG
Append-only, immutable, hash-chained. Every consequential read, every inference decision (incl. EQ.06 attribution), every write.
APPROVAL GATE
Synchronous hold on execution when \(\sigma(z)\) (EQ.02) falls in the ambiguity band or the action's risk class requires human sign-off.
PII MASKING
Field-level masking at the retrieval boundary; deterministic tokenization where regulatory constraints mandate reversibility.
LEAST PRIV
Scoped credentials per module, automatic rotation, zero shared or personal-login access paths.
SANDBOX
All modules validated against synthetic/anonymized data under shadow traffic before any production write path.
08

Rollout

P1DiscoverySchema audit, permission model, workflow inventory.
P2ConnectivityGateway, webhook ingest, auth handshake, event schema definition.
P3FoundationOrchestrator, embedding index, inference serving layer stood up.
P4ModulesQuery, ranking (EQ.01), forecasting (EQ.03), extraction pipelines rolled out.
P5AutomationRule engine live; trigger → action → write-back closed-loop enabled.
P6HardeningLoad testing, audit review, gate-threshold (τ) tuning, staged production rollout.
09

Preconditions

  1. Schema + entity-relationship map, documented or reverse-engineerable.
  2. Transport agreement: source access / API-webhook contract / read-replica.
  3. Module priority ranked by signal-to-noise vs. implementation cost.
  4. Isolated staging environment, representative anonymized data.
  5. RBAC/ABAC model defined, incl. service-principal scope boundaries.
  6. Current business-rule and workflow documentation.
  7. Action risk classification — autonomous vs. approval-gated, per action type.
  8. Security/privacy/compliance requirements as testable constraints.
  9. Named technical counterpart with schema and infrastructure authority.
  10. Phase-1 success criteria defined as measurable thresholds, not narrative.
10

Terminal State

crm.read() → infer() → domain_module() → rule_engine() → crm.write()

Single hard dependency: one stable, permissioned integration contract with the CRM. Every component above — including the formal boundaries in §07 — is downstream of that interface definition.