opencode-mission-control icon indicating copy to clipboard operation
opencode-mission-control copied to clipboard

feat: Capture failure artifacts on job failure (terminal output, diff, env)

Open nigel-dev opened this issue 9 months ago • 0 comments

Description

When a job fails, MC only stores a string error message. The terminal output, git diff, commit history, and environment metadata are all lost — making post-mortem debugging nearly impossible without manually attaching to the (potentially already dead) tmux session.

Use Case

  • Debugging: "Why did job X fail?" — currently requires the tmux pane to still exist.
  • Pattern detection: Identify common failure modes across jobs (e.g., dependency install failures, test flakes).
  • Audit trail: Record what the agent actually did before failing.

Current Implementation

// src/lib/orchestrator.ts:742
error: error instanceof Error ? error.message : String(error),

Only a string error is stored. No terminal output, no diff, no context.

Proposed Solution

On job failure, automatically capture and persist:

interface FailureArtifact {
  jobId: string;
  jobName: string;
  timestamp: string;
  terminalOutput: string;     // Last N lines from tmux capture
  gitDiff?: string;           // git diff --stat in the job worktree
  gitLog?: string;            // git log --oneline of commits made
  errorMessage: string;       // The original error string
  exitCode?: number;          // Process exit code if available
  environment: {
    mode: string;
    branch: string;
    worktreePath: string;
    duration: number;
  };
}

Implementation:

  1. In monitor.ts when a pane death is detected with non-zero exit, capture terminal output before the pane is cleaned up.
  2. In orchestrator.ts when marking a job as failed, run git diff --stat and git log --oneline in the worktree.
  3. Store artifacts as JSON files: {dataDir}/artifacts/{jobId}.json.
  4. Surface in mc_status when viewing a failed job.
  5. Include in mc_overview alerts section.

Files Involved

  • src/lib/orchestrator.ts:742 — job failure handling
  • src/lib/monitor.ts — pane death detection
  • src/tools/status.ts — surface artifacts for failed jobs
  • New: src/lib/artifacts.ts — artifact capture and storage

Additional Context

From audit report Section 9 Phase 2: "Failure artifact capture (terminal output, diff, commits, env metadata)."

nigel-dev avatar Feb 12 '26 03:02 nigel-dev