Skip to content

4.13-B: runtime bundle rewrite + handoff semantic fix + test cleanup#38

Merged
Li-Sanze merged 25 commits into
mainfrom
plan/runtime-slimming-kernel-extraction
May 24, 2026
Merged

4.13-B: runtime bundle rewrite + handoff semantic fix + test cleanup#38
Li-Sanze merged 25 commits into
mainfrom
plan/runtime-slimming-kernel-extraction

Conversation

@Li-Sanze
Copy link
Copy Markdown
Collaborator

变更摘要

三项核心变更

  1. runtime_bundle.py 重写 — 从 subprocess shell-out (sync-runtime-assets.sh) 改为纯 Python (shutil.copytree + write_bundle_manifest),删除 sync-runtime-assets.sh
  2. handoff.py 语义修复 — 当 skill_result 有 tradeoff candidates 但无 checkpoint_request 时,显式写 checkpoint_request_reason_code / checkpoint_request_error
  3. 测试清理 — 删除 34 个退役测试块 (decision/clarification bridge, develop callback/quality, run_plan_loop, go_plan_runtime, plan_orchestrator)

配套变更

  • tests/runtime_test_support.py: 补回 match_decision_policy / build_strategy_pick_template 导入
  • .githooks/pre-commit: 移除已删 sync-runtime-assets.sh
  • CONTRIBUTING.md: 更新 bundle sync 命令
  • 方案包 design.md / tasks.md: 4.13-B 状态更新

验证

  • python3 -m pytest -q619 passed, 49 subtests passed
  • 无孤引用、无假红、无回归

已知遗留 (非本 PR 引入)

  • pre-commit hook 的 bundle smoke check 在 HEAD (改前) 就已 fail (sopify.json 未被 runtime 写出),后续单独修

Li-Sanze added 25 commits May 22, 2026 16:29
新增方案包 20260522_runtime_slimming_kernel_extraction:

- 定位:protocol-first + validator-centered + lightweight kernel
- 在 runtime/ 原地瘦身,保留 gate/route/handoff/checkpoint 最小编排核
- 5 条实施红线:不新开实现线、不新增 machine truth、不承接 UX 外围、
  不保留全功能 engine、不改主协议语义
- 执行顺序:解耦 5 文件 → 提取 kernel → 删非 kernel 面 → 验证 → README 对齐
- 同步更新 blueprint/design.md 维护决策表述
- 同步更新 _registry.yaml 和 blueprint/README.md 指向
S3 outputs written to plan package:
- Kernel core (7 modules): gate/entry_guard/execution_gate/router/handoff/checkpoint_request/checkpoint_materializer
- Kernel support (3): config/state/deterministic_guard
- Priority split target: context_snapshot.py (extract minimal snapshot, delete rest)
- Non-kernel: gate_output.py (text rendering), models.py (delete DEPRECATED)
- Host-facing entry responsibilities: 3 new thin shells, old scripts retire
- Test coverage: 6 preserve equivalent coverage, 2 co-delete
- 14 non-kernel runtime deps mapped for S4 cutoff
- LOC target relaxed: direction not hard constraint, avoid second architecture redesign
… corrections

S3 full completion:
- Table 1: kernel first circle (7 modules, 3238 LOC)
- Table 2: three-layer classification (core / support / non-kernel)
- Table 3: host-facing entries (in-place cutover)
- Table 4: test rebuild (7 preserve-equivalent + 2 co-delete)
- S3.1: file-level deletion candidates (runtime 42 + scripts 15 + tests full)
- S3.2: blocking tables (dual perspective)
- S3.3: recommended strategy (target-state-first, ~28K+ LOC retirement)
- Kernel Context Scope guardrails (4 rules for S4 execution)
- S4 execution roadmap: Step 1 installer cutover → Step 1b release chain → Step 2 kernel extraction → Step 3 batch delete → Step 4 tests
- Architecture diagram (kernel-architecture.svg)
- All advisor corrections applied (models.py 8 modules, in-place cutover, release chain files, step numbering)
Step 1: installer/scripts cutover to kernel-only contracts
- runtime/__init__.py: remove dead heavy imports (engine/models/output/preferences)
- installer/validate.py: trim expected_bundle_paths 18→8 kernel-only
- installer/bootstrap_workspace.py: trim required files/capabilities to kernel-only
- installer/payload.py: remove 4 non-kernel capabilities from bundle manifest
- scripts/sopify_init.py: remove preferences_preload capability
- scripts/install_sopify.py: "runtime" → "kernel" in help text
- scripts/check-runtime-smoke.sh: remove sopify.json checks (install-time artifact)
- tests: 75 installer + doctor tests updated and passing

