PRD — Feedback Loop Architecture

Clone Feedback Loop & Corrections Engine

How audit pages, extraction reviews, and improvement items close the loop back into the clone factory — for any expert, any iteration.

Contents 1. Problem Statement 2. Current State (What Exists) 3. The Complete Feedback Loop 4. New Factory Blocks 5. Corrections Engine Spec 6. Multi-Tester Aggregation 7. Convergence Tracking 8. API Interface Contract 9. Schema Changes 10. Process Factory Integration 11. Build Sequence

1. Problem Statement

The clone factory produces extraction JSONs (L2), compiles them into a system prompt (L3), and tests the clone (L3.5). Automated testing scores 93.8%. But:

The gap: When the expert (or any human tester) identifies something wrong — a misextracted value, a voice drift, a missing framework — there is no automated path from that feedback back into the factory pipeline. Corrections are manual, ad-hoc, and untraceable.

This PRD specifies the feedback loop — the system that takes human audit findings, routes corrections to the right upstream skill, triggers targeted re-runs, and tracks convergence until the expert signs off.

2. Current State (What Exists)

Audit Collection Pages

PageWhat It TestsItemsOutput
Audit v3Clone behavior — does it sound like the expert?10 scenario ratings + 5 questions + live chat + voice/text feedbackclone_feedback row + report + email
Extraction ReviewExtraction accuracy — did we capture the right data?295 items across 6 JSONs (soul, voice, frameworks, resources, offers, FORGE+SHIFT)clone_feedback row + improvement_items + report + email

Data Pipeline (Built)

Audit Submit ──→ clone_feedback table
              └──→ audit-analyze API (auto-fires)
                      └──→ improvement_items table (classified findings)
                              └──→ Improvement Dashboard (triage view)
                                      └──→ ??? (MANUAL GAP)

Extraction Review Submit ──→ clone_feedback table
                          └──→ improvement_items table (per flagged item)
                                  └──→ ??? (MANUAL GAP)

Process Factory (Built)

3. The Complete Feedback Loop

1. COLLECT
Expert runs audit v3 and/or extraction review. Human feedback captured with ratings, corrections, chat transcript, voice notes.
2. CLASSIFY
audit-analyze API auto-classifies findings: voice_gap, tone_drift, framework_gap, missing_capability, content_gap, governance_violation. Maps each to a skill_target.
3. AGGREGATE
Multiple testers submit against the same version. Findings are grouped, weighted by tester role, consensus scored. Items flagged by 2+ testers = confirmed.
4. TRIAGE
Improvement dashboard shows grouped findings. Team accepts, rejects, defers, or merges duplicates. Accepted items become correction tickets.
5. CORRECT
Corrections engine reads accepted items, groups by skill_target, injects expert corrections as context into the targeted extraction skill re-run.
6. RE-RUN
Targeted skills re-extract with corrections → clone-compiler re-compiles → clone-tester re-tests → new version produced. Only changed skills re-run, not the whole pipeline.
7. CONVERGE
Compare version scores. Track which items resolved vs persisted. Loop repeats until: expert signs off + 0 critical items + scores plateau.

4. New Factory Blocks

Three new blocks insert into the factory DAG between existing layers:

Block IDLayerTypeDepends OnHuman Gate
extraction-reviewerL2.6validateAll L2 extractors (soul, voice, framework, resource, offer)after
expert-auditL3.6validateclone-testerafter
corrections-routerL3.7orchestrateexpert-audit OR extraction-reviewer (whichever has findings)none

extraction-reviewer (L2.6)

Purpose: Generate an extraction review page for the expert to verify all 6 extraction JSONs before compilation begins.

Inputs: All L2 extractor artifacts (soul.json, voice.json, frameworks.json, resources.json, offers.json) + expert-framework.json

Execution: Runs build-extraction-review.js --expert={slug} → produces HTML page → publishes to NowPage

Outputs: Published extraction review URL, extraction version tag

Gate: Expert submits review → improvement_items created → gate approved when 0 critical items remain or team accepts remaining items

expert-audit (L3.6)

Purpose: Generate an audit v3 page for the expert to validate clone behavior after compilation and automated testing.

Inputs: clone-compiler artifacts (system prompt, knowledge files) + clone-tester results

Execution: Generates audit page parameterized by expert slug → publishes to NowPage → expert runs audit

Outputs: Published audit URL, feedback_id, improvement_summary

Gate: Expert submits audit → audit-analyze fires → improvement_items created → gate approved when expert is satisfied

corrections-router (L3.7)

Purpose: Read improvement_items for this run, group by skill_target, and trigger targeted re-runs of upstream blocks with corrections as additional context.

Inputs: improvement_items where factory_run_id = {run_id} and status = 'accepted'

Execution:

  1. Query improvement_items grouped by skill_target
  2. For each group: package corrections as structured context
  3. Reset the targeted upstream block(s) to pending
  4. Inject corrections into block.state.corrections (new field)
  5. DAG evaluator makes them ready → they re-run with correction context
  6. Downstream blocks (clone-compiler, clone-tester) auto-cascade

Outputs: List of re-triggered blocks, correction payloads

Gate: None — fully automated. The re-run cycle stops at the next human gate (expert-audit).

Updated DAG Flow

L0  deep-research ─┐
    expert-recon ───┤ (parallel L0-recon)
    masterybook-sync┘
         │
L0.25 expert-framework-creator [gate: after]
         │
L0.5  demo-compiler
         │
L1    rubric-builder
         │
L2    soul ─┐
      voice ─┤
      framework┤ (parallel L2-extractors)
      resource ┤
      offer ───┘
         │
L2.6  extraction-reviewer [gate: after]  ← NEW
         │
L2.5  gap-analyzer [gate: after]
         │
L3    clone-compiler ─┐
      lead-magnet ─────┤ (parallel L3-builders)
      onboarding ──────┤
      design-system ───┘
         │
L3.5  clone-tester [gate: after, threshold: 85]
         │
L3.6  expert-audit [gate: after]  ← NEW
         │
L3.7  corrections-router  ← NEW
         │ (resets upstream blocks if corrections exist)
         │ (re-triggers L2→L3→L3.5→L3.6 cycle)
         │
L4    boarding-orchestrator (only reached when 0 corrections)
         │
L5    marketing-page-builder ─┐
      email-sequence-builder ──┤ (parallel L5-marketing)
      stripe-setup ────────────┘
         │
L6    audit-page-publisher ─┐
      publish-orchestrator ──┘ (parallel L6-publishing)

5. Corrections Engine Spec

How Corrections Flow Into Re-Runs

When corrections-router executes, it:

Step 1: Query Improvement Items

SELECT * FROM improvement_items
WHERE factory_run_id = '{run_id}'
  AND status = 'accepted'
ORDER BY priority DESC, skill_target

Step 2: Group by Skill Target

{
  "voice-extractor": [
    { "source_text": "Too formal in high-energy mode",
      "expert_correction": "I use 'Let's GO!' not 'Let us proceed'",
      "priority": "high" },
    ...
  ],
  "soul-extractor": [
    { "source_text": "Missing value: Community over competition",
      "expert_correction": "I never rank people against each other",
      "priority": "critical" },
    ...
  ]
}

Step 3: Inject Into Block State

New field: block.state.corrections

// Added to the targeted block's state before re-run
block.state.corrections = {
  version: "v7.1→v7.2",
  source: "expert-audit + extraction-review",
  items: [
    { finding: "...", correction: "...", priority: "high" }
  ],
  instruction: "IMPORTANT: The expert reviewed the previous extraction and flagged these corrections. Apply each correction to the output. Do not lose existing correct content — only fix the flagged items."
}

Step 4: Update /api/execute Context

The execute endpoint already builds context from SKILL.md + inputs + upstream artifacts + gaps. Add corrections as a new context section:

// In /api/execute, when building the prompt:
if (block.state.corrections?.items?.length) {
  contextParts.push(`
## EXPERT CORRECTIONS (MUST APPLY)
The expert reviewed the previous version and flagged these corrections.
Apply each one. Do not remove correct content — only fix flagged items.

${block.state.corrections.items.map(c =>
  `- FINDING: ${c.finding}\n  CORRECTION: ${c.correction}\n  PRIORITY: ${c.priority}`
).join('\n\n')}
  `);
}

Step 5: Mark Items Resolved After Re-Run

After the targeted block completes successfully, mark the improvement_items as resolved:

UPDATE improvement_items
SET status = 'resolved',
    resolved_in_version = '{new_version}',
    resolution_notes = 'Auto-resolved via corrections-router re-run'
WHERE factory_run_id = '{run_id}'
  AND skill_target = '{block_skill}'
  AND status = 'accepted'

6. Multi-Tester Aggregation

Tester Roles & Weights

RoleWeightWhoWhat They Validate
Expert3.0Samuel NguVoice accuracy, framework correctness, value alignment
Product Lead2.0Will PrebleUser experience, framework completeness, offer accuracy
Tech Lead1.5Jason MacDonaldGovernance, engineering gaps, tool behavior
Team1.0Derek, Aaron, DrewGeneral quality, user perspective
External0.5Beta testersFresh-eyes validation, usability

Consensus Logic

Confirmed finding: Weighted score ≥ 2.0 across testers for the same item

Example: Samuel flags voice item (3.0) → auto-confirmed. Two team members flag same item (1.0 + 1.0 = 2.0) → confirmed. One external tester (0.5) → needs more validation.

Conflicting feedback: If one tester says "correct" and another says "needs work" for the same item, the higher-weighted tester wins. Ties escalate to triage.

Implementation

Add to clone_feedback table:

ALTER TABLE clone_feedback ADD COLUMN tester_role TEXT DEFAULT 'team';
-- Valid: 'expert', 'product_lead', 'tech_lead', 'team', 'external'

Add to improvement_items table:

ALTER TABLE improvement_items ADD COLUMN consensus_score NUMERIC DEFAULT 0;
ALTER TABLE improvement_items ADD COLUMN flagged_by JSONB DEFAULT '[]';
-- flagged_by: [{ "tester": "samuel-ngu", "role": "expert", "weight": 3.0, "feedback_id": "..." }]

Aggregation runs after each audit submit — queries all improvement_items for the same expert_slug + source_scenario key, recalculates consensus_score across all testers who flagged it.

7. Convergence Tracking

What to Track

MetricSourceGoal
Version score (automated)clone-tester results≥ 90% across all dimensions
Expert approval rateaudit v3 ratings≥ 80% "sounds like me"
Extraction accuracyextraction review≥ 90% "correct"
Open critical itemsimprovement_items0
Open high itemsimprovement_items≤ 3
Iteration countfactory run versionsTypically 2-4 rounds

Ship Criteria

Ready to ship when ALL of:

  1. Expert has approved the latest audit (gate signed off)
  2. 0 critical improvement_items remain open
  3. ≤ 3 high items remain (accepted as known limitations)
  4. Automated test score ≥ 85% (already enforced by clone-tester threshold)
  5. Expert extraction review ≥ 85% correct rate

Convergence Dashboard

New page: align360.asapai.net/{expert}-convergence

Shows version-over-version comparison:

Version  | Auto Score | Expert Rate | Extraction | Critical | High | Status
---------|------------|-------------|------------|----------|------|--------
v7.0     | 91.9%      | —           | —          | 3        | 8    | superseded
v7.1     | 93.8%      | —           | —          | 0        | 5    | superseded
v7.2     | —          | 85%         | 92%        | 0        | 2    | current
v7.3     | —          | —           | —          | —        | —    | pending

8. API Interface Contract

This is the contract between the audit pages (folio-saas) and the corrections engine (process-factory).

Folio-saas → Process Factory (new endpoint)

POST /api/corrections-ingest

Called by audit-analyze and extraction-review-submit after creating improvement_items. Notifies the factory that new corrections are available.

// Request
{
  "run_id": "factory-run-uuid",
  "expert_slug": "samuel-ngu",
  "feedback_id": "clone-feedback-uuid",
  "items_created": 5,
  "by_skill": {
    "voice-extractor": 2,
    "soul-extractor": 1,
    "clone-compiler": 2
  },
  "source": "expert-audit" | "extraction-review"
}

// Response
{
  "acknowledged": true,
  "run_status": "corrections-pending",
  "blocks_to_rerun": ["voice-extractor", "soul-extractor", "clone-compiler"]
}

Process Factory → Folio-saas (existing endpoints, enhanced)

GET /api/a360/improvement-items (new)

Query improvement_items for a factory run. Used by corrections-router.

// Request
GET /api/a360/improvement-items?run_id=xxx&status=accepted&skill_target=voice-extractor

// Response
{
  "items": [
    {
      "id": "uuid",
      "finding_type": "voice_gap",
      "skill_target": "voice-extractor",
      "priority": "high",
      "source_text": "Too formal in high-energy mode",
      "expert_correction": "I use contractions and exclamation marks when excited",
      "consensus_score": 3.0,
      "flagged_by": [{ "tester": "samuel-ngu", "role": "expert", "weight": 3.0 }]
    }
  ],
  "total": 1
}

PATCH /api/a360/improvement-items/:id (new)

Update improvement_item status after correction applied.

// Request
PATCH /api/a360/improvement-items/uuid
{
  "status": "resolved",
  "resolved_in_version": "v7.2",
  "resolution_notes": "Re-extracted with correction context",
  "factory_block_id": "voice-extractor",
  "factory_run_id": "run-uuid"
}

9. Schema Changes

Migration 005: Feedback Loop Support

-- 005-feedback-loop.sql

-- 1. Tester role on clone_feedback
ALTER TABLE clone_feedback ADD COLUMN IF NOT EXISTS tester_role TEXT DEFAULT 'team';

-- 2. Multi-tester consensus on improvement_items
ALTER TABLE improvement_items ADD COLUMN IF NOT EXISTS consensus_score NUMERIC DEFAULT 0;
ALTER TABLE improvement_items ADD COLUMN IF NOT EXISTS flagged_by JSONB DEFAULT '[]';

-- 3. Version tracking
ALTER TABLE improvement_items ADD COLUMN IF NOT EXISTS prompt_version TEXT;
ALTER TABLE improvement_items ADD COLUMN IF NOT EXISTS extraction_version TEXT;

-- 4. Index for corrections-router queries
CREATE INDEX IF NOT EXISTS idx_improvement_items_run_status
  ON improvement_items(factory_run_id, status)
  WHERE factory_run_id IS NOT NULL;

CREATE INDEX IF NOT EXISTS idx_improvement_items_expert_scenario
  ON improvement_items(expert_slug, source_scenario)
  WHERE source_scenario IS NOT NULL;

10. Process Factory Integration

Changes to Process Factory Engine

1. Block state: add corrections field

In lib/types.ts, add to BlockState:

corrections?: {
  version: string;           // "v7.1→v7.2"
  source: string;            // "expert-audit" | "extraction-review" | "both"
  items: Array<{
    finding: string;
    correction: string;
    priority: 'critical' | 'high' | 'medium' | 'low';
    improvement_item_id: string;
  }>;
  instruction: string;       // injected into LLM context
}

2. Execute endpoint: inject corrections context

In /api/execute, when building the LLM prompt, check for block.state.corrections and prepend as a high-priority context section.

3. Gate rejection: inject feedback into corrections

In /api/factory-run reject action, convert gate feedback into a corrections-compatible format and store in block.state.corrections so the next run actually uses it.

4. New blocks in template

Add extraction-reviewer, expert-audit, and corrections-router to clone-factory-template.json with proper dependency wiring.

5. Corrections-router execution logic

The corrections-router is unique — it doesn't call an LLM. It:

  1. Reads improvement_items from folio-saas API
  2. Groups by skill_target
  3. Resets targeted upstream blocks (via factory-run reset action)
  4. Injects corrections into each block's state
  5. If 0 accepted items → marks itself done, DAG proceeds to L4
  6. If > 0 items → triggers re-run cycle, eventually returns to L3.6 (expert-audit) for re-validation

11. Build Sequence

Session A (this session — folio-saas):
  1. Add tester_role to audit v3 page (dropdown: expert/product_lead/tech_lead/team/external)
  2. Build GET /api/a360/improvement-items query endpoint
  3. Build PATCH /api/a360/improvement-items/:id update endpoint
  4. Write migration 005
  5. Enhance audit-analyze to calculate consensus_score across testers
  6. Build convergence dashboard page
Session B (other session — process-factory):
  1. Add corrections field to BlockState type
  2. Update /api/execute to inject corrections context
  3. Update gate rejection to store feedback as corrections
  4. Add 3 new blocks to clone-factory-template.json
  5. Build corrections-router execution logic
  6. Build POST /api/corrections-ingest endpoint
  7. Wire extraction-reviewer block to run build-extraction-review.js
  8. Wire expert-audit block to generate audit v3 page
Shared dependency: Both sessions need the GET /api/a360/improvement-items endpoint. Session A builds it, Session B consumes it. Build Session A items 2-4 first.

Verification

  1. Create a factory run with the updated 26-block template
  2. Run L0→L2 normally
  3. L2.6 extraction-reviewer generates review page → expert submits → improvement_items created
  4. L2.6 gate approved → L2.5 gap-analyzer → L3 compile → L3.5 test
  5. L3.6 expert-audit generates audit page → expert submits → improvement_items created
  6. L3.7 corrections-router reads items → resets targeted L2 blocks → re-runs with corrections
  7. Cycle repeats: L2→L3→L3.5→L3.6→L3.7 until 0 corrections
  8. L3.7 passes through to L4 boarding-orchestrator
  9. Convergence dashboard shows version progression