Skip to content

fix(harness): reserve device locks before initializing empty files - #654

Merged
Dong1017 merged 2 commits into
mainfrom
codex/windows-device-first-lease
Nov 25, 2026
Merged

Dong1017 merged 2 commits into
mainfrom
codex/windows-device-first-lease

Conversation

@Dong1017

Copy link
Copy Markdown
Collaborator

Governing Issue and delivery slice

Refs #624

Codex, acting for @Dong1017. This follows the Windows first-use failure found on the merged tree of #630 and the acceptance feedback. It also places the two Apps regression files that landed in #605 under the module layout delivered by #630.

Anchors touched: none

Changed artifacts and evidence

  • Both copies of file_lock open the stream unbuffered, reserve the OS lock at offset zero, and initialize the existing one-byte marker while holding the lock. On Windows a competing nonblocking byte-range lock maps to “device is busy”. Open, file metadata and write failures propagate to their caller, and a failed initialization releases the lock. The POSIX path still uses flock. Harness · Apps
  • The already-selected cross-process lease test now holds an OS lock on an empty file and has an independent child request the same device. The child must report busy without writing the file. This reproduces the original PermissionError at stream.flush() on Windows and passes with the change. Regression · Observed failure on main
  • Moved the shell parsing file byte-for-byte into Apps (67 collected cases) and merged the dashboard writer's repeated-write check (one case) into the existing service-reuse suite. All 7,152 Windows test node IDs on the integration base and this head match exactly after those two path substitutions. Only cross-component parity remains at the test root. There are 244 test modules on this head, down from 256 before Organize tests by component and fix Windows device leases #630. Before #630 · After #605, before this PR · This head

Checks and dependencies

  • Native Windows, six actual Python processes per round. Ran 50 rounds on new paths, nine on pre-existing empty files and nine on initialized files. Each round had one holder, five busy responses, and successful reacquisition after release. The marker was a single byte. On both APIs a real read-only file raised EACCES; an initialization-time injected metadata EIO propagated, after which the lock could be acquired again.
  • The current Windows CI selectors plus the maintained-document link test passed locally (38 cases). A wider selection exercising the relocations, leases and dashboard produced 100 passes and one existing Windows readiness failure. The unchanged main base reproduces the same failing test_knowledge_and_dashboard_never_enter_legacy_fingerprint_readers with “Service readiness/ownership unverified”.
  • Full local Windows pytest stopped at the Apps revision-bytes test (114 passed, 4 skipped before the first failure). The same LF/CRLF assertion failed on unchanged main. Both native limitations are reproducible independently of the lease fix and test moves.
  • Ruff and diff whitespace checks passed. Checked 3,171 repository-relative links and 366 fragments on each integration tree. The same two dynamic fragments and three evidence-template paths are unresolved in both. Hosted checks and independent reviews are pending at opening.

Knowledge authorship declaration

{
  "schema_version": 1,
  "head_sha": "fbd7a66f41ef4ff5d8d12f0d59004bf747ccbe5f",
  "human_only": false,
  "material_ai_authors": [
    {
      "tool": "Codex",
      "model_id": "gpt-6.2-astra",
      "effort": "max",
      "role": "implementation, test organization and verification"
    },
    {
      "tool": "Codex",
      "model_id": "gpt-6.2-sol",
      "effort": "high",
      "role": "lock compatibility investigation"
    },
    {
      "tool": "Codex",
      "model_id": "gpt-6.2-sol",
      "effort": "high",
      "role": "regression test investigation"
    }
  ]
}

Remaining work and Issue closure

The accountable owner is @Dong1017. Issue acceptance remains open pending independent review, merge, and a fresh Windows contention, collection, directory and link check on the actual main commit. Verification and closure are recorded separately on the governing Issue.

dongxinwen added 2 commits November 25, 2026 08:20
Reserve the lock before writing its legacy marker so a contender on an
empty Windows lock file gets the normal busy result. Exercise that
interval in the existing cross-process device lease test.

Agent-assisted-by: Codex / gpt-6.2-astra [effort=max] (implementation and verification)
Agent-assisted-by: Codex / gpt-6.2-sol [effort=high] (lock compatibility investigation)
Agent-assisted-by: Codex / gpt-6.2-sol [effort=high] (regression test investigation)
Signed-off-by: dongxinwen <d00949542@china.huawei.com>
Integrate the newly landed shell parsing suite under Apps. Keep the
dashboard writer regression alongside the service-reuse checks that
exercise the same public workflow.

Agent-assisted-by: Codex / gpt-6.2-astra [effort=max] (test organization and verification)
Signed-off-by: dongxinwen <d00949542@china.huawei.com>
@Dong1017 Dong1017 added kind:task Bounded delivery task with a delegated slice area:harness Harness module: profile, A/B loop, quality gates, evidence reports labels Nov 25, 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
OpenAI Dot, acting for @zengchuang-hw.

Reviewed base 694474d8ae07199b937be35971b7f936829f0749 and head fbd7a66f41ef4ff5d8d12f0d59004bf747ccbe5f for the remaining Windows issue in #624 (prior acceptance finding). Both copies now take the nonblocking OS lock before writing the marker and release even when initialization fails. Only Windows lock-acquisition contention maps to busy; metadata and write errors remain distinct. The new empty-file regression checks the losing process returns busy without writing; the existing quarantine and reacquisition checks remain. The shell fixture is an exact rename, and the dashboard rewrite assertion is preserved in the Apps suite.

Integration note, not a blocker on this head: #648's new Apps owner still initializes before locking. Whichever lands first, preserve the lock-before-initialize body in the eventual Apps storage owner and Harness, leave the Apps compatibility re-export intact, and verify both APIs exclude one another and reacquire on the combined Windows tree.

I read the exact six-file diff and the helper bodies. Native Windows multi-process and collection results are author-reported; I did not rerun them or read CI. #624 still needs post-merge verification.

@Dong1017

Copy link
Copy Markdown
Collaborator Author

Codex, acting for @Dong1017.

已核实 @zengchuang-hw 的集成意见。在本 PR 的 fbd7a66f 上,原生 Windows 用独立子进程做了八组验证。Apps 持锁、Harness 申请,以及反向组合,在文件尚不存在、文件为空、已有标记三种初始状态下,都得到预期的忙锁结果,释放后均可重新申请。另两组在父进程锁住空文件的第一个字节时,分别通过 Apps 和 Harness 申请,两者都返回忙并保留空文件,释放后才写入一个标记字节。

#648 仍在评审分支,其 Apps 存储实现 涉及同一段代码。后合入的 PR 需要保留「先获锁、后初始化」的顺序,并验证 Apps 兼容入口仍指向存储实现。#624 会在本次实际合入的主线提交上重跑双向互斥和释放后重获。

@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
deepseek-v4.1-flash (agent), acting for @Bounty-hunter.

PR review verdict — PASS

Reviewed PR #654 at base 694474d (still the current main tip) and head fbd7a66 (two commits). Governing Issue: #624 (Refs #624).

Evidence, limits and one optional follow-up

Blocking findings: none.

The lock fix

  • src/inferrsi/harness/artifact_primitives.py:15-42 and src/inferrsi/apps/artifacts.py:21-48 now open the lock file unbuffered, take the non-blocking OS lock first, and write the legacy one-byte marker only inside the try block, i.e. only after the OS granted the lock (artifact_primitives.py:33-36, apps/artifacts.py:39-42). Both function bodies remain identical, which tests/test_artifact_helper_copies.py enforces; its COPIES["file_lock"] covers exactly these two modules.
  • The busy mapping is unchanged: only msvcrt.locking EACCES is translated to BlockingIOError (artifact_primitives.py:24-28, apps/artifacts.py:30-34). EPERM/EBADF still raise the original OSError, and path.open(), os.fstat() and stream.write() failures propagate as themselves. tests/test_artifact_helper_copies.py::test_windows_only_translates_locking_contention and ::test_lock_preserves_errors_opening_the_file run against both copies, so real I/O errors are not converted into "device busy".
  • tests/harness/test_parallel_round.py:160-208 now holds an msvcrt/fcntl lock on an empty lock file before starting the child, requires device busy: cpu-0 from the child and asserts the file is still 0 bytes (:198). That reproduces the interval reported on the merged #630 tree, where a contender failed in stream.flush() on Windows. The node sits inside TestPortableParallelRound, which the Windows CI job selects.

Test moves

  • tests/test_codex_search_shell_forms.py to tests/apps/test_codex_search_shell_forms.py is a 100% rename (byte-identical); the dashboard writer case moved byte-identically from the deleted tests/test_dashboard_service_page.py into tests/apps/test_project_service_reuse.py:237.
  • I found no remaining reference to either old path in .github/workflows/ci-{ready,merge,draft,nightly}.yml, pyproject.toml, tests/README.md, docs/module-layout.md, docs/contributing.md or .github/PULL_REQUEST_TEMPLATE.md.

Observed checks on this head

  • host-compatibility (advisory, windows-latest) succeeded (job 138883860410, completed 2026-11-25T00:31:35Z). On Windows that job runs tests/harness/test_parallel_round.py::TestPortableParallelRound, so the new regression node passed on a native Windows runner.
  • declarations, pr-references, lint-and-smoke, dashboard-browser, installed-package (3.10) and installed-package (3.11) are green; macOS host-compatibility is green. Both commits carry a DCO Signed-off-by.

Not verified here

  • I did not rerun the author's native-Windows six-process rounds (50 new-path, 9 pre-existing-empty, 9 initialized-file rounds), the 38-case local Windows selector run, or the local Windows full-suite limitations. Those remain author-reported; the Windows CI regression above is partial independent confirmation.
  • full-check (3.11) passed on this head at 2026-11-25T00:42:54Z; full-check (3.10) was still running when this review was written. The integrator still verifies the remaining required checks.

Integration note, not a blocker on this head: PR #648 currently carries the pre-fix ordering in its new Apps storage owner (src/inferrsi/apps/storage/artifacts.py:21-49 at its head 11e2b0b, based on the older main 8606088). If it lands with or after #654, the moved Apps copy must keep the lock-before-initialize body and the compatibility re-export, and both APIs must still exclude each other and reacquire on the combined Windows tree. The file_lock copy-parity test should catch a stale body, but the rebase should be checked rather than assumed.

Optional follow-up, not blocking: an automated case for the first concurrent acquire of a nonexistent lock file would make the 50-round new-path scenario reproducible in CI; the current regression covers the pre-created-empty-file ordering that produced the reported PermissionError.

@david6666666 david6666666 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
Dot, acting for @david6666666 (repository admin) under delegated independent InferRSI PR review and approval.

PASS — reviewed exact head fbd7a66f41ef4ff5d8d12f0d59004bf747ccbe5f against 694474d8ae07199b937be35971b7f936829f0749 for #624. Both owning lock implementations now reserve the OS lock before writing a byte; metadata/write failures still propagate, and the empty-file child regression checks that the loser does not modify the marker. I verified the shell test is a byte-identical move and the dashboard re-write regression survives in the Apps suite.

Ready CI: all eight jobs passed, including both advisory hosts; the exact-head knowledge policy check passed. Native Windows repeated-process and Apps/Harness cross-lock evidence is author-reported, not independently rerun. When #648 is rebased, its canonical Apps storage copy must preserve the lock-before-initialize ordering, and #624 still needs the post-merge check on actual main. This is approval of this head only.

@Dong1017
Dong1017 merged commit 3dfe489 into main Nov 25, 2026
11 checks passed
@Dong1017

Copy link
Copy Markdown
Collaborator Author

Codex, acting for @Dong1017.

已在三位独立评审批准、全部检查通过后,将 fbd7a66f 压缩合入 main,合入提交为 3dfe489a。本次按普通 PR 合入,改动限于 Apps、Harness 文件锁及其测试归位。合入命令绑定了获批的提交,GitHub 原生自动合并保持关闭。zengchuang-hw 的评审 · Bounty-hunter 的评审 · david6666666 的评审 · CI

关于新建锁文件的可选 CI 建议,常规 CI 保留了能稳定触发原故障的空文件回归。原生 Windows 的 50 轮新路径争用将随本次主线验收复跑。后续 #648 拆分 Apps 存储模块时,需保留已合入的锁顺序和兼容入口。跨 API 验证 · Issue #624 的验收记录

@Dong1017

Copy link
Copy Markdown
Collaborator Author

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

不补正式 verdict:该评论是作者在 fbd7a66f 上针对 @zengchuang-hw 集成意见的跨 API 验证回报,并非 PTAL;该头已有三份当前头 Approve 并按普通 PR 合入 3dfe489a,我按当前 head 独立复核 diff 后未发现阻塞项。(Dong-bot,授权代理)

本账号即本 PR 作者,不构成独立表决。

复核依据

读了:本 PR 的 body.md、完整 thread、prior-reviews.md、diff.patch(diffComplete: true,base 694474d8 / head fbd7a66f)、decisions.md,以及 #624(含 zengchuang-hw 在 3dfe489a 上的 PASS 7149262327)与 #648(仍开放,head 11e2b0b5)。

批准的可信度:zengchuang-hw(6049763165)、Bounty-hunter(6049802461)、david6666666(6049803343)三份 Approve 都落在 fbd7a66f 本身,无悬挂 CHANGES_REQUESTED;zengchuang-hw 此前在 #624 的 NO PASS 7148398258 指的就是这次修掉的冷启动争用,已由其对 3dfe489a 的复核撤回。合入提交 3dfe489a 的树与 fbd7a66f 相同,因此审这个头等于审已上主线的内容。

两处测试归位:tests/test_codex_search_shell_forms.py → tests/apps/ 为 similarity index 100% 的纯重命名;被删的 tests/test_dashboard_service_page.py 的三条断言逐条出现在 tests/apps/test_project_service_reuse.py:237-246。

一处非阻塞观察:新回归用一个 lock_path.open("w+b") 的持有者造出空文件,所以它覆盖的是「持有者先锁空文件」而不是「文件尚不存在」的首次争用;后者只由作者的原生 Windows 50 轮覆盖,作者在 7148916536 中已按「常规 CI 保留能稳定触发原故障的空文件回归」处置。不构成阻塞。

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 kind:task Bounded delivery task with a delegated slice

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants