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 pull request #2596 from atomantic/claim/issue-2539

[._.]/ Adam Eivycfad5866b117
diff --cc .changelog/NEXT.md
index 909fe8e78e,e7e541a554..d9045b2a6e
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@@ -55,5 -55,5 +55,6 @@@
- **[issue-2527] Route client localStorage and keyboard activation through the shared `safeStorage`/`a11yKeyboard` helpers.** Several client sites bypassed the guarded `safeStorage` helpers with raw `window.localStorage` + hand-rolled `try/catch` (or `typeof window` guards), and several non-`<button>` clickables reimplemented the Enter/Space `onKeyDown` handler inline. Storage reads/writes in `Security.jsx`, `PipelineManuscriptEditor.jsx`, `voiceVisibility.js`, `MortalLoomBanner.jsx`, `WhileAwayWidget.jsx`, and `ManuscriptReadAloud.jsx` now go through `safeReadStorage`/`safeReadJsonStorage`/`safeWriteStorage`/`safeRemoveStorage`; keyboard activation in `IngredientPicker.jsx`, `ManuscriptReadAloud.jsx`, `EditorialHealthPanel.jsx`, `TribeCircleMap.jsx`, and `GenomeTab.jsx` now spreads `clickableProps(handler)` (which supplies `role`/`tabIndex`/`onKeyDown` via the shared `onActivateKeyDown`). Behavior is preserved — same storage keys, same JSON-parse fallbacks and corrupt-entry cleanup, same Enter/Space activation.
- **[issue-2532] Extract the Universe Builder's page-level lightbox into a `useUniverseGallery` hook.** `UniverseBuilder.jsx` inlined ~160 lines of gallery/preview plumbing — the filename→image-sidecar metadata map, the `listImageGallery()` refetch effect (keyed on `runs.length` + a per-job-completion bump), the `previewItems` derivation across variations/composite sheets/style probes/canon+character-sheet refs (namespaced-key dedupe), and the `usePreviewRoute`/`useMediaPreviewActions`/`useMediaAnnotations` wiring. That cohesive concern now lives in `client/src/hooks/useUniverseGallery.js` (takes `{ draft, runsLength }`, returns `{ previewItems, preview, setPreview, previewActions, openPreviewByFilename, openVariationPreview, annotations, updateAnnotation, bumpGalleryRefresh }`), thinning the page shell toward the WritersRoom pattern. Pure structural refactor — behavior identical, no route-contract change; the UniverseBuilder page suite and hooks barrel test stay green. Further hook/panel extractions (draft/expand/canon/bulk-render for UniverseBuilder, `useShellSession` for Shell) remain.
- **[issue-2545] Add `aria-label`s to icon-only controls and fix Templates/MessageDetail form labels.** Several icon-only buttons exposed their purpose only via `title` (unreliable for screen readers): the MessageDetail toolbar (Reply, voice-mode toggle, AI Reply, Refresh, Archive, Delete), MusicVideo scene move-up/move-down/delete, MediaCard hide/delete, the MediaJobsQueue per-job cancel, Review's edit save/cancel, and DuplicateGroup rename now carry an `aria-label` matching their `title`. The MessageDetail reply `<textarea>` (previously placeholder-only) gains an `aria-label`, and the Templates "Target Directory" `<label>` is now wired to its input via `htmlFor`/`id` so click-to-focus and screen readers work. Accessibility attributes only — no behavior or styling change.
+- **[issue-2542] Fix VideoGen busy-retry timer cleanup and FeatureAgentDetail load race.** The VideoGen queue worker's BUSY-backoff `setTimeout` was a local `let busyRetryTimer` assigned inside an async `.catch`, so the effect's own cleanup (consumed on every `setQueue`/`setRunningQueueId` re-run before the timer was ever assigned) couldn't clear it — an unmount during the 1.5s backoff, or a newer dispatch, could still fire `setRunningQueueId` on a torn-down component or steal a slot a newer item owned. The timer now lives on a `useRef`, is cleared by a dedicated unmount cleanup, and every deferred `then`/`catch`/`finally` (and the timer callback) is gated by a per-dispatch generation token plus a `mountedRef` so stale callbacks bail. Separately, `FeatureAgentDetail`'s `getFeatureAgent(id)` load had no stale guard, so an A→B navigation whose A response resolved late could paint the wrong agent; the load is now sequence-tokened (late/stale results ignored) with a `mountedRef` guard, and an A→B switch clears to the spinner immediately instead of flashing the previous agent.
- **[issue-2533] Extract JIRA-ticket claim assembly out of the route into `buildJiraTicketTask` (next to `buildClaimWorkTask`).** `POST /api/cos/tasks/jira-ticket` (the sprint-board per-card play button) inlined its reviewer-CSV resolution (`resolveClaimReviewersCsv`), the target-ticket constraint block (`buildTargetTicketBlock`), and the `claim-issue-jira` prompt assembly directly in `server/routes/cosTaskRoutes.js`. That logic now lives in `server/services/cosTaskGenerator.js` as an exported `buildJiraTicketTask(app, ticketKey)` that returns `{ ticketKey, prompt, taskMetadata }` — beside `buildClaimWorkTask`, sharing the same reviewer/isolation conventions. The route stays thin: validate → JIRA-enabled gate → assemble → queue. Pure refactor — the queued task's context, description, and `useWorktree/openPR` posture are byte-for-byte unchanged; new unit tests cover the extracted assembly.
+ - **[issue-2539] Serialize `createCachedStore` and `backup.saveState` writes; bound the rate-limit state maps.** `createCachedStore` now runs every write through an internal single-tail `createFileWriteQueue` and exposes a `mutate(fn)` primitive that serializes the whole `load → modify → persist` cycle, so two concurrent read-modify-write paths can no longer clobber each other; the feeds, social-accounts, platform-accounts, agent-personalities, and automation-scheduler services were migrated off the racy `load()` + `save()` pair onto `mutate()`. `backup.saveState` gained the same promise-tail so a run completing while the scheduler stamps a status can't lose fields. The moltbook/moltworld rate-limiters, which kept one in-memory state entry per API key / agent id forever, now store it in a new bounded `createBoundedStateMap({ maxSize, ttlMs })` helper (`server/lib/boundedStateMap.js`) that lazily evicts idle (TTL) and least-recently-used (LRU) entries. (The idle pipeline `writeQueues` pruning called for by the issue already shipped via `createKeyedFileWriteQueue`/`createKeyCachedQueue` in #2528/#2524.) Behavior is otherwise unchanged; new unit tests cover the serialized `mutate`, the bounded map, and the rate-limiter.