File size: 5,266 Bytes
276a6a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# CI/CD Pipeline Debugger Environment (OpenEnv)

## 1. Project Goal

This repository implements an AI training and evaluation environment where an agent learns to debug broken CI/CD pipelines automatically.

The environment targets real-world DevOps failure patterns, including:

- YAML syntax and structure issues
- Incorrect build/test commands (for example, npm tset -> npm test)
- Dependency and setup failures
- Multi-stage pipeline execution errors

This is designed as an RL-style interaction loop:

Observe -> Think -> Act -> Get Reward -> Repeat

## 2. Why This Matters

CI/CD failures are common, repetitive, and often multi-step to resolve. This project turns that workflow into a structured learning environment where agents:

- Read failure context
- Reason about root causes
- Propose and apply fixes
- Get shaped rewards for robust behavior

## 3. System Architecture

High-level flow:

Agent (LLM) -> Action -> Environment.step() -> Reward/Evaluation -> Next step

Core integration path:

Model -> Action -> Environment.step() -> RewardCalculator

RewardCalculator integrates:

- DeterministicGrader
- LLMJudge
- HiddenTestRunner
- AntiHackingDetector

## 4. Core Modules

### 4.1 Quality Judge

- File: env/graders/llm_judge.py
- Purpose: quality-aware scoring of fixes
- Output keys: correctness, minimalism, quality (all in [0,1])
- Guarantees:
	- strict JSON parsing attempt
	- robust fallback parsing for messy output
	- no-crash behavior (safe zero scores on failure)

### 4.2 Deterministic Grader

- File: env/graders/deterministic.py
- Purpose: reproducible correctness scoring (0-1)
- Checks:
	- YAML validity
	- command and fix correctness
	- similarity and issue resolution
- Rules:
	- deterministic only
	- same input, same score

### 4.3 Anti-Hacking Detector

- File: env/anti_hacking.py
- Purpose: detect reward-hacking and shortcut behavior
- Penalty detectors:
	- stage skipping (if: false, when: never)
	- fake success (echo tests passed, unsafe exit 0 patterns)
	- pipeline breakage between versions
	- excessive edits
	- timeout abuse via too many steps

### 4.4 Hidden Tests

- File: env/hidden_tests.py
- Purpose: test fix robustness, not just exact-match overfitting
- Method:
	- deterministic variant generation (OS, versions, env shifts)
	- evaluate pass rate across variants

### 4.5 Reward Shaping

- File: env/rewards.py
- Purpose: step-level learning signal
- Components:
	- progress rewards (logs, analysis, fix proposal)
	- execution rewards (pipeline run, tests pass)
	- quality rewards (deterministic + hidden tests + LLM judge)
	- anti-hacking penalties

## 5. Inference and Evaluation

### 5.1 Prompt and Model Layers

- inference/prompts.py: stable prompt templates and fallback action heuristics
- inference/model_wrapper.py: OpenAI-client action generation, candidate generation, and safe fallback

### 5.2 Metrics and Artifacts

- inference/metrics.py: reward, success-rate, and failure reason tracking
- inference/visualize.py: reward curve and metrics artifact export

### 5.3 Submission-Critical Runtime

- File: inference.py (root)
- Responsibilities:
	- initialize model and environment
	- run step loop
	- calculate rewards
	- emit strict stdout contract
	- always emit END line

Required output format:

- [START] task=... env=... model=...
- [STEP] step=<n> action=... reward=0.00 done=<true|false> error=<msg|null>
- [END] success=<true|false> steps=<n> rewards=<r1,r2,...>

Rules enforced:

- single-line logs only
- reward values with 2 decimals
- lowercase booleans
- no extra runtime log noise

## 6. Task Coverage

The project includes 13 CI-fix tasks spanning:

- easy: syntax and typo fixes
- medium: dependency/env/cache/permissions issues
- hard: matrix logic, conditional flow, orchestration-level failures

## 7. Setup

```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```

Environment variables:

```bash
export API_BASE_URL="https://router.huggingface.co/v1"
export MODEL_NAME="Qwen/Qwen2.5-72B-Instruct"
export HF_TOKEN="<your_token>"
export LOCAL_IMAGE_NAME="<your_env_image_name>"
```

## 8. Run Inference

Offline/local mode:

```bash
python inference.py --offline --force-local-env --max-steps 8 --policy-mode imp --trajectories 4
```

Model-backed mode:

```bash
python inference.py --max-steps 8 --policy-mode imp --trajectories 4
```

Policy modes:

- sft: deterministic heuristic policy
- direct: single model action per step
- imp: multi-candidate generation and ranking

## 9. Tests

Run all tests:

```bash
python -m unittest discover -s tests -v
```

Coverage includes:

- LLM judge
- deterministic grader
- anti-hacking detectors
- hidden tests
- reward system
- end-to-end inference output format

## 10. Validation and Submission

OpenEnv validation:

```bash
openenv validate
```

Pre-submission script:

```bash
./validate-submission.sh <your_hf_space_url>
```

Docker run:

```bash
docker build -t cicd-debugger-env .
docker run --rm -e OFFLINE_INFERENCE=1 cicd-debugger-env
```

## 11. One-line Presentation Summary

We built an OpenEnv-compliant reinforcement learning environment where AI agents learn to debug real CI/CD pipelines using multi-step reasoning, hybrid grading, anti-hacking safeguards, and robust reward shaping.