From 82d978a8cdd0f90111ab1cd5072793bf70e8e801 Mon Sep 17 00:00:00 2001 From: TangZ-L <345187680+TangZ-L@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:37:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(attribution):=20=E8=AE=A9=20case-tools=20?= =?UTF-8?q?=E9=80=9A=E9=81=93=E9=80=82=E9=85=8D=E6=98=BE=E5=BC=8F=E7=BB=93?= =?UTF-8?q?=E8=AE=BA=20writer=20(#608)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ugfix-case-tools-explicit-conclusion.en.md | 108 ++++++++++++++++++ ...x-case-tools-explicit-conclusion.i18n.yaml | 5 + .../bugfix-case-tools-explicit-conclusion.md | 108 ++++++++++++++++++ .../bugfix-explicit-skill-conclusion.en.md | 4 +- ...bugfix-explicit-skill-conclusion.i18n.yaml | 4 +- .../bugfix-explicit-skill-conclusion.md | 4 +- ...11-25-case-tools-explicit-conclusion.en.md | 30 +++++ ...5-case-tools-explicit-conclusion.i18n.yaml | 5 + ...26-11-25-case-tools-explicit-conclusion.md | 30 +++++ .../ai_agent/attribution_case_tools.py | 44 +++++-- .../api/tests/attribution/case_cli_fixture.py | 9 ++ apps/api/tests/attribution/test_case_tools.py | 6 + 12 files changed, 342 insertions(+), 15 deletions(-) create mode 100644 .agents/flow/issues/bugfix-case-tools-explicit-conclusion.en.md create mode 100644 .agents/flow/issues/bugfix-case-tools-explicit-conclusion.i18n.yaml create mode 100644 .agents/flow/issues/bugfix-case-tools-explicit-conclusion.md create mode 100644 .agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.en.md create mode 100644 .agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.i18n.yaml create mode 100644 .agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.md diff --git a/.agents/flow/issues/bugfix-case-tools-explicit-conclusion.en.md b/.agents/flow/issues/bugfix-case-tools-explicit-conclusion.en.md new file mode 100644 index 00000000..2e5c3001 --- /dev/null +++ b/.agents/flow/issues/bugfix-case-tools-explicit-conclusion.en.md @@ -0,0 +1,108 @@ +# Fix the contract mismatch between the case-tools attribution runtime and the explicit-conclusion writer + +English | [中文](bugfix-case-tools-explicit-conclusion.md) + +```yaml flow +kind: issue +id: bugfix-60 +milestone: bugfix +depends: [] +priority: P2 +status: ready +scope: + - apps/api/app/third_party_api/ai_agent/** + - apps/api/tests/** + - .agents/** + - plans/** + - docs/** +adr: [] +github: + number: 608 + url: https://github.com/Shadow-Azure/harness-evolution/issues/608 +``` + +## Background + +### Symptom + +`origin/main` has kept `unit-tests-api` red since `744f4f57` (4 cases); main's own push CI fails the same way, the `ci-ok` aggregate is red, and every PR is blocked: + +- `tests/attribution/test_case_tools.py::test_only_platform_writer_chooses_paths_and_case_identity` — `ValueError: platform writer rejected the report: usage: make_probe_report.py ... --input-badcase ... --bad-case-id`. +- `tests/m5-05-launch-wizard/test_launch_api.py::test_startup_claims_existing_binding_with_shared_provider` — expected `(generation, 0)`, got `(generation, 1)`. +- `test_local_attribution_from_wizard_to_cluster[bubblewrap-bound-bubblewrap]` / `[case-tools-other-case-tools]` — TimeoutError. + +### Root cause: two individually green PRs conflicted semantically at merge time + +- `f9ad7434` (PR #562, merged 03:09Z) added `apps/api/app/third_party_api/ai_agent/attribution_case_tools.py` (the MCP tool channel used on Linux without bwrap) and `tests/attribution/test_case_tools.py`. That channel calls `attribute-badcases/make_probe_report.py` with the **old writer CLI**: only `--probe_object` / `--probe_type` / `--attribute-type` / `--probe-description` / `--probe-analysis` and friends. +- `744f4f57` (PR #589, merged 06:21Z) turned the writer into the **explicit-conclusion contract**: `--conclusion` and `--root-cause` became required, repeatable `--evidence-ref` was added, and the bubblewrap path (`canonical_report`) plus the SKILL instructions were updated; `CaseTools`, `tests/attribution/case_cli_fixture.py`, and `tests/attribution/test_case_tools.py` were **not** updated. +- PR #589's CI ran at 02:03Z–02:16Z on head `6adde1d4`, when the base did not yet contain the CaseTools work from `f9ad7434`, so it was green; it merged four hours later against a base that did contain it, and the repo had **no required status checks**, so the stale green result was trusted (that configuration gap is now closed by the `Protect main` ruleset; the merge-queue follow-up issue tracks the systematic fix). + +Result: the case-tools attribution runtime (and the fixture CLI used by the bubblewrap tests) still calls the new writer with the old CLI, the writer rejects it with a usage error, attribution batches fail, and the launch tests time out. + +### Impact + +- On Linux deployments with `HE_ATTRIBUTION_BWRAP_ENABLED=false` or without bubblewrap, the attribution path is unusable (`CaseTools.write_probe_report` is always rejected by the writer). +- Main CI is red and blocks every PR. + +## Goals + +- Adapt `CaseTools` to the explicit-conclusion writer: `ReportFields` gains `conclusion` (`attributed` / `non_target` / `inconclusive`, required), `root_cause` (required), and `evidence_references` (optional list); pass `--conclusion` / `--root-cause` / repeated `--evidence-ref`, keeping the existing semantics of `probe_object` / `probe_type` / `object_version` / proposal options. +- Update `tests/attribution/case_cli_fixture.py` so both the sandbox and case-tools fixtures supply the new required arguments and evidence references. +- Update `tests/attribution/test_case_tools.py` fields and assertions (verdict, root cause, and evidence references reach the report). +- Restore the four failing cases to green without changing the bubblewrap path or the writer contract. + +## Design authority + +- [07 §5.5.3](../../../plans/fullstack-design/07-backend-implementation.md): the submission channel and the platform writer are deterministic collection contracts; a writer contract change must update every caller. +- [attribute-badcases/make_probe_report.py](../../../attribute-badcases/make_probe_report.py): the single source of truth for the explicit-conclusion CLI (required `--conclusion`/`--root-cause`/`--evidence-ref`, and the `--probe_object` / `--object-version` cross-field rule). + +## Implementation + +- `attribution_case_tools.py`: + - `ReportFields` gains `conclusion: Literal["attributed","non_target","inconclusive"]`, `root_cause: str`, and `evidence_references: list[str] = []`; `extra="forbid"` stays. + - `write_probe_report` argument assembly: `--conclusion`, `--root-cause`, one `--evidence-ref` per reference; `attribute_type`/`probe_description`/`probe_analysis` keep `--attribute-type`/`--probe-description`/`--probe-analysis`; `probe_object`/`probe_type` stay underscore-form, `object_version` uses `--object-version`, proposals use `--proposal-*`, and `detail_description` uses `--detail-description`. + - Reading the case row is unchanged (`bad_case_id` remains platform-owned). +- `case_cli_fixture.py`: the sandbox branch adds `--conclusion attributed --root-cause ... --evidence-ref L1`; the case-tools branch adds `conclusion`/`root_cause`/`evidence_references` to the `report` argument. +- `test_case_tools.py`: the success case asserts `conclusion`/`root_cause`/`evidence_references` reach the report; a `probe_object` differing from the selected target without `--object-version` is still rejected; receipt and symlink-guard assertions stay unchanged. +- Docs: when the writer contract is described in docs, note that the case-tools channel follows the same explicit-conclusion contract. + +## Implementation steps + +1. Change `ReportFields` and the `write_probe_report` argument mapping; run `test_case_tools.py`. +2. Change both `case_cli_fixture.py` calls; run the two parameterized `test_launch_api.py` cases. +3. Run the focused cases and `pnpm test:api -- -k "case_tools or local_runtime or launch_api"` to confirm the four failures are gone. +4. Run `pnpm lint:api`, `pnpm typecheck:api`, `pnpm test:gates`; commit and open the PR. + +## Dependencies and boundary + +- Dependencies: none (`bugfix-57`/`bugfix-58` are unrelated). +- Boundary: only `ai_agent/attribution_case_tools.py` and the related test fixtures/cases; no changes to the writer contract, the bubblewrap/`local_attribution` main path, the report structure, or business verdict semantics. + +## Verification + +```sh +pnpm test:api -- -k "case_tools or local_runtime or launch_api" +pnpm test:api -- -k "m5_05 or attribution" +pnpm lint:api +pnpm typecheck:api +``` + +- Expected: `test_case_tools.py` is green; both the `bubblewrap` and `case-tools` parameterized `test_launch_api.py` cases pass; the `probe_reports` row count and attribution-log assertions are restored; main's `unit-tests-api` turns green. + +## Acceptance + +- A report produced by `CaseTools.write_probe_report` contains `conclusion`/`root_cause`/`evidence_references`, and the writer exits 0. +- The four failing cases pass again; `tests/attribution` and `tests/m5-05-launch-wizard` do not regress. +- The writer's required-field and cross-field rules are unchanged; a `probe_object` differing from the selected target still requires `--object-version`. +- Focused gates and `test:gates` pass; no new dependencies. + +## Gates and CI + +- Hit: `pnpm test:api`, `pnpm lint:api`, `pnpm typecheck:api`, `pnpm test:gates`, `pnpm verify:flow`. +- CI uses fake/stub providers and the fixture CLI; no network and no real `claude` binary. + +## Non-goals + +- No changes to the `make_probe_report.py` CLI or report structure; no restoration of old-field compatibility. +- No changes to the bubblewrap main path, the `local_attribution` verdict logic, or the clustering logic. +- No relaxing of `ReportFields.extra="forbid"` or the path guards. diff --git a/.agents/flow/issues/bugfix-case-tools-explicit-conclusion.i18n.yaml b/.agents/flow/issues/bugfix-case-tools-explicit-conclusion.i18n.yaml new file mode 100644 index 00000000..f8afd053 --- /dev/null +++ b/.agents/flow/issues/bugfix-case-tools-explicit-conclusion.i18n.yaml @@ -0,0 +1,5 @@ +# 双语配对一致性记录(docs/i18n/README.md):两侧在最后一次确认一致状态下的 +# git blob hash。两种语言同等权威;编辑任一侧后带上另一侧,然后重录: +# pnpm run record:i18n -- .agents/flow/issues/bugfix-case-tools-explicit-conclusion.md +bugfix-case-tools-explicit-conclusion.md: 8bb394a8346e1c06cb80a1b7710610bbe02e72e2 +bugfix-case-tools-explicit-conclusion.en.md: 2e5c30013acba650cb8fcc0ec44f9419573435e3 diff --git a/.agents/flow/issues/bugfix-case-tools-explicit-conclusion.md b/.agents/flow/issues/bugfix-case-tools-explicit-conclusion.md new file mode 100644 index 00000000..8bb394a8 --- /dev/null +++ b/.agents/flow/issues/bugfix-case-tools-explicit-conclusion.md @@ -0,0 +1,108 @@ +# 修复 case-tools 归因通道与显式结论 writer 的契约错位 + +[English](bugfix-case-tools-explicit-conclusion.en.md) | 中文 + +```yaml flow +kind: issue +id: bugfix-60 +milestone: bugfix +depends: [] +priority: P2 +status: ready +scope: + - apps/api/app/third_party_api/ai_agent/** + - apps/api/tests/** + - .agents/** + - plans/** + - docs/** +adr: [] +github: + number: 608 + url: https://github.com/Shadow-Azure/harness-evolution/issues/608 +``` + +## 背景 + +### 问题现象 + +`origin/main` 在 `744f4f57` 之后 `unit-tests-api` 持续红(4 个用例),main 自己的 push CI 同样失败,`ci-ok` 聚合红,所有 PR 被连带阻断: + +- `tests/attribution/test_case_tools.py::test_only_platform_writer_chooses_paths_and_case_identity` —— `ValueError: platform writer rejected the report: usage: make_probe_report.py ... --input-badcase ... --bad-case-id`。 +- `tests/m5-05-launch-wizard/test_launch_api.py::test_startup_claims_existing_binding_with_shared_provider` —— 期望 `(generation, 0)` 实得 `(generation, 1)`。 +- `test_local_attribution_from_wizard_to_cluster[bubblewrap-bound-bubblewrap]` / `[case-tools-other-case-tools]` —— TimeoutError。 + +### 根因:两个各自为绿的 PR 在合并时语义冲突 + +- `f9ad7434`(PR #562,03:09Z 合入)新增 `apps/api/app/third_party_api/ai_agent/attribution_case_tools.py`(Linux 无 bwrap 时的 MCP 工具通道)与 `tests/attribution/test_case_tools.py`。该通道按**旧 writer CLI** 调用 `attribute-badcases/make_probe_report.py`:只传 `--probe_object` / `--probe_type` / `--attribute-type` / `--probe-description` / `--probe-analysis` 等。 +- `744f4f57`(PR #589,06:21Z 合入)把 writer 改成**显式结论契约**:`--conclusion`、`--root-cause` 变为必填,新增可重复的 `--evidence-ref`,并同步改了 bubblewrap 路径的 `canonical_report` 与 SKILL 指令;但**没有**更新 `CaseTools`、`tests/attribution/case_cli_fixture.py`、`tests/attribution/test_case_tools.py`。 +- PR #589 的 CI 跑在 02:03Z–02:16Z(head `6adde1d4`),当时 base 还没有 `f9ad7434` 的 CaseTools,因此全绿;4 小时后合入时 base 已包含 CaseTools,但仓库当时**没有 required status checks**,旧绿检查被直接采信(该配置缺口已由 ruleset `Protect main` 补齐,另见 merge queue issue)。 + +结果:case-tools 归因通道(以及 bubblewrap 测试用的 fixture CLI)仍按旧 CLI 调用新 writer,writer 以 usage 错误拒绝,归因批次失败,launch 用例超时。 + +### 影响 + +- 生产上 `HE_ATTRIBUTION_BWRAP_ENABLED=false` / 无 bubblewrap 的 Linux 归因路径不可用(`CaseTools.write_probe_report` 必然被 writer 拒绝)。 +- main CI 红,所有 PR 无法合入。 + +## 目标 + +- `CaseTools` 适配显式结论 writer 契约:`ReportFields` 增加 `conclusion`(`attributed` / `non_target` / `inconclusive`,必填)、`root_cause`(必填)、`evidence_references`(可选列表),并把 `--conclusion` / `--root-cause` / 重复 `--evidence-ref` 传给 writer;保留 `probe_object` / `probe_type` / `object_version` / proposal 等可选参数的既有语义。 +- 更新 `tests/attribution/case_cli_fixture.py`:sandbox 与 case-tools 两种 fixture 调用都提供新必填参数与证据引用。 +- 更新 `tests/attribution/test_case_tools.py` 的字段与断言(结论、根因、证据引用进入报告)。 +- 让 main 的 4 个失败用例恢复绿色;不改变 bubblewrap 路径与 writer 契约本身。 + +## 设计依据 + +- [07 §5.5.3](../../../plans/fullstack-design/07-backend-implementation.md):提交通道与平台 writer 是确定性收货契约;writer 契约变更必须同步所有调用方。 +- [attribute-badcases/make_probe_report.py](../../../attribute-badcases/make_probe_report.py):显式结论 CLI 的唯一事实源(`--conclusion`/`--root-cause`/`--evidence-ref` 必填、`--probe_object` 与 `--object-version` 的跨字段规则)。 + +## 实现内容 + +- `attribution_case_tools.py`: + - `ReportFields` 增加 `conclusion: Literal["attributed","non_target","inconclusive"]`、`root_cause: str`、`evidence_references: list[str] = []`;`extra="forbid"` 保持。 + - `write_probe_report` 参数拼接改为:`--conclusion`、`--root-cause`、每个 `--evidence-ref`;`attribute_type`/`probe_description`/`probe_analysis` 仍走 `--attribute-type`/`--probe-description`/`--probe-analysis`;`probe_object`/`probe_type` 走下划线形式,`object_version` 走 `--object-version`,proposal 走 `--proposal-*`;`detail_description` 走 `--detail-description`。 + - 读取 case 行的方式不变(仍由平台持有 `bad_case_id`)。 +- `case_cli_fixture.py`:sandbox 分支的 writer 调用补 `--conclusion attributed --root-cause ... --evidence-ref L1`;case-tools 分支的 `report` 参数补 `conclusion`/`root_cause`/`evidence_references`。 +- `test_case_tools.py`:成功用例断言 `conclusion`/`root_cause`/`evidence_references` 进入报告;`probe_object` 与选中对象不一致且缺 `--object-version` 仍应被 writer 拒绝;收据与符号链接防护断言保持不变。 +- 文档:若 writer 契约在 docs 中有描述,补一句 case-tools 通道同样遵守显式结论契约。 + +## 实施步骤 + +1. 改 `ReportFields` 与 `write_probe_report` 的参数映射,跑 `test_case_tools.py`。 +2. 改 `case_cli_fixture.py` 两处调用,跑 `test_launch_api.py` 的两个参数化用例。 +3. 跑聚焦用例与 `pnpm test:api -- -k "case_tools or local_runtime or launch_api"`,确认 4 个失败用例恢复。 +4. 跑 `pnpm lint:api`、`pnpm typecheck:api`、`pnpm test:gates`,提交并走 PR。 + +## 依赖与交付边界 + +- 依赖:无(`bugfix-57`/`bugfix-58` 等无关)。 +- 交付边界:只改 `ai_agent/attribution_case_tools.py` 与相关测试 fixture/用例;不改 writer 契约、不改 bubblewrap/`local_attribution` 主路径、不改报告结构与业务判定语义。 + +## 独立验证 + +```sh +pnpm test:api -- -k "case_tools or local_runtime or launch_api" +pnpm test:api -- -k "m5_05 or attribution" +pnpm lint:api +pnpm typecheck:api +``` + +- 预期:`test_case_tools.py` 全绿;`test_launch_api.py` 的 `bubblewrap` 与 `case-tools` 参数化用例通过;`probe_reports` 行数与归因日志断言恢复;main 的 `unit-tests-api` 转绿。 + +## 验收标准 + +- `CaseTools.write_probe_report` 生成的新报告包含 `conclusion`/`root_cause`/`evidence_references`,writer 退出码 0。 +- 4 个失败用例恢复通过;`tests/attribution` 与 `tests/m5-05-launch-wizard` 无回归。 +- 不改变 writer 的必填/跨字段规则;`probe_object` 与选中对象不一致时仍要求 `--object-version`。 +- 聚焦门禁与 `test:gates` 通过;无新增依赖。 + +## 门禁与 CI + +- 命中:`pnpm test:api`、`pnpm lint:api`、`pnpm typecheck:api`、`pnpm test:gates`、`pnpm verify:flow`。 +- CI 使用 fake/stub 与 fixture CLI,不触网、不依赖真实 `claude`。 + +## 非目标 + +- 不改 `make_probe_report.py` 的 CLI/报告结构;不恢复旧字段兼容。 +- 不改 bubblewrap 主路径、`local_attribution` 的结论判定与聚类逻辑。 +- 不放宽 `ReportFields.extra="forbid"` 或路径防护。 diff --git a/.agents/flow/issues/bugfix-explicit-skill-conclusion.en.md b/.agents/flow/issues/bugfix-explicit-skill-conclusion.en.md index 2283275d..a43a4cce 100644 --- a/.agents/flow/issues/bugfix-explicit-skill-conclusion.en.md +++ b/.agents/flow/issues/bugfix-explicit-skill-conclusion.en.md @@ -4,11 +4,11 @@ English | [中文](bugfix-explicit-skill-conclusion.md) ```yaml flow kind: issue -id: bugfix-56 +id: bugfix-58 milestone: bugfix depends: [] priority: P2 -status: in-progress +status: done scope: - attribute-badcases/** - apps/api/app/service/evolution/local_attribution.py diff --git a/.agents/flow/issues/bugfix-explicit-skill-conclusion.i18n.yaml b/.agents/flow/issues/bugfix-explicit-skill-conclusion.i18n.yaml index 4364ccb0..fd0d1344 100644 --- a/.agents/flow/issues/bugfix-explicit-skill-conclusion.i18n.yaml +++ b/.agents/flow/issues/bugfix-explicit-skill-conclusion.i18n.yaml @@ -1,5 +1,5 @@ # 双语配对一致性记录(docs/i18n/README.md):两侧在最后一次确认一致状态下的 # git blob hash。两种语言同等权威;编辑任一侧后带上另一侧,然后重录: # pnpm run record:i18n -- .agents/flow/issues/bugfix-explicit-skill-conclusion.md -bugfix-explicit-skill-conclusion.md: 2e4cbe6321c91fe1c9f2934df759c78c64f6d3be -bugfix-explicit-skill-conclusion.en.md: 2283275dda6b71bc2365277dd3f1ec2a5ae6635b +bugfix-explicit-skill-conclusion.md: 36d66349f591bd0719dc87ad1b1d03eaa1bcdce4 +bugfix-explicit-skill-conclusion.en.md: a43a4ccee06f0d8c47a5dcebdf347ba2b972680b diff --git a/.agents/flow/issues/bugfix-explicit-skill-conclusion.md b/.agents/flow/issues/bugfix-explicit-skill-conclusion.md index 2e4cbe63..36d66349 100644 --- a/.agents/flow/issues/bugfix-explicit-skill-conclusion.md +++ b/.agents/flow/issues/bugfix-explicit-skill-conclusion.md @@ -4,11 +4,11 @@ ```yaml flow kind: issue -id: bugfix-56 +id: bugfix-58 milestone: bugfix depends: [] priority: P2 -status: in-progress +status: done scope: - attribute-badcases/** - apps/api/app/service/evolution/local_attribution.py diff --git a/.agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.en.md b/.agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.en.md new file mode 100644 index 00000000..8084959a --- /dev/null +++ b/.agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.en.md @@ -0,0 +1,30 @@ +# Agent Note: adapt the case-tools attribution channel to the explicit-conclusion writer + +Status: implemented + +English | [中文](2026-11-25-case-tools-explicit-conclusion.md) + +## Problem + +After `744f4f57`, `origin/main` kept `unit-tests-api` red (4 cases), the `ci-ok` aggregate was red, and every PR was blocked. The root cause was a semantic conflict between two individually green PRs: PR #562 (`f9ad7434`, 03:09Z) added `CaseTools`, which called `make_probe_report.py` with the old writer CLI (`--probe_object`/`--probe_type`/`--attribute-type` and friends); PR #589 (`744f4f57`, 06:21Z) turned the writer into the explicit-conclusion contract (`--conclusion`/`--root-cause` required, repeatable `--evidence-ref`), updated the bubblewrap path and the SKILL instructions, but did not update `CaseTools` or its fixtures. PR #589's CI ran at 02:03Z–02:16Z (base without CaseTools) and merged four hours later; `Protect main` had no required status checks at the time, so the stale green result was trusted. Consequently the case-tools channel was always rejected by the writer with a usage error, and both the bubblewrap and case-tools launch cases timed out. + +## Decision + +- `CaseTools.ReportFields` gains required `conclusion` (`attributed`/`non_target`/`inconclusive`) and `root_cause`, plus optional `evidence_references`; `probe_object`/`probe_type` become optional and are supplied only when a causal object is identified. +- `write_probe_report` no longer builds flags from `model_dump`; it passes `--conclusion`/`--root-cause`/repeated `--evidence-ref` explicitly and keeps the existing `--probe_object`/`--probe_type`/`--object-version`/proposal semantics. The writer contract and the bubblewrap main path are unchanged. Every argument uses the `--flag=value` form: model-provided text such as `probe_description` may start with `--`, which argparse would mistake for an option in the separated form. +- Both branches of `tests/attribution/case_cli_fixture.py` supply the new arguments; `tests/attribution/test_case_tools.py` asserts that the verdict, root cause, and evidence references reach the report. +- The same PR repairs the main flow-tree drift (`bugfix-56` duplicate → `bugfix-58`; #588 `in-progress` → `done`); otherwise no PR can turn `docs-flow`/`flow-online` green. #605 will rebase and drop the duplicated hunks after this PR merges. +- Repo governance in parallel: `Protect main` now requires `ci-ok` with `strict: true`; the merge queue follows in issue #609. + +## Alternatives considered + +- **Revert the writer to the old contract**: rejected. Explicit conclusions are the product requirement from #588; reverting would undo the shipped attribution semantics. +- **Fix only the tests, not `CaseTools`**: rejected. The production case-tools channel calls the old contract too; leaving it would only hide an unusable runtime. +- **Split into two PRs (flow repair + code fix)**: rejected. They block each other: the flow PR needs green unit tests to merge, and the code PR needs the flow tree to pass `docs-flow`/`flow-online`; a single repair PR is the only self-consistent path. +- **Use the admin bypass to merge #605 first**: rejected. Bypassing the required checks right after adding them contradicts the governance goal; fixing the code and tests first lets the flow PR rebase normally. + +## Consequences + +- The case-tools attribution channel regains explicit-conclusion support, the four failing cases pass, and main's `unit-tests-api` can turn green. +- This PR temporarily carries the flow-drift repair; after rebasing, #605 only keeps the AI-agent backend issue file. +- Until the merge queue lands, `strict` still forces a manual rebase plus a full re-run whenever the base moves; that friction is the next governance item in #609. diff --git a/.agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.i18n.yaml b/.agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.i18n.yaml new file mode 100644 index 00000000..eba22038 --- /dev/null +++ b/.agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.i18n.yaml @@ -0,0 +1,5 @@ +# 双语配对一致性记录(docs/i18n/README.md):两侧在最后一次确认一致状态下的 +# git blob hash。两种语言同等权威;编辑任一侧后带上另一侧,然后重录: +# pnpm run record:i18n -- .agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.md +2026-11-25-case-tools-explicit-conclusion.md: 2fb82afcf1f48c71d11770f77852b8c5e1002a52 +2026-11-25-case-tools-explicit-conclusion.en.md: 8084959ad5436080845b5df9d6d8a606e377b988 diff --git a/.agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.md b/.agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.md new file mode 100644 index 00000000..2fb82afc --- /dev/null +++ b/.agents/notes/implemented/bug-fix/2026-11-25-case-tools-explicit-conclusion.md @@ -0,0 +1,30 @@ +# Agent Note: case-tools 归因通道适配显式结论 writer + +Status: implemented + +[English](2026-11-25-case-tools-explicit-conclusion.en.md) | 中文 + +## Problem + +`origin/main` 在 `744f4f57` 之后 `unit-tests-api` 持续红(4 个用例),`ci-ok` 聚合红,所有 PR 被阻断。根因是两个各自为绿的 PR 在合并时语义冲突:PR #562(`f9ad7434`,03:09Z)新增 `CaseTools`,按旧 writer CLI(`--probe_object`/`--probe_type`/`--attribute-type` 等)调用 `make_probe_report.py`;PR #589(`744f4f57`,06:21Z)把 writer 改成显式结论契约(`--conclusion`/`--root-cause` 必填、`--evidence-ref` 可重复),同步改了 bubblewrap 路径与 SKILL 指令,却没有更新 `CaseTools` 与 fixture。PR #589 的 CI 跑在 02:03Z–02:16Z(base 尚无 CaseTools),4 小时后才合入;当时 `Protect main` 没有 required status checks,旧绿检查被直接采信。结果是 case-tools 通道必然被 writer 以 usage 错误拒绝,bubblewrap/case-tools 两条 launch 用例超时。 + +## Decision + +- `CaseTools.ReportFields` 增加必填 `conclusion`(`attributed`/`non_target`/`inconclusive`)与 `root_cause`、可选 `evidence_references`;`probe_object`/`probe_type` 改为可选,仅在指认因果对象时提供。 +- `write_probe_report` 不再用 `model_dump` 批量拼 flag,而是显式传递 `--conclusion`/`--root-cause`/重复 `--evidence-ref`,并保留 `--probe_object`/`--probe_type`/`--object-version`/proposal 的既有语义;writer 契约与 bubblewrap 主路径不改。所有参数统一用 `--flag=value` 形式:模型提供的 `probe_description` 等文本可能以 `--` 开头,argparse 会把分隔形式的值误判为选项。 +- `tests/attribution/case_cli_fixture.py` 的 sandbox 与 case-tools 两个分支同步新参数;`tests/attribution/test_case_tools.py` 断言结论/根因/证据引用进入报告。 +- 同一 PR 修正 main 的流程树漂移(`bugfix-56` 重复 → `bugfix-58`;#588 状态 `in-progress` → `done`),否则任何 PR 的 `docs-flow`/`flow-online` 都无法转绿;#605 将在本 PR 合入后 rebase 并去掉重复 hunk。 +- 仓库治理同步:`Protect main` 已补 `required_status_checks`(`ci-ok`,`strict: true`);merge queue 另立 issue #609。 + +## Alternatives considered + +- **把 writer 回退到旧契约**:拒绝。显式结论是 #588 的产品需求,回退会撤销已上线的归因语义。 +- **只改测试、不改 `CaseTools`**:拒绝。case-tools 通道在生产上同样按旧契约调用,测试不改只是掩盖生产不可用。 +- **拆成两个 PR(流程修复 + 代码修复)**:拒绝。两者互相阻塞:流程 PR 需要单测绿才能合,代码 PR 需要流程绿才能过 `docs-flow`/`flow-online`;合一的修复 PR 是唯一能自洽的路径。 +- **用管理员 bypass 先合 #605**:拒绝。刚补上 required checks 就用逃生通道违背治理目标;先修代码与测试,再让流程 PR 正常 rebase。 + +## Consequences + +- case-tools 归因通道恢复显式结论能力,4 个失败用例恢复绿色,main 的 `unit-tests-api` 可转绿。 +- 本 PR 临时包含流程漂移修复;#605 rebase 后只保留 AI Agent 后端可替换 issue 文件。 +- merge queue 落地前,`strict` 会在 base 前进时要求手动 rebase + 全量重跑,仍有摩擦;这是 #609 要解决的下一个治理项。 diff --git a/apps/api/app/third_party_api/ai_agent/attribution_case_tools.py b/apps/api/app/third_party_api/ai_agent/attribution_case_tools.py index 262cfa20..780073fb 100644 --- a/apps/api/app/third_party_api/ai_agent/attribution_case_tools.py +++ b/apps/api/app/third_party_api/ai_agent/attribution_case_tools.py @@ -27,8 +27,11 @@ class ReportFields(BaseModel): """Analysis fields accepted by the platform writer. Paths and case ID belong to the server.""" model_config = ConfigDict(extra="forbid", strict=True) - probe_object: str - probe_type: Literal["skill", "agent", "knowledge"] = "skill" + conclusion: Literal["attributed", "non_target", "inconclusive"] + root_cause: str + evidence_references: list[str] = [] + probe_object: str | None = None + probe_type: Literal["skill", "agent", "knowledge"] | None = None object_version: str | None = None attribute_type: Literal["prompt", "model", "error", "flow", "context", "unknown"] probe_description: str @@ -100,15 +103,38 @@ def write_probe_report(self, report: ReportFields) -> str: sys.executable, "-I", str(writer), - "--input-badcase", - str(input_path), + f"--input-badcase={input_path}", f"--bad-case-id={case['bad_case_id']}", - "--output", - str(output), + f"--conclusion={report.conclusion}", + f"--root-cause={report.root_cause}", + f"--output={output}", + *(f"--evidence-ref={reference}" for reference in report.evidence_references), ] - for name, value in report.model_dump(exclude_none=True).items(): - flag = name if name in {"probe_type", "probe_object"} else name.replace("_", "-") - args.append(f"--{flag}={value}") + if report.probe_object is not None: + args.append(f"--probe_object={report.probe_object}") + if report.probe_type is not None: + args.append(f"--probe_type={report.probe_type}") + if report.object_version is not None: + args.append(f"--object-version={report.object_version}") + args.extend( + ( + f"--attribute-type={report.attribute_type}", + f"--probe-description={report.probe_description}", + f"--probe-analysis={report.probe_analysis}", + ), + ) + if report.detail_description is not None: + args.append(f"--detail-description={report.detail_description}") + for name, flag in ( + ("proposal_target_skill", "--proposal-target-skill"), + ("proposal_target_location", "--proposal-target-location"), + ("proposal_change", "--proposal-change"), + ("proposal_expected_behavior", "--proposal-expected-behavior"), + ("proposal_evaluation_plan", "--proposal-evaluation-plan"), + ): + value = getattr(report, name) + if value is not None: + args.append(f"{flag}={value}") result = subprocess.run( # noqa: S603 - the verified shim and both paths are platform-owned. args, cwd=self.work, diff --git a/apps/api/tests/attribution/case_cli_fixture.py b/apps/api/tests/attribution/case_cli_fixture.py index 1734f1cc..3482ed55 100644 --- a/apps/api/tests/attribution/case_cli_fixture.py +++ b/apps/api/tests/attribution/case_cli_fixture.py @@ -28,6 +28,12 @@ async def _write_sandbox_report(args: list[str]) -> None: "input_badcase.json", "--bad-case-id", row["bad_case_id"], + "--conclusion", + "attributed", + "--root-cause", + "fixture cause", + "--evidence-ref", + "fixture:L1", "--probe_object", row["object"], "--probe_type", @@ -78,6 +84,9 @@ async def _write_case_tool_report(args: list[str]) -> None: "write_probe_report", { "report": { + "conclusion": "attributed", + "root_cause": "fixture cause", + "evidence_references": ["fixture:L1"], "probe_object": row["object"], "probe_type": row["type"], "attribute_type": "flow", diff --git a/apps/api/tests/attribution/test_case_tools.py b/apps/api/tests/attribution/test_case_tools.py index 938e704d..6dc15353 100644 --- a/apps/api/tests/attribution/test_case_tools.py +++ b/apps/api/tests/attribution/test_case_tools.py @@ -91,6 +91,9 @@ def test_only_frozen_evidence_and_selected_skill_are_readable(case: Path) -> Non def test_only_platform_writer_chooses_paths_and_case_identity(case: Path) -> None: fields = { + "conclusion": "attributed", + "root_cause": "fixture cause", + "evidence_references": ["fixture:L1"], "probe_object": "reporter", "probe_type": "agent", "attribute_type": "context", @@ -109,6 +112,9 @@ def test_only_platform_writer_chooses_paths_and_case_identity(case: Path) -> Non report = json.loads(output.read_bytes()) assert report["from_bad_cases"][0]["bad_case_id"] == "case-one" assert report["probe_description"] == fields["probe_description"] + assert report["conclusion"] == "attributed" + assert report["root_cause"] == "fixture cause" + assert report["evidence_references"] == ["fixture:L1"] assert json.loads((case / ".platform/receipt.json").read_bytes()) == { "path": output.name, "sha256": hashlib.sha256(output.read_bytes()).hexdigest(),