Skip to content

fix(extension): activate lazily instead of on every window (#1572) - #2183

Open
jacktrnr wants to merge 1 commit into
mainfrom
fix/1572-lazy-activation
Open

jacktrnr wants to merge 1 commit into
mainfrom
fix/1572-lazy-activation

Conversation

@jacktrnr

Copy link
Copy Markdown
Contributor

Closes #1572

Problem

onStartupFinished activated the extension on every VS Code/Cursor window, and activate() always brings up (spawns or adopts) the opencode server. So a window where you weren't using Amicode still started a server. amicode.chat.autoOpen only controls the chat panel, not the server.

Approach: lazy activation (manifest-only)

Activation now happens on first use:

  • Any contributed command. engines.vscode is ^1.95, so VS Code generates onCommand:<id> for every contributed command. The existing explicit onCommand entries stay.
  • Opening the AMICODE view (onView:amicode.workspace). If the sidebar was visible when the window was last closed, it activates at startup. That is the user actively using Amicode.
  • A restored amico-host:/ folder (onFileSystem:amico-host).

After activation, activate() runs exactly as before. Server bring-up, chat.autoOpen, and the stale-port and handshake handling (#2012, #1420) are untouched.

Why this rather than gating on chat.autoOpen (the closed #1575 approach)

  • Smaller. Two manifest lines. Gating would mean wrapping the roughly 2,000-line bring-up region of activate() in a deferred closure, then adding ensureLocalServer() and wait-for-ready calls to every server-dependent entry point (openChat, newChat, chatDeck, bindToEnvironment, newProject, newEnvironment, sidebar launches, restartServer, and others). fix(extension): gate eager server start on chat.autoOpen (#1572) #1575 itself left newProject and newEnvironment uncovered.
  • Safer. No control-flow changes inside activate(), so there is no risk to the adopt/spawn, keepalive, stale-port, or handshake ordering.
  • Actually meets the goal for default users. chat.autoOpen defaults to true, so gating on it would still spawn a server in every window for most users.

Behavior change: with chat.autoOpen=true, chat no longer opens by itself in a fresh window where the Amicode sidebar was not visible. It opens the first time the user engages Amicode, through the sidebar or a command. This is the intent of #1572.

Tests

New file packages/extension/test/lazy_activation_1572.test.ts follows the existing pattern of asserting against the manifest (sidebar_view.test.ts).

  • No eager activation event (onStartupFinished or *). Written first and failed (RED), then passed (GREEN).
  • onFileSystem:amico-host is declared, using HOST_SCHEME from mount_policy. Written first and failed (RED), then passed (GREEN).
  • Guards that commands and views stay activatable on first use. These pass on current main and fail if a later change breaks lazy activation:
    • the engine is at least 1.74, so implicit onCommand and onView events are generated;
    • every menu and keybinding entry targets a contributed command;
    • no enablement or when clause depends on a context key that activate() sets.

Results:

  • pnpm --filter amicode run typecheck: clean.
  • pnpm --filter amicode test: 346 files passed, 2 skipped; 5,820 tests passed, 60 skipped; 0 failures.

Unrelated issue found (not fixed here)

amicode.savePulse is contributed in package.json, but nothing in src registers it, so running it fails with "command not found". This was already true with eager activation and is out of scope here.

Manual check (not run yet)

  • Reload a window with the Amicode sidebar hidden. Confirm the extension does not activate and no opencode server process starts.
  • Run "Amicode: Open Chat" from the palette. Confirm the extension activates, the server starts, and chat opens.
  • Click the AMICODE activity bar icon in a fresh window. Confirm it activates and boots.

🤖 Generated with Claude Code

Drop the onStartupFinished activation event so opening a window where
Amicode isn't used no longer activates the extension, and so no longer
spawns or adopts the opencode server. Activation now happens on first
use: any contributed command (implicit onCommand, engine ^1.95), opening
the AMICODE view (onView), or a restored fleet-client amico-host:/
folder (new onFileSystem:amico-host event, which VS Code never
generates implicitly). Once activated, activate() runs unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e1c2bee5-d587-485b-8cbc-f42bb53f82dd
  • 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

@jacktrnr
jacktrnr marked this pull request as ready for review November 23, 2026 22:21
@jacktrnr

Copy link
Copy Markdown
Contributor Author

Verified hands-on in the combined 0.4.1-beta test build (test/0.4.1-beta, Developer Tools → Rebuild Locally, macOS arm64) on 2026-11-23: all checks in this PR's manual checklist pass.

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.

Extension activates unconditionally on every window via onStartupFinished, independent of chat.autoOpen, with no opt-out

1 participant