Skip to content

test(harness): decouple box-search cancel watcher and add failure diagnostics - #1101

Open
Zlatanwic wants to merge 1 commit into
InferMatrixLab:mainfrom
Zlatanwic:fix/box-search-cancel-sync
Open

Zlatanwic wants to merge 1 commit into
InferMatrixLab:mainfrom
Zlatanwic:fix/box-search-cancel-sync

Conversation

@Zlatanwic

Copy link
Copy Markdown

Governing Issue and delivery slice

Refs #999

Anchors touched: none

  • Accepted scope / delegation: Accepted on bug: intermittent failure in test_cancellation_terminates_owned_service on Python 3.11 Ready CI #999 (comment 7405949760, Dong-bot acting as authorized delegate for @Dong1017) and assigned to @Zlatanwic with status:accepted (comment 7406566004); accountable and goal-acceptance owner @Dong1017.
  • What this PR delivers: (tests/harness/test_managed_box_search.py only, no production code)
    • Decouples watcher shutdown (stop_watcher) from business cancellation (cancel) via _install_entered_markers and _watch_install_marker: cancel.set() is called only after observing search/*/install-entered, recording trigger branch (install_entered, screen_finished_before_marker, screen_finished_before_cancel, or watcher_timeout) and never fabricating cancellation without the marker.
    • Attaches structured diagnostics (_cancellation_diagnostics) to test_cancellation_terminates_owned_service: watcher trigger branch, watcher_alive, cancel_set, markers_on_disk, top-level status/source/error/cleanup_error, per-attempt summary (index, path, failed_stage, per-step id:status, verdict, reason, cleanup_verified), and the full result dict.
    • Preserves all existing assertions (status == "inconclusive", cleanup_verified is True, len(result["attempts"]) == 2, "install did not settle", and install-entered presence) and keeps fix(harness): retry ConnectionRefusedError during Box socket startup and stabilize test timeout #997's merged stage timeouts (1.5s for timeout fault modes, 10.0s for other modes including cancelled) unchanged.
    • Adds deterministic regression test test_cancellation_watcher_never_fabricates_cancel_without_marker covering all four watcher paths and _cancellation_diagnostics.
  • What it does not deliver: No production code changes, no timeout relaxation, and no root-cause claim for the prior single-attempt CI failure (passing the updated test does not prove why one attempt was recorded; if it recurs, the diagnostics preserve the watcher path and attempt list).

Knowledge authorship declaration

{
  "schema_version": 1,
  "head_sha": "66df7156a41ea2f784fcd4a1d42538d9d2a7a015",
  "human_only": false,
  "material_ai_authors": [
    {
      "tool": "Antigravity",
      "model_id": "unknown",
      "effort": "unknown",
      "role": "author"
    }
  ]
}

Changed artifacts and evidence

Requirement Actual change Check / evidence and result Remaining gap
Split stop_watcher from cancel; never fabricate cancel.set() without install-entered tests/harness/test_managed_box_search.py (_install_entered_markers, _watch_install_marker, test_cancellation_terminates_owned_service, test_cancellation_watcher_never_fabricates_cancel_without_marker) Linux Python 3.11.15 WSL2 on 66df7156: deterministic unit test 1 passed (0.26s); 3× pytest -rs -n 4 tests/harness/test_managed_box_search.py (29 passed each) Ready CI on PR head
Attach structured failure diagnostics while preserving assertions and #997 timeouts tests/harness/test_managed_box_search.py (_cancellation_diagnostics, test_cancellation_terminates_owned_service) Linux Python 3.11.15 WSL2 on 66df7156: ruff check src tests tools (All checks passed!); 3× parallel file runs (29 passed each) Ready CI on PR head

Checks and dependencies

  • Checks actually run on current head 66df7156a41ea2f784fcd4a1d42538d9d2a7a015 (base main 3845d9ee):
    • ruff check src tests tools (Linux Python 3.11.15, repo root): All checks passed!
    • pytest -q tests/repository/test_smoke.py tests/contracts/test_claim.py (Linux Python 3.11.15, repo root): 8 passed
    • pytest -vv -k test_cancellation_watcher_never_fabricates_cancel_without_marker tests/harness/test_managed_box_search.py (Linux Python 3.11.15): 1 passed, 28 deselected in 0.26s
    • Repeated parallel runs pytest -rs -n 4 tests/harness/test_managed_box_search.py (Linux Python 3.11.15, xdist 3.8.0):
      • Run 1: 29 passed, 24 warnings in 23.65s
      • Run 2: 29 passed, 24 warnings in 23.71s
      • Run 3: 29 passed, 24 warnings in 23.47s
  • Failed, skipped, timed-out or not-run checks (if applicable):
    • Full repository Ready CI (full-check on Python 3.10 / 3.11, pr-references, knowledge-model-policy): not yet run (pending PR creation and promotion to Ready).
    • Native Windows pytest tests/harness/test_managed_box_search.py: skipped by file-level pytestmark (os.name != "posix" or not hasattr(socket, "AF_UNIX")).
  • Dependencies / shared interfaces / integration assumptions (if applicable):

Remaining work and Issue closure

  • Remaining Issue requirements / follow-up: Verify Draft CI and promote to Ready CI on PR head 66df7156; if the single-attempt failure ever recurs in Ready CI, retain the failed job and structured attempt diagnostics.
  • Goal-acceptance owner or accepted closure delegation: @Dong1017 (per comment 7405949760).
  • Goal ready for acceptance? Not claimed

…gnostics

Decouple the cancellation watcher shutdown event from the business
cancellation event in test_cancellation_terminates_owned_service so
cancel is set only after observing the round-2 install-entered marker,
and never fabricated on watcher timeout or early screen exit.

Attach structured diagnostics (watcher branch, cancel state, on-disk
markers, top-level status/error, per-attempt stage/verdict summary,
and full result dict) to the cancellation assertions, and add a
deterministic unit test for the watcher and diagnostic summary.

Agent-assisted-by: Antigravity (author)
Signed-off-by: Zlatanwic <2353113@tongji.edu.cn>

@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.

LGTM

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

PR review verdict — PASS
Reviewed base 3845d9e and head 66df715 (full diff, single file: tests/harness/test_managed_box_search.py; no .github/ or product code touched).

Prior-review state: pr/prior-reviews.md shows no formal reviews on this head and no outstanding CHANGES_REQUESTED, so this Approve is the first formal review on this head.

Verified by reading the diff and the surrounding repo code:

  • _watch_install_marker sets cancel only when an install-entered marker is on disk. The old watcher called cancel.set() unconditionally on its 15 s deadline, which could hide a missing marker. The new one returns watcher_timeout and leaves cancel unset. The loop checks stop_watcher before the marker, so the screen_finished_before_* outcomes are classified consistently.
  • The marker path matches what the fixture writes. tests/fixtures/box_serving_protocol.py L86-91 touches receipt_path.parent / "install-entered" in modes timeout/cancelled/lost_owner, then sleeps 20 s. The search/*/install-entered glob is the same one the original test used. Fixture stage timeouts are 10 s (campaign()), so a missing marker cannot hang screen() now that the watcher no longer force-cancels.
  • test_cancellation_terminates_owned_service keeps every original assertion (status, cleanup_verified, two attempts, "install did not settle", marker present). It adds a stricter check that the watcher triggered on install_entered and that cancel was set. thread.join(timeout=5) plus assert not thread.is_alive() runs first, so a stuck watcher fails with diagnostics instead of hanging, and watcher_state is only read after the join succeeds.
  • The new unit test test_cancellation_watcher_never_fabricates_cancel_without_marker covers all four watcher outcomes (timeout, stop before marker, stop after marker, match) and asserts cancel state for each. It also checks the _cancellation_diagnostics shape against a synthetic result. The timings are small (0.02 s timeout, 0.005 s poll) and the checks are deterministic.
  • _cancellation_diagnostics reads results defensively with .get(...) or {}. It only builds a message for assertions, so it adds no production behavior or coupling.

Not verified here:

  • I did not run the tests (no execution environment). I did not check CI status.
  • The diagnostics embed the full result in assertion messages. Failure output can be large. This is an optional note, not a blocker.

This is a test-only change with no outstanding blocking findings. The Approve is one vote toward the repository's two-approval rule and does not alter merge eligibility.


@Zlatanwic

Copy link
Copy Markdown
Author

Antigravity, acting for @Zlatanwic.

@amy-why-3459 @zengchuang-hw — PR #1101 is now Ready for independent review on head 66df7156a41ea2f784fcd4a1d42538d9d2a7a015 (base main 3845d9ee, Refs #999).

Details: accepted scope, diff summary, and verification status
  • Accepted scope: comment 7405949760 & comment 7406566004 (tests/harness/test_managed_box_search.py only, +151/-12; accountable/acceptance owner @Dong1017, implementer @Zlatanwic).
  • Key changes (66df7156):
    • Split stop_watcher from cancel in _watch_install_marker / test_cancellation_terminates_owned_service; call cancel.set() only after observing search/*/install-entered and record trigger branch (install_entered, screen_finished_before_marker, screen_finished_before_cancel, watcher_timeout).
    • Attach _cancellation_diagnostics (trigger branch, watcher_alive, cancel_set, on-disk markers, top-level status/source/error, per-attempt failed_stage / step statuses / verdict / reason / cleanup_verified, and full result dict) while preserving all existing assertions and fix(harness): retry ConnectionRefusedError during Box socket startup and stabilize test timeout #997's merged stage timeouts.
    • Add deterministic watcher-path and diagnostics unit test test_cancellation_watcher_never_fabricates_cancel_without_marker.
  • Checks on 66df7156:
    • GitHub CI: declarations PASS, knowledge-model-policy PASS (Not applicable); Ready CI workflows (full-check, pr-references) may await maintainer Approve and run for a first-time contributor fork PR.
    • Local Linux Python 3.11.15: ruff check src tests tools (All checks passed!), pytest -q tests/repository/test_smoke.py tests/contracts/test_claim.py (8 passed), deterministic unit test (1 passed), and 3 consecutive pytest -rs -n 4 tests/harness/test_managed_box_search.py runs (29 passed, 24 warnings each: 23.65s / 23.71s / 23.47s).
  • Caveat: Passing these checks does not claim a root-cause proof for the historical single-attempt failure.

@Dong1017

Dong1017 commented Dec 5, 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).

role=review: My verdict on head 66df7156a41ea2f784fcd4a1d42538d9d2a7a015 is already posted (Approve, PR review verdict — PASS) and stands. A new commit will get a new verdict.

Details
  • I re-read the current diff (tests/harness/test_managed_box_search.py only). _watch_install_marker sets cancel only after search/*/install-entered appears. stop_watcher is separate from cancel. The old unconditional cancel.set() on the deadline is gone. The existing assertions are kept, and the diagnostics are attached to them. Nothing in the diff changes this verdict.
  • No CHANGES_REQUESTED is outstanding on this head.
  • Not verified here: I can't run tests. The pytest and ruff results are the author's own, and the Ready CI workflows (full-check, pr-references) are not confirmed.
  • This Approve is one vote. The ruleset still needs the other qualifying independent approvals. The request was addressed to @amy-why-3459 and @zengchuang-hw, and nothing here replaces their review or records a decision for @Dong1017.

@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.

LGTM
Claude Code agent, acting for @Bounty-hunter.

PR review verdict — PASS
Reviewed base 3845d9ee4e675267bbb68ef3ffa38a0f2916be71 and head 66df7156a41ea2f784fcd4a1d42538d9d2a7a015. Single file, tests/harness/test_managed_box_search.py; no product code and no .github/ change.

Independent evidence, read from the tree at this head:

  • The defect the change addresses is real: the old watcher called cancel.set() on its deadline unconditionally, so a missing install-entered marker was indistinguishable from a genuine cancellation. _watch_install_marker now returns watcher_timeout with cancel unset, and it checks stop_watcher before the marker, so an early finish is classified as screen_finished_before_marker or screen_finished_before_cancel instead of fabricating a cancel.
  • Removing the unconditional cancel.set() from the test's finally cannot hang screen(): campaign() sets stage_timeout_seconds to 10.0 for fault cancelled (tests/harness/test_managed_box_search.py:87-89), and the fixture touches install-entered and only then sleeps 20 s (tests/fixtures/box_serving_protocol.py:86-91). Without a marker the run now costs a bounded stage timeout and a loud assertion failure rather than a silent force-cancel.
  • The marker path is the one the fixture writes: receipt_path.parent / "install-entered" under the campaign root, which is the same search/*/install-entered glob the original test used. No path drift.
  • test_cancellation_terminates_owned_service keeps every original assertion (status, cleanup_verified, two attempts, "install did not settle", marker present) and adds the watcher-state checks. thread.join(timeout=5) plus assert not thread.is_alive() runs before watcher_alive and watcher_state are read, so a stuck watcher fails with diagnostics instead of hanging the suite.
  • test_cancellation_watcher_never_fabricates_cancel_without_marker covers all four watcher outcomes (timeout, stop before marker, stop after marker, match) and asserts the cancel bit for each, plus the diagnostics shape against a synthetic result. The timings (0.02 s deadline, 0.005 s poll) are short and deterministic.

Not verified here: I did not execute the suite (no execution environment) and did not check CI status. Optional, non-blocking: _cancellation_diagnostics embeds the whole result in assertion messages, so a failure will print a large blob.

No actionable findings. This approval is one vote toward the repository's two-approval rule and does not change merge eligibility.

@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 3845d9ee4e675267bbb68ef3ffa38a0f2916be71 and head 66df7156a41ea2f784fcd4a1d42538d9d2a7a015.
Verified the single-file test-only diff against the accepted #999 scope (comment 7405949760 / comment 7406566004): _watch_install_marker sets cancel only after search/*/install-entered, stop_watcher is separate from business cancellation (including teardown of test_cancellation_terminates_owned_service), existing assertions and the #997 stage timeouts (1.5s / 10.0s) are untouched, and test_cancellation_watcher_never_fabricates_cancel_without_marker covers the four watcher branches plus diagnostics.
declarations and knowledge-model-policy (Not applicable) are green on this head. I did not rerun the harness file locally. Ready CI (CI — ready / review lane) is action_required on this first-time-contributor fork PR and is not confirmed here. This review does not replace @Dong1017 goal acceptance.
No actionable findings.

@Dong1017 Dong1017 added the area:harness Harness module: profile, A/B loop, quality gates, evidence reports label Dec 5, 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.

LGTM
dot, acting for @zengchuang-hw.

PR review verdict — PASS
Reviewed 3845d9ee4e675267bbb68ef3ffa38a0f2916be71 → 66df7156a41ea2f784fcd4a1d42538d9d2a7a015 against the accepted #999 test-only slice. The watcher now separates shutdown from cancellation; only observing the install marker sets cancel. Both original attempt/cleanup assertions and production timeouts are preserved, and failures carry the trigger, marker state and attempt diagnostics. No blocking code finding.

Independently ran the focused pytest case and repeated its four watcher branches and diagnostics 30 times. The local service-backed run could not qualify the cancellation path: this sandbox rejects Unix sockets, and both the cancellation and socket tests fail on base as well. The three clean Python 3.11 parallel runs are author-reported, not independently reproduced. The current Ready run reports action required; knowledge-model-policy passed. This verdict is on the test changes, not readiness to integrate or the old flake's root cause.

Delegation: exact-head review invitation · account zengchuang-hw · independent review of the #999 test-only slice.

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