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

Merge remote-tracking branch 'origin/main' into claim/shared-tolerant-fetch-json-helper

[._.]/ Adam Eivy17a8c7775654
diff --cc .changelog/NEXT.md
index 45e37bcfeb,7c455b4837..3f7bc908cf
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@@ -34,7 -34,8 +34,9 @@@
- **[data-versioning-centralize-cosagents-settings] Saving settings is now crash-safe and serialized.** `settings.json` is written through the shared atomic temp-file/rename writer and overlapping saves run one at a time, so a mid-write crash can no longer truncate the file and two near-simultaneous settings changes can no longer clobber each other (no user-facing change).
- **[setup-data-import-drift-tables-from-migrations]** The setup script's "a prompt migration is pending" warning now derives its hash tables directly from the migration files instead of a hand-maintained copy, so the warning can't silently fall out of sync when a new prompt migration ships (no user-facing change).
- **[cos-on-demand-mark-app-review-started-dedupe]** When several on-demand improvement requests for the same app are processed in one CoS dispatch cycle, the app's activity record is now marked review-started once instead of once per request (no user-facing change).
+- **[shared-tolerant-fetch-json-helper]** Hardened the HTTP clients that talk to local model backends, the managed browser, and the background agent runner: a non-JSON/HTML error response now surfaces the real error instead of crashing with "Unexpected token <", via one shared tolerant JSON-body reader (no user-facing change).
+ - **[cos-agent-output-write-amplification] Streamed CoS agent output no longer rewrites the entire agent-state file once per line.** A shared ~250ms output batcher now coalesces the runner's per-line output events and direct-CLI stdout/stderr into single state writes (draining before an agent is marked complete), cutting agent-state write churn on chatty agents from dozens of writes/sec to a few — with no change to the live output tail (no user-facing change).
+ - **[subagent-spawner-top-level-side-effects]** The CoS agent spawner now initializes explicitly at server startup instead of as a side effect of being imported, so importing it (in tests or elsewhere) no longer re-arms its event listeners and timers (no user-facing change).
## Fixed
diff --cc PLAN.md
index 2155a48845,3cbbe8ff31..98ac04720f
--- a/PLAN.md
+++ b/PLAN.md
@@@ -6,9 -6,7 +6,7 @@@ For project goals, see [GOALS.md](./GOA
Claimable, well-specified, no decision needed — `/claim`-able. Unordered.
-- [ ] [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).
+- [ ] [tolerant-fetch-json-additional-clients] **Adopt the shared `readResponseJson` helper in the remaining fetch-based clients.** The `[shared-tolerant-fetch-json-helper]` PR promoted `server/lib/readResponseJson.js` and migrated the originally-scoped clients, but a reuse-review sweep surfaced more fetch-based clients with the same unguarded `await response.json()` crash risk (an HTML/non-JSON error body throws `Unexpected token <`): `server/services/memoryClassifier.js:274`, `server/services/calendarApiSync.js:96`, `server/services/messageApiSync.js:74`, `server/services/insightsService.js:197`, `server/services/localLlmPlayground.js:114`, `server/lib/civitai.js:209` and `:347`, and `server/lib/telegramClient.js:31` and `:59` (all unguarded), plus `server/services/codeReview.js:166` which currently uses a `.catch(() => null)` band-aid that silently swallows the real error. Migrate each to `readResponseJson(response)` (object callers) with `{ fallback: [] }` for array endpoints; for `codeReview.js`, decide whether to surface the error text via the function-fallback form. Deferred out of the helper PR to keep it within its stated single-file-list scope. Surfaced by /simplify reuse review + the multi-reviewer pass on PR #614 (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.
- - [ ] [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`).
- [ ] [conflict-journal-deep-diff] **`diffSummary` is top-level shallow only.** `conflictJournal.diffSummary` compares top-level fields via canonicalStringify, so the UI shows "categories differ" rather than which variation/canon entry changed. Add per-field deep diffing for richer InlineDiff rendering in the Conflicts tab.