fix(ai): fallback PixelRAG platform probe runtime gaps

This commit is contained in:
ogt
2026-07-10 10:03:22 +08:00
parent 4982819493
commit 39d9918f12
5 changed files with 143 additions and 8 deletions

View File

@@ -238,14 +238,40 @@ def _run_capture_subprocess(
payload = json.loads(completed.stdout)
except json.JSONDecodeError:
payload = {}
stderr_excerpt = completed.stderr[:500]
if len(completed.stderr) > 500:
stderr_excerpt = f"{completed.stderr[:250]}...{completed.stderr[-250:]}"
return {
"returncode": completed.returncode,
"stdout_json": payload,
"stdout_excerpt": completed.stdout[:500],
"stderr_excerpt": completed.stderr[:500],
"stderr_excerpt": stderr_excerpt,
}
def _capture_runtime_unavailable(result: Mapping[str, Any]) -> bool:
haystack = " ".join(
[
str(result.get("stdout_excerpt") or ""),
str(result.get("stderr_excerpt") or ""),
]
).lower()
return (
"modulenotfounderror" in haystack
and "playwright" in haystack
) or "no module named 'playwright'" in haystack or (
"from playwright.sync_api" in haystack
and "traceback" in haystack
) or (
"playwright" in haystack
and (
"executable doesn't exist" in haystack
or "please run" in haystack
or "browsertype.launch" in haystack
)
)
def _capture_item(
item: Mapping[str, Any],
*,
@@ -302,8 +328,25 @@ def _capture_item(
and capture_payload.get("success") is True
and capture_payload.get("status") == "captured"
)
runtime_missing = not captured_ok and _capture_runtime_unavailable(result)
structured_fallback_available = bool(
(item.get("structured_source_fallback") or {}).get("available")
)
capture_fallback = not captured_ok and structured_fallback_available
base.update({
"worker_status": "executed_capture_ok" if captured_ok else "capture_worker_error",
"worker_status": (
"executed_capture_ok"
if captured_ok
else (
(
"capture_runtime_unavailable_structured_fallback_package"
if runtime_missing
else "capture_failed_structured_fallback_package"
)
if capture_fallback
else "capture_worker_error"
)
),
"ready_for_execution": True,
"capture_execution_ready": True,
"capture_manifest_id": manifest.get("manifest_id"),
@@ -314,14 +357,39 @@ def _capture_item(
else 0,
"capture_tile_file_count": tile_file_count,
"capture_receipt_path": receipt_path,
"network_call_performed": True,
"network_call_performed": bool(not runtime_missing),
"artifact_write_performed": bool(captured_ok),
"structured_source_fallback": item.get("structured_source_fallback") or {},
"structured_source_package": (
{
"adapter_code": (item.get("structured_source_fallback") or {}).get("adapter_code"),
"available": True,
"source_count": len(list((item.get("structured_source_fallback") or {}).get("sources") or [])),
"network_request_allowed": bool(
(item.get("structured_source_fallback") or {}).get("network_request_allowed")
),
"database_write_allowed": False,
"dry_run_only": True,
"blocked_page_not_product_data": True,
"capture_runtime_unavailable": runtime_missing,
}
if capture_fallback
else None
),
"capture_stdout_excerpt": result["stdout_excerpt"] if not captured_ok else "",
"capture_stderr_excerpt": result["stderr_excerpt"] if not captured_ok else "",
"next_machine_action": (
"run_pixelrag_rag_candidate_replay_after_probe_capture"
if captured_ok
else "repair_pixelrag_platform_probe_worker_capture_runtime_or_use_structured_source"
else (
(
"run_structured_source_or_install_pixelrag_capture_runtime"
if runtime_missing
else "run_structured_source_or_retry_platform_capture"
)
if capture_fallback
else "repair_pixelrag_platform_probe_worker_capture_runtime_or_use_structured_source"
)
),
})
if write_receipt:
@@ -408,7 +476,7 @@ def run_pixelrag_platform_probe_worker(
ready_count = sum(1 for item in probe_items if item.get("probe_ready"))
dry_run_count = sum(1 for item in worker_items if str(item.get("worker_status") or "").startswith("dry_run_"))
structured_count = sum(
1 for item in worker_items if "structured_source_fallback" in str(item.get("worker_status") or "")
1 for item in worker_items if "structured" in str(item.get("worker_status") or "")
)
capture_ready_count = sum(1 for item in worker_items if item.get("capture_execution_ready"))
capture_execute_count = sum(
@@ -417,7 +485,10 @@ def run_pixelrag_platform_probe_worker(
capture_ok_count = sum(1 for item in worker_items if item.get("worker_status") == "executed_capture_ok")
capture_error_count = sum(1 for item in worker_items if item.get("worker_status") == "capture_worker_error")
executed_structured_count = sum(
1 for item in worker_items if item.get("worker_status") == "executed_structured_source_fallback_package"
1
for item in worker_items
if "structured" in str(item.get("worker_status") or "")
and not str(item.get("worker_status") or "").startswith("dry_run_")
)
executed_count = capture_execute_count + executed_structured_count
skipped_count = sum(1 for item in worker_items if str(item.get("worker_status") or "").startswith("skipped_"))