Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

v2.5.0 green-push: fix 6 bugs found by adversarial audit of the not-live-verified items

purple0330aa43eb8b
diff --git a/src-tauri/src/commands/bg_tasks.rs b/src-tauri/src/commands/bg_tasks.rs
index a888ec40..f220240f 100644
--- a/src-tauri/src/commands/bg_tasks.rs
+++ b/src-tauri/src/commands/bg_tasks.rs
@@ -181,6 +181,17 @@ async fn shell_task_start_impl(args: &Value) -> CmdResult {
.spawn()
.map_err(|e| internal(format!("spawn {}: {}", program, e)))?;
+ // Orphan-safety: tie the child to a kill-on-close Job Object so a true app
+ // Quit (tray Quit / parent death) tears these long-running background tasks
+ // down too — matching how Ollama/ComfyUI are handled. shutdown_subprocesses
+ // (state.rs) only knows the AppState-held PIDs, never this static REGISTRY,
+ // so without this a `shell_execute_background` task (e.g. a long build) would
+ // be orphaned on Windows after Quit. (v2.5.0 audit fix.)
+ #[cfg(target_os = "windows")]
+ if let Some(pid) = child.id() {
+ crate::commands::process::assign_pid_to_kill_on_close_job(pid);
+ }
+
let stdout = child.stdout.take();
let stderr = child.stderr.take();
let (cancel_tx, cancel_rx) = tokio::sync::oneshot::channel::<()>();
diff --git a/src-tauri/src/commands/process.rs b/src-tauri/src/commands/process.rs
index 983b5566..e6bee13d 100644
--- a/src-tauri/src/commands/process.rs
+++ b/src-tauri/src/commands/process.rs
@@ -18,9 +18,19 @@ const CREATE_NO_WINDOW: u32 = 0x08000000;
/// automatically terminates all processes in the job — no Drop needed.
#[cfg(target_os = "windows")]
fn assign_to_kill_on_close_job(child: &std::process::Child) {
+ assign_pid_to_kill_on_close_job(child.id());
+}
+
+/// PID-based variant of [`assign_to_kill_on_close_job`]. Usable from spawn paths
+/// that don't own a `std::process::Child` — notably `tokio::process::Child`
+/// (whose `id()` is `Option<u32>`) in the background-task runner (bg_tasks.rs).
+/// Same KILL_ON_JOB_CLOSE semantics; a pid of 0 is ignored.
+#[cfg(target_os = "windows")]
+pub(crate) fn assign_pid_to_kill_on_close_job(pid: u32) {
use windows_sys::Win32::System::JobObjects::*;
use windows_sys::Win32::Foundation::*;
+ if pid == 0 { return; }
unsafe {
let job = CreateJobObjectW(std::ptr::null(), std::ptr::null());
if job.is_null() { return; }
@@ -35,8 +45,6 @@ fn assign_to_kill_on_close_job(child: &std::process::Child) {
std::mem::size_of::<JOBOBJECT_EXTENDED_LIMIT_INFORMATION>() as u32,
);
- // Open process handle from PID
- let pid = child.id();
let handle = windows_sys::Win32::System::Threading::OpenProcess(
windows_sys::Win32::System::Threading::PROCESS_SET_QUOTA
| windows_sys::Win32::System::Threading::PROCESS_TERMINATE,
diff --git a/src/components/chat/StagedChangesPanel.tsx b/src/components/chat/StagedChangesPanel.tsx
index c6f58e69..a711ff58 100644
--- a/src/components/chat/StagedChangesPanel.tsx
+++ b/src/components/chat/StagedChangesPanel.tsx
@@ -43,7 +43,10 @@ export function StagedChangesPanel({ chatId }: Props) {
setApplying((prev) => new Set(prev).add(change.id))
try {
await toolRegistry.execute('file_write', {
- path: change.path,
+ // Use the absolute path captured at stage time: by apply time the run's
+ // active chat/workspace context is cleared, so a relative path would
+ // land in agent-workspace/default/ instead of the project folder. (audit fix)
+ path: change.resolvedPath || change.path,
content: change.newContent,
})
remove(chatId, change.id)
diff --git a/src/components/models/DiscoverModels.tsx b/src/components/models/DiscoverModels.tsx
index 2f6d6577..1029e5a9 100644
--- a/src/components/models/DiscoverModels.tsx
+++ b/src/components/models/DiscoverModels.tsx
@@ -20,6 +20,7 @@ import { useSettingsStore } from '../../stores/settingsStore'
import { useModelStore } from '../../stores/modelStore'
import { useWorkflowStore } from '../../stores/workflowStore'
import { getProviderIdFromModel } from '../../api/providers'
+import { matchesLmStudioInstalled, type InstalledModelLike } from '../../lib/lmstudio-match'
import { hfUrlToOllamaRef, hfUrlToLmStudioSubdir } from '../../lib/hf-to-provider'
import { GlassCard } from '../ui/GlassCard'
import { GlowButton } from '../ui/GlowButton'
@@ -324,24 +325,12 @@ export function DiscoverModels({ category }: Props) {
// because LM Studio surfaces them by file basename in the openai-compat
// listing rather than by an Ollama-style hf.co tag. Match by filename
// (case-insensitive, with/without trailing `.gguf`).
- if (model.filename) {
- const wantBase = model.filename.toLowerCase().replace(/\.gguf$/, '')
- const installedLmStudio = installedModels.filter(m => {
- if (m.provider !== 'openai') return false
- const pname = (m.providerName || '').toLowerCase()
- return pname.includes('lm studio') || pname.includes('lmstudio')
- })
- for (const m of installedLmStudio) {
- const candidates = [m.model, m.name]
- .filter(Boolean)
- .map(s => String(s).toLowerCase())
- for (const c of candidates) {
- const cBase = c.replace(/\.gguf$/, '')
- if (cBase === wantBase || cBase.endsWith(`/${wantBase}`) || cBase.endsWith(`\\${wantBase}`)) {
- return true
- }
- }
- }
+ // Match against LM Studio's installed models too (not just Ollama tags).
+ // The matcher (lib/lmstudio-match.ts, unit-tested) handles both the older
+ // full-basename id form AND LM Studio's modern quant-less publisher/short
+ // key (e.g. "qwen/qwen2.5-vl-7b" vs "Qwen2.5-VL-7B-Instruct-Q4_K_M.gguf").
+ if (model.filename && matchesLmStudioInstalled(model.filename, installedModels as unknown as InstalledModelLike[])) {
+ return true
}
return false
diff --git a/src/components/models/ModelSelector.tsx b/src/components/models/ModelSelector.tsx
index 784fce14..bff30120 100644
--- a/src/components/models/ModelSelector.tsx
+++ b/src/components/models/ModelSelector.tsx
@@ -326,9 +326,13 @@ export function ModelSelector() {
* (the user might have multiple LM Studio models loaded already).
*/
const toggleLmStudioLoad = async (model: AIModel) => {
- const id = ('lmsKey' in model && typeof (model as any).lmsKey === 'string'
- ? (model as any).lmsKey
- : model.name) as string
+ // Use lmsIdOf so LU's `openai::` routing prefix is stripped. Re-deriving the
+ // id inline (as this did) passed "openai::<key>" to `lms load`, which
+ // matches no model → silent failure; and the loaded-set / spinner checks
+ // below compare against the BARE lmsIdOf, so they never matched the prefixed
+ // id either (no spinner, green state never reflected reality). The same
+ // prefix strip is already applied to handleSelectModel + rowId.
+ const id = lmsIdOf(model)
if (!id || togglingLms) return
setTogglingLms(id)
try {
diff --git a/src/hooks/useCodex.ts b/src/hooks/useCodex.ts
index 7807c44f..54d003b7 100644
--- a/src/hooks/useCodex.ts
+++ b/src/hooks/useCodex.ts
@@ -415,7 +415,12 @@ export function useCodex() {
try {
const repoMap = await fetchRepoMap({
workingDirectory: workDir,
- query: instruction,
+ // Do NOT pass the raw instruction as `query`: the Rust side filters
+ // file paths with a whole-string case-insensitive substring match, so
+ // any realistic multi-word instruction ("add a dark mode toggle …")
+ // is never a substring of a path → the map silently empties and the
+ // whole feature no-ops. Omitting query returns the global PageRank
+ // top-N — the intended Aider-style repo map for context.
limit: settings.codexRepoMapLimit ?? 20,
signal: abort.signal,
})
@@ -954,9 +959,18 @@ export function useCodex() {
const path = String(args.path ?? '')
if (!path) return 'file_write: missing path'
const newContent = String(args.content ?? '')
+ // Resolve against the run's workspace NOW (at stage time). Apply
+ // happens later, after this turn's finally clears the active
+ // chat/workspace context, so a relative path would otherwise route to
+ // agent-workspace/default/ instead of the real project folder. The
+ // bridge uses an absolute path as-is. (v2.5.0 audit fix.)
+ const isAbs = /^([a-zA-Z]:[\\/]|[\\/]|\\\\)/.test(path)
+ const resolvedPath = isAbs || !workDir || workDir === '.'
+ ? path
+ : `${workDir.replace(/[\\/]+$/, '')}${workDir.includes('\\') ? '\\' : '/'}${path.replace(/^[\\/]+/, '')}`
let oldContent = ''
try {
- const r = await backendCall<{ content?: string }>('file_read', { path })
+ const r = await backendCall<{ content?: string }>('file_read', { path: resolvedPath })
oldContent = r?.content ?? ''
} catch {
// New file — leave oldContent empty so the diff renders an
@@ -965,6 +979,7 @@ export function useCodex() {
const diff = computeUnifiedDiff(path, oldContent, newContent)
useStagedChangesStore.getState().stage(convId!, {
path,
+ resolvedPath,
oldContent,
newContent,
diff,
diff --git a/src/lib/__tests__/lmstudio-match.test.ts b/src/lib/__tests__/lmstudio-match.test.ts
new file mode 100644
index 00000000..6f8fa3ed
--- /dev/null
+++ b/src/lib/__tests__/lmstudio-match.test.ts
@@ -0,0 +1,64 @@
+import { describe, it, expect } from 'vitest'
+import { matchesLmStudioInstalled, modelIdentity, extractQuant, type InstalledModelLike } from '../lmstudio-match'
+
+const lms = (id: string, field: 'model' | 'name' | 'lmsKey' = 'model'): InstalledModelLike => ({
+ provider: 'openai',
+ providerName: 'LM Studio',
+ [field]: id,
+})
+
+describe('matchesLmStudioInstalled — exact / quant-precise matches (Bug Y/b)', () => {
+ it('matches the older exact full-basename id form', () => {
+ expect(matchesLmStudioInstalled('Hermes-3-Llama-3.1-8B.Q4_K_M.gguf', [lms('hermes-3-llama-3.1-8b.q4_k_m.gguf')])).toBe(true)
+ })
+ it('matches via a publisher/ path suffix', () => {
+ expect(matchesLmStudioInstalled('Hermes-3-Llama-3.1-8B.Q4_K_M.gguf', [lms('mradermacher/hermes-3-llama-3.1-8b.q4_k_m')])).toBe(true)
+ })
+ it('matches the key@quant id form against the SAME quant', () => {
+ expect(matchesLmStudioInstalled('Qwen2.5-0.5B-Instruct-Q4_K_M.gguf', [lms('qwen2.5-0.5b-instruct@q4_k_m')])).toBe(true)
+ })
+ it('also reads the lmsKey field', () => {
+ expect(matchesLmStudioInstalled('Qwen2.5-0.5B-Instruct-Q4_K_M.gguf', [lms('qwen2.5-0.5b-instruct@q4_k_m', 'lmsKey')])).toBe(true)
+ })
+ it('matches a quant-LESS Discover entry from a quant-less id (generic row)', () => {
+ expect(matchesLmStudioInstalled('Qwen2.5-VL-7B-Instruct.gguf', [lms('qwen/qwen2.5-vl-7b')])).toBe(true)
+ })
+})
+
+describe('matchesLmStudioInstalled — NO false positives (v2.5.0 adversarial-audit regression guards)', () => {
+ it('does NOT light a DIFFERENT quant of the same model (q4 id vs q8 row)', () => {
+ expect(matchesLmStudioInstalled('Qwen2.5-0.5B-Instruct-Q8_0.gguf', [lms('qwen2.5-0.5b-instruct@q4_k_m')])).toBe(false)
+ })
+ it('does NOT light quant-specific rows from a COLLAPSED quant-less id — the live over-match', () => {
+ // LM Studio reports "qwen3.6-27b" (one quant on disk, no @quant). The curated
+ // list has 7 quant rows; installing one must NOT badge the siblings.
+ expect(matchesLmStudioInstalled('Qwen3.6-27B-Q4_K_M.gguf', [lms('qwen3.6-27b')])).toBe(false)
+ expect(matchesLmStudioInstalled('Qwen3.6-27B-Q8_0.gguf', [lms('qwen3.6-27b')])).toBe(false)
+ expect(matchesLmStudioInstalled('Qwen3.6-27B-Q5_K_M.gguf', [lms('qwen3.6-27b')])).toBe(false)
+ })
+ it('does NOT collapse genuinely different finetunes (abliterated vs plain)', () => {
+ expect(matchesLmStudioInstalled('Qwen3-8B-abliterated.Q4_K_M.gguf', [lms('qwen3-8b@q4_k_m')])).toBe(false)
+ })
+ it('does NOT light a different model (coder vs vl)', () => {
+ expect(matchesLmStudioInstalled('Qwen2.5-VL-7B-Instruct-Q4_K_M.gguf', [lms('qwen2.5-coder-7b-instruct@q4_k_m')])).toBe(false)
+ })
+ it('ignores non-LM-Studio (ollama) installed entries', () => {
+ expect(matchesLmStudioInstalled('Qwen2.5-0.5B-Instruct-Q4_K_M.gguf', [{ provider: 'ollama', model: 'qwen2.5-0.5b-instruct' }])).toBe(false)
+ })
+ it('empty filename never matches', () => {
+ expect(matchesLmStudioInstalled('', [lms('qwen/qwen2.5-vl-7b')])).toBe(false)
+ })
+})
+
+describe('extractQuant + modelIdentity', () => {
+ it('extractQuant pulls the trailing quant tag', () => {
+ expect(extractQuant('Qwen3.6-27B-Q4_K_M.gguf')).toBe('q4km')
+ expect(extractQuant('qwen2.5-0.5b-instruct@q4_k_m')).toBe('q4km')
+ expect(extractQuant('zai-org_GLM-4.7-Flash-IQ2_M.gguf')).toBe('iq2m')
+ expect(extractQuant('qwen/qwen2.5-vl-7b')).toBe(null)
+ })
+ it('modelIdentity drops publisher, quant, decoration + separators', () => {
+ expect(modelIdentity('Qwen2.5-VL-7B-Instruct-Q4_K_M.gguf')).toBe('qwen25vl7b')
+ expect(modelIdentity('qwen/qwen2.5-vl-7b')).toBe('qwen25vl7b')
+ })
+})
diff --git a/src/lib/lmstudio-match.ts b/src/lib/lmstudio-match.ts
new file mode 100644
index 00000000..5c784810
--- /dev/null
+++ b/src/lib/lmstudio-match.ts
@@ -0,0 +1,97 @@
+// Bug Y/b (v2.5.0) — match an LM-Studio-installed model against a curated
+// Discover entry's GGUF filename so the INSTALLED badge lights up after a
+// restart. Pulled out of DiscoverModels.tsx so it can be unit-tested directly.
+//
+// Two id forms must be bridged:
+// • OLD / full: "Qwen2.5-0.5B-Instruct-Q4_K_M.gguf" or "publisher/...-Q4_K_M"
+// • MODERN short: "qwen2.5-0.5b-instruct@q4_k_m" (LM Studio adds @quant only
+// when several quants of the same model are downloaded)
+// • COLLAPSED: "qwen/qwen2.5-vl-7b" (publisher/repo, NO quant — what LM
+// Studio reports when a model has a single quant on disk)
+//
+// CRITICAL correctness rule (v2.5.0 adversarial-audit fix): a Discover row is
+// quant-SPECIFIC (its filename names exactly one quant), so the INSTALLED badge
+// must only light when we have THAT quant. We therefore require quant equality
+// whenever the Discover filename carries a quant. A COLLAPSED quant-less LM
+// Studio id carries no quant evidence, so it deliberately does NOT light
+// quant-specific rows — a false "you already have this" badge is worse than a
+// missing one, and would otherwise wrongly mark every quant sibling of a model
+// (e.g. all 7 "Qwen 3.6 27B" rows) as installed from a single download.
+
+export interface InstalledModelLike {
+ provider?: string
+ providerName?: string
+ model?: string
+ name?: string
+ lmsKey?: string
+}
+
+// Matches a trailing GGUF quant tag: optional `ud-` prefix, then
+// q<n>… / iq<n>… / f16 / f32 / bf16, delimited by @ . _ or -.
+const QUANT_TAIL = /[@._-]((?:ud-)?(?:iq\d|q\d|f16|f32|bf16)[a-z0-9_]*)$/i
+
+/** The quant token of a model id/filename (compacted, e.g. "q4km"), or null. */
+export function extractQuant(s: string): string | null {
+ const base = (s.toLowerCase().split(/[\\/]/).pop() || '').replace(/\.gguf$/, '')
+ const m = base.match(QUANT_TAIL)
+ return m ? m[1].replace(/[^a-z0-9]/g, '') : null
+}
+
+/**
+ * Model identity WITHOUT quant: last path segment, drop `.gguf`, drop the
+ * trailing quant tag and one trailing decoration word (instruct/it/chat/hf),
+ * then strip separators. Bridges "qwen/qwen2.5-vl-7b" and
+ * "Qwen2.5-VL-7B-Instruct-Q4_K_M.gguf" → both "qwen25vl7b". Decoration words
+ * like abliterated/uncensored/heretic are intentionally NOT stripped so
+ * genuinely different finetunes never collapse together.
+ */
+export function modelIdentity(s: string): string {
+ return (s.toLowerCase().split(/[\\/]/).pop() || '')
+ .replace(/\.gguf$/, '')
+ .replace(QUANT_TAIL, '')
+ .replace(/[._-](instruct|it|chat|hf)$/i, '')
+ .replace(/[^a-z0-9]/g, '')
+}
+
+/**
+ * True when any LM-Studio-installed model corresponds to the given GGUF
+ * filename. Order: exact basename / `publisher/`-suffix (already quant-precise),
+ * then a normalised model-identity match that additionally REQUIRES the quant to
+ * agree whenever the Discover filename names one.
+ */
+export function matchesLmStudioInstalled(
+ filename: string,
+ installed: InstalledModelLike[],
+): boolean {
+ if (!filename) return false
+ const wantBase = filename.toLowerCase().replace(/\.gguf$/, '')
+ const wantId = modelIdentity(filename)
+ const wantQuant = extractQuant(filename)
+ const lms = installed.filter((m) => {
+ if (m.provider !== 'openai') return false
+ const pname = (m.providerName || '').toLowerCase()
+ return pname.includes('lm studio') || pname.includes('lmstudio')
+ })
+ for (const m of lms) {
+ const candidates = [m.model, m.name, m.lmsKey]
+ .filter(Boolean)
+ .map((s) => String(s).toLowerCase())
+ for (const c of candidates) {
+ const cBase = c.replace(/\.gguf$/, '')
+ // (1) exact / path-suffix — full basename ids, already carry the quant
+ if (cBase === wantBase || cBase.endsWith(`/${wantBase}`) || cBase.endsWith(`\\${wantBase}`)) {
+ return true
+ }
+ // (2) normalised identity + quant agreement
+ const cId = modelIdentity(c)
+ if (cId && wantId && cId.length >= 5 && cId === wantId) {
+ if (!wantQuant) return true // generic Discover entry (no quant) → match
+ const cQuant = extractQuant(c)
+ if (cQuant && cQuant === wantQuant) return true // exact quant present
+ // quant-specific Discover row but candidate quant missing/different →
+ // do NOT light (avoids quant-sibling false positives).
+ }
+ }
+ }
+ return false
+}
diff --git a/src/stores/stagedChangesStore.ts b/src/stores/stagedChangesStore.ts
index 18dcffc2..479fa620 100644
--- a/src/stores/stagedChangesStore.ts
+++ b/src/stores/stagedChangesStore.ts
@@ -4,8 +4,17 @@ import { v4 as uuid } from 'uuid'
export interface StagedChange {
/** Stable id assigned at stage-time so the UI can key + remove safely. */
id: string
- /** Path the model called `file_write` with — unresolved; the bridge resolves on apply. */
+ /** Path the model called `file_write` with (as the model wrote it — may be relative). */
path: string
+ /**
+ * Absolute path resolved against the run's workspace AT STAGE TIME. Apply
+ * happens after the run ends, when useCodex's finally has cleared the active
+ * chat/workspace context — so a relative `path` would route to
+ * agent-workspace/default/ instead of the project folder the agent wrote into.
+ * Writing this captured absolute path makes the approved diff land exactly
+ * where it should. Falls back to `path` (already absolute / no workspace set).
+ */
+ resolvedPath?: string
/** Full file content before the write — empty string when the target didn't exist. */
oldContent: string
/** Full file content the model wants to write. */
diff --git a/vite.config.ts b/vite.config.ts
index 70030abc..4b6df627 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -60,6 +60,13 @@ function stripConsolePlugin(): Plugin {
if (id.includes('\0')) return null // virtual module
if (id.includes('node_modules')) return null
const clean = id.split('?')[0]
+ // The structured logger (src/lib/logger.ts) is the ONE sanctioned console
+ // sink: in production it serialises every event to a single-line JSON
+ // object on stdout via `console.log`. That call is a brace-less
+ // `else console.log(line)` which this plugin would neutralise to `void 0`,
+ // silencing every log.info/log.debug in prod and defeating the logger's
+ // whole purpose. Leave the logger module untouched, like node_modules.
+ if (/[\\/]lib[\\/]logger\.[cm]?[jt]sx?$/.test(clean)) return null
if (!STRIPPABLE.test(clean)) return null
if (!code.includes('console.')) return null