Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([cos-runner-client-non-json-response-handling]): tolerate non-JSON runner responses (#610)

[._.]/ Adam Eivy5a770c751213
diff --cc PLAN.md
index eac7546682,2985e59b48..9acd382ef5
--- a/PLAN.md
+++ b/PLAN.md
@@@ -6,8 -6,9 +6,8 @@@ For project goals, see [GOALS.md](./GOA
Claimable, well-specified, no decision needed — `/claim`-able. Unordered.
- - [ ] [cos-runner-client-non-json-response-handling] **`cosRunnerClient.js` fetch wrappers — handle non-JSON runner responses.** `spawnAgentViaRunner` and siblings (~`server/services/cosRunnerClient.js:139`) `await response.json()` unconditionally; if the runner returns a 500 HTML error page (e.g. PM2 crash mid-restart) the client crashes with `Unexpected token <` instead of surfacing the runner's actual error. Wrap each parse in `try { JSON.parse(text) } catch { { error: text } }` and propagate the synthesized error so the caller sees a useful message.
+ - [ ] [shared-tolerant-fetch-json-helper] **Extract a shared tolerant `response.text()`→JSON parser and adopt it across the other fetch-based clients.** `cosRunnerClient.js` now reads runner bodies via a local `readRunnerJson` (delegating to `safeJSONParse`) so a non-JSON error page no longer crashes with `Unexpected token <`. The same unguarded `await response.json()` crash risk remains in other fetch-based clients: `server/lib/aiProvider.js` (~146), `server/services/browserService.js` (~111/207/216/269/291), `server/services/memoryEmbeddings.js`, `huggingFaceCatalog.js`, `messageTokenExtractor.js`, `ollamaManager.js`, and `server/lib/aiToolkit/providers.js` (the `.catch(() => ({ data: [] }))` band-aids). Promote a `fetchJsonTolerant(response)` / `readResponseJson(response)` helper (adjacent to `server/lib/fetchWithTimeout.js`, registered in the lib barrel + README) and migrate these call sites. Deferred from the `[cos-runner-client-non-json-response-handling]` PR (out of its stated single-file scope); surfaced by /simplify altitude (2026-06-01).
- [ ] [cos-agent-output-write-amplification] **`appendAgentOutput` write-amplification — already batched via `appendAgentOutputLines`, audit non-runner producers.** CLAUDE.md documents the streaming-producers convention (batched variant + ~250ms debounce + drain on completion); the runner path uses it. Verify every producer that calls `appendAgentOutput` directly (`server/services/cosAgents.js:216`) is human-pace, not a hot loop. If any hot producer is still calling the per-line variant, migrate it. Likely a no-op audit; capture it so the convention doesn't silently drift.
-- [ ] [cos-on-demand-mark-app-review-started-dedupe] **`evaluateTasks` on-demand loop — dedupe `markAppReviewStarted` calls per app.** When multiple on-demand requests for the same app are queued in a single evaluation cycle (`server/services/cos.js:730`), `markAppReviewStarted` is called once per request — wasted state writes. Collect unique `appId`s before the loop and call once. Nit-level priority.
- [ ] [subagent-spawner-top-level-side-effects] **`subAgentSpawner.js` top-level side effects — move init into an explicit `initSpawner()`.** Module-load (`server/services/subAgentSpawner.js:153`) wires event listeners + timers, which interferes with test isolation (each test import re-arms them). Wrap the init block in `export function initSpawner()` and call it from `server/index.js` after dependencies are ready. Treat as a refactor — needs care that no consumer relies on the import-time wiring.
- [ ] [conflict-journal-media-collections] **Conflict journal does not cover media-collection scalar overwrites.** `mergeMediaCollectionsFromSync` (`server/services/mediaCollections.js`) LWW-overwrites scalars (name/description/coverKey/universeId/seriesId) when `remoteWins`; items are union-merged (never lost). v1 hooks only universe + series merges because the whole-record content hash used by `conflictJournal.detectConflict` would false-positive on collections whenever items differ. Doing it right needs scalar-subset hashing that stays consistent with the sender-side base hash. Low value (scalar loss is minor), deferred.
- [ ] [conflict-journal-issues] **Issue-level conflict journaling.** The share-bucket importer hook (`server/services/sharing/importer.js` `applyAutoMerge`→`mergeOne`) is gated to `universe`/`series`; child issues ride LWW silently. Extend the journal to issues (needs the issue merge path to thread a `source` + call `maybeJournalBeforeOverwrite`).