executions
executions
¶
Execution-related mixin for GlobalLearningStore.
This module provides the ExecutionMixin class that handles all execution-related operations including: - Recording sheet execution outcomes - Querying execution statistics - Finding similar historical executions - Workspace clustering for cross-workspace learning - Optimal execution window analysis
Extracted from global_store.py as part of the modularization effort.
Attributes¶
Classes¶
ExecutionMixin
¶
Mixin providing execution-related methods for GlobalLearningStore.
This mixin requires that the composed class provides: - _get_connection(): Context manager yielding sqlite3.Connection - _logger: Logger instance for logging - hash_workspace(workspace_path): Static method to hash workspace paths - hash_job(job_name, config_hash): Static method to hash job identifiers
Execution Recording Methods: - record_outcome: Record a sheet execution outcome - _extract_sheet_num: Helper to parse sheet numbers from IDs - _calculate_confidence: Calculate confidence score for an outcome
Execution Statistics Methods: - get_execution_stats: Get aggregate statistics from the global store - get_recent_executions: Get recent execution records
Similar Executions Methods (Learning Activation): - get_similar_executions: Find similar historical executions - get_optimal_execution_window: Analyze optimal times for execution
Workspace Clustering Methods: - get_workspace_cluster: Get cluster ID for a workspace - assign_workspace_cluster: Assign a workspace to a cluster - get_similar_workspaces: Get workspaces in the same cluster
Functions¶
record_outcome
¶
Record a sheet outcome to the global store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outcome
|
SheetOutcome
|
The SheetOutcome to record. |
required |
workspace_path
|
Path
|
Path to the workspace for hashing. |
required |
model
|
str | None
|
Optional model name used for execution. |
None
|
error_codes
|
list[str] | None
|
Optional list of error codes encountered. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The execution record ID. |
Source code in src/marianne/learning/store/executions.py
get_execution_stats
¶
Get aggregate statistics from the global store.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with stats like total_executions, success_rate, etc. |
Source code in src/marianne/learning/store/executions.py
get_recent_executions
¶
Get recent execution records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum number of records to return. |
20
|
workspace_hash
|
str | None
|
Optional filter by workspace. |
None
|
Returns:
| Type | Description |
|---|---|
list[ExecutionRecord]
|
List of ExecutionRecord objects. |
Source code in src/marianne/learning/store/executions.py
get_similar_executions
¶
Get similar historical executions for learning.
Learning Activation: Enables querying executions that are similar to the current context, supporting pattern-based decision making.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_hash
|
str | None
|
Optional job hash to filter by similar jobs. |
None
|
workspace_hash
|
str | None
|
Optional workspace hash to filter by. |
None
|
sheet_num
|
int | None
|
Optional sheet number to filter by. |
None
|
limit
|
int
|
Maximum number of records to return. |
10
|
Returns:
| Type | Description |
|---|---|
list[ExecutionRecord]
|
List of ExecutionRecord objects matching the criteria. |
Source code in src/marianne/learning/store/executions.py
get_optimal_execution_window
¶
Analyze historical data to find optimal execution windows.
Learning Activation: Identifies times of day when executions are most likely to succeed, enabling time-aware scheduling recommendations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_code
|
str | None
|
Optional error code to analyze (e.g., for rate limits). |
None
|
model
|
str | None
|
Optional model to filter by. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with optimal window analysis: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Source code in src/marianne/learning/store/executions.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
get_workspace_cluster
¶
Get the cluster ID for a workspace.
Learning Activation: Supports workspace similarity by grouping workspaces with similar patterns into clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace_hash
|
str
|
Hash of the workspace to query. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Cluster ID if assigned, None otherwise. |
Source code in src/marianne/learning/store/executions.py
assign_workspace_cluster
¶
Assign a workspace to a cluster.
Learning Activation: Groups workspaces with similar execution patterns for targeted pattern recommendations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace_hash
|
str
|
Hash of the workspace. |
required |
cluster_id
|
str
|
ID of the cluster to assign to. |
required |
Source code in src/marianne/learning/store/executions.py
get_similar_workspaces
¶
Get workspace hashes in the same cluster.
Learning Activation: Enables cross-workspace learning by identifying workspaces with similar patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cluster_id
|
str
|
Cluster ID to query. |
required |
limit
|
int
|
Maximum number of workspace hashes to return. |
10
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of workspace hashes in the cluster. |
Source code in src/marianne/learning/store/executions.py
record_error_recovery
¶
Record an error recovery for learning adaptive wait times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_code
|
str
|
The error code (e.g., 'E103'). |
required |
suggested_wait
|
float
|
The initially suggested wait time in seconds. |
required |
actual_wait
|
float
|
The actual wait time used in seconds. |
required |
recovery_success
|
bool
|
Whether recovery after waiting succeeded. |
required |
model
|
str | None
|
Optional model name. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The recovery record ID. |
Source code in src/marianne/learning/store/executions.py
get_learned_wait_time
¶
Get the learned optimal wait time for an error code.
Analyzes past error recoveries to suggest an adaptive wait time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_code
|
str
|
The error code to look up. |
required |
model
|
str | None
|
Optional model to filter by. |
None
|
min_samples
|
int
|
Minimum samples required before learning. |
3
|
Returns:
| Type | Description |
|---|---|
float | None
|
Suggested wait time in seconds, or None if not enough data. |
Source code in src/marianne/learning/store/executions.py
get_learned_wait_time_with_fallback
¶
get_learned_wait_time_with_fallback(error_code, static_delay, model=None, min_samples=3, min_confidence=0.7)
Get learned wait time with fallback to static delay and confidence.
This method bridges the global learning store with retry strategies. It returns a delay value along with a confidence score indicating how much to trust the learned value.
Evolution #3: Learned Wait Time Injection - provides the bridge between global_store's cross-workspace learned delays and retry_strategy's blend_historical_delay() method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_code
|
str
|
The error code to look up (e.g., 'E101'). |
required |
static_delay
|
float
|
Fallback static delay if no learned data available. |
required |
model
|
str | None
|
Optional model to filter by. |
None
|
min_samples
|
int
|
Minimum samples required for learning. |
3
|
min_confidence
|
float
|
Minimum confidence threshold for using learned delay. |
0.7
|
Returns:
| Type | Description |
|---|---|
float
|
Tuple of (delay_seconds, confidence, strategy_name). |
float
|
|
str
|
|
tuple[float, float, str]
|
|
Source code in src/marianne/learning/store/executions.py
get_error_recovery_sample_count
¶
Get the number of successful recovery samples for an error code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_code
|
str
|
The error code to query. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of successful recovery samples. |