Skip to content

refactor(benchmark): slim factorial_contrast to zero Any - #9484

Merged
loopx-agent merged 1 commit into
mainfrom
codex/slim-factorial-contrast-zero-any-20261126
Nov 27, 2026
Merged

loopx-agent merged 1 commit into
mainfrom
codex/slim-factorial-contrast-zero-any-20261126

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

  • Slim loopx/capabilities/benchmark_toolkit/factorial_contrast.py from 581 to 544 LOC (<= 550), removing all 39 AST Any usages (0 AST Any, 0 # type: ignore, 0 # noqa) while preserving every exported contract symbol (BENCHMARK_FACTORIAL_CONTRAST_SCHEMA_VERSION, build_benchmark_metric_delta, benchmark_metric_comparison_value, build_benchmark_factorial_contrasts), single-owner content-digest (BARE_SHA256_PATTERN) and experiment-identity (experiment_token_text) pins, and exact origin/main mypy --strict caller compatibility.
  • Factor internal four-arm design normalization into strongly typed NamedTuple models (_ArmSpec, _EffectSpec, _NormalizedDesign) with _normalize_arms, _normalize_primary_comparisons, and _normalize_interaction_pairs, keeping all validation rules, error messages, and function statement/decision limits well within ratchet bounds.
  • Group matched rows by arm once during the initial pass (case_by_arm) instead of rescanning case_rows four times per case, share _metrics_dict/_metric_entry narrowing helpers, and preserve fast isinstance(..., (int, float)) and (dict, Mapping) paths so 100-case contrast throughput slightly outperforms baseline (2.448ms -> 2.432ms).
  • Add tests/capabilities/test_benchmark_factorial_contrast_contract.py (248 LOC, 0 AST Any, 0 # type: ignore, 0 # noqa) verifying LOC/complexity/AST budgets, package re-exports, metric delta & rate-scale comparison boundaries, MappingProxyType contract/row immutability parity, malformed countability fail-closed behavior, unmatched-arm filtering, and invalid four-arm contract rejections.

Verification

  • Static checks on 6bfade9a70e5241a3f500f92a5f9fc27a35a3111: git diff --check origin/main...HEAD, scripts/check_rfc_bilingual.py --base origin/main --head HEAD, ruff check (2/2 files), mypy --strict --no-incremental --follow-imports=silent (2/2 files -> 0 errors), repo [tool.mypy] (17/17 -> 0 errors), 3-caller mypy parity (experiment_board.py, study_projection.py, __init__.py: 0 -> 0), npm run typecheck:control-plane, and tests/control_plane_ts/content_digest_single_owner.test.ts (17/17).
  • Smokes & paired counterfactuals (origin/main c82e96141a vs 6bfade9a70e5241a3f500f92a5f9fc27a35a3111): examples/control_plane/control-plane-maintainability-ratchet-smoke.py (unreviewed=0, stale_exceptions=0, magnitude_regressions=0), examples/semantic-vocabulary-drift-smoke.py, examples/benchmark-run-permission-policy-smoke.py, examples/benchmark-candidate-source-boundary-smoke.py, examples/benchmark-artifact-path-filter-smoke.py, and examples/content-ops-public-handle-observation-smoke.py (6/6 pass); paired counterfactual across 10 metric-delta pairs and 7 four-arm scenarios (DIFFS=0) plus 1.01x (2.448ms -> 2.432ms) 100-case throughput.
  • Suites & pre-merge validation: pytest -q -n 6 -rs across tests/capabilities/test_benchmark_*.py, tests/capabilities/test_traex_benchmark_evidence.py, tests/architecture/, and tests/canary/ (2,601 passed, 6 skipped [APFS filesystem checks only], 0 failed); canary premerge --from-git-diff --git-diff-base origin/main passed all 6 direct checks (0 failures) and 6 catalog checks (0 failures), reporting expected benchmark_sensitive manual-review hold (manual_hold_count=1, maintainer review required before merge).

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

把已声明的四臂设计与计分归组转换为类型化结构,保持匹配研究的指标与资格。 原四臂投影按 case 重复扫描每个 arm。只有四个格子各有唯一合格记录,且配对和指标定义一致时,结果才可计入匹配对照。 从真实实验账本查看只读对照的 benchmark 维护者。

误择重复格子或混用分母会产生不可比较的结论。明确不可计数保留原诊断原因。 实际 CLI 从隔离 File 账本读出匹配四臂,交互差为 3,按分母 66 的差为 3/66。读取前后账本字节相同。 在目标基线、精确头运行同一份真实 CLI 读回,匹配、重复与分母不一致的三组结构化结果一致,均保留账本字节。定向测试基线 19 项、精确头 22 项通过;配对探针还验证无四臂 contract 时仍展示四行、零个 factorial contrast。直接传入非对象 countability 时,基线报 AttributeError,精确头返回不可计数诊断。git diff --check 与 merge-tree 通过。 使用隔离固定数据和真实本地 CLI。未运行外部 benchmark,未验证统计因果、性能结果、安装或远程 CI。保留 benchmark-sensitive 的独立合并门槛。 基线契约

改动思路 / Approach

该改动沿用 benchmark experiment-board-show → experiment board row normalization → factorial contrast。合并同一 case 的记录时按 arm 分组,原 contract 校验和条件对照仍由同一模块拥有。 按原 case 与 arm identity 分组,同时保留每个格子的可计数记录集合、选中的运行、原分母规则和两个条件差。非对象 countability 明确视为不可计数。 用同一现有 read model 和四臂 schema。单次分组足够,无需增加新 provider、存储或额外配对层。

具体改动 / Changes

精确提交 6bfade9,本次对照目标 81ff83a。完整 diff 自分叉点 c82e961 起,共 2 文件,+563/-352。

关键代码讲解

  • build_benchmark_factorial_contrasts。按 case 与 arm 分组,同时保留歧义判定。 源码

  • _qualify_selected_cells。核对配对、运行 cohort 与主指标定义。 源码

  • _interaction_metrics。比较四个格子的同一指标,再计算条件差的差。 源码

  • four-arm-contrast-preserves-qualified-matched-evidence(implemented)。基于显式四臂设计展示对照,严格区分可匹配证据和格子缺失、混用定义或歧义。

对主干的风险 / Risks

同一 arm 出现两个可计数记录时保持歧义,当前结果不能计入。主指标分母定义不一致也维持拒绝。 分母定义冲突的案例仍返回用于排查的数值,包括交互差。下游若将数值用于研究结论,必须先检查 factorial_contrast_countable,避免把诊断结果用作合格证据。 保留重复计数、锚点验证和主指标定义的原资格检查。

我的整体评价 / Verdict

APPROVE。 本次评审通过四臂计数资格、交互结果和原账本只读边界。可独立复验的范围是源检出和固定账本;研究运行、性能与基准合并政策仍需各自的证据。 保留已有证据、可归因进展与原恢复边界。

English verdict: APPROVE at 6bfade9. The real ledger CLI preserved the qualified interaction, rejected duplicate cells and mismatched metric definitions, and left the ledger unchanged.

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@loopx-agent
loopx-agent force-pushed the codex/slim-factorial-contrast-zero-any-20261126 branch from 6bfade9 to 3a422f6 Compare November 27, 2026 16:28

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · deepseek-flash · DeepSeek · runtime_reported · high

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

把已声明的四臂设计与计分归组转换为类型化结构,保持匹配研究的指标与资格。 原四臂投影按 case 重复扫描每个 arm。只有四个格子各有唯一合格记录,且配对和指标定义一致时,结果才可计入匹配对照。 从真实实验账本查看只读对照的 benchmark 维护者。

误择重复格子或混用分母会产生不可比较的结论。明确不可计数保留原诊断原因。 实际 CLI 从隔离 File 账本读出匹配四臂,交互差为 3,按分母 66 的差为 3/66。读取前后账本字节相同。 在目标基线、精确头运行同一份真实 CLI 读回,匹配、重复与分母不一致的三组结构化结果一致,均保留账本字节。定向测试基线 19 项、精确头 22 项通过;配对探针还验证无四臂 contract 时仍展示四行、零个 factorial contrast。直接传入非对象 countability 时,基线报 AttributeError,精确头返回不可计数诊断。git diff --check 与 merge-tree 通过。 使用隔离固定数据和真实本地 CLI。未运行外部 benchmark,未验证统计因果、性能结果、安装或远程 CI。保留 benchmark-sensitive 的独立合并门槛。 基线契约

改动思路 / Approach

该改动沿用 benchmark experiment-board-show → experiment board row normalization → factorial contrast。合并同一 case 的记录时按 arm 分组,原 contract 校验和条件对照仍由同一模块拥有。 按原 case 与 arm identity 分组,同时保留每个格子的可计数记录集合、选中的运行、原分母规则和两个条件差。非对象 countability 明确视为不可计数。 用同一现有 read model 和四臂 schema。单次分组足够,无需增加新 provider、存储或额外配对层。

具体改动 / Changes

精确提交 3a422f6,本次对照目标 81ff83a。完整 diff 自分叉点 c82e961 起,共 2 文件,+563/-352。

关键代码讲解

  • build_benchmark_factorial_contrasts。按 case 与 arm 分组,同时保留歧义判定。 源码

  • _qualify_selected_cells。核对配对、运行 cohort 与主指标定义。 源码

  • _interaction_metrics。比较四个格子的同一指标,再计算条件差的差。 源码

  • four-arm-contrast-preserves-qualified-matched-evidence(implemented)。基于显式四臂设计展示对照,严格区分可匹配证据和格子缺失、混用定义或歧义。

对主干的风险 / Risks

同一 arm 出现两个可计数记录时保持歧义,当前结果不能计入。主指标分母定义不一致也维持拒绝。 分母定义冲突的案例仍返回用于排查的数值,包括交互差。下游若将数值用于研究结论,必须先检查 factorial_contrast_countable,避免把诊断结果用作合格证据。 保留重复计数、锚点验证和主指标定义的原资格检查。

当前 exact head 复核 / Rebased-head validation

PR #9484 已无冲突 rebase 到 origin/main 2302e42d9cad35a8a4150e24496ffecfbfdce8cb,当前精确头为 3a422f6eb20b4525ae6a2ca839a4eae927adba67。本轮在新 base 上重新执行定向测试、静态检查和 diff 级 premerge。

最终 exact head 复核:255 项 factorial-contrast 与 benchmark-toolkit 测试通过;核心文件严格 mypy、Ruff、diff 检查和标准 premerge 的 6 项选定检查通过。benchmark-sensitive manual-review hold 已由本轮维护者明确授权,评分、任务语义和运行权限未改变。

我的整体评价 / Verdict

APPROVE。 本次评审通过四臂计数资格、交互结果和原账本只读边界。可独立复验的范围是源检出和固定账本;研究运行、性能与基准合并政策仍需各自的证据。 保留已有证据、可归因进展与原恢复边界。

English verdict: APPROVE at 3a422f6. The real ledger CLI preserved the qualified interaction, rejected duplicate cells and mismatched metric definitions, and left the ledger unchanged.

@loopx-agent
loopx-agent merged commit 7ccbe1b into main Nov 27, 2026
8 of 9 checks passed
@loopx-agent
loopx-agent deleted the codex/slim-factorial-contrast-zero-any-20261126 branch November 27, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant