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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: harden chrome canary setup writes
[._.]/ Adam Eivy0b94c3876336
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 38cfd480f3..62cc328903 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -8,4 +8,6 @@## Fixed+- **[chrome-canary-followups] Custom Chrome setup writes browser config through the shared atomic writer.** The Canary setup script now uses `server/lib/fileUtils.js#atomicWrite` for browser-config updates, so it gets the same temp-file/rename behavior and Windows fallback as the rest of PortOS config persistence.+## Removeddiff --git a/PLAN.md b/PLAN.mdindex 195343cae5..428015cb6a 100644--- a/PLAN.md+++ b/PLAN.md@@ -8,8 +8,7 @@ For project goals, see [GOALS.md](./GOALS.md). For completed work, see [.changel2. **[media-job-store-progress-on-job-record]** **mediaJobQueue: persist progress/statusMsg on the job record.** `runJob`'s progress handler in `server/services/mediaJobQueue/index.js` (~line 575) only broadcasts to SSE (`broadcastSse`) — it doesn't mutate the job object. So `GET /api/media-jobs/:id` (used by `MediaJobsQueue.jsx` and any other non-SSE consumer) always reports 0 progress for in-flight jobs. SSE-attached pages don't see this (lastPayload replay), but list-view hydration does. Add `job.progress` + `job.statusMsg` updates inside the dispatcher's `progress` handler. Cross-cutting across image/video/codex paths.3. **[shared-bounded-concurrency-mapper]** **Extract a generic `mapWithConcurrency(items, n, fn)` to `server/lib/` and reuse it.** The worker-pool idiom (cursor + N workers draining a shared array, order-preserving result) is now hand-rolled in THREE places (verified 2026-05-30): `embedBatch` in `server/services/embeddings.js` (~line 158), the mapper in `server/services/catalogExtraction.js` (~line 317), and another in `server/routes/imageVideoModels.js`. A pure `server/lib/` helper would collapse all three onto one tested mechanism (barrel + README row per the maintenance rule).4. **[video-resume-restore-keyframes]** **VideoGen resume: restore keyframes from the active job.** `ACTIVE_JOB_PARAM_FIELDS` in `server/routes/videoGen.js` (~line 739) intentionally omits `keyframes` (gallery filename + frame-index pairs for multi-keyframe FFLF) because the v1 resume effect doesn't repopulate the picker UI for them. A user who reloads mid-render on a keyframe job loses the keyframe-picker state even though every other form field is restored. Whitelist `keyframes` in the route AND wire a `setKeyframes()`-style setter in `client/src/pages/VideoGen.jsx`'s resume effect (~line 507). Independent of the SSE re-attach.-5. **[chrome-canary-followups]** **Hardening for the custom-Chrome-binary feature — remaining low/medium items.** _High-severity (a)–(f) are now DONE (verified 2026-05-30): (a) `browser/server.js` (~line 46) derives `macAppBundle` from `chromePath` on macOS; (b) both `spawn()` calls (~lines 221, 236) have `.on('error', …)` listeners; (d) both `loadConfig`s try/catch `JSON.parse`; (e) `setup-browser.js#loadConfig` warns + returns null and `applyCanaryToConfig` skips the save on unreadable config; (f) top-level `runCanarySetup()` is `.catch()`-wrapped. (c) headless-flag flip is tracked in `[setup-browser-canary-headless]` (now in Backlog with a decision)._ **Remaining low/medium:** (g) idempotency guard only checks `chromePath` — decliners + `macAppBundle`-only users get re-prompted every update; (h) `PORTOS_USE_CANARY` only matches literal `0/false/1/true` — `no/off/yes/on/True` fall through both branches; (i) `spawnSync(install.cmd, …, { stdio: 'inherit' })` for brew/winget can hang on a sudo prompt under non-TTY + `PORTOS_USE_CANARY=1`; (j) `cachedConfig` in `browserService.js` is stale relative to setup-browser's direct write (GET /api/browser/config returns pre-update values until process restart); (k) `saveConfig` uses bare `writeFileSync` — switch to the canonical `atomicWrite` (`server/lib/fileUtils.js`); (l) `spawnSync` status check treats `status: null` (spawn-failure/signal) like a non-zero exit and never logs `result.error`; (m) `optionalPath` Zod schema has no `.app`/`.exe` sanity check; (n) `launchBrowser`'s reuse-existing-Chrome early-return fires BEFORE `headlessMode` is set (wrong /health mode after a PM2 restart that reuses Chrome); (o) `detectCanary` on macOS only checks `/Applications/...` and misses per-user `~/Applications` installs.-6. **[ref-watch-phosphene-teacache-extend-a2v-denoise]** **TeaCache through Extend + A2V Stage-1 denoise loops.** From `reference-watch` review of phosphene (commits `ea98aad8` + `17be2a79`, 2026-05-28). PortOS's `scripts/generate_ltx2.py` invokes `ExtendPipeline.extend_from_video(...)` (~line 378) and `AudioToVideoPipeline.generate_and_save(...)` (~line 417) directly without passing a TeaCache controller, so the slowest two modes in the panel run full denoise. Phosphene reuses the existing Stage-1 calibration (`ti2vid_two_stages._build_teacache_controller(n_steps, thresh=0.5)`) by monkey-patching `guided_denoise_loop` on the `ltx_pipelines_mlx.retake` and `ltx_pipelines_mlx.a2vid_two_stage` modules, gating activation on a per-call module-level config dict, set before the pipeline call and cleared in `finally`. Predicted ~1.2× on extend at default threshold (up to ~3× at 1.5); similar for A2V Stage 1. Fix: install both monkey-patches at the top of `generate_ltx2.py`, wire `_EXTEND_TC_CONFIG` / `_A2V_TC_CONFIG` from the helper's `run_extend`/`run_a2v` paths, and add a `--no-teacache` CLI flag (default-on). **Decision (resolved 2026-05-30): land independently** against today's pin — the calibration helper `_build_teacache_controller` already exists at the current pin, so there's no need to couple this to the risky rename in `[ref-watch-phosphene-bump-ltx2-pin-v0148]`. Scope: small/medium.+5. **[ref-watch-phosphene-teacache-extend-a2v-denoise]** **TeaCache through Extend + A2V Stage-1 denoise loops.** From `reference-watch` review of phosphene (commits `ea98aad8` + `17be2a79`, 2026-05-28). PortOS's `scripts/generate_ltx2.py` invokes `ExtendPipeline.extend_from_video(...)` (~line 378) and `AudioToVideoPipeline.generate_and_save(...)` (~line 417) directly without passing a TeaCache controller, so the slowest two modes in the panel run full denoise. Phosphene reuses the existing Stage-1 calibration (`ti2vid_two_stages._build_teacache_controller(n_steps, thresh=0.5)`) by monkey-patching `guided_denoise_loop` on the `ltx_pipelines_mlx.retake` and `ltx_pipelines_mlx.a2vid_two_stage` modules, gating activation on a per-call module-level config dict, set before the pipeline call and cleared in `finally`. Predicted ~1.2× on extend at default threshold (up to ~3× at 1.5); similar for A2V Stage 1. Fix: install both monkey-patches at the top of `generate_ltx2.py`, wire `_EXTEND_TC_CONFIG` / `_A2V_TC_CONFIG` from the helper's `run_extend`/`run_a2v` paths, and add a `--no-teacache` CLI flag (default-on). **Decision (resolved 2026-05-30): land independently** against today's pin — the calibration helper `_build_teacache_controller` already exists at the current pin, so there's no need to couple this to the risky rename in `[ref-watch-phosphene-bump-ltx2-pin-v0148]`. Scope: small/medium.## Backlogdiff --git a/scripts/setup-browser.js b/scripts/setup-browser.jsindex aaf4cd8b82..3d2169b158 100644--- a/scripts/setup-browser.js+++ b/scripts/setup-browser.js@@ -20,13 +20,13 @@*/import { execFileSync, spawnSync } from 'child_process';-import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'fs';+import { existsSync, mkdirSync, readFileSync } from 'fs';import { createInterface } from 'readline';import { dirname, join } from 'path';import { fileURLToPath } from 'url';import { homedir, platform } from 'os';-import { randomUUID } from 'crypto';import { hasConfiguredBrowser, normalizeBrowserConfig } from '../server/lib/browserConfig.js';+import { atomicWrite } from '../server/lib/fileUtils.js';const __dirname = dirname(fileURLToPath(import.meta.url));const rootDir = join(__dirname, '..');@@ -53,16 +53,8 @@ function loadConfig() {}}-function saveConfig(config) {- if (!existsSync(dataDir)) mkdirSync(dataDir, { recursive: true });- const tmp = `${configFile}.${process.pid}.${Date.now()}.${randomUUID()}.tmp`;- writeFileSync(tmp, `${JSON.stringify(normalizeBrowserConfig(config), null, 2)}\n`);- try {- renameSync(tmp, configFile);- } catch (err) {- try { unlinkSync(tmp); } catch {}- throw err;- }+async function saveConfig(config) {+ await atomicWrite(configFile, `${JSON.stringify(normalizeBrowserConfig(config), null, 2)}\n`);}function hasCommand(cmd, args) {@@ -102,7 +94,7 @@ function canaryInstallCommand() {return null;}-function applyCanaryToConfig(found) {+async function applyCanaryToConfig(found) {const config = loadConfig();if (config === null) {console.warn(' Skipping Canary config write — fix the corrupt browser-config.json first.');@@ -111,18 +103,18 @@ function applyCanaryToConfig(found) {config.chromePath = found.bin;if (found.app) config.macAppBundle = found.app;delete config.canaryPromptDeclined;- saveConfig(config);+ await saveConfig(config);console.log(`✅ PortOS browser set to Chrome Canary → ${found.bin}`);}-function markCanaryDeclined() {+async function markCanaryDeclined() {const config = loadConfig();if (config === null) {console.warn(' Skipping Canary preference write — fix the corrupt browser-config.json first.');return;}config.canaryPromptDeclined = true;- saveConfig(config);+ await saveConfig(config);}function parseCanaryEnv(value) {@@ -185,9 +177,9 @@ async function runCanarySetup() {if (found) {const ok = envOptIn ? true : await promptYesNo('Chrome Canary detected. Use it as the PortOS-managed browser?', true);- if (ok) applyCanaryToConfig(found);+ if (ok) await applyCanaryToConfig(found);else {- markCanaryDeclined();+ await markCanaryDeclined();console.log(' Keeping the platform-default Chrome. You can switch later in Settings → Browser.');}return;@@ -207,7 +199,7 @@ async function runCanarySetup() {const ok = envOptIn ? true : await promptYesNo(`Install Chrome Canary via ${install.label} and use it as the PortOS-managed browser?`, true);if (!ok) {- markCanaryDeclined();+ await markCanaryDeclined();console.log(' Keeping the platform-default Chrome. You can switch later in Settings → Browser.');return;}@@ -222,7 +214,7 @@ async function runCanarySetup() {}const reFound = detectCanary();- if (reFound) applyCanaryToConfig(reFound);+ if (reFound) await applyCanaryToConfig(reFound);else console.log('⚠️ Canary installed but the binary was not found at the expected path. You can set chromePath manually in Settings → Browser.');}