Step 2: retained kernel/support modules from .models → sopify_contracts
- config.py, state.py, deterministic_guard.py, router.py, handoff.py,
  checkpoint_request.py, checkpoint_materializer.py, execution_gate.py,
  context_snapshot.py — 9 files, mechanical import rewire
- runtime/models.py retained as bridge for non-kernel consumers until Step 3

Plan docs: context_snapshot reclassified as kernel support, Step 2 scope updated
- New runtime/_kernel_turn.py (~720 LOC) with execute_kernel_turn()
- engine.py run_runtime() degraded to lazy-import wrapper (-611 LOC)
- gate/cli/plan_orchestrator callers switched to _kernel_turn
- 7 test mock patches updated
- _kernel_turn imports from sopify_contracts (not runtime.models)
- Engine helper imports annotated: 18 kernel path + 11 non-kernel handler
- Plan docs updated with Package B completion + Package A/C roadmap

Context-Checkpoint: B

Release-Sync: yes

Release-Version: 2026-05-22.232127

Release-Date: 2026-05-22
Remove the dead runtime_skill_id execution branch and its supporting
module. A2 contract audit confirmed no router producer fills
runtime_skill_id, and output/gate/tests have no skill execution
consumers.

Deleted:
- runtime/skill_runner.py (module)
- tests/test_runtime_skill_runner.py (tests for deleted module)
- _kernel_turn.py: runtime_skill_id branch (lines 966-977)
- _kernel_turn.py: _find_skill import
- engine.py: _find_skill definition + skill_runner import
- runtime_test_support.py: unused skill_runner import

Retained (live contract):
- _build_skill_activation / _activation_target: unconditional
  RuntimeResult.activation producer, not sidecar
- skill_registry.py: _kernel_turn.py:538 SkillRegistry.discover()
- skill_resolver.py: router.py:775 resolve_route_candidate_skills()

740 tests pass, 0 regressions.
…-layer blocker, S3.1 reclassification block

- Package A: downgrade from ✅ to re-scoped/partial close
  engine.py still blocked shell (10 handler imports from _kernel_turn)
  plan_scaffold.py still blocked by engine.py
- Package C: expand blocker scope from 9 retained modules to all
  runtime/ from .models consumers (not exhaustive enumeration)
  entry condition: zero from .models consumers in runtime/
- S3.1: add reclassification annotation block (8 retain, 1 deleted,
  1 delete-candidate-blocked)
- gate/router/checkpoint have direct contract/integration coverage
- end-to-end chain (gate → _kernel_turn → route → handoff → checkpoint)
  covered by 6+ integration tests via run_runtime()
- C1 mechanical rewire unblocked: existing tests catch import breakage
- 4.11 remains open: _kernel_turn has zero direct tests;
  coverage audit ≠ kernel-only independence verification
Mechanical import rewire for 9 A2-retained non-kernel modules:
- archive_lifecycle, clarification, context_recovery, decision, kb,
  output, plan_registry, skill_registry, skill_resolver
- from .models → sopify_contracts.{artifacts,core,decision,handoff}
- runtime/models.py bridge NOT deleted (other consumers remain)
- 740 tests pass, zero behavior change
- C1 done (dbd1bc6): 9 retained modules rewired to sopify_contracts.*
- C2 defined: remaining legacy .models consumers (not exhaustive)
- models.py deletion condition: zero from .models in runtime/
…py bridge

- 13 runtime modules + 3 test files rewired from runtime.models
  to sopify_contracts.{artifacts,core,decision,handoff,proposal}
