YUS200619 commited on
Commit
7f888a4
·
1 Parent(s): 83ea4bd

optimize: Make state updates lazy and non-blocking with comprehensive error handling

Browse files
Files changed (1) hide show
  1. environment.py +28 -12
environment.py CHANGED
@@ -89,7 +89,10 @@ class SWEbenchINEnvironment:
89
  # Update state
90
  self._state.action_history.append(f"{action_type}: {action_args}")
91
  self._state.step_count += 1
92
- self._update_state()
 
 
 
93
 
94
  # Check done
95
  if action_type == "close_case" or self._state.step_count >= self.max_steps:
@@ -223,18 +226,31 @@ class SWEbenchINEnvironment:
223
  return "ERROR: Dispatch failed."
224
 
225
  def _update_state(self):
226
- """Refresh state measurements from live environment."""
227
- server = self.simulator.curl_server()
228
- self._state.server_running = server["success"]
229
-
230
- tests = self.simulator.run_pytest()
231
- self._state.tests_passing_ratio = tests["ratio"]
232
-
233
  import os
234
- reply_path = os.path.join(self.simulator.output_dir, "reply.txt")
235
- self._state.files_correct = (
236
- os.path.exists(reply_path) and os.path.getsize(reply_path) > 0
237
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
 
239
  @staticmethod
240
  def _make_obs(text: str) -> dict:
 
89
  # Update state
90
  self._state.action_history.append(f"{action_type}: {action_args}")
91
  self._state.step_count += 1
92
+
93
+ # Only update measurements on state-changing actions (lazy updates)
94
+ if action_type in ("run_tests", "run_command", "write_file", "check_server", "close_case"):
95
+ self._update_state()
96
 
97
  # Check done
98
  if action_type == "close_case" or self._state.step_count >= self.max_steps:
 
226
  return "ERROR: Dispatch failed."
227
 
228
  def _update_state(self):
229
+ """Refresh state measurements from live environment (non-blocking with error handling)."""
 
 
 
 
 
 
230
  import os
231
+
232
+ # Update server status
233
+ try:
234
+ server = self.simulator.curl_server()
235
+ self._state.server_running = server["success"]
236
+ except Exception:
237
+ pass
238
+
239
+ # Update test pass ratio
240
+ try:
241
+ tests = self.simulator.run_pytest()
242
+ self._state.tests_passing_ratio = tests["ratio"]
243
+ except Exception:
244
+ pass
245
+
246
+ # Update file correctness
247
+ try:
248
+ reply_path = os.path.join(self.simulator.output_dir, "reply.txt")
249
+ self._state.files_correct = (
250
+ os.path.exists(reply_path) and os.path.getsize(reply_path) > 0
251
+ )
252
+ except Exception:
253
+ pass
254
 
255
  @staticmethod
256
  def _make_obs(text: str) -> dict: