Repository navigation
fix(windows): resolve the relocated daemon host off the main thread at startup - #52897
Conversation
…t startup On packaged Windows, startup hook reconcile asked the Antigravity hook service for its runtime path, and the provider ran a fully synchronous getRelocatedDaemonHost(): it sha256-hashed every source and every relocated daemon-host code file with readFileSync on the main thread. The hash cache lives in memory, so every launch re-hashed both trees. With ~2,212 files and on-access AV scanning (~12 ms per cold open) this held the main thread for ~27 s before the window showed. It also ran for users without Antigravity, because the path was resolved before checking that the managed script exists. - getRelocatedDaemonHost() is now async. It reuses the existing async inventory and verification path (streamed hashes) and reads build markers with async I/O. The sync hasher, sync inventory and sync verifier had no other callers and are removed. - The startup hook refresh and the daemon launch share one lookup: materializeOnce joins (or starts) it and only copies when it finds nothing, so both trees are not hashed twice. The lookup skips hashing when no build exists. - The Antigravity runtime path provider is async. refresh skips the lookup when no managed script exists, and install resolves the path before its synchronous hooks.json read-modify-write, then re-checks the hooks setting so a disable during the await wins. The hook scripts and hooks.json output are unchanged. - daemonHostBuildRuntimeMatches computes its expected paths once rather than once per inventory file. - Prunes the sync-fs and main-blocking baselines for the removed calls. Daemon launch still verifies every copied file against its marker before use. Thanks to wurenrumian, whose CPU profile found the cause. Refs #52542
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
ELI5
On Windows, Orca checked a copy of its background helper before it showed the window. That check read about 2,212 files one at a time on the thread that also draws the window. With antivirus scanning each file, the window took about 27 s to appear. The check now runs in the background, so the window shows first.
What Changed
getRelocatedDaemonHost()(daemon-host-relocation.ts) is now async. It uses the existing async inventory and verification path, which streams the hashes at concurrency 2. Build markers and the build directory are read with async I/O. A hook-refresh lookup and the daemon launch share one verification pass, so each tree is hashed once per launch. The sync hasher, sync inventory and sync verifier had no other callers and are removed.daemonHostBuildRuntimeMatchescomputes its expected paths once, not once per inventory file. That was a ~19 ms synchronous block at 2,200 files.antigravity/hook-service.ts): the Windows runtime-path provider now returns a Promise.refreshManagedScriptsreturns early when no Antigravity managed script is installed, so users without Antigravity never trigger the lookup.install()resolves the path before its synchronous hooks.json read-modify-write, and re-checks the hooks setting after that await so a disable made during install still wins.main-process-preflight.ts: the provider isasync () => (await getRelocatedDaemonHost())?.execPath ?? process.execPath.Why
Root cause, from the reporter's CPU profile: on packaged Windows, the startup hook reconcile asked the Antigravity hook service for its runtime path. The provider,
getRelocatedDaemonHost, was fully synchronous. It sha256-hashed about 2,212 daemon-host files withreadFileSyncon the main thread: every source code file, then every relocated copy. The hash cache lives only in memory, so every launch re-hashed both trees. At ~12 ms per cold, antivirus-scanned open, this blocked the main thread for 27.3 s of the 28.7 s gap before window-shown. It ran for every Windows user with agent hooks on, because the path was resolved before checking whether an Antigravity script existed.The daemon launch already verified the relocated host with the async path. The sync twins existed only for this provider. Removing them fixes the block where it starts, and integrity is unchanged: the launch still stream-hashes every copied file against its marker before use.
What this does not change: the async verification still runs in the background at concurrency 2. On a cold antivirus boot, daemon and terminal readiness can still lag. The total time is the same as on main. Only the window no longer waits for it.
Follow-up: persist the verification (the marker fingerprint plus a directory signature), so a launch doesn't re-hash every file each time.
Thanks to wurenrumian, whose CPU profile found the cause.
Linked Issue
Refs #52542
Reported by wurenrumian in #52542.
The issue stays open until the reporter confirms the fix with an A/B cold boot.
Visual Proof
N/A. This changes main-process startup work. There is no UI change, only when the window appears.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
daemon-host-relocation.test.ts:readFileSynccalls under the fixture. It fails on main.hook-service-runtime-path.test.ts:vitest on
src/main/daemon/executable-host/,src/main/agent-hooks/installation/andsrc/main/antigravity/: 168 pass, 2 skipped. 3 tests fail inantigravity-agy-orca-homeandantigravity-chat-naming-home. They fail the same way on main.Windows (awin, NTFS + Defender), on the first commit: the executable-host, agent-hooks/installation and antigravity suites pass (148 pass, 17 skipped), except the same pre-existing failures.
The main-blocking ratchets, oxlint, oxfmt, the anti-slop and native code-quality oxlint configs, ast-grep and the changed-code quality gate are all clean.
Performance
This removes main-thread blocking from startup. For each
getRelocatedDaemonHost()call, with a fresh process and an empty hash cache:The hashing work is unchanged in total. It runs on libuv threads (2 of the 4 slots) instead of the main thread, and the hook lookup and the launch now share one pass instead of hashing twice. Users without Antigravity skip the hook-side lookup and pay one async stat instead. The launch-time verification still runs, as on main. There is no new polling, subprocess or IPC. Not a renderer or store change.
Risk
Level: Medium
isPackagedElectronWin32gate).process.execPathinstead of the relocated host, or be skipped during one startup reconcile. The hook bytes and hooks.json shape are unchanged, andMANAGED_AGENT_HOOK_INSTALLERSalready awaits installers.Review
Claude + Codex + Antigravity reviews. The only blocking item, stale ratchet baselines, is fixed:
run-main-blocking-ratchetspasses.Agent skill upstream boundary
Notes
Security: no new endpoints, IPC or permissions; the launch still verifies every relocated file against its marker. Cross-platform: the changed path runs only on packaged Windows; macOS and Linux are unaffected. Remote SSH and mobile: not touched. Backwards compatibility: no saved data, settings or protocol changes.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)