Skip to content

fix(apps): report Windows session lock contention as retryable - #546

Merged
Dong1017 merged 2 commits into
InferMatrixLab:mainfrom
Inference1:fix/windows-session-lock-contention
Nov 21, 2026
Merged

Dong1017 merged 2 commits into
InferMatrixLab:mainfrom
Inference1:fix/windows-session-lock-contention

Conversation

@Inference1

@Inference1 Inference1 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Governing Issue and delivery slice

Refs #494

This patch follows the proposed lock-acquisition boundary and cross-process acceptance cases in the Issue. Apps and Harness now own separate copies of the lock helper after #535. Issue review

Problem

On Windows, a writer holding the managed campaign's .session.lock causes msvcrt.locking(..., LK_NBLCK, 1) to raise PermissionError(EACCES). Delivery catches BlockingIOError and the export returns a generic publication error for this case.

What

Translate the Windows nonblocking lock-acquisition error to BlockingIOError(EAGAIN) in both helper copies. Assert the error type and reacquisition in the existing cross-process test, and assert the retry message in the managed export probe.

Why needed

An export can run while a campaign is committing evidence. Callers need the documented retry signal so they can wait for that commit and export a consistent snapshot.

Design and implementation

Only EACCES raised at the LK_NBLCK call is translated. The CRT reports EDEADLOCK after exhausting retries in the blocking modes. Opening the lock file, releasing the lock, and other failures keep their original error paths. Both helpers keep the same source and lock byte, and Apps continues to translate contention through SnapshotBusy. CRT locking return codes

Knowledge authorship declaration

Not applicable. The patch touches the Apps and Harness lock helpers and their tests.

Checks and dependencies

  • Linux, Python 3.12.14. Artifact-helper parity, both cross-process contention directions and reacquisition, managed export, agent-session and import/migration tests. 240 passed, 2 skipped, 43 subtests passed. The skipped tests require Playwright.
  • Linux, Python 3.11.18. The lock helpers, cross-process probe and delivery contention regression passed 22 tests.
  • GitHub-hosted native Windows (windows-latest, Python 3.12) on cc6b0ff0. 22 passed. The run covered the artifact helpers, both cross-process contention directions, reacquisition and the managed export regression. Native Windows job
  • ruff check src tests tools and git diff --check passed.

Remaining work and Issue closure

Independent review and the upstream Ready workflow are pending. Issue acceptance stays with its owner.

Normalize the Windows nonblocking acquire error in both session lock helpers. Keep the retryable export error consistent across platforms and cover both lock directions.

Agent-assisted-by: Codex (author)
Signed-off-by: Inference1 <3617237115@qq.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.

LGTM

PR review verdict — PASS
Reviewed base 9466bc8d910c9fef55d4a9e23ee1a82950280c30 and head cc6b0ff0cbec003aecafdfd28417f77be31aade2 (full diff, first review). No prior formal reviews and no outstanding CHANGES_REQUESTED were seeded. This Approve is the only review on this head. I also read #494, the governing issue.

What I verified in the diff

  • Fix location: apps/artifacts.py and harness/artifact_primitives.py get the same change, so both directions of the shared .session.lock are normalized. This follows david6666666's and amy-why-3459's request on #494. There is no Harness→Apps/Infra import, and the copy-sync convention is kept.
  • Narrow translation: only a PermissionError with errno == EACCES raised by msvcrt.locking(..., LK_NBLCK, 1) is converted to BlockingIOError(EAGAIN, ..., path), chained with from error. Other errnos are re-raised unchanged. The open() call is outside the try, so open and path errors are not translated. This matches the #494 acceptance criteria and the "after the lock file opened" scoping.
  • Unit coverage (tests/test_artifact_helper_copies.py), parametrized over every COPIES["file_lock"] module:
    • EACCES becomes BlockingIOError with errno EAGAIN and __cause__ set.
    • EPERM and EBADF pass through as the identical exception object.
    • A failed acquire calls locking exactly once, so there is no unlock or partial-lock state.
    • A retry then acquires and releases, with call args [(NBLCK,1),(NBLCK,1),(UNLCK,1)].
    • FileNotFoundError on a missing directory and PermissionError from open() are preserved.
  • Real cross-process tests: test_session_lock_across_processes.py now asserts the exact result {"acquired": False, "error": "BlockingIOError"} instead of only acquired is False. This holds for every parametrized holder/contender pair, so it covers both directions plus the release/re-acquire step. session_lock_probe.py now asserts that the export returns a "writer is active" error. This replaces the old comment that allowed either exception type.
  • Stale references removed: the docstring pointer to #494 as a separate assertion is gone, consistent with the fix.

Not verified here (no execution in this review)

  • I did not run the tests, and I did not see CI results.
  • I did not run anything on real Windows. The EACCES-on-contention mapping rests on the #494 reproduction and on the mocked msvcrt tests. The real-lock tests run on Windows only if the Windows CI jobs include them. #494 asked for Windows and POSIX verification, so please confirm a Windows run of tests/test_result_delivery.py::test_progress_uses_committed_control_and_a_fixed_clock and the cross-process tests before merge.
  • I did not see COPIES["file_lock"] or the full file_lock body. I could not confirm that no other copy of file_lock exists that needs the same change. The copy-equality test would catch that in CI.
  • EDEADLOCK is not reachable with the non-blocking LK_NBLCK mode, and the PR leaves it unmapped. I did not check other callers for reliance on PermissionError. This is optional follow-up context for the PR description.

Non-blocking: the merge ruleset still needs two eligible approvals and passing required checks.


Posted by Dong-bot, an automated agent acting on behalf of @Dong1017 (always-on-bot, model claude-sonnet-5-5).

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

NO PASS

首次独立检视:9466bc8d910c9fef55d4a9e23ee1a82950280c30…cc6b0ff0cbec003aecafdfd28417f77be31aade2,对照 #494 的范围。代码方向正确:两份锁实现一致,只把 Windows 非阻塞取锁时的 EACCES 转成 BlockingIOError(EAGAIN),Apps 再映射成现有的 SnapshotBusy;打开、解锁和其他错误不走这条转换路径。

批准前还缺 #494 明确要求的原生 Windows 行为证据:让一个独立进程持有 .session.lock,确认 managed export 返回 writer is active 且不发布目录;释放后重试应成功发布。已有探针覆盖这些断言,可直接提供该场景在本提交上的结果。这里缺的是目标平台行为实测,不是 CI 状态,也不需要为了本次检视再改代码。

本轮已读五个变更文件,核对异常传递与两份实现;在隔离临时目录对提取的原实现验证了模拟 Windows 的 EACCES、EPERM、EBADF 和重新取锁,也实际验证了 Linux 跨进程争锁与释放后重取。未运行原生 Windows 或重跑完整导出套件。

@Dong1017 Dong1017 added the kind:task Bounded delivery task with a delegated slice label Nov 21, 2026

Copy link
Copy Markdown
Collaborator

First complete review: 9466bc8d910c9fef55d4a9e23ee1a82950280c30…cc6b0ff0cbec003aecafdfd28417f77be31aade2. I agree with the code direction and with @zengchuang-hw in #546 (review), so I am not Approving on this head.

The two helper copies apply the same narrow translation: only a PermissionError with errno == EACCES from msvcrt.locking(..., LK_NBLCK, 1) becomes BlockingIOError(EAGAIN), chained with from error. Opening the lock file, unlocking, and other errnos stay on their original paths. The new unit tests distinguish EACCES / EPERM / EBADF and preserve open failures. The cross-process probe now asserts BlockingIOError and a writer is active export error.

Blocking: #494 still requires native Windows evidence. The description reports Linux pytest results only. The new tests mock msvcrt and do not exercise a real Windows lock. Before Approve, please post results from this head on Windows: an independent process holds .session.lock, managed export returns writer is active and does not publish, and a retry after release publishes successfully. The existing probe can provide that; no further code change is required for this request.

I read the five changed files and both helper bodies. I did not run a real Windows host.

@Inference1

Copy link
Copy Markdown
Contributor Author

@zengchuang-hw @amy-why-3459 The native Windows run verifies the managed export case on the current review head, cc6b0ff0cbec003aecafdfd28417f77be31aade2. The job checked the full checkout SHA, asserted os.name == 'nt', and finished with 22 passed on windows-latest and CPython 3.12.10. Native job and test log

  • Managed export. test_an_apps_export_of_a_valid_session_is_refused_while_a_harness_process_holds_it passed. It starts a distinct Harness process and waits for it to hold .session.lock. Apps returns writer is active and the destination directory remains absent. The probe then releases the child and retries. The retry publishes a bundle that delivery.read_bundle reads as progress. Test and probe
  • Both directions and the original regression. The Harness-to-Apps and Apps-to-Harness cases both returned BlockingIOError and reacquired after release. test_progress_uses_committed_control_and_a_fixed_clock also passed. I reran the same selection on Linux with CPython 3.12.14 and got 22 passed.
  • Helper scope. COPIES["file_lock"] lists Apps artifacts.py and Harness artifact_primitives.py, the two definitions at this head. Managed delivery catches BlockingIOError, and the CLI uses its generic OSError handler for lock failures in the other command paths. The CRT documents EDEADLOCK for the blocking retry modes. Both helpers use LK_NBLCK. CRT reference

Please re-review cc6b0ff0 with this evidence. The upstream Ready workflow also shows action_required and awaits repository action. Ready workflow

@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

同一提交 cc6b0ff0cbec003aecafdfd28417f77be31aade2 的证据增量复审,没有新代码提交。上轮 NO PASS 缺的是 #494 要求的原生 Windows 管理导出争锁验证;本次复审请求 已补齐。

我直接读取了专门的 Windows 验证任务日志:任务校验了完整 SHA 和原生 Windows,pytest 在 win32 / CPython 3.12.10 报告 22 passed,包含真实跨进程争锁的两个方向、管理导出及原始回归。对照固定测试源码,管理导出用例确实检查持锁时返回 writer is active、不发布目录,释放后重试并能回读 progress。本轮是独立核验证据,不是我在本机重跑 Windows;POSIX 行为沿用上轮的独立锁验证。未查看上游 Ready CI,也不判断合入。

@Inference1

Copy link
Copy Markdown
Contributor Author

@zengchuang-hw Thank you for checking the Windows evidence and recording your independent Approve on cc6b0ff0. The repository asks for LGTM alone on the first nonempty line of an approving review. If your verdict stands, please update the first line of your review to LGTM and keep the verification details below it. Review · Review convention

Copy link
Copy Markdown
Contributor

The approval stands for cc6b0ff0. I’m keeping the existing PASS first line pending a decision on the format, so don’t count this review toward the repository’s first-line LGTM merge requirement.

@Inference1

Copy link
Copy Markdown
Contributor Author

@Dong1017 Please confirm the applicable review format for cc6b0ff0. @zengchuang-hw confirmed their independent Approve and asked that the PASS-headed review stay outside the first-line LGTM count pending that decision. The collaboration guide currently yields one qualifying approval. Reviewer’s reply · Review convention

@amy-why-3459 The native Windows log and the managed export assertions you requested are linked in the follow-up. Please record your independent verdict on cc6b0ff0 when you have reviewed that evidence, with any remaining gap you find. Windows evidence

@Dong1017

Copy link
Copy Markdown
Collaborator

Posted by Dong-bot, an automated agent acting on behalf of @Dong1017 (always-on-bot, model claude-sonnet-5-5).

Decision: the applicable format is the repository rule. An approving review counts only if the first non-empty line is exactly LGTM, in that case and spelling. A PASS-headed Approve does not count toward the two-approval requirement. I'm not waiving the rule for cc6b0ff0.

  • @zengchuang-hw's review. Their substance is accepted as an independent re-check: they read the Windows job log and checked the probe source. It stays outside the count while its first line is PASS. To count, they can submit a new Approve on cc6b0ff0 that starts with LGTM and keeps the verification text below it. If GitHub lets them edit the review body, changing the first line also works. This is a format fix only. No new code or evidence is needed.
  • Current count on cc6b0ff0. One qualifying approval: the Dong-bot (authorized delegate) Approve, which starts with LGTM (review 6004116247). A second qualifying approval is still needed. It can come from zengchuang-hw's reformatted review or from @amy-why-3459.
  • Blockers. None outstanding. There is no CHANGES_REQUESTED on this head. The earlier "NO PASS" was a COMMENT and has been superseded by the Windows evidence.
  • Diff re-check. I re-read the diff against the Windows evidence and my earlier Approve stands.
    • Both file_lock copies translate only PermissionError with errno == EACCES, raised at msvcrt.locking(..., LK_NBLCK, 1), into BlockingIOError(EAGAIN) chained with from error. Other errnos and open failures keep their original paths.
    • The tests cover EACCES, EPERM and EBADF, preservation of open errors, and reacquisition.
    • The cross-process test now asserts the exact BlockingIOError, and the probe asserts writer is active.
    • The native Windows job on this head reported 22 passed, including both contention directions and the managed export regression.
  • Not verified here. I did not run any tests or a Windows host. I relied on the linked job log. I did not look at the upstream Ready workflow, which still shows action_required.
  • Next steps.
    1. zengchuang-hw re-submits an LGTM-first Approve.
    2. amy-why-3459 records an independent verdict on the Windows evidence.
    3. The Ready workflow gets approved by someone with repository access.

@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

PR review verdict — PASS
Same-head re-review of cc6b0ff (PR base 9466bc8), triggered by the native Windows evidence and re-review request in #546 (comment).

The previously blocking #494 request is resolved. I read the job log at https://github.com/Inference1/InferRSI/actions/runs/44885312620/job/136789214446: the follow-up commit a84c9b8 only adds the verification workflow, whose parent is this PR head; the job checked out and asserted HEAD cc6b0ff0cbec003aecafdfd28417f77be31aade2 on windows-latest (Windows Server 2025, CPython 3.12.10, platform win32) and reported 22 passed in 1.73s. That selection includes both cross-process lock directions, test_an_apps_export_of_a_valid_session_is_refused_while_a_harness_process_holds_it (the probe asserts writer is active, no destination directory, and a retry that publishes progress), and the original delivery regression. No new code was pushed to this PR head. I did not rerun a Windows host myself.

This Approve covers the Windows lock-translation change and the linked evidence, not a merge decision. I did not re-check the upstream Ready workflow.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Technical / third-party verify (cursor App permission none — not write+ / dual / merge-ready).

Tip already has Dong1017 always-on + amy + zengchuang Approves — skipping tip re-Approve (dual-clean, head unchanged).

Fork Ready was stuck in action_required; tip Ready run was approved so the Ready lane can finish. Await Ready green; steward merge remains write+ / Dong-bot.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Technical / third-party tip COMMENT (cursor App permission none — not re-Approve; tip already dual-clean Dong + amy + zeng).

Ready blocker: Ready full-check FAIL on test_recovered_attempt_does_not_trust_a_rewritable_declaration / retired inferrsi.infra.artifacts.digest (run 44884610073). Unrelated to Windows session-lock retryable mapping.

Unblock: #556 MERGED. Rebase/update onto main + Ready re-run, then write+ steward merge when green.

@Inference1
Inference1 marked this pull request as draft November 21, 2026 12:06
@Inference1
Inference1 marked this pull request as ready for review November 21, 2026 12:06
Bring in InferMatrixLab#556, which restores the recovery test to the Harness digest.
The five-file Windows session lock patch is identical to the reviewed change.

Agent-assisted-by: Codex (author)
Signed-off-by: Inference1 <3617237115@qq.com>

@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

Incremental review: cc6b0ff0cbec003aecafdfd28417f77be31aade2 → 52c9e19288e3a69e286e4821ce03781c3b483cad. Previous review. The new head merges main@10ba7a55; the five PR files are byte-identical to the previously approved head, and all other changes match that base. The managed export entry point and lock path are unchanged; the added delivery test covers unrelated token projection, and the managed-export regression is unchanged.

For #494, I reran six focused cases with the exact lock helpers and a simulated Windows locking API: both copies translate EACCES to retryable EAGAIN, preserve EPERM/EBADF, and release after reacquisition. The earlier native Windows run on cc6b0ff0 still supports the unchanged cross-process and managed export paths; it is not a native Windows run of this new head. No new code blockers or non-blocking findings. I did not rerun native Windows or the full suite, or inspect CI.

@Dong1017
Dong1017 merged commit 4bc1927 into InferMatrixLab:main Nov 21, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:task Bounded delivery task with a delegated slice

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants