--- /SHiREVault/Backup/OSBackups/SHIRE-ACADEMY-ROUND3-AST-SOURCE-REPAIR-20260805T122334Z/before/design_academy_generic_qualify.py 2026-08-05 20:23:33.799911500 +0800 +++ /SHiREVault/Backup/OSBackups/SHIRE-ACADEMY-ROUND3-AST-SOURCE-REPAIR-20260805T122334Z/staged/design_academy_generic_qualify.py 2026-08-05 20:23:34.825467800 +0800 @@ -322,6 +322,92 @@ "direct_model": MODEL_NAME, } +def classify_brain_failure( + error: AcademyBrainResponseError, +) -> str: + payload = ( + error.payload + if isinstance(error.payload, dict) + else {} + ) + + if ( + payload.get("content_format_failure") is True + or payload.get("failure_class") + == "academy_output_contract_failure" + or payload.get("infrastructure_failure") is False + ): + return "content" + + if practice_service._transient_brain_failure(error): + return "infrastructure" + + return "content" + + +def emit_uncounted_brain_failure( + *, + classification: str, + skill_id: str, + round_number: int, + evidence: Path, + error: AcademyBrainResponseError, + state_before: str, + attempts_before: int, + successes_before: int, +) -> int: + current_state = load(STATE) + current_record = current_state["skills"][skill_id] + + assert sha256(STATE) == state_before + assert int( + current_record.get("attempts") or 0 + ) == attempts_before + assert int( + current_record.get("successful_attempts") or 0 + ) == successes_before + assert current_record.get("knowledge_certified") is False + assert current_record.get("forge_allowed") is False + + infrastructure = classification == "infrastructure" + payload = dict(error.payload or {}) + + result = { + "ok": False, + "classification": ( + "UNCOUNTED_QUALIFICATION_INFRASTRUCTURE_FAILURE" + if infrastructure + else "UNCOUNTED_QUALIFICATION_CONTENT_FAILURE" + ), + "skill_id": skill_id, + "round": round_number, + "score_percent": 0, + "tests": [], + "evidence": str(evidence), + "retryable": infrastructure, + "infrastructure_failure": infrastructure, + "content_format_failure": not infrastructure, + "timeout_stage": payload.get("timeout_stage"), + "error": str(error), + "counted_attempt_consumed": False, + "practice_state_unchanged": True, + "forge_allowed": False, + } + + write_json( + evidence / "result.json", + result, + ) + + print(json.dumps( + result, + indent=2, + sort_keys=True, + )) + + return 75 if infrastructure else 2 + + def main() -> int: parser = argparse.ArgumentParser( description=( @@ -423,7 +509,7 @@ ) except AcademyBrainResponseError as exc: error_payload = dict(exc.payload or {}) - + write_json( evidence / "brain-error.json", { @@ -431,21 +517,20 @@ "payload": error_payload, }, ) - + rejected_raw = str( error_payload.get("raw_answer") or "" ).strip() - - retryable_round3_failure = ( + + failure_kind = classify_brain_failure(exc) + + repairable_round3_content = ( round_number == 3 - and error_payload.get("retryable") is True - and error_payload.get("infrastructure_failure") is True + and failure_kind == "content" + and bool(rejected_raw) ) - - if not retryable_round3_failure: - raise - - if rejected_raw: + + if repairable_round3_content: payload = repair_round3_response( prompt, rejected_raw, @@ -453,9 +538,15 @@ ) repair_used = True else: - payload = generate_round3_direct( - prompt, - evidence, + return emit_uncounted_brain_failure( + classification=failure_kind, + skill_id=skill_id, + round_number=round_number, + evidence=evidence, + error=exc, + state_before=state_before, + attempts_before=attempts_before, + successes_before=successes_before, ) write_json( evidence / "brain_payload.json",