Show the diff
--- decide.py (current)+++ decide.py (candidate)@@ -3,24 +3,56 @@ declared_flags = (context or {}).get("declared_flags", []) if declared_flags is None: declared_flags = []- try:- declared_flags_set = set(declared_flags)- except TypeError:- declared_flags_set = None++ def strip_z_flags(flags):+ if not flags:+ return []+ out = []+ i = 0+ fl = list(flags)+ while i < len(fl):+ tok = str(fl[i])+ if tok == "-z":+ i += 2+ continue+ if tok.startswith("-z") and len(tok) > 2:+ i += 1+ continue+ out.append(tok)+ i += 1+ return out++ base_declared_flags = strip_z_flags(declared_flags)+ n = len(history) if history else 0 if n == 0: return {"kind": "hold", "reason": "no replay available"} def flags_of(r):- return r.get("flags", [])+ return r.get("flags", []) or [] def flags_match(r):- if declared_flags_set is None:- return True- try:- return set(flags_of(r) or []) == declared_flags_set- except TypeError:- return list(flags_of(r) or []) == list(declared_flags or [])+ rf = flags_of(r)+ if strip_z_flags(rf) != base_declared_flags:+ return False+ z_val = r.get("z")+ if z_val is not None:+ fl = list(rf)+ for i, tok in enumerate(fl):+ s = str(tok)+ if s == "-z" and i + 1 < len(fl):+ try:+ if int(fl[i + 1]) != int(z_val):+ return False+ except Exception:+ return False+ elif s.startswith("-z") and len(s) > 2:+ try:+ if int(s[2:]) != int(z_val):+ return False+ except Exception:+ return False+ return True def warnings_of(r): w = r.get("warnings", [])@@ -36,22 +68,61 @@ except Exception: return False - RETRY_SUBS = ("too big", "too large", "too-big", "too-large", "exceed", "larger than", "greater than", "limit", "max job", "max-job", "-z", " size", "size ", "truncat", "skip", "ignor", "dropp", "omit")+ RETRY_SUBS = (+ "too big",+ "too large",+ "too-big",+ "too-large",+ "exceed",+ "larger than",+ "greater than",+ "limit",+ "max job",+ "max-job",+ "-z",+ " size",+ "size ",+ "truncat",+ "skip",+ "ignor",+ "dropp",+ "omit",+ )++ FATAL_SUBS = (+ "corrupt",+ "invalid",+ "bad ",+ "unexpect",+ "short read",+ "eof",+ "checksum",+ "crc",+ "magic",+ "version",+ "permission",+ "denied",+ "no such",+ "i/o",+ "io error",+ "out of memory",+ "oom",+ "unknown",+ "malform",+ ) def is_retryable(r): ws = warnings_of(r)- # count says more jobs exist than listed -> truncated listing- try:- if int(r.get("current_jobs")) > len(jobs_of(r)):- return True- except Exception:- pass+ has_retry = False for line in ws: s = str(line).lower()+ for f in FATAL_SUBS:+ if f in s:+ return False for sub in RETRY_SUBS: if sub in s:- return True- return False+ has_retry = True+ return has_retry def is_clean(i): r = history[i]@@ -61,7 +132,6 @@ return False if not flags_match(r): return False- # job ids must be unique ints j = jobs_of(r) try: if len(set(j)) != len(j):@@ -75,48 +145,19 @@ last_clean = is_clean(n - 1) last_retry = is_retryable(last) - # Latest replay is clean: import it if consistent with prior clean replays. if last_clean:- # all clean replays must be mutually consistent (equal sets);- # otherwise we cannot trust any of them. last_set = set(jobs_of(last)) for i in clean_idx: if set(jobs_of(history[i])) != last_set:- # If sets grow monotonically and earlier ones were clean but- # smaller, the earlier "clean" missed jobs silently; the- # largest is still the only candidate, but silent miss means- # cleanliness is unreliable. Hold unless the only difference- # is explained by a raised -z (monotonic superset).- # Require monotonic superset chain ending at last; else hold.- pass- # verify monotonic superset chain for clean replays ordered by z- # if a clean replay has jobs not in last, last is missing jobs -> hold- for i in clean_idx:- s = set(jobs_of(history[i]))- if not s.issubset(last_set):- return {"kind": "hold", "reason": "clean replays disagree; possible resurrected or missing jobs"}- # if any non-clean replay reports a job id not in last, last missed it- # (only when that replay's flags match, else ignore)- # To avoid importing a subset, hold in that case.+ return {"kind": "hold", "reason": "clean replays disagree on job set"} for i in range(n):- if i in clean_idx:- continue- if not flags_match(history[i]):- continue- # if the unclean replay was retryable (truncated) its set should be subset;- # if it contains extras, last is incomplete- try:- s = set(jobs_of(history[i]))- except TypeError:- continue- if not s.issubset(last_set):- return {"kind": "hold", "reason": "another replay shows jobs missing from latest clean replay"}+ if i not in clean_idx and not is_retryable(history[i]):+ return {"kind": "hold", "reason": "earlier replay had non-size fatal errors or mismatches"} return {"kind": "import", "from_replay": n - 1} - # Latest replay is not clean. if last_retry:- # Raising -z may still help. Detect futility: z not increasing or- # job set stagnant across increases -> hold.+ if not count_ok(last) or not flags_match(last):+ return {"kind": "hold", "reason": "replay has flag or job count mismatch alongside warnings"} if n >= 2: try: z_prev = int(history[n - 2].get("z"))@@ -125,38 +166,16 @@ z_prev = None z_last = None if z_prev is not None and z_last is not None and z_last <= z_prev:- return {"kind": "hold", "reason": "size-limit warning persists without raised -z; no trustworthy replay obtainable"}- # if z increased but job set and warnings identical, further raises unlikely to help after repeats+ return {"kind": "hold", "reason": "size-limit warning persists without raised -z"} if n >= 3: try:- sets = [set(jobs_of(history[k])) for k in range(n - 3, n)] warns = [tuple(map(str, warnings_of(history[k]))) for k in range(n - 3, n)]- if sets[0] == sets[1] == sets[2] and warns[0] == warns[1] == warns[2]:- return {"kind": "hold", "reason": "repeated replays at raised limits show no progress"}+ if warns[0] == warns[1] == warns[2]:+ return {"kind": "hold", "reason": "repeated replays at raised limits show identical warnings"} except Exception: pass- # gentle cap: many attempts with no clean replay -> hold- if n >= 6:- return {"kind": "hold", "reason": "too many replays without a clean result"}+ if n >= 8:+ return {"kind": "hold", "reason": "too many replays without reaching a clean replay"} return {"kind": "replay"} - # Latest is fatal (non-size warnings, count mismatch, or flag mismatch).- # If an earlier clean replay exactly matches latest job set and latest only- # adds benign-seeming noise, we could still import it; but in general a- # fatal latest means completeness cannot be established -> hold.- # Narrow exception: latest z overshoots (too large) while an earlier clean- # exists with identical job set -> import the earlier clean one.- if clean_idx:- try:- last_set = set(jobs_of(last))- for i in reversed(clean_idx):- if set(jobs_of(history[i])) == last_set and count_ok(history[i]) and not warnings_of(history[i]):- # only allow fallback when latest failure looks like overshoot, not corruption- s = " ".join(map(str, warnings_of(last))).lower()- if ("too large" in s or "too big" in s or "exceed" in s or "maximum" in s or "limit" in s) and not count_ok(last):- return {"kind": "import", "from_replay": i}- break- except Exception:- pass- return {"kind": "hold", "reason": "latest replay untrustworthy; earlier clean replay cannot be proven complete"}- return {"kind": "hold", "reason": "latest replay reports errors that raising -z cannot fix"}+ return {"kind": "hold", "reason": "latest replay is unclean and cannot be resolved by raising -z"}