Skip to content
Open
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
15 changes: 15 additions & 0 deletions docs/guides/optimization-workflow-unification.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@ Python 调用者从 `inferrsi.harness.analyzer` 导入 `diagnosis_draft`,从
`inferrsi.harness.indexer` 导入 `resolve_frozen_ranking`。此前后者位于
`inferrsi.harness.optimization`。[组件接口与会话时序](../../src/inferrsi/harness/README.md#managed-session-interfaces)

### 独立验收失败后继续搜索

普通 AB/BA 项目可在 `campaign start --round-mode up_to` 时加上
`--allow-final-continuation`。独立 `final` 完成并得出 `FAIL` 后,`campaign status`
会报告 `can_continue` 和 `current_final_attempt_id`。若仍有轮次和搜索时间,可提交一次显式续跑。

```bash
inferrsi campaign round --directory <campaign-dir> --candidate <editable-project> \
--hypothesis '<what-and-why>' --continue-after-final <current-final-attempt-id> \
--continuation-reason '<why-search-continues>'
```

续跑沿用原冻结协议、截止时间、轮次上限和 `final` 预留。状态、摘要、看板和导出保留
每次独立 `final` 的证据。最近一次确定判定仍是当前结果,直至得到新的确定判定。

### 用 profile 解释改进(可选)

端到端时间会随时钟、温度和共享负载整体漂移,单凭数值很难区分真实改进与波动。测量脚本可以在结果 JSON 中额外输出同一步骤的分区域耗时和工作量计数,单位由脚本自定并在各步骤保持一致:
Expand Down
4 changes: 2 additions & 2 deletions src/inferrsi/apps/cli/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _optimization_actions(stages, *, project=False):
start.add_argument("--round-mode", choices=("exact", "up_to"), default="up_to")
start.add_argument(
"--allow-final-continuation", action="store_true",
help="Allow one explicit continuation after a failed up-to-budget service final",
help="Allow one explicit continuation after a failed up-to-budget project final",
)
else:
start.add_argument("task")
Expand Down Expand Up @@ -259,7 +259,7 @@ def _optimization_actions(stages, *, project=False):
help="JSON mechanism with expected region/counter directions")
if project:
stage.add_argument("--continue-after-final", metavar="ATTEMPT_ID",
help="Reopen a service campaign after this failed final")
help="Reopen a project campaign after this failed final")
stage.add_argument("--continuation-reason",
help="Why search should continue after the failed final")
if name == "final":
Expand Down
61 changes: 41 additions & 20 deletions src/inferrsi/apps/delivery/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ def iterative(snapshot, result):
gap(result, "FROZEN_INPUTS_CHANGED", "final_acceptance", "Frozen file set changed")
for context in state.get("contexts", []):
snapshot.file(context["path"], "knowledge", context.get("sha256"))
best = state.get("best")
final = state.get("final")
best = (final or {}).get("selected_at_final", state.get("best"))
baseline = snapshot.candidate(plan["baseline_path"], plan.get("baseline_sha256"))
result["baseline"] = {**baseline, "configuration": plan.get("evaluation_settings")}
selected = None
Expand All @@ -365,17 +366,21 @@ def iterative(snapshot, result):
"configuration": plan.get("evaluation_settings"),
}
rounds = state.get("rounds", [])
final = state.get("final")
keep_history = plan.get("allow_final_continuation") is True
final_records = state.get("final_attempts", ()) if keep_history else ([final] if final else [])
if keep_history:
result["final_attempts"] = []
parsed = []
final_value = None
final_refs = []
final_candidate = None
final_observation = None
final_assessment_verified = False
latest_final_complete = False
latest_final_verified = False
result["rounds"], result["metrics"], result["checks"] = [], [], []
records = [*rounds, *([final] if final else [])]
records = [*rounds, *final_records]
for index, record in enumerate(records):
is_final = index == len(rounds)
is_final = index >= len(rounds)
phase = "final" if is_final else "search"
directory = record["path"]
observation, ref = snapshot.object(
Expand All @@ -391,13 +396,13 @@ def iterative(snapshot, result):
# this fallback is never current verification.
historical = observation if observation is not None else record
assessment_ref = ref if observation is not None else state_ref
pointer = f"/rounds/{index}"
if is_final:
pointer = f"/final_attempts/{index - len(rounds)}" if keep_history else "/final"
provenance = {
"kind": "retained_observation" if observation is not None else "cached_state",
"artifact_ref": assessment_ref,
"json_pointer": (
"" if observation is not None else "/final" if is_final else f"/rounds/{index}"
)
+ "/assessment",
"json_pointer": ("" if observation is not None else pointer) + "/assessment",
"verification": "verified" if observation is not None else "unverified",
}
value = historical.get("assessment")
Expand Down Expand Up @@ -448,6 +453,27 @@ def iterative(snapshot, result):
)]
for name, expected in (value or {}).get("evidence_files", {}).items():
evidence_refs.append(snapshot.file(directory + "/" + name, "measurement", expected))
if is_final:
latest_final_verified = observation is not None and value is not None
latest_final_complete = (
value is not None
and value["status"] in ("completed", "candidate_failure")
and execution.get("status") in ("completed", "failed")
)
if is_final and keep_history:
verdict = (value or {}).get("verdict")
result["final_attempts"].append({
"attempt_id": directory.rsplit("/", 1)[-1],
"candidate_id": record.get("candidate_id"),
"candidate_fingerprint": record.get("candidate_sha256"),
"verdict": verdict,
"assessment_ref": assessment_ref,
"assessment_provenance": provenance,
"evidence_refs": evidence_refs,
"current": record == final and verdict in ("PASS", "FAIL"),
})
if record != final:
continue
usage_source = (record.get("observations") or {}).get("usage_source")
usage_record = observation or {}
if usage_source:
Expand Down Expand Up @@ -476,8 +502,8 @@ def iterative(snapshot, result):
)
if is_final:
final_value, final_refs = value, [ref, *evidence_refs]
final_candidate, final_observation = candidate, historical
final_assessment_verified = observation is not None and value is not None
final_candidate = candidate
final_assessment_verified = latest_final_verified
result["final"] = {
"attempt_id": directory.rsplit("/", 1)[-1],
"fingerprint": record.get("candidate_sha256"),
Expand Down Expand Up @@ -530,7 +556,7 @@ def iterative(snapshot, result):
"best_score": best_after.get("score"),
}
)
for record in state.get("final_attempts", []):
for record in state.get("final_attempts", ()) if not keep_history else ():
directory = record["path"]
recovery = record["recovery"]
result.setdefault("final_attempts", []).append({
Expand Down Expand Up @@ -561,6 +587,7 @@ def iterative(snapshot, result):
result["export"]["kind"] = "final" if terminal else "progress"
result["execution"] = {
"namespace": "inferrsi.harness.optimization",
**({"evaluation_mode": "abba"} if keep_history else {}),
"state": state.get("state"),
"budget": {
"max_seconds": plan.get("max_seconds"),
Expand All @@ -582,20 +609,14 @@ def iterative(snapshot, result):
if plan["round_mode"] == "exact"
else 0 < len(rounds) <= plan["round_limit"] and bool(state.get("stop_reason"))
)
finished = (
rounds_complete
and final_value is not None
and final_value.get("status") in ("completed", "candidate_failure")
and (final_observation.get("execution") or {}).get("status") in ("completed", "failed")
and state.get("pending") is None
)
finished = rounds_complete and latest_final_complete and state.get("pending") is None
result["completion"] = {
"status": "completed" if finished else "incomplete",
"reason": "Required search and independent final assessment completed"
if finished
else "Required rounds or independent final assessment are incomplete",
}
if finished and not final_assessment_verified:
if finished and not latest_final_verified:
result["completion"]["reason"] = (
"Required search and independent final assessment completed according to "
"cached state; unverified against the retained final observation"
Expand Down
9 changes: 6 additions & 3 deletions src/inferrsi/apps/delivery/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,15 @@ def _sections(result):
sections.insert(0, ("Benchmark metrics", ["Metric", "Value", "Coverage / source"],
benchmark_metric_rows(result["benchmark_metrics"])))
final_attempts = result.get("final_attempts")
if final_attempts and result["execution"].get("evaluation_mode") == "service_reuse":
mode = result["execution"].get("evaluation_mode")
if final_attempts and mode in ("abba", "service_reuse"):
sections.insert(3, (
"Independent final attempts",
["Attempt", "Candidate", "Revision", "Verdict", "Assessment", "Current result"],
["Attempt", "Candidate", "Revision" if mode == "service_reuse" else "Fingerprint",
"Verdict", "Assessment", "Current result"],
[
[row["attempt_id"], row["candidate_id"], row["revision"], row["verdict"],
[row["attempt_id"], row["candidate_id"],
row.get("revision", row.get("candidate_fingerprint")), row["verdict"],
row["assessment_provenance"], "Yes" if row["current"] else ""]
for row in final_attempts
],
Expand Down
14 changes: 12 additions & 2 deletions src/inferrsi/apps/views/dashboard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,19 @@ def _managed_dashboard(root: Path, campaign: dict) -> dict:
displayed_summary["final_reference"] = (
file_ref(root, root / state["final"]["path"] / "observation.json", "final_assessment")
if state["final"] else None)
if attempts := state.get("final_attempts"):
if "final_attempts" in summary:
displayed_summary["current_final_attempt_id"] = summary["current_final_attempt_id"]
displayed_summary["final_attempts"] = [
{"attempt_id": attempt["attempt_id"], "candidate_id": attempt["candidate_id"],
"verdict": attempt["verdict"],
"evidence": file_ref(root, root / attempt["observation"], "final_assessment")}
for attempt in summary["final_attempts"]
]
interrupted = [record["recovery"] for record in state.get("final_attempts", ())
if "recovery" in record]
if interrupted:
displayed_summary["interrupted_finals"] = [
file_ref(root, root / record["recovery"]["path"], "recovery") for record in attempts
file_ref(root, root / record["path"], "recovery") for record in interrupted
]
if gate := state.get("cleanup_unconfirmed"):
displayed_summary["cleanup_unconfirmed"] = file_ref(root, root / gate["path"], "recovery")
Expand Down
12 changes: 11 additions & 1 deletion src/inferrsi/apps/views/optimization_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,19 @@ def render_result(summary: dict) -> str:
fields.append(f'Final {summary["selection"]["metric"]}: {score:.6g}')
if reference.get("state") == "present":
fields.append(f'Evidence: {reference["path"]} (SHA-256 {reference["sha256"]})')
history = []
for row in summary.get("final_attempts", ()):
value = f'{row["attempt_id"]} · {row["candidate_id"]} · {row["verdict"]}'
if row["attempt_id"] == summary["current_final_attempt_id"]:
value += " · Current result"
if row["evidence"].get("state") == "present":
value += f' · {row["evidence"]["path"]}'
history.append(f"<li>{escape(value)}</li>")
attempts = ("<h4>Independent final attempts</h4><ul>" + "".join(history) + "</ul>"
if history else "")
return (f'<section aria-label="Independent final result"><h3>Independent final: '
f'{escape(verdict)}</h3>'
+ "".join(f'<p>{escape(field)}</p>' for field in fields) + '</section>')
+ "".join(f'<p>{escape(field)}</p>' for field in fields) + attempts + '</section>')


def render_curve(summary: dict) -> str:
Expand Down
12 changes: 6 additions & 6 deletions src/inferrsi/harness/manager/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ def run_session(
and request.evaluation_mode == "service_reuse"):
raise ValueError("External round knowledge requires a benchmark or AB/BA campaign")
allow_continuation = getattr(request, "allow_final_continuation", False)
if allow_continuation and (
request.evaluation_mode != "service_reuse" or request.round_mode != "up_to"
):
raise ValueError("Final continuation requires an up-to-budget service-reuse campaign")
if allow_continuation and request.round_mode != "up_to":
raise ValueError("Final continuation requires an up-to-budget project campaign")
if project:
names = (
"metric_key",
Expand Down Expand Up @@ -175,6 +173,8 @@ def run_session(
"evaluation_timeout_seconds": request.evaluation_timeout_seconds,
"evaluation_prefix": evaluation_prefix, "python": request.python,
"runtime_identity": session_runtime_identity(), **candidate, **settings}
if allow_continuation:
plan["allow_final_continuation"] = True
if external_knowledge:
plan["external_knowledge"] = external_knowledge
plan["external_knowledge_project"] = external_project
Expand Down Expand Up @@ -239,8 +239,6 @@ def run_session(
or getattr(request, "repair_reason", None)
or getattr(request, "cleanup_receipt", None)
or getattr(request, "repair_protocol", None)
or getattr(request, "continue_after_final", None) is not None
or getattr(request, "continuation_reason", None) is not None
):
raise ValueError("Service lifecycle/retry operations require a service-reuse campaign")
if plan["runtime_identity"] != session_runtime_identity():
Expand Down Expand Up @@ -306,4 +304,6 @@ def run_session(
selection_reason=getattr(request, "selection_reason", None),
knowledge_refs=getattr(request, "knowledge_ref", None),
mechanism=mechanism,
continue_after_final=getattr(request, "continue_after_final", None),
continuation_reason=getattr(request, "continuation_reason", None),
)
Loading
Loading