diff --git a/skillopt/engine/trainer.py b/skillopt/engine/trainer.py index 18256033..485cf518 100644 --- a/skillopt/engine/trainer.py +++ b/skillopt/engine/trainer.py @@ -574,7 +574,7 @@ def _extract_failure_patterns( ft = fs.get("failure_type", "") sd = fs.get("description", "") analyst_descs.append(f"{ft}: {sd}" if sd else ft) - except Exception: + except (json.JSONDecodeError, OSError, AttributeError, TypeError): pass patterns = [] diff --git a/skillopt/envs/spreadsheetbench/adapter.py b/skillopt/envs/spreadsheetbench/adapter.py index 16e7856f..b426bca2 100644 --- a/skillopt/envs/spreadsheetbench/adapter.py +++ b/skillopt/envs/spreadsheetbench/adapter.py @@ -113,7 +113,7 @@ def rollout( for line in f: try: existing.append(json.loads(line)) - except Exception: + except (json.JSONDecodeError, TypeError): pass if existing: return existing diff --git a/skillopt/envs/spreadsheetbench/rollout.py b/skillopt/envs/spreadsheetbench/rollout.py index 4667775b..102beffe 100644 --- a/skillopt/envs/spreadsheetbench/rollout.py +++ b/skillopt/envs/spreadsheetbench/rollout.py @@ -480,7 +480,7 @@ def run_spreadsheet_batch( r = json.loads(line) done_ids.add(str(r["id"])) existing.append(r) - except Exception: + except (json.JSONDecodeError, KeyError, TypeError): pass pending = [it for it in items if str(it["id"]) not in done_ids] @@ -875,7 +875,7 @@ def run_spreadsheet_batch_codegen( r = json.loads(line) done_ids.add(str(r["id"])) existing.append(r) - except Exception: + except (json.JSONDecodeError, KeyError, TypeError): pass pending = [it for it in items if str(it["id"]) not in done_ids] diff --git a/skillopt/gradient/aggregate.py b/skillopt/gradient/aggregate.py index 8213ad7d..f440084b 100644 --- a/skillopt/gradient/aggregate.py +++ b/skillopt/gradient/aggregate.py @@ -56,7 +56,7 @@ def _merge_batch( for e in merged.get(key, []): e["merge_level"] = level return merged - except Exception: # noqa: BLE001 + except (ValueError, TypeError, KeyError, AttributeError, json.JSONDecodeError): pass # Fallback: concatenate all edits all_edits = [] @@ -248,7 +248,7 @@ def merge_patches( f"{len(f_edits)}+{len(s_edits)} → {len(final[key])} {payload_label(update_mode)}" ) return final - except Exception: # noqa: BLE001 + except (ValueError, TypeError, KeyError, AttributeError, json.JSONDecodeError): pass return { diff --git a/skillopt_sleep/backend.py b/skillopt_sleep/backend.py index 36e0374f..392e4149 100644 --- a/skillopt_sleep/backend.py +++ b/skillopt_sleep/backend.py @@ -423,7 +423,7 @@ def judge(self, task: TaskRecord, response: str) -> Tuple[float, float, str]: try: soft = float(obj.get("score", 0.0)) return (1.0 if soft >= 0.8 else 0.0), soft, str(obj.get("reason", ""))[:200] - except Exception: + except (ValueError, TypeError): pass return 0.0, 0.0, "judge-parse-failed" @@ -786,7 +786,7 @@ def _call(self, prompt: str, *, max_tokens: int = 1024) -> str: try: import shutil shutil.rmtree(clean_cwd, ignore_errors=True) - except Exception: + except OSError: pass out = (proc.stdout or "").strip() self._detect_cli_error(out, proc.stderr or "") @@ -861,7 +861,7 @@ def attempt_with_tools(self, task, skill, memory, tools): finally: try: shutil.rmtree(work, ignore_errors=True) - except Exception: + except OSError: pass def resolve_codex_path(explicit: str = "") -> str: @@ -914,7 +914,7 @@ def resolve_codex_path(explicit: str = "") -> str: # skip the bash shim that execs hermes if head.startswith(b"#!") and b"bash" in head: continue - except Exception: + except OSError: pass return c return "codex" @@ -1001,7 +1001,7 @@ def _call_once(self, prompt: str, *, max_tokens: int = 1024) -> str: finally: try: os.unlink(out_path) - except Exception: + except OSError: pass # Fatal codex failures that will NOT recover on retry — fail fast + loud so a @@ -1129,7 +1129,7 @@ def attempt_with_tools(self, task, skill, memory, tools): try: with open(out_path, encoding="utf-8") as f: resp = f.read().strip() - except Exception: + except OSError: resp = "" # Surface a failed tool-rollout the SAME way _call does: an auth/model/version # failure on this path must show up in diagnostics (call_error), not vanish as a @@ -1148,7 +1148,7 @@ def attempt_with_tools(self, task, skill, memory, tools): finally: try: shutil.rmtree(work, ignore_errors=True) - except Exception: + except OSError: pass def resolve_copilot_path(explicit: str = "") -> str: @@ -1225,7 +1225,7 @@ def __init__(self, model: str = "", copilot_path: str = "", timeout: int = 240) ) try: os.makedirs(self.copilot_home, exist_ok=True) - except Exception: + except OSError: self.copilot_home = "" def _call(self, prompt: str, *, max_tokens: int = 1024) -> str: @@ -1260,7 +1260,7 @@ def _call(self, prompt: str, *, max_tokens: int = 1024) -> str: try: import shutil shutil.rmtree(clean_cwd, ignore_errors=True) - except Exception: + except OSError: pass return self._parse_jsonl_response(proc.stdout or "") @@ -1273,7 +1273,7 @@ def _parse_jsonl_response(raw: str) -> str: continue try: obj = json.loads(line) - except Exception: + except (json.JSONDecodeError, TypeError): continue if obj.get("type") == "assistant.message": content = (obj.get("data") or {}).get("content") @@ -1380,7 +1380,7 @@ def attempt_with_tools(self, task, skill, memory, tools): finally: try: shutil.rmtree(work, ignore_errors=True) - except Exception: + except OSError: pass