Parthiban007 commited on
Commit
7d402e0
Β·
verified Β·
1 Parent(s): 830582d

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. server/rust_coder_environment.py +3 -104
server/rust_coder_environment.py CHANGED
@@ -6,7 +6,6 @@ Multi-dimensional reward system: Compilation(40%), Correctness(20%),
6
  Coverage(20%), Elegance(10%), Efficiency(10%).
7
  """
8
 
9
- import json
10
  import os
11
  import re
12
  import subprocess
@@ -71,29 +70,6 @@ class RustCoderEnvironment(Environment):
71
  self.current_problem_idx: int = 0
72
  self.step_count: int = 0
73
 
74
- # #region agent log
75
- self._debug_log_path = os.getenv("DEBUG_LOG_PATH") or "debug-55b5ef.log"
76
- self._debug_session_id = "55b5ef"
77
- # #endregion
78
-
79
- # #region agent log
80
- def _dbg(self, hypothesis_id: str, location: str, message: str, data: dict, run_id: str = "pre-fix") -> None:
81
- try:
82
- payload = {
83
- "sessionId": self._debug_session_id,
84
- "runId": run_id,
85
- "hypothesisId": hypothesis_id,
86
- "location": location,
87
- "message": message,
88
- "data": data,
89
- "timestamp": int(time.time() * 1000),
90
- }
91
- with open(self._debug_log_path, "a", encoding="utf-8") as f:
92
- f.write(json.dumps(payload, ensure_ascii=False) + "\n")
93
- except Exception:
94
- pass
95
- # #endregion
96
-
97
  # ------------------------------------------------------------------
98
  # Internal helpers
99
  # ------------------------------------------------------------------
@@ -145,19 +121,6 @@ class RustCoderEnvironment(Environment):
145
  code = action.code
146
  header = problem.get("header_section", "")
147
 
148
- self._dbg(
149
- "H1",
150
- "server/rust_coder_environment.py:step:entry",
151
- "env.step called",
152
- {
153
- "step_count": self.step_count,
154
- "problem_id": problem.get("id"),
155
- "title": problem.get("title"),
156
- "code_chars": len(code or ""),
157
- "code_is_empty": not bool((code or "").strip()),
158
- },
159
- )
160
-
161
  if not code.strip():
162
  # Some UIs may "step" without providing an action payload.
163
  # Optionally auto-generate code via LLM so the UI can still progress.
@@ -173,13 +136,6 @@ class RustCoderEnvironment(Environment):
173
  header = problem.get("header_section", "")
174
  if header:
175
  prompt += f"\n\nHeader Section (must be included verbatim in your final code):\n```rust\n{header}\n```"
176
-
177
- self._dbg(
178
- "H5",
179
- "server/rust_coder_environment.py:step:auto_llm",
180
- "AUTO_LLM_ON_EMPTY_STEP enabled; attempting LLM generation",
181
- {"model": model, "base_url": base_url, "prompt_chars": len(prompt), "token_present": bool(token)},
182
- )
183
  self._logger.info(
184
  "Auto-LLM on empty step: model=%s base_url=%s prompt_chars=%d token_present=%s",
185
  model,
@@ -224,28 +180,10 @@ class RustCoderEnvironment(Environment):
224
  text = text.strip()
225
  if text:
226
  code = text
227
- self._dbg(
228
- "H5",
229
- "server/rust_coder_environment.py:step:auto_llm_ok",
230
- "LLM produced non-empty code; continuing evaluation",
231
- {"code_chars": len(code)},
232
- )
233
  self._logger.info("Auto-LLM generated code chars=%d", len(code))
234
  else:
235
- self._dbg(
236
- "H5",
237
- "server/rust_coder_environment.py:step:auto_llm_empty",
238
- "LLM returned empty after cleanup; falling back to empty submission behavior",
239
- {"raw_chars": len((completion.choices[0].message.content or ""))},
240
- )
241
  self._logger.warning("Auto-LLM returned empty after cleanup.")
242
  except Exception as e:
243
- self._dbg(
244
- "H5",
245
- "server/rust_coder_environment.py:step:auto_llm_error",
246
- "LLM call failed; falling back to empty submission behavior",
247
- {"error": str(e)},
248
- )
249
  self._logger.exception("Auto-LLM call failed.")
250
 
251
  if not code.strip():
@@ -256,12 +194,6 @@ class RustCoderEnvironment(Environment):
256
  problem.get("id"),
257
  problem.get("title"),
258
  )
259
- self._dbg(
260
- "H1",
261
- "server/rust_coder_environment.py:step:empty",
262
- "empty code branch taken",
263
- {"step_count": self.step_count, "problem_id": problem.get("id")},
264
- )
265
  done = False
266
  return RustCoderObservation(
267
  problem_description=problem["description"],
@@ -280,42 +212,9 @@ class RustCoderEnvironment(Environment):
280
  reward=0.0,
281
  )
282
 
283
- # #region agent log
284
- # Debug why header checks fail: don't log secrets, only lengths/booleans.
285
- self._dbg(
286
- "H6",
287
- "server/rust_coder_environment.py:step:pre_eval",
288
- "pre-eval header/code relationship",
289
- {
290
- "header_chars": len(header or ""),
291
- "code_chars": len(code or ""),
292
- "header_substring_match": bool(header and header.strip() and (header.strip() in (code or ""))),
293
- "header_first80": (header or "")[:80],
294
- },
295
- )
296
- # #endregion
297
-
298
- # Do NOT mutate submissions by injecting header_section.
299
- # LeetCode-style behavior: the agent/LLM must return a complete Rust file
300
- # that already includes the required header_section.
301
- if header and header.strip() and header.strip() not in (code or ""):
302
- done = False
303
- return RustCoderObservation(
304
- problem_description=problem.get("description", ""),
305
- header_section=header,
306
- compilation_success=False,
307
- compilation_output="Error: submission is missing the required header_section. Return the complete Rust code including the header_section.",
308
- test_results=[],
309
- reward_breakdown={
310
- "compilation": 0.0,
311
- "correctness": 0.0,
312
- "coverage": 0.0,
313
- "elegance": 0.0,
314
- "efficiency": 0.0,
315
- },
316
- done=done,
317
- reward=0.0,
318
- )
319
 
320
  # ── 1. Compilation (40%) ──────────────────────────────────────
321
  compilation_success, compilation_output = self._compile_check(code)
 
6
  Coverage(20%), Elegance(10%), Efficiency(10%).
7
  """
8
 
 
9
  import os
10
  import re
11
  import subprocess
 
70
  self.current_problem_idx: int = 0
71
  self.step_count: int = 0
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  # ------------------------------------------------------------------
74
  # Internal helpers
75
  # ------------------------------------------------------------------
 
121
  code = action.code
122
  header = problem.get("header_section", "")
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  if not code.strip():
125
  # Some UIs may "step" without providing an action payload.
126
  # Optionally auto-generate code via LLM so the UI can still progress.
 
136
  header = problem.get("header_section", "")
137
  if header:
138
  prompt += f"\n\nHeader Section (must be included verbatim in your final code):\n```rust\n{header}\n```"
 
 
 
 
 
 
 
139
  self._logger.info(
140
  "Auto-LLM on empty step: model=%s base_url=%s prompt_chars=%d token_present=%s",
141
  model,
 
180
  text = text.strip()
181
  if text:
182
  code = text
 
 
 
 
 
 
183
  self._logger.info("Auto-LLM generated code chars=%d", len(code))
184
  else:
 
 
 
 
 
 
185
  self._logger.warning("Auto-LLM returned empty after cleanup.")
186
  except Exception as e:
 
 
 
 
 
 
187
  self._logger.exception("Auto-LLM call failed.")
188
 
189
  if not code.strip():
 
194
  problem.get("id"),
195
  problem.get("title"),
196
  )
 
 
 
 
 
 
197
  done = False
198
  return RustCoderObservation(
199
  problem_description=problem["description"],
 
212
  reward=0.0,
213
  )
214
 
215
+ # LeetCode-style header_section is provided as a scaffold/hint in the observation
216
+ # and in the prompt, but we do NOT require it to appear verbatim in submissions.
217
+ # Correctness is enforced by compilation + the problem's tests.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
219
  # ── 1. Compilation (40%) ──────────────────────────────────────
220
  compilation_success, compilation_output = self._compile_check(code)