个人长报告同盘同日重试改为秒回
完整数据版在版本号明确时复用当天的结果。渲染快捷算法留下但默认关闭,本机只快了大约两成。 Co-Authored-By: Grok (agent loop)
This commit is contained in:
co-authored by
Grok (agent loop)
parent
66cd60081f
commit
69c739fbee
@@ -486,15 +486,26 @@ def _drop_dotted_path(payload: Any, path: tuple[str, ...]) -> Any:
|
||||
return cloned
|
||||
|
||||
|
||||
def result_payload_for_binding(
|
||||
def _render_fast() -> bool:
|
||||
try:
|
||||
from scripts.report_perf_flags import report_render_fast_enabled
|
||||
except ModuleNotFoundError: # pragma: no cover - direct scripts/ execution
|
||||
from report_perf_flags import report_render_fast_enabled
|
||||
return report_render_fast_enabled()
|
||||
|
||||
|
||||
def _excluded_binding_top(binding_scope: dict[str, Any]) -> set[str]:
|
||||
return RESULT_BINDING_ENVELOPE_KEYS | {
|
||||
str(key) for key in (binding_scope.get("excluded_top_keys") or ())
|
||||
}
|
||||
|
||||
|
||||
def _result_payload_for_binding_legacy(
|
||||
result: dict[str, Any],
|
||||
scope: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Business payload that participates in result_hash."""
|
||||
binding_scope = scope if isinstance(scope, dict) else default_result_binding_scope()
|
||||
excluded_top = RESULT_BINDING_ENVELOPE_KEYS | {
|
||||
str(key) for key in (binding_scope.get("excluded_top_keys") or ())
|
||||
}
|
||||
excluded_top = _excluded_binding_top(binding_scope)
|
||||
payload = {key: value for key, value in result.items() if key not in excluded_top}
|
||||
for raw_path in binding_scope.get("excluded_paths") or ():
|
||||
parts = tuple(part for part in str(raw_path).split(".") if part)
|
||||
@@ -503,17 +514,73 @@ def result_payload_for_binding(
|
||||
return payload
|
||||
|
||||
|
||||
def _drop_star_keys_and_canonicalize(payload: Any, star_keys: frozenset[str]) -> Any:
|
||||
"""Drop ``**.key`` names and canonicalize keys in one walk.
|
||||
|
||||
String keys use the same inequality as ``_drop_key_recursive``. Non-string
|
||||
keys are kept, then renamed with the same rule as ``canonicalize_result_payload``.
|
||||
"""
|
||||
if isinstance(payload, dict):
|
||||
normalized: dict[str, Any] = {}
|
||||
for key, child in payload.items():
|
||||
if isinstance(key, str):
|
||||
if key in star_keys:
|
||||
continue
|
||||
normalized_key = key
|
||||
else:
|
||||
normalized_key = f"__{type(key).__name__}__:{key}"
|
||||
normalized[normalized_key] = _drop_star_keys_and_canonicalize(child, star_keys)
|
||||
return normalized
|
||||
if isinstance(payload, (list, tuple)):
|
||||
return [_drop_star_keys_and_canonicalize(item, star_keys) for item in payload]
|
||||
return payload
|
||||
|
||||
|
||||
def _result_payload_for_binding_fast(
|
||||
result: dict[str, Any],
|
||||
scope: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
binding_scope = scope if isinstance(scope, dict) else default_result_binding_scope()
|
||||
excluded_top = _excluded_binding_top(binding_scope)
|
||||
payload = {key: value for key, value in result.items() if key not in excluded_top}
|
||||
star_keys: set[str] = set()
|
||||
for raw_path in binding_scope.get("excluded_paths") or ():
|
||||
parts = tuple(part for part in str(raw_path).split(".") if part)
|
||||
if len(parts) == 2 and parts[0] == "**":
|
||||
star_keys.add(parts[1])
|
||||
continue
|
||||
if parts:
|
||||
payload = _drop_dotted_path(payload, parts)
|
||||
return _drop_star_keys_and_canonicalize(payload, frozenset(star_keys))
|
||||
|
||||
|
||||
def result_payload_for_binding(
|
||||
result: dict[str, Any],
|
||||
scope: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Business payload that participates in result_hash."""
|
||||
if _render_fast():
|
||||
return _result_payload_for_binding_fast(result, scope)
|
||||
return _result_payload_for_binding_legacy(result, scope)
|
||||
|
||||
|
||||
def hash_bound_result(
|
||||
result: dict[str, Any],
|
||||
input_hash: str,
|
||||
scope: dict[str, Any] | None = None,
|
||||
) -> str:
|
||||
"""SHA-256 of the canonical bound payload. Does not mutate ``result``."""
|
||||
encoded = json.dumps(
|
||||
canonicalize_result_payload({
|
||||
payload = result_payload_for_binding(result, scope)
|
||||
if _render_fast():
|
||||
# The fast payload is already canonical, including the star-key drop.
|
||||
canonical = {"input_hash": input_hash, "result": payload}
|
||||
else:
|
||||
canonical = canonicalize_result_payload({
|
||||
"input_hash": input_hash,
|
||||
"result": result_payload_for_binding(result, scope),
|
||||
}),
|
||||
"result": payload,
|
||||
})
|
||||
encoded = json.dumps(
|
||||
canonical,
|
||||
ensure_ascii=False,
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
|
||||
Reference in New Issue
Block a user