Skip to content

Optimize bilingual contracts and add runtime preflight - #41

Merged
GhostXia merged 3 commits into
mainfrom
codex/issue-40-contract-dedup
Aug 12, 2026
Merged

Optimize bilingual contracts and add runtime preflight#41
GhostXia merged 3 commits into
mainfrom
codex/issue-40-contract-dedup

Conversation

@GhostXia

@GhostXia GhostXia commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • add structurally aligned optimized English (E1) and Chinese (C1) Skill variants while leaving the release-default E0 and test C0 untouched
  • add a stateless installed-runtime preflight CLI that shares one deterministic dispatch decision with production start
  • validate baseline and optional revision syntax before any Luna spawn
  • document installed-runtime smoke checks and the boundary between protocol preflight, worktree scope checks, and OS sandboxing
  • harden repository validation so optimized variants remain smaller, semantically anchored, and structurally aligned

Runtime behavior

  • preflight: validates a JSON dispatch without creating state; intended for templates and installed-runtime checks
  • start: performs the same preflight and initializes guard state atomically; normal scheduling still uses one command, not preflight plus start
  • invalid contracts return exit 2 with stable invalid_dispatch, errors, destination, and dispatch fingerprint
  • malformed/duplicate case-insensitive JSON fields fail closed as invalid_input
  • BASELINE must be 40/64 lowercase Git hex
  • optional REVISION must equal BASELINE or be worktree-sha256:<64 lowercase hex>

Static contract reduction

Variant Characters Regex words Lines
E0 12,146 1,500 240
E1 10,713 1,296 128
C0 7,400 854 148
C1 6,363 772 128

E1 is 11.8% smaller than E0; C1 is 14.0% smaller than C0. E1/C1 have identical line-level Markdown structure signatures. English remains the release default.

Self-audit findings fixed

  • completed temporary-repository fixtures for all four variants instead of allowing missing optimized files
  • removed an overclaim that protocol preflight checks repository-local artifact directory state
  • unified preflight and start invalid-dispatch reason/errors/fingerprint through one decision function
  • extended conflicting-field tests to both entry points
  • strengthened structural alignment from line counts to line-by-line Markdown skeletons
  • restored explicit path/evidence/causality/severity/blocking/owner requirements for out-of-scope Terra findings

Validation

  • python -B -m unittest discover -s tests - 65 passed, 1 skipped on Windows
  • python -B scripts/validate_repo.py - passed
  • Skill Creator quick_validate.py - root, E1, and C1 passed
  • installed-copy schema and preflight smoke - passed
  • direct preflight/start fingerprint equality smoke - passed
  • git diff --check - passed
  • default root Skill remains byte-identical to skill-variants/en/SKILL.md

Remaining experimental work

Implementation, self-audit, deterministic tests, and the short-context E0/C0/E1/C1 matrix are complete. This PR adds E1/C1 as non-default candidates and does not change the release-default E0. The 100k+ E1/C1 comparison and complete raw-session evidence remain open in #40 and are required before any default switch.

Refs #40

Summary by CodeRabbit

  • New Features

    • Added a stateless preflight validation command for dispatch requests.
    • Added stricter revision identity checks and consistent validation before startup.
    • Added optimized English and Chinese skill variants.
  • Documentation

    • Updated English and Chinese guidance for installation, validation, preflight results, and experimental variants.
  • Tests

    • Expanded coverage for preflight behavior, revision validation, installed usage, and optimized skill consistency.
  • Experiments

    • Added evaluation prompts, test results, mappings, manifests, and a summary report.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: df623ca3-8dfd-4c7f-ba67-49d5c31873d6

📥 Commits

Reviewing files that changed from the base of the PR and between 242d4e7 and cee66e8.

