v1

Architecture & Core Concepts

Deep dive into EngineNear architecture: T0/T1/T2 tiers, customer firewall policies, the degradation ladder, and reversible tokenization.

T0, T1, and T2 Detection Tiers

EngineNear partitions prompt evaluation across three specialized computing tiers to maximize throughput while guaranteeing sub-5ms latency on high-volume hot paths:

  • Tier 0 (Deterministic Scanner): Pure TypeScript/WASM engine running in-browser and off-thread in gateway Piscina worker pools. Uses Aho-Corasick literal automaton over credential prefixes (AKIA, ghp_, sk-, Bearer), sliding-window Shannon entropy O(n) for unformatted keys, and checksum PII validators (Luhn credit cards, Verhoeff Aadhaar). p95 execution is under 0.5 ms on 10 KB inputs.
  • Tier 1 (Fast Heuristics & Injection Classifier): Specialized heuristic analysis and structural token parsing. Evaluates delimiter spoofing, role manipulation, and indirect prompt injection attempts.
  • Tier 2 (Deep Semantic Context & Refinement): Runs in the Context Compiler. Performs entity disambiguation, role-based ACL pre-filtering across connected data sources, and structured prompt generation within strict token budgets.
Rule 3 Compliance: Off-Thread Pool
All CPU-intensive AST parsing and regular expressions are offloaded to dedicated Piscina worker threads. Gateway event loop lag never exceeds our 100ms load-shedding budget under steady or spike traffic.

Policies and Enforcement Modes

Policies are defined in the admin console and compiled into versioned immutable trees. Each policy rule defines a target category, priority order, and assigned action:

  • Monitor Mode: Non-blocking observation. Requests are evaluated and logged with SHA-256 hashes to measure exposure without altering prompts or user workflows.
  • Warn Mode: Soft enforcement. Users and client SDKs receive warning diagnostics detailing potential data leaks, allowing developers to review findings.
  • Enforce Mode: Hard perimeter security. Detected high-entropy secrets and hostile prompt injections are strictly blocked (HTTP 403 / UI block) or tokenized before network transmission.

The Multi-Tier Degradation Ladder

In cloud environments, dependencies experience timeouts, network partitions, and resource exhaustion. EngineNear implements an automatic degradation ladder (ADR 0004 & runbook):

  • Step 1 (Normal Operations): Full T0 + T1 + T2 processing with complete semantic context injection.
  • Step 2 (Elevated Latency): If external model dependencies exceed 250ms, the gateway sheds T2 and falls back to deterministic T0 + T1 heuristics.
  • Step 3 (Heavy Spike / Overload): If gateway event loop delay exceeds 100ms, the system steps down to pure deterministic T0 scanning (sub-5ms p95).
  • Step 4 (Fail-Closed vs Fail-Open): Tenants configure emergency behavior: Fail-Closed blocks unverified requests to prevent data leaks; Fail-Open allows traffic through if business continuity takes precedence.

Tokenization and Detokenization

To enable LLMs to reason about sensitive data without exposing raw values, EngineNear provides reversible client-side tokenization:

1. When personal identifiers (names, cards, emails) are detected, EngineNear replaces the character spans with synthetic tokens like [CREDIT_CARD_1] or [EMAIL_1].

2. The mapping is held in an ephemeral session vault in the client browser or VPC gateway memory.

3. The sanitized prompt is sent to the LLM provider.

4. When the LLM responds, the detokenizer safely swaps tokens back to their original values inside the client interface before rendering to the user.

Data Privacy Boundary
Third-party model providers only ever see synthetic tokens. Real customer payment numbers and private identifiers never leave your perimeter.