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 #2635 from atomantic/claim/issue-2626

[._.]/ Adam Eivy1ef76c04f503
diff --cc .changelog/NEXT.md
index 4624898cff,fdd6ddf6fe..0baa4446ee
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@@ -92,8 -83,5 +92,9 @@@
- **[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.
- **[issue-2554] Align CoS chrome and scrollbar colors with port design tokens.** The Chief of Staff panel chrome hardcoded `bg-slate-900/60`, `hover:bg-slate-800/80`, the `from-slate-900/80 to-slate-900/40` gradients, and `text-slate-400` — a `slate` surface that ignored the active theme. Those now map to `bg-port-card`/`hover:bg-port-border`/`text-port-text-muted` (the collapse button's `text-gray-500 hover:text-white` also became `text-port-text-muted hover:text-port-text` so its icon stays legible in light themes), so the panel restyles with the selected theme. The global `::-webkit-scrollbar-thumb` (and its `:hover`) dropped their hardcoded `#3a3a3a`/`#4a4a4a` for the opaque, theme-derived `rgb(var(--port-text-muted))` and `rgb(var(--port-text))` — colors that stay high-contrast against the already-tokenized `rgb(var(--port-card))` track in both dark and light themes (an alpha-over-track blend would wash out on light cards, so the opaque muted-text token is used). The unread-count badges in `Layout.jsx` (four sites) and `NotificationDropdown.jsx` swapped `bg-yellow-500 text-black` for `bg-port-warning text-port-on-warning`; the Dashboard server-health glow's `shadow-[0_0_8px_#22c55e]`/`#ef4444` now reference `rgb(var(--port-success))`/`rgb(var(--port-error))`. The Ambient full-screen idle display is intentionally left on its fixed deep-black `bg-[#050505]` (with `text-white` content) — it is a theme-independent ambient/OLED surface, and making the backdrop theme-following would strand its non-tokenized white clock and translucent panels invisibly on light themes. Visual-only token swaps — no logic or layout change; the retokenized surfaces now follow the active theme instead of a fixed palette.
+ - **[issue-2626] Raise `bg-port-warning` / `text-port-on-warning` contrast to WCAG AA in day themes.** Two `mode: 'day'` themes paired an amber `--port-warning` with white `--port-on-warning`, dropping the ~180 warning surfaces (buttons, chips, unread-count badges) below the 4.5:1 AA threshold for small text — `lumen-glass-day` (#ca8a04 on white ≈ 2.94:1) and `black-ice-terminal-day` (#aa6e00 on white ≈ 4.25:1). Both now use black `--port-on-warning` at the theme-token layer (`0 0 0`), lifting them to ~7.15:1 and ~4.94:1 respectively; the other two amber day themes (`classic-noon`, `blueprint-ops-day`) already cleared AA at ~5.02:1 on white and were left unchanged. A new `client/src/themes/portosThemes.test.js` computes the WCAG contrast ratio for the warning pair of every theme and asserts ≥4.5:1, so a future theme can't regress the pairing.
+- **[issue-2616] Add type-level consecutive-failure backoff with auto-park + notification; count unparseable agent output as failure.** The agent engine had no failure memory at the task-*type* level, so a permanently-broken scheduled type (or one whose instances all fail) re-queued on schedule forever — burning provider quota with no backoff, auto-disable, or notification (`failureCount` lived only in per-instance metadata; ROTATION types had no cadence gate at all, returning `shouldRun: true` unconditionally). A new per-type failure ledger now lives on the schedule execution record (`consecutiveFailures`/`lastFailureAt`/`lastErrorCategory`, per app + global) — persisted alongside `lastRun`, so it survives restarts as per-install runtime state (additive, backward-compatible, never synced). `shouldRunTask` applies an escalating failure cooldown (`2^n × base`, capped at a day) to *all* cadence types including ROTATION, so a failing type slows down instead of re-queuing every tick; after 5 consecutive failures the type auto-parks (indefinitely, for every cadence type) and fires a user-facing `AGENT_WARNING` notification naming the type, app, and last error category. A success resets the counter and lifts the park; a manual "Run now" or a config change (`updateTaskInterval`) clears the ledger to unpark. Separately, an LLM run that exits 0 but whose `.agent-done` output is unparseable — previously recorded as a benign completed success, invisible to any failure accounting — now feeds a failure signal into the ledger via the pure `resolveTypeFailureSignal` (an `unparseable-response` hook reason, or a thrown output hook, counts as a failure regardless of exit code; benign hook reasons like `no-proposal`/`duplicate` defer to the exit code). The existing per-instance retry ladder (`MAX_TASK_RETRIES`/`MAX_TOTAL_SPAWNS`) is unchanged. New unit tests cover the backoff math, ledger increment/reset/auto-park/notify/unpark, the ROTATION cooldown/park gates, and the unparseable-as-failure decision.
+- **[issue-2535] Paginate the creative-catalog + media list endpoints with the shared `paginateArray` helper.** The primary index `GET`s for creativeDirector (`/`), storyBuilder (`/`), universeBuilder (`/`), moodBoard (`/`), videoTimeline (`/projects`), and loras (`/`) returned unbounded arrays. Each now opts into pagination the moment a client sends `limit`/`offset`, mirroring the `brainCrud` precedent: `isPaginationRequested(req.query)` gates a bounded `{ items, total, limit, offset }` envelope (via the existing `paginateArray` in `server/lib/validation.js`, `defaultLimit: 50`, `maxLimit: 500`), while a request with no pagination params still returns the full array byte-for-byte — so every current client (none of which pass those params to these routes) is unaffected and no client change is required. New route tests assert both the default array and the paginated envelope for each domain (moodBoard gains its first route test). Refs #2535 — CoS tasks (the `?full=1` default-paginated slice) already shipped; privacy vault/orgs/changes/brokers and digital-twin documents remain.
+- **[issue-2535] Paginate the remaining privacy + digital-twin list endpoints, completing the sweep.** The last unbounded index `GET`s flagged by #2535 — privacy `/vault`, `/orgs`, `/changes`, `/brokers`, `/broker-cases`, and digital-twin `/documents` — now opt into the shared `paginateArray` envelope exactly like the creative-catalog routes shipped in #2636: `isPaginationRequested(req.query)` gates a bounded `{ items, total, limit, offset }` response (`defaultLimit: 50`, `maxLimit: 500`) the moment a client passes `limit`/`offset`, while a param-less request returns the full array byte-for-byte, so no client change is required. Because the four privacy list-query schemas are `.strict()` (they'd reject unknown keys), a local `paginationQueryFields` fragment (`limit`/`offset` as passthrough strings — `parsePagination` does the parse+clamp) is spread into `privacyVaultListQuerySchema`, `privacyOrgListQuerySchema`, `privacyBrokerListQuerySchema`, and `privacyBrokerCaseListQuerySchema` in `privacyValidation.js`; the `/orgs` handler strips `limit`/`offset` before passing filters to `listOrgs` so pagination never leaks into the service query. New route tests cover the vault/orgs/changes/broker-cases envelopes (filters preserved) and the digital-twin documents envelope. This closes the remaining slice of #2535 (the CoS-tasks default-paginated shape and the creative-catalog/media routes shipped previously).
+- **[issue-2642] Require provider/runner provenance before excluding environmental failures from task learning.** Environmental-failure exclusion previously trusted `errorAnalysis.category` alone, but that category is produced by the `analyzeAgentFailure` regex sweep over the failed agent's output tail — so ordinary task output could be misclassified as an infra category (e.g. a failing test whose tail prints "rate limit" tripping the unscoped `/rate.?limit/`) and the run would be silently diverted out of the learning aggregates as an "outage." `analyzeAgentFailure` now stamps an `origin` provenance marker on every classification: `'provider'`/`'runner'` when the match carries a genuine structured signal (an `API Error: NNN` line, a Node error code like `ECONNREFUSED`, a provider token like `overloaded_error`/`not_found_error`, or the structural startup-failure), and `'output-scan'` when it comes only from a loose keyword alternative. Mixed patterns (e.g. `API Error: 429` vs a bare `rate limit`) gate the promotion through a per-pattern `structuredMarker` sub-pattern via the new pure `resolvePatternOrigin` helper. The exclusion gate in `recordTaskCompletion` (`server/services/taskLearning/metrics.js`) now runs through a pure `shouldDivertToEnvironmental(outcomeSuccess, category, origin)` that additionally requires `origin !== 'output-scan'`, so an output-scan false positive counts as a genuine failure while structured signals stay excluded. Back-compat is preserved: an `errorAnalysis` with no `origin` (older records / federated peers) keeps the category-only behavior, and the routing-side signature filter is unchanged (it already fails safe). New unit tests cover the provenance stamping across the classifiers and all three acceptance cases in the gate.