Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

fix: harden scheduled imports and proxy validation

nash_su666f72219ae5
diff --git a/src-tauri/src/proxy.rs b/src-tauri/src/proxy.rs
index 253474ed..047bf6ae 100644
--- a/src-tauri/src/proxy.rs
+++ b/src-tauri/src/proxy.rs
@@ -94,9 +94,12 @@ pub fn apply_proxy_env(config: &ProxyConfig) -> String {
// through the now-removed proxy. The same applies to invalid
// URLs and unsupported schemes (treat as disabled).
let url = config.url.trim();
- let invalid_scheme = !url.starts_with("http://") && !url.starts_with("https://");
+ let parsed_url = reqwest::Url::parse(url).ok();
+ let supported_url = parsed_url.as_ref().is_some_and(|parsed| {
+ matches!(parsed.scheme(), "http" | "https") && parsed.host_str().is_some()
+ });
- let proxy_active = config.enabled && !url.is_empty() && !invalid_scheme;
+ let proxy_active = config.enabled && supported_url;
ACCEPT_INVALID_CERTS.store(
proxy_active && config.accept_invalid_certs,
Ordering::Relaxed,
@@ -108,10 +111,15 @@ pub fn apply_proxy_env(config: &ProxyConfig) -> String {
"disabled".to_string()
} else if url.is_empty() {
"disabled (empty url)".to_string()
- } else {
+ } else if !supported_url {
// Mask before logging — an invalid URL might still
// contain a password the user mis-typed.
- format!("disabled (unsupported scheme: {})", redact_url(url))
+ format!(
+ "disabled (invalid or unsupported proxy url: {})",
+ redact_url(url)
+ )
+ } else {
+ "disabled".to_string()
};
}
@@ -325,6 +333,20 @@ mod tests {
});
}
+ #[test]
+ fn rejects_malformed_urls_even_when_the_scheme_prefix_looks_supported() {
+ isolated(|| {
+ apply_proxy_env(&ProxyConfig {
+ enabled: true,
+ url: "http://".into(),
+ bypass_local: true,
+ accept_invalid_certs: true,
+ });
+ assert!(std::env::var("HTTP_PROXY").is_err());
+ assert!(!ACCEPT_INVALID_CERTS.load(Ordering::Relaxed));
+ });
+ }
+
#[test]
fn disable_after_enable_clears_previously_set_env_vars() {
// Regression: if the user enabled the proxy, then disables
diff --git a/src/App.tsx b/src/App.tsx
index c454362f..a1ea47e0 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -94,7 +94,14 @@ function App() {
async function hydrateScheduledImportAfterOpen(proj: WikiProject): Promise<void> {
try {
- const savedScheduledImport = await loadScheduledImportConfig(proj.path)
+ let savedScheduledImport = null
+ try {
+ savedScheduledImport = await loadScheduledImportConfig(proj.path)
+ } catch (err) {
+ // A damaged config for the active project must not disable monitors
+ // belonging to every other recent project.
+ console.warn("[startup] failed to load current scheduled import config:", err)
+ }
if (!isCurrentProject(proj)) return
if (savedScheduledImport) {
// Migrate relative path to absolute (backward compatibility)
@@ -106,15 +113,22 @@ function App() {
...savedScheduledImport,
path,
})
+ } else {
+ useWikiStore.getState().setScheduledImportConfig({
+ enabled: false,
+ path: "",
+ interval: 60,
+ lastScan: null,
+ })
}
const scheduledImportConfig = useWikiStore.getState().scheduledImportConfig
if (!isCurrentProject(proj)) return
- if (scheduledImportConfig.enabled && scheduledImportConfig.path && scheduledImportConfig.interval > 0) {
- const { startScheduledImport } = await import("@/lib/scheduled-import")
- if (!isCurrentProject(proj)) return
- startScheduledImport(proj, scheduledImportConfig)
- }
+ const { startScheduledImport } = await import("@/lib/scheduled-import")
+ if (!isCurrentProject(proj)) return
+ // Start the global sweep even when this project's own schedule is off;
+ // recently opened projects may still have active folder monitors.
+ startScheduledImport(proj, scheduledImportConfig)
} catch (err) {
console.warn("[startup] failed to hydrate scheduled import:", err)
}
diff --git a/src/components/settings/settings-view.tsx b/src/components/settings/settings-view.tsx
index af7bb11c..fba479a3 100644
--- a/src/components/settings/settings-view.tsx
+++ b/src/components/settings/settings-view.tsx
@@ -484,16 +484,10 @@ export function SettingsView() {
if (project) {
await saveScheduledImportConfig(project.path, newScheduledImport)
- const { startScheduledImport, stopScheduledImport } = await import("@/lib/scheduled-import")
- if (
- newScheduledImport.enabled &&
- newScheduledImport.path &&
- newScheduledImport.interval > 0
- ) {
- startScheduledImport(project, newScheduledImport)
- } else {
- stopScheduledImport()
- }
+ const { startScheduledImport } = await import("@/lib/scheduled-import")
+ // Keep the cross-project scheduler alive even if the current
+ // project's own monitor was just disabled.
+ startScheduledImport(project, newScheduledImport)
}
await saveMineruConfig(newMineruConfig)
diff --git a/src/lib/ingest-queue.test.ts b/src/lib/ingest-queue.test.ts
index d208e4c3..37093e17 100644
--- a/src/lib/ingest-queue.test.ts
+++ b/src/lib/ingest-queue.test.ts
@@ -165,6 +165,24 @@ describe("ingest-queue — enqueue & basic processing", () => {
expect(getQueue()).toHaveLength(0)
})
+ it("recovers the inactive-project write chain after a persistence failure", async () => {
+ mockWriteFile
+ .mockRejectedValueOnce(new Error("disk temporarily unavailable"))
+ .mockResolvedValue(undefined as unknown as void)
+
+ await expect(enqueueInactiveProjectBatch(TEST_ID_B, TEST_PATH_B, [
+ { sourcePath: `${TEST_PATH_B}/raw/sources/first.pdf`, folderContext: "" },
+ ])).rejects.toThrow("disk temporarily unavailable")
+
+ await expect(enqueueInactiveProjectBatch(TEST_ID_B, TEST_PATH_B, [
+ { sourcePath: `${TEST_PATH_B}/raw/sources/second.pdf`, folderContext: "" },
+ ])).resolves.toHaveLength(1)
+ expect(mockWriteFile).toHaveBeenLastCalledWith(
+ `${TEST_PATH_B}/.llm-wiki/ingest-queue.json`,
+ expect.stringContaining("raw/sources/second.pdf"),
+ )
+ })
+
it("enqueueIngest adds a pending task and triggers processing", async () => {
mockAutoIngest.mockResolvedValue(["wiki/sources/foo.md"])
diff --git a/src/lib/ingest-queue.ts b/src/lib/ingest-queue.ts
index 0bae4241..4c7377a3 100644
--- a/src/lib/ingest-queue.ts
+++ b/src/lib/ingest-queue.ts
@@ -280,9 +280,7 @@ export async function enqueueInactiveProjectBatch(
const pp = normalizePath(projectPath)
const ids: string[] = []
let written = false
- const previousWrite = inactiveQueueWrite
- inactiveQueueWrite = (async () => {
- await previousWrite
+ const operation = inactiveQueueWrite.then(async () => {
// restoreQueue sets currentProjectId before waiting for this write. If the
// user opened this project meanwhile, leave queuing to the active scanner
// instead of racing its in-memory queue with a stale disk snapshot.
@@ -324,8 +322,13 @@ export async function enqueueInactiveProjectBatch(
}
await writeFile(queueFilePath(pp), JSON.stringify(persisted, null, 2))
written = true
- })()
- await inactiveQueueWrite
+ })
+ // Keep the serialization chain usable after an I/O failure while still
+ // returning the failure to this caller.
+ inactiveQueueWrite = operation.catch((err) => {
+ console.warn("[Ingest Queue] Failed to persist inactive-project tasks:", err)
+ })
+ await operation
return written ? ids : []
}
diff --git a/src/lib/scheduled-import.ts b/src/lib/scheduled-import.ts
index 29534683..7cd6f6ec 100644
--- a/src/lib/scheduled-import.ts
+++ b/src/lib/scheduled-import.ts
@@ -595,10 +595,14 @@ export function startScheduledImport(
stopScheduledImport()
const runId = ++activeRunId
- void runScheduledImportSweep(project, config, runId, true)
+ void runScheduledImportSweep(project, config, runId, true).catch((err) => {
+ console.error("Scheduled import sweep failed:", err)
+ })
scanTimer = setInterval(() => {
- void runScheduledImportSweep(project, config, runId, false)
+ void runScheduledImportSweep(project, config, runId, false).catch((err) => {
+ console.error("Scheduled import sweep failed:", err)
+ })
}, 60 * 1000)
}
@@ -612,11 +616,17 @@ async function runScheduledImportSweep(
const projects = [activeProject, ...recents.filter((item) => item.id !== activeProject.id)]
for (const project of projects) {
if (runId !== activeRunId) return
- const config = project.id === activeProject.id
- ? forceActive
- ? activeConfig
- : (await loadScheduledImportConfig(project.path)) ?? activeConfig
- : await loadScheduledImportConfig(project.path)
+ let config: ScheduledImportConfig | null
+ try {
+ config = project.id === activeProject.id
+ ? forceActive
+ ? activeConfig
+ : (await loadScheduledImportConfig(project.path)) ?? activeConfig
+ : await loadScheduledImportConfig(project.path)
+ } catch (err) {
+ console.warn(`[scheduled-import] failed to load config for ${project.path}:`, err)
+ continue
+ }
if (!config) continue
if (!isScheduledImportDue(config) && !(project.id === activeProject.id && forceActive)) {
continue