Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/ci-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,27 @@ jobs:

- name: Check governance evidence-first contract (structure + semantics)
run: ./scripts/ci/check_governance_evidence_truth.sh

p0-gate:
name: p0-gate
runs-on: ubuntu-latest
needs: [lint, build]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install p0-gate dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest pytest-asyncio langchain-openai langchain-core httpx starlette uvicorn

- name: Install project editable package
run: python -m pip install -e . --no-deps

- name: Run p0 conformance gate
run: python scripts/ci/p0_gate.py
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
├── guides/Development_Constraints.md (开发约束清单)
├── guides/Documentation_First_Development_SOP.md (文档先行 SOP,Bug/Feature/Refactor 必走)
├── guides/Evidence_Truth_Implementation_Strategy.md (Evidence Truth 固化策略与 CI 落地计划)
├── guides/P0_Gate_Runbook.md (P0 gate 本地运行、发布归档、flaky 处理操作手册)
├── governance/Documentation_Management_Model.md (文档目录分层、生命周期、OpenSpec/TODO 双模式协作)
├── features/README.md (特性聚合文档规范与归档规则)
└── design/Design_Doc_Minimum_Standard.md (设计文档最小完备标准)
Expand Down Expand Up @@ -97,6 +98,7 @@
| `guides/Development_Constraints.md` | 开发约束:架构不破坏、测试必备、日志/命名/复用/信任边界等硬性要求 |
| `guides/Documentation_First_Development_SOP.md` | 文档先行 SOP:先设计文档、再 gap 分析、再 TODO、再 OpenSpec 修复、再归档 |
| `guides/Evidence_Truth_Implementation_Strategy.md` | Evidence Truth 固化策略:证据结构、审计要求、CI 分阶段落地 |
| `guides/P0_Gate_Runbook.md` | P0 gate 操作手册:本地执行、失败分诊、发布归档、flaky 策略 |
| `governance/Documentation_Management_Model.md` | 文档管理模型:目录分层、文档类型规则、生命周期依赖、OpenSpec/无 OpenSpec 协作 |
| `features/README.md` | 特性聚合文档规范:单一状态源、证据回写与归档迁移 |
| `guides/Team_Agent_Collab_Playbook.md` | 团队并行开发协作手册,含 spec-driven 认领粒度与 execution board 规则 |
Expand Down
108 changes: 108 additions & 0 deletions docs/features/p0-conformance-gate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
change_ids: ["p0-conformance-gate"]
doc_kind: feature
topics: ["p0", "conformance", "ci-gate", "runtime-validation"]
created: 2026-03-03
updated: 2026-03-03
status: active
mode: openspec
---

# Feature: p0-conformance-gate

## Scope

将 P0 运行时不变量收敛成统一的 `p0-gate` 质量门禁,覆盖安全门控、`step_driven` 执行闭环、默认事件链审计三类关键约束,并把 CI / 发布流程接入这条硬门槛。

## OpenSpec Artifacts

- Proposal: `openspec/changes/p0-conformance-gate/proposal.md`
- Design: `openspec/changes/p0-conformance-gate/design.md`
- Specs:
- `openspec/changes/p0-conformance-gate/specs/p0-conformance-gate/spec.md`
- `openspec/changes/p0-conformance-gate/specs/validation/spec.md`
- `openspec/changes/p0-conformance-gate/specs/core-runtime/spec.md`
- Tasks: `openspec/changes/p0-conformance-gate/tasks.md`

## Governance Anchors

- `docs/guides/Development_Constraints.md`
- `docs/guides/Documentation_First_Development_SOP.md`
- `openspec/specs/core-runtime/spec.md`
- `openspec/specs/validation/spec.md`

## Evidence

### Commands

