File size: 1,796 Bytes
10dd572
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
export type RenderFailureCategory =
  | 'code'
  | 'resource'
  | 'timeout'
  | 'environment'
  | 'cancelled'

export interface RenderFailureDecision {
  category: RenderFailureCategory
  allowAiRepair: boolean
  reason: string
}

const NON_REPAIRABLE_FAILURES: Array<{
  category: Exclude<RenderFailureCategory, 'code'>
  pattern: RegExp
  reason: string
}> = [
  {
    category: 'cancelled',
    pattern: /(?:job cancelled|operation cancelled|render cancelled)/i,
    reason: 'render was cancelled'
  },
  {
    category: 'resource',
    pattern: /(?:MemoryError|Unable to allocate|out of memory|ENOMEM|paging file is too small)/i,
    reason: 'render exhausted available memory'
  },
  {
    category: 'timeout',
    pattern: /(?:render timeout|timed out|ETIMEDOUT)/i,
    reason: 'render exceeded its execution deadline'
  },
  {
    category: 'environment',
    pattern: /(?:ENOSPC|no space left on device|disk quota exceeded|read-only file system)/i,
    reason: 'render environment cannot write its output'
  },
  {
    category: 'environment',
    pattern: /(?:spawn manim ENOENT|No module named ['"]manim['"]|manim(?:\.exe)?: command not found)/i,
    reason: 'Manim runtime is unavailable'
  },
  {
    category: 'environment',
    pattern: /(?:Fatal Python error|access violation|segmentation fault)/i,
    reason: 'render runtime terminated fatally'
  }
]

export function classifyRenderFailure(stderr: string): RenderFailureDecision {
  for (const failure of NON_REPAIRABLE_FAILURES) {
    if (failure.pattern.test(stderr)) {
      return {
        category: failure.category,
        allowAiRepair: false,
        reason: failure.reason
      }
    }
  }

  return {
    category: 'code',
    allowAiRepair: true,
    reason: 'render failure may be repaired by changing code'
  }
}