Skip to content

bug(apps): Windows busy delivery lock escapes as PermissionError #494

Open

Description

@zengchuang-hw

Refs #490
Refs #493

Problem

On Windows, exporting a managed optimization campaign while its writer holds .session.lock raises a raw PermissionError instead of the documented retryable SnapshotBusy / writer-active error.

infra.artifacts.file_lock calls msvcrt.locking(..., LK_NBLCK, 1). Lock contention raises PermissionError: [Errno 13] Permission denied. apps.delivery.project catches BlockingIOError, so this Windows contention case bypasses the public error translation.

Reproduction and observed evidence

Environment was Windows and CPython 3.12. Run the existing regression with the checkout installed or its src on PYTHONPATH.

python -m pytest -o addopts= -q --tb=short tests/test_result_delivery.py::test_progress_uses_committed_control_and_a_fixed_clock

The test holds optimization._locked(root) and calls delivery.project(root, export_id="busy"). It expects ValueError matching writer is active through the SnapshotBusy subclass. The observed exception originates at src/inferrsi/infra/artifacts.py:28 and escapes through src/inferrsi/apps/delivery/__init__.py:123.

The same test fails on an unmodified archive of base 8aba657da79e8ed9f6e6fbb33437e9d9fdd8f1c7 and on #493. The storage implementation bodies in #493 are unchanged; its direct import migration does not introduce this failure. No assertion or platform coverage was weakened.

Proposed bounded correction and acceptance

  • Normalize genuine lock contention at the appropriate owning boundary so Apps reports its existing retryable writer-active error on Windows and POSIX.
  • Preserve real permission, missing-path and unrelated filesystem errors; do not treat every OSError as a busy writer.
  • Keep the existing nested-lock regression and add focused coverage distinguishing contention from unrelated I/O failures, including lock release/retry.
  • Verify on Windows and POSIX. Existing Linux full-check and the narrower Windows host-compatibility checks do not establish that this full Windows test passes.

This issue tracks the baseline limitation requested during #490's design and implementation follow-up. This correction is separate from the physical directory migration in #493.

Activity

  1. Dong1017 commented on Nov 18, 2026

    @Dong1017
    Collaborator

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

    Assessment: This looks like a valid, well-scoped Windows-only bug. msvcrt.locking(..., LK_NBLCK, 1) reports lock contention as PermissionError (Errno 13). On POSIX the equivalent contention surfaces as BlockingIOError, which apps.delivery.project catches. So the Windows path skips the SnapshotBusy / "writer is active" translation. The issue's claim that this predates #493 is credible. It reproduces on base 8aba657 and the storage bodies in #493 are unchanged. I haven't run anything myself. This is based on the issue text only.

    Where to fix it: I'd normalize at the owning boundary, infra.artifacts.file_lock. That function is where the platform difference originates, and it avoids Apps needing to know about msvcrt semantics. Two options:

    1. file_lock catches the Windows contention error and re-raises BlockingIOError (or a dedicated LockContention subclass of BlockingIOError). Apps then stays unchanged and POSIX behavior is identical.
    2. Widen the except in apps.delivery to include PermissionError. I'd avoid this because it treats genuine permission failures as a busy writer, which the acceptance criteria forbid.

    Option 1 is preferable.

    Risks and gaps to settle before implementing:

    • How to tell contention from a real permission error. A bare PermissionError is ambiguous. On Windows, msvcrt.locking failing under LK_NBLCK reports EACCES (13), and a real denied-open also reports EACCES. The safest split is by call site. Only exceptions raised by the msvcrt.locking call itself, after the lock file has been opened successfully, should be mapped to contention. Errors from open() or the path stay untouched. The issue should state this explicitly.
    • Other msvcrt errors. EDEADLOCK (36) can also occur with the blocking LK_LOCK variants. Confirm it is not reachable here, or map it deliberately.
    • Other callers of file_lock. Check whether other callers (the optimization writer, other apps) depend on seeing PermissionError today. Changing the exception type is a behavior change for them.
    • Lock release and retry. The acceptance criteria mention this. The test should show that after the holder releases, a second acquire succeeds. It should also show that a failed acquire doesn't leave a handle or partial lock behind.
    • Test strategy. The unit coverage for "contention vs. unrelated I/O" should not need real Windows. Monkeypatch msvcrt.locking to raise PermissionError, and separately make open raise PermissionError and FileNotFoundError. Keep one real-lock test that runs on both platforms.
    • CI. The issue says Linux full-check and the narrow Windows host-compat checks don't cover this test. A Windows job that runs tests/test_result_delivery.py, or the whole suite, would close that gap. It could be a follow-up if the Windows runner cost is a concern. Say which.

    Suggested next steps:

    1. Decide on option 1 and state the contention-vs-permission rule (by call site, as above) in the issue.
    2. Implement it in infra/artifacts.py, keep test_progress_uses_committed_control_and_a_fixed_clock as is, and add the focused tests listed above.
    3. Report Windows and POSIX results in the PR. Keep this PR separate from the refactor(apps): group artifact storage under apps.storage #493 directory migration, as the issue already says.

    Not verified: I have not run the regression or inspected the code at artifacts.py:28 or delivery/__init__.py:123. The points above rely on the issue's description.

  2. added
    area:harnessHarness module: profile, A/B loop, quality gates, evidence reports
    kind:bugDefect report: an observable symptom that differs from expected behavior
    on Nov 18, 2026
  3. david6666666 commented on Nov 18, 2026

    @david6666666
    Collaborator

    Could the Windows regression exercise both directions of contention on the same .session.lock? At the merged storage commit, Apps export acquires it through infra.artifacts.file_lock, while Harness optimization uses its separate R2 artifact_primitives.file_lock. An Infra-only change can fix the existing writer-to-export case without testing what the Harness caller sees. Please verify both directions and reacquisition, and state whether error normalization is export-only or shared without reintroducing a Harness-to-Infra import.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:harnessHarness module: profile, A/B loop, quality gates, evidence reportskind:bugDefect report: an observable symptom that differs from expected behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions