You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[P1][bug] AI permission handler holds tokio worker thread for up to 5 min — worker starvation risk under load #315
src-tauri/crates/mas-ai/src/service.rs:295-345 (per-tool permission handler). The Copilot SDK permission callback is synchronous (called from SDK code). The implementation does tokio::task::block_in_place(|| tokio::runtime::Handle::current().block_on(async { ... timeout(5min) ... })). Audit finding F8 in docs/audits/ai.md.
Problem
This holds a tokio worker thread hostage for up to 5 minutes per pending approval. With N concurrent sessions, N workers are parked. Default multi-thread runtime uses ~CPU-count workers; a small CI box (2 vCPU) can have its entire worker pool starved with 2 concurrent permission requests, every other async task stops making progress. The frontend's pendingPermission state doesn't show the user how long the prompt has been waiting, doesn't auto-deny, doesn't have a timeout indicator. Worst case: the user walks away, the worker is held until the SDK session times out internally or the user finally responds.
src/stores/aiStore.ts:194-201, 297-308 (pendingPermission state, no timeout)
Repro
Static analysis + dynamic: open 5 concurrent AI conversations that all issue a run_query permission request. Within 60s, issue a normal execute_query from a third tab — observe it hanging because the worker pool is starved.
Expected
Worker threads are not parked for the duration of a user-permission wait. The frontend auto-denies after a UI-appropriate timeout (60s, matching native dialog conventions). A normal DB query from a sibling tab executes unimpeded.
Proposed fix
Scope M. (a) Reduce the timeout from 300s to 60s. (b) Have the frontend auto-deny after a 60s timeout: useEffect timer in AIChatPanel that, when pendingPermission is set, starts a countdown; on expiry calls approvePermission(false). (c) Move the permission handler to a dedicated blocking thread pool (spawn_blocking from a single ApprovalActor) so the main worker pool isn't poisoned.
Acceptance
Open 5 concurrent AI conversations that all issue a run_query permission request; after 60s the frontend auto-denies all 5; workers free up immediately; the main pool handles unrelated IPC commands (test by issuing a normal DB query concurrently).
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: the permission handler is gone. Approval happens in SQLPilot's own window — see §2, which is the keystone of the design — and nothing blocks a worker thread waiting for a human.
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.
Activity
EVWorth commentedon Sep 12, 2026
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-aicrate, its Copilot SDK session, its system prompt and its tool guards are all going.What that does to this issue specifically: the permission handler is gone. Approval happens in SQLPilot's own window — see §2, which is the keystone of the design — and nothing blocks a worker thread waiting for a human.
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.