📒 Files selected for processing (42)
  • .agents/skills/lean-dev-router/scripts/runtime_guard.py
  • README.md
  • docs/zh-CN/README.md
  • experiments/issue-40-cli/blind/bundle.json
  • experiments/issue-40-cli/blind/judge-result.json
  • experiments/issue-40-cli/blind/mapping.json
  • experiments/issue-40-cli/manifest.json
  • experiments/issue-40-cli/prompt_C0_en_r1.txt
  • experiments/issue-40-cli/prompt_C0_en_r2.txt
  • experiments/issue-40-cli/prompt_C0_en_r3.txt
  • experiments/issue-40-cli/prompt_C0_zh_r1.txt
  • experiments/issue-40-cli/prompt_C0_zh_r2.txt
  • experiments/issue-40-cli/prompt_C0_zh_r3.txt
  • experiments/issue-40-cli/prompt_C1_en_r1.txt
  • experiments/issue-40-cli/prompt_C1_en_r2.txt
  • experiments/issue-40-cli/prompt_C1_en_r3.txt
  • experiments/issue-40-cli/prompt_C1_zh_r1.txt
  • experiments/issue-40-cli/prompt_C1_zh_r2.txt
  • experiments/issue-40-cli/prompt_C1_zh_r3.txt
  • experiments/issue-40-cli/prompt_E0_en_r1.txt
  • experiments/issue-40-cli/prompt_E0_en_r2.txt
  • experiments/issue-40-cli/prompt_E0_en_r3.txt
  • experiments/issue-40-cli/prompt_E0_zh_r1.txt
  • experiments/issue-40-cli/prompt_E0_zh_r2.txt
  • experiments/issue-40-cli/prompt_E0_zh_r3.txt
  • experiments/issue-40-cli/prompt_E1_en_r1.txt
  • experiments/issue-40-cli/prompt_E1_en_r2.txt
  • experiments/issue-40-cli/prompt_E1_en_r3.txt
  • experiments/issue-40-cli/prompt_E1_zh_r1.txt
  • experiments/issue-40-cli/prompt_E1_zh_r2.txt
  • experiments/issue-40-cli/prompt_E1_zh_r3.txt
  • experiments/issue-40-cli/results.json
  • experiments/issue-40-short-test-pilot.json
  • experiments/issue-40-short-test-report.md
  • experiments/issue-40-task-packets/en.md
  • experiments/issue-40-task-packets/zh.md
  • experiments/run_issue40_short_test_cli.py
  • scripts/validate_repo.py
  • skill-variants/en-optimized/SKILL.md
  • skill-variants/zhcn-optimized/SKILL.md
  • tests/test_runtime_guard.py
  • tests/test_validate_repo.py

📝 Walkthrough

Walkthrough

The pull request adds deterministic revision and dispatch preflight validation, integrates preflight into start, validates optimized English and Chinese Skills, updates documentation, and adds Issue 40 routing-evaluation prompts, runners, results, and reports.

Changes

Runtime preflight and Skill validation

Layer / File(s) Summary
Dispatch preflight and start gating
.agents/skills/lean-dev-router/scripts/runtime_guard.py, tests/test_runtime_guard.py
The guard validates Git baselines and revision identities, exposes a stateless preflight command, and prevents invalid start requests from creating state.
Optimized Skill contracts and validation
skill-variants/*/SKILL.md, scripts/validate_repo.py, tests/test_validate_repo.py
Optimized Skills define the routing and runtime protocol. Repository validation checks required content, Markdown structure, size limits, and preflight symbols.
Runtime installation and usage documentation
README.md, docs/zh-CN/README.md
Documentation describes atomic start behavior, stateless preflight, installed-runtime checks, and experimental Skill variants.

Issue 40 routing evaluation

Layer / File(s) Summary
Routing evaluation inputs and runner
experiments/issue-40-task-packets/*, experiments/issue-40-cli/prompt_*.txt, experiments/run_issue40_short_test_cli.py
Task packets and prompts define eight routing scenarios with strict JSON outputs. The runner executes the variant, language, and repetition matrix and records logs and manifests.
Evaluation results and report
experiments/issue-40-short-test-pilot.json, experiments/issue-40-cli/*, experiments/issue-40-short-test-report.md
The added datasets record pilot outputs, blind mappings, run metadata, judgments, and experiment findings.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Evaluator
  participant run_issue40_short_test_cli.py
  participant Codex
  participant ExperimentManifest
  Evaluator->>run_issue40_short_test_cli.py: select matrix and worker count
  run_issue40_short_test_cli.py->>Codex: execute read-only routing prompt
  Codex-->>run_issue40_short_test_cli.py: output, session ID, and status
  run_issue40_short_test_cli.py->>ExperimentManifest: write run metadata and logs
Loading

Possibly related issues

  • Issue 40: The pull request adds the deterministic preflight work, installed-runtime checks, optimized Skill variants, and routing evaluation assets described by the issue.

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/issue-40-contract-dedup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@GhostXia

Copy link
Copy Markdown
Owner Author

Issue #40 短程测试结果(实验门禁,PR #41

1. 实验设置

  • 变体:E0(英文基线)、C0(中文基线)、E1(英文去重)、C1(中文去重)。
  • 控制指标:完整读取 Skill 之后的首次模型调用输入 token。所有有效样本恰好 2 个 token_count 事件(首轮消息 + 读 Skill 后的回答)。
  • 两批数据:
    • Pilot 批:14 次有效运行,模型 gpt-5.6-sol(原线程子代理,原始加密任务包;原始提示词文本不可恢复)。数据:issue-40-short-test-pilot.json
    • CLI 控制批:24 次有效运行(4 变体 × 英/中任务包 × 3 次),模型 deepseek-v4-flash、reasoning effort max,全部为全新 codex exec 会话;提示词模板、24 份提示词、日志、session id 均入库。这是当前受控矩阵。

可复现材料:

2. CLI 控制批 token 结果(读 Skill 后首次调用,每格中位数)

变体 语言 输入中位数 缓存输入中位数 未缓存输入中位数 输出中位数 reasoning 中位数 n
E0 en 22975 19712 3263 6530 5232 3
E0 zh 23065 19712 3261 13691 12165 3
E1 en 22324 19712 2612 15301 13995 3
E1 zh 22289 19712 2577 10908 9151 3
C0 en 23169 19712 3457 6565 4780 3
C0 zh 23187 19712 3475 6731 5174 3
C1 en 22482 19712 2733 8077 6682 3
C1 zh 22666 19968 2745 9095 7370 3

3. 效应分解(CLI 控制批,输入 token 中位数差异)

效应 对比 en 差值 zh 差值
语言基线 C0 − E0 +194 +122
英文去重 E1 − E0 −651 −776
中文去重 C1 − C0 −687 −521
优化后语言 C1 − E1 +158 +377
组合 C1 − E0 −493 −399

未缓存输入(Skill 内容新增 token)同样显示去重收益:E1 比 E0 少约 650–690,C1 比 C0 少约 720–730;优化后中文仍比优化后英文多约 120–170。

4. 质量门

  • 结构校验:24/24 样本均为合法 JSON,8 个场景字段完整。
  • 关键词门:24/24 通过(唯一“未命中”是 cli_C0_en_r3 第 7 场景用 scope 表述而非字面 PATHS_ALLOW,语义正确)。
  • 盲审:匿名会话(不泄露变体/语言标签)对 24 个样本打分,全部 10/10/10,零实质语义错误。结果:judge-result.json
  • Pilot 批:14/14 行为正确。

5. 短程结论

  • E1 最优:英文包 22324、中文包 22289,均为四者最低。
  • C1 次之:显著优于自己的基线 C0(约省 520–690 token),但仍比 E1 多约 160–380 token。
  • 质量四者打平(盲审满分),因此按输入 token 排序:E1 < C1 < E0 < C0
  • 短程数据不支持切换中文默认;默认语言决定仍须等 100k+ 测试。

6. 尚未完成

@GhostXia
GhostXia marked this pull request as ready for review August 12, 2026 11:29
@GhostXia
GhostXia merged commit 3f7d19e into main Aug 12, 2026
1 of 2 checks passed
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