Skip to content

Nightwatch stagnation detection and redirection (Phase 4) #730

@AlexMikhalev

Description

@AlexMikhalev

Summary

Extend Nightwatch drift detection with stagnation metrics and automatic redirection strategies when agents stop making progress.

Approach

Stagnation Detection

  • Extend DriftMetrics with novelty_score, learning_velocity, quality_trend
  • Add observe_evolution() method and StagnationLevel classification
  • Detect stagnation: 3+ consecutive windows with no new lessons

Redirection Strategies (tried in order)

  1. Prompt variation: Append "Previous approaches exhausted. Try different angle: [prior approach summary]"
  2. Model rotation: Force different model via RoutingEngine override
  3. Task decomposition: Split into sub-tasks, hand off to fresh agents

Safeguards

  • Require 3 consecutive stagnant windows before first redirect
  • Cap at 3 redirections per agent per day
  • All redirections logged as Process lessons

Critical Files

  • crates/terraphim_orchestrator/src/nightwatch.rs -- StagnationMetrics, observe_evolution(), StagnationLevel
  • crates/terraphim_orchestrator/src/lib.rs -- handle CorrectionAction::RedirectStrategy

Acceptance Criteria

  • Nightwatch detects stagnation when no new lessons for 3 windows
  • Prompt variation applied on first alert
  • Model rotation on persistent stagnation
  • All redirections logged
  • cargo test --workspace passes

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions