Show the diff
--- decide.py (current)+++ decide.py (candidate)@@ -1,19 +1,52 @@ def decide(context, history):- declared_flags = context.get("declared_flags", [])+ declared_flags = context.get("declared_flags", []) or [] declared_z = context.get("declared_z", 0) try:- declared_flag_set = set(declared_flags or [])+ declared_z = int(declared_z) except Exception:- declared_flag_set = set()-- def norm_flags(f):- try:- return set(f or [])- except Exception:- return set()+ declared_z = 0 SIZE_KEYWORDS = ("truncat", "limit", "exceed", "overflow", "full", "size", "max", "too large", "too big", "large", "space", "exhaust", "-z", "\"z\"", "'z'", "journal", "binlog", "wal", "behind", "missing", "dropped", "lost", "omitted", "skipped", "cut off", "cutoff") HARD_KEYWORDS = ("corrupt", "checksum", "invalid", "mismatch", "failed to", "unreadable", "not a", "panic", "assert", "segment mismatch", "magic")++ def strip_z(flags):+ # Remove '-z' and its value so a raised-limit replay can still match declared flags.+ # Returns (remaining_tokens_list, z_value_or_None)+ try:+ toks = [str(t) for t in (flags or [])]+ except Exception:+ return ([], None)+ rest = []+ zval = None+ i = 0+ while i < len(toks):+ t = toks[i]+ if t == "-z" and i + 1 < len(toks):+ try:+ zval = int(toks[i + 1])+ except Exception:+ zval = toks[i + 1]+ i += 2+ continue+ # also handle "-z1024" glued form+ if t.startswith("-z") and len(t) > 2:+ try:+ zval = int(t[2:])+ except Exception:+ zval = t[2:]+ i += 1+ continue+ rest.append(t)+ i += 1+ return (rest, zval)++ def flags_match_declared(rep_flags):+ try:+ d_rest, _ = strip_z(declared_flags)+ r_rest, _ = strip_z(rep_flags)+ return sorted(d_rest) == sorted(r_rest)+ except Exception:+ return False def warnings_text(rep): ws = rep.get("warnings", []) or []@@ -24,7 +57,6 @@ for k in SIZE_KEYWORDS: if k in txt: return True- # count mismatch suggests jobs the copy counts but did not report try: cj = rep.get("current_jobs") jids = rep.get("job_ids", []) or []@@ -46,7 +78,7 @@ z = rep.get("z") if z is None or int(z) < int(declared_z): return False- if norm_flags(rep.get("flags", [])) != declared_flag_set:+ if not flags_match_declared(rep.get("flags", [])): return False ws = rep.get("warnings", []) if ws is None:@@ -73,7 +105,6 @@ except Exception: return False - # collect trustworthy candidates trusted_idx = [] trusted_sets = [] for i, rep in enumerate(history or []):@@ -85,7 +116,6 @@ trusted_sets.append(None) if trusted_idx:- # look for a single maximal superset; all others must be subsets of it best = None for a in range(len(trusted_idx)): sa = trusted_sets[a]@@ -105,7 +135,6 @@ best = a if best is not None: target_set = trusted_sets[best]- # import the latest replay carrying exactly that set chosen = trusted_idx[best] for k in range(len(trusted_idx)): if trusted_sets[k] == target_set and trusted_idx[k] > chosen:@@ -113,16 +142,11 @@ return {"kind": "import", "from_replay": int(chosen)} return {"kind": "hold", "reason": "trustworthy replays disagree on job set; importing risks leaving a job behind or resurrecting a deleted job"} - # no trustworthy replay: decide between another raised-limit copy and hold if not history: return {"kind": "hold", "reason": "no replay output to trust"} last = history[-1]- # flags mismatch on the latest copy is not cured by raising -z alone- if norm_flags(last.get("flags", [])) != declared_flag_set:- # a re-run at declared flags plus raised limit could still be worth one try- # but if flags already correct-declared and still mismatched, hold+ if not flags_match_declared(last.get("flags", [])): return {"kind": "hold", "reason": "replay flags do not match declared flags; no raised-limit replay can make this log trustworthy"}- # if progress stalled despite raised limits, stop asking if len(history) >= 3: try: zs = [int(r.get("z", 0)) for r in history]@@ -136,13 +160,11 @@ w_last = list(last.get("warnings", []) or []) w_prev = list(history[-2].get("warnings", []) or []) if s_last == s_prev and len(w_last) > 0 and len(w_prev) > 0:- # check whether raising z changed anything at all recently s_first = set(list(history[0].get("job_ids", []) or [])) if s_last == s_first: return {"kind": "hold", "reason": "raised limit did not change recovered jobs or clear warnings; further replays will not become trustworthy"} except Exception: pass- # cap number of replays / size growth try: last_z = int(last.get("z", declared_z)) except Exception:@@ -160,20 +182,13 @@ pass size_hint = has_size_hint(last) hard = has_hard_error(last)- # Any warning at all with no size hint and no count mismatch: raising -z cannot fix it. if hard and not size_hint: return {"kind": "hold", "reason": "replay reports log corruption or unreadable records; a raised limit cannot repair it"} if size_hint: return {"kind": "replay"}- # warnings present but ambiguous: allow one raised-limit attempt from the declared value,- # then hold so a human decides rather than resurrecting or dropping jobs. if len(history) <= 1: txt = warnings_text(last) if txt.strip() != "":- # unknown warning on first replay: one retry at a raised limit is the only- # replay variant available; take it before holding. return {"kind": "replay"}- # no warnings but still untrustworthy (e.g. count mismatch without text,- # bad ids, z below declared): one retry may resolve. return {"kind": "replay"} return {"kind": "hold", "reason": "no replay is clean (warnings or job-count mismatch); a further raised-limit replay is not expected to become trustworthy"}