Skip to content

test(config): hold a racing uninstall to its guarantee whatever its outcome (#8379) - #8876

Merged
lidge-jun merged 1 commit into
devfrom
fix/8379-ownership-race-test
Nov 17, 2026
Merged

lidge-jun merged 1 commit into
devfrom
fix/8379-ownership-race-test

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

tests/config/config-ownership-concurrent-record.test.ts failed intermittently ("a registration racing uninstall ... with its first run finding the lock still held", Windows dev batch run 44072572278, job "windows 7/14"): a child exited 0 after recording its path, yet the path still existed. The test asserted that every recorded path was removed before it looked at the uninstall's status, so any first run that did not reach removal failed at that line. Besides the busy-lock refusal that #8822 already retries, two such outcomes exist:

  • A refusal for another reason, before the tombstone. On Windows, opening a file while another process renames over it can fail with EPERM, so uninstall's unlocked metadata check (src/lib/config-ownership.ts:881) can refuse a valid home as "missing or invalid" while a child is replacing the manifest under the lock. The child's registration then succeeds.
  • A partial run that stopped while removing its snapshot (src/lib/config-ownership.ts:943), which names only the entry it failed on.

Neither loses a registration. The refused run writes nothing, the partial run leaves its tombstoned manifest, and in both the recorded path stays listed, so the next run removes it. The product keeps its guarantee; the test's outcome model was incomplete. There is no src/ change.

  • settleRacingUninstall checks the guarantee for every outcome. A recorded path is either removed, or the run was refused (no tombstone, whole home reported) or partial and the manifest still lists the path. In that case the test reruns uninstall after the race, as a user would, and the rerun must remove it. A path that was never recorded must be a residual path of the run that retired the metadata. Failure messages now carry the uninstall result and the child exit codes, which the failing CI log did not have.
  • Four forced cases pin each outcome in order using the file's existing hooks: registrations before, during (step hook inside the lock hold) and after the run; a registration after a refusal by a busy lock; one after a refusal by unreadable metadata (stand-in for the Windows open failure; POSIX non-root only); and one behind a removal stopped by an unwritable directory (POSIX non-root only).
  • structure/config-ownership.md lists the new coverage.

Which of the two outcomes the Windows job hit is inferred: the failed job logged no uninstall result. If it fails again, the message will name it. A possible follow-up, outside this PR: on Windows a concurrent registration can make ocx uninstall print a transient, misleading "missing or invalid" refusal for a valid home (nothing is lost; a rerun works).

Closes #8379

Verification

  • Regression proof: with the old assertions put back into a temporary copy of the file, the three refused/partial forced cases fail with the CI symptom (expect(existsSync(path)).toBe(false), Expected: false, Received: true). The before/during/after case and both racing cases pass.
  • Non-vacuity: making the manifest write for the racing paths a no-op fails both racing cases and all three regression cases.
  • Loops of 50 runs of the file on Linux, 4 vCPU: origin/dev version 50/0 idle and 50/0 under load (nproc+2 busy loops, load average about 8); this branch 50/0 idle and 50/0 under load. The origin/dev version does not fail on Linux, consistent with a Windows-only trigger.
  • bun test tests/config/config-ownership-concurrent-record.test.ts on the rebased head: 64 pass, 0 fail.
  • bun test tests/config/config-ownership-removal.test.ts tests/config/config-ownership-uninstall.test.ts tests/config/config-ownership-concurrent-record.test.ts tests/cli/uninstall.test.ts with a private TMPDIR: 189 pass, 7 skip, 0 fail. (The agent host's default TMPDIR is group-writable, which makes 10 elevated-run cases in the untouched config-ownership-removal file fail the ancestor trust check; environmental.)
  • bun run test:changed: 1 file, 64 pass, 0 fail.
  • bun test tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/file-size-ratchet.test.ts tests/ci-workflows/structure-ssot.test.ts tests/ci-workflows/repo-hygiene.test.ts: 105 pass, 0 fail.
  • bun run typecheck, bun run structure:check, bun run privacy:scan: pass.
  • NOT RUN: real Windows (no Windows host available; the next dev batch run covers it). Full bun run test: this is a test-only change to one file whose import graph reaches only itself, so the focused runs above cover it.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Summary by CodeRabbit

  • Documentation
    • Clarified the documented outcomes when a registration overlaps an uninstall, including cases where it is removed, rejected, reported afterward, or retained for a rerun.
  • Tests
    • Expanded coverage of concurrent registrations across successful, refused, and interrupted uninstall outcomes, including reruns and reporting of paths that remain.

…utcome (#8379)

The racing-uninstall test asserted that every child that recorded its path saw that path removed,
before it checked the uninstall's status. Any first run that did not reach removal therefore failed
with "expected false, received true": a refusal for a reason other than a busy lock (on Windows, the
unlocked check can fail to open a manifest a registration is renaming over) or a partial run that
stopped in its snapshot. Neither loses a registration: the path stays listed in the untouched or
tombstoned manifest, and a rerun removes it.

settleRacingUninstall now checks exactly that, reruns such a run once the race is over, and puts the
uninstall result and child exit codes in every failure message. Four forced cases pin each outcome
in order; the refused and partial ones fail against the old assertions.

Closes #8379
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 17, 2026 12:14
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T12:16:19.792926Z 8bf488f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). label Nov 17, 2026
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The concurrent config-ownership tests now cover racing registrations across refused, partial, and completed uninstall outcomes. They check that remaining registrations stay listed for a rerun. The coverage documentation records the tested outcomes.

Changes: Concurrent uninstall race coverage

Layer / File(s) Summary
Settle racing uninstall outcomes
tests/config/config-ownership-concurrent-record.test.ts:178-219, 250-252, 279-280
A shared helper checks refused and tombstoned outcomes, reruns uninstall when needed, and verifies removed and residual paths. The existing race test delegates its final checks to this helper and includes result and child exit codes in assertion failures.
Exercise forced race outcomes
tests/config/config-ownership-concurrent-record.test.ts:361-427, structure/config-ownership.md:167-170
Tests cover registrations before, during, and after uninstall, refusal due to a busy lock or unreadable metadata, and a partial run caused by an unwritable directory. The documentation lists the covered outcomes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other · Severity of issue fixed: Low

Possibly related PRs

Merge Risk: Minimal · up to 8bf48

This updates tests and documentation so concurrent config-ownership uninstall races account for refused and partial outcomes. It does not change production behavior, so the merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the test file's scope (config uninstall racing with registration) and states the change: a racing uninstall is held to its guarantee whatever its outcome. The raw summary and objective…
Linked Issues check Passed Issue #8379 asks that the concurrent config-ownership test stop treating a refused uninstall as a failure when a registration succeeds after the refusal. At head 8bf488f, tests/config/config-ownership…
Out of Scope Changes check Passed All changes are test-only plus one documentation file, structure/config-ownership.md, which the summary describes as listing the new coverage. No src/ change is reported. The extra forced cases (befor…
Full details: Title check

Explanation

The title names the test file's scope (config uninstall racing with registration) and states the change: a racing uninstall is held to its guarantee whatever its outcome. The raw summary and objectives confirm the PR extends the concurrent config-ownership test to cover refused and partial uninstall outcomes, with a rerun when a recorded path remains. The title is specific and relevant. Minor nit: 'hold ... to its guarantee' is somewhat abstract, and the title is 83 characters, slightly above a typical concise length, but it still conveys the primary change to a reader scanning history.

Full details: Linked Issues check

Explanation

Issue #8379 asks that the concurrent config-ownership test stop treating a refused uninstall as a failure when a registration succeeds after the refusal. At head 8bf488f, tests/config/config-ownership-concurrent-record.test.ts adds settleRacingUninstall. For a refused first run, it asserts residualPaths equals [dir] and that no tombstone (uninstallStartedAt) exists. For a partial or retained-manifest run, it asserts each recorded path that still exists is still listed in the manifest, reruns removeOwnedConfigState, and requires the rerun to remove every recorded path. Unrecorded paths must be reported as residual. The racing test.each cases use this helper for the busy-lock outcome, which matches the issue's reproduction. The file's header comment and the settle helper's doc comment both reference #8379. The structure/config-ownership.md update, which the raw summary describes, was not read directly. Evidence for the remaining forced cases comes from the truncated diff of the test file (read at head, 16000-byte limit), so those cases were confirmed only from the PR description and summary. The requirement itself is met by code I read directly.

Full details: Out of Scope Changes check

Explanation

All changes are test-only plus one documentation file, structure/config-ownership.md, which the summary describes as listing the new coverage. No src/ change is reported. The extra forced cases (before/during/after registration, registration after an unreadable-metadata refusal, registration after a partial removal stopped by an unwritable directory) all test the outcome model that #8379 requires: refused or partial uninstall must not be treated as a failure when registrations remain listed for a rerun. The Windows-motivated EPERM refusal case is a refusal outcome of the same kind as the busy-lock refusal named in the issue, so it is a related extension, not unrelated work. The summary states that the file's import graph reaches only itself, so the change does not touch shared code paths. Limit: the truncated diff did not allow line-by-line review of the forced cases, so this verdict relies on the consistent structure of the visible helper and on the PR's stated scope.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0eafdf8 and 8bf488f.

Files selected for processing: 2

  • structure/config-ownership.md
  • tests/config/config-ownership-concurrent-record.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration into dev under MAINTAINERS.md (not an approving review), 2026-11-17 triage round.

  • Exact head: 8bf488fdade125c4e893537809f55a6376441c61
  • Required PR checks at that head: gates SUCCESS; test jobs SUCCESS: test changed; no failing or pending checks.
  • Fixes the flaky ownership race test (Cover refused uninstall in concurrent config ownership test #8379): no product bug; the test now holds a racing uninstall to its guarantee for every legal outcome (removed, refused, partial + rerun). Old assertions fail three forced cases with the CI symptom; a lost-write mutation fails five; 50x loops idle and loaded pass.
  • Test-only change to one file plus its structure doc; test changed ran that file on this head; Windows coverage comes from the next dev batch.
  • scripts/ci/assert-mergeable-review.sh --maintainer-integration passed for this head.

@lidge-jun
lidge-jun merged commit c7dc85a into dev Nov 17, 2026
31 checks passed
@lidge-jun
lidge-jun deleted the fix/8379-ownership-race-test branch November 17, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cover refused uninstall in concurrent config ownership test

1 participant