fix(cli): create connection state root privately before locking
Closed
MI
3d ago+1595+1595+0123456789012345678901234567890123456789-89-89-01234567890123456789
Summary
Fixes #5137.
Invariant: Connection admission repairs owned group/other-writable state roots (0o775/0o777 -> 0o700), preserves owned non-writable roots (0o750/0o755) on connect/disconnect, creates missing roots/subdirectories privately via physical-parent walks and O_DIRECTORY | O_NOFOLLOW descriptor fchmodSync, waits on 0o500 init under umask 0200, keeps admitted (dev, ino) handles open across locks/writes, and keeps update-check active without creating stateDir.
Before / after
# Prior head (2f6490bec):
# - refused owned 0o775 roots on CLI/connect; mutated 0o750/0o755; skipped update-check without stateDir
# - locked/wrote via pathname re-resolution; alias /tmp under umask 0700 left 0o000; broke linked config dirs
# Current head:
# - removed refuseWritableRoot; preserveNonWritableRoot only skips tightening owned 0o750/0o755 on connect/disconnect
# - physical parent verified before mkdir; fchmod via descriptor; 0o500 wait returns retriable PrivateDirectoryInitializingError
# - VerifiedDirectoryHandle stays open across process-lock & cloud record/attachment writes
# - update-check uses XDG/HOME cache when stateDir is absent; generated-config & remote-connection-state set allowOwnedSymlinks
Validation
Validated on Windows 11 (Node v22.14.0):
oxfmt --check(19 files),pnpm typecheck,scripts/layering/check.ts(2080files),oxlint . --deny-warnings(5614files),tsdown --config-loader native(553files): passed.- Vitest (
--project unit-core): non-POSIX cases passed infile.test.ts,daemon-resolution-state-root.test.ts,remote-connection-state.test.ts,cloud-connection-record.test.ts,command-connection.test.ts(at--testTimeout=60000), and-tfilteredcli-state-root-admission.test.ts/update-check.test.ts. POSIXumask002/0200/0700, symlink, andcli-cloud-session.test.tssuites require Linux/macOS CI approval.