failproofai 1.0.3 → 1.0.4-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/standalone/.next/BUILD_ID +1 -1
- package/.next/standalone/.next/build-manifest.json +5 -5
- package/.next/standalone/.next/prerender-manifest.json +5 -5
- package/.next/standalone/.next/required-server-files.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/_global-error/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_global-error.html +1 -1
- package/.next/standalone/.next/server/app/_global-error.rsc +7 -7
- package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +6 -6
- package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +7 -7
- package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/_not-found/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_not-found.html +1 -1
- package/.next/standalone/.next/server/app/_not-found.rsc +15 -15
- package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +15 -15
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +14 -14
- package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/api/audit/invite/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/audit/invite/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/audit/run/route.js +4 -4
- package/.next/standalone/.next/server/app/api/audit/run/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/audit/run/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/audit/status/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/audit/status/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/auth/login-request/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/login-request/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/auth/login-verify/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/login-verify/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/auth/logout/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/logout/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/auth/status/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/status/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/download/[project]/[session]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/download/[project]/[session]/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/audit/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/audit/page/server-reference-manifest.json +37 -4
- package/.next/standalone/.next/server/app/audit/page.js +2 -2
- package/.next/standalone/.next/server/app/audit/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/audit/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/index.html +1 -1
- package/.next/standalone/.next/server/app/index.rsc +15 -15
- package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +14 -14
- package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +15 -15
- package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/policies/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/policies/page/server-reference-manifest.json +14 -14
- package/.next/standalone/.next/server/app/policies/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/policies/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/react-loadable-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/server-reference-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/projects/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/projects/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/projects/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/projects/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/settings/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/settings/page/server-reference-manifest.json +4 -4
- package/.next/standalone/.next/server/app/settings/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/settings/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/chunks/{[externals]__0-9ti7z._.js → [externals]__1lh7m5d._.js} +1 -1
- package/.next/standalone/.next/server/chunks/{[externals]__0u3wrvq._.js → [externals]__1rqkg_y._.js} +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0o07qi9._.js +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__1adacul._.js +1 -1
- package/.next/standalone/.next/server/chunks/{_1-akg6w._.js → _08w6xzm._.js} +2 -2
- package/.next/standalone/.next/server/chunks/_0tovk6q._.js +1 -1
- package/.next/standalone/.next/server/chunks/_0trp3yc._.js +1 -1
- package/.next/standalone/.next/server/chunks/_1ek68ln._.js +4 -4
- package/.next/standalone/.next/server/chunks/lib_telemetry_ts_0dctyyw._.js +1 -1
- package/.next/standalone/.next/server/chunks/node_modules_posthog-node_dist_entrypoints_index_node_mjs_01r25oi._.js +2 -2
- package/.next/standalone/.next/server/chunks/node_modules_posthog-node_dist_entrypoints_index_node_mjs_09z9-p7._.js +2 -2
- package/.next/standalone/.next/server/chunks/package_json_[json]_cjs_1nxcc4v._.js +1 -1
- package/.next/standalone/.next/server/chunks/src_hooks_fp-home_ts_09kv0bn._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__013jr2b._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__01wy8d-._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__02npjtd._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0da85px._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0ftmoxc._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0oa1lav._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0p-5p8u._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0rgu2r3._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0s740oi._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1p2otjt._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/_0-oij9d._.js +23 -0
- package/.next/standalone/.next/server/chunks/ssr/_08x1r5t._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_0l2hi_d._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_0oq1dh6._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_1es2j7i._.js +47 -13
- package/.next/standalone/.next/server/chunks/ssr/_1u8-lu2._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_next-internal_server_app_policies_page_actions_1sp2-yo.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/app_audit__components_audit-dashboard_tsx_0p9ud47._.js +1 -69
- package/.next/standalone/.next/server/chunks/ssr/app_audit__components_rerun-button_tsx_0blihgw._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/app_global-error_tsx_1kp6l3x._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_policies_hooks-client_tsx_19dqvpc._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_settings_settings-client_tsx_20lq-mq._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/node_modules_13n822a._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/node_modules_posthog-node_dist_entrypoints_index_node_mjs_11bnuzn._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_builtin-policies_ts_09j2ndl._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_fp-config_ts_04t589g._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_fp-home_ts_0je3xkv._.js +1 -1
- package/.next/standalone/.next/server/middleware-build-manifest.js +5 -5
- package/.next/standalone/.next/server/pages/404.html +1 -1
- package/.next/standalone/.next/server/pages/500.html +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.json +54 -21
- package/.next/standalone/.next/static/chunks/010bv1w6j171t.js +1 -0
- package/.next/standalone/.next/static/chunks/04r6ch8uf_n8m.js +1 -0
- package/.next/standalone/.next/static/chunks/{29-iqnp9v_axt.css → 0o-hh5_turzlz.css} +1 -1
- package/.next/standalone/.next/static/chunks/{40nr6ehj4p3cw.css → 0qmsunv04x4na.css} +1 -1
- package/.next/standalone/.next/static/chunks/{0ollg-nnu3t3e.js → 0wz8yftk18ts2.js} +1 -1
- package/.next/standalone/.next/static/chunks/0zebh1n9jkfbt.js +1 -0
- package/.next/standalone/.next/static/chunks/1eyl7fzkmnkf_.js +1 -0
- package/.next/standalone/.next/static/chunks/1pb1oztsbwcss.js +1 -0
- package/.next/standalone/.next/static/chunks/{1-_zkmnm-jwei.js → 2aquitk72k2op.js} +1 -1
- package/.next/standalone/.next/static/chunks/2bi_1y0a_smt7.js +6 -0
- package/.next/standalone/.next/static/chunks/{42yfkhekx440s.js → 2ej3b8gk5ittu.js} +1 -1
- package/.next/standalone/.next/static/chunks/{354-n7p7labpn.js → 2zafgs90r_leq.js} +1 -1
- package/.next/standalone/.next/static/chunks/{2xm5mj1d21b4n.js → 32spub4wqjem-.js} +1 -1
- package/.next/standalone/.next/static/chunks/{1a6u7l3giejch.js → 3m4upvybtrexd.js} +1 -1
- package/.next/standalone/.next/static/chunks/{2k9f4tyv04809.css → 3uyhmm01g64k4.css} +1 -0
- package/.next/standalone/.next/static/chunks/{turbopack-2x-o099q64i8h.js → turbopack-3s3c-u_u_l0u9.js} +1 -1
- package/.next/standalone/.opencode/plugins/failproofai.mjs +51 -27
- package/.next/standalone/app/actions/get-leaks.ts +100 -0
- package/.next/standalone/app/audit/_components/audit-dashboard.tsx +112 -33
- package/.next/standalone/app/audit/_components/audit-poster.tsx +29 -10
- package/.next/standalone/app/audit/_components/come-back-better-section.tsx +6 -1
- package/.next/standalone/app/audit/_components/empty-state.tsx +4 -1
- package/.next/standalone/app/audit/_components/how-to-improve-section.tsx +19 -5
- package/.next/standalone/app/audit/_components/leak-section.tsx +179 -0
- package/.next/standalone/app/audit/_components/share-templates.ts +110 -44
- package/.next/standalone/app/audit/audit-styles.css +114 -1
- package/.next/standalone/fp-cloud-cli/CHANGELOG.md +26 -3
- package/.next/standalone/fp-cloud-cli/fp_cli/_click_compat.py +31 -8
- package/.next/standalone/fp-cloud-cli/fp_cli/permissions.py +1 -0
- package/.next/standalone/fp-cloud-cli/pyproject.toml +9 -2
- package/.next/standalone/fp-cloud-cli/tests/test_click_compat.py +54 -0
- package/.next/standalone/fp-cloud-cli/uv.lock +9 -12
- package/.next/standalone/lib/auth/api-server-client.ts +28 -0
- package/.next/standalone/lib/claude-sessions.ts +101 -27
- package/.next/standalone/node_modules/@next/env/package.json +1 -1
- package/.next/standalone/node_modules/next/dist/build/swc/index.js +1 -1
- package/.next/standalone/node_modules/next/dist/compiled/next-server/app-page-turbo-experimental.runtime.prod.js +1 -1
- package/.next/standalone/node_modules/next/dist/compiled/next-server/app-page-turbo.runtime.prod.js +1 -1
- package/.next/standalone/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js +1 -1
- package/.next/standalone/node_modules/next/dist/compiled/next-server/pages-turbo.runtime.prod.js +5 -5
- package/.next/standalone/node_modules/next/dist/experimental/testmode/fetch.js +10 -2
- package/.next/standalone/node_modules/next/dist/lib/patch-incorrect-lockfile.js +3 -3
- package/.next/standalone/node_modules/next/dist/lib/typescript/runTypeScriptCli.js +2 -2
- package/.next/standalone/node_modules/next/dist/lib/verify-typescript-setup.js +3 -1
- package/.next/standalone/node_modules/next/dist/server/config.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/dev/hot-reloader-turbopack.js +2 -2
- package/.next/standalone/node_modules/next/dist/server/dev/hot-reloader-webpack.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/lib/app-info-log.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/lib/incremental-cache/file-system-cache.js +17 -4
- package/.next/standalone/node_modules/next/dist/server/lib/start-server.js +1 -1
- package/.next/standalone/node_modules/next/dist/shared/lib/router/utils/escape-path-delimiters.js +1 -1
- package/.next/standalone/node_modules/next/dist/telemetry/anonymous-meta.js +1 -1
- package/.next/standalone/node_modules/next/dist/telemetry/events/swc-load-failure.js +1 -1
- package/.next/standalone/node_modules/next/dist/telemetry/events/version.js +2 -2
- package/.next/standalone/node_modules/next/package.json +11 -11
- package/.next/standalone/package.json +14 -13
- package/.next/standalone/sdk/python/CHANGELOG.md +155 -0
- package/.next/standalone/sdk/python/README.md +8 -0
- package/.next/standalone/sdk/python/examples/evaluator_worker.py +121 -0
- package/.next/standalone/sdk/python/failproofai_sdk/_version.py +1 -1
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/__init__.py +101 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/__main__.py +49 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/_sandbox_runner.py +63 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/authoring.py +404 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/client.py +299 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/protocol.py +754 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/runtime.py +936 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/source.py +684 -0
- package/.next/standalone/sdk/python/tests/fixtures/evaluator_v2/README.md +28 -0
- package/.next/standalone/sdk/python/tests/fixtures/evaluator_v2/contract.json +252 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_authoring.py +124 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_client.py +253 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_example.py +35 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_http_e2e.py +636 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_main.py +47 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_protocol.py +246 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_review_fixes.py +164 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_runtime.py +1103 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_source.py +430 -0
- package/.next/standalone/sdk/python/tests/test_zero_dependencies.py +17 -0
- package/.next/standalone/sdk/python/uv.lock +29 -29
- package/.next/standalone/server.js +1 -1
- package/README.md +13 -58
- package/dist/cli.mjs +5368 -8756
- package/dist/worker.mjs +539 -312
- package/lib/auth/api-server-client.ts +28 -0
- package/lib/claude-sessions.ts +101 -27
- package/package.json +14 -13
- package/pi-extension/index.ts +42 -4
- package/scripts/changelog-open.py +115 -0
- package/src/audit/cli.ts +134 -0
- package/src/audit/desktop-notify.ts +420 -0
- package/src/audit/harm-report.ts +101 -0
- package/src/audit/index.ts +141 -13
- package/src/audit/leak-fingerprint.ts +200 -0
- package/src/audit/leak-notice.ts +161 -0
- package/src/audit/leak-record.ts +232 -0
- package/src/audit/leak-scan.ts +292 -0
- package/src/audit/leak-store.ts +217 -0
- package/src/audit/macos-notifier.ts +310 -0
- package/src/audit/redact-example.ts +266 -14
- package/src/audit/report-harm.ts +12 -1
- package/src/audit/report.ts +6 -3
- package/src/audit/schedule-cli.ts +37 -0
- package/src/audit/scoring.ts +49 -0
- package/src/audit/types.ts +41 -0
- package/src/hooks/builtin-policies.ts +67 -2
- package/src/hooks/configure-wizard.ts +20 -0
- package/src/hooks/fp-config.ts +71 -11
- package/src/hooks/fp-home.ts +27 -0
- package/src/hooks/handler.ts +59 -1
- package/src/hooks/integrations.ts +47 -13
- package/src/hooks/notice.ts +155 -0
- package/src/hooks/uninstall-cli.ts +15 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1b5jzxr._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_0j6gd_k._.js +0 -23
- package/.next/standalone/.next/server/chunks/ssr/_0v8eebd._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_1ylae7o._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_1zopuov._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/node_modules_html-to-image_es_index_1ao30b1.js +0 -3
- package/.next/standalone/.next/static/chunks/03slu0c8_71y7.js +0 -1
- package/.next/standalone/.next/static/chunks/0nm11ysn0153h.js +0 -1
- package/.next/standalone/.next/static/chunks/0u64yey446k4f.css +0 -1
- package/.next/standalone/.next/static/chunks/1r9676mkvihto.js +0 -1
- package/.next/standalone/.next/static/chunks/30pct5s734jua.js +0 -6
- package/.next/standalone/.next/static/chunks/3pibxnbhjza7n.js +0 -69
- package/.next/standalone/.next/static/chunks/3qfoeqhy5l10x.js +0 -1
- package/.next/standalone/.next/static/chunks/3zkg2s2vzxc3d.js +0 -1
- package/.next/standalone/.next/static/chunks/41b5ptaocvi_l.js +0 -1
- /package/.next/standalone/.next/static/{JBYgkXkA1PS48m9P_hKNw → aKNv4Kmv98Xpwns0Xa-C-}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{JBYgkXkA1PS48m9P_hKNw → aKNv4Kmv98Xpwns0Xa-C-}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{JBYgkXkA1PS48m9P_hKNw → aKNv4Kmv98Xpwns0Xa-C-}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
import socket
|
|
7
|
+
import threading
|
|
8
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
9
|
+
from dataclasses import replace
|
|
10
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
11
|
+
from urllib.parse import urlsplit
|
|
12
|
+
from uuid import UUID, uuid5
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
from failproofai_sdk.evaluator import (
|
|
17
|
+
Assignment,
|
|
18
|
+
ClaimRequest,
|
|
19
|
+
EvalResult,
|
|
20
|
+
EvalSelection,
|
|
21
|
+
Evaluator,
|
|
22
|
+
EvaluatorAPIError,
|
|
23
|
+
EvaluatorClient,
|
|
24
|
+
HeartbeatRequest,
|
|
25
|
+
HeartbeatRun,
|
|
26
|
+
PlanRequest,
|
|
27
|
+
ResultItem,
|
|
28
|
+
ResultKind,
|
|
29
|
+
ResultRequest,
|
|
30
|
+
Score,
|
|
31
|
+
TerminalRunStatus,
|
|
32
|
+
WorkerConfig,
|
|
33
|
+
WorkerRuntime,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
_NAMESPACE = UUID("4d592d9c-aed4-4f07-9b2d-e14963399df6")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ProtocolState:
|
|
40
|
+
def __init__(self) -> None:
|
|
41
|
+
self.lock = threading.Lock()
|
|
42
|
+
self.base_url = ""
|
|
43
|
+
self.instances = {
|
|
44
|
+
"customer-a-token": ("instance-customer-a", "customer", "org-a"),
|
|
45
|
+
"customer-b-token": ("instance-customer-b", "customer", "org-b"),
|
|
46
|
+
"managed-token": ("instance-managed", "managed", None),
|
|
47
|
+
}
|
|
48
|
+
self.registrations: dict[str, dict] = {}
|
|
49
|
+
self.assignments: dict[str, dict] = {}
|
|
50
|
+
self.runs: dict[str, dict] = {}
|
|
51
|
+
self.result_attempts = 0
|
|
52
|
+
self.result_commits = 0
|
|
53
|
+
self.last_result_body: dict | None = None
|
|
54
|
+
self.drop_first_result_response = False
|
|
55
|
+
|
|
56
|
+
def add_assignment(self, name: str, *, token: str, org: str) -> str:
|
|
57
|
+
assignment_id = str(uuid5(_NAMESPACE, name))
|
|
58
|
+
self.assignments[assignment_id] = {
|
|
59
|
+
"token": token,
|
|
60
|
+
"org": org,
|
|
61
|
+
"status": "available",
|
|
62
|
+
"worker_id": None,
|
|
63
|
+
"lease_generation": 0,
|
|
64
|
+
"expired": False,
|
|
65
|
+
"session_id": f"session-{name}",
|
|
66
|
+
"session_revision_id": f"revision-{name}",
|
|
67
|
+
}
|
|
68
|
+
return assignment_id
|
|
69
|
+
|
|
70
|
+
def expire(self, assignment_id: str) -> None:
|
|
71
|
+
with self.lock:
|
|
72
|
+
self.assignments[assignment_id]["expired"] = True
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class ProtocolServer:
|
|
76
|
+
def __init__(self, state: ProtocolState) -> None:
|
|
77
|
+
self.state = state
|
|
78
|
+
handler = _handler_for(state)
|
|
79
|
+
self.server = ThreadingHTTPServer(("127.0.0.1", 0), handler)
|
|
80
|
+
self.server.daemon_threads = True
|
|
81
|
+
state.base_url = f"http://127.0.0.1:{self.server.server_address[1]}"
|
|
82
|
+
self.thread = threading.Thread(target=self.server.serve_forever, daemon=True)
|
|
83
|
+
|
|
84
|
+
def __enter__(self) -> ProtocolServer: # noqa: PYI034 - Python 3.10 lacks Self
|
|
85
|
+
self.thread.start()
|
|
86
|
+
return self
|
|
87
|
+
|
|
88
|
+
def __exit__(self, *_args) -> None:
|
|
89
|
+
self.server.shutdown()
|
|
90
|
+
self.server.server_close()
|
|
91
|
+
self.thread.join(timeout=5)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _handler_for(state: ProtocolState):
|
|
95
|
+
class Handler(BaseHTTPRequestHandler):
|
|
96
|
+
def do_POST(self) -> None:
|
|
97
|
+
token = self._token()
|
|
98
|
+
if token not in state.instances:
|
|
99
|
+
self._error(401, "invalid_credentials", False)
|
|
100
|
+
return
|
|
101
|
+
body = self._body()
|
|
102
|
+
path = urlsplit(self.path).path
|
|
103
|
+
if path == "/v1/evaluator/workers/register":
|
|
104
|
+
state.registrations[token] = body
|
|
105
|
+
instance_id, kind, _org = state.instances[token]
|
|
106
|
+
self._json(
|
|
107
|
+
200,
|
|
108
|
+
{
|
|
109
|
+
"protocol_version": "2",
|
|
110
|
+
"evaluator_instance_id": instance_id,
|
|
111
|
+
"evaluator_kind": kind,
|
|
112
|
+
"heartbeat_interval_seconds": 30,
|
|
113
|
+
"lease_duration_seconds": 120,
|
|
114
|
+
"poll_interval_seconds": 10,
|
|
115
|
+
"claim_limit": body["max_concurrency"],
|
|
116
|
+
"disabled_definitions": [],
|
|
117
|
+
},
|
|
118
|
+
)
|
|
119
|
+
return
|
|
120
|
+
if path == "/v1/evaluator/assignments/claim":
|
|
121
|
+
self._claim(token, body)
|
|
122
|
+
return
|
|
123
|
+
if path.endswith("/plan"):
|
|
124
|
+
self._plan(token, path.split("/")[-2], body)
|
|
125
|
+
return
|
|
126
|
+
if path == "/v1/evaluator/runs/heartbeat":
|
|
127
|
+
self._heartbeat(token, body)
|
|
128
|
+
return
|
|
129
|
+
if path.endswith("/result"):
|
|
130
|
+
self._result(token, path.split("/")[-2], body)
|
|
131
|
+
return
|
|
132
|
+
self._error(404, "assignment_not_found", False)
|
|
133
|
+
|
|
134
|
+
def do_GET(self) -> None:
|
|
135
|
+
token = self._token()
|
|
136
|
+
if token not in state.instances:
|
|
137
|
+
self._error(401, "invalid_credentials", False)
|
|
138
|
+
return
|
|
139
|
+
path = urlsplit(self.path).path
|
|
140
|
+
if path.endswith("/transcript"):
|
|
141
|
+
self._transcript(token, path.split("/")[-2])
|
|
142
|
+
return
|
|
143
|
+
self._error(404, "assignment_not_found", False)
|
|
144
|
+
|
|
145
|
+
def _claim(self, token: str, body: dict) -> None:
|
|
146
|
+
claimed = []
|
|
147
|
+
with state.lock:
|
|
148
|
+
for assignment_id, item in state.assignments.items():
|
|
149
|
+
if len(claimed) >= body["capacity"]:
|
|
150
|
+
break
|
|
151
|
+
if item["token"] != token:
|
|
152
|
+
continue
|
|
153
|
+
if item["status"] in {"leased", "planned"} and not item["expired"]:
|
|
154
|
+
continue
|
|
155
|
+
if item["status"] not in {"available", "leased", "planned"}:
|
|
156
|
+
continue
|
|
157
|
+
item["status"] = "leased"
|
|
158
|
+
item["expired"] = False
|
|
159
|
+
item["worker_id"] = body["worker_id"]
|
|
160
|
+
item["lease_generation"] += 1
|
|
161
|
+
claimed.append(self._assignment_wire(assignment_id, item))
|
|
162
|
+
self._json(200, {"protocol_version": "2", "assignments": claimed})
|
|
163
|
+
|
|
164
|
+
def _transcript(self, token: str, assignment_id: str) -> None:
|
|
165
|
+
item = self._leased_assignment(
|
|
166
|
+
token,
|
|
167
|
+
assignment_id,
|
|
168
|
+
self.headers.get("X-FailproofAI-Worker-Id"),
|
|
169
|
+
self.headers.get("X-FailproofAI-Lease-Generation"),
|
|
170
|
+
)
|
|
171
|
+
if item is None:
|
|
172
|
+
return
|
|
173
|
+
self._json(
|
|
174
|
+
200,
|
|
175
|
+
{
|
|
176
|
+
"schema_version": "2",
|
|
177
|
+
"assignment_id": assignment_id,
|
|
178
|
+
"session_id": item["session_id"],
|
|
179
|
+
"session_revision_id": item["session_revision_id"],
|
|
180
|
+
"agent_id": "agent-e2e",
|
|
181
|
+
"environment": "test",
|
|
182
|
+
"started_at": "2026-08-28T12:00:00.000000Z",
|
|
183
|
+
"ended_at": "2026-08-28T12:00:01.000000Z",
|
|
184
|
+
"event_count": 1,
|
|
185
|
+
"events": [
|
|
186
|
+
{
|
|
187
|
+
"id": "event-1",
|
|
188
|
+
"ts": "2026-08-28T12:00:00.500000Z",
|
|
189
|
+
"event_type": "model_response",
|
|
190
|
+
"payload": {"content": "done"},
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
def _plan(self, token: str, assignment_id: str, body: dict) -> None:
|
|
197
|
+
item = self._leased_assignment(
|
|
198
|
+
token, assignment_id, body["worker_id"], body["lease_generation"]
|
|
199
|
+
)
|
|
200
|
+
if item is None:
|
|
201
|
+
return
|
|
202
|
+
runs = []
|
|
203
|
+
with state.lock:
|
|
204
|
+
for selected in body["selected"]:
|
|
205
|
+
run_id = str(
|
|
206
|
+
uuid5(
|
|
207
|
+
_NAMESPACE,
|
|
208
|
+
f"{assignment_id}:{selected['eval_key']}:{selected['eval_version']}",
|
|
209
|
+
)
|
|
210
|
+
)
|
|
211
|
+
run = state.runs.setdefault(
|
|
212
|
+
run_id,
|
|
213
|
+
{
|
|
214
|
+
"token": token,
|
|
215
|
+
"assignment_id": assignment_id,
|
|
216
|
+
"worker_id": body["worker_id"],
|
|
217
|
+
"lease_generation": body["lease_generation"],
|
|
218
|
+
"submission_id": None,
|
|
219
|
+
"checksum": None,
|
|
220
|
+
},
|
|
221
|
+
)
|
|
222
|
+
if run["submission_id"] is None:
|
|
223
|
+
run["worker_id"] = body["worker_id"]
|
|
224
|
+
run["lease_generation"] = body["lease_generation"]
|
|
225
|
+
runs.append(
|
|
226
|
+
{
|
|
227
|
+
"evaluation_run_id": run_id,
|
|
228
|
+
"execution_mode": "local",
|
|
229
|
+
**selected,
|
|
230
|
+
}
|
|
231
|
+
)
|
|
232
|
+
item["status"] = "planned" if runs else "skipped"
|
|
233
|
+
self._json(
|
|
234
|
+
200,
|
|
235
|
+
{
|
|
236
|
+
"protocol_version": "2",
|
|
237
|
+
"assignment_id": assignment_id,
|
|
238
|
+
"assignment_status": item["status"],
|
|
239
|
+
"runs": runs,
|
|
240
|
+
},
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
def _heartbeat(self, token: str, body: dict) -> None:
|
|
244
|
+
accepted = []
|
|
245
|
+
with state.lock:
|
|
246
|
+
for requested in body["runs"]:
|
|
247
|
+
run = state.runs.get(requested["evaluation_run_id"])
|
|
248
|
+
assignment = (
|
|
249
|
+
state.assignments.get(run["assignment_id"])
|
|
250
|
+
if run is not None
|
|
251
|
+
else None
|
|
252
|
+
)
|
|
253
|
+
if (
|
|
254
|
+
run is not None
|
|
255
|
+
and assignment is not None
|
|
256
|
+
and run["token"] == token
|
|
257
|
+
and run["worker_id"] == body["worker_id"]
|
|
258
|
+
and run["lease_generation"] == body["lease_generation"]
|
|
259
|
+
and assignment["worker_id"] == body["worker_id"]
|
|
260
|
+
and assignment["lease_generation"] == body["lease_generation"]
|
|
261
|
+
and not assignment["expired"]
|
|
262
|
+
):
|
|
263
|
+
accepted.append(requested["evaluation_run_id"])
|
|
264
|
+
if not accepted:
|
|
265
|
+
self._error(409, "lease_lost", False)
|
|
266
|
+
return
|
|
267
|
+
self._json(
|
|
268
|
+
200,
|
|
269
|
+
{
|
|
270
|
+
"protocol_version": "2",
|
|
271
|
+
"lease_expires_at": "2026-08-28T12:02:30.000000Z",
|
|
272
|
+
"accepted_run_ids": accepted,
|
|
273
|
+
},
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
def _result(self, token: str, run_id: str, body: dict) -> None:
|
|
277
|
+
with state.lock:
|
|
278
|
+
run = state.runs.get(run_id)
|
|
279
|
+
if run is None or run["token"] != token:
|
|
280
|
+
self._error(404, "run_not_found", False)
|
|
281
|
+
return
|
|
282
|
+
if (
|
|
283
|
+
run["worker_id"] != body["worker_id"]
|
|
284
|
+
or run["lease_generation"] != body["lease_generation"]
|
|
285
|
+
):
|
|
286
|
+
self._error(409, "lease_lost", False)
|
|
287
|
+
return
|
|
288
|
+
checksum = hashlib.sha256(
|
|
289
|
+
json.dumps(body, sort_keys=True, separators=(",", ":")).encode()
|
|
290
|
+
).hexdigest()
|
|
291
|
+
if run["submission_id"] is not None:
|
|
292
|
+
if (
|
|
293
|
+
run["submission_id"] != body["submission_id"]
|
|
294
|
+
or run["checksum"] != checksum
|
|
295
|
+
):
|
|
296
|
+
self._error(409, "submission_conflict", False)
|
|
297
|
+
return
|
|
298
|
+
replay = True
|
|
299
|
+
else:
|
|
300
|
+
run["submission_id"] = body["submission_id"]
|
|
301
|
+
run["checksum"] = checksum
|
|
302
|
+
state.result_commits += 1
|
|
303
|
+
state.last_result_body = body
|
|
304
|
+
replay = False
|
|
305
|
+
state.result_attempts += 1
|
|
306
|
+
drop = state.drop_first_result_response and state.result_attempts == 1
|
|
307
|
+
if drop:
|
|
308
|
+
self.connection.shutdown(socket.SHUT_RDWR)
|
|
309
|
+
self.connection.close()
|
|
310
|
+
return
|
|
311
|
+
self._json(
|
|
312
|
+
200,
|
|
313
|
+
{
|
|
314
|
+
"protocol_version": "2",
|
|
315
|
+
"evaluation_run_id": run_id,
|
|
316
|
+
"submission_id": body["submission_id"],
|
|
317
|
+
"status": "committed",
|
|
318
|
+
"idempotent_replay": replay,
|
|
319
|
+
"result_count": len(body["results"]),
|
|
320
|
+
"result_checksum": checksum,
|
|
321
|
+
},
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
def _leased_assignment(
|
|
325
|
+
self,
|
|
326
|
+
token: str,
|
|
327
|
+
assignment_id: str,
|
|
328
|
+
worker_id: str | None,
|
|
329
|
+
generation: str | int | None,
|
|
330
|
+
) -> dict | None:
|
|
331
|
+
with state.lock:
|
|
332
|
+
item = state.assignments.get(assignment_id)
|
|
333
|
+
if item is None or item["token"] != token:
|
|
334
|
+
self._error(404, "assignment_not_found", False)
|
|
335
|
+
return None
|
|
336
|
+
try:
|
|
337
|
+
generation = int(generation) if generation is not None else None
|
|
338
|
+
except ValueError:
|
|
339
|
+
generation = None
|
|
340
|
+
if (
|
|
341
|
+
item["status"] != "leased"
|
|
342
|
+
or item["expired"]
|
|
343
|
+
or item["worker_id"] != worker_id
|
|
344
|
+
or item["lease_generation"] != generation
|
|
345
|
+
):
|
|
346
|
+
self._error(409, "lease_lost", False)
|
|
347
|
+
return None
|
|
348
|
+
return item
|
|
349
|
+
|
|
350
|
+
def _assignment_wire(self, assignment_id: str, item: dict) -> dict:
|
|
351
|
+
return {
|
|
352
|
+
"assignment_id": assignment_id,
|
|
353
|
+
"lease_generation": item["lease_generation"],
|
|
354
|
+
"lease_expires_at": "2026-08-28T12:02:00.000000Z",
|
|
355
|
+
"session_id": item["session_id"],
|
|
356
|
+
"session_revision_id": item["session_revision_id"],
|
|
357
|
+
"agent_id": "agent-e2e",
|
|
358
|
+
"environment": "test",
|
|
359
|
+
"trigger_reason": "agent_end",
|
|
360
|
+
"event_count": 1,
|
|
361
|
+
"transcript_url": (
|
|
362
|
+
f"{state.base_url}/v1/evaluator/assignments/"
|
|
363
|
+
f"{assignment_id}/transcript"
|
|
364
|
+
),
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
def _token(self) -> str | None:
|
|
368
|
+
value = self.headers.get("Authorization", "")
|
|
369
|
+
return (
|
|
370
|
+
value.removeprefix("Bearer ") if value.startswith("Bearer ") else None
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
def _body(self) -> dict:
|
|
374
|
+
size = int(self.headers.get("Content-Length", "0"))
|
|
375
|
+
return json.loads(self.rfile.read(size))
|
|
376
|
+
|
|
377
|
+
def _error(self, status: int, code: str, retryable: bool) -> None:
|
|
378
|
+
self._json(
|
|
379
|
+
status,
|
|
380
|
+
{
|
|
381
|
+
"protocol_version": "2",
|
|
382
|
+
"error": {
|
|
383
|
+
"code": code,
|
|
384
|
+
"message": code.replace("_", " "),
|
|
385
|
+
"retryable": retryable,
|
|
386
|
+
"request_id": "request-e2e",
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
def _json(self, status: int, value: dict) -> None:
|
|
392
|
+
body = json.dumps(value, separators=(",", ":")).encode()
|
|
393
|
+
self.send_response(status)
|
|
394
|
+
self.send_header("Content-Type", "application/json")
|
|
395
|
+
self.send_header("Content-Length", str(len(body)))
|
|
396
|
+
self.end_headers()
|
|
397
|
+
self.wfile.write(body)
|
|
398
|
+
|
|
399
|
+
def log_message(self, format: str, *args) -> None:
|
|
400
|
+
return
|
|
401
|
+
|
|
402
|
+
return Handler
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def _client(state: ProtocolState, token: str) -> EvaluatorClient:
|
|
406
|
+
return EvaluatorClient(
|
|
407
|
+
base_url=state.base_url,
|
|
408
|
+
credential=token,
|
|
409
|
+
max_retries=2,
|
|
410
|
+
sleeper=lambda _seconds: None,
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def _claim(client: EvaluatorClient, worker_id: str):
|
|
415
|
+
return client.claim(
|
|
416
|
+
ClaimRequest(
|
|
417
|
+
worker_id=worker_id,
|
|
418
|
+
catalog_revision="sha256:" + "a" * 64,
|
|
419
|
+
capacity=1,
|
|
420
|
+
)
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
def test_real_http_worker_survives_lost_result_response_without_duplicate_commit():
|
|
425
|
+
state = ProtocolState()
|
|
426
|
+
state.add_assignment("runtime", token="customer-a-token", org="org-a")
|
|
427
|
+
state.drop_first_result_response = True
|
|
428
|
+
evaluator = Evaluator(name="e2e", version="1")
|
|
429
|
+
|
|
430
|
+
@evaluator.eval("completion_present", version="1")
|
|
431
|
+
def completion_present(session):
|
|
432
|
+
return EvalResult(score=Score(float(bool(session.events))))
|
|
433
|
+
|
|
434
|
+
with ProtocolServer(state):
|
|
435
|
+
runtime = WorkerRuntime(
|
|
436
|
+
evaluator,
|
|
437
|
+
WorkerConfig(
|
|
438
|
+
server_url=state.base_url,
|
|
439
|
+
credential="customer-a-token",
|
|
440
|
+
worker_id="worker-a",
|
|
441
|
+
),
|
|
442
|
+
client=_client(state, "customer-a-token"),
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
async def run():
|
|
446
|
+
await runtime.register()
|
|
447
|
+
return await runtime.run_once()
|
|
448
|
+
|
|
449
|
+
assert asyncio.run(run()) == 1
|
|
450
|
+
|
|
451
|
+
run_id = next(iter(state.runs))
|
|
452
|
+
committed = ResultRequest.from_wire(state.last_result_body)
|
|
453
|
+
replay = runtime.client.submit_result(run_id, committed)
|
|
454
|
+
assert replay.idempotent_replay is True
|
|
455
|
+
|
|
456
|
+
with pytest.raises(EvaluatorAPIError) as caught:
|
|
457
|
+
runtime.client.submit_result(
|
|
458
|
+
run_id,
|
|
459
|
+
replace(committed, summary="different content"),
|
|
460
|
+
)
|
|
461
|
+
assert caught.value.code == "submission_conflict"
|
|
462
|
+
|
|
463
|
+
assert state.result_attempts == 3
|
|
464
|
+
assert state.result_commits == 1
|
|
465
|
+
assert len(state.runs) == 1
|
|
466
|
+
assert next(iter(state.runs.values()))["submission_id"] is not None
|
|
467
|
+
assert runtime.metrics()["runs_succeeded"] == 1
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
def test_two_workers_racing_receive_one_unique_lease():
|
|
471
|
+
state = ProtocolState()
|
|
472
|
+
assignment_id = state.add_assignment("race", token="customer-a-token", org="org-a")
|
|
473
|
+
with ProtocolServer(state):
|
|
474
|
+
first = _client(state, "customer-a-token")
|
|
475
|
+
second = _client(state, "customer-a-token")
|
|
476
|
+
with ThreadPoolExecutor(max_workers=2) as executor:
|
|
477
|
+
responses = list(
|
|
478
|
+
executor.map(
|
|
479
|
+
lambda pair: _claim(*pair),
|
|
480
|
+
[(first, "worker-a"), (second, "worker-b")],
|
|
481
|
+
)
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
claimed = [item for response in responses for item in response.assignments]
|
|
485
|
+
assert [item.assignment_id for item in claimed] == [assignment_id]
|
|
486
|
+
assert state.assignments[assignment_id]["lease_generation"] == 1
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
def test_expired_lease_is_reclaimed_and_stale_worker_is_fenced():
|
|
490
|
+
state = ProtocolState()
|
|
491
|
+
assignment_id = state.add_assignment(
|
|
492
|
+
"reclaim", token="customer-a-token", org="org-a"
|
|
493
|
+
)
|
|
494
|
+
with ProtocolServer(state):
|
|
495
|
+
client = _client(state, "customer-a-token")
|
|
496
|
+
first = _claim(client, "worker-a").assignments[0]
|
|
497
|
+
plan = client.plan(
|
|
498
|
+
assignment_id,
|
|
499
|
+
PlanRequest(
|
|
500
|
+
worker_id="worker-a",
|
|
501
|
+
lease_generation=first.lease_generation,
|
|
502
|
+
selected=(EvalSelection("quality", "1"),),
|
|
503
|
+
),
|
|
504
|
+
)
|
|
505
|
+
state.expire(assignment_id)
|
|
506
|
+
second = _claim(client, "worker-b").assignments[0]
|
|
507
|
+
|
|
508
|
+
assert second.lease_generation == first.lease_generation + 1
|
|
509
|
+
with pytest.raises(EvaluatorAPIError) as caught:
|
|
510
|
+
client.transcript(first, worker_id="worker-a")
|
|
511
|
+
assert caught.value.code == "lease_lost"
|
|
512
|
+
assert caught.value.retryable is False
|
|
513
|
+
|
|
514
|
+
with pytest.raises(EvaluatorAPIError) as caught:
|
|
515
|
+
client.heartbeat(
|
|
516
|
+
HeartbeatRequest(
|
|
517
|
+
worker_id="worker-a",
|
|
518
|
+
lease_generation=first.lease_generation,
|
|
519
|
+
runs=(HeartbeatRun(plan.runs[0].evaluation_run_id, "running"),),
|
|
520
|
+
)
|
|
521
|
+
)
|
|
522
|
+
assert caught.value.code == "lease_lost"
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
def test_replacement_worker_finishes_after_forced_worker_loss():
|
|
526
|
+
state = ProtocolState()
|
|
527
|
+
assignment_id = state.add_assignment(
|
|
528
|
+
"forced-worker-loss", token="customer-a-token", org="org-a"
|
|
529
|
+
)
|
|
530
|
+
result_sample = ResultRequest(
|
|
531
|
+
submission_id=str(uuid5(_NAMESPACE, "forced-worker-loss-result")),
|
|
532
|
+
worker_id="worker-a",
|
|
533
|
+
lease_generation=1,
|
|
534
|
+
status=TerminalRunStatus.SUCCEEDED,
|
|
535
|
+
started_at="2026-08-28T12:00:10.000000Z",
|
|
536
|
+
finished_at="2026-08-28T12:00:10.100000Z",
|
|
537
|
+
duration_ms=100,
|
|
538
|
+
summary="Replacement worker completed the evaluation.",
|
|
539
|
+
results=(
|
|
540
|
+
ResultItem(
|
|
541
|
+
result_key="quality",
|
|
542
|
+
result_kind=ResultKind.SCORE,
|
|
543
|
+
numeric_value=1.0,
|
|
544
|
+
),
|
|
545
|
+
),
|
|
546
|
+
error_code=None,
|
|
547
|
+
error_message=None,
|
|
548
|
+
)
|
|
549
|
+
|
|
550
|
+
with ProtocolServer(state):
|
|
551
|
+
client = _client(state, "customer-a-token")
|
|
552
|
+
first = _claim(client, "worker-a").assignments[0]
|
|
553
|
+
first_plan = client.plan(
|
|
554
|
+
assignment_id,
|
|
555
|
+
PlanRequest(
|
|
556
|
+
worker_id="worker-a",
|
|
557
|
+
lease_generation=first.lease_generation,
|
|
558
|
+
selected=(EvalSelection("quality", "1"),),
|
|
559
|
+
),
|
|
560
|
+
)
|
|
561
|
+
|
|
562
|
+
# Worker A disappears after planning. Its lease expires and worker B
|
|
563
|
+
# reclaims the same logical assignment and deterministic run.
|
|
564
|
+
state.expire(assignment_id)
|
|
565
|
+
second = _claim(client, "worker-b").assignments[0]
|
|
566
|
+
second_plan = client.plan(
|
|
567
|
+
assignment_id,
|
|
568
|
+
PlanRequest(
|
|
569
|
+
worker_id="worker-b",
|
|
570
|
+
lease_generation=second.lease_generation,
|
|
571
|
+
selected=(EvalSelection("quality", "1"),),
|
|
572
|
+
),
|
|
573
|
+
)
|
|
574
|
+
assert (
|
|
575
|
+
second_plan.runs[0].evaluation_run_id
|
|
576
|
+
== first_plan.runs[0].evaluation_run_id
|
|
577
|
+
)
|
|
578
|
+
|
|
579
|
+
stale_result = replace(
|
|
580
|
+
result_sample,
|
|
581
|
+
worker_id="worker-a",
|
|
582
|
+
lease_generation=first.lease_generation,
|
|
583
|
+
)
|
|
584
|
+
with pytest.raises(EvaluatorAPIError) as caught:
|
|
585
|
+
client.submit_result(first_plan.runs[0].evaluation_run_id, stale_result)
|
|
586
|
+
assert caught.value.code == "lease_lost"
|
|
587
|
+
|
|
588
|
+
replacement_result = replace(
|
|
589
|
+
result_sample,
|
|
590
|
+
worker_id="worker-b",
|
|
591
|
+
lease_generation=second.lease_generation,
|
|
592
|
+
)
|
|
593
|
+
committed = client.submit_result(
|
|
594
|
+
second_plan.runs[0].evaluation_run_id, replacement_result
|
|
595
|
+
)
|
|
596
|
+
assert committed.status == "committed"
|
|
597
|
+
assert committed.idempotent_replay is False
|
|
598
|
+
|
|
599
|
+
assert state.result_attempts == 1
|
|
600
|
+
assert state.result_commits == 1
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
def test_customer_tenants_are_isolated_and_managed_worker_coexists():
|
|
604
|
+
state = ProtocolState()
|
|
605
|
+
customer_id = state.add_assignment(
|
|
606
|
+
"customer", token="customer-a-token", org="org-a"
|
|
607
|
+
)
|
|
608
|
+
managed_id = state.add_assignment("managed", token="managed-token", org="org-b")
|
|
609
|
+
with ProtocolServer(state):
|
|
610
|
+
customer_a = _client(state, "customer-a-token")
|
|
611
|
+
customer_b = _client(state, "customer-b-token")
|
|
612
|
+
managed = _client(state, "managed-token")
|
|
613
|
+
|
|
614
|
+
customer_assignment = _claim(customer_a, "worker-a").assignments[0]
|
|
615
|
+
assert customer_assignment.assignment_id == customer_id
|
|
616
|
+
assert _claim(customer_b, "worker-b").assignments == ()
|
|
617
|
+
assert (
|
|
618
|
+
_claim(managed, "worker-managed").assignments[0].assignment_id == managed_id
|
|
619
|
+
)
|
|
620
|
+
|
|
621
|
+
stolen = Assignment(
|
|
622
|
+
assignment_id=customer_assignment.assignment_id,
|
|
623
|
+
lease_generation=customer_assignment.lease_generation,
|
|
624
|
+
lease_expires_at=customer_assignment.lease_expires_at,
|
|
625
|
+
session_id=customer_assignment.session_id,
|
|
626
|
+
session_revision_id=customer_assignment.session_revision_id,
|
|
627
|
+
agent_id=customer_assignment.agent_id,
|
|
628
|
+
environment=customer_assignment.environment,
|
|
629
|
+
trigger_reason=customer_assignment.trigger_reason,
|
|
630
|
+
event_count=customer_assignment.event_count,
|
|
631
|
+
transcript_url=customer_assignment.transcript_url,
|
|
632
|
+
)
|
|
633
|
+
with pytest.raises(EvaluatorAPIError) as caught:
|
|
634
|
+
customer_b.transcript(stolen, worker_id="worker-a")
|
|
635
|
+
assert caught.value.status == 404
|
|
636
|
+
assert caught.value.code == "assignment_not_found"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from failproofai_sdk.evaluator import Evaluator
|
|
8
|
+
from failproofai_sdk.evaluator.__main__ import load_evaluator
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_module_loader_defaults_to_app(tmp_path, monkeypatch):
|
|
12
|
+
(tmp_path / "my_evals.py").write_text(
|
|
13
|
+
"from failproofai_sdk.evaluator import Evaluator\n"
|
|
14
|
+
"app = Evaluator(name='example', version='1')\n",
|
|
15
|
+
encoding="utf-8",
|
|
16
|
+
)
|
|
17
|
+
monkeypatch.syspath_prepend(str(tmp_path))
|
|
18
|
+
try:
|
|
19
|
+
loaded = load_evaluator("my_evals")
|
|
20
|
+
finally:
|
|
21
|
+
sys.modules.pop("my_evals", None)
|
|
22
|
+
assert isinstance(loaded, Evaluator)
|
|
23
|
+
assert loaded.name == "example"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_module_loader_supports_an_explicit_attribute(tmp_path, monkeypatch):
|
|
27
|
+
(tmp_path / "custom_evals.py").write_text(
|
|
28
|
+
"from failproofai_sdk.evaluator import Evaluator\n"
|
|
29
|
+
"worker = Evaluator(name='custom', version='1')\n",
|
|
30
|
+
encoding="utf-8",
|
|
31
|
+
)
|
|
32
|
+
monkeypatch.syspath_prepend(str(tmp_path))
|
|
33
|
+
try:
|
|
34
|
+
loaded = load_evaluator("custom_evals:worker")
|
|
35
|
+
finally:
|
|
36
|
+
sys.modules.pop("custom_evals", None)
|
|
37
|
+
assert loaded.name == "custom"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_module_loader_rejects_the_wrong_object_type(tmp_path, monkeypatch):
|
|
41
|
+
(tmp_path / "not_evals.py").write_text("app = object()\n", encoding="utf-8")
|
|
42
|
+
monkeypatch.syspath_prepend(str(tmp_path))
|
|
43
|
+
try:
|
|
44
|
+
with pytest.raises(TypeError, match="not Evaluator"):
|
|
45
|
+
load_evaluator("not_evals")
|
|
46
|
+
finally:
|
|
47
|
+
sys.modules.pop("not_evals", None)
|