Spaces:
Runtime error
Runtime error
Commit ·
41aa728
1
Parent(s): d64e3c6
fix: clamp inference score strictly to 0.999 to avoid float format rounding to 1.000
Browse filesFiles changed (4)
- benchmark_run_log.txt+16-69
- brutal_stress.pyAdded+87
- code-review-env/inference.py+3-4
- run_benchmark.py+1-1
12345679 unmodified lines17181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495============================================================Model: deepseek/deepseek-chatTimestamp: 2026-04-10T12:56:32.858185+00:00Return code: 0STDOUT:[START] task=easy env=code-review-env model=deepseek/deepseek-chat9 unmodified lines============================================================Model: qwen/qwen-2.5-72b-instructTimestamp: 2026-04-10T12:57:21.835114+00:00Return code: 0STDOUT:[START] task=easy env=code-review-env model=qwen/qwen-2.5-72b-instruct[STEP] step=1 action={"operation":"add_comment","line_number":25,"severity":"minor","category":"bug","message":"The condition should use '==' instead of '='. Using a single '=' is an assignment, not a comparison."} reward=0.25 done=false error=null[STEP] step=2 action={"operation":"add_comment","line_number":18,"severity":"major","category":"bug","message":"The loop should iterate up to len(items) - 1 to avoid an IndexError when accessing items[i + 1]."} reward=0.25 done=false error=null[STEP] step=3 action={"operation":"add_comment","line_number":25,"severity":"minor","category":"bug","message":"The variable 'include' is always set to False, making the condition 'if include == delta > 0:' redundant. Consider removing the 'include' variable and directly using 'if delta > 0:' to simplify the code."} reward=0.01 done=false error=null[STEP] step=4 action={"operation":"done"} reward=0.99 done=true error=null[END] success=true steps=4 score=0.999 rewards=0.25,0.25,0.01,0.99[START] task=medium env=code-review-env model=qwen/qwen-2.5-72b-instruct[STEP] step=1 action={"operation":"add_comment","line_number":4,"severity":"major","category":"bug","message":"The 'db' variable is used before it is defined. It should be defined before being used in the query."} reward=0.01 done=false error=null[STEP] step=2 action={"operation":"add_comment","line_number":21,"severity":"critical","category":"security","message":"SQL injection vulnerability: The query string is constructed using string concatenation with user input, which can lead to SQL injection attacks. Use parameterized queries to prevent this."} reward=0.25 done=false error=null[STEP] step=3 action={"operation":"add_comment","line_number":20,"severity":"major","category":"security","message":"Hardcoded API key in the code is a security risk. Consider using environment variables or a secure vault to manage secrets."} reward=0.25 done=false error=null[STEP] step=4 action={"operation":"add_comment","line_number":10,"severity":"minor","category":"bug","message":"The variable 'q' is passed to the function but not used in the query. It should either be used or removed from the function signature if it's not needed."} reward=0.01 done=false error=null[STEP] step=5 action={"operation":"done"} reward=0.99 done=true error=null[END] success=true steps=5 score=0.999 rewards=0.01,0.25,0.25,0.01,0.99[START] task=hard env=code-review-env model=qwen/qwen-2.5-72b-instruct[STEP] step=1 action={"operation":"add_comment","line_number":28,"severity":"critical","category":"security","message":"Using ECB mode for AES encryption is insecure and can lead to vulnerabilities. Consider using a more secure mode like CBC or GCM."} reward=0.25 done=false error=null[STEP] step=2 action={"operation":"add_comment","line_number":23,"severity":"critical","category":"security","message":"The `yaml.load` function is vulnerable to arbitrary code execution. Use `yaml.safe_load` instead to avoid security risks."} reward=0.30 done=false error=null[STEP] step=3 action={"operation":"add_comment","line_number":40,"severity":"critical","category":"bug","message":"The `token.decode('utf-8', errors='ignore')` may result in loss of data if the token contains non-UTF-8 characters. Consider handling encoding errors more gracefully or ensuring the token is always valid UTF-8."} reward=0.20 done=false error=null[STEP] step=4 action={"operation":"add_comment","line_number":38,"severity":"major","category":"bug","message":"The `audit_stream` is not being used effectively. The `if not chunk: break` statement will only break the loop if an empty chunk is received, which may not be the intended behavior. Consider adding a more robust check or logging mechanism."} reward=0.01 done=false error=null[STEP] step=5 action={"operation":"add_comment","line_number":43,"severity":"minor","category":"bug","message":"The `for attempt in range(3):` loop will always return after the first iteration, making the retry mechanism ineffective. Consider removing the `return` statement or rethinking the retry logic."} reward=0.01 done=false error=null[STEP] step=6 action={"operation":"done"} reward=0.96 done=true error=null[END] success=true steps=6 score=0.999 rewards=0.25,0.30,0.20,0.01,0.01,0.96============================================================Model: meta-llama/llama-3.3-70b-instructTimestamp: 2026-04-10T12:58:27.294301+00:00Return code: 0STDOUT:[START] task=easy env=code-review-env model=meta-llama/llama-3.3-70b-instruct[STEP] step=1 action={"operation":"add_comment","line_number":18,"severity":"major","category":"bug","message":"The loop will go out of bounds because it iterates over the entire length of the list and then tries to access the next element with 'items[i + 1]'. This will result in an IndexError."} reward=0.25 done=false error=null[STEP] step=2 action={"operation":"add_comment","line_number":25,"severity":"minor","category":"bug","message":"The condition 'if include = delta > 0' is an assignment, not a comparison. It should be 'if include == delta > 0' or more likely 'if delta > 0'. Also, the variable 'include' is always False, so the condition will never be met."} reward=0.25 done=false error=null[STEP] step=3 action={"operation":"add_comment","line_number":21,"severity":"major","category":"bug","message":"The line 'if left.value < 0: continue' will throw an AttributeError if 'left' is None, because 'items' is a list of Optional[Item]. You should add a check for None before trying to access 'left.value'."} reward=0.25 done=false error=null[STEP] step=4 action={"operation":"done"} reward=0.99 done=true error=null[END] success=true steps=4 score=0.999 rewards=0.25,0.25,0.25,0.99[START] task=medium env=code-review-env model=meta-llama/llama-3.3-70b-instruct[STEP] step=1 action={"operation":"add_comment","line_number":15,"severity":"critical","category":"security","message":"Hardcoded secret key 'sk_live_51HARD_CODED_SECRET' is a significant security risk. Consider using environment variables or a secure secrets management system."} reward=0.20 done=false error=null[STEP] step=2 action={"operation":"add_comment","line_number":21,"severity":"critical","category":"security","message":"The query is vulnerable to SQL injection attacks because it directly concatenates user input into the query string. Consider using parameterized queries or an ORM to prevent this."} reward=0.25 done=false error=null[STEP] step=3 action={"operation":"add_comment","line_number":20,"severity":"major","category":"bug","message":"The function render_profile_html is called with 'q' as the display_name, but 'q' seems to be a query string, not a display name. It should probably be called with the actual display name of the user."} reward=0.01 done=false error=null[STEP] step=4 action={"operation":"add_comment","line_number":19,"severity":"major","category":"bug","message":"The variable 'row' is not checked for None before accessing its elements. If 'db.fetch_one(query)' returns None, this will result in a KeyError. Consider adding a check to handle this case."} reward=0.01 done=false error=null[STEP] step=5 action={"operation":"add_comment","line_number":18,"severity":"minor","category":"bug","message":"The 'current_user_id' parameter is not used anywhere in the function. Consider removing it if it's not necessary, or use it to implement some kind of access control or authentication."} reward=0.01 done=false error=null[STEP] step=6 action={"operation":"add_comment","line_number":17,"severity":"major","category":"bug","message":"The variable 'db' is used before it's defined. It seems like 'db' should be 'FakeDB()' instead of just 'db' in the line where 'row' is assigned."} reward=0.01 done=false error=null[STEP] step=7 action={"operation":"done"} reward=0.75 done=true error=null[END] success=true steps=7 score=0.999 rewards=0.20,0.25,0.01,0.01,0.01,0.01,0.75[START] task=hard env=code-review-env model=meta-llama/llama-3.3-70b-instruct[STEP] step=1 action={"operation":"add_comment","line_number":40,"severity":"critical","category":"bug","message":"Potential concurrency issue: updating the global _SESSION_CACHE dictionary without proper synchronization can lead to data corruption or loss in a multi-threaded environment."} reward=0.25 done=false error=null[STEP] step=2 action={"operation":"add_comment","line_number":17,"severity":"major","category":"bug","message":"The 'token' key in the config dictionary is not checked for existence before being accessed, which can lead to a KeyError if the key is missing."} reward=0.15 done=false error=null[STEP] step=3 action={"operation":"add_comment","line_number":23,"severity":"critical","category":"security","message":"The 'config' variable is not checked for None before accessing its elements, which can lead to an AttributeError if 'yaml.load' returns None."} reward=0.20 done=false error=null[STEP] step=4 action={"operation":"add_comment","line_number":28,"severity":"critical","category":"security","message":"The use of ECB mode in AES encryption is insecure and can lead to data leakage. A more secure mode like CBC or GCM should be used instead."} reward=0.25 done=false error=null[STEP] step=5 action={"operation":"add_comment","line_number":34,"severity":"major","category":"bug","message":"The 'audit_stream' is not properly closed after use, which can lead to resource leaks. It's recommended to use a 'try-except-finally' block or a 'with' statement to ensure the stream is properly closed."} reward=0.20 done=false error=null[STEP] step=6 action={"operation":"add_comment","line_number":38,"severity":"major","category":"bug","message":"The network backoff retry block catches all exceptions, which can mask important errors and make debugging difficult. It's recommended to catch specific exceptions that are expected to occur during the retry process."} reward=0.01 done=false error=null[STEP] step=7 action={"operation":"add_comment","line_number":10,"severity":"major","category":"security","message":"The key material for AES encryption is hardcoded, which is a security risk. It's recommended to load the key material from a secure source, such as an environment variable or a secure key store."} reward=0.01 done=false error=null[STEP] step=8 action={"operation":"add_comment","line_number":43,"severity":"major","category":"bug","message":"The function 'process_user_sessions' does not handle the case where 'user_params' is None or empty, which can lead to unexpected behavior or errors. It's recommended to add input validation to handle these cases."} reward=0.01 done=false error=null[STEP] step=9 action={"operation":"add_comment","line_number":23,"severity":"critical","category":"security","message":"The 'yaml.load' function can raise a 'YAMLError' if the input string is not a valid YAML. It's recommended to add error handling to catch and handle this exception."} reward=0.01 done=false error=null[STEP] step=10 action={"operation":"add_comment","line_number":40,"severity":"critical","category":"bug","message":"The 'user_id' variable is not validated or sanitized before being used as a key in the '_SESSION_CACHE' dictionary, which can lead to potential security vulnerabilities or data corruption if the 'user_id' is not properly formatted or contains malicious characters."} reward=0.01 done=false error=null[STEP] step=11 action={"operation":"done"} reward=0.99 done=true error=null[END] success=true steps=11 score=0.999 rewards=0.25,0.15,0.20,0.25,0.20,0.01,0.01,0.01,0.01,0.01,0.99============================================================Model: google/gemma-3-27b-itTimestamp: 2026-04-10T12:58:53.005418+00:00Return code: 0STDOUT:[START] task=easy env=code-review-env model=google/gemma-3-27b-it[STEP] step=1 action={"operation":"done"} reward=0.01 done=true error=Expecting value: line 1 column 1 (char 0)[END] success=false steps=1 score=0.001 rewards=0.01[START] task=medium env=code-review-env model=google/gemma-3-27b-it[STEP] step=1 action={"operation":"done"} reward=0.01 done=true error=Expecting value: line 1 column 1 (char 0)[END] success=false steps=1 score=0.001 rewards=0.01[START] task=hard env=code-review-env model=google/gemma-3-27b-it[STEP] step=1 action={"operation":"done"} reward=0.01 done=true error=Expecting value: line 1 column 1 (char 0)[END] success=false steps=1 score=0.001 rewards=0.0112345679 unmodified lines1718192021222324252627282930313233343536373839404142============================================================Model: deepseek/deepseek-chatTimestamp: 2026-04-10T14:14:52.110861+00:00Return code: 0STDOUT:[START] task=easy env=code-review-env model=deepseek/deepseek-chat9 unmodified lines============================================================Model: qwen/qwen-2.5-72b-instructTimestamp: 2026-04-10T14:15:42.143869+00:00Return code: 0STDOUT:[START] task=easy env=code-review-env model=qwen/qwen-2.5-72b-instruct[STEP] step=1 action={"operation":"add_comment","line_number":18,"severity":"major","category":"bug","message":"IndexError will occur when i is the last index of the list, as items[i + 1] will be out of bounds."} reward=0.25 done=false error=null[STEP] step=2 action={"operation":"add_comment","line_number":25,"severity":"major","category":"bug","message":"SyntaxError: invalid syntax. The assignment operator '=' should not be used in the condition of an if statement. It should be 'if include == delta > 0:' or simply 'if delta > 0:' since 'include' is not used elsewhere."} reward=0.20 done=false error=null[STEP] step=3 action={"operation":"done"} reward=0.99 done=true error=null[END] success=true steps=3 score=0.999 rewards=0.25,0.20,0.99[START] task=medium env=code-review-env model=qwen/qwen-2.5-72b-instruct[STEP] step=1 action={"operation":"add_comment","line_number":5,"severity":"major","category":"bug","message":"The 'db' variable is used before it is defined. It should be defined before being used in the 'fetch_one' method call."} reward=0.01 done=false error=null[STEP] step=2 action={"operation":"add_comment","line_number":21,"severity":"critical","category":"security","message":"SQL injection vulnerability: The query string is constructed using string concatenation with user input, which can lead to SQL injection attacks. Use parameterized queries to prevent this."} reward=0.25 done=false error=null[STEP] step=3 action={"operation":"add_comment","line_number":10,"severity":"critical","category":"security","message":"The 'api_key' should not be hardcoded in the code. It should be stored in a secure environment variable or a configuration file to prevent exposure."} reward=0.01 done=false error=null[STEP] step=4 action={"operation":"add_comment","line_number":12,"severity":"major","category":"bug","message":"The function `get_profile_handler` does not handle the case where `row` is `None`. If the query does not return any results, `row` will be `None`, and attempting to access `row['id']` or `row['owner_id']` will raise a `TypeError`. Consider adding a check to handle this scenario."} reward=0.01 done=false error=null[STEP] step=5 action={"operation":"done"} reward=0.96 done=true error=null[END] success=true steps=5 score=0.907 rewards=0.01,0.25,0.01,0.01,0.96[START] task=hard env=code-review-env model=qwen/qwen-2.5-72b-instruct[STEP] step=1 action={"operation":"add_comment","line_number":28,"severity":"critical","category":"security","message":"Using ECB mode for AES encryption is insecure and can lead to vulnerabilities. Consider using a more secure mode like CBC or GCM."} reward=0.25 done=false error=null[STEP] step=2 action={"operation":"add_comment","line_number":18,"severity":"critical","category":"security","message":"The `stream_data` method is called with a hardcoded URL 'audit_service'. This should be configurable or at least documented."} reward=0.25 done=false error=null[STEP] step=3 action={"operation":"add_comment","line_number":34,"severity":"minor","category":"bug","message":"The `token.decode('utf-8', errors='ignore')` may silently ignore decoding errors. Consider using a more robust error handling strategy."} reward=0.10 done=false error=null[STEP] step=4 action={"operation":"add_comment","line_number":23,"severity":"critical","category":"security","message":"The `yaml.load` function with `Loader=yaml.Loader` is vulnerable to YAML deserialization attacks (e.g., arbitrary code execution). Consider using `yaml.safe_load` instead."} reward=0.30 done=false error=null[STEP] step=5 action={"operation":"done"} reward=0.99 done=true error=null[END] success=true steps=5 score=0.999 rewards=0.25,0.25,0.10,0.30,0.99
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687import asyncioimport httpximport timeimport randomfrom typing import Dict, Any
SERVER_URL = "http://127.0.0.1:7860"
def generate_random_action() -> Dict[str, Any]: operations = ["add_comment", "approve", "request_changes", "inspect_file", "inspect_lines", "done", "invalid_op"] op = random.choice(operations) # Boundary/glitch values line_nums = [-1, 0, 1, 100, 999999, None] severities = ["critical", "major", "minor", "nit", "invalid", "", None] categories = ["bug", "security", "performance", "style", "invalid", "", None] confidences = [-10, 0, 50, 100, 150, "string", None] action = {"operation": op} if op == "add_comment": action["line_number"] = random.choice(line_nums) action["severity"] = random.choice(severities) action["category"] = random.choice(categories) action["message"] = f"Random glitch test {random.random()} \x00 unicode 🎉" action["confidence"] = random.choice(confidences) # Randomly omit keys if random.random() < 0.1: del action["line_number"] elif op in ["approve", "request_changes"]: action["summary"] = f"Glitch summary {random.random()}" if random.random() < 0.1: del action["summary"] elif op == "inspect_file": action["filename"] = random.choice(["server.py", "../../../etc/passwd", "", None]) elif op == "inspect_lines": action["filename"] = "server.py" action["start_line"] = random.choice([-100, 0, 1, 50]) action["end_line"] = random.choice([-10, 0, 1, 100, 500]) return action
async def stress_worker(worker_id: int): async with httpx.AsyncClient(timeout=10.0) as client: # Reset task randomly task = random.choice(["easy", "medium", "hard", "invalid"]) try: r = await client.post(f"{SERVER_URL}/reset", json={"task_id": task}) print(f"Worker {worker_id} RESET {task}: {r.status_code}") except Exception as e: print(f"Worker {worker_id} RESET error: {e}") for step in range(50): action = generate_random_action() try: r = await client.post(f"{SERVER_URL}/step", json=action) if r.status_code == 200: data = r.json() if data.get("done"): print(f"Worker {worker_id} DONE reached at step {step}") break except Exception as e: pass # network drops or connection limits # Randomly check state try: r = await client.get(f"{SERVER_URL}/state") except Exception as e: pass
async def main(): print("Beginning BRUTAL STRESS TEST on /reset and /step endpoints...") # Fire off 200 concurrent aggressive workers start = time.time() workers = [stress_worker(i) for i in range(200)] await asyncio.gather(*workers) duration = time.time() - start print(f"Brutal stress test completed 200 concurrent runs in {duration:.2f}s") # Final health check try: async with httpx.AsyncClient() as client: r = await client.get(f"{SERVER_URL}/health") print(f"Server survival check: HTTP {r.status_code} - {r.text}") except Exception as e: print(f"Server CRASHED or UNRESPONSIVE: {e}")
if __name__ == "__main__": asyncio.run(main())60 unmodified lines61626364656667579 unmodified lines6476486496506516526536541 unmodified line65665765865966066166260 unmodified linesdef _print_end(success: bool, steps: int, score: float, rewards: List[float], calibration_score: Optional[float] = None) -> None:"""Print the mandatory END line."""score = max(0.001, min(1 - 1e-6, score))rewards_str = ",".join(f"{r:.2f}" for r in rewards)end_line = f"[END] success={_fmt_bool(success)} steps={steps} score={score:.3f} rewards={rewards_str}"if calibration_score is not None:579 unmodified linesif done:break# Do not override score with average. Score tracks info["current_score"] properly.score = max(0.001, min(score, 1 - 1e-6))success = bool(done and score > 0.10)except Exception as e:success = False1 unmodified linesteps_taken = 1_print_step(steps_taken, "{\"operation\":\"done\"}", 0.01, True, str(e))finally:score = max(0.001, min(score, 1 - 1e-6))_print_end(success, steps_taken, score, rewards)60 unmodified lines61626364656667579 unmodified lines6476486496506516526531 unmodified line65565665765865966066160 unmodified linesdef _print_end(success: bool, steps: int, score: float, rewards: List[float], calibration_score: Optional[float] = None) -> None:"""Print the mandatory END line."""score = max(0.001, min(0.999, score))rewards_str = ",".join(f"{r:.2f}" for r in rewards)end_line = f"[END] success={_fmt_bool(success)} steps={steps} score={score:.3f} rewards={rewards_str}"if calibration_score is not None:579 unmodified linesif done:breakscore = max(0.001, min(score, 0.999))success = bool(done and score > 0.10)except Exception as e:success = False1 unmodified linesteps_taken = 1_print_step(steps_taken, "{\"operation\":\"done\"}", 0.01, True, str(e))finally:score = max(0.001, min(score, 0.999))_print_end(success, steps_taken, score, rewards)
10 unmodified lines1112131415161710 unmodified linesfrom datetime import datetime, timezone# OpenRouter API configurationOPENROUTER_API_KEY = "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"OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1"# Models to benchmark via OpenRouter10 unmodified lines1112131415161710 unmodified linesfrom datetime import datetime, timezone# OpenRouter API configurationOPENROUTER_API_KEY = "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"OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1"# Models to benchmark via OpenRouter
benchmark_run_log.txt+16-69
brutal_stress.pyAdded+87
code-review-env/inference.py+3-4
run_benchmark.py+1-1