Spaces:
Sleeping
Sleeping
Nitish commited on
Commit Β·
68fc10b
1
Parent(s): 36a39de
fix(inference): exactly match required LLM initialization and remove deterministic fallbacks
Browse files- inference.py +5 -72
inference.py
CHANGED
|
@@ -143,39 +143,7 @@ def run_task(task_id: str, task_num: int, client=None) -> dict:
|
|
| 143 |
# ββ LLM call ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 144 |
try:
|
| 145 |
if client is None:
|
| 146 |
-
|
| 147 |
-
if not file_requested:
|
| 148 |
-
action_dict = {"request_file": True}
|
| 149 |
-
file_requested = True
|
| 150 |
-
elif task_id == "python-off-by-one":
|
| 151 |
-
action_dict = {
|
| 152 |
-
"bug_identified": True,
|
| 153 |
-
"bug_location": "line 3",
|
| 154 |
-
"bug_type": "off-by-one",
|
| 155 |
-
"bug_description": "loop range(len(transactions) + 1) index error off-by-one out of bounds error",
|
| 156 |
-
"severity": "medium",
|
| 157 |
-
"suggested_fix": "range(len(transactions))",
|
| 158 |
-
}
|
| 159 |
-
elif task_id == "js-idor-auth":
|
| 160 |
-
action_dict = {
|
| 161 |
-
"bug_identified": True,
|
| 162 |
-
"bug_location": "line 4 β no check that req.user.id matches req.params.userId",
|
| 163 |
-
"bug_type": "logic-error",
|
| 164 |
-
"bug_description": "idor insecure direct object reference authorization horizontal privilege escalation missing check req.user params.userId ownership access control",
|
| 165 |
-
"severity": "high",
|
| 166 |
-
"suggested_fix": "Add check req.user.id === req.params.userId else return 403 Forbidden",
|
| 167 |
-
}
|
| 168 |
-
else:
|
| 169 |
-
action_dict = {
|
| 170 |
-
"bug_identified": True,
|
| 171 |
-
"bug_location": "line 4",
|
| 172 |
-
"bug_type": "security-vulnerability",
|
| 173 |
-
"bug_description": "deserialization pickle rce arbitrary code execution loads magic exploit un-serialize cve untrusted payload",
|
| 174 |
-
"severity": "critical",
|
| 175 |
-
"suggested_fix": "json.loads or safe_load",
|
| 176 |
-
}
|
| 177 |
-
action_str = json.dumps(action_dict)
|
| 178 |
-
error = None
|
| 179 |
else:
|
| 180 |
# Multi-turn: build conversation history
|
| 181 |
if not messages:
|
|
@@ -198,38 +166,8 @@ def run_task(task_id: str, task_num: int, client=None) -> dict:
|
|
| 198 |
error = None
|
| 199 |
except Exception as exc:
|
| 200 |
error = str(exc).replace("\n", " ")
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
action_dict = {"request_file": True}
|
| 204 |
-
file_requested = True
|
| 205 |
-
elif task_id == "python-off-by-one":
|
| 206 |
-
action_dict = {
|
| 207 |
-
"bug_identified": True,
|
| 208 |
-
"bug_location": "line 3 - range(len(transactions) + 1)",
|
| 209 |
-
"bug_type": "off-by-one",
|
| 210 |
-
"bug_description": "loop range(len(transactions) + 1) index error off-by-one out of bounds error",
|
| 211 |
-
"severity": "medium",
|
| 212 |
-
"suggested_fix": "Change range(len(transactions) + 1) to range(len(transactions))",
|
| 213 |
-
}
|
| 214 |
-
elif task_id == "js-idor-auth":
|
| 215 |
-
action_dict = {
|
| 216 |
-
"bug_identified": True,
|
| 217 |
-
"bug_location": "line 4 - no check that req.user.id matches req.params.userId",
|
| 218 |
-
"bug_type": "logic-error",
|
| 219 |
-
"bug_description": "idor insecure direct object reference authorization horizontal privilege escalation missing check req.user params.userId ownership access control",
|
| 220 |
-
"severity": "high",
|
| 221 |
-
"suggested_fix": "Add check req.user.id === req.params.userId else return 403 Forbidden",
|
| 222 |
-
}
|
| 223 |
-
else:
|
| 224 |
-
action_dict = {
|
| 225 |
-
"bug_identified": True,
|
| 226 |
-
"bug_location": "line 11 - pickle.loads(cached) deserializes untrusted Redis data",
|
| 227 |
-
"bug_type": "security-vulnerability",
|
| 228 |
-
"bug_description": "pickle deserializ untrusted redis cache arbitrary code execution rce cache poisoning validate hmac signature injection",
|
| 229 |
-
"severity": "critical",
|
| 230 |
-
"suggested_fix": "Replace pickle with json serialization and validate cache with hmac signature",
|
| 231 |
-
}
|
| 232 |
-
action_str = json.dumps(action_dict)
|
| 233 |
|
| 234 |
# ββ Step env ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 235 |
step_resp = env_post("/step", data=action_dict)
|
|
@@ -264,14 +202,9 @@ def main():
|
|
| 264 |
|
| 265 |
client = None
|
| 266 |
try:
|
| 267 |
-
|
| 268 |
-
client = OpenAI(base_url=os.environ["API_BASE_URL"], api_key=os.environ["API_KEY"])
|
| 269 |
-
else:
|
| 270 |
-
if not API_KEY:
|
| 271 |
-
raise ValueError("API_KEY or HF_TOKEN must be set.")
|
| 272 |
-
client = OpenAI(base_url=API_BASE_URL, api_key=API_KEY)
|
| 273 |
except Exception as exc:
|
| 274 |
-
print(f"[WARN] Client init failed: {exc}
|
| 275 |
|
| 276 |
TASK_FILTER = os.environ.get("TASK")
|
| 277 |
|
|
|
|
| 143 |
# ββ LLM call ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 144 |
try:
|
| 145 |
if client is None:
|
| 146 |
+
raise ValueError("OpenAI client was not initialized. Proxy evaluation cannot proceed.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
else:
|
| 148 |
# Multi-turn: build conversation history
|
| 149 |
if not messages:
|
|
|
|
| 166 |
error = None
|
| 167 |
except Exception as exc:
|
| 168 |
error = str(exc).replace("\n", " ")
|
| 169 |
+
print(f"\n[CRITICAL ERROR] LLM CALL FAILED: {error}\n", flush=True)
|
| 170 |
+
raise exc # Fail fast to see the real error instead of silently falling back
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
# ββ Step env ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 173 |
step_resp = env_post("/step", data=action_dict)
|
|
|
|
| 202 |
|
| 203 |
client = None
|
| 204 |
try:
|
| 205 |
+
client = OpenAI(base_url=os.environ["API_BASE_URL"], api_key=os.environ["API_KEY"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
except Exception as exc:
|
| 207 |
+
print(f"[WARN] Client init failed: {exc}", flush=True)
|
| 208 |
|
| 209 |
TASK_FILTER = os.environ.get("TASK")
|
| 210 |
|