- runtime/models.py deleted (-50 LOC): zero consumers remain
- Combined with C1 (dbd1bc6): 22 files total rewired across C1+C2
- 740 tests pass, zero behavior change
- C1 (dbd1bc6): 9 retained modules rewired
- C2 (e346583): 13 runtime + 3 test files rewired, models.py deleted
- 4.10c marked done
- Delete runtime/decision_tables.py (1,602 LOC) — zero runtime production callers
- Delete runtime/contracts/ directory (7 files, 928 LOC) — all schemas/data for deleted consumers
- Delete tests/test_runtime_decision_tables.py + 2 fixtures (context_fail_close_contract, fail_close_case_matrix)
- Clean test_action_intent.py: remove 3 decision-table test classes + import
- Clean check-context-checkpoints.py: remove deleted files from checkpoint A scope/requirements
- Fix 3 pre-existing test failures (commit 5427520): replace deleted scope trigger files with surviving ones
- Update plan docs: mark 6.1 complete, reorder topics (router split → skill_ids → discovery → plan_registry)

Runtime: 38 files / 17,147 LOC (was 39 / 18,749 before this change)
281 tests pass including action_intent, context_checkpoints, release_hooks
- helper dedup: snapshot helpers → context_snapshot.py, run state → state.py
- protocol split: bare text 继续/取消 removed from Router.classify() main path
- derive move: _derive_route_from_authorized_proposal + 4 sub-functions → router.py
- checkpoint admission tightened: pending/collecting/confirmed only
- dead code cleanup: _ACTION_TYPE_TO_ROUTE[propose_plan] + _build_static_route cancel_active branch
- test boundary: derive unit tests consolidated in test_runtime_router.py::DeriveRouteTests (10 tests)
- 技术债记账: confirmed dual-path, white-box develop context, exec_plan handoff gap
- protocol.md:410: 宿主接续依据改为 required_host_action + artifacts + machine truth
- design.md:402: handoff schema 去掉 recommended_skill_ids,标注退役
- tasks.md: 6.3 裁定收口,6.4 范围锁定承接 C1
…ll_ids, router candidate_skill_ids 全面静态化, eval baseline 同步收口

- 删 RuntimeHandoff.recommended_skill_ids (contract/handoff/kernel/engine 全链)
- 删 skill_registry.py (255 LOC) + skill_resolver.py (111 LOC) + 测试 (380 LOC)
- 保留 skill_schema.py (generate-builtin-catalog.py CI 依赖)
- Router 28+ _candidate_skills() 调用替换为静态 tuple
- Router.classify() + 全部子分类器 + derive 函数移除 skills 参数
- _kernel_turn 移除 SkillRegistry.discover() 调用
- check-skill-eval-gate.py discovery/navigation 退化为 no-op
- evals/skill_eval_baseline.json 删 discovery_cases/navigation_cases
- 3 个 dynamic skill resolution 测试删除
- tasks.md 更新 6.4 执行段 + bare-text heuristic 债务记录
- dump_yaml/is_yaml_scalar/yaml_scalar 从 plan_registry.py 搬至 _yaml.py
- _yaml.py 统一承接 YAML 读写基础设施 (load_yaml + dump_yaml)
- plan_registry.py 保留为独立治理层,priority-note trio 留原处
- plan_registry.py: 1013 → 953 LOC
- 裁定: plan_registry 不是问题源,不拆散
- 删 _is_zero_write_conflict_inspect (dup: _kernel_turn:88)
- 删 _resolve_execution_state_store (dup: _kernel_turn:250)
- 删 _promote_review_state_to_global_execution (dup: _kernel_turn:204)
- 删 _with_global_handoff_ownership (dup: _kernel_turn:123)
- 删 _result_state_store_for_route (dup: _kernel_turn:287)
- 删 _new_resolution_id (dup: _kernel_turn:79)
- 删 _derived_resolution_id (dup: _kernel_turn:169)
- 删 _with_route_artifacts (dup: _kernel_turn:83)
- 删 _pending_required_host_action (dup: _kernel_turn:92)
- 删 _exec_plan_unavailable_route (dup: _kernel_turn:353)
- 清理 6 个变成 unused 的 import
- engine.py: 1892 → 1673 LOC
Module split:
- 新建 _planning.py: planning 主链 + resume + gate checkpoint
- engine.py 瘦身至 343 LOC: conflict/cancel + activation + archive + wrapper
- engine.py planning 知识归零

双份清除:
- 删 _kernel_turn.py 7 双份 helper, 改从 _planning 导入
- 删 2 死常量 (_CANONICAL_ROUTE_FAMILIES, _NON_FAMILY_SURFACES)
- 修正 2 错位常量归 engine (_ABORTABLE_RUN_STAGES, _ABORTABLE_HANDOFF_ACTIONS)

Execution-resume 下沉:
- 新增 resolve_execution_resume(): gate eval + state mutation 单入口
- _kernel_turn 不再内联 130 行 gate 分支/RunState 构造/state persistence
- 删 _exec_plan_unavailable_route (移入 _planning)
- 清理 4 废弃 import (evaluate_execution_gate, make_run_state 等)

终态指标:
- _kernel_turn: 1040 → 783 LOC | _planning: 1496 LOC | engine: 343 LOC
- import 面: _planning×7 + engine×5 = 12 (原 engine×9 + 7 隐藏重复 = 16)
- 测试: 0 新增失败, 22 已知 legacy fail 不变
删除 (6 tracked files):
- scripts/check-host-doc-contract.py (74)
- scripts/check-skill-eval-gate.py (305) + evals/ 整组 (baseline/slo)
- scripts/plan_registry_runtime.py (109)
- scripts/preferences_preload_runtime.py (72)

联动清理 (14 files, −251 LOC):
- manifest.py: 删 PLAN_REGISTRY_ENTRY/PREFERENCES_PRELOAD_ENTRY +
  plan_registry_hosts 块 + preferences_preload 系列
- workspace_preflight.py: 删 _LEGACY_WORKSPACE_PREFERENCES_PRELOAD_ENTRY
- ci.yml/release-preflight.sh/check-runtime-smoke.sh/sync-runtime-assets.sh
- test_runtime_engine.py (−81): bundle 脚本断言 + manifest 字段 + preload 执行块
- test_runtime_gate.py (−7): preferences_preload_entry 构造/断言/capability
- test_runtime_plan_registry.py (−67): script inspect test
- test_installer.py/protocol.md/design.md/CONTRIBUTING×2

方案包收口:
- tasks.md: P4.6 标完成 (P4.6-A = 全部交付), 原 P4.6-B 废弃 → 4.13 installer 瘦身
- design.md: scripts 退场表同步至 P4.6-A 后现实, runtime_bundle.py→REWRITE,
  check-skill-eval-gate.py 阻塞标为已解除

验证: test_runtime_gate 75p; test_runtime_plan_registry+test_installer 60p
删除 .sopify-runtime/manifest.json 整条链: 双写/读/合并/fallback/诊断。
workspace activation 收敛到 .sopify-skills/sopify.json 单标记。
global bundle 缺失一律 fail-close,不再本地兜底。

stub 合同修正: workspace_preflight fallback 删除 preferences_preload
(P4.6-A 遗漏),与 installer.validate 对齐。

文档同步: protocol.md/CONTRIBUTING/CONTRIBUTING_CN 改写 workspace
marker 引用 + 退役已删 bridge helper 描述。

27 files, +317 −771, 149 tests passed
- Rewrite installer/runtime_bundle.py from shell-out to pure Python
  (shutil.copytree + write_bundle_manifest), delete sync-runtime-assets.sh
- Fix handoff.py: explicit checkpoint_request_reason_code when
  skill_result has tradeoff candidates but no checkpoint_request
- Add missing imports in runtime_test_support.py (match_decision_policy,
  build_strategy_pick_template)
- Remove 34 retired test blocks (decision/clarification bridge, develop
  callback/quality, run_plan_loop, go_plan_runtime, plan_orchestrator)
- Update .githooks/pre-commit, CONTRIBUTING.md, plan design/tasks docs

Test: 619 passed, 49 subtests passed
@Li-Sanze Li-Sanze merged commit 6f61514 into main May 24, 2026
2 of 4 checks passed
@Li-Sanze Li-Sanze deleted the plan/runtime-slimming-kernel-extraction branch May 26, 2026 06:38
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