Skip to content

fix(pip): lazy-load NativeKit - #2056

Merged
zerob13 merged 2 commits into
devfrom
codex/fix-native-pip-lazy-load
Jul 29, 2026
Merged

fix(pip): lazy-load NativeKit#2056
zerob13 merged 2 commits into
devfrom
codex/fix-native-pip-lazy-load

Conversation

@zerob13

@zerob13 zerob13 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • remove NativeKit initialization from the application startup workload
  • load NativeKit only for the first Browser capture or concrete Computer Use target
  • disable native PiP process-wide after loading or startup fails
  • open the existing side Browser automatically when Browser PiP is unavailable
  • keep Computer Use running without PiP when native preview is unavailable
  • upgrade @zerob13/nativekit from 0.6.2 to 0.6.3
  • retain the provider and ACP registry refresh produced by the normal build

Root cause

The package import was dynamic, but the startup workload immediately called the preview initializer, so NativeKit was effectively loaded eagerly. A missing native dependency could therefore affect application startup, and the failure path selected the renderer Canvas fallback for both Browser and Computer Use.

User impact

BEFORE  NativeKit load failed
├─ Browser      -> Canvas PiP
└─ Computer Use -> Canvas PiP

AFTER   NativeKit load failed
├─ Browser      -> existing side Browser opens
└─ Computer Use -> no PiP; tools continue normally

NativeKit 0.6.3 also statically links the Windows x64 MSVC runtime, reducing deployment-time dynamic runtime failures.

Verification

  • pnpm run format
  • pnpm run i18n
  • pnpm run lint
  • pnpm run typecheck
  • pnpm run build
  • focused main tests: 73 passed
  • focused renderer tests: 20 passed
  • built main output retains await import('@zerob13/nativekit')

Physical Windows packaged smoke testing remains release QA.

Summary by CodeRabbit

  • New Features

    • Native picture-in-picture now uses NativeKit 0.6.3 when supported.
    • If native PiP isn’t available, Browser automatically opens the existing side panel, and Computer Use shows no PiP.
  • Bug Fixes

    • Native PiP loading is deferred until a preview is actually requested.
    • Tightened “native unavailable” behavior and removed the prior canvas-based fallback path.
  • Chores

    • Updated PiP migration documentation and pinned NativeKit to 0.6.3.
    • Refreshed agent/model catalog entries.
  • Tests

    • Added/updated tests to cover native-available vs native-unavailable flows.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR updates NativeKit to 0.6.3, defers initialization until concrete preview requests, routes unavailable Browser previews to the side panel, disables Computer Use PiP when unavailable, updates related tests and documentation, and refreshes ACP and model catalog metadata.

Changes

Native PiP routing

Layer / File(s) Summary
PiP contracts and rollout behavior
docs/architecture/nativekit-agent-browser-pip/*, docs/features/*, package.json
Documents NativeKit 0.6.3, on-demand loading, native-overlay/none selection, Browser side-panel fallback, and no Computer Use PiP on unavailable runtimes.
On-demand presenter integration
src/main/app/composition.ts, src/main/desktop/{browser,computerUse,preview}/*, src/shared/types/desktop.ts
Removes startup initialization, initializes NativeKit during concrete preview requests, and handles unavailable surfaces per source.
PiP routing validation
test/main/{app,build,desktop}/**
Tests deferred initialization, unavailable Browser activation, Computer Use no-surface behavior, and coordinator disablement.

Provider catalog updates

Layer / File(s) Summary
ACP distribution metadata
resources/acp-registry/registry.json
Updates selected agent versions, package versions, binary archives, and checksums.
Provider and model catalog
resources/model-db/providers.json
Adds and removes models and providers, updates capabilities and pricing, and adds batch model entries.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BrowserCapture
  participant YoBrowserPresenter
  participant AgentPreviewCoordinator
  participant BrowserSidePanel
  BrowserCapture->>YoBrowserPresenter: request capture preview
  YoBrowserPresenter->>AgentPreviewCoordinator: initialize and prepare target
  AgentPreviewCoordinator-->>YoBrowserPresenter: native-overlay or none
  YoBrowserPresenter->>AgentPreviewCoordinator: present frame
  YoBrowserPresenter->>BrowserSidePanel: activate when surface is none
Loading
sequenceDiagram
  participant CUA
  participant ComputerUsePreviewPresenter
  participant AgentPreviewCoordinator
  participant NativeKit
  CUA->>ComputerUsePreviewPresenter: concrete preview target
  ComputerUsePreviewPresenter->>AgentPreviewCoordinator: initialize
  AgentPreviewCoordinator->>NativeKit: start overlay
  NativeKit-->>AgentPreviewCoordinator: capability result
  AgentPreviewCoordinator-->>ComputerUsePreviewPresenter: native surface or none
  ComputerUsePreviewPresenter->>NativeKit: present current frame
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: NativeKit is now lazy-loaded for PiP handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-native-pip-lazy-load

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

Comment @coderabbitai help to get the list of available commands.

@zerob13
zerob13 marked this pull request as ready for review July 29, 2026 05:04
@dosubot

dosubot Bot commented Jul 29, 2026

Copy link
Copy Markdown

📄 Knowledge review

Dosu skipped reviewing this PR because your organization has used its 200 included credits for the month. Your usage will reset on 2026-08-01. To have Dosu review this PR before then, ask your organization admin to upgrade to a pro account.


Leave Feedback Ask Dosu about deepchat Add Dosu to your team

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (1)
test/main/desktop/computerUse/ComputerUsePreviewPresenter.test.ts (1)

26-28: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the native surface as the happy-path test default.

setup() still defaults to renderer-canvas, while the updated Computer Use outcomes are native-overlay when available and none when unavailable. If existing happy-path tests call setup() without an argument, they can pass without exercising NativeKit delivery; prefer native-overlay as the default and make Canvas explicit only in a compatibility test, or verify why the legacy default is required.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/main/desktop/computerUse/ComputerUsePreviewPresenter.test.ts` around
lines 26 - 28, Change the default nativeSurface value in the setup helper to
native-overlay so argument-less happy-path tests exercise NativeKit delivery.
Keep renderer-canvas only in tests that explicitly validate canvas
compatibility, and preserve none for unavailable-surface scenarios.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/architecture/nativekit-agent-browser-pip/plan.md`:
- Around line 69-90: Update the AgentPreviewCoordinator interface to include the
presenter-facing register, dismiss, and isCurrent methods used by
YoBrowserPresenter and ComputerUsePreviewPresenter, with signatures matching
their implementation. Keep the existing coordinator methods unchanged so the
documented contract fully reflects the available API.

In `@docs/features/agent-browser-pip/spec.md`:
- Around line 14-16: Update the linked heading associated with this
frame-delivery behavior from “NativeKit 0.6.0 surface migration” to “NativeKit
0.6.3 surface migration,” preserving the paragraph content and link target.
- Around line 49-50: Update the PiP behavior specification around the closed
right-side panel rule to remove the promise of a draggable in-chat preview; make
the “otherwise” behavior apply only when native PiP is available, while
preserving automatic side-panel opening when native PiP is unavailable.

In `@docs/features/computer-use-snapshot-pip/spec.md`:
- Around line 215-217: Update the shared coordinator behavior described in the
Computer Use PiP specification so frame-push failures remain transient: limit
permanent process-level native PiP disablement to NativeKit import/load,
startup, and host-attach failures, while retaining and retrying the previous
presentation after pushImage() failures. Apply the same correction to the
corresponding behavior statement at the additional referenced section.

In `@src/main/desktop/computerUse/ComputerUsePreviewPresenter.ts`:
- Around line 500-502: Update the presentation flow around
ComputerUsePreviewPresenter.presentCurrent so a prepare-time native failure that
makes previewCoordinator unavailable transitions the state out of eligible after
presentation; ensure shouldCaptureAfterClick no longer schedules private
snapshots, and apply the same unavailable-state handling during frame
processing.

In `@test/main/app/compositionBoundaries.test.ts`:
- Around line 5-14: Replace the source-text checks in the composition startup
test with a behavioral test that exercises composition startup using a mocked
coordinator. Assert the coordinator’s initialize() is not called during startup,
then request a concrete preview target and verify initialization occurs only at
that point.

---

Nitpick comments:
In `@test/main/desktop/computerUse/ComputerUsePreviewPresenter.test.ts`:
- Around line 26-28: Change the default nativeSurface value in the setup helper
to native-overlay so argument-less happy-path tests exercise NativeKit delivery.
Keep renderer-canvas only in tests that explicitly validate canvas
compatibility, and preserve none for unavailable-surface scenarios.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 096dff42-db55-4ffc-8cc3-224f0efc5061

📥 Commits

Reviewing files that changed from the base of the PR and between 0bb2cc9 and 0e8c84c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (20)
  • docs/architecture/nativekit-agent-browser-pip/plan.md
  • docs/architecture/nativekit-agent-browser-pip/spec.md
  • docs/architecture/nativekit-agent-browser-pip/tasks.md
  • docs/features/agent-browser-pip/spec.md
  • docs/features/computer-use-snapshot-pip/plan.md
  • docs/features/computer-use-snapshot-pip/spec.md
  • docs/features/computer-use-snapshot-pip/tasks.md
  • package.json
  • resources/acp-registry/registry.json
  • resources/model-db/providers.json
  • src/main/app/composition.ts
  • src/main/desktop/browser/YoBrowserPresenter.ts
  • src/main/desktop/computerUse/ComputerUsePreviewPresenter.ts
  • src/main/desktop/preview/AgentPreviewCoordinator.ts
  • src/shared/types/desktop.ts
  • test/main/app/compositionBoundaries.test.ts
  • test/main/build/electronBuilderConfig.test.ts
  • test/main/desktop/browser/YoBrowserPresenter.test.ts
  • test/main/desktop/computerUse/ComputerUsePreviewPresenter.test.ts
  • test/main/desktop/preview/AgentPreviewCoordinator.test.ts
💤 Files with no reviewable changes (2)
  • src/shared/types/desktop.ts
  • src/main/app/composition.ts

Comment thread docs/architecture/nativekit-agent-browser-pip/plan.md
Comment thread docs/features/agent-browser-pip/spec.md
Comment thread docs/features/agent-browser-pip/spec.md
Comment thread docs/features/computer-use-snapshot-pip/spec.md Outdated
Comment thread src/main/desktop/computerUse/ComputerUsePreviewPresenter.ts
Comment on lines +5 to +14
it('does not load NativeKit from the application startup workload', async () => {
const { readFileSync } = await vi.importActual<typeof import('node:fs')>('node:fs')
const compositionSource = readFileSync(
path.resolve(process.cwd(), 'src/main/app/composition.ts'),
'utf8'
)

expect(compositionSource).not.toContain('main:yo-browser')
expect(compositionSource).not.toContain('yoBrowserPresenter.initialize()')
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Replace source-text assertions with a startup behavior test.

These checks only lock implementation spellings and do not prove startup avoids NativeKit initialization. Exercise composition startup with a mocked coordinator and assert initialize() is untouched until a concrete preview target is requested.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/main/app/compositionBoundaries.test.ts` around lines 5 - 14, Replace the
source-text checks in the composition startup test with a behavioral test that
exercises composition startup using a mocked coordinator. Assert the
coordinator’s initialize() is not called during startup, then request a concrete
preview target and verify initialization occurs only at that point.

Source: Coding guidelines

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
test/main/desktop/computerUse/ComputerUsePreviewPresenter.test.ts (2)

342-342: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid asserting the exact internal prepare call count.

toHaveBeenCalledTimes(2) couples this regression test to the presenter’s current call structure. Wait for the observable stop/release behavior instead, then assert only that preparation occurred and the unavailable surface was handled.

As per coding guidelines, committed tests should remain lean and focused on observable contracts rather than implementation internals.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/main/desktop/computerUse/ComputerUsePreviewPresenter.test.ts` at line
342, Update the regression test around coordinator.prepare to wait for the
observable stop/release behavior instead of asserting an exact prepare call
count. After that wait, assert that preparation occurred and that the
unavailable surface was handled, preserving the test’s focus on externally
observable behavior.

Source: Coding guidelines


62-63: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Model NativeKit initialization state in the test double.

isAvailable() returns true for native surfaces before initialize() runs, so the success-path tests could pass even if the presenter skipped deferred initialization. Track initialization/disablement in the mock and assert that native preparation cannot proceed before initialization.

The PR objective requires NativeKit to load only for the first concrete target.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/main/desktop/computerUse/ComputerUsePreviewPresenter.test.ts` around
lines 62 - 63, Update the NativeKit test double’s initialize and isAvailable
methods to track initialization and disablement state, so native surfaces are
unavailable until initialize completes and remain unavailable when
initialization is disabled. Add assertions covering the pre-initialization state
and verify that native preparation proceeds only after initialization,
preserving the requirement that NativeKit loads only for the first concrete
target.
test/main/desktop/preview/AgentPreviewCoordinator.test.ts (1)

302-304: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert that startup failure disables NativeKit process-wide.

The test verifies that prepare() returns 'none', but not that coordinator.isAvailable() becomes false. Without that assertion, a regression could leave the coordinator globally available and cause later presenters to retry NativeKit after startup failure.

The PR objective explicitly requires NativeKit to be disabled process-wide when loading or startup fails.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/main/desktop/preview/AgentPreviewCoordinator.test.ts` around lines 302 -
304, Extend the startup-failure test for AgentPreviewCoordinator by asserting
that coordinator.isAvailable() returns false after initialize() resolves false.
Keep the existing prepare() and overlay.attachHost assertions unchanged,
ensuring NativeKit is verified as disabled process-wide after loading or startup
failure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/main/desktop/computerUse/ComputerUsePreviewPresenter.test.ts`:
- Line 342: Update the regression test around coordinator.prepare to wait for
the observable stop/release behavior instead of asserting an exact prepare call
count. After that wait, assert that preparation occurred and that the
unavailable surface was handled, preserving the test’s focus on externally
observable behavior.
- Around line 62-63: Update the NativeKit test double’s initialize and
isAvailable methods to track initialization and disablement state, so native
surfaces are unavailable until initialize completes and remain unavailable when
initialization is disabled. Add assertions covering the pre-initialization state
and verify that native preparation proceeds only after initialization,
preserving the requirement that NativeKit loads only for the first concrete
target.

In `@test/main/desktop/preview/AgentPreviewCoordinator.test.ts`:
- Around line 302-304: Extend the startup-failure test for
AgentPreviewCoordinator by asserting that coordinator.isAvailable() returns
false after initialize() resolves false. Keep the existing prepare() and
overlay.attachHost assertions unchanged, ensuring NativeKit is verified as
disabled process-wide after loading or startup failure.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f410f370-1aa9-434b-934f-97303171a454

📥 Commits

Reviewing files that changed from the base of the PR and between 0e8c84c and d98f73f.

📒 Files selected for processing (7)
  • docs/architecture/nativekit-agent-browser-pip/plan.md
  • docs/features/agent-browser-pip/spec.md
  • docs/features/computer-use-snapshot-pip/spec.md
  • src/main/desktop/computerUse/ComputerUsePreviewPresenter.ts
  • src/main/desktop/preview/AgentPreviewCoordinator.ts
  • test/main/desktop/computerUse/ComputerUsePreviewPresenter.test.ts
  • test/main/desktop/preview/AgentPreviewCoordinator.test.ts
💤 Files with no reviewable changes (1)
  • src/main/desktop/preview/AgentPreviewCoordinator.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • docs/features/agent-browser-pip/spec.md
  • src/main/desktop/computerUse/ComputerUsePreviewPresenter.ts
  • docs/features/computer-use-snapshot-pip/spec.md
  • docs/architecture/nativekit-agent-browser-pip/plan.md

@zerob13
zerob13 merged commit c7feb49 into dev Jul 29, 2026
15 checks passed
@zhangmo8
zhangmo8 deleted the codex/fix-native-pip-lazy-load branch July 30, 2026 06:00
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