bugx-cli 0.1.0 → 0.1.1
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/README.md +190 -186
- package/core/README.md +2 -2
- package/core/agent/README.md +2 -1
- package/core/agent/agent_artifacts.py +8 -6
- package/core/agent/agent_eval.py +136 -54
- package/core/agent/agent_execution.py +218 -52
- package/core/agent/agent_orchestrator.py +14 -8
- package/core/agent/agent_targets.py +8 -2
- package/core/agent/feature_baseline.py +150 -0
- package/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
- package/core/assets/axe-core/LICENSE.txt +362 -0
- package/core/assets/axe-core/UPSTREAM.md +10 -0
- package/core/assets/axe-core/axe.min.js +12 -0
- package/core/assets/bugx-hero-en.svg +74 -0
- package/core/assets/bugx-hero-zh.svg +74 -0
- package/core/assets/codex.png +0 -0
- package/core/assets/dsh.png +0 -0
- package/core/assets/webui-chatgpt.jpg +0 -0
- package/core/assets/webui-session.jpg +0 -0
- package/core/assets/webui-skills.jpg +0 -0
- package/core/assets/webui-studio.jpg +0 -0
- package/core/assets/webui-zcode.jpg +0 -0
- package/core/assets/zcode.png +0 -0
- package/core/autonomous_cve/SPEC.md +1 -1
- package/core/autonomous_cve/attack_graph_store.py +152 -106
- package/core/autonomous_cve/behavior_graph.py +8 -2
- package/core/autonomous_cve/verifier.py +4 -1
- package/core/bugx.md +1 -1
- package/core/bugx_paths.py +43 -8
- package/core/cli-help.txt +66 -0
- package/core/cloud_sync/SPEC.md +1 -1
- package/core/cloud_sync/cloud_client.py +25 -6
- package/core/cloud_sync/cloud_onboard.py +42 -1
- package/core/cloud_sync/flywheel_client.py +16 -7
- package/core/cloud_sync/network_transport.py +24 -3
- package/core/cloud_sync/sensitive_filter.py +2 -2
- package/core/cloud_sync/sync_push.py +12 -10
- package/core/contracts/AGENT_GUIDE.md +6 -9
- package/core/contracts/README.md +2 -2
- package/core/contracts/bugx-runtime-contract.md +1 -1
- package/core/contracts/bugx-worker.md +1 -1
- package/core/contracts/engine_gap_contracts.py +86 -3
- package/core/coverage/coverage_discovery.py +599 -29
- package/core/coverage/coverage_evidence.py +47 -0
- package/core/coverage/coverage_forensics.py +9 -0
- package/core/coverage/coverage_validate.py +6 -1
- package/core/dev_harness/SPEC.md +1 -1
- package/core/engine-integrity.json +591 -419
- package/core/fuzzing/concurrency_fuzzer.py +53 -0
- package/core/fuzzing/differential_oracle.py +562 -27
- package/core/fuzzing/fuzz_input.py +109 -6
- package/core/fuzzing/stateful_fuzzer.py +72 -0
- package/core/governance/secret_redactor.py +22 -10
- package/core/host_acp/SPEC.md +1 -1
- package/core/host_acp/__init__.py +4 -4
- package/core/host_acp/claude.py +59 -1
- package/core/host_acp/cline.py +64 -1
- package/core/host_acp/codex.py +56 -1
- package/core/host_acp/dsh.py +59 -1
- package/core/host_acp/opencode.py +56 -1
- package/core/host_acp/pi.py +59 -1
- package/core/host_acp/zcode.py +59 -1
- package/core/host_runtime/SPEC.md +1 -1
- package/core/host_runtime/adapters.py +1 -1
- package/core/host_runtime/cline.py +13 -0
- package/core/host_runtime/host_evaluators.py +44 -4
- package/core/host_runtime/host_probe.py +1 -1
- package/core/host_runtime/host_provider_arbitrator.py +116 -62
- package/core/host_runtime/host_registry.py +15 -8
- package/core/host_runtime/mcp_registry_gate.py +12 -1
- package/core/host_runtime/pi.py +102 -0
- package/core/host_runtime/provider_facts.py +66 -0
- package/core/hosts/SPEC.md +1 -1
- package/core/hosts/__init__.py +6 -2
- package/core/hosts/_dsh_usage.py +1 -1
- package/core/hosts/base.py +32 -4
- package/core/hosts/claude.py +55 -0
- package/core/hosts/cline.py +6 -2
- package/core/hosts/codex.py +58 -0
- package/core/hosts/dsh.py +9 -1
- package/core/hosts/opencode.py +6 -6
- package/core/hosts/pi.py +159 -2
- package/core/infra/README.md +4 -2
- package/core/infra/__init__.py +2 -0
- package/core/infra/build_info.py +22 -3
- package/core/infra/client_metadata.py +1 -1
- package/core/infra/json_utils.py +22 -0
- package/core/launch_phases/README.md +2 -2
- package/core/launch_phases/SPEC.md +1 -1
- package/core/launch_phases/common.py +21 -2
- package/core/launch_phases/finding_confirm_phase.py +5 -1
- package/core/launch_phases/finding_settlement.py +188 -1
- package/core/launch_phases/judge_phase.py +69 -12
- package/core/launch_phases/orchestrator_controls.py +11 -7
- package/core/launch_phases/post_coverage_sync.py +9 -2
- package/core/launch_phases/post_phase.py +139 -3
- package/core/launch_phases/post_receipt.py +12 -1
- package/core/launch_phases/pre_phase.py +3 -3
- package/core/launch_phases/pre_recon_scout.py +53 -36
- package/core/launch_phases/pre_state_builder.py +23 -176
- package/core/launch_phases/round_orchestrator.py +15 -32
- package/core/launch_phases/session_runtime.py +56 -9
- package/core/launch_phases/startup_gates.py +36 -8
- package/core/launch_phases/startup_interaction.py +68 -12
- package/core/launch_phases/startup_version_gate.py +9 -3
- package/core/launch_phases/supervisor_bridge.py +46 -17
- package/core/launch_phases/supervisor_coverage.py +8 -2
- package/core/launch_phases/supervisor_degraded.py +1 -9
- package/core/launch_phases/worker_barriers.py +15 -5
- package/core/launch_phases/worker_orchestrator.py +105 -25
- package/core/ledger/README.md +1 -1
- package/core/ledger/SPEC.md +1 -1
- package/core/ledger/_facade.py +2 -1
- package/core/ledger/archive_ops.py +60 -2
- package/core/ledger/cli.py +6 -1
- package/core/ledger/export_ops.py +6 -1
- package/core/ledger/finding_confirmation.py +48 -6
- package/core/ledger/finding_lifecycle.py +428 -5
- package/core/ledger/finding_verification.py +44 -8
- package/core/ledger/incidents.py +10 -4
- package/core/ledger/patterns.py +10 -7
- package/core/ledger/receipt_contract.py +17 -1
- package/core/ledger/sync_ops.py +21 -16
- package/core/ledger/tool_experience.py +2 -1
- package/core/ledger/verify_life.py +88 -17
- package/core/locales/en-US.json +2 -2
- package/core/locales/zh-CN.json +2 -2
- package/core/mcp_handlers/SPEC.md +1 -1
- package/core/mcp_handlers/base.py +23 -3
- package/core/mcp_handlers/channel_lifecycle.py +85 -30
- package/core/mcp_handlers/retrieval_handlers.py +11 -1
- package/core/mcp_handlers/rpc_server.py +6 -1
- package/core/mcp_handlers/supervisor_handlers.py +32 -6
- package/core/mcp_handlers/tool_table.py +15 -0
- package/core/mcp_runtime_support/environment.py +0 -38
- package/core/mcp_runtime_support/verifier.py +0 -52
- package/core/metadata.txt +2 -3
- package/core/planning/README.md +1 -1
- package/core/planning/domain_router.py +4 -2
- package/core/planning/dynamic_flow_analyzer.py +219 -14
- package/core/planning/judge_pipeline.py +87 -4
- package/core/planning/prompt_harness.py +7 -5
- package/core/planning/spec_harvester.py +4 -4
- package/core/probes/INTERFACE.md +11 -1
- package/core/probes/SPEC.md +11 -1
- package/core/probes/__init__.py +46 -40
- package/core/probes/android_probe.py +177 -9
- package/core/probes/codebase_memory_probe.py +57 -0
- package/core/probes/desktop_probe.py +104 -0
- package/core/probes/differential_probe.py +99 -21
- package/core/probes/efficiency_probe.py +64 -0
- package/core/probes/ios_binary_probe.py +105 -1
- package/core/probes/memory_probe.py +66 -0
- package/core/probes/miniprogram_probe.py +75 -13
- package/core/probes/mobile_probe.py +215 -30
- package/core/probes/native_probe.py +88 -0
- package/core/probes/openwiki_probe.py +70 -0
- package/core/probes/pattern_probe.py +106 -0
- package/core/probes/platform_probe.py +81 -0
- package/core/probes/probe_registry.py +108 -7
- package/core/probes/sast_fixture_corpus.py +340 -0
- package/core/probes/sast_probe.py +553 -52
- package/core/probes/sast_rules.py +668 -28
- package/core/probes/sca_scanner.py +48 -0
- package/core/probes/ui_accessibility.py +149 -0
- package/core/probes/ui_audit.py +513 -0
- package/core/probes/ui_contract.py +273 -0
- package/core/probes/ui_evidence.py +212 -0
- package/core/probes/ui_measurements.py +314 -0
- package/core/probes/ui_repair.py +250 -0
- package/core/probes/ui_review.py +133 -0
- package/core/probes/ui_storybook.py +107 -0
- package/core/probes/ui_tokens.py +185 -0
- package/core/probes/ui_visual_diff.py +131 -0
- package/core/probes/web_probe.py +373 -18
- package/core/project_profiler/SPEC.md +1 -1
- package/core/project_profiler/arbitrator.py +6 -1
- package/core/project_profiler/detector.py +8 -1
- package/core/project_profiler/strategy.py +51 -15
- package/core/prompts/command_routing_en.md +2 -2
- package/core/prompts/command_routing_zh.md +2 -2
- package/core/prompts/stages/stage_repair.md +1 -1
- package/core/repair/README.md +1 -1
- package/core/repair/l7_repair_loop.py +1 -4
- package/core/repair/rsi_fixer.py +4 -4
- package/core/repair/rsi_loop.py +1 -3
- package/core/repair/rsi_repair.py +7 -7
- package/core/repair/rsi_scope.py +27 -8
- package/core/report_engine/SPEC.md +1 -1
- package/core/report_engine/attestation.py +8 -4
- package/core/report_engine/finding_report.py +2 -1
- package/core/report_engine/models.py +7 -9
- package/core/report_engine/sast_bridge.py +2 -2
- package/core/report_engine/server.py +18 -8
- package/core/report_engine/web-conformance.md +123 -18
- package/core/report_engine/web_conformance.py +21 -52
- package/core/retrieval/README.md +1 -1
- package/core/retrieval/SPEC.md +1 -1
- package/core/retrieval/code_analyzer.py +50 -14
- package/core/retrieval/context_assembler.py +7 -1
- package/core/retrieval/knowledge_sync.py +108 -14
- package/core/retrieval/symbol_index.py +25 -6
- package/core/retrieval/universal_code_matcher.py +234 -49
- package/core/runtime/README.md +1 -1
- package/core/runtime/bugx_logging.py +78 -7
- package/core/runtime/fixture_solidify.py +5 -10
- package/core/runtime/incident_eval.py +1 -1
- package/core/runtime/model_runner.py +4 -41
- package/core/runtime/platform_adapter.py +2 -2
- package/core/runtime/prep_validate.py +4 -2
- package/core/runtime/project_settings.py +2 -1
- package/core/runtime/scenario_eval.py +50 -8
- package/core/skills/bugx_docs_mcp_server.py +3 -1
- package/core/skills/bugx_mcp_server.py +29 -2
- package/core/skills/tools_kb.py +1 -1
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/SPEC.md +1 -1
- package/core/supervisor/budget_governor.py +503 -9
- package/core/supervisor/checkpoint_pipeline.py +248 -6
- package/core/supervisor/checkpoint_sync.py +13 -0
- package/core/supervisor/claim_events.py +1 -1
- package/core/supervisor/finding_workflow.py +22 -5
- package/core/supervisor/lease_manager.py +1 -1
- package/core/supervisor/lifecycle_blocks.py +6 -1
- package/core/supervisor/rejection_remedies.py +52 -5
- package/core/supervisor/serial_authorization.py +48 -4
- package/core/supervisor/task_scheduler.py +2 -2
- package/core/supervisor/worker_checkpoint.py +8 -1
- package/core/supervisor/worker_runtime.py +8 -2
- package/core/supervisor_types/worker_claim.py +9 -0
- package/core/webui/README.md +1 -1
- package/core/webui/SPEC.md +2 -1
- package/core/webui/adapters/claude.py +5 -1
- package/core/webui/adapters/cline.py +10 -2
- package/core/webui/adapters/codex.py +5 -1
- package/core/webui/adapters/dsh.py +5 -1
- package/core/webui/docs_session_service.py +2 -2
- package/core/webui/mcp_inspector.py +11 -7
- package/core/webui/static/00-base.css +1060 -0
- package/core/webui/static/01-monitoring.css +802 -0
- package/core/webui/static/02-header-actions.css +321 -0
- package/core/webui/static/03-trigger-popover.css +697 -0
- package/core/webui/static/04-composer.css +628 -0
- package/core/webui/static/05-skills-center.css +878 -0
- package/core/webui/static/06-mcp-center.css +623 -0
- package/core/webui/static/07-skill-detail.css +265 -0
- package/core/webui/static/08-files-management.css +167 -0
- package/core/webui/static/09-files-center.css +386 -0
- package/core/webui/static/10-icons.css +105 -0
- package/core/webui/static/11-project-options.css +185 -0
- package/core/webui/static/12-profile-tab.css +383 -0
- package/core/webui/static/design-tokens.css +113 -0
- package/core/webui/static/index.html +14 -1
- package/core/webui/workspace_service.py +1 -1
- package/docs/07_distribution/01_README_NPM.md +190 -186
- package/ecosystem/integrations/README.md +1 -1
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
- package/ecosystem/integrations/opencode/mcp-lock.json +14 -6
- package/ecosystem/integrations/opencode/opencode.json +23 -12
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/qoder/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
- package/interfaces/bin/bugx.js +37 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -2
- package/interfaces/cli/bugx_cli/cli.py +11 -4
- package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
- package/interfaces/cli/bugx_cli/commands/agent.py +339 -73
- package/interfaces/cli/bugx_cli/commands/audit.py +2 -2
- package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
- package/interfaces/cli/bugx_cli/commands/cloud.py +4 -3
- package/interfaces/cli/bugx_cli/commands/doctor.py +449 -204
- package/interfaces/cli/bugx_cli/commands/interaction.py +5 -1
- package/interfaces/cli/bugx_cli/commands/knowledge.py +2 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
- package/interfaces/cli/bugx_cli/commands/plugin.py +55 -20
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +7 -7
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +2 -1
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +1 -1
- package/interfaces/cli/bugx_cli/commands/report.py +2 -6
- package/interfaces/cli/bugx_cli/commands/system.py +11 -11
- package/interfaces/cli/bugx_cli/common.py +15 -7
- package/interfaces/cli/bugx_cli/host_adapters.py +29 -54
- package/interfaces/cli/bugx_cli/hosts/registry.py +8 -6
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +157 -27
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +18 -10
- package/interfaces/cli/bugx_cli/infra/host_sync.py +11 -8
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +76 -5
- package/interfaces/cli/bugx_cli/infra/security.py +13 -6
- package/package.json +2 -1
- package/pyproject.toml +20 -8
- package/scripts/ensure-python.mjs +7 -7
- package/scripts/sync-version.mjs +10 -21
- package/scripts/test-npm-wrapper.mjs +1 -1
- package/core/webui/static/project-settings.css +0 -6458
- package/docs/07_distribution/README.md +0 -16
- package/docs/README.md +0 -121
- package/interfaces/README.md +0 -143
- package/interfaces/bin/README.md +0 -35
- package/interfaces/cli/README.md +0 -90
- package/scripts/README.md +0 -118
|
@@ -2,6 +2,34 @@
|
|
|
2
2
|
"""core/supervisor/budget_governor.py - Supervisor 预算管控与并发协调服务 (DOC-070)。
|
|
3
3
|
|
|
4
4
|
负责轮次截止期、软硬预算监控、并发状态对齐、僵尸检测及预算耗尽状态转换。
|
|
5
|
+
|
|
6
|
+
恢复会话结算语义(2026-11-17 用户裁决,三维度):
|
|
7
|
+
|
|
8
|
+
* 维度 1【继承豁免】:expired claim 的单元若已 100% 沿链继承覆盖(清单行带
|
|
9
|
+
``inherited_from`` 备注且 ``coverage_discovery.resolve_inherited_evidence``
|
|
10
|
+
溯源可达祖先 passed 证据),该 claim 标记 ``superseded_by_inheritance``
|
|
11
|
+
并从并行门的 expired 重试债集合移除,不再重派;未覆盖单元才进入重派路径。
|
|
12
|
+
标记以 hash-chain 事件 ``expired_claim_superseded_by_inheritance`` 落账
|
|
13
|
+
(不改动 WorkerClaim 持久化 schema);豁免按当前清单状态**确定性重算**,
|
|
14
|
+
清单继承引用被内容失效撤回时重试债如实回归。
|
|
15
|
+
* 维度 2【恢复场景豁免】:并行门(require_parallel 的并发证明债)对恢复
|
|
16
|
+
会话豁免,三条件缺一不可(fail-closed):① owner_cancelled 死亡证明在
|
|
17
|
+
Supervisor 权威链(operation=lifecycle, gate=owner_cancelled);② 本 Life
|
|
18
|
+
covered 100% 来自继承+历史证据(判定口径:本 round 零新增证据记录,含
|
|
19
|
+
failed/error——OQ-2 加强,不只 passed);③ 本会话无新增 findings(owner
|
|
20
|
+
死亡锚点之后 findings 增量为 0)。豁免动作落专项留痕事件
|
|
21
|
+
``parallel_gate_inherited_closeout``(含三条件逐项快照);非 ``--final``
|
|
22
|
+
收口场景由 post 侧拒绝消费该豁免(D5)。
|
|
23
|
+
* 维度 3【合账语义(2026-11-17 用户裁决"新证据为准 + chain 保留")】:单元
|
|
24
|
+
证据分三层——L1 本轮重派本地记录 / L2 本 Life 历史本地记录 / L3 沿链继承
|
|
25
|
+
(清单行 ``inherited_from`` 备注 + ``resolve_inherited_evidence`` 溯源)。
|
|
26
|
+
判定读取优先级 L1/L2 本地最新 > L3 沿链(R-1,实现在
|
|
27
|
+
``coverage_discovery.inherited_unit_coverage_verdicts`` /
|
|
28
|
+
``recovery_closeout_coverage_census``):本函数消费 verdict 的 ``backing``
|
|
29
|
+
归属字段(supersede 快照可区分凭继承/凭本地证据豁免),维度 1 决策逻辑
|
|
30
|
+
不变——字面只有沿链继承豁免(OQ-1 有意的 fail-closed 浪费);清单行遗留
|
|
31
|
+
备注永不改写(R-3 chain 保留),本地新证据推翻继承时 divergence 随 census
|
|
32
|
+
快照显性化(R-5)。
|
|
5
33
|
"""
|
|
6
34
|
|
|
7
35
|
from __future__ import annotations
|
|
@@ -58,12 +86,62 @@ from core.supervisor.lease_manager import (
|
|
|
58
86
|
)
|
|
59
87
|
|
|
60
88
|
|
|
89
|
+
# ---------------------------------------------------------------------------
|
|
90
|
+
# 第四批缺陷修复(假并发门禁):并发证据只认**真实 worker**。
|
|
91
|
+
#
|
|
92
|
+
# 实证(2026-11-16 zcode 会话 supervisor.json):judge 判读取证电池的记账式
|
|
93
|
+
# claim(provider=judge-collect/judge-flow,core/launch_phases/judge_phase.py)
|
|
94
|
+
# process_pid=None、tokens_consumed=0、心跳零推进、同波 execution_finished_at
|
|
95
|
+
# 逐秒相同——它们是引擎判读取证的记账,不是 LLM worker;但重叠执行窗口曾被
|
|
96
|
+
# 并行门禁当作真实并发证据(parallel_history max_active=6/overlap 787s)。
|
|
97
|
+
#
|
|
98
|
+
# 真实性判据(三选二,与 provider 解耦——记账方未来换名也不失效):
|
|
99
|
+
# 1. process_pid 非空(真实进程被启动);
|
|
100
|
+
# 2. tokens_consumed > 0(LLM 用量被实测);
|
|
101
|
+
# 3. 心跳推进:last_heartbeat_at 晚于 execution_started_at
|
|
102
|
+
# (记账 claim 的 last_heartbeat_at 在 start_worker 时一次性写入,
|
|
103
|
+
# 与 started_at 同值,永不推进——实测字段特征)。
|
|
104
|
+
# ---------------------------------------------------------------------------
|
|
105
|
+
WORKER_AUTHENTICITY_MIN_SIGNALS = 2
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def worker_authenticity_signals(claim: WorkerClaim) -> int:
|
|
109
|
+
"""统计单条 claim 的真实 worker 证据数(0..3)。"""
|
|
110
|
+
signals = 0
|
|
111
|
+
if getattr(claim, "process_pid", None) is not None:
|
|
112
|
+
signals += 1
|
|
113
|
+
try:
|
|
114
|
+
if int(getattr(claim, "tokens_consumed", 0) or 0) > 0:
|
|
115
|
+
signals += 1
|
|
116
|
+
except (TypeError, ValueError):
|
|
117
|
+
pass
|
|
118
|
+
heartbeat_at = getattr(claim, "last_heartbeat_at", None)
|
|
119
|
+
started_at = getattr(claim, "execution_started_at", None)
|
|
120
|
+
if heartbeat_at is not None and (
|
|
121
|
+
started_at is None or float(heartbeat_at) > float(started_at)
|
|
122
|
+
):
|
|
123
|
+
signals += 1
|
|
124
|
+
return signals
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def is_authentic_worker_claim(claim: WorkerClaim) -> bool:
|
|
128
|
+
"""三选二:满足至少两项真实证据才算 LLM worker 的执行证据。"""
|
|
129
|
+
return worker_authenticity_signals(claim) >= WORKER_AUTHENTICITY_MIN_SIGNALS
|
|
130
|
+
|
|
131
|
+
|
|
61
132
|
def reconcile_parallel(state: RunState, now: float) -> None:
|
|
62
|
-
"""从持久化执行窗口重建本轮真实重叠,跨进程 resume 也不丢失。
|
|
133
|
+
"""从持久化执行窗口重建本轮真实重叠,跨进程 resume 也不丢失。
|
|
134
|
+
|
|
135
|
+
只有真实 worker(:func:`is_authentic_worker_claim`)的执行窗口才构成
|
|
136
|
+
并发证据;judge 记账式 claim 不再能把 ``round_max_active_workers`` /
|
|
137
|
+
``round_overlap_seconds`` 抬到假达标。
|
|
138
|
+
"""
|
|
63
139
|
intervals: list[tuple[float, float]] = []
|
|
64
140
|
for claim in state.claims.values():
|
|
65
141
|
if claim.round_no != state.round_no or claim.execution_started_at is None:
|
|
66
142
|
continue
|
|
143
|
+
if not is_authentic_worker_claim(claim):
|
|
144
|
+
continue
|
|
67
145
|
start = float(claim.execution_started_at)
|
|
68
146
|
if claim.execution_state == "running":
|
|
69
147
|
# B5:开区间右端必须夹到真实租约边界,否则僵尸 running claim 的
|
|
@@ -89,6 +167,7 @@ def reconcile_parallel(state: RunState, now: float) -> None:
|
|
|
89
167
|
active_count = 0
|
|
90
168
|
peak = sum(
|
|
91
169
|
claim.active and claim.execution_state == "running"
|
|
170
|
+
and is_authentic_worker_claim(claim)
|
|
92
171
|
for claim in state.claims.values()
|
|
93
172
|
if claim.round_no == state.round_no
|
|
94
173
|
)
|
|
@@ -103,6 +182,7 @@ def reconcile_parallel(state: RunState, now: float) -> None:
|
|
|
103
182
|
state.round_overlap_seconds = round(overlap, 6)
|
|
104
183
|
current_running = sum(
|
|
105
184
|
claim.active and claim.execution_state == "running"
|
|
185
|
+
and is_authentic_worker_claim(claim)
|
|
106
186
|
and claim.round_no == state.round_no
|
|
107
187
|
for claim in state.claims.values()
|
|
108
188
|
)
|
|
@@ -264,6 +344,319 @@ def parallel_required(state: RunState) -> bool:
|
|
|
264
344
|
)
|
|
265
345
|
|
|
266
346
|
|
|
347
|
+
# ---------------------------------------------------------------------------
|
|
348
|
+
# 恢复会话结算语义(2026-11-17 用户裁决,三维度;语义总纲见模块 docstring)。
|
|
349
|
+
#
|
|
350
|
+
# 门禁侧只做两件事:维度 1 把「单元已 100% 沿链继承覆盖」的 expired 重试债
|
|
351
|
+
# 标记 superseded_by_inheritance 并移出 expired 集合(不重派);维度 2 在
|
|
352
|
+
# 三条件全真时豁免 require_parallel 的并发证明债并落
|
|
353
|
+
# ``parallel_gate_inherited_closeout`` 留痕。fail-closed 红线:
|
|
354
|
+
# * 豁免三条件缺一即拒绝;
|
|
355
|
+
# * 伪造继承覆盖(清单行无 inherited_from 备注 / 沿链溯源失败)不得触发豁免;
|
|
356
|
+
# * 探针/清单/证据任何基础设施故障 → 一律维持原门禁(legacy 行为),
|
|
357
|
+
# 只在快照里留诊断字段,绝不借故障放宽。
|
|
358
|
+
#
|
|
359
|
+
# 定位注记:``parallel_gate_result`` 是无 root 的纯函数,而 manifest/证据文件
|
|
360
|
+
# 与 supervisor.json 同目录(life state 目录)。Supervisor 每次查询/变更都会
|
|
361
|
+
# 先经 :func:`refresh`(携带 workspace_root),这里用**有界**的 run_id→root
|
|
362
|
+
# 提示表把 root 带给门禁(进程内、键为 run_id、容量 32 FIFO 覆盖)。定位
|
|
363
|
+
# 失败/布局不符 → 返回 None → 门禁维持 legacy 行为,绝不猜测路径。
|
|
364
|
+
# ---------------------------------------------------------------------------
|
|
365
|
+
_GATE_WORKSPACE_ROOT_HINTS: dict[str, str] = {}
|
|
366
|
+
_GATE_WORKSPACE_ROOT_HINTS_MAX = 32
|
|
367
|
+
|
|
368
|
+
#: 项目布局 run_id 形态(``lifecycle-<polling_id>-<lifecycle_id>``)。
|
|
369
|
+
_LIFECYCLE_RUN_ID_RE = re.compile(r"^lifecycle-(polling-\d+)-(lifecycle-\d+)$")
|
|
370
|
+
|
|
371
|
+
#: 维度 2 豁免只针对 require_parallel 的并发证明债;串行合法性、active
|
|
372
|
+
#: worker、expired 重试债(维度 1 管辖)不在豁免范围。
|
|
373
|
+
_RECOVERY_PARALLEL_PROOF_REASONS = frozenset({
|
|
374
|
+
"parallel_peak_below_two",
|
|
375
|
+
"parallel_overlap_missing",
|
|
376
|
+
"parallel_workers_missing_checkpoint",
|
|
377
|
+
"bookkeeping_only_no_real_parallel",
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
_EXPIRE_SUPERSEDE_EVENT = "expired_claim_superseded_by_inheritance"
|
|
381
|
+
_CLOSEOUT_EXEMPT_EVENT = "parallel_gate_inherited_closeout"
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def _remember_gate_workspace_root(run_id: str, workspace_root: object) -> None:
|
|
385
|
+
"""记录 run_id → workspace_root 提示(有界 FIFO;仅供门禁定位 life 目录)。"""
|
|
386
|
+
if not run_id or workspace_root is None:
|
|
387
|
+
return
|
|
388
|
+
try:
|
|
389
|
+
resolved = str(Path(workspace_root).resolve())
|
|
390
|
+
except (OSError, ValueError, RuntimeError):
|
|
391
|
+
return
|
|
392
|
+
_GATE_WORKSPACE_ROOT_HINTS.pop(str(run_id), None)
|
|
393
|
+
_GATE_WORKSPACE_ROOT_HINTS[str(run_id)] = resolved
|
|
394
|
+
while len(_GATE_WORKSPACE_ROOT_HINTS) > _GATE_WORKSPACE_ROOT_HINTS_MAX:
|
|
395
|
+
oldest = next(iter(_GATE_WORKSPACE_ROOT_HINTS))
|
|
396
|
+
_GATE_WORKSPACE_ROOT_HINTS.pop(oldest, None)
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def _recovery_closeout_probe(state: RunState) -> dict[str, str] | None:
|
|
400
|
+
"""从 run_id + workspace_root 提示定位 life state 目录;失败返回 None。
|
|
401
|
+
|
|
402
|
+
只做路径解析与存在性检查(廉价 stat),不做任何清单解析——解析由
|
|
403
|
+
coverage_discovery 的只读 helper 在确有 expired 债/并行要求时才执行。
|
|
404
|
+
"""
|
|
405
|
+
run_id = str(getattr(state, "run_id", "") or "")
|
|
406
|
+
match = _LIFECYCLE_RUN_ID_RE.match(run_id)
|
|
407
|
+
if match is None:
|
|
408
|
+
return None
|
|
409
|
+
root = _GATE_WORKSPACE_ROOT_HINTS.get(run_id)
|
|
410
|
+
if not root:
|
|
411
|
+
return None
|
|
412
|
+
try:
|
|
413
|
+
import core.bugx_paths as bugx_paths
|
|
414
|
+
|
|
415
|
+
state_dir = (
|
|
416
|
+
bugx_paths.bugx_root(Path(root)) / "pollings"
|
|
417
|
+
/ match.group(1) / "lifecycles" / match.group(2) / "state"
|
|
418
|
+
)
|
|
419
|
+
except Exception: # noqa: BLE001 - 定位失败一律维持 legacy 门禁行为
|
|
420
|
+
return None
|
|
421
|
+
if not state_dir.is_dir():
|
|
422
|
+
return None
|
|
423
|
+
return {
|
|
424
|
+
"project_root": root,
|
|
425
|
+
"polling_id": match.group(1),
|
|
426
|
+
"lifecycle_id": match.group(2),
|
|
427
|
+
"manifest_path": str(state_dir / "module-coverage.md"),
|
|
428
|
+
"evidence_path": str(state_dir / "coverage-evidence.json"),
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def _owner_cancelled_chain_proof(state: RunState) -> tuple[bool, dict[str, object]]:
|
|
433
|
+
"""条件①:Supervisor 权威链在场 owner_cancelled 死亡证明(post 同口径)。
|
|
434
|
+
|
|
435
|
+
与 ``post_phase._supervisor_owner_cancelled_proof`` 第 3 步同源:
|
|
436
|
+
``operation=lifecycle`` / ``gate=owner_cancelled`` 的 lifecycle_blocked
|
|
437
|
+
事件。链身份绑定(lifecycle/run/session 代际)由 post 的接手门独立
|
|
438
|
+
fail-closed 把关,这里只认本 run 自己链上的死亡证明。
|
|
439
|
+
"""
|
|
440
|
+
last: dict[str, object] | None = None
|
|
441
|
+
for event in getattr(state, "history", []) or []:
|
|
442
|
+
if not isinstance(event, Mapping):
|
|
443
|
+
continue
|
|
444
|
+
if (
|
|
445
|
+
event.get("type") in {"lifecycle_blocked", "lifecycle_blocked_throttled"}
|
|
446
|
+
and event.get("operation") == "lifecycle"
|
|
447
|
+
and event.get("gate") == "owner_cancelled"
|
|
448
|
+
):
|
|
449
|
+
seq = event.get("seq")
|
|
450
|
+
order = seq if isinstance(seq, int) and not isinstance(seq, bool) else 0
|
|
451
|
+
last_seq = (
|
|
452
|
+
last.get("seq") if isinstance(last, dict) else None
|
|
453
|
+
)
|
|
454
|
+
last_order = (
|
|
455
|
+
last_seq if isinstance(last_seq, int) and not isinstance(last_seq, bool) else -1
|
|
456
|
+
)
|
|
457
|
+
if order >= last_order:
|
|
458
|
+
last = event
|
|
459
|
+
if last is None:
|
|
460
|
+
return False, {
|
|
461
|
+
"present": False,
|
|
462
|
+
"reason": "no owner_cancelled death proof in supervisor chain",
|
|
463
|
+
}
|
|
464
|
+
return True, {
|
|
465
|
+
"present": True,
|
|
466
|
+
"last_seq": last.get("seq"),
|
|
467
|
+
"last_at": last.get("at"),
|
|
468
|
+
"event_type": last.get("type"),
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def _findings_increment_since(
|
|
473
|
+
state: RunState, anchor_at: float | None,
|
|
474
|
+
) -> tuple[bool, dict[str, object]]:
|
|
475
|
+
"""条件③:owner 死亡锚点之后无新增 findings(found_total 增量为 0)。
|
|
476
|
+
|
|
477
|
+
会话归属口径:owner_cancelled 证明事件之后落账的 finding 只能来自
|
|
478
|
+
接手会话的新增挖掘(死亡进程不可能再产 finding),因此以「最后一条
|
|
479
|
+
owner_cancelled 的 at」为会话分界锚点。fail-closed:finding 无
|
|
480
|
+
``origin_receipt.sealed_at``(无法证明早于死亡)视为不可归属,同样
|
|
481
|
+
使条件③不成立——豁免宁可不做,不放行任何可能的新增挖掘。
|
|
482
|
+
"""
|
|
483
|
+
findings = getattr(state, "findings", []) or []
|
|
484
|
+
new_since_anchor = 0
|
|
485
|
+
unattributable = 0
|
|
486
|
+
new_worker_ids: set[str] = set()
|
|
487
|
+
if anchor_at is None:
|
|
488
|
+
return False, {
|
|
489
|
+
"anchor_at": None,
|
|
490
|
+
"total_findings": len(findings),
|
|
491
|
+
"new_since_anchor": 0,
|
|
492
|
+
"unattributable": len(findings),
|
|
493
|
+
"new_worker_ids": [],
|
|
494
|
+
"reason": "no owner_cancelled anchor (condition 1 failed)",
|
|
495
|
+
}
|
|
496
|
+
for item in findings:
|
|
497
|
+
receipt = item.get("origin_receipt") if isinstance(item, Mapping) else None
|
|
498
|
+
sealed_at = (
|
|
499
|
+
receipt.get("sealed_at") if isinstance(receipt, Mapping) else None
|
|
500
|
+
)
|
|
501
|
+
if isinstance(sealed_at, bool) or not isinstance(sealed_at, (int, float)):
|
|
502
|
+
unattributable += 1
|
|
503
|
+
continue
|
|
504
|
+
if float(sealed_at) > float(anchor_at):
|
|
505
|
+
new_since_anchor += 1
|
|
506
|
+
worker_id = receipt.get("worker_id") if isinstance(receipt, Mapping) else None
|
|
507
|
+
if worker_id:
|
|
508
|
+
new_worker_ids.add(str(worker_id))
|
|
509
|
+
return (
|
|
510
|
+
new_since_anchor == 0 and unattributable == 0,
|
|
511
|
+
{
|
|
512
|
+
"anchor_at": float(anchor_at),
|
|
513
|
+
"total_findings": len(findings),
|
|
514
|
+
"new_since_anchor": new_since_anchor,
|
|
515
|
+
"unattributable": unattributable,
|
|
516
|
+
"new_worker_ids": sorted(new_worker_ids),
|
|
517
|
+
},
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
def _has_gate_event(state: RunState, event_type: str, worker_id: str | None = None) -> bool:
|
|
522
|
+
"""幂等守卫:同类留痕事件在本 round 已在场则不重复落账。
|
|
523
|
+
|
|
524
|
+
history 有界裁剪可能移除旧事件,重放只产生语义相同的重复留痕,不影响
|
|
525
|
+
豁免/标记结论(结论按清单状态确定性重算,不依赖事件在场)。
|
|
526
|
+
"""
|
|
527
|
+
for event in getattr(state, "history", []) or []:
|
|
528
|
+
if not isinstance(event, Mapping) or event.get("type") != event_type:
|
|
529
|
+
continue
|
|
530
|
+
if event.get("round_no") != state.round_no:
|
|
531
|
+
continue
|
|
532
|
+
if worker_id is not None and event.get("worker_id") != worker_id:
|
|
533
|
+
continue
|
|
534
|
+
return True
|
|
535
|
+
return False
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
def _supersede_expired_claims_by_inheritance(
|
|
539
|
+
state: RunState,
|
|
540
|
+
expired_claims: list[WorkerClaim],
|
|
541
|
+
probe: dict[str, str],
|
|
542
|
+
now: float,
|
|
543
|
+
) -> tuple[list[WorkerClaim], dict[str, object]]:
|
|
544
|
+
"""维度 1:单元已 100% 沿链继承覆盖的 expired claim 移出重试债。
|
|
545
|
+
|
|
546
|
+
判定粒度是 claim(重派以 claim 任务包为单位):claim 的**全部**单元都
|
|
547
|
+
沿链继承覆盖才标记 superseded_by_inheritance;任一单元未覆盖/伪造/
|
|
548
|
+
溯源失败 → 整包保留在 expired 集合(进入重派路径)。标记 = hash-chain
|
|
549
|
+
事件(幂等守卫:同 round 同 worker 不重复落账)。
|
|
550
|
+
|
|
551
|
+
合账语义(R-1/R-6):verdict 由 coverage_discovery 按「本地最新记录 >
|
|
552
|
+
沿链继承」优先级解析并携带 ``backing`` 归属(local_round/local_historical/
|
|
553
|
+
local_overturns/inherited/unbacked);本函数决策逻辑不变——只有
|
|
554
|
+
``backing == "inherited"``(沿链继承)触发豁免,本地证据覆盖不触发
|
|
555
|
+
(OQ-1 字面 fail-closed);``backing``/``local_record`` 随 verdict 自然
|
|
556
|
+
进入 supersede 事件快照(F-4:快照更富,schema 不变)。
|
|
557
|
+
"""
|
|
558
|
+
scopes: list[str] = []
|
|
559
|
+
for claim in expired_claims:
|
|
560
|
+
for unit in claim.unit_ids:
|
|
561
|
+
scope = _UNIT_PREFIX_RE.sub("", str(unit)).strip()
|
|
562
|
+
if scope:
|
|
563
|
+
scopes.append(scope)
|
|
564
|
+
try:
|
|
565
|
+
from core.coverage.coverage_discovery import inherited_unit_coverage_verdicts
|
|
566
|
+
|
|
567
|
+
verdicts = inherited_unit_coverage_verdicts(
|
|
568
|
+
Path(probe["project_root"]), Path(probe["manifest_path"]), scopes,
|
|
569
|
+
evidence_path=Path(probe["evidence_path"]),
|
|
570
|
+
round_started_epoch=float(
|
|
571
|
+
getattr(state, "round_started_at", 0.0) or 0.0
|
|
572
|
+
),
|
|
573
|
+
)
|
|
574
|
+
except Exception as exc: # noqa: BLE001 - 探针故障 fail-closed:维持原债
|
|
575
|
+
return expired_claims, {
|
|
576
|
+
"available": False,
|
|
577
|
+
"reason": f"inheritance verdict unavailable: {type(exc).__name__}: {exc}"[:200],
|
|
578
|
+
}
|
|
579
|
+
kept: list[WorkerClaim] = []
|
|
580
|
+
superseded: dict[str, dict[str, object]] = {}
|
|
581
|
+
for claim in expired_claims:
|
|
582
|
+
unit_verdicts: list[dict[str, object]] = []
|
|
583
|
+
fully_inherited = bool(claim.unit_ids)
|
|
584
|
+
for unit in claim.unit_ids:
|
|
585
|
+
scope = _UNIT_PREFIX_RE.sub("", str(unit)).strip()
|
|
586
|
+
verdict = verdicts.get(scope) if scope else None
|
|
587
|
+
if verdict is None:
|
|
588
|
+
verdict = {
|
|
589
|
+
"inherited": False, "covered": False, "backing": "unbacked",
|
|
590
|
+
"reference": None, "chain": "",
|
|
591
|
+
"reason": f"unit scope 不可解析或不在请求集: {scope or unit}",
|
|
592
|
+
}
|
|
593
|
+
unit_verdicts.append({"unit": str(unit), **verdict})
|
|
594
|
+
if not verdict.get("inherited"):
|
|
595
|
+
fully_inherited = False
|
|
596
|
+
if fully_inherited:
|
|
597
|
+
superseded[claim.worker_id] = {
|
|
598
|
+
"worker_id": claim.worker_id,
|
|
599
|
+
"unit_ids": list(claim.unit_ids),
|
|
600
|
+
"attempt": claim.attempt,
|
|
601
|
+
"lease_id": claim.lease_id,
|
|
602
|
+
"verdicts": unit_verdicts,
|
|
603
|
+
}
|
|
604
|
+
else:
|
|
605
|
+
kept.append(claim)
|
|
606
|
+
for worker_id, snapshot in superseded.items():
|
|
607
|
+
if not _has_gate_event(state, _EXPIRE_SUPERSEDE_EVENT, worker_id):
|
|
608
|
+
append_event(
|
|
609
|
+
state, _EXPIRE_SUPERSEDE_EVENT, now,
|
|
610
|
+
round_no=state.round_no,
|
|
611
|
+
**snapshot,
|
|
612
|
+
)
|
|
613
|
+
return kept, {"available": True, "claims": superseded}
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
def _recovery_closeout_exemption(
|
|
617
|
+
state: RunState, now: float, probe: dict[str, str],
|
|
618
|
+
) -> dict[str, object]:
|
|
619
|
+
"""维度 2 三条件判定(fail-closed,逐条件快照供留痕事件与门禁快照)。"""
|
|
620
|
+
cancelled, cancelled_snapshot = _owner_cancelled_chain_proof(state)
|
|
621
|
+
anchor = (
|
|
622
|
+
cancelled_snapshot.get("last_at") if cancelled else None
|
|
623
|
+
)
|
|
624
|
+
anchor_at = anchor if isinstance(anchor, (int, float)) and not isinstance(anchor, bool) else None
|
|
625
|
+
findings_ok, findings_snapshot = _findings_increment_since(state, anchor_at)
|
|
626
|
+
try:
|
|
627
|
+
from core.coverage.coverage_discovery import recovery_closeout_coverage_census
|
|
628
|
+
|
|
629
|
+
census = recovery_closeout_coverage_census(
|
|
630
|
+
Path(probe["project_root"]),
|
|
631
|
+
Path(probe["manifest_path"]),
|
|
632
|
+
Path(probe["evidence_path"]),
|
|
633
|
+
float(getattr(state, "round_started_at", 0.0) or 0.0),
|
|
634
|
+
)
|
|
635
|
+
except Exception as exc: # noqa: BLE001 - 基础设施故障 fail-closed
|
|
636
|
+
census = {
|
|
637
|
+
"available": False,
|
|
638
|
+
"covered_all_inherited_or_historical": False,
|
|
639
|
+
"no_new_evidence_records_this_round": False,
|
|
640
|
+
"reason": f"{type(exc).__name__}: {exc}"[:200],
|
|
641
|
+
}
|
|
642
|
+
# 条件②为 OQ-2 加强口径:本轮零新增证据记录(含 failed/error)。
|
|
643
|
+
# 纯 failed 的重派轮不再误获豁免——任何新证据都证明存在真实挖掘/重派。
|
|
644
|
+
census_ok = bool(
|
|
645
|
+
census.get("covered_all_inherited_or_historical")
|
|
646
|
+
and census.get("no_new_evidence_records_this_round")
|
|
647
|
+
)
|
|
648
|
+
eligible = bool(cancelled and census_ok and findings_ok)
|
|
649
|
+
return {
|
|
650
|
+
"eligible": eligible,
|
|
651
|
+
"checked_at": now,
|
|
652
|
+
"conditions": {
|
|
653
|
+
"owner_cancelled_proof": cancelled_snapshot,
|
|
654
|
+
"coverage_census": census,
|
|
655
|
+
"findings_increment": findings_snapshot,
|
|
656
|
+
},
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
|
|
267
660
|
def parallel_gate_result(
|
|
268
661
|
state: RunState,
|
|
269
662
|
*,
|
|
@@ -293,10 +686,33 @@ def parallel_gate_result(
|
|
|
293
686
|
) > (previous.attempt, previous.claimed_at):
|
|
294
687
|
latest_by_unit[unit_id] = claim
|
|
295
688
|
|
|
296
|
-
expired
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
689
|
+
# 恢复结算维度 1(继承豁免):在把 expired 报成重试债之前,先检查每个
|
|
690
|
+
# expired claim 的单元是否已 100% 沿链继承覆盖(manifest 行带
|
|
691
|
+
# inherited_from 备注 + 溯源可达 passed)。全继承的 claim 标记
|
|
692
|
+
# superseded_by_inheritance(hash-chain 留痕)并移出 expired 集合,不再
|
|
693
|
+
# 重派;任一单元未覆盖/伪造/溯源失败 → 整包保留(进入重派路径)。
|
|
694
|
+
# 探针不可用(非项目布局 run_id / root 提示缺失)→ 维持 legacy 行为。
|
|
695
|
+
expired_by_worker: dict[str, WorkerClaim] = {}
|
|
696
|
+
for claim in latest_by_unit.values():
|
|
697
|
+
if claim.state == "expired":
|
|
698
|
+
expired_by_worker.setdefault(claim.worker_id, claim)
|
|
699
|
+
closeout_probe = _recovery_closeout_probe(state)
|
|
700
|
+
closeout_event_now = float(now) if now is not None else float(time.time())
|
|
701
|
+
superseded_block: dict[str, object] = {"available": False}
|
|
702
|
+
if closeout_probe is not None and expired_by_worker:
|
|
703
|
+
kept_claims, superseded_block = _supersede_expired_claims_by_inheritance(
|
|
704
|
+
state, list(expired_by_worker.values()), closeout_probe, closeout_event_now,
|
|
705
|
+
)
|
|
706
|
+
expired_by_worker = {claim.worker_id: claim for claim in kept_claims}
|
|
707
|
+
expired = sorted(expired_by_worker)
|
|
708
|
+
superseded_workers = sorted(
|
|
709
|
+
claim.get("worker_id")
|
|
710
|
+
for claim in (
|
|
711
|
+
superseded_block.get("claims", {}).values()
|
|
712
|
+
if isinstance(superseded_block.get("claims"), dict) else []
|
|
713
|
+
)
|
|
714
|
+
if isinstance(claim, Mapping) and claim.get("worker_id")
|
|
715
|
+
)
|
|
300
716
|
active = sorted(state.active_claims)
|
|
301
717
|
running = sorted(
|
|
302
718
|
claim.worker_id for claim in state.claims.values()
|
|
@@ -311,23 +727,34 @@ def parallel_gate_result(
|
|
|
311
727
|
# Do not trust the mutable summary counters alone. A real parallel proof
|
|
312
728
|
# needs two distinct workers that both completed a non-empty checkpoint,
|
|
313
729
|
# plus overlapping persisted execution windows.
|
|
730
|
+
# 第四批修复(假并发门禁):执行窗口与 checkpoint 进度只统计真实 worker
|
|
731
|
+
# (is_authentic_worker_claim 三选二)。judge 记账式 claim 的重叠窗口
|
|
732
|
+
# 单独留档——若"仅记账 claim 达标"必须如实 FAIL 并注明,绝不放行。
|
|
314
733
|
intervals: list[tuple[float, float]] = []
|
|
734
|
+
bookkeeping_intervals: list[tuple[float, float]] = []
|
|
735
|
+
bookkeeping_workers: set[str] = set()
|
|
315
736
|
observed_peak = sum(
|
|
316
737
|
1
|
|
317
738
|
for claim in state.claims.values()
|
|
318
739
|
if claim.round_no == state.round_no
|
|
319
740
|
and claim.active
|
|
320
741
|
and claim.execution_state == "running"
|
|
742
|
+
and is_authentic_worker_claim(claim)
|
|
321
743
|
)
|
|
322
744
|
progress_workers: list[str] = []
|
|
323
745
|
for claim in state.claims.values():
|
|
324
746
|
if claim.round_no != state.round_no or claim.execution_started_at is None:
|
|
325
747
|
continue
|
|
748
|
+
authentic = is_authentic_worker_claim(claim)
|
|
326
749
|
if claim.state == "submitted" and claim.submitted_at is not None:
|
|
327
750
|
end = claim.execution_finished_at or claim.submitted_at
|
|
328
751
|
if end > claim.execution_started_at:
|
|
329
|
-
intervals.append(
|
|
330
|
-
|
|
752
|
+
(intervals if authentic else bookkeeping_intervals).append(
|
|
753
|
+
(claim.execution_started_at, end)
|
|
754
|
+
)
|
|
755
|
+
if not authentic:
|
|
756
|
+
bookkeeping_workers.add(claim.worker_id)
|
|
757
|
+
if claim.last_checkpoint_digest and authentic:
|
|
331
758
|
progress_workers.append(claim.worker_id)
|
|
332
759
|
elif claim.active and claim.execution_state == "running":
|
|
333
760
|
# A lease expiry is a promise about the future, not evidence that
|
|
@@ -340,9 +767,17 @@ def parallel_gate_result(
|
|
|
340
767
|
else (claim.last_heartbeat_at or claim.execution_started_at)
|
|
341
768
|
)
|
|
342
769
|
if end > claim.execution_started_at:
|
|
343
|
-
intervals.append(
|
|
770
|
+
(intervals if authentic else bookkeeping_intervals).append(
|
|
771
|
+
(claim.execution_started_at, end)
|
|
772
|
+
)
|
|
773
|
+
if not authentic:
|
|
774
|
+
bookkeeping_workers.add(claim.worker_id)
|
|
344
775
|
elif claim.execution_finished_at is not None:
|
|
345
|
-
intervals.append(
|
|
776
|
+
(intervals if authentic else bookkeeping_intervals).append(
|
|
777
|
+
(claim.execution_started_at, claim.execution_finished_at)
|
|
778
|
+
)
|
|
779
|
+
if not authentic:
|
|
780
|
+
bookkeeping_workers.add(claim.worker_id)
|
|
346
781
|
observed_overlap = 0.0
|
|
347
782
|
points: dict[float, int] = {}
|
|
348
783
|
for start, end in intervals:
|
|
@@ -358,6 +793,18 @@ def parallel_gate_result(
|
|
|
358
793
|
if index + 1 < len(ordered_points) and current >= 2:
|
|
359
794
|
observed_overlap += ordered_points[index + 1] - point
|
|
360
795
|
progress_workers = sorted(set(progress_workers))
|
|
796
|
+
# 记账式 claim 的假并发峰值(仅用于如实标注 FAIL,不构成证据)。
|
|
797
|
+
bookkeeping_peak = 0
|
|
798
|
+
bk_points: dict[float, int] = {}
|
|
799
|
+
for start, end in bookkeeping_intervals:
|
|
800
|
+
if end <= start:
|
|
801
|
+
continue
|
|
802
|
+
bk_points[start] = bk_points.get(start, 0) + 1
|
|
803
|
+
bk_points[end] = bk_points.get(end, 0) - 1
|
|
804
|
+
bk_current = 0
|
|
805
|
+
for point in sorted(bk_points):
|
|
806
|
+
bk_current += bk_points[point]
|
|
807
|
+
bookkeeping_peak = max(bookkeeping_peak, bk_current)
|
|
361
808
|
required = parallel_required(state)
|
|
362
809
|
reasons: list[str] = []
|
|
363
810
|
if (
|
|
@@ -375,6 +822,38 @@ def parallel_gate_result(
|
|
|
375
822
|
reasons.append("parallel_overlap_missing")
|
|
376
823
|
if required and observed_peak >= 2 and len(progress_workers) < 2:
|
|
377
824
|
reasons.append("parallel_workers_missing_checkpoint")
|
|
825
|
+
if required and observed_peak < 2 and bookkeeping_peak >= 2:
|
|
826
|
+
# 第四批修复(假并发门禁):被真实性过滤后不足阈值,但记账式 claim
|
|
827
|
+
# 的重叠窗口本可"达标"——如实 FAIL 并注明仅记账 claim、无真实并发,
|
|
828
|
+
# 禁止假并发借记账窗口通过门禁(fail-closed 诚实化)。
|
|
829
|
+
reasons.append("bookkeeping_only_no_real_parallel")
|
|
830
|
+
# 恢复结算维度 2(恢复场景豁免):三条件全真(owner_cancelled 死亡证明
|
|
831
|
+
# 在权威链 + 本 Life covered 100% 继承/历史证据且本 round 零新增证据
|
|
832
|
+
# 记录(含 failed/error,OQ-2)+ owner 死亡锚点后零新增 findings)时,
|
|
833
|
+
# 豁免 require_parallel 的
|
|
834
|
+
# 并发证明债并落 ``parallel_gate_inherited_closeout`` 留痕(含三条件
|
|
835
|
+
# 逐项快照)。fail-closed:任一条件不成立/探针不可用 → 并行证明债原样
|
|
836
|
+
# 保留。串行合法性、active worker、expired 重试债(维度 1 管辖)不在
|
|
837
|
+
# 豁免范围;非 --final 收口由 post 侧拒绝消费该豁免(D5)。
|
|
838
|
+
closeout_exemption: dict[str, object] | None = None
|
|
839
|
+
if required and closeout_probe is not None:
|
|
840
|
+
closeout_exemption = _recovery_closeout_exemption(
|
|
841
|
+
state, closeout_event_now, closeout_probe,
|
|
842
|
+
)
|
|
843
|
+
suppressed = (
|
|
844
|
+
[r for r in reasons if r in _RECOVERY_PARALLEL_PROOF_REASONS]
|
|
845
|
+
if closeout_exemption.get("eligible") else []
|
|
846
|
+
)
|
|
847
|
+
closeout_exemption["suppressed_reasons"] = suppressed
|
|
848
|
+
if suppressed:
|
|
849
|
+
reasons = [r for r in reasons if r not in _RECOVERY_PARALLEL_PROOF_REASONS]
|
|
850
|
+
if not _has_gate_event(state, _CLOSEOUT_EXEMPT_EVENT):
|
|
851
|
+
append_event(
|
|
852
|
+
state, _CLOSEOUT_EXEMPT_EVENT, closeout_event_now,
|
|
853
|
+
round_no=state.round_no,
|
|
854
|
+
conditions=closeout_exemption.get("conditions"),
|
|
855
|
+
suppressed_reasons=list(suppressed),
|
|
856
|
+
)
|
|
378
857
|
return {
|
|
379
858
|
"round": state.round_no,
|
|
380
859
|
"required": required,
|
|
@@ -386,8 +865,16 @@ def parallel_gate_result(
|
|
|
386
865
|
"submitted_workers": submitted,
|
|
387
866
|
"progress_workers": progress_workers,
|
|
388
867
|
"expired_workers": sorted(expired),
|
|
868
|
+
# 恢复结算语义:维度 1 superseded 标记与维度 2 豁免快照(消费方:
|
|
869
|
+
# post 的 D5 守卫与结算留痕;无恢复语义时恒为 []/None)。
|
|
870
|
+
"expired_workers_superseded_by_inheritance": superseded_workers,
|
|
871
|
+
"recovery_closeout_exemption": closeout_exemption,
|
|
389
872
|
"serial_reason": state.budget.serial_reason,
|
|
390
873
|
"reasons": reasons,
|
|
874
|
+
# 第四批修复:并发证据的真实性口径留档(取证与回归用)。
|
|
875
|
+
"bookkeeping_claims_filtered": len(bookkeeping_workers),
|
|
876
|
+
"bookkeeping_workers": sorted(bookkeeping_workers),
|
|
877
|
+
"bookkeeping_only_peak": bookkeeping_peak,
|
|
391
878
|
}
|
|
392
879
|
|
|
393
880
|
|
|
@@ -590,6 +1077,13 @@ def refresh(
|
|
|
590
1077
|
workspace_root: Path | None = None,
|
|
591
1078
|
now_mono: float | None = None,
|
|
592
1079
|
) -> None:
|
|
1080
|
+
# 恢复结算门禁的 root 提示(有界 FIFO,见 _GATE_WORKSPACE_ROOT_HINTS):
|
|
1081
|
+
# parallel_gate_result 是无 root 纯函数,Supervisor 每次查询/变更都先经
|
|
1082
|
+
# 本函数(携带 workspace_root),在这里登记 run_id → root,门禁即可定位
|
|
1083
|
+
# life state 目录(manifest/证据文件与 supervisor.json 同目录)。
|
|
1084
|
+
_remember_gate_workspace_root(
|
|
1085
|
+
str(getattr(state, "run_id", "") or ""), workspace_root,
|
|
1086
|
+
)
|
|
593
1087
|
if now_mono is None:
|
|
594
1088
|
now_mono = time.monotonic()
|
|
595
1089
|
# D3:一次 refresh 内所有墙钟写入(事件时间戳、租约展示期、预算锚)
|