Skip to content
Draft
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
18 changes: 17 additions & 1 deletion doc/architecture/SPEC/direct_routing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# direct_routing.py —— 规范

<!-- verified-against: 2026-10-08 -->
<!-- verified-against: 2026-11-15 -->

`LOC ~880 · Direct 模式完整策略包与仓库中立的知识路由 · refactor-status: stable`

Expand All @@ -23,6 +23,15 @@ Direct policy bundle)、`direct_knowledge_routes`、
`thin_mcp_server` 既有调用点/测试使用(它继续直接 import 下划线名)。

## 不变量
- **Direct negative-claim evidence**: the canonical `first_review_checklist`
requires tracing concrete production callers, subclass/keyword forwarding
and the consumer before claiming a missing input or effect. Cleanup claims
inspect the actual library callee at the applicable version/platform and
check success/exception ownership before proposing potentially duplicate,
non-idempotent cleanup. Unreadable source or unverified dependencies remain
explicit evidence gaps, not proof of absence; independently demonstrated
reachable defects remain reportable. This is host guidance carried by the
raw plan and SDK serialization, not a new completion field or semantic gate.
- **repo 守卫最先跑**:不支持的仓库在任何路由计算之前被拒 —— 修的是一个
真实历史 bug(守卫曾排在空 intent 提前返回之后,向不支持的仓库泄漏
owner 知识)。
Expand Down Expand Up @@ -78,6 +87,12 @@ stdlib + PyYAML + `.adapters`(AdapterError / AdapterRegistry / RepoAdapter)+
旧 bundle 的 6,000 字符相关背景预算保持不变。

## 测试
`test_sdk_v1.py::test_direct_plan_carries_negative_claim_tracing_guidance`
checks that the public SDK plan and its serialized checklist retain the
canonical caller/callee, cleanup-safety and evidence-limit guidance. This
is a prompt-delivery regression, not proof of model compliance or a measured
review-quality improvement.

`test_knowledge_view_routing.py`(150 个真实 vllm-omni PR 的黄金路由输出、
第二仓库经自身 `_routes.yaml` 路由、快照切换下一请求生效、快照篡改 fail-closed、
SDK 完成校验钉住计划时快照、模块源码不含仓库名);`test_contract.py`(公开家、import 方向、中立性豁免);
Expand All @@ -94,3 +109,4 @@ SDK 完成校验钉住计划时快照、模块源码不含仓库名);`test_c
Route-table validation checks unused navigation targets for integrity without serving their content. Selected owner/model reads pass `KnowledgeView.path` and current containment. Quickmap extraction first removes retired rules. Related retrieval excludes specifically held pages; invalid or stale policy still fails the request closed.

With containment enabled, the raw `direct_review_plan` also returns a private-registry-backed `knowledge_usage` receipt for its selected route, procedure, and related-document dependencies. It binds a private delivery session for later raw document reads/searches without claiming model injection inside the planner. The public `direct_completion_result` requires that receipt and rechecks all original and follow-up issued resources against the current policy. Missing, forged, stale, or held provenance returns `partial_review` with `publish_ready=false`; the original structural evidence checks remain in force. The SDK forwards its own issued context receipt to the same gate. Disabled deployments retain the existing bundle and completion result shape.

4 changes: 4 additions & 0 deletions src/infermatrix_copilot/direct_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def _validate_routes(data: object, relative: str, view: KnowledgeView) -> dict:
"When the PR is a bugfix (title, labels, or linked issue), require a regression test that pins the original failure path; happy-path-only additions do not count, and a missing pin becomes an explicit blocking or non-blocking finding, never silence.",
"Check the PR body's Test Plan and Test Result against the CI definition at the frozen head: name the guard steps whose declared source dependencies cover the changed paths, then compare their commands with what the PR reports running by selector — test targets, marker expression, run level — not by literal text. A guard step never run, a dropped marker, or absent test evidence is a blocking finding naming the step and both commands.",
"When the diff passes a new argument to a dependency, check it against the lowest version the project's own constraints still permit, not the version installed here.",
"Before claiming an input is never forwarded or an effect never occurs, trace the concrete production caller through subclass overrides, explicit keywords, **kwargs and super() to the consumer; cite the decisive caller/callee locations at the frozen head, not just a local search or test stub.",
"For cleanup claims, inspect the actual callee, including standard-library/dependency code, at the applicable version and platform; distinguish success and exception paths and identify who already owns each side effect. Before suggesting extra cleanup, check whether it duplicates unregister, release, close or other non-idempotent work.",
"If a relevant caller, callee, dependency version or platform cannot be verified with available tools, keep that claim unresolved and state the exact evidence gap; do not infer absence from unreadable or sparse source. Preserve independently demonstrated reachable defects rather than suppressing them because another path is safe.",
"For resource or cache changes, trace budget measurement through reservation and physical consumption, including warmup/profile/activation ordering and low-resource behavior.",
"For runtime changes, trace exception propagation, partial-allocation cleanup, cancellation, timeout, shutdown, and concurrent scheduling to the terminal user-visible signal.",
"At native dependency boundaries, verify the pinned API contract and caller inputs; native reuse does not prove the caller's budget, ordering, adapter, or lifecycle correctness.",
Expand Down Expand Up @@ -971,3 +974,4 @@ def _direct_completion_result(
direct_execution_budget = _direct_execution_budget
direct_completion_result = _direct_completion_result
direct_mandatory_review_guides = _direct_mandatory_review_guides

27 changes: 27 additions & 0 deletions test/test_sdk_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ def test_direct_plan_is_typed_complete_and_path_free():
assert document["sha256"].startswith("sha256:")


def test_direct_plan_carries_negative_claim_tracing_guidance():
# Prompt delivery only: no model is asked to apply these instructions.
from infermatrix_copilot.direct_routing import DIRECT_REVIEW_CHECKLIST

plan = DirectClient().plan(
_request("vllm-omni", "vllm_omni/core/sched/scheduler.py")
)
checklist = plan.to_dict()["first_review_checklist"]
assert tuple(checklist) == DIRECT_REVIEW_CHECKLIST
caller = next((item for item in checklist if "Before claiming an input" in item), "")
for evidence in ("concrete production caller", "subclass overrides",
"explicit keywords", "**kwargs", "super()", "consumer",
"decisive caller/callee locations", "frozen head"):
assert evidence in caller
cleanup = next((item for item in checklist if "For cleanup claims" in item), "")
for evidence in ("actual callee", "standard-library/dependency code",
"version and platform", "success and exception paths",
"owns each side effect", "duplicates unregister",
"non-idempotent"):
assert evidence in cleanup
limits = next((item for item in checklist if "keep that claim unresolved" in item), "")
for evidence in ("available tools", "exact evidence gap", "sparse source",
"Preserve independently demonstrated reachable defects"):
assert evidence in limits


def test_second_adapter_routes_from_packaged_adapter_registry():
plan = DirectClient().plan(
_request("afd-plugin", "afd_plugin/compat/vllm.py")
Expand Down Expand Up @@ -467,3 +493,4 @@ def test_strict_reservation_carries_evidence_through_policy(settings):
from infermatrix_copilot.mcp_policy import enforce_mcp_policy
spec = enforce_mcp_policy(payload, allowed_repos=["vllm-omni"])
assert spec.params["carried_findings"] == [_carried().to_dict()]

Loading