Skip to content

feat(swarm): wire RemDiversityService + LessonContradictionGate into REM digest #137

Description

@Dewinator

Problem

Two Phase-4 services exist as substrate but are never instantiated in the runtime — they're dead code outside of unit tests:

Service Migration Spec Status
RemDiversityService 082 §10.4 anti-echo-chamber class exists, no new …() call
LessonContradictionGate 080 §10.3 contradicts-trigger class exists, no new …() call

RemAuditService (4h) and RemPromotionService (4i.2) are correctly wired in mcp-server/src/index.ts and called from tools/digest.ts. The other two were not.

Empirically:

  • lesson_diversity_log stays at 0 rows after REM cycles run.
  • swarm_lesson_contradictions stays at 0 rows even when ingesting test data with deliberate polarity flips.

The dashboard shows these as empty — correctly, because the writers don't run.

Scope

RemDiversityService — nightly REM step

  1. Instantiate alongside the other REM services in index.ts.
  2. Add a step in tools/digest.ts that calls the diversity check after RemPromotion runs. Order matters: diversity dampens weight, promotion increases weight; if diversity runs second it will counterbalance promotion correctly.
  3. The check writes one row per evaluated lesson into lesson_diversity_log.

LessonContradictionGate — runs on inbound (and after REM)

  1. Instantiate as a member of ConscienceAgent (mcp-server/src/agents/conscience-agent.ts) — the §10.3 spec puts the gate in the conscience-agent flow.
  2. Call the gate after every successful inbound lesson admission (when the inbound endpoint exists; until then, expose it via a digest step that scans the recently-arrived swarm_lessons window).
  3. Gate populates swarm_lesson_contradictions and demotes both endpoints to Tier-B per §10.3.

Acceptance

  • After a REM cycle on a DB with diverse lessons, lesson_diversity_log has rows.
  • After ingesting two semantically-near swarm_lessons with opposite polarity (test fixture), swarm_lesson_contradictions has the pair, and both rows in swarm_lessons have lesson_tier='B'.
  • Order in digest: audit → contradicts → promotion → diversity (matches the §10.5 → §10.3 → §10.6 → §10.4 spec sequence).
  • Existing 566+ tests still green.
  • An integration test runs the full REM cycle against a fresh DB with seeded swarm lessons and asserts the four log tables get populated as expected.

Out of scope

  • Inbound HTTP endpoint that actually admits lessons (separate issue).
  • Operator UI for resolving contradicts (covered by the dashboard-action issue).
  • Contradicts-resolution timer (Phase 4f — already shipped).

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-eligibleAutonomous agent loop is allowed to pick thisfoundationPhase-0/1 Fundament für ein größeres FeatureswarmSchwarm-Foundation: dezentrale P2P-Architektur

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions