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 session map has no eviction — HashMap grows unboundedly across conversations #318
src-tauri/crates/mas-ai/src/service.rs:22-43 (sessions: Arc<RwLock<HashMap<String, SessionEntry>>>). Every unique conversation_id adds a SessionEntry (including an Arc<copilot_sdk::Session>) to the in-memory map. The frontend's aiStore.newConversation generates a UUID per "New Chat" click. Audit finding F11 in docs/audits/ai.md.
Problem
There is no LRU, no TTL, no max-size. Over weeks of normal use the map grows linearly; the Copilot SDK holds per-session state in its Node.js subprocess (model context, conversation history, any in-flight request). On a developer machine that uses the AI panel daily, after a few months the Rust process holds N stale sessions with their SDK-side counterparts, contributing to memory pressure and SDK subprocess heap pressure.
Static analysis: grep for sessions.remove and evict in service.rs — only the Drop impl (service.rs:574-584) touches the field. No eviction logic anywhere.
Expected
Session count stays bounded regardless of how many New Chat clicks happen. Eviction is observable via tracing.
Proposed fix
Scope M. Change sessions to Arc<Mutex<LruCache<String, Arc<Session>>>> (e.g., lru crate, capacity 50) keyed by conversation_id. On chat insertion, if the LRU evicts, call session.abort() + drop. Document the cap in AiStatus (e.g., session_limit: 50). Emit a tracing::info! on eviction.
Acceptance
Starting 100 conversations (newConversation + sendMessage) keeps the in-memory session count at the configured cap; the 51st conversation abort()s the oldest; a tracing info line is emitted on eviction.
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 session map goes with the crate. Sessions in the new design are harness processes with explicit lifetimes — attached, cancellable, and gone when they end (§6).
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 session map goes with the crate. Sessions in the new design are harness processes with explicit lifetimes — attached, cancellable, and gone when they end (§6).
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.