Skip to content

fix(harness): revalidate reference guard and short check on sequential final - #1074

Open
cassieliang6709 wants to merge 4 commits into
InferMatrixLab:mainfrom
cassieliang6709:fix/sequential-final-reference-guard
Open

cassieliang6709 wants to merge 4 commits into
InferMatrixLab:mainfrom
cassieliang6709:fix/sequential-final-reference-guard

Conversation

@cassieliang6709

@cassieliang6709 cassieliang6709 commented Dec 4, 2026 •

Copy link
Copy Markdown

Governing Issue and delivery slice

Refs #1051

  • Accepted scope / delegation: Accepted scope. Implementer @cassieliang6709 by name; accountable and goal-acceptance owner @Dong1017.
  • User-visible problem and worst-case tradeoff: A one-shot A/A session (identical baseline and candidate SHA-256) reported PASS with a 1.20× speedup, because the machine drifted 20% before final and final skipped the drift check. After this PR, that final is INCONCLUSIVE and dispatches no measurement. The worst case is a session with a spent round budget whose references keep drifting: it can recover once, then has to close with final --end-search and reports no speedup. That is the accepted outcome for references that cannot be trusted.
  • What this PR delivers: In a one-shot sequential project, final now goes through the same reference guard as round. It runs the freshness precheck, freezes short_check_anchor, runs the frozen short check before the final measurement, and verifies the receipt. Expired, missing, drifted or unverifiable references end the final as INCONCLUSIVE and keep the attempt. Two explicit recovery paths are added. One is a post-final refresh-references --drift. The other is final --retry-of for reference_check_unavailable.
  • What it does not deliver: No automatic refresh on INCONCLUSIVE. Retained final records are not relabelled. AB/BA, service-reuse and packaged benchmark finals are unchanged.

Knowledge authorship declaration

{
  "schema_version": 1,
  "head_sha": "90415454e64cdaeb39b0a82dba022316d30dce65",
  "human_only": false,
  "material_ai_authors": [
    {"tool": "Antigravity", "model_id": "gemini-4-neon", "effort": "high", "role": "author"},
    {"tool": "Claude Code", "model_id": "claude-opus-5-5", "effort": "unknown", "role": "author"}
  ]
}

No path protected by docs/knowledge-model-policy.md is changed, so the expected status is Not applicable.

Changed artifacts and evidence

Requirement (accepted answer) Actual change Check / evidence and result Remaining gap
1. final gets the freshness precheck, anchor freeze, frozen short check and receipt verification _sequential_project.py _attempt / _assessment, _ordinary.py execute_project_single_side test_final_short_check_blocks_aa_drift_and_binds_receipt, test_final_valid_ab_binds_short_check_receipt_and_passes: pass none
Expired or missing reference: INCONCLUSIVE, no final measurement dispatched, attempt kept Shared precheck in _attempt for kind in ("round", "final") test_final_precheck_blocks_without_dispatching_measurement[age, missing_anchor] uses a fake clock and asserts that no short or measure events run: pass none
Probe drift over 5% or unverifiable probe: INCONCLUSIVE, attempt and earlier rounds kept _assessment verifies the final probe Issue reproduction script, before the fix PASS fixed_checks_satisfied 1.2 False, after the fix INCONCLUSIVE reference_drift_exceeded None True steps=[] none
2. Refresh stays user-triggered No automatic refresh added ResumeSession past a final drift is still rejected (asserted in the A/A test) none
3. After a final drift or probe INCONCLUSIVE, one explicit refresh may re-measure (initial, parent) even with a spent round_limit, then one final under the new epoch without using a round _post_final_refresh_attempt, refresh branch of _attempt, _establish_references, _verify_selection test_post_final_drift_refresh_allows_single_new_epoch_final_when_budget_spent, test_post_final_refresh_exemption_is_single_use[exact, up_to]: pass see Notes on the single-use rule
4. final --retry-of for reference_check_unavailable; STALE_REFERENCES blocked until refresh FinalizeSession extends _Retryable; CLI session final --retry-of / --repair-reason; run_command final branch test_final_unavailable_probe_supports_explicit_retry_of (Python and CLI parse), plus drift retry rejection in the A/A test: pass none
5. Bind the final record to reference_epoch, short_check_anchor, reference_guard and the SHA-256 of execution/short-check/result.json _assessment adds the receipt to evidence_files; pending carries the epoch and anchor Asserted in the A/A and A/B tests none
6. Retained final records stay readable, not relabelled No migration; _verify_selection replay unchanged for records without reference-blocked finals test_legacy_final_without_short_check_remains_readable: pass none
7. #853 AB/BA and packaged benchmark contracts preserved AB/BA path untouched; service-reuse final retry is still rejected by its kind map test_abba_final_rejects_retry_options: pass; tests/apps/test_project_optimization.py: pass none
Docs match the new final and refresh behaviour docs/guides/optimization-workflow-unification.md (Default sequential evaluation) Reviewed against _final_reason, _post_final_refresh_attempt and the final branch of run_command none
A valid A/B final passes as a positive control n/a test_final_valid_ab_binds_short_check_receipt_and_passes: PASS, speedup 1.2 none

Notes on design choices

  • final revalidates the retained reference with the frozen short check. It does not re-measure the baseline. This follows accepted answer 1, which gives final the same revalidation as round. The cost is one short-check run per final. When the check fails, refresh-references --drift re-measures (initial, parent) on the current machine. Interleaved measurement stays available through AB/BA.

  • final does not apply max_rounds_without_refresh. Round prechecks already block at settled_rounds_in_epoch >= max_rounds_without_refresh, so a final sees at most the limit. Applying the rounds check to final would leave a max_rounds_without_refresh=1 epoch with no path to a final. max_age_seconds, anchor presence and the short check still apply.

  • The post-final refresh exemption is single-use. Only the first accepted refresh after the last round skips the remaining-round requirement and the current-conditions acceptance. If the next final drifts again, an exhausted budget closes with final --end-search. With rounds left, the refresh is a normal one and needs an accepted round. This reads "one explicit final retry" in accepted answer 3 as one per search. It stops a session from repeating refresh and final until one final looks good. @Dong1017, if you want a different limit, it is one condition in _post_final_refresh_attempt. After that refresh, the selected candidate no longer has a parent from its acceptance, so the final is gated against the refreshed initial reference, and min_improvement_pct still applies (test_post_final_refresh_final_keeps_min_improvement_gate).

Checks and dependencies

  • Checks actually run (result and tested scope), at exact head 9041545 on Linux / Python venv, CPU only:
    • ruff check src tests tools: all checks passed. git diff --check: clean.
    • pytest -n 8 tests/repository: 698 passed, 39 skipped.
    • pytest -n 8 tests/harness/test_sequential_project.py tests/apps/test_project_optimization.py tests/repository/test_smoke.py tests/contracts/test_claim.py tests/repository/test_architecture_anchors.py tests/harness/test_reference_guard.py: 138 passed.
    • tests/harness/test_sequential_project.py: 44 passed (33 existing plus 11 new cases).
    • Rollback check: with src/ restored to 020708f and the new tests kept, 10 of the 11 new cases fail. test_legacy_final_without_short_check_remains_readable passes on the base by design. test_abba_final_rejects_retry_options fails on the base because FinalizeSession had no retry_of field.
  • Failed, skipped, timed-out or not-run checks: The full repository suite, the dashboard-browser checks and multi-platform wheel builds were not run locally. They are left to CI.
  • Dependencies / shared interfaces / integration assumptions: FinalizeSession now accepts retry_of, repair_reason, repair_protocol and cleanup_receipt. AB/BA and service-reuse finals still reject them. evaluate_reference_guard_precheck gains a keyword check_rounds=True, and the default keeps existing callers unchanged.

Remaining work and Issue closure

  • Remaining Issue requirements / follow-up: none known within the accepted scope.
  • Goal-acceptance owner or accepted closure delegation: @Dong1017.
  • Goal ready for acceptance? Not claimed. Exact-head CI and independent review are pending.

🤖 Generated with Claude Code

…l final

Enforce frozen reference-guard revalidation before independent final
evaluation in one-shot sequential projects instead of bypassing it:

- Run freshness precheck (max_age_seconds and guard-state validity,
  without re-applying max_rounds_without_refresh on final to avoid
  deadlocking max_rounds_without_refresh=1 epochs) and freeze
  short_check_anchor for final attempts before execution.
- Execute and verify the frozen short_check probe on final attempts,
  binding reference_epoch, short_check_anchor, reference_guard, and
  execution/short-check/result.json SHA-256 to the final record while
  leaving pre-existing retained final records readable without
  relabelling.
- Allow an explicit user-triggered refresh-references --drift to
  re-measure (initial, parent) after a reference-blocked INCONCLUSIVE
  final even when round_limit is spent, permitting one explicit final
  retry under the new reference_epoch without consuming a round.
- Wire final --retry-of (Python FinalizeSession and CLI session final)
  for reference_check_unavailable while keeping stale references blocked
  until refresh and preserving AB/BA and packaged benchmark contracts.
- Add CPU regression coverage for A/A over-limit drift, fake-clock
  expired and missing-anchor precheck, unavailable probe retry,
  post-final drift refresh with exhausted round budget, legacy final
  readability, valid A/B positive control, and AB/BA retry rejection.

Agent-assisted-by: Antigravity (author)
Signed-off-by: Liang Yue <liangyue3666@gmail.com>
A final run after a post-final reference refresh had no parent at
acceptance, so the minimum-improvement gate was skipped and a final
within noise of the refreshed baseline could PASS. Gate that final
against the refreshed initial reference instead.

Limit the post-final refresh exemption to the first accepted refresh
after the last round. A spent round budget can no longer cycle through
refresh and final retries; later drift goes through a normal refresh
that needs an accepted round, or final --end-search.

Agent-assisted-by: Claude Code (author)
Signed-off-by: Liang Yue <liangyue3666@gmail.com>

@Dong1017 Dong1017 left a comment

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.

PR review verdict — DO NOT PASS

Posted by Dong-bot (review), an automated agent acting on behalf of @Dong1017 (always-on-bot, model auto-smart?optimize_for=balanced).

This is a self-check and not an independent approval. I found no code blocker. I am withholding the formal Approve because this account cannot supply an eligible one. This COMMENT does not approve the PR and does not change its scope.

Reviewed base 020708f4dbfc8bfee6a1bc930cd954cf5f56203b and head 6f50d8f6f6c238a4d311ac4d67a96178e4d845a7, full diff, no previous head.

Blocker: no eligible independent approval from this account

  • The PR body and #1051 name @Dong1017 as accountable and goal-acceptance owner. The scope-acceptance comment on #1051 was posted by Dong-bot for Dong1017.
  • skills/review-pr/references/agent-collaboration-pr-review.md says the accountable parent for a delivery slice cannot supply an independent approval, including through another agent acting under their account. SKILL.md says to label such an assessment a self-check and hand the formal review to an independent reviewer.
  • Dong-bot's Approve would therefore count as an ineligible vote.
  • Needed: an independent reviewer with write access, plus the two qualifying approvals the ruleset requires.
  • pr/prior-reviews.md shows no formal review, no APPROVED on this head and no CHANGES_REQUESTED. No independent approval exists on this head yet.

Missing evidence

  • The PR body says exact-head CI and independent review are pending. The full suite, dashboard-browser and the wheel builds were not run. A green exact-head CI is still needed before merge.

What I verified (read at head 6f50d8f, nothing run)

  • The change matches the accepted answers 1-7 on #1051.
    • _sequential_project.py::_attempt runs the precheck, freezes short_check_anchor and sets pending["reference_block_reason"] for kind in ("round", "final").
    • _assessment and _ordinary.py::execute_project_single_side no longer skip the short check on final.
    • check_rounds=(kind == "round") keeps max_rounds_without_refresh off final. The default check_rounds=True leaves existing callers unchanged.
  • _post_final_refresh_attempt is single-use.
    • Walking attempts in reverse, a PASS refresh after the blocked final returns None. A second drifted final therefore gets no exemption.
    • _verify_selection replays the same helper per refresh, so requires_current_conditions_acceptance is consistent between live state and replay.
    • The final is gated against the refreshed initial when parent_reference_at_acceptance is absent, so min_improvement_pct still applies.
  • final --retry-of
    • _retry_attempt rejects STALE_REFERENCES for final.
    • run_command allows a final retry only when reference_block_reason == REFERENCE_CHECK_UNAVAILABLE. _final_reason(..., retrying_probe=True) bypasses only that block and the blocked state.
    • --end-search combined with retry options is rejected.
    • _settle clears a stale non-guard block reason after a final.
    • The CLI adds --retry-of and --repair-reason only under project. The final request now carries the _Retryable fields, and repair_protocol and cleanup_receipt are still rejected by _retry_attempt.
  • Tests: the new cases map to the issue's acceptance clauses. They cover A/A drift, fake-clock age and missing anchor with no dispatch, unavailable probe plus retry, the post-final refresh with a spent budget, the single-use rule in exact and up_to modes, legacy readability, and the AB/BA rejection.

Not verified here

  • I ran no tests, no ruff and no rollback check. The 138 passed / 44 passed / 10-of-11 rollback results are the author's report.
  • I did not read tests/apps/test_project_optimization.py or the evaluator and reference-guard internals beyond the diff.
  • I did not trace the AB/BA and service-reuse final paths. I did not confirm where _session_request maps the new CLI fields. The CLI test in the PR covers that mapping.
  • I did not read #853, so the overlap is unchecked.

Optional follow-up, non-blocking

  • The single-use limit on the post-final refresh is a design choice the author flagged for @Dong1017. Record the decision on #1051 so the independent reviewers know it is accepted.

@Dong1017 Dong1017 added the area:harness Harness module: profile, A/B loop, quality gates, evidence reports label Dec 4, 2026
zengchuang-hw
zengchuang-hw previously approved these changes Dec 4, 2026

@zengchuang-hw zengchuang-hw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PASS
dot, acting for zengchuang-hw.

首次检视 #1051 的修复,head 6f50d8f6f6c238a4d311ac4d67a96178e4d845a7。最终验证现在与参照纪元绑定:先核对有效期和短探针,再决定是否采用留存参照;同 SHA A/A 漂移不会报告可接受加速,正常 A/B 仍测,缺探针保留原尝试并允许明确重试。预算耗尽时,final 参照问题只允许一次成功刷新,保持对初始参照的增益门槛;不把刷新后的候选当成自己的对照。历史 final 的读取和 AB/BA 继续保持原行为。

精确 head 独立运行顺序评估整组 CPU 测试 44 项通过,涵盖回放/收据、正常和负对照、预算耗尽恢复。未运行真实服务、模型或设备;不合并。

State that a one-shot final passes the same reference checks as a round
except the completed round limit. Describe the single post-final refresh
exception, its gate against the remeasured A, and final --retry-of for an
unavailable short check.

Agent-assisted-by: Claude Code (author)
Signed-off-by: Liang Yue <liangyue3666@gmail.com>
@cassieliang6709

Copy link
Copy Markdown
Author

Claude Code, acting for @cassieliang6709.

Thanks @Dong1017 for the self-check and @zengchuang-hw for the review.

New head 9041545, docs only. The one-shot section of docs/guides/optimization-workflow-unification.md said final is always judged against its acceptance parent, and that --retry-of covers refresh and round only. The new commit describes the final reference checks, the single post-final refresh and its gate against the remeasured A, and final --retry-of. src/ and tests/ are unchanged from 6f50d8f. The push dismissed the approval on 6f50d8f under the stale-review rule, so @zengchuang-hw, please re-check the docs-only diff 6f50d8f..9041545.

Requests

Checks at exact head 9041545 (Linux, CPU)

  • ruff check src tests tools: all checks passed.
  • pytest -n 8 on the sequential, project optimization, smoke, claim, architecture-anchor and reference-guard test files: 138 passed.
  • pytest -n 8 tests/repository: 698 passed, 39 skipped.
  • Rollback: with src/ restored to 020708f, 10 of the 11 new cases fail.
  • Not run locally: the full suite, dashboard-browser checks and wheel builds.

On the paths your self-check left open

  • AB/BA: _session.py rejects final retry options. This is covered by test_abba_final_rejects_retry_options.
  • Service-reuse: a final retry fails the kind check in _state.py, which maps only round, baseline and refresh. I read this code but have not tested it.
  • Require evidence-backed feasibility checks for project performance targets #699 also changes the test_sequential_project.py fixture and _requests.py. A trial merge with its head adc14174 has no conflicts, and the sequential tests pass (45 passed).

@Dong1017

Dong1017 commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Posted by Dong-bot (review), an automated agent acting on behalf of @Dong1017 (always-on-bot, model auto-smart?optimize_for=balanced).

Technical assessment: the "one post-final refresh per search" reading fits answer 3 of #1051 and the code, but I can't confirm it or approve CI for Dong1017. Those decisions stay with Dong1017, and no decision is recorded here.

This comment is not a formal review. The docs-only re-check is requested from @zengchuang-hw. My earlier COMMENT on 6f50d8f was a self-check, because Dong1017 is the accountable owner and cannot supply an independent approval.

Details

Reviewed base 020708f4, head 90415454. I read pr/body.md, pr/thread.md, pr/prior-reviews.md, pr/diff.patch, #1051 and its accepted-scope comment. There is no APPROVED review on this head and no outstanding CHANGES_REQUESTED.

Single-use rule

Docs diff 6f50d8f..9041545
The new text matches the code:

  • Final skips only the completed-round limit (check_rounds=(kind == "round")).
  • The post-final refresh exemption is single-use.
  • --retry-of covers a final whose short check was unavailable.
  • A final after the refresh is gated against the remeasured initial reference.

The diff changes no src/ or tests/ files. These are not covered by that range.

Not verified:

@Bounty-hunter Bounty-hunter left a comment

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.

Claude Code agent, acting for @Bounty-hunter.

PR review verdict — PASS

This is a non-voting comment: the current head carries no review invitation for this account, so I am not submitting a formal review. The re-check was requested from @zengchuang-hw.

Reviewed base 020708f4dbfc8bfee6a1bc930cd954cf5f56203b and head 90415454e64cdaeb39b0a82dba022316d30dce65. The delta 6f50d8f..9041545 is one commit changing one file, docs/guides/optimization-workflow-unification.md (+11/-3). src/ and tests/ are unchanged between the two heads, which matches the author's claim.

I checked each new sentence of the guide against the code at the same head:

  • "Final passes the same reference checks as a round, except the completed round limit." _attempt calls evaluate_reference_guard_precheck(..., check_rounds=(kind == "round")), then freezes and verifies short_check_anchor for both kinds. _assessment and execute_project_single_side no longer exempt kind == "final" from the short check. The guard key that is skipped (max_rounds_without_refresh) is the one the guide calls the completed round limit in its intake paragraph.
  • "The first passing refresh after the last round may run even when the round budget is spent." _post_final_refresh_attempt walks back to the last round and returns the blocked final only while no passing refresh follows it. _attempt skips the allocated >= plan["round_limit"] rejection only when that helper returns a blocked final, and _establish_references plus _verify_selection drop requires_current_conditions_acceptance for that same refresh.
  • "After a later reference stop, a refresh needs a remaining round and an accepted round before final. Otherwise close with final --end-search." Once a passing refresh sits after the last round, the helper returns None, the budget check applies again, and an ordinary refresh sets requires_current_conditions_acceptance=True, so final waits for an accepted round. With a spent budget the only close is final --end-search, as written.
  • "--retry-of ... to retry a candidate or final whose short check was unavailable." _retry_attempt rejects a final retry only when the block reason is in STALE_REFERENCES, and run_command accepts a final retry only for reference_check_unavailable.

Optional, non-blocking: "except the completed round limit" can also be read as the search's round_limit, which final still requires. Naming the guard key (max_rounds_without_refresh) would remove the ambiguity.

Not verified: CI on this head (fork workflows await approval), the full suite, and behaviour beyond the four sentences above. I did not run the tests again; I read the code at 90415454 and the docs diff.

Copy link
Copy Markdown
Contributor

dot, acting for zengchuang-hw.

收到本条独立复核请求。当前 9041545 的文档复核已登记;按同 PR 检视节奏留到窗口后提交一次正式结论,不另开重复检视。

Copy link
Copy Markdown
Contributor

dot, acting for zengchuang-hw.

收到本条文档复审。已确认 9041545 相对 6f50d8f 只改一篇说明,源码和测试树相同。上一份正式检视离现在不足 30 分钟;本条先记收悉,正式意见留在节奏窗口后,旧批准不沿用。

@zengchuang-hw zengchuang-hw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
dot, acting for zengchuang-hw.

PR review verdict — PASS

回应文档复审及另条提醒,6f50d8f → 90415454e64cdaeb39b0a82dba022316d30dce65,base 020708f4dbfc8bfee6a1bc930cd954cf5f56203b。只有说明变更;Git 的 src 与 tests 树完全一致。说明与 #1051 已定边界一致:final 查参照,耗尽预算后的首次成功刷新可直接进入一次 final,按重测 A 判,并支持短检查不可用时的明确 retry。无可行动阻塞。

已静态复核增量;44 项 CPU 测试是上轮结果,未冒充当前重跑。当前 CI:full-check (3.10): in_progress;installed-package (3.11): success;installed-package (3.10): success;full-check (3.11): failure。CI 失败/运行状态不作为本次单文件文档的技术结论。

Reviewer: dot / zengchuang-hw / 独立文档复审、发表与投票。公开请求 · 范围决定。

@amy-why-3459 amy-why-3459 left a comment

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.

LGTM
inferRSI, acting for @amy-why-3459.

PR review verdict — PASS
Reviewed base 020708f4dbfc8bfee6a1bc930cd954cf5f56203b and head 90415454e64cdaeb39b0a82dba022316d30dce65 against the accepted scope.

The one-shot sequential final now shares the reference precheck, short_check_anchor freeze, frozen short check and receipt verification with round. An over-limit A/A drift or expired/missing/unusable reference becomes INCONCLUSIVE and does not dispatch a final measurement. final --retry-of is limited to reference_check_unavailable; stale references stay blocked until an explicit refresh. The first passing post-final refresh may run with a spent round budget, after which the final is gated against the remeasured initial A. AB/BA still rejects the new retry options, and pre-#1051 final records remain readable. New tests map to those clauses. No actionable blockers.

Verification

Static review of the seven-file diff. I did not re-run the author's CPU tests or exact-head CI (this is a fork PR, and the branch is still based on 020708f4). Architecture and change necessity look sound: the guard lives in the existing harness manager/executor/evaluator path, check_rounds defaults to the previous behavior, and the added tests cover distinct acceptance cases rather than duplicating one path.

Accuracy and performance comparison experiments are not applicable; this is a harness correctness fix with focused CPU tests.

Optional, non-blocking: the single-use reading of “one explicit final retry” is still waiting for @Dong1017 to record the decision on #1051. If a different cap is chosen, it is one condition in _post_final_refresh_attempt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:harness Harness module: profile, A/B loop, quality gates, evidence reports

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants