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
8 changes: 6 additions & 2 deletions docs/guides/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ arguments until no continuation remains. Each page records only its returned
bytes, with UTF-8 boundaries preserved. The continuation keeps the same
resource, revision and search reference.
Cite a used read's `reference.path` with `round --knowledge-ref` in a one-shot
project or benchmark. A service-reuse attempt retains prepared contexts
automatically. Record any passage that influenced the candidate in its
project or benchmark. A `service_reuse` round also accepts a local Read receipt

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.

这里已经把 service-reuse 的同 session/current epoch Read 写进指南了,但同一提交的 session round --help 还写「benchmark or AB/BA」,并把 CANNBot 与本地 Read 并列。直接从 CLI 找入口的人会以为 service-reuse 仍不支持,或误用 CANNBot。建议同步 apps/cli/arguments.py,明确 service-reuse 仅接受本地 Read,并在 help 测试中卡住两种模式的区别。

from the same session and the current reference epoch. The citation is stored
on that attempt and listed by `session status`; each retry records its own.
Find receipts, receipts from other sessions and stale receipts are refused
before the round launches. A successful reference refresh or stage switch
starts a new epoch. Record any passage that influenced the candidate in its
hypothesis. If the host clipped an asynchronous round's response, use
`session status --session DIR --round-receipt N` before closing the archive.
It reads the verified observation for completed round N.
Expand Down
9 changes: 6 additions & 3 deletions src/inferrsi/apps/cli/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,12 @@ def _optimization_actions(stages, *, project=False, historical=False, typed_star
"benchmark or AB/BA campaign)")
stage.add_argument("--selection-reason",
help="Why this candidate was chosen to try (benchmark or AB/BA)")
stage.add_argument("--knowledge-ref", action="append",
help="Cite a read receipt in a benchmark or AB/BA campaign round "
"(path, path#item-ref, or CANNBot receipt; repeatable)")
stage.add_argument(
"--knowledge-ref", action="append", metavar="RECEIPT",
help="Cite a delivered receipt for this round (repeatable). A one-shot "
"benchmark or AB/BA round accepts a path, path#item-ref or CANNBot "
"read receipt; a service-reuse round accepts only a local Read "
"receipt from this session and the current reference epoch")
stage.add_argument("--mechanism-file", type=Path,
help="JSON mechanism with expected region/counter directions")
if project:
Expand Down
3 changes: 2 additions & 1 deletion src/inferrsi/harness/manager/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ def run_session(
if getattr(request, "alternative", None) is not None or getattr(
request, "selection_reason", None) is not None:
raise ValueError("Round decision declarations require a benchmark or AB/BA campaign")
if getattr(request, "knowledge_ref", None) is not None:
if (getattr(request, "knowledge_ref", None) is not None
and request.action != "round"):
raise ValueError("Round knowledge references require a benchmark or AB/BA campaign")
result = state.service_command(root, request, ranking_policy_for=ranking_policy_for)
if request.action in ("round", "recover"):
Expand Down
80 changes: 79 additions & 1 deletion src/inferrsi/harness/manager/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,12 @@ def _commit_knowledge(root, ticket, delivery, *, external_search=None, retained_
if (context.get("retrieval", {}).get("entrypoint") == "read"
or (request.get("mode") == "pinned_selection" and "search_ref" in request)):
retained["search_ref"] = request["search_ref"]
service_mode = plan.get("evaluation_mode") == "service_reuse"
if "stage_id" in state:
retained.update(reference_epoch=ticket.reference_epoch, stage_id=state["stage_id"])
service_mode = plan.get("evaluation_mode") == "service_reuse"
elif service_mode:
# Prove a later round citation against the epoch that delivered the material.
retained["reference_epoch"] = ticket.reference_epoch
if service_mode:
service_io.no_fingerprints(context)
path = service_io.safe_path(root, reference["path"])
Expand Down Expand Up @@ -977,6 +980,61 @@ def _validate_knowledge_refs(root, contexts, refs):
raise ValueError("Cite a scoped Read receipt; legacy captures are audit-only")


def _validate_service_round_refs(root, state, refs):
"""Accept only local Read receipts of this session and reference epoch.

The registered context path is the whole same-session check: another
session's receipt, an unknown path or a traversal attempt never resolves.
"""
if not isinstance(refs, list) or any(not isinstance(ref, str) for ref in refs):
raise ValueError("Knowledge references must be a list of delivered references")
if len(set(refs)) != len(refs):
raise ValueError("Cite unique delivered knowledge references")
registered = {entry["path"]: entry for entry in state["contexts"]}
searches = {entry["path"] for entry in state["contexts"]
if entry.get("kind") == "knowledge_search"}
epoch = state.get("reference_epoch")
for ref in refs:
path, separator, item = ref.partition("#")
reference = registered.get(path)
if reference is None:
raise ValueError("Cite a Read receipt retained by this service-reuse session")
if reference.get("kind") != "delivered_context":
raise ValueError("Cite a local Read receipt, not a Find or external result")
search_ref = reference.get("search_ref")
if not isinstance(search_ref, str) or search_ref not in searches:
raise ValueError("Cite a local Read receipt retained from a registered Find")
if reference.get("reference_epoch") != epoch:
raise ValueError(
"Cite a Read receipt from the current reference epoch; "
"read the material again after refreshing references"
)
if "stage_id" in state and reference.get("stage_id") != state["stage_id"]:
raise ValueError("Cite a Read receipt from the current evaluation stage")
capture = service_io.read(service_io.safe_path(root, path))
retrieval, request = capture.get("retrieval"), capture.get("request")
if (
not isinstance(retrieval, dict) or retrieval.get("entrypoint") != "read"
or not isinstance(request, dict) or request.get("search_ref") != search_ref
):
raise ValueError("Cite a scoped Read receipt from this service-reuse session")
contexts = capture.get("contexts")
if not isinstance(contexts, list) or not any(
isinstance(entry, dict)
and any(
isinstance(resource, dict) and resource.get("content")
for resource in entry.get("resources") or ()
)
for entry in contexts
):
raise ValueError("Cite a Read receipt that delivered resources")
if separator and not any(
isinstance(entry, dict) and entry.get("ref") == item for entry in contexts
):
raise ValueError("Cite an item delivered by this Read receipt")
return list(refs)


def _usage_record(source, *, fingerprint=True):
if source is None:
return {"usage": None, "tool_calls": None, "usage_source": None}, None
Expand Down Expand Up @@ -2288,6 +2346,15 @@ def _service_load(root, plan, state, *, read_only=False, observed_contexts=None)
raise ValueError("Retained attempt and control record disagree")
if attempt["kind"] == "round":
_check_activity_diagnosis(plan, diagnoses, attempt)
if attempt.get("knowledge_refs"):
submitted = {ref["path"]: ref for ref in attempt.get("contexts", ())}
known = {context["path"]: context for context in state["contexts"]}
for citation in attempt["knowledge_refs"]:
path = citation.partition("#")[0]
if path not in submitted or submitted[path] != known.get(path):
raise ValueError(
"Cited knowledge receipt is absent from the attempt snapshot"
)
for attempt in state.get("unrun_attempts", ()):
if not service_observations.matches_control(root, attempt):
raise ValueError("Retained static-only attempt and control record disagree")
Expand Down Expand Up @@ -3224,6 +3291,8 @@ def _service_status_with_rounds(root, plan, state):
"attempt_id": attempt["attempt_id"],
"verdict": attempt["assessment"]["verdict"],
"profiling": _service_profiling(root, attempt),
**({"knowledge_refs": attempt["knowledge_refs"]}
if attempt.get("knowledge_refs") else {}),
}
for number, attempt in latest_by_round.items()
]
Expand Down Expand Up @@ -3455,6 +3524,13 @@ def service_command(root, request, *, ranking_policy_for=None):
}.get(action)
if kind is None:
raise ValueError("Unknown service campaign action")
submitted_refs = getattr(request, "knowledge_ref", None)
if submitted_refs is not None and action != "round":
raise ValueError("Round knowledge references require a benchmark or AB/BA campaign")
refs = (
_validate_service_round_refs(root, state, submitted_refs)
if submitted_refs is not None else None
)
initial, parent = state["initial_reference"], state["comparison_parent"]
admission = None
transition = None
Expand Down Expand Up @@ -3650,6 +3726,8 @@ def service_command(root, request, *, ranking_policy_for=None):
"contexts": list(state["contexts"]),
"admission_failure": admission,
}
if refs is not None:
pending["knowledge_refs"] = refs
pending.update(stages.binding(state, plan))
if "stage_id" in state:
pending["contexts"] = [c for c in state["contexts"]
Expand Down
Loading
Loading