Skip to content

fix(windows): resolve the relocated daemon host off the main thread at startup - #52897

Merged
nwparker merged 1 commit into
mainfrom
bugbash/issue-52542
Nov 30, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/issue-52542

Conversation

@nwparker

@nwparker nwparker commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​120 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​109
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​88 $\color{#cf222e}{\Huge{\mathbf{−}}}$​164 $\color{#cf222e}{\Huge{\mathbf{−}}}$​76

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.
  • daemonHostBuildRuntimeMatches computes its expected paths once, not once per inventory file. That was a ~19 ms synchronous block at 2,200 files.
  • Antigravity hook service (antigravity/hook-service.ts): the Windows runtime-path provider now returns a Promise. refreshManagedScripts returns 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.
  • Antigravity hook output is unchanged: the same script bytes, wrapper scripts, hooks.json entries and commands. Only two things changed: how the runtime exec path is obtained, and the early return when no Antigravity script is installed.
  • main-process-preflight.ts: the provider is async () => (await getRelocatedDaemonHost())?.execPath ?? process.execPath.
  • The main-blocking ratchet baselines drop the sync daemon-host entries that this change removes.

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 with readFileSync on 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:

    • "finds a published host on a fresh start without synchronous reads" resets modules, which empties the hash cache. It expects the same host with 0 readFileSync calls under the fixture. It fails on main.
    • "hashes each file once when the hook lookup and the launch start together" covers the shared verification pass.
  • hook-service-runtime-path.test.ts:

    • The runtime path is not resolved when no managed script is installed.
    • An installed script gets the resolved path.
    • hooks.json is not written when hooks are disabled while the path resolves.
  • vitest on src/main/daemon/executable-host/, src/main/agent-hooks/installation/ and src/main/antigravity/: 168 pass, 2 skipped. 3 tests fail in antigravity-agy-orca-home and antigravity-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:

host files main: sync reads / main blocked branch: sync reads / max loop gap
macOS (warm SSD) 2,200 4,422 / 194-199 ms 0 / 1.9-2.7 ms
macOS 6,000 12,022 / 540-570 ms 0 / 4.5-4.9 ms
awin Windows (NTFS + Defender, warm) 2,200 4,422 / 1,395-1,581 ms 0 / 3.6-7.3 ms
awin 6,000 12,022 / 4,087 ms 0 / 9.4 ms

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

  • Windows packaged startup only (the isPackagedElectronWin32 gate).
  • The riskiest part is the Antigravity install becoming async. If it went wrong, Antigravity hooks on Windows could point at process.execPath instead of the relocated host, or be skipped during one startup reconcile. The hook bytes and hooks.json shape are unchanged, and MANAGED_AGENT_HOOK_INSTALLERS already awaits installers.
  • Daemon and terminal readiness on a cold antivirus boot still lag, as on main (see Why).
  • Back out with a plain revert. There are no saved-data or settings changes.

Review

Claude + Codex + Antigravity reviews. The only blocking item, stale ratchet baselines, is fixed: run-main-blocking-ratchets passes.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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
@coderabbitai

coderabbitai Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Windows daemon-host inventory and relocation now use asynchronous filesystem operations, with startup awaiting relocation lookup. Managed Antigravity hook installation now supports asynchronous Windows runtime-path resolution and checks a continuation callback before writing configuration.

Merge Risk: Minimal · up to 40634

On packaged Windows startup, daemon-host lookup and hashing no longer block the main thread, so the window can appear sooner. Hook scripts and hooks.json output are unchanged. A hook disable during the runtime-path await takes precedence over the install. No concrete defect or regression remains in the supplied evidence.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: moving the relocated daemon-host lookup off the main thread during Windows startup. It uses the conventional fix(scope) prefix and is specific. The changeset matches i…
Description check Passed The description follows the repository template closely. It includes ELI5, What Changed, Why, Linked Issue (Refs #52542, not 'Fixes #'), Visual Proof marked N/A with a reason, Testing with checkboxes …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: moving the relocated daemon-host lookup off the main thread during Windows startup. It uses the conventional fix(scope) prefix and is specific. The changeset matches it: getRelocatedDaemonHost becomes async, the sync hasher and inventory are removed, and the Antigravity runtime-path provider is awaited. The title is 78 characters, which is within a normal length for a commit subject.

Full details: Description check

Explanation

The description follows the repository template closely. It includes ELI5, What Changed, Why, Linked Issue (Refs #52542, not 'Fixes #'), Visual Proof marked N/A with a reason, Testing with checkboxes and concrete test names, Performance with a measured table, Risk with level and back-out plan, AI Disclosure, Review, the upstream boundary checkbox, Notes, and the Checklist. The linked issue is referenced with 'Refs' rather than a closing 'Fixes' line. The template states that 'Refs' is not sufficient for outside contributors, and the author does not state whether they are an outside contributor. The AI Disclosure section is left as the template comment, with no content. The description is thorough and mostly complete.

Resolution

Optional: confirm whether the author is an outside contributor. If so, link an actual issue with 'Fixes #' rather than 'Refs #'. Optional: fill in the AI Disclosure section, or leave it blank if the author is a StablyAI team member.

  • 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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 935df60d-9a33-400c-b355-9e83a5c867bb
Commits

Reviewing files that changed from the base of the PR and between 530c232 and 40634b3.

Files selected for processing: 12

  • config/main-blocking-helper-baseline.txt
  • config/main-sync-fs-baseline.txt
  • src/main/agent-hooks/installation/managed-agent-hook-controls.ts
  • src/main/agent-hooks/installation/managed-agent-hook-registry.ts
  • src/main/antigravity/hook-service-runtime-path.test.ts
  • src/main/antigravity/hook-service.ts
  • src/main/daemon/executable-host/windows/daemon-host-build-inventory.ts
  • src/main/daemon/executable-host/windows/daemon-host-file-hash-cache.ts
  • src/main/daemon/executable-host/windows/daemon-host-inventory-roots.ts
  • src/main/daemon/executable-host/windows/daemon-host-relocation.ts
  • src/main/daemon/executable-host/windows/testing/daemon-host-relocation.test.ts
  • src/main/startup/main-process-preflight.ts

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

@nwparker
nwparker merged commit 9c9084b into main Nov 30, 2026
59 checks passed
@nwparker
nwparker deleted the bugbash/issue-52542 branch November 30, 2026 04:07
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.

1 participant