diagnose
diagnose
¶
Diagnostic commands for Marianne CLI.
This module implements commands for inspecting job state and debugging issues:
- logs: View and follow log files
- errors: List errors for a job with filtering
- diagnose: Generate comprehensive diagnostic reports
★ Insight ─────────────────────────────────────
1. Layered debugging approach: The three commands form a debugging hierarchy:
logs for real-time streaming, errors for filtered error lists, and
diagnose for comprehensive reports. Users typically progress through
these as they narrow down issues.
-
Synthetic error records: When older state files lack error_history, the commands synthesize ErrorRecord objects from sheet-level error_message fields. This maintains backward compatibility with pre-history state files.
-
Error type inference: The
infer_error_typefunction categorizes errors into permanent/transient/rate_limit based on error_category strings. This enables appropriate color-coding and helps users understand retry behavior. ─────────────────────────────────────────────────
Attributes¶
Classes¶
LogFollower
¶
Parse, filter, and display structured log entries.
Extracted from the logs() command closures to enable unit testing
of log parsing, filtering, and formatting independently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_path
|
Path
|
Path to the log file. |
required |
job_id
|
str | None
|
Optional job ID filter (None = show all). |
None
|
min_level
|
int
|
Minimum log level (0=DEBUG, 1=INFO, 2=WARNING, 3=ERROR, 4=CRITICAL). |
0
|
json_output
|
bool
|
If True, output raw JSON instead of formatted lines. |
False
|
Source code in src/marianne/cli/commands/diagnose.py
Functions¶
parse_line
¶
Parse a JSON log line, returning None if blank.
Source code in src/marianne/cli/commands/diagnose.py
should_include
¶
Check if a log entry passes the configured filters.
Source code in src/marianne/cli/commands/diagnose.py
format_entry
¶
Format a log entry for Rich console display.
Source code in src/marianne/cli/commands/diagnose.py
read_lines
¶
Read lines from the log file (handles .gz compression).
Source code in src/marianne/cli/commands/diagnose.py
display
¶
Display filtered log entries.
Source code in src/marianne/cli/commands/diagnose.py
follow
¶
Follow log file for new entries (like tail -f).
Source code in src/marianne/cli/commands/diagnose.py
Functions¶
logs
¶
logs(job_id=Argument(None, help='Score ID to filter logs for (optional, shows all if not specified)'), workspace=Option(None, '--workspace', '-w', help='Workspace directory to find logs (debug override)', hidden=True), log_file=Option(None, '--file', '-f', help='Specific log file path (overrides workspace default)'), follow=Option(False, '--follow', '-F', help='Follow the log file for new entries (like tail -f)'), lines=Option(50, '--lines', '-n', help='Number of lines to show (0 for all)'), level=Option(None, '--level', '-l', help='Filter by minimum log level (DEBUG, INFO, WARNING, ERROR)'), json_output=Option(False, '--json', '-j', help='Output raw JSON log entries'))
Show or tail log files for a score.
Displays log entries from Marianne log files. Supports both current log files and compressed rotated logs (.gz).
Examples:
mzt logs # Show recent logs mzt logs my-job # Filter by job ID mzt logs --follow # Follow log file (like tail -f) mzt logs --lines 100 # Show last 100 lines mzt logs --level ERROR # Show only ERROR and above mzt logs --json # Output raw JSON entries
Note
Log files are stored at {workspace}/logs/marianne.log by default. Use --file to specify a different log file path.
Source code in src/marianne/cli/commands/diagnose.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 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 | |
errors
¶
errors(job_id=Argument(..., help='Score ID to show errors for'), sheet=Option(None, '--sheet', '-b', help='Filter errors by specific sheet number'), error_type=Option(None, '--type', '-t', help='Filter by error type: transient, rate_limit, or permanent'), error_code=Option(None, '--code', '-c', help='Filter by error code (e.g., E001, E101)'), verbose=Option(False, '--verbose', '-V', help='Show full stdout/stderr tails for each error'), workspace=Option(None, '--workspace', '-w', help='Workspace directory to search for score state (debug override)', hidden=True), json_output=Option(False, '--json', '-j', help='Output errors as JSON'))
List all errors for a score with detailed information.
Displays errors grouped by sheet, with color-coding by error type: - Red: Permanent errors (non-retriable, fatal) - Yellow: Transient errors (retriable with backoff) - Blue: Rate limit errors (retriable after wait)
Examples:
mzt errors my-job # Show all errors mzt errors my-job --sheet 3 # Errors for sheet 3 only mzt errors my-job --type transient # Only transient errors mzt errors my-job --code E001 # Only timeout errors mzt errors my-job --verbose # Show stdout/stderr details
Source code in src/marianne/cli/commands/diagnose.py
diagnose
¶
diagnose(job_id=Argument(..., help='Score ID to diagnose'), workspace=Option(None, '--workspace', '-w', help='Workspace directory (for scores not in conductor registry)'), json_output=Option(False, '--json', '-j', help='Output diagnostic report as JSON'), include_logs=Option(False, '--include-logs', help='Inline the last 50 lines from each sheet/hook log file in the output'), resources=Option(False, '--resources', help='Include resource profile (peak memory, CPU-time, syscalls, anomalies)'))
Generate a comprehensive diagnostic report for a score.
The diagnostic report includes: - Score overview and current status - Preflight warnings from all sheets - Prompt metrics (token counts, line counts) - Execution timeline with timing information - All errors with full context and output tails - Log file locations, sizes, and modification times - (with --include-logs) Inline log content from each log file - (with --resources) Resource profile from profiler data
This command is particularly useful for debugging failed scores or understanding why a score is running slowly.
Examples:
mzt diagnose my-job # Full diagnostic report mzt diagnose my-job --json # Machine-readable output mzt diagnose my-job --include-logs # Include inline log content mzt diagnose my-job --resources # Include resource profile
Source code in src/marianne/cli/commands/diagnose.py
history
¶
history(job_id=Argument(..., help='Score ID to show execution history for'), sheet=Option(None, '--sheet', '-b', help='Filter by specific sheet number'), limit=Option(50, '--limit', '-n', help='Maximum number of records to show'), workspace=Option(None, '--workspace', '-w', help='Workspace directory to search for score state (debug override)', hidden=True), json_output=Option(False, '--json', '-j', help='Output history as JSON'))
Show execution history for a score.
Displays a table of past execution attempts from the SQLite state backend, including sheet number, attempt number, exit code, duration, and timestamp.
Requires the SQLite state backend (execution history is not available with the JSON backend).
Examples:
mzt history my-job # Show all history mzt history my-job --sheet 3 # History for sheet 3 only mzt history my-job --limit 100 # Show more records mzt history my-job --json # Machine-readable output