Spaces:
Paused
Paused
Edit: Code Exe Tool - The get_terminal_output function will now detect if the last 128 characters repeat 5 times consecutively and will stop execution if this pattern occurs, indicating a likely infinite loop.
Browse filesNow, when a repeating output pattern is detected:
An error message will be printed to the console, indicating the loop and that the session is being reset.
The log will be updated.
self.reset_terminal(session=session) will be called to reset the specific session where the loop occurred.
A detailed message will be returned to the agent, including the captured output, the loop detection confirmation, a notification that the session was reset, and advice to review the problematic code/command.
231 unmodified lines2322332342352362372382392402413 unmodified lines245246247248249250251252253254231 unmodified lineslast_output_time = start_timefull_output = ""got_output = Falsewhile True:await asyncio.sleep(sleep_time)full_output, partial_output = await self.state.shells[session].read_output(timeout=between_output_timeout, reset_full_output=reset_full_output)reset_full_output = False3 unmodified linesnow = time.time()if partial_output:PrintStyle(font_color="#85C1E9").stream(partial_output)self.log.update(content=full_output)last_output_time = nowgot_output = True# Check for shell prompt at the end of outputlast_lines = full_output.splitlines()[-3:] if full_output else []for line in last_lines:231 unmodified lines2322332342352362372382392402412422432443 unmodified lines248249250251252253254255256257258259260261262263264265266267268269270271272273274275231 unmodified lineslast_output_time = start_timefull_output = ""got_output = False# --- Configuration for repetition detection ---chunk_size = 128 # Size of the block to check for repetitionrepeat_threshold = 5 # How many times the block must repeat consecutivelywhile True:await asyncio.sleep(sleep_time)current_full_output, partial_output = await self.state.shells[session].read_output(timeout=between_output_timeout, reset_full_output=reset_full_output)reset_full_output = False3 unmodified linesnow = time.time()if partial_output:PrintStyle(font_color="#85C1E9").stream(partial_output)full_output += partial_output # Append new outputself.log.update(content=full_output)last_output_time = nowgot_output = True# --- Check for repeating output pattern ---required_len = chunk_size * repeat_thresholdif len(full_output) >= required_len:check_segment = full_output[-required_len:]last_chunk = full_output[-chunk_size:]expected_segment = last_chunk * repeat_thresholdif check_segment == expected_segment:loop_detected_msg = f"Detected repeating output pattern (last {chunk_size} chars repeated {repeat_threshold} times), likely an infinite loop."PrintStyle.error(f"{loop_detected_msg} Resetting session {session}.")self.log.update(content=full_output + f"\n--- LOOP DETECTED --- Session {session} reset.")# Automatically reset the problematic sessionawait self.reset_terminal(session=session)# Return informative message to the agentreturn f"{full_output}\n--- LOOP DETECTED & SESSION RESET ---\n{loop_detected_msg}\nThe terminal session {session} was automatically reset.\nPlease review the code or command that caused the loop to prevent recurrence."# --- End of repetition check ---# Check for shell prompt at the end of outputlast_lines = full_output.splitlines()[-3:] if full_output else []for line in last_lines:
python/tools/code_execution_tool.py+22-1