- `git fetch origin`
- `git worktree add .worktrees/p0-conformance-gate -b codex/p0-conformance-gate origin/main`
- `../../.venv/bin/python -m pytest -q tests/unit/test_transport_adapters.py tests/unit/test_interaction_dispatcher.py tests/unit/test_transport_channel.py tests/integration/test_client_cli_flow.py tests/unit/test_examples_cli.py tests/unit/test_examples_cli_mcp.py`
- `../../.venv/bin/python -m pytest -q tests/integration/test_security_policy_gate_flow.py`
- `../../.venv/bin/python -m pytest -q tests/integration/test_p0_conformance_gate.py`
- `../../.venv/bin/python -m pytest -q tests/integration/test_security_policy_gate_flow.py tests/integration/test_p0_conformance_gate.py tests/unit/test_dare_agent_step_driven_mode.py`
- `../../.venv/bin/python -m pytest -q tests/unit/test_dare_agent_security_policy_gate.py tests/unit/test_dare_agent_security_boundary.py tests/unit/test_five_layer_agent.py`
- `../../.venv/bin/python -m pytest -q tests/unit/test_p0_gate_ci.py`
- `../../.venv/bin/python scripts/ci/p0_gate.py`
- `openspec validate p0-conformance-gate --type change --strict --json --no-interactive`
- `./scripts/ci/check_governance_evidence_truth.sh`

### Results

- `git fetch origin`: confirmed `origin/main` advanced to merge commit `36c8b38`, which includes the completed archive closeout for `refactor-dare-agent-structure-split` and provides the clean baseline for the next active change.
- `git worktree add .worktrees/p0-conformance-gate -b codex/p0-conformance-gate origin/main`: created an isolated continuation workspace for the next active change directly from merged `main`.
- `../../.venv/bin/python -m pytest -q tests/unit/test_transport_adapters.py tests/unit/test_interaction_dispatcher.py tests/unit/test_transport_channel.py tests/integration/test_client_cli_flow.py tests/unit/test_examples_cli.py tests/unit/test_examples_cli_mcp.py`: passed (`76 passed, 1 warning`) as the current baseline for the already-landed P0-related contract coverage recorded under tasks `2.4` and `5.1`.
- `../../.venv/bin/python -m pytest -q tests/integration/test_security_policy_gate_flow.py`: passed (`3 passed, 1 warning`) after extending the integration file to cover the full security gate decision surface: direct allow, direct deny with structured `not_allow`, and approval-required escalation.
- `../../.venv/bin/python -m pytest -q tests/integration/test_p0_conformance_gate.py`: passed (`2 passed, 1 warning`) after adding the missing step-driven integration anchor that exercises the full `agent("task")` closed loop, covering both ordered happy-path execution and fail-fast behavior when the first validated step fails.
- `../../.venv/bin/python -m pytest -q tests/integration/test_security_policy_gate_flow.py tests/integration/test_p0_conformance_gate.py tests/unit/test_dare_agent_step_driven_mode.py`: passed (`28 passed, 1 warning`) after the new `p0` integration file also absorbed the default event-log replay/hash-chain runtime anchor, confirming the security gate slice, step-driven closed-loop slice, and audit-chain slice can run together as the emerging P0 gate bundle.
- `../../.venv/bin/python -m pytest -q tests/unit/test_dare_agent_security_policy_gate.py tests/unit/test_dare_agent_security_boundary.py tests/unit/test_five_layer_agent.py`: passed (`50 passed, 1 warning`) after the new security-gate integration coverage landed, confirming the added integration assertions do not regress the existing direct runtime and no-planner approval semantics.
- `../../.venv/bin/python -m pytest -q tests/unit/test_p0_gate_ci.py`: passed (`4 passed`) after extending the CI-side unit contract so `p0-gate` also preserves node ids from pytest `ERROR` summary lines, not only assertion-style `FAILED` lines.
- `../../.venv/bin/python scripts/ci/p0_gate.py`: passed and emitted:
`p0-gate: PASS`
`- SECURITY_REGRESSION: 0 failures`
`- STEP_EXEC_REGRESSION: 0 failures`
`- AUDIT_CHAIN_REGRESSION: 0 failures`
which confirms the repository now has a single deterministic command entrypoint for the three frozen P0 categories.
- `openspec validate p0-conformance-gate --type change --strict --json --no-interactive`: passed (`1/1` change valid, `0` issues) after restoring the missing active feature aggregation record for this change.
- `./scripts/ci/check_governance_evidence_truth.sh`: initially failed because the restored feature doc lacked historical PR/review links; after linking the already-landed P0 evidence PRs, the governance gate passed, and remained green after task `1.1-1.3` synchronized the gate scope matrix and rollout contract into the active docs/spec set.
- `./scripts/ci/check_governance_evidence_truth.sh`: remained green after adding `docs/guides/P0_Gate_Runbook.md` plus the new navigation links in `docs/README.md` and `docs/guides/Team_Agent_Collab_Playbook.md`, confirming the operationalization docs did not break the governance acceptance pack.

### Behavior Verification

- Happy path: the existing contract-focused transport / interaction / example CLI suites still pass from a clean `origin/main` baseline, so the previously landed P0 contract assertions remain intact before new gate work begins.
- Error branch: the baseline suite still includes the approval action normalization and structured failure-contract assertions captured by tasks `2.4` and `5.1`, which are the current minimal regression anchors for `p0-gate`.
- Happy path: task `1.1-1.3` now defines a stable three-category matrix with explicit ownership modules, anchor suites, and required-mode thresholds, so later CI wiring can attach to a fixed scope instead of an ad hoc test grab-bag.
- Error branch: the rollout contract now explicitly blocks promoting `p0-gate` to a required check if any category lacks a green anchor set or emits uncategorized failures, preventing partial rollout from being misread as full P0 coverage.
- Happy path: task `2.1` now proves the security gate allows low-risk tool execution without creating pending approvals and still preserves the existing approval-required flow for high-risk execution.
- Error branch: task `2.1` now proves a denied capability is blocked before gateway invocation and recorded as a structured `not_allow` tool result inside the full agent flow, not only in direct `_run_tool_loop` unit tests.
- Happy path: task `2.2` now proves `step_driven` mode can complete a full session-loop closed loop with a planner and validator, preserve step order, and pass `_previous_output` from the first validated step into the second step during actual runtime execution.
- Error branch: task `2.2` now proves a failed first validated step aborts the remaining step sequence within the same milestone attempt and reaches `verify_milestone` as a structured failed run result instead of continuing to later steps.
- Happy path: task `2.3` now proves the default SQLite runtime event log can replay a real session window from `session.start` through later runtime events while keeping per-event `task_id` / `run_id` / `session_id` correlation intact.
- Error branch: task `2.3` now proves the same runtime-backed SQLite log fails `verify_chain()` after on-disk payload tampering, so the audit-chain invariant is validated against actual session data rather than only synthetic unit fixtures.
- Happy path: task `3.1` now exposes a single CI command entrypoint, `python scripts/ci/p0_gate.py`, that runs the three category bundles without relying on ad hoc workflow-local command duplication.
- Error branch: task `3.3` now guarantees failed `p0-gate` runs produce deterministic category-tagged triage output with failing node ids, module ownership, and first-action guidance instead of raw pytest noise alone.
- Error branch: the latest PR review fix now keeps deterministic node ids even when pytest stops in collection/import/runtime with `ERROR` summary lines, so CI triage does not collapse to `<no failing test ids captured>` for non-assertion failures.
- Happy path: tasks `4.1-4.3` now publish a single runbook that tells contributors exactly how to run `p0-gate`, where to look first for each category, how to archive release evidence, and how to record flaky incidents without inventing a second workflow.
- Error branch: the runbook now forbids silent anchor removal and silent rerun-based “fixes”; failed `p0-gate` runs must either be repaired or escalated through the documented flaky/quarantine path with owner and expiry.

### Risks and Rollback

- Risk: this change currently has partial task completion but had no active feature aggregation record, which weakens traceability until the governance baseline is restored.
- Risk: task `3.2` still depends on repo-admin branch protection / ruleset changes outside the repository, so `p0-gate` is not yet a true protected-branch merge blocker even though the job and summary contract now exist in-tree.
- Risk: `3.2` is now the only remaining open task in this change, and it cannot be completed from the repository contents alone.
- Rollback: if the new `p0-gate` workflow job proves too noisy before repo-admin rollout, remove the job entry from `.github/workflows/ci-gate.yml` and keep `scripts/ci/p0_gate.py` plus the runbook as local-only tooling until the category bundle is re-tuned.
- Rollback: no runtime behavior changed in this kickoff step; reverting only removes the restored governance record for the active change.

### Review and Merge Gate Links

- Current continuation branch: `codex/p0-conformance-gate`
- Current implementation PR: `https://github.com/zts212653/Deterministic-Agent-Runtime-Engine/pull/172`
- Historical PR for task `2.4`: `https://github.com/zts212653/Deterministic-Agent-Runtime-Engine/pull/130`
- Historical PR for task `5.1` baseline recovery path: `https://github.com/zts212653/Deterministic-Agent-Runtime-Engine/pull/113`
- Historical review evidence: `https://github.com/zts212653/Deterministic-Agent-Runtime-Engine/pull/130#pullrequestreview-3872526843`
- Historical merge evidence: `https://github.com/zts212653/Deterministic-Agent-Runtime-Engine/pull/130`
- PR status for this continuation branch: implementation PR opened at `#172`

## Next Milestone

Schedule the repo-admin follow-up for task `3.2`: add `p0-gate` to the protected-branch required checks / ruleset after this change merges.
5 changes: 5 additions & 0 deletions docs/governance/branch-protection.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ If your GitHub plan supports merge queue:
- Phase 1 (now, required): `lint`, `build`
- Phase 2 (observe first, then required): `smoke-tests`
- Phase 3 (after 1-2 stable weeks, then required): `risk-matrix`, `test-skip-guard`, `lockfile-policy`
- Phase 4 (planned after `p0-conformance-gate` lands): `p0-gate`
- workflow entrypoint: `.github/workflows/ci-gate.yml` job `p0-gate` runs `python scripts/ci/p0_gate.py`
- promotion threshold: security / step-driven / audit category anchors all green in the same run
- summary contract: `p0-gate` must emit deterministic category labels and failing test/module pointers before it can become a required branch check
- repo-admin action: after this change merges, add `p0-gate` to the protected-branch required checks list / ruleset

## Fallback if Merge Queue Is Unavailable
Use pre-merge combined checks:
Expand Down
123 changes: 123 additions & 0 deletions docs/guides/P0_Gate_Runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# P0 Gate Runbook

> Scope: `p0-conformance-gate` operational usage after the category matrix, CI entrypoint, and summary contract have been frozen.

## 1. Command of Record

Run the gate from the repository root:

```bash
.venv/bin/python scripts/ci/p0_gate.py
```

Expected success output:

```text
p0-gate: PASS
- SECURITY_REGRESSION: 0 failures
- STEP_EXEC_REGRESSION: 0 failures
- AUDIT_CHAIN_REGRESSION: 0 failures
```

The same command is used by `.github/workflows/ci-gate.yml` job `p0-gate`.

## 2. Category Mapping

### SECURITY_REGRESSION

Primary signal:
- `tests/integration/test_security_policy_gate_flow.py`
- `tests/unit/test_dare_agent_security_policy_gate.py`
- `tests/unit/test_dare_agent_security_boundary.py`
- `tests/unit/test_transport_adapters.py`
- `tests/unit/test_examples_cli.py`
- `tests/unit/test_examples_cli_mcp.py`

Inspect first:
- `dare_framework/security/`
- `dare_framework/tool/_internal/governed_tool_gateway.py`
- `dare_framework/transport/_internal/adapters.py`
- `examples/05-dare-coding-agent-enhanced/cli.py`
- `examples/06-dare-coding-agent-mcp/cli.py`

### STEP_EXEC_REGRESSION

Primary signal:
- `tests/integration/test_p0_conformance_gate.py::test_step_driven_session_executes_validated_steps_in_order`
- `tests/integration/test_p0_conformance_gate.py::test_step_driven_session_stops_after_first_failed_step`
- `tests/unit/test_dare_agent_step_driven_mode.py`

Inspect first:
- `dare_framework/agent/dare_agent.py`
- `dare_framework/agent/_internal/execute_engine.py`
- `dare_framework/plan/`

### AUDIT_CHAIN_REGRESSION

Primary signal:
- `tests/integration/test_p0_conformance_gate.py::test_default_event_log_replay_and_hash_chain_hold_for_runtime_session`
- `tests/unit/test_event_sqlite_event_log.py`
- `tests/unit/test_builder_security_boundary.py::test_default_event_log_replay_returns_ordered_session_window`

Inspect first:
- `dare_framework/event/_internal/sqlite_event_log.py`
- `dare_framework/event/kernel.py`
- `dare_framework/observability/_internal/event_trace_bridge.py`
- `dare_framework/agent/builder.py`

## 3. Local Troubleshooting Flow

1. Run `.venv/bin/python scripts/ci/p0_gate.py`.
2. Record the first failing summary block before any rerun.
3. Rerun only the category-local anchors listed in the summary.
4. Fix the regression, then rerun the full `p0-gate` command.
5. Do not claim the gate is fixed until the full command returns `PASS`.

If the summary itself looks malformed, rerun:

```bash
.venv/bin/python -m pytest -q tests/unit/test_p0_gate_ci.py
```

That suite locks the `PASS/FAIL + category + tests + modules + action` contract.

## 4. Release Archive Step

Every release candidate, release PR, or final tag cut that relies on protected-branch quality gates MUST archive the latest `p0-gate` result.

Minimum archive payload:
- exact command: `.venv/bin/python scripts/ci/p0_gate.py`
- exact summary text
- workflow/job URL when run in GitHub Actions
- release identifier (`tag`, `release PR`, or release issue)
- operator and timestamp

Archive location rule:
- preferred: release PR description or release issue checklist
- acceptable fallback: release note draft section named `P0 Gate`

If `p0-gate` is not green, the release must stop; do not archive a failed run as release evidence unless the release is explicitly aborted.

## 5. Flaky Handling Policy

P0 gate failures are blocker-grade until proven otherwise. Treat reruns as evidence collection, not as remediation.

Rules:
1. One immediate rerun is allowed only after preserving the first failing summary.
2. A category may be called flaky only if the same node id both fails and passes without code changes.
3. Flaky suspicion requires an issue or TODO entry that records:
- failing node id
- category label
- first failed run link
- rerun result
- owner and expiry
4. A flaky anchor must not be silently removed from `scripts/ci/p0_gate.py`.
5. Any temporary downgrade or quarantine requires a docs-first change that names the replacement anchor or the rollback plan.

Escalation threshold:
- two flaky incidents for the same node id within seven days triggers quarantine review
- quarantine review must finish within two business days

## 6. Branch Protection Follow-up

After `p0-conformance-gate` merges, a repository administrator still needs to add `p0-gate` to the protected branch required checks / ruleset. That step is outside the repository contents and is tracked separately in `docs/governance/branch-protection.md`.
2 changes: 2 additions & 0 deletions docs/guides/Team_Agent_Collab_Playbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ pytest -q tests/smoke -m smoke
- `risk-matrix`
- `test-skip-guard`
- `lockfile-policy`
- `p0-gate`(已入 workflow;是否 required 取决于 branch protection rollout)

治理配置说明:
- `docs/governance/branch-protection.md`
- `docs/guides/P0_Gate_Runbook.md`

## 4. 免费版主干护栏(main-guard)

Expand Down
Loading
Loading