models
models
¶
Data models for the global learning store.
This module contains all dataclasses and enums used by the GlobalLearningStore. These models represent the various records stored in the SQLite database for cross-workspace pattern persistence and learning.
Extracted from global_store.py as part of the modularization effort.
Classes¶
QuarantineStatus
¶
Bases: str, Enum
Status of a pattern in the quarantine lifecycle.
v19 Evolution: Pattern Quarantine & Provenance - patterns transition through these states as they are validated through successful applications:
- PENDING: New patterns start here, awaiting initial validation
- QUARANTINED: Explicitly marked for review due to concerns
- VALIDATED: Proven effective through repeated successful applications
- RETIRED: No longer active, kept for historical reference
Attributes¶
PENDING
class-attribute
instance-attribute
¶
New pattern awaiting validation through application.
QUARANTINED
class-attribute
instance-attribute
¶
Pattern under review - may have caused issues or needs investigation.
VALIDATED
class-attribute
instance-attribute
¶
Pattern has proven effective and is trusted for autonomous application.
RETIRED
class-attribute
instance-attribute
¶
Pattern no longer in active use, retained for history.
SuccessFactors
dataclass
¶
SuccessFactors(validation_types=list(), error_categories=list(), prior_sheet_status=None, time_of_day_bucket=None, retry_iteration=0, escalation_was_pending=False, grounding_confidence=None, occurrence_count=1, success_rate=1.0)
Captures WHY a pattern succeeded - the context conditions and factors.
v22 Evolution: Metacognitive Pattern Reflection - patterns now capture not just WHAT happened but WHY it worked. This enables better pattern selection by understanding causality, not just correlation.
Success factors include: - Context conditions: validation types, error categories, execution phase - Timing factors: time of day, retry iteration, prior sheet outcomes - Prerequisite states: prior sheet completion, escalation status
Attributes¶
validation_types
class-attribute
instance-attribute
¶
Validation types that were active: file, regex, artifact, etc.
error_categories
class-attribute
instance-attribute
¶
Error categories present in the execution: rate_limit, auth, validation, etc.
prior_sheet_status
class-attribute
instance-attribute
¶
Status of the immediately prior sheet: completed, failed, skipped.
time_of_day_bucket
class-attribute
instance-attribute
¶
Time bucket: morning, afternoon, evening, night.
retry_iteration
class-attribute
instance-attribute
¶
Which retry attempt this success occurred on (0 = first attempt).
escalation_was_pending
class-attribute
instance-attribute
¶
Whether an escalation was pending when pattern succeeded.
grounding_confidence
class-attribute
instance-attribute
¶
Grounding confidence score if external validation was present.
occurrence_count
class-attribute
instance-attribute
¶
How often this factor combination has been observed.
success_rate
class-attribute
instance-attribute
¶
Success rate when these factors are present (0.0-1.0).
Functions¶
__post_init__
¶
Clamp success_rate and occurrence_count to valid bounds.
to_dict
¶
Serialize to dictionary for JSON storage.
Source code in src/marianne/learning/store/models.py
from_dict
classmethod
¶
Deserialize from dictionary.
Source code in src/marianne/learning/store/models.py
get_time_bucket
staticmethod
¶
Get time bucket for an hour (0-23).
Source code in src/marianne/learning/store/models.py
ExecutionRecord
dataclass
¶
ExecutionRecord(id, workspace_hash, job_hash, sheet_num, started_at, completed_at, duration_seconds, status, retry_count, success_without_retry, validation_pass_rate, confidence_score, model, error_codes=list())
A record of a sheet execution stored in the global database.
Functions¶
__post_init__
¶
Clamp fields to valid ranges.
Source code in src/marianne/learning/store/models.py
PatternRecord
dataclass
¶
PatternRecord(id, pattern_type, pattern_name, description, occurrence_count, first_seen, last_seen, last_confirmed, led_to_success_count, led_to_failure_count, effectiveness_score, variance, suggested_action, context_tags, priority_score, quarantine_status=PENDING, provenance_job_hash=None, provenance_sheet_num=None, quarantined_at=None, validated_at=None, quarantine_reason=None, trust_score=0.5, trust_calculation_date=None, success_factors=None, success_factors_updated_at=None, active=True, content_hash=None, instrument_name=None)
A pattern record stored in the global database.
v19 Evolution: Extended with quarantine_status, provenance, and trust_score fields to support the Pattern Quarantine & Provenance and Pattern Trust Scoring evolutions.
Attributes¶
quarantine_status
class-attribute
instance-attribute
¶
quarantine_status = PENDING
Current status in the quarantine lifecycle.
provenance_job_hash
class-attribute
instance-attribute
¶
Hash of the job that first created this pattern.
provenance_sheet_num
class-attribute
instance-attribute
¶
Sheet number where this pattern was first observed.
quarantined_at
class-attribute
instance-attribute
¶
When the pattern was moved to QUARANTINED status.
validated_at
class-attribute
instance-attribute
¶
When the pattern was moved to VALIDATED status.
quarantine_reason
class-attribute
instance-attribute
¶
Reason for quarantine (if quarantined).
trust_score
class-attribute
instance-attribute
¶
Trust score (0.0-1.0). 0.5 is neutral, >0.7 is high trust.
trust_calculation_date
class-attribute
instance-attribute
¶
When trust_score was last calculated.
success_factors
class-attribute
instance-attribute
¶
WHY this pattern succeeds - captured context conditions and factors.
success_factors_updated_at
class-attribute
instance-attribute
¶
When success_factors were last updated.
active
class-attribute
instance-attribute
¶
Whether this pattern is active (False = soft-deleted).
content_hash
class-attribute
instance-attribute
¶
SHA-256 hash of pattern content for cross-name deduplication.
instrument_name
class-attribute
instance-attribute
¶
Backend instrument that produced this pattern (e.g., 'claude_cli').
Functions¶
__post_init__
¶
Clamp scored fields to valid ranges.
Source code in src/marianne/learning/store/models.py
ErrorRecoveryRecord
dataclass
¶
ErrorRecoveryRecord(id, error_code, suggested_wait, actual_wait, recovery_success, recorded_at, model, time_of_day)
A record of error recovery timing for learning adaptive waits.
RateLimitEvent
dataclass
¶
A rate limit event for cross-workspace coordination.
Evolution #8: Tracks rate limit events across workspaces so that parallel jobs can coordinate and avoid hitting the same rate limits.
EscalationDecisionRecord
dataclass
¶
EscalationDecisionRecord(id, job_hash, sheet_num, confidence, action, guidance, validation_pass_rate, retry_count, outcome_after_action=None, recorded_at=(lambda: now(tz=UTC))(), model=None)
A record of a human/AI escalation decision.
Evolution v11: Escalation Learning Loop - records escalation decisions to learn from feedback over time and potentially suggest actions for similar future escalations.
Attributes¶
confidence
instance-attribute
¶
Aggregate confidence score at time of escalation (0.0-1.0).
validation_pass_rate
instance-attribute
¶
Pass percentage of validations at escalation time.
outcome_after_action
class-attribute
instance-attribute
¶
What happened after the action: success, failed, aborted, skipped.
recorded_at
class-attribute
instance-attribute
¶
When the escalation decision was recorded.
PatternDiscoveryEvent
dataclass
¶
PatternDiscoveryEvent(id, pattern_id, pattern_name, pattern_type, source_job_hash, recorded_at, expires_at, effectiveness_score, context_tags=list())
A pattern discovery event for cross-job broadcasting.
v14 Evolution: Real-time Pattern Broadcasting - enables jobs to share newly discovered patterns with other concurrent jobs, so knowledge propagates across the ecosystem without waiting for aggregation.
DriftMetrics
dataclass
¶
DriftMetrics(pattern_id, pattern_name, window_size, effectiveness_before, effectiveness_after, grounding_confidence_avg, drift_magnitude, drift_direction, applications_analyzed, threshold_exceeded=False)
Metrics for pattern effectiveness drift detection.
v12 Evolution: Goal Drift Detection - tracks how pattern effectiveness changes over time to detect drifting patterns that may need attention.
Attributes¶
effectiveness_before
instance-attribute
¶
Effectiveness score in the older window (applications N-2W to N-W).
effectiveness_after
instance-attribute
¶
Effectiveness score in the recent window (applications N-W to N).
grounding_confidence_avg
instance-attribute
¶
Average grounding confidence across all applications in analysis.
drift_magnitude
instance-attribute
¶
Absolute magnitude of drift: |effectiveness_after - effectiveness_before|.
drift_direction
instance-attribute
¶
Direction of drift: 'positive', 'negative', or 'stable'.
applications_analyzed
instance-attribute
¶
Total number of applications analyzed (should be 2 × window_size).
threshold_exceeded
class-attribute
instance-attribute
¶
Whether drift_magnitude exceeds the alert threshold.
EpistemicDriftMetrics
dataclass
¶
EpistemicDriftMetrics(pattern_id, pattern_name, window_size, confidence_before, confidence_after, belief_change, belief_entropy, applications_analyzed, threshold_exceeded=False, drift_direction='stable')
Metrics for epistemic drift detection - tracking belief changes about patterns.
v21 Evolution: Epistemic Drift Detection - tracks how confidence/belief in patterns changes over time, complementing effectiveness drift. While effectiveness drift measures outcome changes, epistemic drift measures belief evolution.
This enables detection of belief degradation before effectiveness actually declines.
Attributes¶
confidence_before
instance-attribute
¶
Average grounding confidence in the older window (applications N-2W to N-W).
confidence_after
instance-attribute
¶
Average grounding confidence in the recent window (applications N-W to N).
belief_change
instance-attribute
¶
Change in belief/confidence: confidence_after - confidence_before.
belief_entropy
instance-attribute
¶
Entropy of confidence values (0 = consistent beliefs, 1 = high variance).
applications_analyzed
instance-attribute
¶
Total number of applications analyzed (should be 2 × window_size).
threshold_exceeded
class-attribute
instance-attribute
¶
Whether belief_change magnitude exceeds the alert threshold.
drift_direction
class-attribute
instance-attribute
¶
Direction of belief drift: 'strengthening', 'weakening', or 'stable'.
EvolutionEntryInput
dataclass
¶
EvolutionEntryInput(cycle, evolutions_completed, evolutions_deferred, issue_classes, cv_avg, implementation_loc, test_loc, loc_accuracy, research_candidates_resolved=0, research_candidates_created=0, notes='')
Input parameters for recording an evolution trajectory entry.
Bundles the 11 parameters of record_evolution_entry() into a single object for cleaner API usage. The method still accepts individual kwargs for backward compatibility.
Attributes¶
evolutions_completed
instance-attribute
¶
Number of evolutions completed in this cycle.
evolutions_deferred
instance-attribute
¶
Number of evolutions deferred in this cycle.
issue_classes
instance-attribute
¶
Issue classes addressed (e.g., ['infrastructure_activation']).
research_candidates_resolved
class-attribute
instance-attribute
¶
Number of research candidates resolved.
research_candidates_created
class-attribute
instance-attribute
¶
Number of new research candidates created.
EvolutionTrajectoryEntry
dataclass
¶
EvolutionTrajectoryEntry(id, cycle, recorded_at, evolutions_completed, evolutions_deferred, issue_classes, cv_avg, implementation_loc, test_loc, loc_accuracy, research_candidates_resolved=0, research_candidates_created=0, notes='')
A record of a single evolution cycle in Marianne's self-improvement trajectory.
v16 Evolution: Evolution Trajectory Tracking - enables Marianne to track its own evolution history, identifying recurring issue classes and measuring improvement over time.
Attributes¶
evolutions_completed
instance-attribute
¶
Number of evolutions completed in this cycle.
evolutions_deferred
instance-attribute
¶
Number of evolutions deferred in this cycle.
issue_classes
instance-attribute
¶
Issue classes addressed (e.g., 'infrastructure_activation', 'epistemic_drift').
research_candidates_resolved
class-attribute
instance-attribute
¶
Number of research candidates resolved in this cycle.
research_candidates_created
class-attribute
instance-attribute
¶
Number of new research candidates created in this cycle.
PatternEntropyMetrics
dataclass
¶
PatternEntropyMetrics(calculated_at, shannon_entropy, max_possible_entropy, diversity_index, unique_pattern_count, effective_pattern_count, total_applications, dominant_pattern_share, threshold_exceeded=False)
Metrics for pattern population Shannon entropy analysis.
Used by the patterns-entropy CLI command to monitor pattern diversity.
Shannon entropy measures how evenly patterns are used across the population:
high entropy indicates healthy diversity, low entropy signals collapse risk.
Attributes¶
shannon_entropy
instance-attribute
¶
Shannon entropy in bits: -sum(p * log2(p)) for each pattern probability.
max_possible_entropy
instance-attribute
¶
Maximum possible entropy: log2(unique_pattern_count).
diversity_index
instance-attribute
¶
Normalized diversity: shannon_entropy / max_possible_entropy (0.0-1.0).
unique_pattern_count
instance-attribute
¶
Total number of unique patterns in the population.
effective_pattern_count
instance-attribute
¶
Number of patterns with at least one application.
total_applications
instance-attribute
¶
Total number of pattern applications across all patterns.
dominant_pattern_share
instance-attribute
¶
Fraction of applications held by the most-used pattern (0.0-1.0).
threshold_exceeded
class-attribute
instance-attribute
¶
Whether diversity_index fell below the alert threshold (set by caller).
ExplorationBudgetRecord
dataclass
¶
ExplorationBudgetRecord(id, job_hash, recorded_at, budget_value, entropy_at_time, adjustment_type, adjustment_reason=None)
A record of exploration budget state over time.
v23 Evolution: Exploration Budget Maintenance - tracks the dynamic exploration budget to prevent convergence to zero. The budget adjusts based on pattern entropy observations.
Attributes¶
entropy_at_time
instance-attribute
¶
Pattern entropy at time of recording (if measured).
adjustment_type
instance-attribute
¶
Type of adjustment: 'initial', 'decay', 'boost', 'floor_enforced'.
adjustment_reason
class-attribute
instance-attribute
¶
Human-readable reason for this adjustment.
EntropyResponseRecord
dataclass
¶
EntropyResponseRecord(id, job_hash, recorded_at, entropy_at_trigger, threshold_used, actions_taken, budget_boosted=False, quarantine_revisits=0, patterns_revisited=list())
A record of an automatic entropy response event.
v23 Evolution: Automatic Entropy Response - records when the system automatically responded to low entropy conditions by injecting diversity.
Attributes¶
entropy_at_trigger
instance-attribute
¶
The entropy value that triggered this response.
actions_taken
instance-attribute
¶
List of actions taken: 'budget_boost', 'quarantine_revisit', etc.
budget_boosted
class-attribute
instance-attribute
¶
Whether the exploration budget was boosted.
quarantine_revisits
class-attribute
instance-attribute
¶
Number of quarantined patterns revisited.
patterns_revisited
class-attribute
instance-attribute
¶
IDs of patterns that were marked for revisit.