fix: restore stage-based Alpha check classification
This commit is contained in:
+11
-9
@@ -7,7 +7,7 @@ from datetime import datetime
|
||||
from sqlalchemy import or_, select, update
|
||||
|
||||
from .models import Alpha, Research, ResearchTag, SelfCorrelation, now
|
||||
from .platform_checks import split_checks, submission_limits
|
||||
from .platform_checks import check_result, split_checks, submission_limits
|
||||
from .research.provenance import source_alpha_ids
|
||||
|
||||
METRIC_FIELDS = (
|
||||
@@ -20,16 +20,17 @@ def failed_checks(checks):
|
||||
"""Return failed Alpha check names, excluding submission limits and local correlation."""
|
||||
return [
|
||||
check.get("name") if isinstance(check.get("name"), str) else "未命名检查"
|
||||
for check in split_checks(checks)[0] if isinstance(check, dict) and check.get("result") == "FAIL"
|
||||
for check in split_checks(checks)[0] if isinstance(check, dict) and check_result(check) == "FAIL"
|
||||
] if isinstance(checks, list) else []
|
||||
|
||||
|
||||
def snapshot_columns(settings, metrics, checks):
|
||||
def snapshot_columns(settings, metrics, checks, *, checked=False):
|
||||
"""Derive list fields from a platform snapshot, preserving missing metrics as null.
|
||||
|
||||
Submission limits are excluded. Only explicit Alpha FAIL results count.
|
||||
Empty, malformed and unfinished Alpha checks are
|
||||
pending; all known checks passing without PROD_CORRELATION is only a pre-check.
|
||||
Sync snapshots with no failures are PRE_CHECK; a completed explicit /check
|
||||
with no failures is PASS. WARNING/PENDING do not count as failures, matching
|
||||
the legacy workflow. Empty, malformed or unknown results remain PENDING.
|
||||
No submission eligibility or activity eligibility is inferred here.
|
||||
"""
|
||||
settings = settings if isinstance(settings, dict) else {}
|
||||
@@ -40,10 +41,10 @@ def snapshot_columns(settings, metrics, checks):
|
||||
by_name = {check["name"]: check for check in valid if isinstance(check.get("name"), str)}
|
||||
if failures:
|
||||
check_type = "FAIL_1" if failures == 1 else "FAIL_2"
|
||||
elif not checks or len(valid) != len(checks) or any(check.get("result") != "PASS" for check in valid):
|
||||
elif not checks or len(valid) != len(checks) or any(check_result(check) not in ("PASS", "WARNING", "PENDING") for check in valid):
|
||||
check_type = "PENDING"
|
||||
else:
|
||||
check_type = "PASS" if "PROD_CORRELATION" in by_name else "PRE_CHECK"
|
||||
check_type = "PASS" if checked else "PRE_CHECK"
|
||||
# /check values are freshest; submitted snapshots also expose a scalar in IS.
|
||||
prod_correlation = number(by_name.get("PROD_CORRELATION", {}).get("value"))
|
||||
if prod_correlation is None:
|
||||
@@ -66,12 +67,13 @@ def snapshot_columns(settings, metrics, checks):
|
||||
}
|
||||
|
||||
|
||||
def check_summary(checks):
|
||||
def check_summary(checks, *, check_type):
|
||||
"""Separate cached Alpha findings from submission limits; infer no live eligibility."""
|
||||
return {
|
||||
"check_type": snapshot_columns({}, {}, checks)["check_type"],
|
||||
"check_type": check_type,
|
||||
"failed_checks": failed_checks(checks),
|
||||
"submission_limits": submission_limits(checks),
|
||||
"meaning": "PRE_CHECK 为同步无失败项;PASS 为主动检查完成且无失败项。PENDING/WARNING 不算失败,不代表全部检查项 PASS 或当前可提交",
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
"""Classify platform evidence without discarding unknown checks or inferring eligibility."""
|
||||
|
||||
|
||||
def check_result(check):
|
||||
"""Normalize known upstream result casing without rewriting the raw evidence."""
|
||||
value = check.get("result") if isinstance(check, dict) else None
|
||||
return value.upper() if isinstance(value, str) else None
|
||||
|
||||
|
||||
def is_submission_limit(check):
|
||||
"""Recognize only the confirmed account-limit check; unknown names remain Alpha checks."""
|
||||
return isinstance(check, dict) and check.get("name") == "REGULAR_SUBMISSION"
|
||||
@@ -16,8 +22,8 @@ def split_checks(checks):
|
||||
def submission_limits(checks):
|
||||
"""Summarize the observed limit, never the account's current allowance or reset time."""
|
||||
_, limits = split_checks(checks)
|
||||
status = "blocked" if any(c.get("result") == "FAIL" for c in limits) else (
|
||||
"not_blocked" if limits and all(c.get("result") == "PASS" for c in limits) else "unknown"
|
||||
status = "blocked" if any(check_result(c) == "FAIL" for c in limits) else (
|
||||
"not_blocked" if limits and all(check_result(c) == "PASS" for c in limits) else "unknown"
|
||||
)
|
||||
return {"status": status, "checks": limits,
|
||||
"meaning": "仅反映缓存观测时的提交限制,不代表当前额度或正式提交资格"}
|
||||
|
||||
@@ -222,7 +222,7 @@ class ResearchAccess:
|
||||
return {"alpha_id": args.alpha_id, "snapshot": submission_fingerprint(context),
|
||||
**context, "descriptions": {key: item["description"] for key, item in context["sections"].items()},
|
||||
"can_check": alpha.status == "UNSUBMITTED" and await correlation_allows_check(self.db, args.alpha_id),
|
||||
"checks": alpha.checks, "check_summary": check_summary(alpha.checks), "source": "local_cache", "production_submission": False,
|
||||
"checks": alpha.checks, "check_summary": check_summary(alpha.checks, check_type=alpha.check_type), "source": "local_cache", "production_submission": False,
|
||||
"job_id": job.id if job else None, "job_status": job.status if job else None,
|
||||
"checked_at": job.checkpoint.get("checked_at") if job else None}
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ def router(runner, ai):
|
||||
return {
|
||||
"snapshot": fingerprint(context),
|
||||
"checks": alpha.checks,
|
||||
"check_summary": check_summary(alpha.checks),
|
||||
"check_summary": check_summary(alpha.checks, check_type=alpha.check_type),
|
||||
"sections": context["sections"],
|
||||
"descriptions": {key: item["description"] for key, item in context["sections"].items()},
|
||||
"model": config.description_model,
|
||||
@@ -355,7 +355,7 @@ async def run_check(runner, job_id, payload):
|
||||
alpha.checks = sanitize(checks)
|
||||
alpha.is_metrics = {**alpha.is_metrics, "checks": alpha.checks}
|
||||
alpha.raw = {**alpha.raw, "is": {**(alpha.raw.get("is") or {}), "checks": alpha.checks}}
|
||||
for key, value in snapshot_columns(alpha.settings, alpha.is_metrics, alpha.checks).items():
|
||||
for key, value in snapshot_columns(alpha.settings, alpha.is_metrics, alpha.checks, checked=True).items():
|
||||
setattr(alpha, key, value)
|
||||
db.add(JobItem(job_id=job_id, alpha_id=alpha_id))
|
||||
job.processed = 1
|
||||
|
||||
Reference in New Issue
Block a user