Skip to content
88 changes: 79 additions & 9 deletions docs/guides/candidate-static-check.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# Candidate static checks
# Candidate pre-checks (L0 and optional L1)

Add `--candidate-static-check` to `session start project` or `session start benchmark`.
The check is off by default, including plans without this setting. Add
`--static-check-timeout-seconds <seconds>` to override the default 60 seconds.
The plan freezes the rule version and timeout. The check uses Git locally
for immutable diff objects, with no external act-base checkout or script.
Add `--candidate-pre-check=l0` or `--candidate-pre-check=l1` (or legacy
`--candidate-static-check`, mapped to `l0`) to `session start project` or
`session start benchmark`. Python callers set `candidate_pre_check` on
`StartProjectSession` / `StartBenchmarkSession`.
The check is off by default, including plans without this setting; recovering an
older plan without `candidate_pre_check` maps enabled `candidate_static_check`
to `l0` and keeps disabled plans off. Invalid levels fail before creating any
attempt or reserving devices. Add `--static-check-timeout-seconds <seconds>`
to override the default 60-second L0 static cutoff, `--l1-probe-timeout-seconds`
to override the L1 probe budget (default 120 seconds), and
`--candidate-target-path <relpath>` for single-file benchmark logical routing.
The plan freezes the level, rule versions and timeouts. The static stage uses
Git locally for immutable diff objects, with no external act-base checkout or script.

InferRSI compares the retained candidate and frozen baseline, including a
single-file benchmark candidate or a project directory submitted before
Expand Down Expand Up @@ -46,9 +54,9 @@ an ordinary session, Harness blocks the session. An active worker retains
ownership of its attempt until it exits. Run `recover` to collect its execution
evidence and settle the integrity failure.

Each submission has a `static-check.json` next to its observation. Enabled
observations also retain the snapshot identity, elapsed time and frozen rule
version. Each scan writes a separate `static-report-*.json` in the attempt
In L0-only mode, each submission has a `static-check.json` next to its
observation. The audit retains the snapshot identity, elapsed time and frozen
rule version. Each L0-only scan writes a separate `static-report-*.json` in the attempt
directory. A report received after the cutoff remains available for audit.
Only findings accepted before the cutoff contribute to the decision.
Recovering a committed decision or cancelling a waiting check does not rerun
Expand Down Expand Up @@ -78,7 +86,69 @@ protected renames, incomplete coverage and legitimate layout dispatch.
Managed session cases cover cutoff ordering, feedback filtering and the two
failure points at runtime handoff.

## Pre-check reports, L0 -> L1 handoff and diagnostic exceptions

When enabled, every candidate attempt produces one `pre_check_report.json` in
its attempt directory recording `candidate_pre_check`:

- **`l0`:** writes `{"candidate_pre_check": "l0", "status": ..., "feedback": ...}`
alongside the `static-check.json` audit and `static-report-*.json` captures.
- **`l1`:** L0 passes a versioned private handoff (attempt, baseline, snapshot,
workload, rules version, deadline, raw status, findings, route, suggested checks,
complexity and integer lookup values) to the L1 gate inside the Manager lock,
skipping standalone static sidecars and writing strictly three public fields:
`{"candidate_pre_check": "l1", "verdict": ..., "feedback": ...}` where
`verdict` is `PASS`, `FAIL`, `timeout`, or `INCONCLUSIVE`.

L0 rejection (any timely confirmed `BLOCK`, including mixed `BLOCK`+`WARN` or
`INCOMPLETE`+`BLOCK`) immediately settles `l1` as `FAIL` with zero L1 probes,
zero device allocations and zero downstream runs, charging one round. Untrusted,
version-mismatched, `OFFLINE`, or route-incomplete handoffs (including a merged
`clear` without raw route or required checks) settle as `INCONCLUSIVE` with zero
L1 or downstream dispatch.

When L0 passes cleanly:
- Pure `R2_scheduler` or `R4_loader_infra` with zero `WARN` and no specialized
L1 checks directly passes (`static_only`, zero L1 device calls) before
proceeding to downstream offline simulation / cold-load + GPU/NPU performance
evaluation. Pre-check `PASS` does not skip downstream validation or turn a
downstream failure into a passing round.
- `R1_kernel` requires L1-A, `R3_model_graph` requires L1-B, and mixed buckets
such as `R1+R2` require both. Applicable warnings and suggested checks add
their probes once. A runtime `PASS` requires a passing result for every
required probe and a confirmed trace when the frozen attribution threshold is
exceeded. The CPU runner reports missing device evidence as `INCONCLUSIVE`.

If L0 static check reaches its cutoff without a timely `BLOCK` while the outer
evaluation/session budget remains valid, `l1` writes `verdict: "timeout"` with
the exact L0 timeout text, skips L1 probes, and dispatches the same snapshot to
normal downstream evaluation at most once without charging an extra round. If L1
probes exhaust their own budget or lack assets/coverage without a confirmed hard
gate failure, `l1` records `timeout` (`本轮运行时预检超时,未能形成结论。`) or
`INCONCLUSIVE` (`本轮预检未形成结论。`) and continues to downstream at most
once only when the outer budget is valid and probe cleanup is verified; unconfirmed
cleanup blocks concurrent downstream dispatch until recovery confirms cleanup.
Recovery may repeat an unfinished L0 scan on the original snapshots. Once
Manager records L0 admission, recovery verifies the saved handoff and probe
plan before launching a probe. Missing or mismatched records at that point
end the attempt as `INCONCLUSIVE` without dispatch. Confirming cleanup after
a cancellation releases the resources and preserves the cancellation.
If the scanner reports a frozen-input or rule-version change, or the L1
worker detects snapshot drift before acceptance, the session blocks. In
service-reuse mode, a downstream worker that stops without a cleanup result
requires a separate cleanup inspection taken after runtime acceptance.

Both `l0` and `l1` apply one narrow exception to fixed feedback: trusted
parser (`ast`) or compiler diagnostics confirmed to belong to the candidate's
own source may report `<relative_path>:<line>[:<col>]:语法错误|编译错误,<detail>。`
without leaking raw stderr, toolchain logs, or private evaluator paths.
Round returns and `latest_observation` expose separate `pre_check_status` and
`downstream_status` labels (`预检通过` / `预检超时` / `预检未形成结论` vs
`下游评测进行中` / `下游评测通过` / `下游验证失败` / `下游评测失败`) without
modifying the settled `pre_check_report.json` bytes.

```sh
python -m pytest tests/harness/test_candidate_static_rules.py tests/apps/test_service_static_round.py
python -m pytest tests/harness/test_l1_pre_check.py tests/apps/test_managed_pre_check.py tests/apps/test_pre_check_cleanup.py
python -m pytest tests/apps/test_optimization_session.py tests/apps/test_project_optimization.py -k static
```
5 changes: 3 additions & 2 deletions docs/guides/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,9 @@ snapshot pinned at startup. The campaign Dashboard remains available through
record the measured bottleneck before candidate search. The
[shared workflow](optimization-workflow-unification.md) defines round limits,
recovery and dashboard generation from the Harness control record.
- **Check a candidate before evaluation.** Opt in with `--candidate-static-check`
when starting a managed project or benchmark session. See
- **Check a candidate before evaluation.** Opt in with `--candidate-pre-check=l0|l1`
(or legacy `--candidate-static-check`) when starting a managed project or
benchmark session. See
[candidate static checks](candidate-static-check.md) for outcomes and recovery.
- **Optimize a packaged task.** Follow the [benchmark session workflow](../benchmarks/optimization-benchmarks.md)
through rounds and independent final retest. By default the initiator prepares,
Expand Down
3 changes: 2 additions & 1 deletion docs/guides/service-reuse-campaigns.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ the campaign.
Replacing a retained directory does not replace the executed version; an unavailable
source commit makes execution INCONCLUSIVE. Older records without a source repository
cannot establish that binding and must start a new campaign.
With [candidate static checks](candidate-static-check.md) enabled, a round can
With [candidate pre-checks](candidate-static-check.md) (`--candidate-pre-check=l0|l1`
or legacy `--candidate-static-check`) enabled, a round can
submit uncommitted files. For a candidate continuing to runtime, Harness seals
the retained files into a private Git revision for execution, profiling and final.

Expand Down
8 changes: 8 additions & 0 deletions src/inferrsi/apps/cli/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,19 @@ def _optimization_start(start, *, project):
else:
start.add_argument("task")
start.add_argument("--evaluation-args", required=True)
start.add_argument(
"--candidate-target-path",
help="Logical target relative path for single-file candidate pre-check routing",
)
start.set_defaults(round_mode="exact")
start.add_argument("--session", "--directory", dest="session", type=Path, required=True)
start.add_argument("--rounds", type=int, required=True)
start.add_argument("--max-minutes", type=float, required=True)
start.add_argument("--evaluation-timeout-seconds", type=float, required=True)
start.add_argument("--candidate-pre-check", choices=("l0", "l1"), default=None,
help="Run candidate pre-check gate (l0 static or l0->l1 runtime)")
start.add_argument("--l1-probe-timeout-seconds", type=float,
help="L1 runtime probe wall-clock budget per candidate (default 120)")
start.add_argument("--candidate-static-check", action=argparse.BooleanOptionalAction,
default=False,
help="Check retained candidate snapshots before runtime evaluation")
Expand Down
5 changes: 3 additions & 2 deletions src/inferrsi/apps/views/dashboard_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from datetime import datetime, timezone

from inferrsi.harness.manager import _static_round as static_round
from inferrsi.harness.records.evidence import STAGES, relative_location, sanitized_text

from .dashboard_data import _managed_diagnoses, _managed_submission, _number, _optimization
Expand Down Expand Up @@ -58,7 +59,7 @@ def service_inputs(plan, state, captures):
"items": [{**{key: item.get(key) for key in ("ref", "title", "revision")},
"delivered": item["ref"] in delivered}
for item in items]})
pending = state.get("pending")
pending = static_round.public(state.get("pending"))
return public_value({"service_objectives": objectives, "stage_objectives": by_stage,
"service_pending": pending,
"managed_diagnoses": diagnoses, "managed_retrievals": queries})
Expand All @@ -80,7 +81,7 @@ def sequential_inputs(root, plan, state, summary):
attempts = [*attempts.values(), *([pending] if pending else [])]
return public_value({
"comparison": plan["comparison"], "service_lifetime": plan["service_lifetime"],
"sequential_optimization": summary, "service_pending": pending,
"sequential_optimization": summary, "service_pending": static_round.public(pending),
"service_objectives": {settings["metric_key"]: {
"unit": settings["metric_unit"], "direction": settings["direction"],
"aggregate": "median", "workload": settings.get("scope"),
Expand Down
Loading
Loading