Skip to content

[P1][bug] ai_get_status always calls ensure_started() — checking AI status triggers heavy SDK spin-up #316

Closed

Description

@EVWorth

Context

src-tauri/crates/mas-ai/src/service.rs:512-547 (get_status). get_status first calls self.ensure_started().await, which does Client::builder().build() + client.start().await if the client hasn't been initialized. Audit finding F9 in docs/audits/ai.md.

Problem

Calling start() on the Copilot SDK spins up a Node.js subprocess, establishes JSON-RPC, performs the initial handshake. That's a heavy operation that should not be on the hot path of checking availability. aiStore.checkStatus is called on AIChatPanel mount and after setConfig — both benign. But any future caller (settings panel, status bar, OS integration) that polls aiGetStatus once per minute will pay the SDK spin-up cost repeatedly. Also: get_status failure paths all collapse to available: false — doesn't differentiate "CLI missing" vs "not authenticated" vs "network error" vs "rate limited".

Files

  • src-tauri/crates/mas-ai/src/service.rs:512-547 (get_status, ensure_started)
  • src-tauri/crates/mas-ai/src/models.rs (AiStatus type)
  • src/stores/aiStore.ts:78-91 (checkStatus caller)

Repro

Call api.aiGetStatus() once, then again within 1s — the first call takes ~500ms-2s (SDK handshake), subsequent calls are cached. But ensure_started failure swallows the actual error reason.

Expected

Cached status check is < 1ms; full status refresh is opt-in. Available reason is distinguishable (CLI missing / unauthenticated / network / rate-limited).

Proposed fix

Scope S. Split into get_status() (cheap, cached) and refresh_status() (full re-handshake). Make ensure_started only run inside refresh_status. Extend AiStatus to carry a reason: Option<String> distinguishing CLI-missing / unauthenticated / network-error. Surface in AIChatPanel header so the user knows whether to install the CLI vs log in vs retry.

Acceptance

Calling aiGetStatus() once at app start (full), then 5 more times in quick succession — only the first call does the SDK handshake; subsequent calls return cached state in < 1ms. Status carries a reason field that distinguishes "not installed" vs "not authenticated".

Needs human verify

yes

Activity

  1. added
    audit
    severity/p1
    kind/bug
    area/ai
    on Jul 31, 2026
  2. EVWorth commented on Sep 12, 2026

    @EVWorth
    OwnerAuthor

    Closing as obsolete rather than fixed: this describes the implementation that ADR-011 replaces.

    The AI feature is being rebuilt around a decision made in #673 — SQLPilot does not call a model. It exposes the database, under its own policy, to whatever harness the user already runs and pays for. The mas-ai crate, its Copilot SDK session, its system prompt and its tool guards are all going.

    What that does to this issue specifically: there is no SDK to spin up, so nothing heavy happens when the UI asks about status. What replaces it is harness discovery: is a harness installed, is a session attached.

    The design is in docs/design/AI_INTEGRATION.md and ADR-011. If any part of this issue survives the redesign in a form I have missed, reopen it — I would rather re-argue it than lose it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/aiauditkind/bugseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions