{"slug":"triage/02-EXECUTION_FLOW","title":"02 — Execution Flow","section":"triage","sectionLabel":"Triage","status":"canon","type":"document","path":"triage/02-EXECUTION_FLOW.mdx","bytes":15128,"description":"The end-to-end triage execution flow from intake trigger through classification, staging, and governed promotion.","updated":"2026-08-24","source":"integratewise/Integratewise-docs-wiki","content":"\n\n## Two-Path Mapping\n\nTriage spans the **User Path** (human experience) and **System Path** (operational pipeline). The diagram below shows which steps belong to which path.\n\n```\n┌─────────────────── SYSTEM PATH ───────────────────────────────┐\n│                                                               │\n│  Intake → Classify → Link → Dedup → Stage → Audit            │\n│                                                               │\n└───────────────────────────┬───────────────────────────────────┘\n                            │\n                     ┌──────▼──────┐\n                     │  BOUNDARY   │\n                     │  Candidates │\n                     │  flow to    │\n                     │  User Path  │\n                     └──────┬──────┘\n                            │\n┌───────────────────────────▼───────────────────────────────────┐\n│                                                               │\n│  User Path: Discover → Understand → Contextualize → DECIDE   │\n│                                                               │\n└───────────────────────────┬───────────────────────────────────┘\n                            │\n                     ┌──────▼──────┐\n                     │  BOUNDARY   │\n                     │  Decisions  │\n                     │  flow to    │\n                     │  System Path│\n                     └──────┬──────┘\n                            │\n┌───────────────────────────▼───────────────────────────────────┐\n│                                                               │\n│  System Path: Consolidate → Promote → Index → Consume        │\n│                                                               │\n└───────────────────────────────────────────────────────────────┘\n```\n\n| Phase | Path | Steps |\n|---|---|---|\n| **Intake & Classification** | System | Intake → Classify → Link → Dedup → Stage → Audit |\n| **Governance Decision** | User | Discover → Understand → Contextualize → Decide (approve/reject/defer) |\n| **Promotion & Indexing** | System | Consolidate → Promote → Index → Consume |\n\n**Neither path can bypass the other.** The System Path never writes canonical memory. The User Path never classifies.\n\n## End-to-End Data Flow\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│                    INTAKE SOURCES                            │\n│  MCP Capture · Conversation Archive · Session · Manual       │\n└──────────────────────┬──────────────────────────────────────┘\n                       │\n                       ▼\n┌─────────────────────────────────────────────────────────────┐\n│                  TRIAGE INTAKE                               │\n│  iw-agent-runtime TriageAgent (Durable Object)              │\n│  - classify(content) → route                                │\n│  - triage_items (operational state)                         │\n│  - emitTriageInput → Continuity service                     │\n└──────────────────────┬──────────────────────────────────────┘\n                       │\n                       ▼\n┌─────────────────────────────────────────────────────────────┐\n│              COGNITIVE TRIAGE (intelligence)                 │\n│  TriageAgent (WorkflowStep)                                 │\n│  - 4 Cognitive Dimensions: classify, link, review, govern   │\n│  - Output: STAGE_FOR_REVIEW or REJECT                       │\n│  - No AUTO_APPROVE for org memory                           │\n└──────────────────────┬──────────────────────────────────────┘\n                       │\n                       ▼\n┌─────────────────────────────────────────────────────────────┐\n│                  DURABLE WORKFLOW                            │\n│  TriageWorkflow (Cloudflare Workflow)                       │\n│  - Routes pending_approval → HITL DLQ                       │\n│  - Routes rejected → terminal                               │\n│  - NO direct writes to R2/Vectorize/D1/Pipeline             │\n└──────────────────────┬──────────────────────────────────────┘\n                       │\n                       ▼\n┌─────────────────────────────────────────────────────────────┐\n│              KNOWLEDGE SERVICE (triage-bot)                  │\n│  AI extraction (Workers AI)                                 │\n│  - All outputs: approval_status = 'pending'                 │\n│  - Writes to triage_results (Neon/D1)                       │\n│  - Slack notification (review channel, not authority)        │\n└──────────────────────┬──────────────────────────────────────┘\n                       │\n                       ▼\n┌─────────────────────────────────────────────────────────────┐\n│              HUMAN IN THE LOOP                              │\n│  Knowledge Service: PATCH /v1/knowledge/triage/:id          │\n│  - Authenticated principal                                  │\n│  - Tenant authority                                         │\n│  - Optimistic/version check                                 │\n│  - Actions: approve | discard | defer                       │\n└──────────┬─────────────────────┬────────────────────────────┘\n           │                     │\n     ┌─────▼─────┐        ┌─────▼─────┐\n     │  approve   │        │  discard  │\n     └─────┬─────┘        └─────┬─────┘\n           │                     │\n           ▼                     ▼\n┌──────────────────┐    ┌──────────────┐\n│  QUEUE:          │    │  TERMINAL    │\n│  consolidation   │    │  No memory   │\n│  trigger         │    │  published   │\n└────────┬─────────┘    └──────────────┘\n         │\n         ▼\n┌─────────────────────────────────────────────────────────────┐\n│         MEMORY CONSOLIDATOR (scheduled worker)              │\n│  - Hourly: topic clustering of recent sessions              │\n│  - Daily: user/account consolidation + health signals       │\n│  - Weekly: cross-account patterns + best practices          │\n│  - Reads approved triage items only                         │\n└──────────────────────┬──────────────────────────────────────┘\n                       │\n                       ▼\n┌─────────────────────────────────────────────────────────────┐\n│         CANONICAL PROMOTION (pipeline/memory-promoter)      │\n│  - scoreForPromotion() — 7 Promotion Signals                │\n│  - Governance gate: staging vs approved                     │\n│  - Writes to org_memory (D1)                                │\n│  - Audit trail (memory_promotion_audit)                     │\n└──────────────────────┬──────────────────────────────────────┘\n                       │\n                       ▼\n┌─────────────────────────────────────────────────────────────┐\n│         INDEXING (pipeline/memory-indexer)                   │\n│  - Bulk index approved org_memory → AI Search               │\n│  - Markdown + metadata per vector                           │\n│  - Idempotent re-upload                                     │\n└──────────────────────┬──────────────────────────────────────┘\n                       │\n                       ▼\n┌─────────────────────────────────────────────────────────────┐\n│         CONSUMER                                           │\n│  Twin reads published memory through bounded context        │\n│  projection — never raw canonical storage                   │\n└─────────────────────────────────────────────────────────────┘\n```\n\n## Step-by-Step Walkthrough\n\n### Step 1: Intake\n\nAn event arrives from one of:\n- **MCP Connector** — saves session memory after a tool call\n- **Conversation Archive** — triggers extraction when a conversation is archived\n- **Session Triage** — `/v1/triage/session` endpoint receives session summary\n- **Manual Trigger** — admin triggers triage via API\n\nThe `iw-agent-runtime` `TriageAgent` (Durable Object) receives the event, classifies it by simple pattern matching, and stores it as a `triage_item` in operational state.\n\n### Step 2: Continuity Emission\n\nThe TriageAgent calls `emitTriageInput()` which posts to the Continuity service at `http://internal/v1/continuity/events`. This creates a cognition/system event in the continuity stream.\n\n### Step 3: Cognitive Evaluation\n\nIf the event qualifies for cognitive triage (higher-stakes content), the `intelligence` service's `TriageAgent` performs a deep evaluation:\n\n1. **Intelligent Categorization** — What is the true intent? (Lead, Document, Operational Request)\n2. **Contextual Linking** — How does this relate to canonical memory? Which entities does it touch?\n3. **Canonical Review** — Is it stale? Duplicate? Conflicts with established truths?\n4. **Guardrails & Governance** — Based on sensitivity, should it be staged for review or rejected?\n\nOutput is strictly: `\"STAGE_FOR_REVIEW\"` or `\"REJECT\"`. **No AUTO_APPROVE.**\n\n### Step 4: Workflow Routing\n\nThe `TriageWorkflow` durable workflow routes the result:\n\n- **`pending_approval`** → sent to HITL DLQ (Human-In-The-Loop Dead Letter Queue)\n- **`rejected`** → terminal state, no memory published\n- **`approved`** (legacy — should not occur after patching) → treated as staging_for_review\n\n**No direct writes to R2, Pipeline, D1, or Vectorize from this workflow.**\n\n### Step 5: Knowledge Extraction\n\nThe `knowledge` service's `triage-bot.ts` extracts structured knowledge using Workers AI:\n\n- Memory types: insight, preference, fact, decision, action_item, relationship\n- All extractions written to `triage_results` with `approval_status = 'pending'`\n- Slack notification sent for review (channel, not authority bypass)\n\n### Step 6: Human Review\n\nA human reviews the triage item via:\n\n- **Workspace Triage Inbox** — `GET /v1/knowledge/inbox` shows pending/deferred items\n- **Slack Reactions** — ✅ Approve, ❌ Discard, ⏰ Defer (must be verified as approval event)\n- **API** — `PATCH /v1/knowledge/triage/:id` with action: approve/discard/defer\n\nThe approval endpoint requires:\n1. Authenticated principal\n2. Tenant authority\n3. Optimistic/version check\n4. Approver identity and timestamp\n5. Immutable decision audit\n\n### Step 7: Consolidation\n\nThe Memory Consolidator runs on schedule:\n\n| Schedule | What It Does |\n|---|---|\n| **Hourly** | Topic clustering of recent sessions |\n| **Daily** | Deep user/account consolidation + health signals |\n| **Weekly** | Cross-account pattern extraction + best practices |\n\nIt reads only approved triage items and generates consolidated memories.\n\n### Step 8: Canonical Promotion\n\nThe Pipeline's `memory-promoter.ts` is the sole canonical writer:\n\n1. Scores the Spine write against 7 Promotion Signals\n2. Determines governance state (staging vs approved)\n3. Writes to `org_memory` (D1)\n4. Deduplicates by lineage_ref\n5. Creates audit trail in `memory_promotion_audit`\n6. Indexes approved memory into AI Search\n\n### Step 9: Indexing and Consumption\n\nApproved org_memory entries are indexed into AI Search as markdown documents with full metadata. Twin reads published memory through bounded context projection — never raw canonical storage.\n"}