Skip to content

feat(contract): add authority source digest locks and executable invariants probe - #7321

Open
hhyykk wants to merge 1 commit into
loopx-project:mainfrom
hhyykk:feat/top-level-invariants
Open

hhyykk wants to merge 1 commit into
loopx-project:mainfrom
hhyykk:feat/top-level-invariants

Conversation

@hhyykk

@hhyykk hhyykk commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

  • Outcome basis / optional anchor: Self-contained control-plane contract hardening under CONTRIBUTING.md#find-work and the Kernel/capability responsibility boundary in docs/architecture.md#runtime-responsibility-model.
  • Goal/source and gap: bootstrap_project previously recorded an explicit --goal-doc in authority_sources without a content digest lock, did not discover top-level repository specifications (architecture.md, goal-and-requirements.md), and check_contract did not verify whether registered authority sources were deleted or mutated after bootstrap or whether snapshotted repository-wide invariants were violated during replans.
  • Observable before → after, with the validation row that proves it:
    • Before: Mutating or deleting a registered authority source or violating declared repository-wide invariants (forbid_import, forbid_pattern, must_exist, immutable_path) passed check_contract (ok=True, errors=[]).
    • After: bootstrap_project records sha256 locks for existing --goal-doc files and discovered architecture.md / goal-and-requirements.md specifications (and renders ## Repo-Wide Architecture Invariants into ACTIVE_GOAL_STATE.md). check_contract runs domain-neutral verify_authority_source_digests unconditionally and runs verify_executable_architecture_invariants when include_architecture_invariants=True (proven by tests/test_architecture_invariants.py, 13 passed).
  • Issue/task and intended base: Targets main (self-contained contract increment; no pre-existing issue ID claimed).

Author Declaration

  • Written by: model_agent (OpenAI GPT-6.1-sol via Codex CLI and Google Gemini pair-programming assistant, operated by @hhyykk).

Implemented against

  • Specification and revision: no written specification; the request in this PR is the basis, aligned with docs/architecture.md at 59464f9741fe177381743eadaaffebbb54e5472e.
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
Lock existing --goal-doc and discovered top-level specs with SHA-256 at bootstrap while allowing non-existent --goal-doc paths to register without a digest implemented build_goal_entry in loopx/bootstrap.py; discover_top_level_specs in loopx/control_plane/goals/architecture_invariants.py pytest -q tests/test_architecture_invariants.py
Separate domain-neutral authority digest verification from optional executable invariant probing implemented verify_authority_source_digests, verify_executable_architecture_invariants in loopx/control_plane/goals/architecture_invariants.py; check_contract in loopx/contract.py pytest -q tests/test_architecture_invariants.py
Enforce forbid_import, forbid_pattern, must_exist, and immutable_path from bootstrap-snapshotted rules without allowing active-state prose to forge lock approvals implemented verify_executable_architecture_invariants in loopx/control_plane/goals/architecture_invariants.py pytest -q tests/test_architecture_invariants.py
  • Self-check before submission: Verified 13 focused unit/integration tests in tests/test_architecture_invariants.py, 316 existing bootstrap/contract tests (tests/test_*bootstrap*.py and tests/test_*contract*.py), 298 architecture boundary & content-digest single-owner tests, scripts/generate_semantic_inventory.py --changed-from HEAD, scan_public_boundary, ruff check, and git diff --check. Left full cross-platform CI matrix and live benchmark suites to GitHub Actions CI.

Scope And Continuation

  • Completed scope and remaining work: Completed Slice 1 (domain-neutral authority_sources SHA-256 digest locking and verification) and Slice 2 (opt-in include_architecture_invariants probe for forbid_import, forbid_pattern, must_exist, and immutable_path rules snapshotted at bootstrap).
  • Slice boundary / successor: Complete within this scope; if maintainers prefer relocating Slice 2's AST/regex invariant probe into a standalone engineering capability package or CLI subcommand, verify_executable_architecture_invariants is already cleanly isolated from verify_authority_source_digests.

Validation

  • Tested revision: 576af8b44def7095aaec839c5e159ed49829d88d
  • Run state: finished
  • Input classes: synthetic, public_fixture
Check kind Result Public-safe evidence / limitation
unit passed python3 -m pytest -q tests/test_architecture_invariants.py (13 passed: covers explicit/missing --goal-doc digest locking, include_architecture_invariants=False/True, forbid_import, forbid_pattern, must_exist, immutable_path, path traversal rejection, and spec tampering recovery).
regression_parity passed python3 -m pytest -q tests/test_*bootstrap*.py tests/test_*contract*.py (303 passed, 1 skipped on existing bootstrap/contract suites with zero regressions; A/B comparison against baseline 59464f9741fe177381743eadaaffebbb54e5472e confirmed baseline missed layer-bypass imports, deleted required modules, and spec rule erasure while candidate caught all 3 invariant violations + unapproved spec mutation).
static passed python3 -m pytest -q tests/architecture/test_content_digest_production_owner.py tests/architecture/test_content_digest_single_owner.py tests/architecture/test_control_plane_import_boundaries.py (298 passed); python3 scripts/generate_semantic_inventory.py --changed-from 59464f9741fe177381743eadaaffebbb54e5472e (0 candidates); ruff check on added modules and git diff --check passed; scan_public_boundary passed with 0 hits/warnings.
  • Coverage and gaps: The focused unit and regression suites cover bootstrap_project, build_goal_entry, render_state_markdown, check_contract, verify_authority_source_digests, and verify_executable_architecture_invariants. Full repository pytest shards and Windows PowerShell checks were not run locally and will run in PR CI.

Frontend / Visual Evidence

  • UI impact: none
  • Before: N/A
  • After: N/A
  • First viewport and preview: N/A
  • States and viewports shown: N/A
  • Source data: none
  • Attention review: N/A
  • Craft review: N/A

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring (no functional changes)
  • Documentation update
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)
  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)
  • Capability or extension (providers, adapters, skills)
  • Public docs or presentation surface (README, protocols, dashboard)
  • Build, packaging, installer, or CI
  • Host or runtime integration

Technical Direction

  • Direction / acceptance reference, when applicable: Core control-plane hardening (authority_sources digest integrity and repository-wide invariant diagnostics).

Shared-authority RFC fixture impact

  • Production-scale fixture schema: N/A
  • Semantic dimensions changed, or reviewed no-impact rationale: N/A
  • Provider conformance arms run: N/A
  • Read-only legacy/file/PostgreSQL three-arm rehearsal (required for promotion, runtime-routing, or compatibility-projection changes): N/A

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md).
  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.
  • I kept the change scoped to the linked issue/task.
  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes, or no paired RFC changed.
  • I completed the visual evidence section for UI changes, or marked UI impact none.
  • Every commit includes a DCO Signed-off-by trailer (git commit -s).

…riants probe

Signed-off-by: aihop <4408344+hhyykk@users.noreply.github.com>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

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.1-sol | OpenAI | runtime_reported | reasoning_effort=max

评审对象:576af8b44def7095aaec839c5e159ed49829d88d。两项阻塞:

  • [P2] 将软件扫描从默认通用健康路径隔离。 check_contract 的新参数默认是 True,普通 CLI 和 status 调用都不传它。一次性项目仅包含声明缺少文件的规范、没有任何显式启用操作,同输入旧基线 check 为 exit 0,当前为 exit 1;当前直接传 False 又通过。bootstrap 同时已经快照软件规则并生成 Agent 义务,所以内部 bool 也不能隔离完整行为。将源码规则从普通 check/status 的默认路径分离,通过显式、带作用域的工程检查启用;只改 Python 默认参数仍不足以隔离 bootstrap 已生成的新增义务。保留来源校验的独立 owner,并补开/关与旧版默认行为对照。
  • [P2] 检查 from-import 中的实际子模块。 ImportFrom 分支 只比较 node.module。声明禁止 pkg.db 时,import pkg.db 会报错,改成 from pkg import db 却返回 ok=True/errors=[],实际 Python 导入仍加载同一个被禁止的模块。检查 ImportFrom 的模块与导入成员组合,正确处理子模块和相对导入;把 import pkg.db 与 from pkg import db 作为同一禁止依赖的成对反例,避免靠改写合法 import 绕过。

动机

把已有项目接入 LoopX、随后正常检查状态或继续修改代码的用户,会受到自动发现的仓库规范影响。旧版普通 bootstrap 后的 check 不执行这些软件规则;新版仅凭规范文件名就把源码规则接入默认健康检查,即使用户没有显式启用工程扫描。来源摘要锁能发现修改和删除,但当前 head 的默认 CLI 出现新增拒绝,同时一个普通静态导入写法能让禁止依赖检查返回干净结果。本次评审不否定来源完整性需求,也不要求完成整个 TypeScript 迁移;要求把通用完整性与可选软件检查分清,并让已声明规则可靠。

改动思路

来源完整性与软件源代码约束属于两项不同责任;后者不能仅因发现文件名就在通用健康路径默认启用。保留有用的来源校验,先把软件扫描移到显式工程检查边界,并修复已声明导入规则的漏检;无需等待整套控制面迁移。这里应区分三类机制:文件字节及历史接受版本的完整性是通用来源事实;AST/正则扫描是软件工程领域策略;文件读取是只读 provider IO。复用通用诊断容器不会让领域策略自动成为 Kernel 的默认责任。既有注册来源 witness 核的是注册字节身份,与单份文档内容锁不同,不能因同用 SHA-256 就硬合并;已有工程检查能力的显式作用域则是可复用边界。

具体改动

采用作者引用的 docs/architecture.md,固定规格版本 59464f9741fe177381743eadaaffebbb54e5472e:Runtime Responsibility Model 的 capability/domain-policy 与 Kernel 分工未满足;Guided Autonomy, Not Recommendation Lock-In 对显式 typed 强制边界的要求也未满足。修复针对上述当前默认/范围问题,不将未来整套迁移当作前置门。来源摘要在现有测试里能够发现改动、删除,并且 active-state prose 不能批准换锁,这些正向价值保留。

关键代码讲解

  1. build_goal_entry 给已存在的显式 goal 文档加摘要,并自动发现四个候选规范位置;它还保存解析规则、原理和 immutable 文件摘要。缺少的显式文档仍保持旧的无摘要注册。
  2. check_contract 始终加入来源摘要诊断,并在新增参数为真时加入软件规则。默认值为真且现有公共调用方省略参数,实际行为与“Slice 2 opt-in”不符;bootstrap 的新增指令也没有同一个开关。
  3. verify_authority_source_digests 保留旧无摘要记录,对缺少、不可读和内容改变产生 Goal 诊断。需要保留该兼容意义,而不是删除旧来源格式;测试里直接改字典摘要并不等同普通授权恢复旅程。
  4. _check_python_forbidden_imports 区分 Import/ImportFrom,后一支丢失导入成员,使同一个子模块依赖得到不同结论。文件有 381 行生产逻辑,同时维护解析、扫描、IO 和策略,不能以 268 行新测试证明整体责任合适。

对主干的风险

独立运行新增测试 13 过,现有 bootstrap/contract 与架构边界测试 601 过、1 跳过;该跳过是同一原生 Windows/PowerShell 用例,base/head 的早期条件、源码和原因相同。原生 premerge 的 6 项直接、6 项 catalog 和 8 项风险检查通过,没有手工 hold;这些绿色结果没有覆盖上述反例。按当前策略没有读取、轮询或等待 CI。

同输入生产路径 旧基线 当前完整 head
普通 bootstrap 后默认 CLI check,无显式工程启用 exit 0,干净 exit 1,软件规则错误
当前内部显式停用软件 probe 旧版无该参数 通过,但 bootstrap 指令/快照仍已产生
同一禁止子模块的直接 import / from-import 尚无此规则 前者拒绝,后者错误通过

两臂都使用真实 bootstrap、公共 CLI 和一次性 File 注册/runtime,未修改活跃 Goal。首次夹具放在被忽略私有树里,两个 CLI 都因独立的 public-boundary 扫描拒绝;原失败保留,随后在全新系统临时目录完整重放两臂,没有删除或关闭生产扫描来制造结果。当前两个反例均稳定成立。修复后应重跑默认/显式开关、完整生成指令和规则元数据、来源变更/删除/合法恢复,以及直接/from/相对导入的正反矩阵。

语义与 CI 对齐

本 PR 新建了来源种类、规则 kind、快照字段及健康诊断语义,kind: str 加注释不是 typed 规则合同;静态 advisory 未报 candidate 也不能证明没有新词汇。软件策略应归显式工程 owner,通用来源完整性应复用当前 typed 边界和诊断语义。include_architecture_invariants 是机器执行分支,失败会产生健康错误,不宜表述成仅供参考的指导。现行原生校验通过仍不能覆盖默认范围和导入漏检。

我的整体评价

REQUEST_CHANGES。来源摘要锁有可验证的价值,但完整提案仍包含默认行为回归和错误的规则通过,用户的正常检查及后续恢复没有形成可用闭环。长期有效工作是否保持尚未证明;用户体验已观察到无额外启用却新增拒绝。来源完整性与软件源代码约束属于两项不同责任;后者不能仅因发现文件名就在通用健康路径默认启用。保留有用的来源校验,先把软件扫描移到显式工程检查边界,并修复已声明导入规则的漏检;无需等待整套控制面迁移。已检查 bootstrap 生成的 Agent Markdown、CLI check 和 status collection:本 PR 没有修改渲染页面组件,问题在默认策略和诊断,因此不以截图充当其正确性证据。未验证范围:原生 Windows/PowerShell、完整跨平台 CI、已安装客户端、长期扫描成本和获授权锁更新后的真实继续工作未获本次资格;这些不替代已复现的两项缺陷。这是当前精确 head 的评审结论,不要求用户代作者操作,也不授予合并、安装或额外执行权限。

English verdict: REQUEST_CHANGES 576af8b. Ordinary bootstrap/check implicitly enables the claimed optional software probe, and a normal from-import bypasses the declared forbidden submodule rule. Independent CLI counterexamples reproduce despite passing focused/regression tests and native premerge; separate the responsibility/activation boundary and repair import resolution.

This branch has not been deployed

No deployments
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.

2 participants