niceeval 0.13.1 → 0.13.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/INDEX.md +25 -2
- package/README.md +9 -10
- package/README.zh.md +9 -10
- package/dist/agents/ai-sdk.cjs.map +1 -1
- package/dist/agents/ai-sdk.d.cts +1 -1
- package/dist/agents/ai-sdk.d.mts +1 -1
- package/dist/agents/ai-sdk.d.ts +1 -1
- package/dist/agents/bub-install-spec.cjs +19 -5
- package/dist/agents/bub-install-spec.cjs.map +1 -1
- package/dist/agents/bub-install-spec.d.cts +9 -2
- package/dist/agents/bub-install-spec.d.mts +9 -2
- package/dist/agents/bub-install-spec.d.ts +9 -2
- package/dist/agents/bub-install-spec.js +14 -12
- package/dist/agents/bub.cjs +10 -6
- package/dist/agents/bub.cjs.map +1 -1
- package/dist/agents/bub.d.cts +2 -2
- package/dist/agents/bub.d.mts +2 -2
- package/dist/agents/bub.d.ts +2 -2
- package/dist/agents/claude-code.cjs.map +1 -1
- package/dist/agents/claude-code.d.cts +2 -2
- package/dist/agents/claude-code.d.mts +2 -2
- package/dist/agents/claude-code.d.ts +2 -2
- package/dist/agents/codex.cjs +4 -4
- package/dist/agents/codex.cjs.map +1 -1
- package/dist/agents/codex.d.cts +3 -3
- package/dist/agents/codex.d.mts +3 -3
- package/dist/agents/codex.d.ts +3 -3
- package/dist/agents/coding-cli-versions.cjs +10 -1
- package/dist/agents/coding-cli-versions.cjs.map +1 -1
- package/dist/agents/coding-cli-versions.d.cts +8 -3
- package/dist/agents/coding-cli-versions.d.mts +8 -3
- package/dist/agents/coding-cli-versions.d.ts +8 -3
- package/dist/agents/coding-cli-versions.js +18 -12
- package/dist/agents/deepseek-harness.cjs +151 -0
- package/dist/agents/deepseek-harness.cjs.map +1 -0
- package/dist/agents/deepseek-harness.d.cts +14 -0
- package/dist/agents/deepseek-harness.d.mts +14 -0
- package/dist/agents/deepseek-harness.d.ts +14 -0
- package/dist/agents/deepseek-harness.js +7 -0
- package/dist/agents/deepseek-harness.js.map +1 -0
- package/dist/agents/exact-npm-plugins.cjs +28 -0
- package/dist/agents/exact-npm-plugins.cjs.map +1 -0
- package/dist/agents/exact-npm-plugins.d.cts +10 -0
- package/dist/agents/exact-npm-plugins.d.mts +10 -0
- package/dist/agents/exact-npm-plugins.d.ts +10 -0
- package/dist/agents/exact-npm-plugins.js +8 -0
- package/dist/agents/exact-npm-plugins.js.map +1 -0
- package/dist/agents/index.cjs +5 -1
- package/dist/agents/index.cjs.map +1 -1
- package/dist/agents/index.d.cts +4 -0
- package/dist/agents/index.d.mts +4 -0
- package/dist/agents/index.d.ts +4 -0
- package/dist/agents/index.js +54 -50
- package/dist/agents/index.mjs +54 -50
- package/dist/agents/omp.cjs +170 -0
- package/dist/agents/omp.cjs.map +1 -0
- package/dist/agents/omp.d.cts +14 -0
- package/dist/agents/omp.d.mts +14 -0
- package/dist/agents/omp.d.ts +14 -0
- package/dist/agents/omp.js +7 -0
- package/dist/agents/omp.js.map +1 -0
- package/dist/agents/openclaw.cjs +51 -2
- package/dist/agents/openclaw.cjs.map +1 -1
- package/dist/agents/openclaw.d.cts +2 -0
- package/dist/agents/openclaw.d.mts +2 -0
- package/dist/agents/openclaw.d.ts +2 -0
- package/dist/agents/types.cjs.map +1 -1
- package/dist/agents/types.d.cts +4 -4
- package/dist/agents/types.d.mts +4 -4
- package/dist/agents/types.d.ts +4 -4
- package/dist/agents/ui-message-stream.cjs +24 -7
- package/dist/agents/ui-message-stream.cjs.map +1 -1
- package/dist/analysis/api.cjs +28 -2
- package/dist/analysis/api.cjs.map +1 -1
- package/dist/analysis/api.d.cts +22 -1
- package/dist/analysis/api.d.mts +22 -1
- package/dist/analysis/api.d.ts +22 -1
- package/dist/analysis/api.js +8 -6
- package/dist/analysis/bindings.cjs +11 -18
- package/dist/analysis/bindings.cjs.map +1 -1
- package/dist/analysis/bindings.d.cts +177 -49
- package/dist/analysis/bindings.d.mts +177 -49
- package/dist/analysis/bindings.d.ts +177 -49
- package/dist/analysis/contracts.cjs +1 -0
- package/dist/analysis/contracts.cjs.map +1 -1
- package/dist/analysis/contracts.d.cts +43 -3
- package/dist/analysis/contracts.d.mts +43 -3
- package/dist/analysis/contracts.d.ts +43 -3
- package/dist/analysis/cost-projection.cjs +2 -1
- package/dist/analysis/cost-projection.cjs.map +1 -1
- package/dist/analysis/cost-projection.d.cts +1 -1
- package/dist/analysis/cost-projection.d.mts +1 -1
- package/dist/analysis/cost-projection.d.ts +1 -1
- package/dist/analysis/cost.cjs +13 -3
- package/dist/analysis/cost.cjs.map +1 -1
- package/dist/analysis/cost.d.cts +10 -3
- package/dist/analysis/cost.d.mts +10 -3
- package/dist/analysis/cost.d.ts +10 -3
- package/dist/analysis/experiment-groups.cjs +96 -0
- package/dist/analysis/experiment-groups.cjs.map +1 -0
- package/dist/analysis/experiment-groups.d.cts +9 -0
- package/dist/analysis/experiment-groups.d.mts +9 -0
- package/dist/analysis/experiment-groups.d.ts +9 -0
- package/dist/analysis/experiment-groups.js +10 -0
- package/dist/analysis/experiment-groups.js.map +1 -0
- package/dist/analysis/index.cjs +4 -1
- package/dist/analysis/index.cjs.map +1 -1
- package/dist/analysis/index.d.cts +4 -2
- package/dist/analysis/index.d.mts +4 -2
- package/dist/analysis/index.d.ts +4 -2
- package/dist/analysis/index.js +40 -36
- package/dist/analysis/index.mjs +40 -36
- package/dist/assertions/limits.cjs +4 -0
- package/dist/assertions/limits.cjs.map +1 -1
- package/dist/assertions/limits.d.cts +4 -0
- package/dist/assertions/limits.d.mts +4 -0
- package/dist/assertions/limits.d.ts +4 -0
- package/dist/assertions/match.cjs +63 -25
- package/dist/assertions/match.cjs.map +1 -1
- package/dist/assertions/match.d.cts +7 -0
- package/dist/assertions/match.d.mts +7 -0
- package/dist/assertions/match.d.ts +7 -0
- package/dist/assertions/record/attachment.cjs +32 -4
- package/dist/assertions/record/attachment.cjs.map +1 -1
- package/dist/assertions/record/diff.cjs +10 -4
- package/dist/assertions/record/diff.cjs.map +1 -1
- package/dist/assertions/record/producer.cjs +101 -4
- package/dist/assertions/record/producer.cjs.map +1 -1
- package/dist/assertions/record/producer.d.cts +4 -1
- package/dist/assertions/record/producer.d.mts +4 -1
- package/dist/assertions/record/producer.d.ts +4 -1
- package/dist/assertions/runtime.cjs +45 -5
- package/dist/assertions/runtime.cjs.map +1 -1
- package/dist/cli/record.cjs +113 -8
- package/dist/cli/record.cjs.map +1 -1
- package/dist/cli/record.d.cts +20 -1
- package/dist/cli/record.d.mts +20 -1
- package/dist/cli/record.d.ts +20 -1
- package/dist/cli/record.js +4 -2
- package/dist/cli.cjs +386 -31
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +10 -2
- package/dist/cli.d.mts +10 -2
- package/dist/cli.d.ts +10 -2
- package/dist/context/send-retry.cjs +4 -4
- package/dist/context/send-retry.cjs.map +1 -1
- package/dist/coordination/host/runtime.cjs +8 -30
- package/dist/coordination/host/runtime.cjs.map +1 -1
- package/dist/coordination/host/runtime.d.cts +3 -3
- package/dist/coordination/host/runtime.d.mts +3 -3
- package/dist/coordination/host/runtime.d.ts +3 -3
- package/dist/coordination/host/types.cjs.map +1 -1
- package/dist/coordination/host/types.d.cts +0 -5
- package/dist/coordination/host/types.d.mts +0 -5
- package/dist/coordination/host/types.d.ts +0 -5
- package/dist/coordination/platform/node.cjs +90 -9
- package/dist/coordination/platform/node.cjs.map +1 -1
- package/dist/define.cjs +25 -1
- package/dist/define.cjs.map +1 -1
- package/dist/experiment/host/index.cjs +1 -0
- package/dist/experiment/host/index.cjs.map +1 -1
- package/dist/i18n/en.cjs +26 -8
- package/dist/i18n/en.cjs.map +1 -1
- package/dist/i18n/en.d.cts +19 -6
- package/dist/i18n/en.d.mts +19 -6
- package/dist/i18n/en.d.ts +19 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/o11y/parsers/hermes.cjs +1 -1
- package/dist/o11y/parsers/hermes.cjs.map +1 -1
- package/dist/o11y/prices.json +1 -1
- package/dist/o11y/record/families.cjs +12 -3
- package/dist/o11y/record/families.cjs.map +1 -1
- package/dist/o11y/record/families.d.cts +8 -8
- package/dist/o11y/record/families.d.mts +8 -8
- package/dist/o11y/record/families.d.ts +8 -8
- package/dist/o11y/record/family-projectors.d.cts +66 -18
- package/dist/o11y/record/family-projectors.d.mts +66 -18
- package/dist/o11y/record/family-projectors.d.ts +66 -18
- package/dist/o11y/record/family-writers.d.cts +11 -3
- package/dist/o11y/record/family-writers.d.mts +11 -3
- package/dist/o11y/record/family-writers.d.ts +11 -3
- package/dist/o11y/record/runner-producer.cjs +14 -4
- package/dist/o11y/record/runner-producer.cjs.map +1 -1
- package/dist/record/codec/core.d.cts +2 -2
- package/dist/record/codec/core.d.mts +2 -2
- package/dist/record/codec/core.d.ts +2 -2
- package/dist/record/family/catalog.d.cts +44 -12
- package/dist/record/family/catalog.d.mts +44 -12
- package/dist/record/family/catalog.d.ts +44 -12
- package/dist/record/family/index.js +128 -124
- package/dist/record/family/observability-v1.cjs +35 -0
- package/dist/record/family/observability-v1.cjs.map +1 -0
- package/dist/record/family/observability-v1.d.cts +3 -0
- package/dist/record/family/observability-v1.d.mts +3 -0
- package/dist/record/family/observability-v1.d.ts +3 -0
- package/dist/record/family/observability-v1.js +6 -0
- package/dist/record/family/observability-v1.js.map +1 -0
- package/dist/record/family/observability.cjs +58 -9
- package/dist/record/family/observability.cjs.map +1 -1
- package/dist/record/family/observability.d.cts +1014 -15
- package/dist/record/family/observability.d.mts +1014 -15
- package/dist/record/family/observability.d.ts +1014 -15
- package/dist/record/family/observability.js +22 -18
- package/dist/record/host/runtime.cjs +600 -31
- package/dist/record/host/runtime.cjs.map +1 -1
- package/dist/record/host/types.cjs.map +1 -1
- package/dist/record/host/types.d.cts +33 -9
- package/dist/record/host/types.d.mts +33 -9
- package/dist/record/host/types.d.ts +33 -9
- package/dist/record/maintenance/runtime.cjs +1 -2
- package/dist/record/maintenance/runtime.cjs.map +1 -1
- package/dist/record/model/core.cjs.map +1 -1
- package/dist/record/model/core.d.cts +1 -1
- package/dist/record/model/core.d.mts +1 -1
- package/dist/record/model/core.d.ts +1 -1
- package/dist/record/model/definition.d.cts +6 -6
- package/dist/record/model/definition.d.mts +6 -6
- package/dist/record/model/definition.d.ts +6 -6
- package/dist/record/model/identifiers.cjs +1 -1
- package/dist/record/model/identifiers.cjs.map +1 -1
- package/dist/record/model/identifiers.d.cts +1 -1
- package/dist/record/model/identifiers.d.mts +1 -1
- package/dist/record/model/identifiers.d.ts +1 -1
- package/dist/record/platform/node.cjs +159 -23
- package/dist/record/platform/node.cjs.map +1 -1
- package/dist/record/platform/services.cjs.map +1 -1
- package/dist/record/platform/services.d.cts +15 -2
- package/dist/record/platform/services.d.mts +15 -2
- package/dist/record/platform/services.d.ts +15 -2
- package/dist/record/reader/errors.cjs +37 -1
- package/dist/record/reader/errors.cjs.map +1 -1
- package/dist/record/reader/errors.d.cts +49 -1
- package/dist/record/reader/errors.d.mts +49 -1
- package/dist/record/reader/errors.d.ts +49 -1
- package/dist/record/reader/errors.js +22 -12
- package/dist/record/reader/format.cjs +76 -17
- package/dist/record/reader/format.cjs.map +1 -1
- package/dist/record/reader/format.d.cts +11 -4
- package/dist/record/reader/format.d.mts +11 -4
- package/dist/record/reader/format.d.ts +11 -4
- package/dist/record/reader/format.js +2 -0
- package/dist/record/reader/index.js +32 -18
- package/dist/record/reader/runtime.cjs +64 -0
- package/dist/record/reader/runtime.cjs.map +1 -1
- package/dist/record/reader/runtime.d.cts +15 -0
- package/dist/record/reader/runtime.d.mts +15 -0
- package/dist/record/reader/runtime.d.ts +15 -0
- package/dist/record/reader/runtime.js +2 -0
- package/dist/report/assets/styles.css +53 -29
- package/dist/report/built-in/analysis-values.cjs +21 -13
- package/dist/report/built-in/analysis-values.cjs.map +1 -1
- package/dist/report/built-in/analysis-values.d.cts +11 -22
- package/dist/report/built-in/analysis-values.d.mts +11 -22
- package/dist/report/built-in/analysis-values.d.ts +11 -22
- package/dist/report/built-in/analysis-values.js +4 -6
- package/dist/report/built-in/index.cjs +1 -3
- package/dist/report/built-in/index.cjs.map +1 -1
- package/dist/report/built-in/index.d.cts +1 -1
- package/dist/report/built-in/index.d.mts +1 -1
- package/dist/report/built-in/index.d.ts +1 -1
- package/dist/report/built-in/index.js +4 -8
- package/dist/report/built-in/index.mjs +4 -8
- package/dist/report/built-in/machine.cjs +0 -2
- package/dist/report/built-in/machine.cjs.map +1 -1
- package/dist/report/built-in/machine.d.cts +0 -2
- package/dist/report/built-in/machine.d.mts +0 -2
- package/dist/report/built-in/machine.d.ts +0 -2
- package/dist/report/built-in/result-components.cjs +49 -51
- package/dist/report/built-in/result-components.cjs.map +1 -1
- package/dist/report/built-in/result-components.d.cts +16 -17
- package/dist/report/built-in/result-components.d.mts +16 -17
- package/dist/report/built-in/result-components.d.ts +16 -17
- package/dist/report/built-in/result-components.js +0 -4
- package/dist/report/built-in/run-membership-overview.cjs +126 -17
- package/dist/report/built-in/run-membership-overview.cjs.map +1 -1
- package/dist/report/built-in/run-membership-overview.d.cts +14 -0
- package/dist/report/built-in/run-membership-overview.d.mts +14 -0
- package/dist/report/built-in/run-membership-overview.d.ts +14 -0
- package/dist/report/built-in/run-membership-overview.js +4 -2
- package/dist/report/built-in/standard.cjs +80 -45
- package/dist/report/built-in/standard.cjs.map +1 -1
- package/dist/report/built-in/standard.d.cts +19 -41
- package/dist/report/built-in/standard.d.mts +19 -41
- package/dist/report/built-in/standard.d.ts +19 -41
- package/dist/report/built-in/standard.js +6 -6
- package/dist/report/components/attempt-detail/compute.cjs +78 -2
- package/dist/report/components/attempt-detail/compute.cjs.map +1 -1
- package/dist/report/components/attempt-detail/compute.d.cts +1 -1
- package/dist/report/components/attempt-detail/compute.d.mts +1 -1
- package/dist/report/components/attempt-detail/compute.d.ts +1 -1
- package/dist/report/components/attempt-detail/content.cjs +1 -1
- package/dist/report/components/attempt-detail/content.cjs.map +1 -1
- package/dist/report/components/entity-lists/compute.cjs +42 -5
- package/dist/report/components/entity-lists/compute.cjs.map +1 -1
- package/dist/report/components/entity-lists/compute.d.cts +10 -8
- package/dist/report/components/entity-lists/compute.d.mts +10 -8
- package/dist/report/components/entity-lists/compute.d.ts +10 -8
- package/dist/report/components/entity-lists/content.cjs +31 -6
- package/dist/report/components/entity-lists/content.cjs.map +1 -1
- package/dist/report/components/entity-lists/index.cjs +9 -4
- package/dist/report/components/entity-lists/index.cjs.map +1 -1
- package/dist/report/components/entity-lists/index.d.cts +4 -7
- package/dist/report/components/entity-lists/index.d.mts +4 -7
- package/dist/report/components/entity-lists/index.d.ts +4 -7
- package/dist/report/components/summaries/compute.cjs +8 -1
- package/dist/report/components/summaries/compute.cjs.map +1 -1
- package/dist/report/components/summaries/compute.d.cts +9 -1
- package/dist/report/components/summaries/compute.d.mts +9 -1
- package/dist/report/components/summaries/compute.d.ts +9 -1
- package/dist/report/components/summaries/index.cjs +48 -4
- package/dist/report/components/summaries/index.cjs.map +1 -1
- package/dist/report/components/summaries/index.d.cts +7 -4
- package/dist/report/components/summaries/index.d.mts +7 -4
- package/dist/report/components/summaries/index.d.ts +7 -4
- package/dist/report/definition/cell.cjs +3 -0
- package/dist/report/definition/cell.cjs.map +1 -1
- package/dist/report/definition/cell.d.cts +2 -0
- package/dist/report/definition/cell.d.mts +2 -0
- package/dist/report/definition/cell.d.ts +2 -0
- package/dist/report/definition/primitives/chart.cjs +8 -5
- package/dist/report/definition/primitives/chart.cjs.map +1 -1
- package/dist/report/definition/primitives/points-dataset.cjs +1 -0
- package/dist/report/definition/primitives/points-dataset.cjs.map +1 -1
- package/dist/report/definition/primitives.cjs +15 -2
- package/dist/report/definition/primitives.cjs.map +1 -1
- package/dist/report/definition/report.cjs +27 -3
- package/dist/report/definition/report.cjs.map +1 -1
- package/dist/report/definition/report.d.cts +8 -0
- package/dist/report/definition/report.d.mts +8 -0
- package/dist/report/definition/report.d.ts +8 -0
- package/dist/report/execution/machine.cjs +30 -14
- package/dist/report/execution/machine.cjs.map +1 -1
- package/dist/report/execution/machine.d.cts +20 -10
- package/dist/report/execution/machine.d.mts +20 -10
- package/dist/report/execution/machine.d.ts +20 -10
- package/dist/report/execution/machine.js +6 -6
- package/dist/report/host/execute.cjs +25 -16
- package/dist/report/host/execute.cjs.map +1 -1
- package/dist/report/host/execute.d.cts +4 -0
- package/dist/report/host/execute.d.mts +4 -0
- package/dist/report/host/execute.d.ts +4 -0
- package/dist/report/host/from-record.cjs +22 -5
- package/dist/report/host/from-record.cjs.map +1 -1
- package/dist/report/host/machine.cjs +53 -11
- package/dist/report/host/machine.cjs.map +1 -1
- package/dist/report/host/site-runtime.cjs +9 -8
- package/dist/report/host/site-runtime.cjs.map +1 -1
- package/dist/report/host/site-runtime.d.cts +1 -1
- package/dist/report/host/site-runtime.d.mts +1 -1
- package/dist/report/host/site-runtime.d.ts +1 -1
- package/dist/report/host/static.cjs +56 -9
- package/dist/report/host/static.cjs.map +1 -1
- package/dist/report/index.cjs.map +1 -1
- package/dist/report/index.d.cts +1 -1
- package/dist/report/index.d.mts +1 -1
- package/dist/report/index.d.ts +1 -1
- package/dist/report/model/dataset.cjs +7 -2
- package/dist/report/model/dataset.cjs.map +1 -1
- package/dist/report/model/locale.cjs +2 -0
- package/dist/report/model/locale.cjs.map +1 -1
- package/dist/report/model/locale.d.cts +1 -0
- package/dist/report/model/locale.d.mts +1 -0
- package/dist/report/model/locale.d.ts +1 -0
- package/dist/report/model/metrics.cjs +3 -1
- package/dist/report/model/metrics.cjs.map +1 -1
- package/dist/report/model/pricing.cjs +16 -11
- package/dist/report/model/pricing.cjs.map +1 -1
- package/dist/report/react/styles.css +53 -29
- package/dist/runner/adoption.cjs +1 -0
- package/dist/runner/adoption.cjs.map +1 -1
- package/dist/runner/attempt.cjs +44 -5
- package/dist/runner/attempt.cjs.map +1 -1
- package/dist/runner/attempt.d.cts +13 -1
- package/dist/runner/attempt.d.mts +13 -1
- package/dist/runner/attempt.d.ts +13 -1
- package/dist/runner/config-identity.cjs +10 -2
- package/dist/runner/config-identity.cjs.map +1 -1
- package/dist/runner/config-identity.d.cts +4 -2
- package/dist/runner/config-identity.d.mts +4 -2
- package/dist/runner/config-identity.d.ts +4 -2
- package/dist/runner/feedback/human.cjs +298 -59
- package/dist/runner/feedback/human.cjs.map +1 -1
- package/dist/runner/feedback/json.cjs +14 -6
- package/dist/runner/feedback/json.cjs.map +1 -1
- package/dist/runner/feedback/json.d.cts +3 -2
- package/dist/runner/feedback/json.d.mts +3 -2
- package/dist/runner/feedback/json.d.ts +3 -2
- package/dist/runner/feedback/reducer.cjs +2 -0
- package/dist/runner/feedback/reducer.cjs.map +1 -1
- package/dist/runner/judge-config.cjs +1 -1
- package/dist/runner/judge-config.cjs.map +1 -1
- package/dist/runner/ledger.cjs +124 -12
- package/dist/runner/ledger.cjs.map +1 -1
- package/dist/runner/project-current.cjs +13 -5
- package/dist/runner/project-current.cjs.map +1 -1
- package/dist/runner/run.cjs +564 -256
- package/dist/runner/run.cjs.map +1 -1
- package/dist/runner/sandbox-pool.cjs +161 -30
- package/dist/runner/sandbox-pool.cjs.map +1 -1
- package/dist/runner/sandbox-pool.d.cts +34 -2
- package/dist/runner/sandbox-pool.d.mts +34 -2
- package/dist/runner/sandbox-pool.d.ts +34 -2
- package/dist/runner/shared-state-lease.cjs +803 -0
- package/dist/runner/shared-state-lease.cjs.map +1 -0
- package/dist/runner/shared-state-lease.d.cts +121 -0
- package/dist/runner/shared-state-lease.d.mts +121 -0
- package/dist/runner/shared-state-lease.d.ts +121 -0
- package/dist/runner/shared-state-lease.js +24 -0
- package/dist/runner/shared-state-lease.js.map +1 -0
- package/dist/runner/teardown-registry.cjs +97 -34
- package/dist/runner/teardown-registry.cjs.map +1 -1
- package/dist/runner/teardown-registry.d.cts +27 -1
- package/dist/runner/teardown-registry.d.mts +27 -1
- package/dist/runner/teardown-registry.d.ts +27 -1
- package/dist/runner/teardown-registry.js +20 -16
- package/dist/runner/types.cjs.map +1 -1
- package/dist/runner/types.d.cts +31 -5
- package/dist/runner/types.d.mts +31 -5
- package/dist/runner/types.d.ts +31 -5
- package/dist/sample/analysis.cjs +249 -459
- package/dist/sample/analysis.cjs.map +1 -1
- package/dist/sample/capability.cjs +138 -7
- package/dist/sample/capability.cjs.map +1 -1
- package/dist/sample/capability.d.cts +3 -1
- package/dist/sample/capability.d.mts +3 -1
- package/dist/sample/capability.d.ts +3 -1
- package/dist/sample/capability.js +8 -6
- package/dist/sandbox/docker-agent-image.cjs +5 -1
- package/dist/sandbox/docker-agent-image.cjs.map +1 -1
- package/dist/sandbox/docker-agent-image.d.cts +2 -0
- package/dist/sandbox/docker-agent-image.d.mts +2 -0
- package/dist/sandbox/docker-agent-image.d.ts +2 -0
- package/dist/sandbox/docker-agent-image.js +14 -10
- package/dist/sandbox/docker-profile/schema.cjs +283 -534
- package/dist/sandbox/docker-profile/schema.cjs.map +1 -1
- package/dist/sandbox/docker-profile/schema.d.cts +10 -27
- package/dist/sandbox/docker-profile/schema.d.mts +10 -27
- package/dist/sandbox/docker-profile/schema.d.ts +10 -27
- package/dist/sandbox/e2b-agent-template.cjs +5 -2
- package/dist/sandbox/e2b-agent-template.cjs.map +1 -1
- package/dist/sandbox/index.cjs +4 -2
- package/dist/sandbox/index.cjs.map +1 -1
- package/dist/sandbox/index.d.cts +1 -1
- package/dist/sandbox/index.d.mts +1 -1
- package/dist/sandbox/index.d.ts +1 -1
- package/dist/sandbox/index.js +120 -116
- package/dist/sandbox/index.mjs +120 -116
- package/dist/sandbox/keep-registry.cjs +28 -66
- package/dist/sandbox/keep-registry.cjs.map +1 -1
- package/dist/sandbox/types.cjs.map +1 -1
- package/dist/sandbox/types.d.cts +1 -1
- package/dist/sandbox/types.d.mts +1 -1
- package/dist/sandbox/types.d.ts +1 -1
- package/dist/shared/aggregate.cjs +16 -6
- package/dist/shared/aggregate.cjs.map +1 -1
- package/dist/shared/aggregate.d.cts +12 -4
- package/dist/shared/aggregate.d.mts +12 -4
- package/dist/shared/aggregate.d.ts +12 -4
- package/dist/shared/turn-label.cjs +20 -2
- package/dist/shared/turn-label.cjs.map +1 -1
- package/dist/shared/turn-label.d.cts +2 -0
- package/dist/shared/turn-label.d.mts +2 -0
- package/dist/shared/turn-label.d.ts +2 -0
- package/dist/shared/turn-label.js +4 -2
- package/dist/vendor/remark/remark-gfm.cjs +7 -7
- package/dist/vendor/remark/remark-gfm.cjs.map +1 -1
- package/dist/vendor/remark/remark-parse.cjs +12 -12
- package/dist/vendor/remark/remark-parse.cjs.map +1 -1
- package/dist/vendor/remark/remark.cjs +13 -13
- package/dist/vendor/remark/remark.cjs.map +1 -1
- package/dist/view/server.cjs +6 -0
- package/dist/view/server.cjs.map +1 -1
- package/docs-site/images/hitl-handshake-zh.svg +3 -3
- package/docs-site/zh/examples/ai-agent-application.mdx +1 -1
- package/docs-site/zh/examples/coding-agent-extensions.mdx +1 -1
- package/docs-site/zh/examples/integrations/ai-sdk-v7.mdx +4 -3
- package/docs-site/zh/examples/integrations/claude-sdk.mdx +3 -3
- package/docs-site/zh/examples/integrations/codex-sdk.mdx +5 -5
- package/docs-site/zh/examples/integrations/langgraph.mdx +4 -4
- package/docs-site/zh/examples/integrations/pi-sdk.mdx +5 -5
- package/docs-site/zh/explanation/adapter.mdx +5 -5
- package/docs-site/zh/explanation/assert.mdx +7 -7
- package/docs-site/zh/explanation/drive.mdx +4 -2
- package/docs-site/zh/explanation/evals.mdx +10 -8
- package/docs-site/zh/explanation/experiment.mdx +2 -2
- package/docs-site/zh/explanation/hitl.mdx +9 -9
- package/docs-site/zh/explanation/judge.mdx +5 -5
- package/docs-site/zh/explanation/overview.mdx +3 -3
- package/docs-site/zh/explanation/runner.mdx +1 -1
- package/docs-site/zh/index.mdx +3 -3
- package/docs-site/zh/reference/builtin-agents.mdx +13 -13
- package/docs-site/zh/reference/capabilities.mdx +1 -1
- package/docs-site/zh/reference/cli.mdx +18 -12
- package/docs-site/zh/reference/define-agent.mdx +130 -5
- package/docs-site/zh/reference/define-config.mdx +2 -2
- package/docs-site/zh/reference/define-eval.mdx +4 -4
- package/docs-site/zh/reference/events.mdx +11 -11
- package/docs-site/zh/reference/official-adapters.mdx +6 -6
- package/docs-site/zh/reference/results-data.mdx +6 -0
- package/docs-site/zh/troubleshooting/debugging.mdx +1 -1
- package/docs-site/zh/troubleshooting/recover-after-kill.mdx +37 -5
- package/docs-site/zh/tutorials/accept-results.mdx +72 -0
- package/docs-site/zh/tutorials/agent-onboarding.mdx +6 -6
- package/docs-site/zh/tutorials/authoring.mdx +9 -13
- package/docs-site/zh/tutorials/ci-integration.mdx +6 -6
- package/docs-site/zh/tutorials/compare-runs.mdx +61 -0
- package/docs-site/zh/tutorials/concurrency.mdx +13 -12
- package/docs-site/zh/tutorials/configuration.mdx +4 -6
- package/docs-site/zh/tutorials/connect-your-agent.mdx +1 -1
- package/docs-site/zh/tutorials/control-run-cost.mdx +58 -0
- package/docs-site/zh/tutorials/criteria-files.mdx +2 -2
- package/docs-site/zh/tutorials/custom-reports.mdx +2 -2
- package/docs-site/zh/tutorials/debug-lifecycle-plan.mdx +46 -0
- package/docs-site/zh/tutorials/docker-in-docker.mdx +52 -43
- package/docs-site/zh/tutorials/eval-groups.mdx +6 -6
- package/docs-site/zh/tutorials/evaluation-kinds.mdx +3 -3
- package/docs-site/zh/tutorials/experiments.mdx +2 -3
- package/docs-site/zh/tutorials/handle-execution-failures.mdx +18 -10
- package/docs-site/zh/tutorials/install-custom-sandbox-agent.mdx +16 -8
- package/docs-site/zh/tutorials/nixos-managed-dind.mdx +160 -0
- package/docs-site/zh/tutorials/plugins.mdx +14 -0
- package/docs-site/zh/tutorials/rerun-and-cache.mdx +4 -2
- package/docs-site/zh/tutorials/sandbox-agent.mdx +17 -11
- package/docs-site/zh/tutorials/sandbox-providers.mdx +17 -13
- package/docs-site/zh/tutorials/sandbox-reuse.mdx +12 -19
- package/docs-site/zh/tutorials/select-and-preview.mdx +65 -0
- package/docs-site/zh/tutorials/verify-judge.mdx +78 -0
- package/docs-site/zh/tutorials/viewing-results.mdx +38 -1
- package/docs-site/zh/tutorials/write-experiment.mdx +7 -5
- package/docs-site/zh/tutorials/write-send.mdx +9 -8
- package/package.json +9 -5
- package/dist/report/built-in/overview.cjs +0 -44
- package/dist/report/built-in/overview.cjs.map +0 -1
- package/dist/report/built-in/overview.d.cts +0 -6
- package/dist/report/built-in/overview.d.mts +0 -6
- package/dist/report/built-in/overview.d.ts +0 -6
- package/dist/report/built-in/overview.js +0 -9
- package/dist/report/built-in/overview.js.map +0 -1
- package/dist/runner/gate-lease.cjs +0 -283
- package/dist/runner/gate-lease.cjs.map +0 -1
- package/dist/runner/gate-lease.d.cts +0 -62
- package/dist/runner/gate-lease.d.mts +0 -62
- package/dist/runner/gate-lease.d.ts +0 -62
- package/dist/runner/gate-lease.js +0 -22
- package/dist/runner/gate-lease.js.map +0 -1
|
@@ -26,7 +26,16 @@ class ReusableSandboxPool {
|
|
|
26
26
|
waiters = [];
|
|
27
27
|
creating = 0;
|
|
28
28
|
stopped = false;
|
|
29
|
+
/** One physical stop operation owns every instance/finalizer exactly once. */
|
|
30
|
+
stopCompletion;
|
|
29
31
|
runtimeFailures = [];
|
|
32
|
+
/**
|
|
33
|
+
* Whole-Experiment physical cleanup ledger. This is intentionally distinct
|
|
34
|
+
* from `runtimeFailures`: the latter is a per-Attempt diagnostic channel and
|
|
35
|
+
* is drained once that Attempt seals, whereas this collection is replayed by
|
|
36
|
+
* the terminal `stop()` even if an entry was retired long before then.
|
|
37
|
+
*/
|
|
38
|
+
cleanupFailures = [];
|
|
30
39
|
/** Provider 可观察的物理 owner;Group 池不能随首个未携入成员改用另一个 Eval ID。 */
|
|
31
40
|
materializationOwnerId;
|
|
32
41
|
/** 本次 Run 内的 Sandbox 编号计数器;淘汰的实例不让号,编号在结果里永远指向同一个实例。 */
|
|
@@ -47,9 +56,21 @@ class ReusableSandboxPool {
|
|
|
47
56
|
this.groupPluginContext = groupPluginContext;
|
|
48
57
|
this.materializationOwnerId = materializationOwnerId ?? plan.pair.evalId;
|
|
49
58
|
}
|
|
50
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Registers only an awaiter in the outer Invocation Scope. The real stop is
|
|
61
|
+
* initiated by the Experiment lifecycle before its teardown; if the outer
|
|
62
|
+
* Scope closes first it joins the same single-flight result rather than
|
|
63
|
+
* repeating provider or plugin finalizers.
|
|
64
|
+
*/
|
|
51
65
|
managed() {
|
|
52
|
-
return effect_1.Effect.addFinalizer(() => this.stop()).pipe(effect_1.Effect.as(this));
|
|
66
|
+
return effect_1.Effect.addFinalizer(() => this.stop().pipe(effect_1.Effect.ignore)).pipe(effect_1.Effect.as(this));
|
|
67
|
+
}
|
|
68
|
+
/** Closes admission before the Experiment starts physical cleanup. */
|
|
69
|
+
freeze() {
|
|
70
|
+
return effect_1.Effect.sync(() => {
|
|
71
|
+
this.stopped = true;
|
|
72
|
+
this.wake();
|
|
73
|
+
});
|
|
53
74
|
}
|
|
54
75
|
/**
|
|
55
76
|
* @param attemptDeadlineMs 这条 Attempt 实际生效的超时上限(解析链见 runner/timeout.ts)。
|
|
@@ -109,29 +130,72 @@ class ReusableSandboxPool {
|
|
|
109
130
|
});
|
|
110
131
|
}
|
|
111
132
|
stop() {
|
|
133
|
+
return effect_1.Effect.uninterruptibleMask((restore) => effect_1.Effect.gen(this, function* () {
|
|
134
|
+
const created = yield* effect_1.Deferred.make();
|
|
135
|
+
const completion = yield* effect_1.Effect.sync(() => {
|
|
136
|
+
if (this.stopCompletion !== undefined)
|
|
137
|
+
return this.stopCompletion;
|
|
138
|
+
this.stopCompletion = created;
|
|
139
|
+
this.stopped = true;
|
|
140
|
+
this.wake();
|
|
141
|
+
return created;
|
|
142
|
+
});
|
|
143
|
+
// A caller joining an already-started stop remains cancelable. The one
|
|
144
|
+
// caller that starts it cannot be interrupted between publishing the
|
|
145
|
+
// Deferred and recording its terminal Exit.
|
|
146
|
+
if (completion !== created)
|
|
147
|
+
return yield* restore(effect_1.Deferred.await(completion));
|
|
148
|
+
// Stop must finish every physical cleanup even if the initiating
|
|
149
|
+
// Invocation is interrupted. Its recorded Exit is replayed to joiners.
|
|
150
|
+
const exit = yield* effect_1.Effect.exit(this.stopAll());
|
|
151
|
+
yield* effect_1.Deferred.done(created, exit);
|
|
152
|
+
if (effect_1.Exit.isFailure(exit))
|
|
153
|
+
return yield* effect_1.Effect.failCause(exit.cause);
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
stopAll() {
|
|
112
157
|
return effect_1.Effect.gen(this, function* () {
|
|
113
|
-
|
|
114
|
-
this
|
|
115
|
-
//
|
|
116
|
-
// 使用中 teardown。创建中的 entry 尚未进 entries,必须等它落入唯一 retire 路径。
|
|
158
|
+
// Leases own their Attempt scopes. Wait until each lease has returned
|
|
159
|
+
// before closing provider scopes; this is also the barrier that makes
|
|
160
|
+
// pool stop safe to place before Experiment teardown.
|
|
117
161
|
while (this.creating > 0 || this.entries.some((entry) => entry.lifecycle._tag === "Leased")) {
|
|
118
162
|
yield* this.awaitWake();
|
|
119
163
|
}
|
|
120
|
-
|
|
164
|
+
const exits = [];
|
|
165
|
+
const retired = yield* effect_1.Effect.forEach([...this.entries], (entry) => effect_1.Effect.exit(this.retire(entry)), {
|
|
121
166
|
concurrency: "unbounded",
|
|
122
|
-
discard: true,
|
|
123
167
|
});
|
|
168
|
+
exits.push(...retired);
|
|
124
169
|
if (this.groupPluginContext !== undefined) {
|
|
125
|
-
yield* effect_1.Effect.forEach(this.groupPlugins.slice(0, this.activatedGroupPlugins).reverse(), (entry) => entry.teardown === undefined
|
|
126
|
-
? effect_1.Effect.void
|
|
127
|
-
: (0, cleanup_timeout_ts_1.cleanupCallback)((signal) => entry.teardown({
|
|
170
|
+
const groupTeardowns = yield* effect_1.Effect.forEach(this.groupPlugins.slice(0, this.activatedGroupPlugins).reverse(), (entry) => entry.teardown === undefined
|
|
171
|
+
? effect_1.Effect.succeed(effect_1.Exit.void)
|
|
172
|
+
: effect_1.Effect.exit((0, cleanup_timeout_ts_1.cleanupCallback)((signal) => entry.teardown({
|
|
128
173
|
...this.groupPluginContext,
|
|
129
174
|
signal,
|
|
130
|
-
}))
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
175
|
+
}))), { concurrency: "unbounded" });
|
|
176
|
+
for (const exit of groupTeardowns) {
|
|
177
|
+
exits.push(exit);
|
|
178
|
+
if (effect_1.Exit.isFailure(exit)) {
|
|
179
|
+
this.feedback.diagnostic({
|
|
180
|
+
code: "plugin-lifecycle-teardown-failed",
|
|
181
|
+
level: "warning",
|
|
182
|
+
message: String(effect_1.Cause.squash(exit.cause)),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const failures = [];
|
|
188
|
+
for (const exit of exits) {
|
|
189
|
+
if (effect_1.Exit.isFailure(exit))
|
|
190
|
+
failures.push(effect_1.Cause.squash(exit.cause));
|
|
191
|
+
}
|
|
192
|
+
// An entry may have been removed by a failed Attempt release before this
|
|
193
|
+
// terminal sweep. Replaying the durable pool-local ledger makes that
|
|
194
|
+
// physical Scope/provider cleanup failure visible to Experiment teardown
|
|
195
|
+
// and therefore to sharedState lease release.
|
|
196
|
+
failures.push(...this.cleanupFailures.map((failure) => failure.error));
|
|
197
|
+
if (failures.length > 0) {
|
|
198
|
+
return yield* effect_1.Effect.fail(new AggregateError([...new Set(failures)], "Sandbox reuse pool cleanup failed."));
|
|
135
199
|
}
|
|
136
200
|
});
|
|
137
201
|
}
|
|
@@ -164,33 +228,48 @@ class ReusableSandboxPool {
|
|
|
164
228
|
? { _tag: "Unlimited" }
|
|
165
229
|
: { _tag: "Bounded", timeoutMs: Math.max(1, minRemainingMs - cleanup_timeout_ts_1.CLEANUP_TIMEOUT_MS), deadlineAt };
|
|
166
230
|
const entryScope = yield* effect_1.Scope.make();
|
|
231
|
+
// One wrapper per physical materialization. Both provider feedback and
|
|
232
|
+
// SandboxLayer hook context must use this exact instance: runtime sends
|
|
233
|
+
// provider release failures through `feedback`, while
|
|
234
|
+
// `runTeardownHooks` reports through `hookContext.diagnostic`.
|
|
235
|
+
const lifecycleFeedback = this.lifecycleFeedback();
|
|
236
|
+
const lifecycleHookContext = {
|
|
237
|
+
...this.setupContext,
|
|
238
|
+
progress: lifecycleFeedback.progress,
|
|
239
|
+
diagnostic: lifecycleFeedback.diagnostic,
|
|
240
|
+
};
|
|
167
241
|
const materialized = yield* effect_1.Scope.extend((0, runtime_ts_1.materializeSandboxRunPlan)({
|
|
168
242
|
plan: this.plan,
|
|
169
243
|
evalId: this.materializationOwnerId,
|
|
170
244
|
deadline,
|
|
171
|
-
|
|
245
|
+
// Runtime intentionally reports SandboxLayer/provider finalizer errors
|
|
246
|
+
// as diagnostics so it can continue the remaining finalizers. The pool
|
|
247
|
+
// must nevertheless retain those physical cleanup failures until its
|
|
248
|
+
// terminal stop; otherwise an early retire can disappear from
|
|
249
|
+
// `entries` and incorrectly permit sharedState release.
|
|
250
|
+
feedback: lifecycleFeedback,
|
|
172
251
|
signal: this.setupContext.signal,
|
|
173
|
-
hookContext:
|
|
252
|
+
hookContext: lifecycleHookContext,
|
|
174
253
|
buildLocators,
|
|
175
254
|
...(this.agent !== undefined ? { agent: this.agent } : {}),
|
|
176
255
|
...(this.runTiming !== undefined ? { runTiming: this.runTiming } : {}),
|
|
177
256
|
provisionSlot: { _tag: "Detached" },
|
|
178
257
|
services: this.runtimeServices,
|
|
179
258
|
release: { _tag: "Stop" },
|
|
180
|
-
}), entryScope).pipe(effect_1.Effect.onError((cause) =>
|
|
259
|
+
}), entryScope).pipe(effect_1.Effect.onError((cause) => this.closeFailedCreateScope(entryScope, effect_1.Exit.failCause(cause), "sandbox.materialize-cleanup")));
|
|
181
260
|
const sandbox = materialized.sandbox;
|
|
182
261
|
// 能力只能来自 provider 实现:探不到就硬失败,没有通用记账兜底(见
|
|
183
262
|
// docs/feature/sandbox/reuse.md「派发前确认」)。
|
|
184
263
|
const lifetime = (0, backend_ts_1.sandboxReuseCapability)(sandbox);
|
|
185
264
|
if (!lifetime) {
|
|
186
|
-
yield*
|
|
265
|
+
yield* this.closeFailedCreateScope(entryScope, effect_1.Exit.void, "sandbox.ensure-lifetime-cleanup");
|
|
187
266
|
return yield* effect_1.Effect.fail(new Error(`sandboxReuse needs the "${capabilities.provider}" provider to confirm sandbox lifetime, but it does not implement ` +
|
|
188
267
|
"ensureLifetime(minRemainingMs). Only a provider can prove the lifetime is set on its own backend; the runner " +
|
|
189
268
|
"will not keep local books for it. Use a provider that implements it (docker / e2b / vercel), or drop sandboxReuse."));
|
|
190
269
|
}
|
|
191
|
-
const confirmed = yield* externalPromise(() => lifetime.ensureLifetime(minRemainingMs)).pipe(effect_1.Effect.onError((cause) =>
|
|
270
|
+
const confirmed = yield* externalPromise(() => lifetime.ensureLifetime(minRemainingMs)).pipe(effect_1.Effect.onError((cause) => this.closeFailedCreateScope(entryScope, effect_1.Exit.failCause(cause), "sandbox.ensure-lifetime-cleanup")));
|
|
192
271
|
if (!confirmed.ready) {
|
|
193
|
-
yield*
|
|
272
|
+
yield* this.closeFailedCreateScope(entryScope, effect_1.Exit.void, "sandbox.ensure-lifetime-cleanup");
|
|
194
273
|
return yield* effect_1.Effect.fail(new Error(`sandboxReuse cannot prepare the "${capabilities.provider}" sandbox: ${confirmed.reason}`));
|
|
195
274
|
}
|
|
196
275
|
const prepared = yield* effect_1.Effect.gen(this, function* () {
|
|
@@ -221,7 +300,7 @@ class ReusableSandboxPool {
|
|
|
221
300
|
ordinal: 0,
|
|
222
301
|
lifecycle: { _tag: "Idle" },
|
|
223
302
|
};
|
|
224
|
-
}).pipe(effect_1.Effect.onError((cause) =>
|
|
303
|
+
}).pipe(effect_1.Effect.onError((cause) => this.closeFailedCreateScope(entryScope, effect_1.Exit.failCause(cause), "sandbox.prepare-cleanup")));
|
|
225
304
|
return prepared;
|
|
226
305
|
});
|
|
227
306
|
}
|
|
@@ -246,18 +325,22 @@ class ReusableSandboxPool {
|
|
|
246
325
|
? settled.release.release
|
|
247
326
|
: { _tag: "Retire" };
|
|
248
327
|
if (release._tag === "Retire") {
|
|
249
|
-
|
|
328
|
+
// The Attempt has already sealed. Do not turn its return finalizer
|
|
329
|
+
// into a defect; `retire` persists the physical failure and terminal
|
|
330
|
+
// `stop()` replays it to Experiment cleanup/lease release.
|
|
331
|
+
yield* this.retire(entry).pipe(effect_1.Effect.catchAll(() => effect_1.Effect.void));
|
|
250
332
|
}
|
|
251
333
|
else if (entry.lifecycle._tag !== "Retired") {
|
|
252
334
|
const reset = yield* effect_1.Effect.either(externalPromise(() => entry.ledger.resetToAnchor()));
|
|
253
335
|
if (effect_1.Either.isLeft(reset)) {
|
|
254
336
|
this.runtimeFailures.push(Object.freeze({ stage: "sandbox.reset", error: reset.left }));
|
|
337
|
+
this.recordCleanupFailure("sandbox.reset", reset.left);
|
|
255
338
|
this.feedback.diagnostic({
|
|
256
339
|
code: "sandbox-reset-failed",
|
|
257
340
|
level: "warning",
|
|
258
341
|
message: `Sandbox #${entry.reuseSandbox} reset to anchor failed, retiring the instance: ${(0, util_ts_1.firstLine)((0, util_ts_1.formatThrown)(reset.left))}`,
|
|
259
342
|
});
|
|
260
|
-
yield* this.retire(entry);
|
|
343
|
+
yield* this.retire(entry).pipe(effect_1.Effect.catchAll(() => effect_1.Effect.void));
|
|
261
344
|
}
|
|
262
345
|
else {
|
|
263
346
|
entry.lifecycle = { _tag: "Idle" };
|
|
@@ -291,11 +374,17 @@ class ReusableSandboxPool {
|
|
|
291
374
|
const at = this.entries.indexOf(entry);
|
|
292
375
|
if (at >= 0)
|
|
293
376
|
this.entries.splice(at, 1);
|
|
294
|
-
yield* effect_1.Scope.close(entry.scope, effect_1.Exit.void)
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
377
|
+
const exit = yield* effect_1.Effect.exit(effect_1.Scope.close(entry.scope, effect_1.Exit.void));
|
|
378
|
+
if (effect_1.Exit.isFailure(exit)) {
|
|
379
|
+
const error = this.recordCleanupFailure("sandbox.retire", effect_1.Cause.squash(exit.cause));
|
|
380
|
+
this.feedback.diagnostic({
|
|
381
|
+
code: "sandbox-stop-failed",
|
|
382
|
+
level: "warning",
|
|
383
|
+
message: `Sandbox reuse case finalizer failed: ${String(error)}`,
|
|
384
|
+
});
|
|
385
|
+
this.wake();
|
|
386
|
+
return yield* effect_1.Effect.fail(error);
|
|
387
|
+
}
|
|
299
388
|
this.wake();
|
|
300
389
|
});
|
|
301
390
|
}
|
|
@@ -313,6 +402,48 @@ class ReusableSandboxPool {
|
|
|
313
402
|
});
|
|
314
403
|
});
|
|
315
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* A create/ensureLifetime failure can still run provider and Sandbox Scope
|
|
407
|
+
* finalizers. The entry is not yet in `entries`, so `stopAll()` cannot find
|
|
408
|
+
* it later; record a close failure now and replay it from the Experiment
|
|
409
|
+
* lifetime ledger instead of letting an `onError` cleanup failure vanish.
|
|
410
|
+
*/
|
|
411
|
+
closeFailedCreateScope(scope, exit, stage) {
|
|
412
|
+
return effect_1.Effect.exit(effect_1.Scope.close(scope, exit)).pipe(effect_1.Effect.flatMap((close) => effect_1.Exit.isFailure(close)
|
|
413
|
+
? effect_1.Effect.sync(() => {
|
|
414
|
+
const error = this.recordCleanupFailure(stage, effect_1.Cause.squash(close.cause));
|
|
415
|
+
this.feedback.diagnostic({
|
|
416
|
+
code: "sandbox-stop-failed",
|
|
417
|
+
level: "warning",
|
|
418
|
+
message: `Sandbox reuse setup cleanup failed: ${String(error)}`,
|
|
419
|
+
});
|
|
420
|
+
})
|
|
421
|
+
: effect_1.Effect.void));
|
|
422
|
+
}
|
|
423
|
+
recordCleanupFailure(stage, cause) {
|
|
424
|
+
const error = cause instanceof Error ? cause : new Error(String(cause));
|
|
425
|
+
this.cleanupFailures.push(Object.freeze({ stage, error }));
|
|
426
|
+
return error;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* `materializeSandboxRunPlan` deliberately converts hook/provider cleanup
|
|
430
|
+
* failures into feedback and continues its Scope.close. Preserve that signal
|
|
431
|
+
* beside thrown Scope close failures, without changing the public Sandbox
|
|
432
|
+
* lifecycle API or its diagnostic-only finalizer contract.
|
|
433
|
+
*/
|
|
434
|
+
lifecycleFeedback() {
|
|
435
|
+
return {
|
|
436
|
+
progress: (update) => this.feedback.progress(update),
|
|
437
|
+
diagnostic: (input) => {
|
|
438
|
+
this.feedback.diagnostic(input);
|
|
439
|
+
if (input.code === "sandbox-teardown-failed" ||
|
|
440
|
+
input.code === "sandbox-stop-failed" ||
|
|
441
|
+
input.code === "plugin-lifecycle-teardown-failed") {
|
|
442
|
+
this.recordCleanupFailure("sandbox.lifecycle-diagnostic", new Error(input.message));
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
};
|
|
446
|
+
}
|
|
316
447
|
}
|
|
317
448
|
exports.ReusableSandboxPool = ReusableSandboxPool;
|
|
318
449
|
function externalPromise(run) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-pool.js","sourceRoot":"","sources":["sandbox-pool.ts"],"names":[],"mappings":";;;AAAA,wDAA8D;AAC9D,sDAA4F;AAC5F,kDAA8D;AAC9D,wEAA4E;AAG5E,sDAAqL;AAErL,6DAA2E;AAC3E,2CAAoE;AACpE,wCAAqD;AACrD,mCAA4D;AAqD5D,6DAA6D;AAC7D,MAAa,mBAAmB;IAaC;IAER;IAAmC;IAA2C;IAAmD;IAAuF;IAAuC;IAAuG;IAAwD;IAAqF;IAdvf,OAAO,GAAY,EAAE,CAAC;IACtB,OAAO,GAAsB,EAAE,CAAC;IACzC,QAAQ,GAAG,CAAC,CAAC;IACb,OAAO,GAAG,KAAK,CAAC;IACP,eAAe,GAAwC,EAAE,CAAC;IAC3E,4DAA4D;IAC3C,sBAAsB,CAAS;IAChD,wDAAwD;IAChD,OAAO,GAAG,CAAC,CAAC;IACZ,uBAAuB,GAAG,KAAK,CAAC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,EAAE,wCAAwC,MAAM,CAAC,KAAK,CAAC,EAAE;aACnE,CAAC,CAAC,CAAC,CAAC,CAAC;YACN,IAAI,CAAC,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IACO,IAAI;QACR,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3D,CAAC;IACO,SAAS;QACb,OAAO,eAAM,CAAC,KAAK,CAAO,CAAC,MAAM,EAAE,EAAE;YACjC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,eAAM,CAAC,IAAI,CAAC,CAAC;YACvC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACxB,OAAO,eAAM,CAAC,IAAI,CAAC,GAAG,EAAE;gBACpB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACzC,IAAI,KAAK,IAAI,CAAC;oBACV,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA5RD,kDA4RC;AACD,SAAS,eAAe,CAAQ,GAAyB;IACrD,OAAO,eAAM,CAAC,UAAU,CAAC;QACrB,GAAG,EAAE,GAAG;QACR,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KAC9E,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { applyCommandDeadline } from \"../sandbox/deadline.ts\";\nimport { sandboxReuseCapability, type SandboxProviderBackend } from \"../sandbox/backend.ts\";\nimport { makeSandboxAuthorFacade } from \"../sandbox/paths.ts\";\nimport { makeSandboxRequestExecutor } from \"../sandbox/request-executor.ts\";\nimport type { LinkedRunPlan } from \"../sandbox/plan.ts\";\nimport type { BuildKey } from \"../sandbox/identity.ts\";\nimport { materializeSandboxRunPlan, liveSandboxRuntimeServices, sandboxRuntimeCapabilities, type SandboxRuntimeDeadline, type SandboxRuntimeServices, } from \"../sandbox/runtime.ts\";\nimport type { JsonValue, Sandbox, SandboxAgent, SandboxHookContext, SandboxReuseCapability, ScopedFeedback } from \"../types.ts\";\nimport { CLEANUP_TIMEOUT_MS, cleanupCallback } from \"./cleanup-timeout.ts\";\nimport { createChangeLedger, type ChangeLedger } from \"./ledger.ts\";\nimport { firstLine, formatThrown } from \"../util.ts\";\nimport { Cause, Effect, Either, Exit, Scope } from \"effect\";\nimport type { GroupPluginContext, LinkedPluginLifecycle } from \"../plugin/contracts.ts\";\nexport interface ReusableSandboxLease {\n readonly sandbox: Sandbox;\n readonly reuseSandbox: number;\n readonly reuseOrdinal: number;\n /** 提交本次 Attempt 的归还决策;Scope 退出负责实际 reset/retire,漏提交默认 Retire。 */\n commit(disposition: ReusableLeaseRelease): Effect.Effect<void>;\n}\nexport type ReusableLeaseRelease = {\n readonly _tag: \"Reset\";\n} | {\n readonly _tag: \"Retire\";\n};\n/** A post-attempt physical lifecycle failure observed after its result sealed. */\nexport interface ReusableSandboxPoolRuntimeFailure {\n readonly stage: \"sandbox.reset\";\n readonly error: Error;\n}\ntype EntryLifecycle = {\n readonly _tag: \"Idle\";\n} | {\n readonly _tag: \"Leased\";\n} | {\n readonly _tag: \"Retired\";\n};\ninterface Entry {\n /** 资源面 Sandbox:registry / stop / suspend / ledger / lifetime / deadline 都用它。 */\n sandbox: Sandbox;\n /** 物化时的 raw provider backend:只用于逐次租借构建 author facade,不保存 facade/executor。 */\n authorBackend: SandboxProviderBackend;\n scope: Scope.CloseableScope;\n /** provider 自己实现的寿命确认;没有这条能力的实例根本进不来(见 create)。 */\n lifetime: SandboxReuseCapability;\n ledger: ChangeLedger;\n reuseSandbox: number;\n ordinal: number;\n lifecycle: EntryLifecycle;\n}\n/** Scope 尚未关闭前,lease 只能在这里两种归还意图之间演进。 */\ntype LeaseReleaseDecision = {\n readonly _tag: \"Uncommitted\";\n} | {\n readonly _tag: \"Committed\";\n readonly release: ReusableLeaseRelease;\n};\n/** 漏 commit 保持 Uncommitted,finalizer 因而 Retire;不再用 boolean 记账。 */\ntype LeaseLifecycle = {\n readonly _tag: \"Open\";\n readonly release: LeaseReleaseDecision;\n} | {\n readonly _tag: \"Finalized\";\n};\n/** 一个 pair-owned physical plan 的按需复用池;实例始终独占借给单条 Attempt。 */\nexport class ReusableSandboxPool {\n private readonly entries: Entry[] = [];\n private readonly waiters: Array<() => void> = [];\n private creating = 0;\n private stopped = false;\n private readonly runtimeFailures: ReusableSandboxPoolRuntimeFailure[] = [];\n /** Provider 可观察的物理 owner;Group 池不能随首个未携入成员改用另一个 Eval ID。 */\n private readonly materializationOwnerId: string;\n /** 本次 Run 内的 Sandbox 编号计数器;淘汰的实例不让号,编号在结果里永远指向同一个实例。 */\n private created = 0;\n private groupPluginSetupStarted = false;\n private groupPluginSetupError: unknown;\n private activatedGroupPlugins = 0;\n constructor(private readonly plan: Extract<LinkedRunPlan, {\n readonly _tag: \"Sandbox\";\n }>, private readonly capacity: number, private readonly feedback: ScopedFeedback, private readonly setupContext: SandboxHookContext, private readonly runtimeServices: SandboxRuntimeServices = liveSandboxRuntimeServices, private readonly agent?: SandboxAgent, private readonly runTiming?: import(\"./timing.ts\").RunTimingRecorder, materializationOwnerId?: string, private readonly nextReuseSandboxNumber?: () => number, private readonly groupPlugins: readonly LinkedPluginLifecycle[] = Object.freeze([]), private readonly groupPluginContext?: GroupPluginContext) {\n this.materializationOwnerId = materializationOwnerId ?? plan.pair.evalId;\n }\n /** 把整座池登记进调用方 Scope;Invocation 中断与正常结束走同一条 stop finalizer。 */\n managed(): Effect.Effect<this, never, Scope.Scope> {\n return Effect.addFinalizer(() => this.stop()).pipe(Effect.as(this));\n }\n /**\n * @param attemptDeadlineMs 这条 Attempt 实际生效的超时上限(解析链见 runner/timeout.ts)。\n * `undefined` = 四层都没声明上限:请求的寿命只能覆盖收尾预留——Attempt 本身没有 deadline,\n * 池无从知道它要跑多久,也不替它编一个数。此后实例被 provider 按自己的 `lifetimeMs` 回收\n * 就是「不声明上限」的代价(两种时间的分界见 docs/feature/sandbox/reuse.md)。\n */\n acquire(attemptDeadlineMs: number | undefined, buildLocators: ReadonlyMap<BuildKey, JsonValue>): Effect.Effect<ReusableSandboxLease, Error | import(\"../sandbox/runtime.ts\").SandboxRuntimeMaterializationError, Scope.Scope> {\n return Effect.gen(this, function* () {\n const minRemainingMs = (attemptDeadlineMs ?? 0) + CLEANUP_TIMEOUT_MS;\n /**\n * 借出期内单条命令的上限从这条线派生(`undefined` = 四层都没声明上限,照旧不发明一条线)。\n * 实例活得比 attempt 长,所以这条线必须**每次借出重设**——只在 create 时给一次的话,\n * 第二条 attempt 起就落回 provider SDK 的默认值(e2b 是 60 秒),实验声明的 timeoutMs\n * 完全不生效(见 sandbox/deadline.ts 的 `SandboxCommandDeadline`)。\n * 用 minRemainingMs 而不是 attemptDeadlineMs:归还时的分类账复位跑在同一条线下,\n * 不至于一还回来就撞一条已经过期的线。\n */\n const leaseDeadlineAt = attemptDeadlineMs === undefined ? undefined : () => Date.now() + minRemainingMs;\n for (;;) {\n if (this.stopped)\n return yield* Effect.fail(new Error(\"sandbox reuse pool has been stopped\"));\n const ready = this.entries.find((entry) => entry.lifecycle._tag === \"Idle\");\n if (ready) {\n // 派发前确认:请求足以覆盖 Attempt deadline 与收尾预留的寿命。不 ready 就停掉这台、\n // 交给下一轮创建替代实例(替代实例在 create 里再确认一次,还不行就报错,不反复重建)。\n const lifetime = yield* externalPromise(() => ready.lifetime.ensureLifetime(minRemainingMs));\n // lifetime 检查是异步 provider I/O;其间 stop() 或另一条 release 可能已经退休这台。\n // 只有仍是 Idle 的实例才能真正借出,stop 后让下一轮在入口处统一失败。\n if (lifetime.ready && !this.stopped && ready.lifecycle._tag === \"Idle\") {\n return yield* this.lease(ready, leaseDeadlineAt?.());\n }\n if (this.stopped || ready.lifecycle._tag !== \"Idle\")\n continue;\n yield* this.retire(ready);\n continue;\n }\n if (this.entries.length + this.creating < this.capacity) {\n this.creating += 1;\n return yield* Effect.gen(this, function* () {\n const created = yield* this.create(minRemainingMs, leaseDeadlineAt?.(), buildLocators);\n this.entries.push(created);\n // stop 可能在物化期间开始。把刚创建的 entry 先纳入池,再由唯一 retire 路径关闭\n // 它自己的 Scope;绝不能把它借给已停止的池,也不能让 stop 在 creating=0 时漏掉它。\n if (this.stopped) {\n yield* this.retire(created);\n return yield* Effect.fail(new Error(\"sandbox reuse pool has been stopped\"));\n }\n return yield* this.lease(created, leaseDeadlineAt?.());\n }).pipe(Effect.ensuring(Effect.sync(() => {\n this.creating -= 1;\n this.wake();\n })));\n }\n yield* this.awaitWake();\n }\n });\n }\n stop(): Effect.Effect<void> {\n return Effect.gen(this, function* () {\n this.stopped = true;\n this.wake();\n // 已借出的 lease 仍在执行其 Attempt/cleanup;现在关闭 entry Scope 会把 Sandbox 在\n // 使用中 teardown。创建中的 entry 尚未进 entries,必须等它落入唯一 retire 路径。\n while (this.creating > 0 || this.entries.some((entry) => entry.lifecycle._tag === \"Leased\")) {\n yield* this.awaitWake();\n }\n yield* Effect.forEach([...this.entries], (entry) => this.retire(entry), {\n concurrency: \"unbounded\",\n discard: true,\n });\n if (this.groupPluginContext !== undefined) {\n yield* Effect.forEach(this.groupPlugins.slice(0, this.activatedGroupPlugins).reverse(), (entry) => entry.teardown === undefined\n ? Effect.void\n : cleanupCallback((signal) => (entry.teardown as (context: GroupPluginContext) => void | Promise<void>)({\n ...this.groupPluginContext!,\n signal,\n })).pipe(Effect.catchAll((cause) => Effect.sync(() => this.feedback.diagnostic({\n code: \"plugin-lifecycle-teardown-failed\",\n level: \"warning\",\n message: cause instanceof Error ? cause.message : String(cause),\n })))), { discard: true });\n }\n });\n }\n /** Drained by the scheduler after the lease Scope sealed the prior result. */\n drainRuntimeFailures(): readonly ReusableSandboxPoolRuntimeFailure[] {\n return Object.freeze(this.runtimeFailures.splice(0));\n }\n private create(minRemainingMs: number, deadlineAt: number | undefined, buildLocators: ReadonlyMap<BuildKey, JsonValue>): Effect.Effect<Entry, Error | import(\"../sandbox/runtime.ts\").SandboxRuntimeMaterializationError> {\n return Effect.gen(this, function* () {\n if (this.groupPluginSetupError !== undefined)\n return yield* Effect.fail(this.groupPluginSetupError as Error);\n if (!this.groupPluginSetupStarted && this.groupPluginContext !== undefined) {\n this.groupPluginSetupStarted = true;\n const setup = yield* Effect.exit(Effect.forEach(this.groupPlugins, (entry, index) => {\n this.activatedGroupPlugins = index + 1;\n return entry.setup === undefined\n ? Effect.void\n : externalPromise(() => Promise.resolve((entry.setup as (context: GroupPluginContext) => void | Promise<void>)(this.groupPluginContext!)));\n }, { discard: true }));\n if (Exit.isFailure(setup)) {\n this.groupPluginSetupError = Cause.squash(setup.cause);\n return yield* Effect.fail(this.groupPluginSetupError as Error);\n }\n }\n const capabilities = sandboxRuntimeCapabilities(this.plan);\n if (capabilities.reuse._tag === \"Unsupported\") {\n return yield* Effect.fail(new Error(`sandboxReuse is unsupported by provider ${JSON.stringify(capabilities.provider)}: ${capabilities.reuse.reason}`));\n }\n const deadline: SandboxRuntimeDeadline = deadlineAt === undefined\n ? { _tag: \"Unlimited\" }\n : { _tag: \"Bounded\", timeoutMs: Math.max(1, minRemainingMs - CLEANUP_TIMEOUT_MS), deadlineAt };\n const entryScope = yield* Scope.make();\n const materialized = yield* Scope.extend(materializeSandboxRunPlan({\n plan: this.plan,\n evalId: this.materializationOwnerId,\n deadline,\n feedback: this.feedback,\n signal: this.setupContext.signal,\n hookContext: this.setupContext,\n buildLocators,\n ...(this.agent !== undefined ? { agent: this.agent } : {}),\n ...(this.runTiming !== undefined ? { runTiming: this.runTiming } : {}),\n provisionSlot: { _tag: \"Detached\" },\n services: this.runtimeServices,\n release: { _tag: \"Stop\" },\n }), entryScope).pipe(Effect.onError((cause) => Scope.close(entryScope, Exit.failCause(cause))));\n const sandbox = materialized.sandbox;\n // 能力只能来自 provider 实现:探不到就硬失败,没有通用记账兜底(见\n // docs/feature/sandbox/reuse.md「派发前确认」)。\n const lifetime = sandboxReuseCapability(sandbox);\n if (!lifetime) {\n yield* Scope.close(entryScope, Exit.void);\n return yield* Effect.fail(new Error(`sandboxReuse needs the \"${capabilities.provider}\" provider to confirm sandbox lifetime, but it does not implement ` +\n \"ensureLifetime(minRemainingMs). Only a provider can prove the lifetime is set on its own backend; the runner \" +\n \"will not keep local books for it. Use a provider that implements it (docker / e2b / vercel), or drop sandboxReuse.\"));\n }\n const confirmed = yield* externalPromise(() => lifetime.ensureLifetime(minRemainingMs)).pipe(Effect.onError((cause) => Scope.close(entryScope, Exit.failCause(cause))));\n if (!confirmed.ready) {\n yield* Scope.close(entryScope, Exit.void);\n return yield* Effect.fail(new Error(`sandboxReuse cannot prepare the \"${capabilities.provider}\" sandbox: ${confirmed.reason}`));\n }\n const prepared = yield* Effect.gen(this, function* () {\n const ledger = yield* externalPromise(() => createChangeLedger(sandbox));\n // root 执行身份下题间 reset 永不安全(Agent 能读上一条 Attempt 留下的私有分类账对象);\n // 在实例进池、第一条 Attempt 派发前就拒绝,而不是等到归还时才在 resetToAnchor() 里\n // 暴露(那样首条 Attempt 已经跑完,失败还可能被静默退休吞掉)。\n if (ledger.rootExecutionIdentity) {\n return yield* Effect.fail(new Error(`sandboxReuse cannot reuse the \"${capabilities.provider}\" sandbox: the Agent's execution identity is root and could read private ledger objects left by earlier attempts; ` +\n \"use a non-root execution user (declare USER in the image) or disable sandboxReuse\"));\n }\n // 建分类账会烧掉寿命:备好之后再确认一次。这次不够就报错收场——\n // 反复创建同样的替代实例只会反复烧同样的时间(见 reuse.md「派发前确认」)。\n const afterSetup = yield* externalPromise(() => lifetime.ensureLifetime(minRemainingMs));\n if (!afterSetup.ready) {\n return yield* Effect.fail(new Error(`sandboxReuse cannot use the \"${capabilities.provider}\" sandbox after baseline setup: ${afterSetup.reason}`));\n }\n const reuseSandbox = this.nextReuseSandboxNumber === undefined\n ? ++this.created\n : this.nextReuseSandboxNumber();\n return {\n sandbox,\n authorBackend: materialized.authorBackend,\n scope: entryScope,\n lifetime,\n ledger,\n reuseSandbox,\n ordinal: 0,\n lifecycle: { _tag: \"Idle\" } satisfies EntryLifecycle,\n };\n }).pipe(Effect.onError((cause) => Scope.close(entryScope, Exit.failCause(cause))));\n return prepared;\n });\n }\n private lease(entry: Entry, deadlineAt: number | undefined): Effect.Effect<ReusableSandboxLease, never, Scope.Scope> {\n return Effect.gen(this, function* () {\n entry.lifecycle = { _tag: \"Leased\" };\n entry.ordinal += 1;\n applyCommandDeadline(entry.sandbox, deadlineAt);\n let lifecycle: LeaseLifecycle = {\n _tag: \"Open\",\n release: { _tag: \"Uncommitted\" },\n };\n // 先登记 release/reset finalizer:executor/facade 的封闭 finalizer 在其后登记,Scope\n // 关闭时按 LIFO 先中断在飞请求、封闭旧 facade,再对资源面执行 reset/retire——reset\n // 期间不会再有旧 facade 的请求借道写入 ledger/workdir。\n yield* Effect.addFinalizer(() => Effect.gen(this, function* () {\n if (lifecycle._tag === \"Finalized\")\n return;\n const settled = lifecycle;\n lifecycle = { _tag: \"Finalized\" };\n const release: ReusableLeaseRelease = settled.release._tag === \"Committed\"\n ? settled.release.release\n : { _tag: \"Retire\" };\n if (release._tag === \"Retire\") {\n yield* this.retire(entry);\n }\n else if (entry.lifecycle._tag !== \"Retired\") {\n const reset = yield* Effect.either(externalPromise(() => entry.ledger.resetToAnchor()));\n if (Either.isLeft(reset)) {\n this.runtimeFailures.push(Object.freeze({ stage: \"sandbox.reset\", error: reset.left }));\n this.feedback.diagnostic({\n code: \"sandbox-reset-failed\",\n level: \"warning\",\n message: `Sandbox #${entry.reuseSandbox} reset to anchor failed, retiring the instance: ${firstLine(formatThrown(reset.left))}`,\n });\n yield* this.retire(entry);\n }\n else {\n entry.lifecycle = { _tag: \"Idle\" };\n }\n }\n this.wake();\n }));\n // 每次租借在当前 Attempt Scope 新建 executor 与 author facade:上一轮 facade/executor\n // 不跨租借复用,不把旧 Runtime 带进新 Attempt。\n const executor = yield* makeSandboxRequestExecutor();\n const authorSandbox = makeSandboxAuthorFacade(entry.authorBackend, executor, this.plan.providerPlan.provider);\n return {\n sandbox: authorSandbox,\n reuseSandbox: entry.reuseSandbox,\n reuseOrdinal: entry.ordinal,\n commit: (release) => Effect.sync(() => {\n if (lifecycle._tag !== \"Open\")\n return;\n lifecycle = { ...lifecycle, release: { _tag: \"Committed\", release } };\n }),\n };\n });\n }\n /** 淘汰一台实例:停资源组并移出池——留在池里会占满容量,\n * 让后续 acquire 既等不到空闲实例、也创建不出替代实例(等待者永远醒不来)。 */\n private retire(entry: Entry): Effect.Effect<void> {\n return Effect.gen(this, function* () {\n if (entry.lifecycle._tag === \"Retired\")\n return;\n entry.lifecycle = { _tag: \"Retired\" };\n const at = this.entries.indexOf(entry);\n if (at >= 0)\n this.entries.splice(at, 1);\n yield* Scope.close(entry.scope, Exit.void).pipe(Effect.catchAllCause((cause) => Effect.sync(() => this.feedback.diagnostic({\n code: \"sandbox-stop-failed\",\n level: \"warning\",\n message: `Sandbox reuse case finalizer failed: ${String(cause)}`,\n }))));\n this.wake();\n });\n }\n private wake(): void {\n this.waiters.splice(0).forEach((resolve) => resolve());\n }\n private awaitWake(): Effect.Effect<void> {\n return Effect.async<void>((resume) => {\n const wake = () => resume(Effect.void);\n this.waiters.push(wake);\n return Effect.sync(() => {\n const index = this.waiters.indexOf(wake);\n if (index >= 0)\n this.waiters.splice(index, 1);\n });\n });\n }\n}\nfunction externalPromise<Value>(run: () => Promise<Value>): Effect.Effect<Value, Error> {\n return Effect.tryPromise({\n try: run,\n catch: (cause) => cause instanceof Error ? cause : new Error(String(cause)),\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sandbox-pool.js","sourceRoot":"","sources":["sandbox-pool.ts"],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AC,UAAU,CAAC;QACrB,GAAG,EAAE,GAAG;QACR,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KAC9E,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { applyCommandDeadline } from \"../sandbox/deadline.ts\";\nimport { sandboxReuseCapability, type SandboxProviderBackend } from \"../sandbox/backend.ts\";\nimport { makeSandboxAuthorFacade } from \"../sandbox/paths.ts\";\nimport { makeSandboxRequestExecutor } from \"../sandbox/request-executor.ts\";\nimport type { LinkedRunPlan } from \"../sandbox/plan.ts\";\nimport type { BuildKey } from \"../sandbox/identity.ts\";\nimport { materializeSandboxRunPlan, liveSandboxRuntimeServices, sandboxRuntimeCapabilities, type SandboxRuntimeDeadline, type SandboxRuntimeServices, } from \"../sandbox/runtime.ts\";\nimport type { JsonValue, Sandbox, SandboxAgent, SandboxHookContext, SandboxReuseCapability, ScopedFeedback } from \"../types.ts\";\nimport { CLEANUP_TIMEOUT_MS, cleanupCallback } from \"./cleanup-timeout.ts\";\nimport { createChangeLedger, type ChangeLedger } from \"./ledger.ts\";\nimport { firstLine, formatThrown } from \"../util.ts\";\nimport { Cause, Deferred, Effect, Either, Exit, Scope } from \"effect\";\nimport type { GroupPluginContext, LinkedPluginLifecycle } from \"../plugin/contracts.ts\";\nexport interface ReusableSandboxLease {\n readonly sandbox: Sandbox;\n readonly reuseSandbox: number;\n readonly reuseOrdinal: number;\n /** 提交本次 Attempt 的归还决策;Scope 退出负责实际 reset/retire,漏提交默认 Retire。 */\n commit(disposition: ReusableLeaseRelease): Effect.Effect<void>;\n}\nexport type ReusableLeaseRelease = {\n readonly _tag: \"Reset\";\n} | {\n readonly _tag: \"Retire\";\n};\n/** A post-attempt physical lifecycle failure observed after its result sealed. */\nexport interface ReusableSandboxPoolRuntimeFailure {\n readonly stage: \"sandbox.reset\";\n readonly error: Error;\n}\n/**\n * A physical Sandbox Scope or reset failure that must remain observable until\n * the owning Experiment has completed its one-and-only pool stop. Unlike\n * `runtimeFailures`, this ledger is deliberately never drained by Attempt\n * result sealing: an early retire may have already removed its entry from the\n * live pool, but it must still make Experiment cleanup fail.\n */\ninterface ReusableSandboxPoolCleanupFailure {\n readonly stage: \"sandbox.reset\" | \"sandbox.retire\" | \"sandbox.materialize-cleanup\" | \"sandbox.ensure-lifetime-cleanup\" | \"sandbox.prepare-cleanup\" | \"sandbox.lifecycle-diagnostic\";\n readonly error: Error;\n}\ntype EntryLifecycle = {\n readonly _tag: \"Idle\";\n} | {\n readonly _tag: \"Leased\";\n} | {\n readonly _tag: \"Retired\";\n};\ninterface Entry {\n /** 资源面 Sandbox:registry / stop / suspend / ledger / lifetime / deadline 都用它。 */\n sandbox: Sandbox;\n /** 物化时的 raw provider backend:只用于逐次租借构建 author facade,不保存 facade/executor。 */\n authorBackend: SandboxProviderBackend;\n scope: Scope.CloseableScope;\n /** provider 自己实现的寿命确认;没有这条能力的实例根本进不来(见 create)。 */\n lifetime: SandboxReuseCapability;\n ledger: ChangeLedger;\n reuseSandbox: number;\n ordinal: number;\n lifecycle: EntryLifecycle;\n}\n/** Scope 尚未关闭前,lease 只能在这里两种归还意图之间演进。 */\ntype LeaseReleaseDecision = {\n readonly _tag: \"Uncommitted\";\n} | {\n readonly _tag: \"Committed\";\n readonly release: ReusableLeaseRelease;\n};\n/** 漏 commit 保持 Uncommitted,finalizer 因而 Retire;不再用 boolean 记账。 */\ntype LeaseLifecycle = {\n readonly _tag: \"Open\";\n readonly release: LeaseReleaseDecision;\n} | {\n readonly _tag: \"Finalized\";\n};\n/** 一个 pair-owned physical plan 的按需复用池;实例始终独占借给单条 Attempt。 */\nexport class ReusableSandboxPool {\n private readonly entries: Entry[] = [];\n private readonly waiters: Array<() => void> = [];\n private creating = 0;\n private stopped = false;\n /** One physical stop operation owns every instance/finalizer exactly once. */\n private stopCompletion: Deferred.Deferred<void, unknown> | undefined;\n private readonly runtimeFailures: ReusableSandboxPoolRuntimeFailure[] = [];\n /**\n * Whole-Experiment physical cleanup ledger. This is intentionally distinct\n * from `runtimeFailures`: the latter is a per-Attempt diagnostic channel and\n * is drained once that Attempt seals, whereas this collection is replayed by\n * the terminal `stop()` even if an entry was retired long before then.\n */\n private readonly cleanupFailures: ReusableSandboxPoolCleanupFailure[] = [];\n /** Provider 可观察的物理 owner;Group 池不能随首个未携入成员改用另一个 Eval ID。 */\n private readonly materializationOwnerId: string;\n /** 本次 Run 内的 Sandbox 编号计数器;淘汰的实例不让号,编号在结果里永远指向同一个实例。 */\n private created = 0;\n private groupPluginSetupStarted = false;\n private groupPluginSetupError: unknown;\n private activatedGroupPlugins = 0;\n constructor(private readonly plan: Extract<LinkedRunPlan, {\n readonly _tag: \"Sandbox\";\n }>, private readonly capacity: number, private readonly feedback: ScopedFeedback, private readonly setupContext: SandboxHookContext, private readonly runtimeServices: SandboxRuntimeServices = liveSandboxRuntimeServices, private readonly agent?: SandboxAgent, private readonly runTiming?: import(\"./timing.ts\").RunTimingRecorder, materializationOwnerId?: string, private readonly nextReuseSandboxNumber?: () => number, private readonly groupPlugins: readonly LinkedPluginLifecycle[] = Object.freeze([]), private readonly groupPluginContext?: GroupPluginContext) {\n this.materializationOwnerId = materializationOwnerId ?? plan.pair.evalId;\n }\n /**\n * Registers only an awaiter in the outer Invocation Scope. The real stop is\n * initiated by the Experiment lifecycle before its teardown; if the outer\n * Scope closes first it joins the same single-flight result rather than\n * repeating provider or plugin finalizers.\n */\n managed(): Effect.Effect<this, never, Scope.Scope> {\n return Effect.addFinalizer(() => this.stop().pipe(Effect.ignore)).pipe(Effect.as(this));\n }\n /** Closes admission before the Experiment starts physical cleanup. */\n freeze(): Effect.Effect<void> {\n return Effect.sync(() => {\n this.stopped = true;\n this.wake();\n });\n }\n /**\n * @param attemptDeadlineMs 这条 Attempt 实际生效的超时上限(解析链见 runner/timeout.ts)。\n * `undefined` = 四层都没声明上限:请求的寿命只能覆盖收尾预留——Attempt 本身没有 deadline,\n * 池无从知道它要跑多久,也不替它编一个数。此后实例被 provider 按自己的 `lifetimeMs` 回收\n * 就是「不声明上限」的代价(两种时间的分界见 docs/feature/sandbox/reuse.md)。\n */\n acquire(attemptDeadlineMs: number | undefined, buildLocators: ReadonlyMap<BuildKey, JsonValue>): Effect.Effect<ReusableSandboxLease, Error | import(\"../sandbox/runtime.ts\").SandboxRuntimeMaterializationError, Scope.Scope> {\n return Effect.gen(this, function* () {\n const minRemainingMs = (attemptDeadlineMs ?? 0) + CLEANUP_TIMEOUT_MS;\n /**\n * 借出期内单条命令的上限从这条线派生(`undefined` = 四层都没声明上限,照旧不发明一条线)。\n * 实例活得比 attempt 长,所以这条线必须**每次借出重设**——只在 create 时给一次的话,\n * 第二条 attempt 起就落回 provider SDK 的默认值(e2b 是 60 秒),实验声明的 timeoutMs\n * 完全不生效(见 sandbox/deadline.ts 的 `SandboxCommandDeadline`)。\n * 用 minRemainingMs 而不是 attemptDeadlineMs:归还时的分类账复位跑在同一条线下,\n * 不至于一还回来就撞一条已经过期的线。\n */\n const leaseDeadlineAt = attemptDeadlineMs === undefined ? undefined : () => Date.now() + minRemainingMs;\n for (;;) {\n if (this.stopped)\n return yield* Effect.fail(new Error(\"sandbox reuse pool has been stopped\"));\n const ready = this.entries.find((entry) => entry.lifecycle._tag === \"Idle\");\n if (ready) {\n // 派发前确认:请求足以覆盖 Attempt deadline 与收尾预留的寿命。不 ready 就停掉这台、\n // 交给下一轮创建替代实例(替代实例在 create 里再确认一次,还不行就报错,不反复重建)。\n const lifetime = yield* externalPromise(() => ready.lifetime.ensureLifetime(minRemainingMs));\n // lifetime 检查是异步 provider I/O;其间 stop() 或另一条 release 可能已经退休这台。\n // 只有仍是 Idle 的实例才能真正借出,stop 后让下一轮在入口处统一失败。\n if (lifetime.ready && !this.stopped && ready.lifecycle._tag === \"Idle\") {\n return yield* this.lease(ready, leaseDeadlineAt?.());\n }\n if (this.stopped || ready.lifecycle._tag !== \"Idle\")\n continue;\n yield* this.retire(ready);\n continue;\n }\n if (this.entries.length + this.creating < this.capacity) {\n this.creating += 1;\n return yield* Effect.gen(this, function* () {\n const created = yield* this.create(minRemainingMs, leaseDeadlineAt?.(), buildLocators);\n this.entries.push(created);\n // stop 可能在物化期间开始。把刚创建的 entry 先纳入池,再由唯一 retire 路径关闭\n // 它自己的 Scope;绝不能把它借给已停止的池,也不能让 stop 在 creating=0 时漏掉它。\n if (this.stopped) {\n yield* this.retire(created);\n return yield* Effect.fail(new Error(\"sandbox reuse pool has been stopped\"));\n }\n return yield* this.lease(created, leaseDeadlineAt?.());\n }).pipe(Effect.ensuring(Effect.sync(() => {\n this.creating -= 1;\n this.wake();\n })));\n }\n yield* this.awaitWake();\n }\n });\n }\n stop(): Effect.Effect<void, unknown> {\n return Effect.uninterruptibleMask((restore) => Effect.gen(this, function* () {\n const created = yield* Deferred.make<void, unknown>();\n const completion = yield* Effect.sync(() => {\n if (this.stopCompletion !== undefined)\n return this.stopCompletion;\n this.stopCompletion = created;\n this.stopped = true;\n this.wake();\n return created;\n });\n // A caller joining an already-started stop remains cancelable. The one\n // caller that starts it cannot be interrupted between publishing the\n // Deferred and recording its terminal Exit.\n if (completion !== created)\n return yield* restore(Deferred.await(completion));\n // Stop must finish every physical cleanup even if the initiating\n // Invocation is interrupted. Its recorded Exit is replayed to joiners.\n const exit = yield* Effect.exit(this.stopAll());\n yield* Deferred.done(created, exit);\n if (Exit.isFailure(exit))\n return yield* Effect.failCause(exit.cause);\n }));\n }\n private stopAll(): Effect.Effect<void, unknown> {\n return Effect.gen(this, function* () {\n // Leases own their Attempt scopes. Wait until each lease has returned\n // before closing provider scopes; this is also the barrier that makes\n // pool stop safe to place before Experiment teardown.\n while (this.creating > 0 || this.entries.some((entry) => entry.lifecycle._tag === \"Leased\")) {\n yield* this.awaitWake();\n }\n const exits: Exit.Exit<void, unknown>[] = [];\n const retired = yield* Effect.forEach([...this.entries], (entry) => Effect.exit(this.retire(entry)), {\n concurrency: \"unbounded\",\n });\n exits.push(...retired);\n if (this.groupPluginContext !== undefined) {\n const groupTeardowns = yield* Effect.forEach(this.groupPlugins.slice(0, this.activatedGroupPlugins).reverse(), (entry) => entry.teardown === undefined\n ? Effect.succeed(Exit.void)\n : Effect.exit(cleanupCallback((signal) => (entry.teardown as (context: GroupPluginContext) => void | Promise<void>)({\n ...this.groupPluginContext!,\n signal,\n }))), { concurrency: \"unbounded\" });\n for (const exit of groupTeardowns) {\n exits.push(exit);\n if (Exit.isFailure(exit)) {\n this.feedback.diagnostic({\n code: \"plugin-lifecycle-teardown-failed\",\n level: \"warning\",\n message: String(Cause.squash(exit.cause)),\n });\n }\n }\n }\n const failures: unknown[] = [];\n for (const exit of exits) {\n if (Exit.isFailure(exit))\n failures.push(Cause.squash(exit.cause));\n }\n // An entry may have been removed by a failed Attempt release before this\n // terminal sweep. Replaying the durable pool-local ledger makes that\n // physical Scope/provider cleanup failure visible to Experiment teardown\n // and therefore to sharedState lease release.\n failures.push(...this.cleanupFailures.map((failure) => failure.error));\n if (failures.length > 0) {\n return yield* Effect.fail(new AggregateError([...new Set(failures)], \"Sandbox reuse pool cleanup failed.\"));\n }\n });\n }\n /** Drained by the scheduler after the lease Scope sealed the prior result. */\n drainRuntimeFailures(): readonly ReusableSandboxPoolRuntimeFailure[] {\n return Object.freeze(this.runtimeFailures.splice(0));\n }\n private create(minRemainingMs: number, deadlineAt: number | undefined, buildLocators: ReadonlyMap<BuildKey, JsonValue>): Effect.Effect<Entry, Error | import(\"../sandbox/runtime.ts\").SandboxRuntimeMaterializationError> {\n return Effect.gen(this, function* () {\n if (this.groupPluginSetupError !== undefined)\n return yield* Effect.fail(this.groupPluginSetupError as Error);\n if (!this.groupPluginSetupStarted && this.groupPluginContext !== undefined) {\n this.groupPluginSetupStarted = true;\n const setup = yield* Effect.exit(Effect.forEach(this.groupPlugins, (entry, index) => {\n this.activatedGroupPlugins = index + 1;\n return entry.setup === undefined\n ? Effect.void\n : externalPromise(() => Promise.resolve((entry.setup as (context: GroupPluginContext) => void | Promise<void>)(this.groupPluginContext!)));\n }, { discard: true }));\n if (Exit.isFailure(setup)) {\n this.groupPluginSetupError = Cause.squash(setup.cause);\n return yield* Effect.fail(this.groupPluginSetupError as Error);\n }\n }\n const capabilities = sandboxRuntimeCapabilities(this.plan);\n if (capabilities.reuse._tag === \"Unsupported\") {\n return yield* Effect.fail(new Error(`sandboxReuse is unsupported by provider ${JSON.stringify(capabilities.provider)}: ${capabilities.reuse.reason}`));\n }\n const deadline: SandboxRuntimeDeadline = deadlineAt === undefined\n ? { _tag: \"Unlimited\" }\n : { _tag: \"Bounded\", timeoutMs: Math.max(1, minRemainingMs - CLEANUP_TIMEOUT_MS), deadlineAt };\n const entryScope = yield* Scope.make();\n // One wrapper per physical materialization. Both provider feedback and\n // SandboxLayer hook context must use this exact instance: runtime sends\n // provider release failures through `feedback`, while\n // `runTeardownHooks` reports through `hookContext.diagnostic`.\n const lifecycleFeedback = this.lifecycleFeedback();\n const lifecycleHookContext: SandboxHookContext = {\n ...this.setupContext,\n progress: lifecycleFeedback.progress,\n diagnostic: lifecycleFeedback.diagnostic,\n };\n const materialized = yield* Scope.extend(materializeSandboxRunPlan({\n plan: this.plan,\n evalId: this.materializationOwnerId,\n deadline,\n // Runtime intentionally reports SandboxLayer/provider finalizer errors\n // as diagnostics so it can continue the remaining finalizers. The pool\n // must nevertheless retain those physical cleanup failures until its\n // terminal stop; otherwise an early retire can disappear from\n // `entries` and incorrectly permit sharedState release.\n feedback: lifecycleFeedback,\n signal: this.setupContext.signal,\n hookContext: lifecycleHookContext,\n buildLocators,\n ...(this.agent !== undefined ? { agent: this.agent } : {}),\n ...(this.runTiming !== undefined ? { runTiming: this.runTiming } : {}),\n provisionSlot: { _tag: \"Detached\" },\n services: this.runtimeServices,\n release: { _tag: \"Stop\" },\n }), entryScope).pipe(Effect.onError((cause) => this.closeFailedCreateScope(entryScope, Exit.failCause(cause), \"sandbox.materialize-cleanup\")));\n const sandbox = materialized.sandbox;\n // 能力只能来自 provider 实现:探不到就硬失败,没有通用记账兜底(见\n // docs/feature/sandbox/reuse.md「派发前确认」)。\n const lifetime = sandboxReuseCapability(sandbox);\n if (!lifetime) {\n yield* this.closeFailedCreateScope(entryScope, Exit.void, \"sandbox.ensure-lifetime-cleanup\");\n return yield* Effect.fail(new Error(`sandboxReuse needs the \"${capabilities.provider}\" provider to confirm sandbox lifetime, but it does not implement ` +\n \"ensureLifetime(minRemainingMs). Only a provider can prove the lifetime is set on its own backend; the runner \" +\n \"will not keep local books for it. Use a provider that implements it (docker / e2b / vercel), or drop sandboxReuse.\"));\n }\n const confirmed = yield* externalPromise(() => lifetime.ensureLifetime(minRemainingMs)).pipe(Effect.onError((cause) => this.closeFailedCreateScope(entryScope, Exit.failCause(cause), \"sandbox.ensure-lifetime-cleanup\")));\n if (!confirmed.ready) {\n yield* this.closeFailedCreateScope(entryScope, Exit.void, \"sandbox.ensure-lifetime-cleanup\");\n return yield* Effect.fail(new Error(`sandboxReuse cannot prepare the \"${capabilities.provider}\" sandbox: ${confirmed.reason}`));\n }\n const prepared = yield* Effect.gen(this, function* () {\n const ledger = yield* externalPromise(() => createChangeLedger(sandbox));\n // root 执行身份下题间 reset 永不安全(Agent 能读上一条 Attempt 留下的私有分类账对象);\n // 在实例进池、第一条 Attempt 派发前就拒绝,而不是等到归还时才在 resetToAnchor() 里\n // 暴露(那样首条 Attempt 已经跑完,失败还可能被静默退休吞掉)。\n if (ledger.rootExecutionIdentity) {\n return yield* Effect.fail(new Error(`sandboxReuse cannot reuse the \"${capabilities.provider}\" sandbox: the Agent's execution identity is root and could read private ledger objects left by earlier attempts; ` +\n \"use a non-root execution user (declare USER in the image) or disable sandboxReuse\"));\n }\n // 建分类账会烧掉寿命:备好之后再确认一次。这次不够就报错收场——\n // 反复创建同样的替代实例只会反复烧同样的时间(见 reuse.md「派发前确认」)。\n const afterSetup = yield* externalPromise(() => lifetime.ensureLifetime(minRemainingMs));\n if (!afterSetup.ready) {\n return yield* Effect.fail(new Error(`sandboxReuse cannot use the \"${capabilities.provider}\" sandbox after baseline setup: ${afterSetup.reason}`));\n }\n const reuseSandbox = this.nextReuseSandboxNumber === undefined\n ? ++this.created\n : this.nextReuseSandboxNumber();\n return {\n sandbox,\n authorBackend: materialized.authorBackend,\n scope: entryScope,\n lifetime,\n ledger,\n reuseSandbox,\n ordinal: 0,\n lifecycle: { _tag: \"Idle\" } satisfies EntryLifecycle,\n };\n }).pipe(Effect.onError((cause) => this.closeFailedCreateScope(entryScope, Exit.failCause(cause), \"sandbox.prepare-cleanup\")));\n return prepared;\n });\n }\n private lease(entry: Entry, deadlineAt: number | undefined): Effect.Effect<ReusableSandboxLease, never, Scope.Scope> {\n return Effect.gen(this, function* () {\n entry.lifecycle = { _tag: \"Leased\" };\n entry.ordinal += 1;\n applyCommandDeadline(entry.sandbox, deadlineAt);\n let lifecycle: LeaseLifecycle = {\n _tag: \"Open\",\n release: { _tag: \"Uncommitted\" },\n };\n // 先登记 release/reset finalizer:executor/facade 的封闭 finalizer 在其后登记,Scope\n // 关闭时按 LIFO 先中断在飞请求、封闭旧 facade,再对资源面执行 reset/retire——reset\n // 期间不会再有旧 facade 的请求借道写入 ledger/workdir。\n yield* Effect.addFinalizer(() => Effect.gen(this, function* () {\n if (lifecycle._tag === \"Finalized\")\n return;\n const settled = lifecycle;\n lifecycle = { _tag: \"Finalized\" };\n const release: ReusableLeaseRelease = settled.release._tag === \"Committed\"\n ? settled.release.release\n : { _tag: \"Retire\" };\n if (release._tag === \"Retire\") {\n // The Attempt has already sealed. Do not turn its return finalizer\n // into a defect; `retire` persists the physical failure and terminal\n // `stop()` replays it to Experiment cleanup/lease release.\n yield* this.retire(entry).pipe(Effect.catchAll(() => Effect.void));\n }\n else if (entry.lifecycle._tag !== \"Retired\") {\n const reset = yield* Effect.either(externalPromise(() => entry.ledger.resetToAnchor()));\n if (Either.isLeft(reset)) {\n this.runtimeFailures.push(Object.freeze({ stage: \"sandbox.reset\", error: reset.left }));\n this.recordCleanupFailure(\"sandbox.reset\", reset.left);\n this.feedback.diagnostic({\n code: \"sandbox-reset-failed\",\n level: \"warning\",\n message: `Sandbox #${entry.reuseSandbox} reset to anchor failed, retiring the instance: ${firstLine(formatThrown(reset.left))}`,\n });\n yield* this.retire(entry).pipe(Effect.catchAll(() => Effect.void));\n }\n else {\n entry.lifecycle = { _tag: \"Idle\" };\n }\n }\n this.wake();\n }));\n // 每次租借在当前 Attempt Scope 新建 executor 与 author facade:上一轮 facade/executor\n // 不跨租借复用,不把旧 Runtime 带进新 Attempt。\n const executor = yield* makeSandboxRequestExecutor();\n const authorSandbox = makeSandboxAuthorFacade(entry.authorBackend, executor, this.plan.providerPlan.provider);\n return {\n sandbox: authorSandbox,\n reuseSandbox: entry.reuseSandbox,\n reuseOrdinal: entry.ordinal,\n commit: (release) => Effect.sync(() => {\n if (lifecycle._tag !== \"Open\")\n return;\n lifecycle = { ...lifecycle, release: { _tag: \"Committed\", release } };\n }),\n };\n });\n }\n /** 淘汰一台实例:停资源组并移出池——留在池里会占满容量,\n * 让后续 acquire 既等不到空闲实例、也创建不出替代实例(等待者永远醒不来)。 */\n private retire(entry: Entry): Effect.Effect<void, Error> {\n return Effect.gen(this, function* () {\n if (entry.lifecycle._tag === \"Retired\")\n return;\n entry.lifecycle = { _tag: \"Retired\" };\n const at = this.entries.indexOf(entry);\n if (at >= 0)\n this.entries.splice(at, 1);\n const exit = yield* Effect.exit(Scope.close(entry.scope, Exit.void));\n if (Exit.isFailure(exit)) {\n const error = this.recordCleanupFailure(\"sandbox.retire\", Cause.squash(exit.cause));\n this.feedback.diagnostic({\n code: \"sandbox-stop-failed\",\n level: \"warning\",\n message: `Sandbox reuse case finalizer failed: ${String(error)}`,\n });\n this.wake();\n return yield* Effect.fail(error);\n }\n this.wake();\n });\n }\n private wake(): void {\n this.waiters.splice(0).forEach((resolve) => resolve());\n }\n private awaitWake(): Effect.Effect<void> {\n return Effect.async<void>((resume) => {\n const wake = () => resume(Effect.void);\n this.waiters.push(wake);\n return Effect.sync(() => {\n const index = this.waiters.indexOf(wake);\n if (index >= 0)\n this.waiters.splice(index, 1);\n });\n });\n }\n /**\n * A create/ensureLifetime failure can still run provider and Sandbox Scope\n * finalizers. The entry is not yet in `entries`, so `stopAll()` cannot find\n * it later; record a close failure now and replay it from the Experiment\n * lifetime ledger instead of letting an `onError` cleanup failure vanish.\n */\n private closeFailedCreateScope(scope: Scope.CloseableScope, exit: Exit.Exit<unknown, unknown>, stage: Extract<ReusableSandboxPoolCleanupFailure[\"stage\"], \"sandbox.materialize-cleanup\" | \"sandbox.ensure-lifetime-cleanup\" | \"sandbox.prepare-cleanup\">): Effect.Effect<void> {\n return Effect.exit(Scope.close(scope, exit)).pipe(Effect.flatMap((close) => Exit.isFailure(close)\n ? Effect.sync(() => {\n const error = this.recordCleanupFailure(stage, Cause.squash(close.cause));\n this.feedback.diagnostic({\n code: \"sandbox-stop-failed\",\n level: \"warning\",\n message: `Sandbox reuse setup cleanup failed: ${String(error)}`,\n });\n })\n : Effect.void));\n }\n private recordCleanupFailure(stage: ReusableSandboxPoolCleanupFailure[\"stage\"], cause: unknown): Error {\n const error = cause instanceof Error ? cause : new Error(String(cause));\n this.cleanupFailures.push(Object.freeze({ stage, error }));\n return error;\n }\n /**\n * `materializeSandboxRunPlan` deliberately converts hook/provider cleanup\n * failures into feedback and continues its Scope.close. Preserve that signal\n * beside thrown Scope close failures, without changing the public Sandbox\n * lifecycle API or its diagnostic-only finalizer contract.\n */\n private lifecycleFeedback(): ScopedFeedback {\n return {\n progress: (update) => this.feedback.progress(update),\n diagnostic: (input) => {\n this.feedback.diagnostic(input);\n if (input.code === \"sandbox-teardown-failed\" ||\n input.code === \"sandbox-stop-failed\" ||\n input.code === \"plugin-lifecycle-teardown-failed\") {\n this.recordCleanupFailure(\"sandbox.lifecycle-diagnostic\", new Error(input.message));\n }\n },\n };\n }\n}\nfunction externalPromise<Value>(run: () => Promise<Value>): Effect.Effect<Value, Error> {\n return Effect.tryPromise({\n try: run,\n catch: (cause) => cause instanceof Error ? cause : new Error(String(cause)),\n });\n}\n"]}
|
|
@@ -37,7 +37,16 @@ export declare class ReusableSandboxPool {
|
|
|
37
37
|
private readonly waiters;
|
|
38
38
|
private creating;
|
|
39
39
|
private stopped;
|
|
40
|
+
/** One physical stop operation owns every instance/finalizer exactly once. */
|
|
41
|
+
private stopCompletion;
|
|
40
42
|
private readonly runtimeFailures;
|
|
43
|
+
/**
|
|
44
|
+
* Whole-Experiment physical cleanup ledger. This is intentionally distinct
|
|
45
|
+
* from `runtimeFailures`: the latter is a per-Attempt diagnostic channel and
|
|
46
|
+
* is drained once that Attempt seals, whereas this collection is replayed by
|
|
47
|
+
* the terminal `stop()` even if an entry was retired long before then.
|
|
48
|
+
*/
|
|
49
|
+
private readonly cleanupFailures;
|
|
41
50
|
/** Provider 可观察的物理 owner;Group 池不能随首个未携入成员改用另一个 Eval ID。 */
|
|
42
51
|
private readonly materializationOwnerId;
|
|
43
52
|
/** 本次 Run 内的 Sandbox 编号计数器;淘汰的实例不让号,编号在结果里永远指向同一个实例。 */
|
|
@@ -48,8 +57,15 @@ export declare class ReusableSandboxPool {
|
|
|
48
57
|
constructor(plan: Extract<LinkedRunPlan, {
|
|
49
58
|
readonly _tag: "Sandbox";
|
|
50
59
|
}>, capacity: number, feedback: ScopedFeedback, setupContext: SandboxHookContext, runtimeServices?: SandboxRuntimeServices, agent?: SandboxAgent | undefined, runTiming?: import("./timing.cjs").RunTimingRecorder | undefined, materializationOwnerId?: string, nextReuseSandboxNumber?: (() => number) | undefined, groupPlugins?: readonly LinkedPluginLifecycle[], groupPluginContext?: GroupPluginContext | undefined);
|
|
51
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Registers only an awaiter in the outer Invocation Scope. The real stop is
|
|
62
|
+
* initiated by the Experiment lifecycle before its teardown; if the outer
|
|
63
|
+
* Scope closes first it joins the same single-flight result rather than
|
|
64
|
+
* repeating provider or plugin finalizers.
|
|
65
|
+
*/
|
|
52
66
|
managed(): Effect.Effect<this, never, Scope.Scope>;
|
|
67
|
+
/** Closes admission before the Experiment starts physical cleanup. */
|
|
68
|
+
freeze(): Effect.Effect<void>;
|
|
53
69
|
/**
|
|
54
70
|
* @param attemptDeadlineMs 这条 Attempt 实际生效的超时上限(解析链见 runner/timeout.ts)。
|
|
55
71
|
* `undefined` = 四层都没声明上限:请求的寿命只能覆盖收尾预留——Attempt 本身没有 deadline,
|
|
@@ -57,7 +73,8 @@ export declare class ReusableSandboxPool {
|
|
|
57
73
|
* 就是「不声明上限」的代价(两种时间的分界见 docs/feature/sandbox/reuse.md)。
|
|
58
74
|
*/
|
|
59
75
|
acquire(attemptDeadlineMs: number | undefined, buildLocators: ReadonlyMap<BuildKey, JsonValue>): Effect.Effect<ReusableSandboxLease, Error | import("../sandbox/runtime.cjs").SandboxRuntimeMaterializationError, Scope.Scope>;
|
|
60
|
-
stop(): Effect.Effect<void>;
|
|
76
|
+
stop(): Effect.Effect<void, unknown>;
|
|
77
|
+
private stopAll;
|
|
61
78
|
/** Drained by the scheduler after the lease Scope sealed the prior result. */
|
|
62
79
|
drainRuntimeFailures(): readonly ReusableSandboxPoolRuntimeFailure[];
|
|
63
80
|
private create;
|
|
@@ -67,4 +84,19 @@ export declare class ReusableSandboxPool {
|
|
|
67
84
|
private retire;
|
|
68
85
|
private wake;
|
|
69
86
|
private awaitWake;
|
|
87
|
+
/**
|
|
88
|
+
* A create/ensureLifetime failure can still run provider and Sandbox Scope
|
|
89
|
+
* finalizers. The entry is not yet in `entries`, so `stopAll()` cannot find
|
|
90
|
+
* it later; record a close failure now and replay it from the Experiment
|
|
91
|
+
* lifetime ledger instead of letting an `onError` cleanup failure vanish.
|
|
92
|
+
*/
|
|
93
|
+
private closeFailedCreateScope;
|
|
94
|
+
private recordCleanupFailure;
|
|
95
|
+
/**
|
|
96
|
+
* `materializeSandboxRunPlan` deliberately converts hook/provider cleanup
|
|
97
|
+
* failures into feedback and continues its Scope.close. Preserve that signal
|
|
98
|
+
* beside thrown Scope close failures, without changing the public Sandbox
|
|
99
|
+
* lifecycle API or its diagnostic-only finalizer contract.
|
|
100
|
+
*/
|
|
101
|
+
private lifecycleFeedback;
|
|
70
102
|
}
|
|
@@ -37,7 +37,16 @@ export declare class ReusableSandboxPool {
|
|
|
37
37
|
private readonly waiters;
|
|
38
38
|
private creating;
|
|
39
39
|
private stopped;
|
|
40
|
+
/** One physical stop operation owns every instance/finalizer exactly once. */
|
|
41
|
+
private stopCompletion;
|
|
40
42
|
private readonly runtimeFailures;
|
|
43
|
+
/**
|
|
44
|
+
* Whole-Experiment physical cleanup ledger. This is intentionally distinct
|
|
45
|
+
* from `runtimeFailures`: the latter is a per-Attempt diagnostic channel and
|
|
46
|
+
* is drained once that Attempt seals, whereas this collection is replayed by
|
|
47
|
+
* the terminal `stop()` even if an entry was retired long before then.
|
|
48
|
+
*/
|
|
49
|
+
private readonly cleanupFailures;
|
|
41
50
|
/** Provider 可观察的物理 owner;Group 池不能随首个未携入成员改用另一个 Eval ID。 */
|
|
42
51
|
private readonly materializationOwnerId;
|
|
43
52
|
/** 本次 Run 内的 Sandbox 编号计数器;淘汰的实例不让号,编号在结果里永远指向同一个实例。 */
|
|
@@ -48,8 +57,15 @@ export declare class ReusableSandboxPool {
|
|
|
48
57
|
constructor(plan: Extract<LinkedRunPlan, {
|
|
49
58
|
readonly _tag: "Sandbox";
|
|
50
59
|
}>, capacity: number, feedback: ScopedFeedback, setupContext: SandboxHookContext, runtimeServices?: SandboxRuntimeServices, agent?: SandboxAgent | undefined, runTiming?: import("./timing.mjs").RunTimingRecorder | undefined, materializationOwnerId?: string, nextReuseSandboxNumber?: (() => number) | undefined, groupPlugins?: readonly LinkedPluginLifecycle[], groupPluginContext?: GroupPluginContext | undefined);
|
|
51
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Registers only an awaiter in the outer Invocation Scope. The real stop is
|
|
62
|
+
* initiated by the Experiment lifecycle before its teardown; if the outer
|
|
63
|
+
* Scope closes first it joins the same single-flight result rather than
|
|
64
|
+
* repeating provider or plugin finalizers.
|
|
65
|
+
*/
|
|
52
66
|
managed(): Effect.Effect<this, never, Scope.Scope>;
|
|
67
|
+
/** Closes admission before the Experiment starts physical cleanup. */
|
|
68
|
+
freeze(): Effect.Effect<void>;
|
|
53
69
|
/**
|
|
54
70
|
* @param attemptDeadlineMs 这条 Attempt 实际生效的超时上限(解析链见 runner/timeout.ts)。
|
|
55
71
|
* `undefined` = 四层都没声明上限:请求的寿命只能覆盖收尾预留——Attempt 本身没有 deadline,
|
|
@@ -57,7 +73,8 @@ export declare class ReusableSandboxPool {
|
|
|
57
73
|
* 就是「不声明上限」的代价(两种时间的分界见 docs/feature/sandbox/reuse.md)。
|
|
58
74
|
*/
|
|
59
75
|
acquire(attemptDeadlineMs: number | undefined, buildLocators: ReadonlyMap<BuildKey, JsonValue>): Effect.Effect<ReusableSandboxLease, Error | import("../sandbox/runtime.mjs").SandboxRuntimeMaterializationError, Scope.Scope>;
|
|
60
|
-
stop(): Effect.Effect<void>;
|
|
76
|
+
stop(): Effect.Effect<void, unknown>;
|
|
77
|
+
private stopAll;
|
|
61
78
|
/** Drained by the scheduler after the lease Scope sealed the prior result. */
|
|
62
79
|
drainRuntimeFailures(): readonly ReusableSandboxPoolRuntimeFailure[];
|
|
63
80
|
private create;
|
|
@@ -67,4 +84,19 @@ export declare class ReusableSandboxPool {
|
|
|
67
84
|
private retire;
|
|
68
85
|
private wake;
|
|
69
86
|
private awaitWake;
|
|
87
|
+
/**
|
|
88
|
+
* A create/ensureLifetime failure can still run provider and Sandbox Scope
|
|
89
|
+
* finalizers. The entry is not yet in `entries`, so `stopAll()` cannot find
|
|
90
|
+
* it later; record a close failure now and replay it from the Experiment
|
|
91
|
+
* lifetime ledger instead of letting an `onError` cleanup failure vanish.
|
|
92
|
+
*/
|
|
93
|
+
private closeFailedCreateScope;
|
|
94
|
+
private recordCleanupFailure;
|
|
95
|
+
/**
|
|
96
|
+
* `materializeSandboxRunPlan` deliberately converts hook/provider cleanup
|
|
97
|
+
* failures into feedback and continues its Scope.close. Preserve that signal
|
|
98
|
+
* beside thrown Scope close failures, without changing the public Sandbox
|
|
99
|
+
* lifecycle API or its diagnostic-only finalizer contract.
|
|
100
|
+
*/
|
|
101
|
+
private lifecycleFeedback;
|
|
70
102
|
}
|