opencode-mission-control
opencode-mission-control copied to clipboard
feat: Capture failure artifacts on job failure (terminal output, diff, env)
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:
- In
monitor.tswhen a pane death is detected with non-zero exit, capture terminal output before the pane is cleaned up. - In
orchestrator.tswhen marking a job as failed, rungit diff --statandgit log --onelinein the worktree. - Store artifacts as JSON files:
{dataDir}/artifacts/{jobId}.json. - Surface in
mc_statuswhen viewing a failed job. - Include in
mc_overviewalerts section.
Files Involved
src/lib/orchestrator.ts:742— job failure handlingsrc/lib/monitor.ts— pane death detectionsrc/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)."