From d2ec6fe99cc6f79013e689732fdc7f77089a8ed7 Mon Sep 17 00:00:00 2001 From: Agando Date: Tue, 27 Oct 2026 14:41:20 +0100 Subject: fix(newos4): name the real Ollama failure, bound auto-connect, fix the review findings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Second pass over v4.6.105, driven by an independent review that reproduced each item. - ollama-manager.js: chat() now reports the captured cause ("Ollama error: Failed to fetch", "…: HTTP 500") instead of the generic "No provider responded"; _lastChatError is reset per call so an old reason is never replayed. chatWithTools carries the reason in its error string. - ollama-manager.js: _ensureConnected() bounds connect() with a deadline (connectTimeoutMs, default 10 s). connect() uses a bare fetch(), so a blackholed endpoint previously left the shared in-flight promise pending forever and hung every later message — the old code failed fast. The attempt is now try/finally, so a throwing terminal.log() can no longer poison _connecting and suppress the retry on the next message. - ollama-manager.js: an automatic connect no longer silently rewrites the user's saved model; the previous choice is restored in memory and in localStorage, and the user is told. - ollama-manager.js: the DeepSeek empty-content branch returned top-level tool_calls with content '', so the caller pushed an assistant message with no tool_calls and then a role:'tool' reply — an orphan tool message, which is the HTTP 400 that branch exists to prevent. tool_calls now live inside the message as well. - module-aiassist.js: a no-argument list_files returned the ROOT instead of the cwd (readDir('/') instead of ls()); it now means the current directory again. Error text keeps the path as the caller wrote it, and write_file distinguishes a read-only virtual path (/sys/…) from a missing parent instead of blaming the parent. Tests: test-ollama-error-text.js (new, 14 asserts, RED 9/5 before the edit), test-ai-fs-tools.js 7 → 16 asserts (write onto a directory, /sys write, list a file, '/', no-arg cwd, relative path), test-ollama-autoconnect.js 11 → 19 (blackholed endpoint settles + retries, saved model survives; the old "connecting hint" assertion is now falsifiable — the reviewer showed it also matched connect()'s pre-existing line). Suite: 10/10 files green. Live on v4.6.106: healthy auto-connect 42 ms with the hint; blackholed endpoint settles in 1242 ms with connectTimeoutMs=1200, prints "timed out" and "unreachable", _connecting cleared. --- modules/core/module-aiassist.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'modules/core/module-aiassist.js') diff --git a/modules/core/module-aiassist.js b/modules/core/module-aiassist.js index 303f9c2..ac8d297 100644 --- a/modules/core/module-aiassist.js +++ b/modules/core/module-aiassist.js @@ -2379,10 +2379,11 @@ buildSystemPrompt() { // MAINT-011: readDir() resolves the virtual mounts and returns null for a // path that does not exist. The old hand-rolled walk over root.content could // not see /sys, so a directory the UI shows answered "Directory not found". - const entries = fsapi.readDir(p || '/'); + // No argument means "the current directory", which ls() already does. + const entries = p ? fsapi.readDir(p) : fsapi.ls(); fsapi.currentPath = saved; if (entries === null || entries === undefined) { - return JSON.stringify({ error: `Directory not found: ${p || '/'}` }); + return JSON.stringify({ error: `Directory not found: ${originalPath || p}` }); } return JSON.stringify(entries.map(f => ({ name: f.name, type: f.type, size: f.size }))); } @@ -2430,9 +2431,12 @@ buildSystemPrompt() { const wrote = this.terminal.fs.writeFile(path, content); this.terminal.fs.currentPath = savedW; if (!wrote) { - return `Write FAILED: ${path} — parent directory missing or target is a directory; nothing was written`; + const why = (typeof this.terminal.fs._isVirtualPath === 'function' && this.terminal.fs._isVirtualPath(wp)) + ? 'read-only virtual path' + : 'parent directory missing or target is a directory'; + return `Write FAILED: ${wp} — ${why}; nothing was written`; } - return `File written: ${path} (${content.length} chars)`; + return `File written: ${wp} (${content.length} chars)`; } case 'make_directory': { const mp = a.path || ''; -- cgit v1.2.3