1 agents

strangler-pattern-specialist

strangler-pattern-specialist

Overview

The Strangler Pattern Specialist is an L3 agent operating in the integration domain of the Prismatic Platform. This agent manages the gradual replacement of legacy system components using the strangler fig pattern -- a software migration strategy inspired by the strangler fig tree that grows around its host, eventually replacing it entirely while maintaining system functionality throughout the transition.

In a platform with 90 umbrella applications and over 20 years of accumulated knowledge in the GARDEN legacy repository system, systematic legacy replacement is an ongoing operational concern. The Strangler Pattern Specialist ensures that legacy components are replaced incrementally, with each replacement step maintaining full backward compatibility and zero downtime. This approach contrasts with "big bang" rewrites that carry unacceptable risk for production systems operating under the NO MERCY doctrine.

This agent is part of the platform's 434-strong autonomous agent ecosystem, operating under AIAD standard compliance and coordinating with the GARDEN integration infrastructure for legacy knowledge extraction.

The Strangler Fig Pattern

The strangler fig pattern was first described by Martin Fowler and has become the industry-standard approach for safely replacing legacy systems. The pattern consists of three phases applied iteratively to each component of the legacy system.

PhaseActivityRisk LevelDuration
TransformCreate new implementation alongside legacyLowDays-Weeks
CoexistRoute traffic to new implementation graduallyMediumWeeks
EliminateRemove legacy component once fully replacedLowDays

Pattern Lifecycle

Legacy System (100% traffic)
    ├── Step 1: Build new component A alongside legacy A
    ├── Step 2: Route 10% traffic to new A (canary)
    ├── Step 3: Route 50% traffic to new A (split)
    ├── Step 4: Route 100% traffic to new A (full cutover)
    ├── Step 5: Remove legacy A (elimination)
    └── Repeat for components B, C, D...

Migration Tracking

The Strangler Pattern Specialist maintains a comprehensive migration registry that tracks the status of every legacy component undergoing replacement.

ComponentLegacy LocationNew LocationPhaseTraffic SplitHealth
Entity ResolutionGARDEN/sigprismatic_storage_coreEliminated100% newHealthy
OSINT ProvidersGARDEN/sigprismatic_osintCoexist85% newHealthy
Graph StorageGARDEN/kuzu-exprismatic_storage_kuzuCoexist90% newHealthy
Blackboard SystemGARDEN/prismatic-legacyprismatic_blackboardTransform0% newIn Progress

Technical Implementation

defmodule PrismaticAgents.StranglerPatternSpecialist do
  @moduledoc """
  L3 Strangler Pattern Specialist agent.
  Manages gradual legacy system replacement using strangler fig pattern.
  """

  use GenServer
  require Logger

  @migration_check_interval_ms :timer.hours(1)

  defstruct [
    :migration_registry,
    :active_migrations,
    :traffic_split_configs,
    :health_checks,
    :last_check_at,
    status: :monitoring
  ]

  @spec start_link(keyword()) :: GenServer.on_start()
  def start_link(opts \\ []) do
    GenServer.start_link(__MODULE__, opts, name: __MODULE__)
  end

  @impl true
  def init(_opts) do
    registry = load_migration_registry()
    schedule_migration_check()
    {:ok, %__MODULE__{migration_registry: registry, active_migrations: []}}
  end

  @impl true
  def handle_info(:migration_check, state) do
    health = check_all_migration_health(state.migration_registry)
    recommendations = analyze_traffic_split_readiness(state.migration_registry)

    :telemetry.execute(
      [:prismatic, :agents, :strangler, :check],
      %{active_migrations: length(state.active_migrations)},
      %{healthy: health.healthy_count, unhealthy: health.unhealthy_count}
    )

    schedule_migration_check()

    {:noreply, %{state |
      health_checks: health,
      last_check_at: DateTime.utc_now()
    }}
  end

  @spec advance_migration(String.t(), float()) :: {:ok, map()} | {:error, term()}
  def advance_migration(component_id, new_traffic_percentage) do
    GenServer.call(__MODULE__, {:advance, component_id, new_traffic_percentage})
  end

  @impl true
  def handle_call({:advance, component_id, percentage}, _from, state) do
    with {:ok, migration} <- find_migration(state.migration_registry, component_id),
         :ok <- validate_health_prerequisites(migration),
         {:ok, updated} <- update_traffic_split(migration, percentage) do
      {:reply, {:ok, updated}, update_registry(state, updated)}
    else
      {:error, reason} -> {:reply, {:error, reason}, state}
    end
  end
end

Traffic Routing Strategy

The Strangler Pattern Specialist implements sophisticated traffic routing that enables gradual migration with real-time health monitoring.

Routing StrategyDescriptionUse Case
CanaryRoute small percentage to new systemInitial validation
A/B SplitDeterministic split based on request attributesComparative testing
ShadowSend copies to new system without using resultsPre-production validation
Gradual RampIncrementally increase new system trafficControlled rollout
Feature FlagRoute based on feature flag statePer-feature migration

Health Check Framework

Before any traffic split advancement, the specialist runs comprehensive health checks on both legacy and new implementations.

Health CheckThresholdBlock Advancement
Error rate< 0.1%Yes
Latency P95< 2x legacyYes
Data consistency100% matchYes
Resource usage< 1.5x legacyWarning
Test coverage> 90%Yes

GARDEN Integration

The Strangler Pattern Specialist coordinates closely with the GARDEN legacy knowledge system to extract patterns, algorithms, and domain knowledge from legacy repositories before replacement. This extraction process ensures that decades of accumulated domain knowledge are preserved and migrated to the new implementations rather than being lost during component replacement.

GARDEN RepositoryContentFilesExtraction StatusPriority
sig250+ OSINT providers1,200+85% extractedP1
prismatic-legacyBlackboard system, core logic1,30260% extractedP1
kuzu-exKuzuDB Elixir SDK4595% extractedP2
crisstalPattern matching engine28070% extractedP2
code-weaverCode generation templates15050% extractedP3
simple_geocoderGeocoding library35100% extractedComplete

Migration Risk Assessment

Before advancing any migration phase, the Strangler Pattern Specialist conducts a comprehensive risk assessment that evaluates both technical and operational risks associated with the migration step.

defmodule PrismaticAgents.StranglerPatternSpecialist.RiskAssessment do
  @moduledoc """
  Migration risk assessment for strangler pattern phase advancement.
  Evaluates technical and operational risks before traffic split changes.
  """

  @spec assess_migration_risk(map(), float()) :: {:ok, :acceptable} | {:error, :unacceptable, map()}
  def assess_migration_risk(migration, target_percentage) do
    risks = [
      assess_data_consistency_risk(migration),
      assess_performance_risk(migration),
      assess_rollback_capability(migration),
      assess_downstream_impact(migration, target_percentage),
      assess_monitoring_coverage(migration)
    ]

    max_risk = Enum.max_by(risks, & &1.score)
    total_risk = Enum.sum(Enum.map(risks, & &1.score)) / length(risks)

    cond do
      max_risk.score > 0.8 ->
        {:error, :unacceptable, %{reason: max_risk.category, score: max_risk.score}}
      total_risk > 0.6 ->
        {:error, :unacceptable, %{reason: :aggregate_risk, score: total_risk}}
      true ->
        {:ok, :acceptable}
    end
  end

  defp assess_data_consistency_risk(migration) do
    consistency_score = compare_output_consistency(
      migration.legacy_component,
      migration.new_component,
      migration.test_inputs
    )

    %{category: :data_consistency, score: 1.0 - consistency_score}
  end
end
Risk CategoryAssessment MethodAcceptable ThresholdBlocking
Data ConsistencyOutput comparison with 1,000+ test inputs< 0.1% divergenceYes
PerformanceBenchee comparison under realistic load< 2x legacy latencyYes
Rollback CapabilityVerified rollback procedure with test executionMust complete < 5 minYes
Downstream ImpactDependency analysis of all consumersNo breaking changesYes
Monitoring CoverageTelemetry event verification100% of key metrics coveredYes

Integration Points

Rollback Procedures

Every migration managed by the Strangler Pattern Specialist includes a documented and tested rollback procedure. Rollback capability is a non-negotiable prerequisite for advancing any migration phase, as the NO MERCY doctrine requires that no migration step can leave the platform in a state where reversal is impossible.

Rollback AspectRequirementVerification
Traffic RoutingInstant redirect back to legacy componentTested before each advancement
Data MigrationBackward-compatible schema changes onlySchema reversibility proven
ConfigurationFeature flags for instant toggleFlag state verified in staging
DependenciesBoth legacy and new dependencies availableDependency tree validated
State RecoveryStateful components preserve rollback stateState snapshot before advancement

The Strangler Pattern Specialist maintains rollback procedures as executable scripts that can be triggered manually by operators or automatically by the platform's health monitoring system. Each rollback procedure is tested quarterly to ensure it remains functional as the system evolves.

Migration Success Criteria

Before any migration component can be declared "eliminated" (fully migrated), it must pass a comprehensive set of success criteria verified by both automated testing and manual review.

CriterionMeasurementThresholdAuthority
Functional EquivalenceOutput comparison against 10,000+ test cases100% matchAutomated
Performance ParityBenchmark comparison under production loadWithin 10% of legacyAutomated
Zero DowntimeMonitoring during migration period0 user-visible errorsAutomated
Test CoverageNew implementation test coverage> 95% line coverageAutomated
DocumentationMigration report with architectural decisionsComplete report filedManual review

AIAD Specification Compliance

AIAD ComponentStatus
Agent specification fileCompliant
Behavioral rules12 rules defined
Telemetry integrationFull coverage
NM/ND doctrine enforcementActive
SEADF integrationRegistered

Authority Level

L3 - Strategic Command - Multi-domain coordination with authority to manage legacy system replacement across the platform's umbrella applications.


Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL