Skip to content

fix(desktop): pre-check Windows install locations and guide drive-root ACL recovery - #666

Open
oldwinter53 wants to merge 1 commit into
mainfrom
oldwinter53/whi-896-win-datadrive
Open

oldwinter53 wants to merge 1 commit into
mainfrom
oldwinter53/whi-896-win-datadrive

Conversation

@oldwinter53

@oldwinter53 oldwinter53 commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

Secondary Windows NTFS data drives formatted with the stock Everyone:(OI)(CI)(F) ACL grant DeleteSubdirectoriesAndFiles, ChangePermissions, and TakeOwnership on the volume root. Private-path validation intentionally keeps refusing that root ACL with WINDOWS_PRIVATE_PATH_UNSAFE (UNSAFE_PARENT_ACCESS), so another local account cannot replace the private Linger home folder or rewrite the drive root's ACL.

main already runs windowsPrivateLocation during Windows install preflight and in chooseLocation (keeping the previous valid location, recording error and rejectedPath, and pre-checking disk space in the redesigned install-location bar). On top of that, this PR adds structured refusal metadata, drive-root subfolder targeting, and localized recovery guidance:

  • Structured picker refusal (apps/desktop/src/main/local-server.ts, shared/setup.ts): extract #checkLocation in LocalServerModule so chooseLocation records structured location.refusal (WindowsPrivateRefusal) alongside error and rejectedPath when windowsPrivateLocation refuses a candidate folder, preserving the previous valid location and its freeBytes/minFreeBytes metadata and clearing location.refusal on valid selection, reset, or #ready.
  • Drive roots: installLocation always targets a Linger subfolder when a drive or filesystem root (such as an empty F:\) is picked, unless the root already holds instances or installer.
  • Recovery guidance (apps/desktop/src/shell/setup.html, setup.messages.ts, i18n/locales/zh-CN.json):
    • On the failed screen, UNSAFE_PARENT_ACCESS on a folder directly on a drive (E:\Linger, F:\) now shows recovery guidance too: use the default location, pick another drive, or remove other accounts' Full Control in <drive> Properties → Security.
    • In the welcome screen's install-location bar (#location-sub), locationErrorText surfaces matching recovery guidance for UNSAFE_PARENT_ACCESS refusals of both drive-root and nested folders while falling back to the raw location.error for other errors and preserving disk-space warning precedence and Reset behavior.
    • English and Simplified Chinese catalogs stay in parity.
  • Native Windows tests (packages/local-installation/src/windows-private.native.test.ts): cover windowsPrivateLocation for refused, existing, and missing candidates and verify that candidates are not created or mutated.

Verification

  • pnpm --filter @linger/desktop typecheck && pnpm --filter @linger/desktop lint
  • pnpm --filter @linger/desktop exec vitest run src/main/local-server.test.ts src/main/setup-window.test.ts src/shell/setup-page.test.ts src/i18n/catalog.test.ts (4/4 test files, 290/290 tests)
  • pnpm --filter @linger/local-installation typecheck && pnpm --filter @linger/local-installation lint && pnpm --filter @linger/local-installation exec vitest run src/windows-private.test.ts (10/10; native Windows tests skip on Linux)
  • pnpm exec commitlint --from origin/main --to HEAD --verbose, pnpm env:inventory:check, bash scripts/ci/check-changed-files.sh origin/main HEAD scripts/ci/app-linted-paths.txt, make check-docs
  • All GitHub CI checks green (check (desktop), check (packages), check (installer), check (web), repository-gate, changes, CodeQL)

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

Approve with nits (1 P2, 2 P3)

Scope: base main, merge base 00b9065d, 1 commit, 13 files reviewed at 3eff2715. Loaded coderbook, ponytail-review, karpathy-guidelines. Ran in a separate session.

Findings

P2

  • windowsPrivateLocation is a copy of windowsPrivatePath — packages/local-installation/src/windows-private.ts:446
    Lines 446–466 repeat lines 420–438 line for line: same run ? run(powershellPath(), …) : defaultWorker.execute(payload) dispatch, same timeout, same privatePathError throw. The only difference is kind: "location" with repair: false. Now there are two copies of the request/transport code, and any later change (timeout, worker routing, error shape) has to be made in both. Fix: widen windowsPrivatePath's kind to "file" | "directory" | "location" and make windowsPrivateLocation(dir, run) call windowsPrivatePath(dir, "location", false, run). You could also drop the wrapper and call it directly from local-server.ts.

P3

  • installLocation has win32 handling that only the Linux test needs — apps/desktop/src/main/local-server.ts:4437-4441
    On Windows, path.dirname("F:\\") === "F:\\" already detects a drive root, and path.join already is path.win32.join. So the /^[A-Za-z]:[\\/]$/ root regex and the path.win32.join switch only matter when the new installLocation("F:\\") assertion runs on Linux/macOS CI. Production code gains a branch that never runs in production. Fix: keep path.dirname(picked) === picked and path.join, and drop the drive-letter assertion or make it Windows-only.

  • The drive-root guidance always says to remove Everyone's Full Control — apps/desktop/src/shell/setup.messages.ts:75 (and locationPickDriveRootHint, plus the zh-CN entries)
    At a volume root, the ACL program refuses any untrusted Allow ACE that grants DeleteSubdirectoriesAndFiles, ChangePermissions or TakeOwnership (windows-private.ts:99-105). That can be Users:(F) or a custom group, not only Everyone. In that case "remove Full Control for Everyone in F:\ Properties → Security" doesn't work, and the user is left with a refusal they can't clear. Fix: refer to "other accounts' Full Control" in the remedy sentence, as the first sentence already does with "such as Everyone".

Verified as fine

  • Pre-check is read-only: the location branch of WINDOWS_PRIVATE_CHECK_BODY only uses Test-Path/Get-Item/Get-Acl. The repair and DACL checks are wrapped in if ($request.kind -ne 'location') (windows-private.ts:110-146), and the ancestor rules (root vs. below-root Delete, windows-private.ts:99-100) are shared unchanged. Volume-root security is not weakened, and the new FULL_CONTROL & mask(EVERYWHERE) test pins this.
  • Missing target: the probe walks up to the nearest existing ancestor. Through the picker, the candidate is either the picked folder or picked\Linger, so at most one level is missing and the nearest ancestor is the picked folder itself. An existing drive root as the target throws UNSAFE_TYPE (!$item.Parent), but installLocation never returns a bare root without an existing installation.
  • chooseLocation on refusal keeps the previous location, sets refusal/rejectedPath, and does not recheck because previous === #location (local-server.ts:820-836). Reset clears all four fields. A later disk-space error clears the stale refusal because problem?.refusal is undefined.
  • #install refusal propagation: the thrown error carries refusal, and the failure path reads (error as {refusal}).refusal through windowsPrivateRefusal (local-server.ts:1464), so the failed screen gets the code and reason. Covered by "fails fast with refusal…".
  • Non-Windows platforms skip the ACL check (#checkLocation platform guard). The default worker unrefs and idles out (windows-private.ts:295-301), so Desktop gains no lingering child process.
  • UI hints are keyed on refusal.code/refusal.reason, not on message text. Other reasons fall back to the raw error (tested). setup-window.ts passes rejectedPath through shown() like path.
  • English/zh-CN catalog parity holds. CJK appears only in apps/desktop/src/i18n/locales/zh-CN.json (allowed), and the commit message is English. apps/desktop/AGENTS.md is updated.
  • Unverified: the native Windows tests (windows-private.native.test.ts) are skipIf(!win32), and no Windows CI job ran (computer-go-windows skipped), so the PowerShell location branch has only been checked by reading it and by string-contains tests.

Process notes

  • The branch is behind main (00b9065d vs 8b7fe39b) and main requires up-to-date branches: rebase before merging.
  • One commit, no merge or fixup commits.

CI

All checks that ran passed: check (desktop), check (packages), check (installer), check (web), repository-gate, CodeQL. Go/contracts/web-test jobs were skipped as not affected. I ran no tests locally.

Automated review by Claude Code


Automated review of 3eff271 by Claude Code.

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

Approve with nits (1 P3)

Scope: follow-up on 3eff271. Base main, merge base eafcfd41. Reviewed 1 commit (de7da430) and 10 files. The branch was force-pushed and rebased onto a main that now ships windowsPrivateLocation and the Windows install preflight, so I compared the old and new versions of the commit with git range-diff and re-reviewed the full merge-base diff. Loaded coderbook (sections 2, 3, 5), ponytail-review (sections 1–3) and karpathy-guidelines (sections 2–3). Ran in a separate session.

Previous findings

  • P2 windowsPrivateLocation duplicated windowsPrivatePath: Resolved. The PR no longer touches packages/local-installation/src/windows-private.ts. It now uses the windowsPrivateLocation that main ships (packages/local-installation/src/windows-private.ts:755).
  • P3 installLocation had test-only branches: Resolved. apps/desktop/src/main/local-server.ts:4508 detects a root only with path.dirname(picked) === picked and uses plain path.join. The F:\ assertion now runs only on win32 (local-server.test.ts:3466).
  • P3 drive-root guidance always told users to remove Everyone: Resolved. Both the English text (setup.messages.ts) and the zh-CN text now say to remove Full Control for other accounts. Everyone stays only as an example.

Findings

P3

  • apps/desktop/src/main/local-server.test.ts:3542: the test "fails fast with refusal when a chosen Windows folder becomes unsafe before install" tests behavior that already exists on main. The install preflight (local-server.ts:1303-1327) and its refusal tagging are already covered by main's "preserves the Windows private-path refusal when home preflight fails" (local-server.test.ts:3174). The only difference is that the new test uses a custom location. Its name also suggests this PR adds the behavior, but the PR only adds the picker check. Fix: drop the new test, or add one custom-location assertion to the existing test.

Verified as fine

  • Picker check: on Windows, chooseLocation → #checkLocation (local-server.ts:846-869) first runs the existing free-space and folder check, then windowsPrivateLocation. When the check refuses the folder, #location stays at the previous valid folder (local-server.ts:839), and refusal and rejectedPath are recorded. The recheck is skipped because previous === this.#location. Choosing null clears all of it (local-server.ts:828-833). The test at local-server.test.ts:3470 covers refuse → valid → refuse-keeps-previous → reset.
  • The check does not change the picked folder: on main, the location kind of the ACL program checks the folder if it exists, or else the nearest existing parent and every folder above it. It never runs the repair or create code. The native test (windows-private.native.test.ts:347-362) checks that a missing folder is not created and that an existing folder's inherited DACL is left alone. That test only runs on Windows, and CI has no Windows job for packages.
  • Drive roots: if F:\ is empty or can't be read, readdir falls back to []. Before, Linger would then install straight into the root. Now installLocation returns F:\Linger, while a root that already holds instances or installer is still used as is (local-server.ts:4505-4510). On POSIX, / was never empty, so nothing changes there.
  • Install preflight still runs after a pick, because main's #install calls checkPrivate(home) before unpacking (local-server.ts:1303-1307). The PR description says this correctly.
  • Page guidance: windowsDriveLocation (setup.html) tells D:\a\b (nested) apart from F:\Linger, F:\Linger\ and F:\ (directly on the drive). Both locationHint and locationErrorText show guidance only when the refusal is WINDOWS_PRIVATE_PATH_UNSAFE/UNSAFE_PARENT_ACCESS, and otherwise fall back to the raw error. Shortened paths that shown() produces don't match the drive patterns, so they safely fall back as well. The decision is driven by structured codes, not by message text.
  • Reset: Customize reset now also fires when only refusal is set (setup.html:4906). Since a refusal always comes with error, this changes nothing but is harmless.
  • i18n: the English and zh-CN catalogs gain the same three keys. Chinese text appears only in apps/desktop/src/i18n/locales/zh-CN.json, which the repo allows. There is no Chinese in code, comments or the commit message.
  • Docs: apps/desktop/AGENTS.md is updated to describe the picker check, the drive-root rule and the guidance.
  • Unverified: I could not run the Windows-only native tests (windows-private.native.test.ts) here. CI skips them too.

Process notes

  • The branch is 2 commits behind main (963f4b52), and main requires up-to-date branches, so it needs a rebase before merge.
  • There is one commit and no merge or fixup commits. The commit author is Dongdong Chen <cdd@simplexai.com>.

CI

These checks pass: check (desktop), check (packages), check (installer), check (web), repository-gate, changes, CodeQL. The other jobs were skipped by path filters. No job runs the Windows-native local-installation tests. I ran no tests myself.

Automated review by Claude Code


Automated review of de7da43 by Claude Code.

…t ACL recovery

Secondary Windows NTFS data drives formatted with the stock Everyone:(OI)(CI)(F) ACL grant DeleteSubdirectoriesAndFiles, ChangePermissions, and TakeOwnership on the volume root. Private-path validation intentionally keeps rejecting that root ACL with UNSAFE_PARENT_ACCESS so other local accounts cannot replace the Linger home folder, but selecting such a drive passed location picking without structured refusal details and showed no recovery guidance for drive-root paths because locationHint only matched nested paths.

- Record structured WindowsPrivateRefusal alongside error and rejectedPath in chooseLocation when windowsPrivateLocation refuses a candidate folder, keeping the previous valid location and disk-space metadata intact; install preflight still checks the home again before unpacking.
- Always target a Linger subfolder when a drive or filesystem root is picked unless it already holds an installation.
- Show localized recovery guidance in setup.html (English and Simplified Chinese) in the install-location bar and on the failed step when UNSAFE_PARENT_ACCESS refuses a folder directly on a drive or a nested drive path.
- Cover windowsPrivateLocation on native Windows for refused, existing, and missing candidates without mutating them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oldwinter53
oldwinter53 force-pushed the oldwinter53/whi-896-win-datadrive branch from de7da43 to 97e7568 Compare November 26, 2026 19:09

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

Approve with nits (1 P3)

Scope: follow-up on de7da43. The PR was rebased since then, so I compared the two versions with git range-diff and also reviewed the full diff against merge base 6a511c15 (main, up to date). That covers 1 commit and 9 files. Loaded coderbook, ponytail-review and karpathy-guidelines. Ran in a separate session.

Previous findings

  • Resolved: the duplicated install-preflight test was removed in the rebase. The "fails fast with refusal when a chosen Windows folder becomes unsafe before install" case is gone, and only the chooseLocation pre-check test remains (apps/desktop/src/main/local-server.test.ts:4174).

Findings

P3

  • apps/desktop/src/main/local-server.ts:1124: the PR body overstates what this PR adds. It says the PR "now only adds the picker-time check" and that chooseLocation "records location.refusal and location.rejectedPath". The removed lines show main already ran windowsPrivateLocation in chooseLocation, kept the previous location on refusal and recorded rejectedPath. The new part is the structured refusal (via #checkLocation), the drive-root installLocation rule, and the guidance text. The commit message describes this correctly. Please align the PR body with it so reviewers don't look for a picker check that main already had.

Verified as fine

  • Refusal state lifecycle: #locationRefusal is written alongside #locationError and #locationRejectedPath only after the stale-choice guard (local-server.ts:1140-1149). It is cleared by chooseLocation(null) and by a successful pick, and with rejectedPath in #ready (local-server.ts:3939). The test covers refuse → valid → refuse-keeps-previous → reset, including the free-space metadata (local-server.test.ts:4206-4253).
  • The refusal sent to the page holds only {code, reason} (windowsPrivateRefusal, asserted with toEqual at local-server.test.ts:4217). The shown rejectedPath goes through shown() (setup-window.ts:640).
  • installLocation (local-server.ts:5953-5960): an existing installation (instances/installer) still wins. Empty non-root folders still install in place. A root (path.dirname(p) === p, true for F:\ and /) always gets Linger. Only roots whose only entries are dot entries change behaviour, and the docs say so.
  • Setup page: locationErrorText falls back to location.error (setup.html:3145), so the spaceLow, shownLocationPath and reset-button logic behave as before for non-refusal errors. Drive-root and nested regexes are covered for pick-time and failed-step hints in setup-page.test.ts. The EN and zh-CN catalogs have the same keys. CJK appears only in apps/desktop/src/i18n/locales/zh-CN.json.
  • apps/desktop/AGENTS.md documents the picker pre-check, the drive-root rule and where the guidance shows.

Process notes

  • Single commit, no merge or fixup commits; the branch is up to date with main.

CI
All checks that ran passed: desktop, packages, installer, web (quick pass), repository-gate, CodeQL. The rest were skipped as not affected. The native Windows windows-private.native.test.ts cases skip off Windows, so CI on Linux does not run them. I ran no tests myself.

Automated review by Claude Code


Automated review of 97e7568 by Claude Code.

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

Approve with nits (1 P2)

Follow-up on 97e7568; the head is unchanged, so this re-checks the whole PR against merge base 6a511c15 on main (1 commit, 9 files). Helper skills loaded: coderbook, ponytail-review, karpathy-guidelines. Ran in a separate session.

Previous findings

  • Resolved: PR description counted main's existing pick-time pre-check as new (apps/desktop/src/main/local-server.ts:1124). The PR body now says main already runs windowsPrivateLocation in chooseLocation and that this PR adds only the structured refusal, drive-root targeting, and guidance.

Findings

P2

  • apps/desktop/src/shell/setup.html:3136 (locationErrorText, nested branch) and :3125 (locationHint): the nested-path guidance sends users on a stock data drive to a location that will also be refused.
    Scenario: D:\ has the stock Everyone:(OI)(CI)(F) ACL that this PR targets. The user picks D:\Games, and installLocation turns it into D:\Games\Linger. The ancestor loop in packages/local-installation/src/windows-private.ts:231-262 refuses D:\Games, which inherits the Everyone Full Control grant, with UNSAFE_PARENT_ACCESS. windowsDriveLocation classifies the path as nested, so the bar says "Choose D:\ itself (Linger installs into D:\Linger)". The user does that, and the same loop refuses D:\Linger on the root's own ACL, so only then does the user see the drive-root hint (properties → Security, or another drive). The shape of the path alone cannot tell "a nested folder's ACL is the problem" apart from "the drive root's ACL is the problem", because WindowsPrivateRefusal carries only code/reason.
    Fix: the simplest option is to word locationPickNestedHint (and locationHint) so it also covers the drive-permission case, for example by adding the "or remove Full Control for other accounts in {drive} Properties → Security" clause. A more precise option is to pre-check the drive's Linger candidate before suggesting it, which costs one more ACL probe.

Verified as fine

  • #checkLocation (apps/desktop/src/main/local-server.ts:1162-1185) keeps the earlier order: disk-space/checkLocation first, then the Windows private check, which runs only on win32. windowsPrivateRefusal (packages/local-installation/src/windows-private.ts:803-815) returns undefined for non-refusal errors, so refusal is omitted and the UI falls back to the raw error.
  • State transitions: on refusal, #location and #locationFreeBytes are not touched because updateFreeBytes stays false (local-server.ts:1137-1151). A valid pick or Reset clears #locationRefusal (:1148), and #ready clears it too (:3939). A stale pick is dropped through #locationChoiceSeq before any field is written.
  • installLocation (local-server.ts:5953-5960): an existing installation (instances/installer) still wins. Only a filesystem root (path.dirname(p) === p) that would otherwise be "empty" now goes to <root>\Linger. Non-root behaviour is unchanged, and local-server.test.ts:4159-4172 covers it.
  • The windowsDriveLocation regexes (setup.html:3104-3110) classify F:\, F:\Linger, and F:\Linger\ as drive-level and D:\a\b as nested. Non-drive paths (UNC) return undefined and fall back to the raw error.
  • The warning precedence in the welcome bar is the same as before: the location error comes before low-space, and Reset stays visible when there is an error (setup.html:4405-4477).
  • English and zh-CN catalogs are in parity for the 3 new keys. There is no CJK outside apps/desktop/src/i18n/locales/ and none in the commit message. apps/desktop/AGENTS.md is updated for the new behaviour.
  • WindowsPrivateRefusal is imported from @linger/local-installation (a package), not across apps/*.

Process notes

  • Single commit, no merge or fixup commits.

CI

All relevant checks pass: check (desktop), check (packages), check (installer), check (web), repository-gate, changes, CodeQL. Checks for other apps were skipped by path filters. The native Windows tests in windows-private.native.test.ts skip on Linux CI, so they are unverified here. I ran no tests myself.

Automated review by Claude Code


Automated review of 97e7568 by Claude Code.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants