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 next/issue-2620

[._.]/ Adam Eivy3f02e3cbab21
diff --cc .changelog/NEXT.md
index 92e53cacff,095bce0443..12a7f367e9
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@@ -2,7 -2,8 +2,10 @@@
## CoS self-learning reliability
+- **[issue-2620] Layered Intelligence stops re-proposing finished work** — completed plan items stay recognized as done, and proposal outcomes now distinguish merged, rejected, and abandoned instead of counting every closed issue as merged.
++- **[issue-2617] Task learning forgives fixed problems** — scheduling, model-routing, and self-diagnostics decisions now weigh recent runs instead of lifetime totals, so a task type recovers as soon as it starts succeeding again.
+ - **[issue-2615] One investigation per failure cause, not one per failure** — repeated agent failures now dedupe into a single investigation task, with an hourly cap and no investigations-of-investigations.
+ - **[issue-2621] Feature brainstorming remembers rejected ideas** — the feature-ideas task now checks REJECTED.md and previously closed-unmerged proposals before suggesting, so declined ideas stop coming back.
## Added
@@@ -71,5 -77,10 +79,7 @@@
- **[issue-2532] Extract the Shell page's socket/session/terminal lifecycle into a `useShellSession` hook.** `pages/Shell.jsx` inlined ~750 lines of xterm setup, the Socket.IO `shell:*` protocol, and the single-subscriber PTY attach/detach contract (the `pendingAttachRef {target,generation}` guards, `claim`-vs-user-intent handling, `userIdleRef` passive-idle gating, `mountedRef` deferred-work guards, and URL sync). That cohesive concern now lives in `client/src/hooks/useShellSession.js` — which documents the full attach/detach contract at the top of the file — and the route drops to a thin presentational shell (header, quick-commands, terminal container) plus two extracted panels, `components/shell/TerminalHotKeys.jsx` and `components/shell/ShellSessionTabs.jsx`. Pure structural refactor toward the WritersRoom pattern — behavior identical, generation guards preserved byte-for-byte, no route-contract change; lint, the hooks barrel test, and the client build stay green.
- **[issue-2580] Await the canvas draw assertions in `MidiVisualization.test.jsx` to fix a CI flake.** The "paints the roll" test `await`ed the footer text (`findByText(/3 notes · /)`) then *synchronously* asserted `expect(ctx.fill).toHaveBeenCalled()`, but the roll paints in the `<MidiPianoRoll>` child a tick after the footer text commits — so CI intermittently landed the paint one tick late and the assertion failed. That draw assertion (and the zoom-controls `ctx.clearRect` assertion, which followed the fit/zoom button clicks) are now wrapped in `waitFor(...)` so they wait for the draw deterministically. Audited the sibling songs canvas tests (`PianoRoll`, `MidiPianoRoll`, `Metronome`, `RoundStack`, `PitchTuner`, `SingToScore`, `SongTraining`, `ReferenceAnalysis`, `SongRecordings`): only `MidiVisualization` gates its paint behind async data loading, so it was the only racy one — `PianoRoll`/`MidiPianoRoll` assert after a synchronous `render()`/`pump()` (no text-`findBy` gap), and the rest have no canvas assertions. Test-only; each test keeps its own explicit `getContext` mock.
- **[issue-2541] Add a wall-clock timeout to the AI toolkit's API runner so a hung provider can't leak `activeRuns`.** `runner.js#executeApiRun` attached an `AbortController` but armed no timer, so an upstream that opened the SSE stream then stalled (or never responded) held its controller in `activeRuns` — and thus the run slot — indefinitely; the CLI path (`executeCliRun`) already had an internal timeout, and the Runs-router path invoked the API runner with no outer guard. `executeApiRun` now accepts an optional `timeout` (falling back to `provider.timeout` then a 300s default, mirroring `aiProvider`/`askService`) and arms it before the fetch. A single-settlement gate (`markSettled()`) guarantees exactly one of {timer, response paths} finalizes the run: on timeout the timer aborts the fetch/reader AND independently finalizes the run as an `ERROR_CATEGORIES.TIMEOUT` failure — so a stalled fetch/stream, a provider that never responds, and even a `ensureProviderReady` hook that never reaches the fetch are all bounded, and the failure is recorded as a timeout instead of the raw AbortError's `UNKNOWN`/HTTP 0. Both the Runs router and `promptRunner` now thread their `effectiveTimeout` into the API call (parity with the CLI/TUI branches), so a per-call override — e.g. the importer's long stage timeout — governs the ceiling instead of being cut short by the provider/default fallback; `promptRunner`'s own timer is demoted to a delayed backstop so the runner's timeout wins classification. The non-2xx error-body read now runs with the abort timer still armed (a provider that sends error headers then stalls the body is cancelled, not hung), and the success-path finalization-failure fallback rebuilds metadata from the stored record so run identity survives a write error. New unit tests prove both a hung stream and a hung readiness hook flip `isRunActive` back to false and complete with `errorCategory: 'timeout'`.
+ - **[issue-2533] Split the ~990-line `server/routes/digital-twin.js` flat router into a `digital-twin/` sub-router directory (mirroring the apps/pipeline layout).** The single multi-domain file is now an assembled `index.js` mounting thirteen domain sub-routers at the same `/api/digital-twin` base — `status`, `documents`, `tests` (behavioral/values-alignment/adversarial/multi-turn suites + generate), `enrichment`, `export`, `settings`, `personas`, `analysis` (validate/writing-style/identity-image/traits/confidence/gaps/assessment), `import`, `feedback`, `taste`, `snapshots`, and `evidence` — with the shared `assertPersonaExists` guard extracted to `digital-twin/shared.js`. The route contract is byte-for-byte unchanged: all 73 endpoints keep their exact method+path, Zod validation, and `ServerError` status mapping, and the order-sensitive pairs (`/personas/active` before `/personas/:id`; `/taste/sections` before `/taste/:section/...`) each live entirely within one file so mount order is irrelevant. The route test moved into the directory as `digital-twin/index.test.js` (21 cases green). Completes the last remaining slice of #2533 (the imageGen setup, apps-list enrichment, and `buildJiraTicketTask` extractions shipped earlier in #2600/#2589).
- **[issue-2553] Size four viewport-height surfaces with `100dvh` (vh fallback) so iOS Safari chrome no longer clips them.** MediaLightbox's fullscreen image (`max-h-[100vh]`), the CollectionPicker popover (`min(360px, calc(100vh - 16px))`), the Layout sidebar flyout (`calc(100vh - 16px)`), and the ChiefOfStaff avatar panel/canvas caps (`min(460px|620px, calc(100vh - 1rem))`) all measured against `100vh`, which iOS Safari inflates by the retractable browser-chrome height — so each spilled under the chrome. New parametrized `max-h-dvh-cap`/`min-h-dvh-cap`/`h-dvh-cap` `@utility` classes in `index.css` size to `100dvh` (the visible dynamic viewport) with a `100vh` fallback gated behind `@supports (height: 1dvh)` — the two-declaration idiom `.h-dvh-screen` uses does not work once the value is wrapped in `var()`/`min()`/`calc()` (both declarations become valid-at-parse-time, so the `dvh` one wins the cascade then computes to invalid rather than restoring the `vh` line), so the `vh` value is the unconditional base and the `dvh` value overrides only where supported. A `--dvh-cap` upper bound and `--dvh-inset` subtracted margin (set per-surface, and per-breakpoint via arbitrary-property utilities for the responsive CoS caps) let one utility serve the plain, capped, and inset variants; the CoS panel keeps its fixed `min-h-[180px]`/`190px` at base/sm/md and only switches to the dvh cap at `lg:`/`xl:`, where the original used a viewport unit. Behavior is byte-identical on engines that predate `dvh`; on iOS Safari the surfaces now stay within the visible viewport.
- **[issue-2548] Replace the vacuous agentLifecycle spawn/completion replica tests with imports of real guard helpers.** `agentLifecycle.test.js` re-implemented production logic — local `unfixedSpawn`/`fixedSpawn` copies of the `spawningTasks` dedup flow and a `runCompletion`/`makeCompletionHarness` copy of the completion try/finally — and never imported `spawnAgentForTask`/`handleAgentCompletion`, so they stayed green when production regressed. The two concurrency contracts those replicas modelled are now extracted into `server/services/agentGuards.js`: `withSpawnDedupGuard(spawningTasks, taskId, fn)` (acquire-before-first-await, hold across the whole spawn body incl. the runner-enqueue handoff, release in `finally`, `SPAWN_DEDUP_SKIP` on a concurrent duplicate) and `withMapEntryCleanup(map, key, fn)` (delete the `runnerAgents` entry in `finally` even when a completion step throws). `spawnAgentForTask` now wraps `runAgentSpawn` in the former (dropping six inline `spawningTasks.delete` sites), and `handleAgentCompletion` wraps its body in the latter — so the tests drive the exact code production runs. The late-delete race that spawned a second agent for the same task id is now a behavioral test against the real guard, not a hand-copied one; the remaining source-scan tests were trimmed to non-negotiable orderings (the handedOff pre-spawn/post-handoff split, the #1563 claim/register ordering, the #989 marker release, the #2243 runner env merge) plus two wiring guards that pin the delegation. `cos.test.js` already drove the real `createDequeueCapacity`/`isMissionTierEligible`/`isIdleTierEligible` exports after #2530, so it was left as-is. New `agentGuards.test.js` unit-tests both helpers in isolation.
+
-## CoS self-learning reliability
-
-- **[issue-2617] Task learning forgives fixed problems** — scheduling, model-routing, and self-diagnostics decisions now weigh recent runs instead of lifetime totals, so a task type recovers as soon as it starts succeeding again.