Add the perf governor (ease motion, never blur) and gate 60fps on the reference laptop #63

Description

@kateebonner

Important

Problem

The Chat's expensive combination — high-radius backdrop-blur recomputed per frame across many glass cards over an animating Brain, while scrolling — can blow the 60fps budget on a real laptop webview (see #56 for the why). This slice builds the pre-agreed release valve and proves the budget actually holds on real hardware.

Approach

Add a frame-time governor that observes the single Brain render loop and, only under sustained over-budget load, eases the Brain's motion stepwise (dual-guard hysteresis before restoring, so it never oscillates) down to a full motion stop, then — if that still misses budget — hard-pauses to a static blurred field as the terminal valve. It never touches blur or tint: motion is the only give. The release criterion is a manual 60fps sign-off on the pinned reference laptop webview; a headless-Chromium rAF-interval trace is a pre-gate proxy only. HITL because only a human on the reference machine can close the gate.

Scope

In: the frame-time monitor + motion-ease governor (trip, ease ladder, hysteresis restore, terminal hard-pause); the paused-loop measurement guard (no phantom over-budget when the engine is paused); the blur/tint-never-degraded invariant; a dev force-full-tempo hook (pins full tempo AND disables the governor); a headless-Chromium rAF-trace proxy harness over a long-thread fixture, both themes; the manual perf-gate checklist + sign-off on the reference laptop, both themes.
Out: reducing blur radius or tint under load (the frosted look is the protected aesthetic; motion is the only give); dynamic per-frame backdrop sampling / adaptive-contrast glass (rejected in #56 as the biggest perf risk); the glass tokens and the motion engine themselves (owned by the glassed-components and full-motion slices; this slice only steers and protects them); node-cap / recency bounds and occluded-Panel paint-skipping (separate perf levers on the motion slice, not the release valve); any automated or CI substitute for the reference-laptop run (the gate is a deliberate manual sign-off).


Acceptance Criteria

  • Trip + ease ladder: fed a frame-time sequence whose rolling p95 exceeds the 16.7ms budget continuously for a full sustained trip window, the governor steps the Brain's motion down one ease level (lower tempo); continued over-budget steps it further, down to a full motion stop. Below-budget input never triggers a step-down.
  • Terminal valve: with motion already at a full stop and p95 still over budget for the sustained window, the governor hard-pauses the render loop to a static blurred field; it never steps past full-stop into any state that keeps painting motion.
  • Hysteresis / no oscillation: on a frame sequence that hovers at the budget boundary (alternating just-over / just-under across windows), the governor does not change motion level every window; restoring one level up requires p95 to stay at or below the restore threshold (a fixed margin below budget) for the full, longer restore window. A single under-budget window never restores.
  • Blur/tint invariant: across every governor action (ease, full-stop, hard-pause, restore), the glass blur-radius and tint-opacity tokens are byte-identical before and after; the governor exposes no path that writes a glass token.
  • Rest = full fidelity: when the frame budget is being met and the engine reports at-rest/breathing, the governor holds motion at full tempo and never pre-emptively eases; full blur + full motion always apply at rest.
  • Paused-loop inertness (no phantom over-budget): while the engine reports paused (window hidden, off-screen, or prefers-reduced-motion), the governor pauses its own measurement and discards the stalled inter-frame gaps, so a long paused stretch followed by resume never trips a step-down or the terminal hard-pause. Fed multi-second frame gaps tagged paused, the emitted motion level and the engine's pause state are unchanged.
  • Force-full-tempo hook: enabling the dev hook pins the Brain at full tempo and disables the governor (so a gated run measures the un-eased worst case); disabling it restores normal governed behavior.
  • Headless proxy harness: a headless-Chromium script loads the app with the force hook, scrolls a >=40-card thread continuously for >=10s in each theme, and emits a report of p95 and max frame time; the report is labeled a pre-gate proxy and its pass does not close the release gate.
  • Perf gate (manual sign-off): on the reference laptop VS Code webview (battery-powered, pinned before the run), a >=10s continuous scroll of a >=40-card thread at full Brain tempo yields p95 <=16.7ms with zero frames >33ms, in both themes; recorded as a signed-off checklist artifact on the PR before merge.

Testing Decisions

  • CREATE brain-perf-governor unit tests: drive the governor through an injected clock / frame-time source (external behavior = the emitted motion level and the engine's pause state, given frame times in). Cover: step-down ladder to full-stop on sustained over-budget; terminal hard-pause once motion is at full-stop and still over budget; hysteresis on a boundary-hovering sequence (assert no per-window flipping and that restore needs the full longer clear window below the restore threshold); the blur/tint invariant (snapshot the glass tokens before/after a full trip+restore cycle and assert equality); rest-inertness (below-budget + at-rest never eases); paused-loop inertness (feed multi-second gaps tagged paused and assert the motion level and pause state are unchanged — a stalled loop never registers a phantom over-budget frame or trips the fallback). No real rAF or wall clock — feed synthetic frame times.
  • EXTEND the full-motion slice's engine motion tests ("extends slice 4 test surface"): assert the governor steers the same single tempo control slice 4 exposes and adds no second render loop or second frame-time clock — reuse its tick()/tempo assertions rather than re-deriving tempo behavior.
  • CREATE a headless perf-trace smoke test: assert the harness boots the app with the force-full-tempo hook, scrolls the >=40-card fixture for >=10s in each theme, and produces a p95 + max-frame-time report object. This asserts the harness runs and reports — it is the pre-gate proxy, not the gate.
  • Manual gate is not an automated test: it is a documented checklist executed on the reference laptop and signed off on the PR (this is why the slice is HITL). No test asserts the gate's numeric outcome in CI.

Key Decisions

  • Budget + red line: p95 target = 16.7ms (one 60fps frame); the hard per-frame red line = 33ms (any single frame over this is a dropped frame and fails the gate).
  • Trip condition: p95 over a rolling ~2s frame window exceeds 16.7ms continuously for a sustained ~2s trip window, then step down one ease level. Ease ladder: full tempo -> eased/calm (stepping down the tempo ladder toward its slowest) -> motion full-stop -> [terminal] hard-pause to a static blurred field.
  • Hysteresis (dual-guard): restoring one level up requires BOTH a longer clear window (~2x the trip window) AND p95 at or below a restore threshold set a fixed margin below budget (~13ms), not merely below 16.7ms. Restoration is one level per clear window, never a jump straight back to full.
  • Terminal valve = the engine's existing hard-pause (rAF stop), leaving the last high-blur frame as a static field; it is the only step past motion-full-stop, and only the return to a met budget (per hysteresis) resumes the loop.
  • Governor levers, bounded: the governor's ONLY levers are the motion tempo control (from the full-motion slice) and the terminal hard-pause. It has no access to glass blur/tint tokens by construction.
  • Paused-loop guard: the governor reads the engine's paused state and pauses its own measurement while paused (hidden / off-screen / prefers-reduced-motion), discarding the stalled inter-frame gaps so resume never false-trips the fallback.
  • Force-full-tempo hook pins full tempo AND disables the governor, so the gate and the headless proxy both measure the un-eased worst case; if that passes on the reference laptop, the governor is a rarely-tripped safety net.
  • Gate parameters (fixed): reference laptop VS Code webview, battery-powered and pinned before the run, >=40-card thread, >=10s continuous scroll, full Brain tempo, both themes, manual sign-off recorded on the PR. Headless Chromium is a proxy only and never substitutes for the sign-off.
  • Data contract — governor input: a stream of per-frame durations (ms) plus the engine's current at-rest/active and paused state; output: a discrete motion level in {full, eased-N..., full-stop, hard-paused}. It reads frame times only from the existing loop; it does not run its own painting clock.

Constraints & Invariants

  • The fallback MUST NOT reduce blur radius or tint opacity — ever, at any level (easing, full-stop, hard-pause, or restoring). Blur fidelity is non-negotiable; the frosted look is the protected aesthetic.
  • Motion is the only give; the ease is discrete-stepwise, never a continuous flicker, and the dual-guard hysteresis must prevent per-window oscillation.
  • The governor is inert at rest: full blur + full motion always apply when the budget is met; it must never pre-emptively ease.
  • The headless-Chromium trace is a proxy and MUST NOT be recorded or presented as satisfying the release gate; only manual sign-off on the pinned reference laptop closes it.
  • One render loop only: the governor observes and steers the existing single rAF loop — it must not spawn a second render loop or a second frame-time clock that itself burns frames.
  • The governor must pause its own measurement whenever the engine is paused (window hidden, off-screen, or prefers-reduced-motion), so a stalled loop never registers phantom over-budget frames and false-trips the fallback.
  • Amicode design-system law applies to any dev/gate affordance chrome; browser-first iteration (vite dev on the app), not VSIX rebuilds; npm run lint clean + app typecheck before the PR.
Prior Art / Patterns - The old branch's `?brainForceActive` URL param in `brain-atmosphere.tsx` pins the brain at full musical tempo for perf capture — reuse/rename it as the force-full-tempo hook, and extend it to also disable the governor. - The Brain engine's existing hard-pause is the terminal valve: `pause()`/`resume()` in the current `brain-engine.ts` (and `suspend()`/`resume()` in the old-branch `engine.ts`), driving the single rAF loop. - The `TEMPI` tempo ladder (largo -> presto) and the full-motion slice's `setActive` adaptive heartbeat (the old-branch `setActive`) are the motion lever the governor eases — "extends slice 4 test surface." - `glass-tokens.ts` (`GlassTier.blur` / `alpha`) and `glass.css` (`--glass-*-blur` / `-bg`) hold the blur+tint the invariant protects — the governor must never write them. - #56's "Pre-agreed perf fallback" and ADR 0002 set the law: motion is the give, blur fidelity never degrades, the laptop-webview 60fps gate is the real target and headless Chromium is only a proxy.

Source

Part of #56. Durable record: ADR packages/app/docs/adr/0002-brain-as-chat-background.md.
Blocked by #61
Blocked by #62

Metadata

Metadata

Assignees

No one assigned

    Labels

    hitlNeeds a human decision/review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
       blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
      }
      } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
      })();
      (function(){
      try {
      var __m = "github.com";
      var __re = new RegExp('^' + "github\\.com" + '
      
      Skip to content

      Add the perf governor (ease motion, never blur) and gate 60fps on the reference laptop #63

      Description

      @kateebonner

      Important

      Problem

      The Chat's expensive combination — high-radius backdrop-blur recomputed per frame across many glass cards over an animating Brain, while scrolling — can blow the 60fps budget on a real laptop webview (see #56 for the why). This slice builds the pre-agreed release valve and proves the budget actually holds on real hardware.

      Approach

      Add a frame-time governor that observes the single Brain render loop and, only under sustained over-budget load, eases the Brain's motion stepwise (dual-guard hysteresis before restoring, so it never oscillates) down to a full motion stop, then — if that still misses budget — hard-pauses to a static blurred field as the terminal valve. It never touches blur or tint: motion is the only give. The release criterion is a manual 60fps sign-off on the pinned reference laptop webview; a headless-Chromium rAF-interval trace is a pre-gate proxy only. HITL because only a human on the reference machine can close the gate.

      Scope

      In: the frame-time monitor + motion-ease governor (trip, ease ladder, hysteresis restore, terminal hard-pause); the paused-loop measurement guard (no phantom over-budget when the engine is paused); the blur/tint-never-degraded invariant; a dev force-full-tempo hook (pins full tempo AND disables the governor); a headless-Chromium rAF-trace proxy harness over a long-thread fixture, both themes; the manual perf-gate checklist + sign-off on the reference laptop, both themes.
      Out: reducing blur radius or tint under load (the frosted look is the protected aesthetic; motion is the only give); dynamic per-frame backdrop sampling / adaptive-contrast glass (rejected in #56 as the biggest perf risk); the glass tokens and the motion engine themselves (owned by the glassed-components and full-motion slices; this slice only steers and protects them); node-cap / recency bounds and occluded-Panel paint-skipping (separate perf levers on the motion slice, not the release valve); any automated or CI substitute for the reference-laptop run (the gate is a deliberate manual sign-off).


      Acceptance Criteria

      • Trip + ease ladder: fed a frame-time sequence whose rolling p95 exceeds the 16.7ms budget continuously for a full sustained trip window, the governor steps the Brain's motion down one ease level (lower tempo); continued over-budget steps it further, down to a full motion stop. Below-budget input never triggers a step-down.
      • Terminal valve: with motion already at a full stop and p95 still over budget for the sustained window, the governor hard-pauses the render loop to a static blurred field; it never steps past full-stop into any state that keeps painting motion.
      • Hysteresis / no oscillation: on a frame sequence that hovers at the budget boundary (alternating just-over / just-under across windows), the governor does not change motion level every window; restoring one level up requires p95 to stay at or below the restore threshold (a fixed margin below budget) for the full, longer restore window. A single under-budget window never restores.
      • Blur/tint invariant: across every governor action (ease, full-stop, hard-pause, restore), the glass blur-radius and tint-opacity tokens are byte-identical before and after; the governor exposes no path that writes a glass token.
      • Rest = full fidelity: when the frame budget is being met and the engine reports at-rest/breathing, the governor holds motion at full tempo and never pre-emptively eases; full blur + full motion always apply at rest.
      • Paused-loop inertness (no phantom over-budget): while the engine reports paused (window hidden, off-screen, or prefers-reduced-motion), the governor pauses its own measurement and discards the stalled inter-frame gaps, so a long paused stretch followed by resume never trips a step-down or the terminal hard-pause. Fed multi-second frame gaps tagged paused, the emitted motion level and the engine's pause state are unchanged.
      • Force-full-tempo hook: enabling the dev hook pins the Brain at full tempo and disables the governor (so a gated run measures the un-eased worst case); disabling it restores normal governed behavior.
      • Headless proxy harness: a headless-Chromium script loads the app with the force hook, scrolls a >=40-card thread continuously for >=10s in each theme, and emits a report of p95 and max frame time; the report is labeled a pre-gate proxy and its pass does not close the release gate.
      • Perf gate (manual sign-off): on the reference laptop VS Code webview (battery-powered, pinned before the run), a >=10s continuous scroll of a >=40-card thread at full Brain tempo yields p95 <=16.7ms with zero frames >33ms, in both themes; recorded as a signed-off checklist artifact on the PR before merge.

      Testing Decisions

      • CREATE brain-perf-governor unit tests: drive the governor through an injected clock / frame-time source (external behavior = the emitted motion level and the engine's pause state, given frame times in). Cover: step-down ladder to full-stop on sustained over-budget; terminal hard-pause once motion is at full-stop and still over budget; hysteresis on a boundary-hovering sequence (assert no per-window flipping and that restore needs the full longer clear window below the restore threshold); the blur/tint invariant (snapshot the glass tokens before/after a full trip+restore cycle and assert equality); rest-inertness (below-budget + at-rest never eases); paused-loop inertness (feed multi-second gaps tagged paused and assert the motion level and pause state are unchanged — a stalled loop never registers a phantom over-budget frame or trips the fallback). No real rAF or wall clock — feed synthetic frame times.
      • EXTEND the full-motion slice's engine motion tests ("extends slice 4 test surface"): assert the governor steers the same single tempo control slice 4 exposes and adds no second render loop or second frame-time clock — reuse its tick()/tempo assertions rather than re-deriving tempo behavior.
      • CREATE a headless perf-trace smoke test: assert the harness boots the app with the force-full-tempo hook, scrolls the >=40-card fixture for >=10s in each theme, and produces a p95 + max-frame-time report object. This asserts the harness runs and reports — it is the pre-gate proxy, not the gate.
      • Manual gate is not an automated test: it is a documented checklist executed on the reference laptop and signed off on the PR (this is why the slice is HITL). No test asserts the gate's numeric outcome in CI.

      Key Decisions

      • Budget + red line: p95 target = 16.7ms (one 60fps frame); the hard per-frame red line = 33ms (any single frame over this is a dropped frame and fails the gate).
      • Trip condition: p95 over a rolling ~2s frame window exceeds 16.7ms continuously for a sustained ~2s trip window, then step down one ease level. Ease ladder: full tempo -> eased/calm (stepping down the tempo ladder toward its slowest) -> motion full-stop -> [terminal] hard-pause to a static blurred field.
      • Hysteresis (dual-guard): restoring one level up requires BOTH a longer clear window (~2x the trip window) AND p95 at or below a restore threshold set a fixed margin below budget (~13ms), not merely below 16.7ms. Restoration is one level per clear window, never a jump straight back to full.
      • Terminal valve = the engine's existing hard-pause (rAF stop), leaving the last high-blur frame as a static field; it is the only step past motion-full-stop, and only the return to a met budget (per hysteresis) resumes the loop.
      • Governor levers, bounded: the governor's ONLY levers are the motion tempo control (from the full-motion slice) and the terminal hard-pause. It has no access to glass blur/tint tokens by construction.
      • Paused-loop guard: the governor reads the engine's paused state and pauses its own measurement while paused (hidden / off-screen / prefers-reduced-motion), discarding the stalled inter-frame gaps so resume never false-trips the fallback.
      • Force-full-tempo hook pins full tempo AND disables the governor, so the gate and the headless proxy both measure the un-eased worst case; if that passes on the reference laptop, the governor is a rarely-tripped safety net.
      • Gate parameters (fixed): reference laptop VS Code webview, battery-powered and pinned before the run, >=40-card thread, >=10s continuous scroll, full Brain tempo, both themes, manual sign-off recorded on the PR. Headless Chromium is a proxy only and never substitutes for the sign-off.
      • Data contract — governor input: a stream of per-frame durations (ms) plus the engine's current at-rest/active and paused state; output: a discrete motion level in {full, eased-N..., full-stop, hard-paused}. It reads frame times only from the existing loop; it does not run its own painting clock.

      Constraints & Invariants

      • The fallback MUST NOT reduce blur radius or tint opacity — ever, at any level (easing, full-stop, hard-pause, or restoring). Blur fidelity is non-negotiable; the frosted look is the protected aesthetic.
      • Motion is the only give; the ease is discrete-stepwise, never a continuous flicker, and the dual-guard hysteresis must prevent per-window oscillation.
      • The governor is inert at rest: full blur + full motion always apply when the budget is met; it must never pre-emptively ease.
      • The headless-Chromium trace is a proxy and MUST NOT be recorded or presented as satisfying the release gate; only manual sign-off on the pinned reference laptop closes it.
      • One render loop only: the governor observes and steers the existing single rAF loop — it must not spawn a second render loop or a second frame-time clock that itself burns frames.
      • The governor must pause its own measurement whenever the engine is paused (window hidden, off-screen, or prefers-reduced-motion), so a stalled loop never registers phantom over-budget frames and false-trips the fallback.
      • Amicode design-system law applies to any dev/gate affordance chrome; browser-first iteration (vite dev on the app), not VSIX rebuilds; npm run lint clean + app typecheck before the PR.
      Prior Art / Patterns - The old branch's `?brainForceActive` URL param in `brain-atmosphere.tsx` pins the brain at full musical tempo for perf capture — reuse/rename it as the force-full-tempo hook, and extend it to also disable the governor. - The Brain engine's existing hard-pause is the terminal valve: `pause()`/`resume()` in the current `brain-engine.ts` (and `suspend()`/`resume()` in the old-branch `engine.ts`), driving the single rAF loop. - The `TEMPI` tempo ladder (largo -> presto) and the full-motion slice's `setActive` adaptive heartbeat (the old-branch `setActive`) are the motion lever the governor eases — "extends slice 4 test surface." - `glass-tokens.ts` (`GlassTier.blur` / `alpha`) and `glass.css` (`--glass-*-blur` / `-bg`) hold the blur+tint the invariant protects — the governor must never write them. - #56's "Pre-agreed perf fallback" and ADR 0002 set the law: motion is the give, blur fidelity never degrades, the laptop-webview 60fps gate is the real target and headless Chromium is only a proxy.

      Source

      Part of #56. Durable record: ADR packages/app/docs/adr/0002-brain-as-chat-background.md.
      Blocked by #61
      Blocked by #62

      Metadata

      Metadata

      Assignees

      No one assigned

        Labels

        hitlNeeds a human decision/review

        Type

        No type

        Projects

        No projects

          Milestone

          No milestone

          Relationships

          None yet

          Development

          No branches or pull requests

          Issue actions

          , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
          Skip to content

          Add the perf governor (ease motion, never blur) and gate 60fps on the reference laptop #63

          Description

          @kateebonner

          Important

          Problem

          The Chat's expensive combination — high-radius backdrop-blur recomputed per frame across many glass cards over an animating Brain, while scrolling — can blow the 60fps budget on a real laptop webview (see #56 for the why). This slice builds the pre-agreed release valve and proves the budget actually holds on real hardware.

          Approach

          Add a frame-time governor that observes the single Brain render loop and, only under sustained over-budget load, eases the Brain's motion stepwise (dual-guard hysteresis before restoring, so it never oscillates) down to a full motion stop, then — if that still misses budget — hard-pauses to a static blurred field as the terminal valve. It never touches blur or tint: motion is the only give. The release criterion is a manual 60fps sign-off on the pinned reference laptop webview; a headless-Chromium rAF-interval trace is a pre-gate proxy only. HITL because only a human on the reference machine can close the gate.

          Scope

          In: the frame-time monitor + motion-ease governor (trip, ease ladder, hysteresis restore, terminal hard-pause); the paused-loop measurement guard (no phantom over-budget when the engine is paused); the blur/tint-never-degraded invariant; a dev force-full-tempo hook (pins full tempo AND disables the governor); a headless-Chromium rAF-trace proxy harness over a long-thread fixture, both themes; the manual perf-gate checklist + sign-off on the reference laptop, both themes.
          Out: reducing blur radius or tint under load (the frosted look is the protected aesthetic; motion is the only give); dynamic per-frame backdrop sampling / adaptive-contrast glass (rejected in #56 as the biggest perf risk); the glass tokens and the motion engine themselves (owned by the glassed-components and full-motion slices; this slice only steers and protects them); node-cap / recency bounds and occluded-Panel paint-skipping (separate perf levers on the motion slice, not the release valve); any automated or CI substitute for the reference-laptop run (the gate is a deliberate manual sign-off).


          Acceptance Criteria

          • Trip + ease ladder: fed a frame-time sequence whose rolling p95 exceeds the 16.7ms budget continuously for a full sustained trip window, the governor steps the Brain's motion down one ease level (lower tempo); continued over-budget steps it further, down to a full motion stop. Below-budget input never triggers a step-down.
          • Terminal valve: with motion already at a full stop and p95 still over budget for the sustained window, the governor hard-pauses the render loop to a static blurred field; it never steps past full-stop into any state that keeps painting motion.
          • Hysteresis / no oscillation: on a frame sequence that hovers at the budget boundary (alternating just-over / just-under across windows), the governor does not change motion level every window; restoring one level up requires p95 to stay at or below the restore threshold (a fixed margin below budget) for the full, longer restore window. A single under-budget window never restores.
          • Blur/tint invariant: across every governor action (ease, full-stop, hard-pause, restore), the glass blur-radius and tint-opacity tokens are byte-identical before and after; the governor exposes no path that writes a glass token.
          • Rest = full fidelity: when the frame budget is being met and the engine reports at-rest/breathing, the governor holds motion at full tempo and never pre-emptively eases; full blur + full motion always apply at rest.
          • Paused-loop inertness (no phantom over-budget): while the engine reports paused (window hidden, off-screen, or prefers-reduced-motion), the governor pauses its own measurement and discards the stalled inter-frame gaps, so a long paused stretch followed by resume never trips a step-down or the terminal hard-pause. Fed multi-second frame gaps tagged paused, the emitted motion level and the engine's pause state are unchanged.
          • Force-full-tempo hook: enabling the dev hook pins the Brain at full tempo and disables the governor (so a gated run measures the un-eased worst case); disabling it restores normal governed behavior.
          • Headless proxy harness: a headless-Chromium script loads the app with the force hook, scrolls a >=40-card thread continuously for >=10s in each theme, and emits a report of p95 and max frame time; the report is labeled a pre-gate proxy and its pass does not close the release gate.
          • Perf gate (manual sign-off): on the reference laptop VS Code webview (battery-powered, pinned before the run), a >=10s continuous scroll of a >=40-card thread at full Brain tempo yields p95 <=16.7ms with zero frames >33ms, in both themes; recorded as a signed-off checklist artifact on the PR before merge.

          Testing Decisions

          • CREATE brain-perf-governor unit tests: drive the governor through an injected clock / frame-time source (external behavior = the emitted motion level and the engine's pause state, given frame times in). Cover: step-down ladder to full-stop on sustained over-budget; terminal hard-pause once motion is at full-stop and still over budget; hysteresis on a boundary-hovering sequence (assert no per-window flipping and that restore needs the full longer clear window below the restore threshold); the blur/tint invariant (snapshot the glass tokens before/after a full trip+restore cycle and assert equality); rest-inertness (below-budget + at-rest never eases); paused-loop inertness (feed multi-second gaps tagged paused and assert the motion level and pause state are unchanged — a stalled loop never registers a phantom over-budget frame or trips the fallback). No real rAF or wall clock — feed synthetic frame times.
          • EXTEND the full-motion slice's engine motion tests ("extends slice 4 test surface"): assert the governor steers the same single tempo control slice 4 exposes and adds no second render loop or second frame-time clock — reuse its tick()/tempo assertions rather than re-deriving tempo behavior.
          • CREATE a headless perf-trace smoke test: assert the harness boots the app with the force-full-tempo hook, scrolls the >=40-card fixture for >=10s in each theme, and produces a p95 + max-frame-time report object. This asserts the harness runs and reports — it is the pre-gate proxy, not the gate.
          • Manual gate is not an automated test: it is a documented checklist executed on the reference laptop and signed off on the PR (this is why the slice is HITL). No test asserts the gate's numeric outcome in CI.

          Key Decisions

          • Budget + red line: p95 target = 16.7ms (one 60fps frame); the hard per-frame red line = 33ms (any single frame over this is a dropped frame and fails the gate).
          • Trip condition: p95 over a rolling ~2s frame window exceeds 16.7ms continuously for a sustained ~2s trip window, then step down one ease level. Ease ladder: full tempo -> eased/calm (stepping down the tempo ladder toward its slowest) -> motion full-stop -> [terminal] hard-pause to a static blurred field.
          • Hysteresis (dual-guard): restoring one level up requires BOTH a longer clear window (~2x the trip window) AND p95 at or below a restore threshold set a fixed margin below budget (~13ms), not merely below 16.7ms. Restoration is one level per clear window, never a jump straight back to full.
          • Terminal valve = the engine's existing hard-pause (rAF stop), leaving the last high-blur frame as a static field; it is the only step past motion-full-stop, and only the return to a met budget (per hysteresis) resumes the loop.
          • Governor levers, bounded: the governor's ONLY levers are the motion tempo control (from the full-motion slice) and the terminal hard-pause. It has no access to glass blur/tint tokens by construction.
          • Paused-loop guard: the governor reads the engine's paused state and pauses its own measurement while paused (hidden / off-screen / prefers-reduced-motion), discarding the stalled inter-frame gaps so resume never false-trips the fallback.
          • Force-full-tempo hook pins full tempo AND disables the governor, so the gate and the headless proxy both measure the un-eased worst case; if that passes on the reference laptop, the governor is a rarely-tripped safety net.
          • Gate parameters (fixed): reference laptop VS Code webview, battery-powered and pinned before the run, >=40-card thread, >=10s continuous scroll, full Brain tempo, both themes, manual sign-off recorded on the PR. Headless Chromium is a proxy only and never substitutes for the sign-off.
          • Data contract — governor input: a stream of per-frame durations (ms) plus the engine's current at-rest/active and paused state; output: a discrete motion level in {full, eased-N..., full-stop, hard-paused}. It reads frame times only from the existing loop; it does not run its own painting clock.

          Constraints & Invariants

          • The fallback MUST NOT reduce blur radius or tint opacity — ever, at any level (easing, full-stop, hard-pause, or restoring). Blur fidelity is non-negotiable; the frosted look is the protected aesthetic.
          • Motion is the only give; the ease is discrete-stepwise, never a continuous flicker, and the dual-guard hysteresis must prevent per-window oscillation.
          • The governor is inert at rest: full blur + full motion always apply when the budget is met; it must never pre-emptively ease.
          • The headless-Chromium trace is a proxy and MUST NOT be recorded or presented as satisfying the release gate; only manual sign-off on the pinned reference laptop closes it.
          • One render loop only: the governor observes and steers the existing single rAF loop — it must not spawn a second render loop or a second frame-time clock that itself burns frames.
          • The governor must pause its own measurement whenever the engine is paused (window hidden, off-screen, or prefers-reduced-motion), so a stalled loop never registers phantom over-budget frames and false-trips the fallback.
          • Amicode design-system law applies to any dev/gate affordance chrome; browser-first iteration (vite dev on the app), not VSIX rebuilds; npm run lint clean + app typecheck before the PR.
          Prior Art / Patterns - The old branch's `?brainForceActive` URL param in `brain-atmosphere.tsx` pins the brain at full musical tempo for perf capture — reuse/rename it as the force-full-tempo hook, and extend it to also disable the governor. - The Brain engine's existing hard-pause is the terminal valve: `pause()`/`resume()` in the current `brain-engine.ts` (and `suspend()`/`resume()` in the old-branch `engine.ts`), driving the single rAF loop. - The `TEMPI` tempo ladder (largo -> presto) and the full-motion slice's `setActive` adaptive heartbeat (the old-branch `setActive`) are the motion lever the governor eases — "extends slice 4 test surface." - `glass-tokens.ts` (`GlassTier.blur` / `alpha`) and `glass.css` (`--glass-*-blur` / `-bg`) hold the blur+tint the invariant protects — the governor must never write them. - #56's "Pre-agreed perf fallback" and ADR 0002 set the law: motion is the give, blur fidelity never degrades, the laptop-webview 60fps gate is the real target and headless Chromium is only a proxy.

          Source

          Part of #56. Durable record: ADR packages/app/docs/adr/0002-brain-as-chat-background.md.
          Blocked by #61
          Blocked by #62

          Metadata

          Metadata

          Assignees

          No one assigned

            Labels

            hitlNeeds a human decision/review

            Type

            No type

            Projects

            No projects

              Milestone

              No milestone

              Relationships

              None yet

              Development

              No branches or pull requests

              Issue actions

              , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
              Skip to content

              Add the perf governor (ease motion, never blur) and gate 60fps on the reference laptop #63

              Description

              @kateebonner

              Important

              Problem

              The Chat's expensive combination — high-radius backdrop-blur recomputed per frame across many glass cards over an animating Brain, while scrolling — can blow the 60fps budget on a real laptop webview (see #56 for the why). This slice builds the pre-agreed release valve and proves the budget actually holds on real hardware.

              Approach

              Add a frame-time governor that observes the single Brain render loop and, only under sustained over-budget load, eases the Brain's motion stepwise (dual-guard hysteresis before restoring, so it never oscillates) down to a full motion stop, then — if that still misses budget — hard-pauses to a static blurred field as the terminal valve. It never touches blur or tint: motion is the only give. The release criterion is a manual 60fps sign-off on the pinned reference laptop webview; a headless-Chromium rAF-interval trace is a pre-gate proxy only. HITL because only a human on the reference machine can close the gate.

              Scope

              In: the frame-time monitor + motion-ease governor (trip, ease ladder, hysteresis restore, terminal hard-pause); the paused-loop measurement guard (no phantom over-budget when the engine is paused); the blur/tint-never-degraded invariant; a dev force-full-tempo hook (pins full tempo AND disables the governor); a headless-Chromium rAF-trace proxy harness over a long-thread fixture, both themes; the manual perf-gate checklist + sign-off on the reference laptop, both themes.
              Out: reducing blur radius or tint under load (the frosted look is the protected aesthetic; motion is the only give); dynamic per-frame backdrop sampling / adaptive-contrast glass (rejected in #56 as the biggest perf risk); the glass tokens and the motion engine themselves (owned by the glassed-components and full-motion slices; this slice only steers and protects them); node-cap / recency bounds and occluded-Panel paint-skipping (separate perf levers on the motion slice, not the release valve); any automated or CI substitute for the reference-laptop run (the gate is a deliberate manual sign-off).


              Acceptance Criteria

              • Trip + ease ladder: fed a frame-time sequence whose rolling p95 exceeds the 16.7ms budget continuously for a full sustained trip window, the governor steps the Brain's motion down one ease level (lower tempo); continued over-budget steps it further, down to a full motion stop. Below-budget input never triggers a step-down.
              • Terminal valve: with motion already at a full stop and p95 still over budget for the sustained window, the governor hard-pauses the render loop to a static blurred field; it never steps past full-stop into any state that keeps painting motion.
              • Hysteresis / no oscillation: on a frame sequence that hovers at the budget boundary (alternating just-over / just-under across windows), the governor does not change motion level every window; restoring one level up requires p95 to stay at or below the restore threshold (a fixed margin below budget) for the full, longer restore window. A single under-budget window never restores.
              • Blur/tint invariant: across every governor action (ease, full-stop, hard-pause, restore), the glass blur-radius and tint-opacity tokens are byte-identical before and after; the governor exposes no path that writes a glass token.
              • Rest = full fidelity: when the frame budget is being met and the engine reports at-rest/breathing, the governor holds motion at full tempo and never pre-emptively eases; full blur + full motion always apply at rest.
              • Paused-loop inertness (no phantom over-budget): while the engine reports paused (window hidden, off-screen, or prefers-reduced-motion), the governor pauses its own measurement and discards the stalled inter-frame gaps, so a long paused stretch followed by resume never trips a step-down or the terminal hard-pause. Fed multi-second frame gaps tagged paused, the emitted motion level and the engine's pause state are unchanged.
              • Force-full-tempo hook: enabling the dev hook pins the Brain at full tempo and disables the governor (so a gated run measures the un-eased worst case); disabling it restores normal governed behavior.
              • Headless proxy harness: a headless-Chromium script loads the app with the force hook, scrolls a >=40-card thread continuously for >=10s in each theme, and emits a report of p95 and max frame time; the report is labeled a pre-gate proxy and its pass does not close the release gate.
              • Perf gate (manual sign-off): on the reference laptop VS Code webview (battery-powered, pinned before the run), a >=10s continuous scroll of a >=40-card thread at full Brain tempo yields p95 <=16.7ms with zero frames >33ms, in both themes; recorded as a signed-off checklist artifact on the PR before merge.

              Testing Decisions

              • CREATE brain-perf-governor unit tests: drive the governor through an injected clock / frame-time source (external behavior = the emitted motion level and the engine's pause state, given frame times in). Cover: step-down ladder to full-stop on sustained over-budget; terminal hard-pause once motion is at full-stop and still over budget; hysteresis on a boundary-hovering sequence (assert no per-window flipping and that restore needs the full longer clear window below the restore threshold); the blur/tint invariant (snapshot the glass tokens before/after a full trip+restore cycle and assert equality); rest-inertness (below-budget + at-rest never eases); paused-loop inertness (feed multi-second gaps tagged paused and assert the motion level and pause state are unchanged — a stalled loop never registers a phantom over-budget frame or trips the fallback). No real rAF or wall clock — feed synthetic frame times.
              • EXTEND the full-motion slice's engine motion tests ("extends slice 4 test surface"): assert the governor steers the same single tempo control slice 4 exposes and adds no second render loop or second frame-time clock — reuse its tick()/tempo assertions rather than re-deriving tempo behavior.
              • CREATE a headless perf-trace smoke test: assert the harness boots the app with the force-full-tempo hook, scrolls the >=40-card fixture for >=10s in each theme, and produces a p95 + max-frame-time report object. This asserts the harness runs and reports — it is the pre-gate proxy, not the gate.
              • Manual gate is not an automated test: it is a documented checklist executed on the reference laptop and signed off on the PR (this is why the slice is HITL). No test asserts the gate's numeric outcome in CI.

              Key Decisions

              • Budget + red line: p95 target = 16.7ms (one 60fps frame); the hard per-frame red line = 33ms (any single frame over this is a dropped frame and fails the gate).
              • Trip condition: p95 over a rolling ~2s frame window exceeds 16.7ms continuously for a sustained ~2s trip window, then step down one ease level. Ease ladder: full tempo -> eased/calm (stepping down the tempo ladder toward its slowest) -> motion full-stop -> [terminal] hard-pause to a static blurred field.
              • Hysteresis (dual-guard): restoring one level up requires BOTH a longer clear window (~2x the trip window) AND p95 at or below a restore threshold set a fixed margin below budget (~13ms), not merely below 16.7ms. Restoration is one level per clear window, never a jump straight back to full.
              • Terminal valve = the engine's existing hard-pause (rAF stop), leaving the last high-blur frame as a static field; it is the only step past motion-full-stop, and only the return to a met budget (per hysteresis) resumes the loop.
              • Governor levers, bounded: the governor's ONLY levers are the motion tempo control (from the full-motion slice) and the terminal hard-pause. It has no access to glass blur/tint tokens by construction.
              • Paused-loop guard: the governor reads the engine's paused state and pauses its own measurement while paused (hidden / off-screen / prefers-reduced-motion), discarding the stalled inter-frame gaps so resume never false-trips the fallback.
              • Force-full-tempo hook pins full tempo AND disables the governor, so the gate and the headless proxy both measure the un-eased worst case; if that passes on the reference laptop, the governor is a rarely-tripped safety net.
              • Gate parameters (fixed): reference laptop VS Code webview, battery-powered and pinned before the run, >=40-card thread, >=10s continuous scroll, full Brain tempo, both themes, manual sign-off recorded on the PR. Headless Chromium is a proxy only and never substitutes for the sign-off.
              • Data contract — governor input: a stream of per-frame durations (ms) plus the engine's current at-rest/active and paused state; output: a discrete motion level in {full, eased-N..., full-stop, hard-paused}. It reads frame times only from the existing loop; it does not run its own painting clock.

              Constraints & Invariants

              • The fallback MUST NOT reduce blur radius or tint opacity — ever, at any level (easing, full-stop, hard-pause, or restoring). Blur fidelity is non-negotiable; the frosted look is the protected aesthetic.
              • Motion is the only give; the ease is discrete-stepwise, never a continuous flicker, and the dual-guard hysteresis must prevent per-window oscillation.
              • The governor is inert at rest: full blur + full motion always apply when the budget is met; it must never pre-emptively ease.
              • The headless-Chromium trace is a proxy and MUST NOT be recorded or presented as satisfying the release gate; only manual sign-off on the pinned reference laptop closes it.
              • One render loop only: the governor observes and steers the existing single rAF loop — it must not spawn a second render loop or a second frame-time clock that itself burns frames.
              • The governor must pause its own measurement whenever the engine is paused (window hidden, off-screen, or prefers-reduced-motion), so a stalled loop never registers phantom over-budget frames and false-trips the fallback.
              • Amicode design-system law applies to any dev/gate affordance chrome; browser-first iteration (vite dev on the app), not VSIX rebuilds; npm run lint clean + app typecheck before the PR.
              Prior Art / Patterns - The old branch's `?brainForceActive` URL param in `brain-atmosphere.tsx` pins the brain at full musical tempo for perf capture — reuse/rename it as the force-full-tempo hook, and extend it to also disable the governor. - The Brain engine's existing hard-pause is the terminal valve: `pause()`/`resume()` in the current `brain-engine.ts` (and `suspend()`/`resume()` in the old-branch `engine.ts`), driving the single rAF loop. - The `TEMPI` tempo ladder (largo -> presto) and the full-motion slice's `setActive` adaptive heartbeat (the old-branch `setActive`) are the motion lever the governor eases — "extends slice 4 test surface." - `glass-tokens.ts` (`GlassTier.blur` / `alpha`) and `glass.css` (`--glass-*-blur` / `-bg`) hold the blur+tint the invariant protects — the governor must never write them. - #56's "Pre-agreed perf fallback" and ADR 0002 set the law: motion is the give, blur fidelity never degrades, the laptop-webview 60fps gate is the real target and headless Chromium is only a proxy.

              Source

              Part of #56. Durable record: ADR packages/app/docs/adr/0002-brain-as-chat-background.md.
              Blocked by #61
              Blocked by #62

              Metadata

              Metadata

              Assignees

              No one assigned

                Labels

                hitlNeeds a human decision/review

                Type

                No type

                Projects

                No projects

                  Milestone

                  No milestone

                  Relationships

                  None yet

                  Development

                  No branches or pull requests

                  Issue actions

                  , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
                  Skip to content

                  Add the perf governor (ease motion, never blur) and gate 60fps on the reference laptop #63

                  Description

                  @kateebonner

                  Important

                  Problem

                  The Chat's expensive combination — high-radius backdrop-blur recomputed per frame across many glass cards over an animating Brain, while scrolling — can blow the 60fps budget on a real laptop webview (see #56 for the why). This slice builds the pre-agreed release valve and proves the budget actually holds on real hardware.

                  Approach

                  Add a frame-time governor that observes the single Brain render loop and, only under sustained over-budget load, eases the Brain's motion stepwise (dual-guard hysteresis before restoring, so it never oscillates) down to a full motion stop, then — if that still misses budget — hard-pauses to a static blurred field as the terminal valve. It never touches blur or tint: motion is the only give. The release criterion is a manual 60fps sign-off on the pinned reference laptop webview; a headless-Chromium rAF-interval trace is a pre-gate proxy only. HITL because only a human on the reference machine can close the gate.

                  Scope

                  In: the frame-time monitor + motion-ease governor (trip, ease ladder, hysteresis restore, terminal hard-pause); the paused-loop measurement guard (no phantom over-budget when the engine is paused); the blur/tint-never-degraded invariant; a dev force-full-tempo hook (pins full tempo AND disables the governor); a headless-Chromium rAF-trace proxy harness over a long-thread fixture, both themes; the manual perf-gate checklist + sign-off on the reference laptop, both themes.
                  Out: reducing blur radius or tint under load (the frosted look is the protected aesthetic; motion is the only give); dynamic per-frame backdrop sampling / adaptive-contrast glass (rejected in #56 as the biggest perf risk); the glass tokens and the motion engine themselves (owned by the glassed-components and full-motion slices; this slice only steers and protects them); node-cap / recency bounds and occluded-Panel paint-skipping (separate perf levers on the motion slice, not the release valve); any automated or CI substitute for the reference-laptop run (the gate is a deliberate manual sign-off).


                  Acceptance Criteria

                  • Trip + ease ladder: fed a frame-time sequence whose rolling p95 exceeds the 16.7ms budget continuously for a full sustained trip window, the governor steps the Brain's motion down one ease level (lower tempo); continued over-budget steps it further, down to a full motion stop. Below-budget input never triggers a step-down.
                  • Terminal valve: with motion already at a full stop and p95 still over budget for the sustained window, the governor hard-pauses the render loop to a static blurred field; it never steps past full-stop into any state that keeps painting motion.
                  • Hysteresis / no oscillation: on a frame sequence that hovers at the budget boundary (alternating just-over / just-under across windows), the governor does not change motion level every window; restoring one level up requires p95 to stay at or below the restore threshold (a fixed margin below budget) for the full, longer restore window. A single under-budget window never restores.
                  • Blur/tint invariant: across every governor action (ease, full-stop, hard-pause, restore), the glass blur-radius and tint-opacity tokens are byte-identical before and after; the governor exposes no path that writes a glass token.
                  • Rest = full fidelity: when the frame budget is being met and the engine reports at-rest/breathing, the governor holds motion at full tempo and never pre-emptively eases; full blur + full motion always apply at rest.
                  • Paused-loop inertness (no phantom over-budget): while the engine reports paused (window hidden, off-screen, or prefers-reduced-motion), the governor pauses its own measurement and discards the stalled inter-frame gaps, so a long paused stretch followed by resume never trips a step-down or the terminal hard-pause. Fed multi-second frame gaps tagged paused, the emitted motion level and the engine's pause state are unchanged.
                  • Force-full-tempo hook: enabling the dev hook pins the Brain at full tempo and disables the governor (so a gated run measures the un-eased worst case); disabling it restores normal governed behavior.
                  • Headless proxy harness: a headless-Chromium script loads the app with the force hook, scrolls a >=40-card thread continuously for >=10s in each theme, and emits a report of p95 and max frame time; the report is labeled a pre-gate proxy and its pass does not close the release gate.
                  • Perf gate (manual sign-off): on the reference laptop VS Code webview (battery-powered, pinned before the run), a >=10s continuous scroll of a >=40-card thread at full Brain tempo yields p95 <=16.7ms with zero frames >33ms, in both themes; recorded as a signed-off checklist artifact on the PR before merge.

                  Testing Decisions

                  • CREATE brain-perf-governor unit tests: drive the governor through an injected clock / frame-time source (external behavior = the emitted motion level and the engine's pause state, given frame times in). Cover: step-down ladder to full-stop on sustained over-budget; terminal hard-pause once motion is at full-stop and still over budget; hysteresis on a boundary-hovering sequence (assert no per-window flipping and that restore needs the full longer clear window below the restore threshold); the blur/tint invariant (snapshot the glass tokens before/after a full trip+restore cycle and assert equality); rest-inertness (below-budget + at-rest never eases); paused-loop inertness (feed multi-second gaps tagged paused and assert the motion level and pause state are unchanged — a stalled loop never registers a phantom over-budget frame or trips the fallback). No real rAF or wall clock — feed synthetic frame times.
                  • EXTEND the full-motion slice's engine motion tests ("extends slice 4 test surface"): assert the governor steers the same single tempo control slice 4 exposes and adds no second render loop or second frame-time clock — reuse its tick()/tempo assertions rather than re-deriving tempo behavior.
                  • CREATE a headless perf-trace smoke test: assert the harness boots the app with the force-full-tempo hook, scrolls the >=40-card fixture for >=10s in each theme, and produces a p95 + max-frame-time report object. This asserts the harness runs and reports — it is the pre-gate proxy, not the gate.
                  • Manual gate is not an automated test: it is a documented checklist executed on the reference laptop and signed off on the PR (this is why the slice is HITL). No test asserts the gate's numeric outcome in CI.

                  Key Decisions

                  • Budget + red line: p95 target = 16.7ms (one 60fps frame); the hard per-frame red line = 33ms (any single frame over this is a dropped frame and fails the gate).
                  • Trip condition: p95 over a rolling ~2s frame window exceeds 16.7ms continuously for a sustained ~2s trip window, then step down one ease level. Ease ladder: full tempo -> eased/calm (stepping down the tempo ladder toward its slowest) -> motion full-stop -> [terminal] hard-pause to a static blurred field.
                  • Hysteresis (dual-guard): restoring one level up requires BOTH a longer clear window (~2x the trip window) AND p95 at or below a restore threshold set a fixed margin below budget (~13ms), not merely below 16.7ms. Restoration is one level per clear window, never a jump straight back to full.
                  • Terminal valve = the engine's existing hard-pause (rAF stop), leaving the last high-blur frame as a static field; it is the only step past motion-full-stop, and only the return to a met budget (per hysteresis) resumes the loop.
                  • Governor levers, bounded: the governor's ONLY levers are the motion tempo control (from the full-motion slice) and the terminal hard-pause. It has no access to glass blur/tint tokens by construction.
                  • Paused-loop guard: the governor reads the engine's paused state and pauses its own measurement while paused (hidden / off-screen / prefers-reduced-motion), discarding the stalled inter-frame gaps so resume never false-trips the fallback.
                  • Force-full-tempo hook pins full tempo AND disables the governor, so the gate and the headless proxy both measure the un-eased worst case; if that passes on the reference laptop, the governor is a rarely-tripped safety net.
                  • Gate parameters (fixed): reference laptop VS Code webview, battery-powered and pinned before the run, >=40-card thread, >=10s continuous scroll, full Brain tempo, both themes, manual sign-off recorded on the PR. Headless Chromium is a proxy only and never substitutes for the sign-off.
                  • Data contract — governor input: a stream of per-frame durations (ms) plus the engine's current at-rest/active and paused state; output: a discrete motion level in {full, eased-N..., full-stop, hard-paused}. It reads frame times only from the existing loop; it does not run its own painting clock.

                  Constraints & Invariants

                  • The fallback MUST NOT reduce blur radius or tint opacity — ever, at any level (easing, full-stop, hard-pause, or restoring). Blur fidelity is non-negotiable; the frosted look is the protected aesthetic.
                  • Motion is the only give; the ease is discrete-stepwise, never a continuous flicker, and the dual-guard hysteresis must prevent per-window oscillation.
                  • The governor is inert at rest: full blur + full motion always apply when the budget is met; it must never pre-emptively ease.
                  • The headless-Chromium trace is a proxy and MUST NOT be recorded or presented as satisfying the release gate; only manual sign-off on the pinned reference laptop closes it.
                  • One render loop only: the governor observes and steers the existing single rAF loop — it must not spawn a second render loop or a second frame-time clock that itself burns frames.
                  • The governor must pause its own measurement whenever the engine is paused (window hidden, off-screen, or prefers-reduced-motion), so a stalled loop never registers phantom over-budget frames and false-trips the fallback.
                  • Amicode design-system law applies to any dev/gate affordance chrome; browser-first iteration (vite dev on the app), not VSIX rebuilds; npm run lint clean + app typecheck before the PR.
                  Prior Art / Patterns - The old branch's `?brainForceActive` URL param in `brain-atmosphere.tsx` pins the brain at full musical tempo for perf capture — reuse/rename it as the force-full-tempo hook, and extend it to also disable the governor. - The Brain engine's existing hard-pause is the terminal valve: `pause()`/`resume()` in the current `brain-engine.ts` (and `suspend()`/`resume()` in the old-branch `engine.ts`), driving the single rAF loop. - The `TEMPI` tempo ladder (largo -> presto) and the full-motion slice's `setActive` adaptive heartbeat (the old-branch `setActive`) are the motion lever the governor eases — "extends slice 4 test surface." - `glass-tokens.ts` (`GlassTier.blur` / `alpha`) and `glass.css` (`--glass-*-blur` / `-bg`) hold the blur+tint the invariant protects — the governor must never write them. - #56's "Pre-agreed perf fallback" and ADR 0002 set the law: motion is the give, blur fidelity never degrades, the laptop-webview 60fps gate is the real target and headless Chromium is only a proxy.

                  Source

                  Part of #56. Durable record: ADR packages/app/docs/adr/0002-brain-as-chat-background.md.
                  Blocked by #61
                  Blocked by #62

                  Metadata

                  Metadata

                  Assignees

                  No one assigned

                    Labels

                    hitlNeeds a human decision/review

                    Type

                    No type

                    Projects

                    No projects

                      Milestone

                      No milestone

                      Relationships

                      None yet

                      Development

                      No branches or pull requests

                      Issue actions

                      , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
                      Skip to content

                      Add the perf governor (ease motion, never blur) and gate 60fps on the reference laptop #63

                      Description

                      @kateebonner

                      Important

                      Problem

                      The Chat's expensive combination — high-radius backdrop-blur recomputed per frame across many glass cards over an animating Brain, while scrolling — can blow the 60fps budget on a real laptop webview (see #56 for the why). This slice builds the pre-agreed release valve and proves the budget actually holds on real hardware.

                      Approach

                      Add a frame-time governor that observes the single Brain render loop and, only under sustained over-budget load, eases the Brain's motion stepwise (dual-guard hysteresis before restoring, so it never oscillates) down to a full motion stop, then — if that still misses budget — hard-pauses to a static blurred field as the terminal valve. It never touches blur or tint: motion is the only give. The release criterion is a manual 60fps sign-off on the pinned reference laptop webview; a headless-Chromium rAF-interval trace is a pre-gate proxy only. HITL because only a human on the reference machine can close the gate.

                      Scope

                      In: the frame-time monitor + motion-ease governor (trip, ease ladder, hysteresis restore, terminal hard-pause); the paused-loop measurement guard (no phantom over-budget when the engine is paused); the blur/tint-never-degraded invariant; a dev force-full-tempo hook (pins full tempo AND disables the governor); a headless-Chromium rAF-trace proxy harness over a long-thread fixture, both themes; the manual perf-gate checklist + sign-off on the reference laptop, both themes.
                      Out: reducing blur radius or tint under load (the frosted look is the protected aesthetic; motion is the only give); dynamic per-frame backdrop sampling / adaptive-contrast glass (rejected in #56 as the biggest perf risk); the glass tokens and the motion engine themselves (owned by the glassed-components and full-motion slices; this slice only steers and protects them); node-cap / recency bounds and occluded-Panel paint-skipping (separate perf levers on the motion slice, not the release valve); any automated or CI substitute for the reference-laptop run (the gate is a deliberate manual sign-off).


                      Acceptance Criteria

                      • Trip + ease ladder: fed a frame-time sequence whose rolling p95 exceeds the 16.7ms budget continuously for a full sustained trip window, the governor steps the Brain's motion down one ease level (lower tempo); continued over-budget steps it further, down to a full motion stop. Below-budget input never triggers a step-down.
                      • Terminal valve: with motion already at a full stop and p95 still over budget for the sustained window, the governor hard-pauses the render loop to a static blurred field; it never steps past full-stop into any state that keeps painting motion.
                      • Hysteresis / no oscillation: on a frame sequence that hovers at the budget boundary (alternating just-over / just-under across windows), the governor does not change motion level every window; restoring one level up requires p95 to stay at or below the restore threshold (a fixed margin below budget) for the full, longer restore window. A single under-budget window never restores.
                      • Blur/tint invariant: across every governor action (ease, full-stop, hard-pause, restore), the glass blur-radius and tint-opacity tokens are byte-identical before and after; the governor exposes no path that writes a glass token.
                      • Rest = full fidelity: when the frame budget is being met and the engine reports at-rest/breathing, the governor holds motion at full tempo and never pre-emptively eases; full blur + full motion always apply at rest.
                      • Paused-loop inertness (no phantom over-budget): while the engine reports paused (window hidden, off-screen, or prefers-reduced-motion), the governor pauses its own measurement and discards the stalled inter-frame gaps, so a long paused stretch followed by resume never trips a step-down or the terminal hard-pause. Fed multi-second frame gaps tagged paused, the emitted motion level and the engine's pause state are unchanged.
                      • Force-full-tempo hook: enabling the dev hook pins the Brain at full tempo and disables the governor (so a gated run measures the un-eased worst case); disabling it restores normal governed behavior.
                      • Headless proxy harness: a headless-Chromium script loads the app with the force hook, scrolls a >=40-card thread continuously for >=10s in each theme, and emits a report of p95 and max frame time; the report is labeled a pre-gate proxy and its pass does not close the release gate.
                      • Perf gate (manual sign-off): on the reference laptop VS Code webview (battery-powered, pinned before the run), a >=10s continuous scroll of a >=40-card thread at full Brain tempo yields p95 <=16.7ms with zero frames >33ms, in both themes; recorded as a signed-off checklist artifact on the PR before merge.

                      Testing Decisions

                      • CREATE brain-perf-governor unit tests: drive the governor through an injected clock / frame-time source (external behavior = the emitted motion level and the engine's pause state, given frame times in). Cover: step-down ladder to full-stop on sustained over-budget; terminal hard-pause once motion is at full-stop and still over budget; hysteresis on a boundary-hovering sequence (assert no per-window flipping and that restore needs the full longer clear window below the restore threshold); the blur/tint invariant (snapshot the glass tokens before/after a full trip+restore cycle and assert equality); rest-inertness (below-budget + at-rest never eases); paused-loop inertness (feed multi-second gaps tagged paused and assert the motion level and pause state are unchanged — a stalled loop never registers a phantom over-budget frame or trips the fallback). No real rAF or wall clock — feed synthetic frame times.
                      • EXTEND the full-motion slice's engine motion tests ("extends slice 4 test surface"): assert the governor steers the same single tempo control slice 4 exposes and adds no second render loop or second frame-time clock — reuse its tick()/tempo assertions rather than re-deriving tempo behavior.
                      • CREATE a headless perf-trace smoke test: assert the harness boots the app with the force-full-tempo hook, scrolls the >=40-card fixture for >=10s in each theme, and produces a p95 + max-frame-time report object. This asserts the harness runs and reports — it is the pre-gate proxy, not the gate.
                      • Manual gate is not an automated test: it is a documented checklist executed on the reference laptop and signed off on the PR (this is why the slice is HITL). No test asserts the gate's numeric outcome in CI.

                      Key Decisions

                      • Budget + red line: p95 target = 16.7ms (one 60fps frame); the hard per-frame red line = 33ms (any single frame over this is a dropped frame and fails the gate).
                      • Trip condition: p95 over a rolling ~2s frame window exceeds 16.7ms continuously for a sustained ~2s trip window, then step down one ease level. Ease ladder: full tempo -> eased/calm (stepping down the tempo ladder toward its slowest) -> motion full-stop -> [terminal] hard-pause to a static blurred field.
                      • Hysteresis (dual-guard): restoring one level up requires BOTH a longer clear window (~2x the trip window) AND p95 at or below a restore threshold set a fixed margin below budget (~13ms), not merely below 16.7ms. Restoration is one level per clear window, never a jump straight back to full.
                      • Terminal valve = the engine's existing hard-pause (rAF stop), leaving the last high-blur frame as a static field; it is the only step past motion-full-stop, and only the return to a met budget (per hysteresis) resumes the loop.
                      • Governor levers, bounded: the governor's ONLY levers are the motion tempo control (from the full-motion slice) and the terminal hard-pause. It has no access to glass blur/tint tokens by construction.
                      • Paused-loop guard: the governor reads the engine's paused state and pauses its own measurement while paused (hidden / off-screen / prefers-reduced-motion), discarding the stalled inter-frame gaps so resume never false-trips the fallback.
                      • Force-full-tempo hook pins full tempo AND disables the governor, so the gate and the headless proxy both measure the un-eased worst case; if that passes on the reference laptop, the governor is a rarely-tripped safety net.
                      • Gate parameters (fixed): reference laptop VS Code webview, battery-powered and pinned before the run, >=40-card thread, >=10s continuous scroll, full Brain tempo, both themes, manual sign-off recorded on the PR. Headless Chromium is a proxy only and never substitutes for the sign-off.
                      • Data contract — governor input: a stream of per-frame durations (ms) plus the engine's current at-rest/active and paused state; output: a discrete motion level in {full, eased-N..., full-stop, hard-paused}. It reads frame times only from the existing loop; it does not run its own painting clock.

                      Constraints & Invariants

                      • The fallback MUST NOT reduce blur radius or tint opacity — ever, at any level (easing, full-stop, hard-pause, or restoring). Blur fidelity is non-negotiable; the frosted look is the protected aesthetic.
                      • Motion is the only give; the ease is discrete-stepwise, never a continuous flicker, and the dual-guard hysteresis must prevent per-window oscillation.
                      • The governor is inert at rest: full blur + full motion always apply when the budget is met; it must never pre-emptively ease.
                      • The headless-Chromium trace is a proxy and MUST NOT be recorded or presented as satisfying the release gate; only manual sign-off on the pinned reference laptop closes it.
                      • One render loop only: the governor observes and steers the existing single rAF loop — it must not spawn a second render loop or a second frame-time clock that itself burns frames.
                      • The governor must pause its own measurement whenever the engine is paused (window hidden, off-screen, or prefers-reduced-motion), so a stalled loop never registers phantom over-budget frames and false-trips the fallback.
                      • Amicode design-system law applies to any dev/gate affordance chrome; browser-first iteration (vite dev on the app), not VSIX rebuilds; npm run lint clean + app typecheck before the PR.
                      Prior Art / Patterns - The old branch's `?brainForceActive` URL param in `brain-atmosphere.tsx` pins the brain at full musical tempo for perf capture — reuse/rename it as the force-full-tempo hook, and extend it to also disable the governor. - The Brain engine's existing hard-pause is the terminal valve: `pause()`/`resume()` in the current `brain-engine.ts` (and `suspend()`/`resume()` in the old-branch `engine.ts`), driving the single rAF loop. - The `TEMPI` tempo ladder (largo -> presto) and the full-motion slice's `setActive` adaptive heartbeat (the old-branch `setActive`) are the motion lever the governor eases — "extends slice 4 test surface." - `glass-tokens.ts` (`GlassTier.blur` / `alpha`) and `glass.css` (`--glass-*-blur` / `-bg`) hold the blur+tint the invariant protects — the governor must never write them. - #56's "Pre-agreed perf fallback" and ADR 0002 set the law: motion is the give, blur fidelity never degrades, the laptop-webview 60fps gate is the real target and headless Chromium is only a proxy.

                      Source

                      Part of #56. Durable record: ADR packages/app/docs/adr/0002-brain-as-chat-background.md.
                      Blocked by #61
                      Blocked by #62

                      Metadata

                      Metadata

                      Assignees

                      No one assigned

                        Labels

                        hitlNeeds a human decision/review

                        Type

                        No type

                        Projects

                        No projects

                          Milestone

                          No milestone

                          Relationships

                          None yet

                          Development

                          No branches or pull requests

                          Issue actions

                          , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
                          Skip to content

                          Add the perf governor (ease motion, never blur) and gate 60fps on the reference laptop #63

                          Description

                          @kateebonner

                          Important

                          Problem

                          The Chat's expensive combination — high-radius backdrop-blur recomputed per frame across many glass cards over an animating Brain, while scrolling — can blow the 60fps budget on a real laptop webview (see #56 for the why). This slice builds the pre-agreed release valve and proves the budget actually holds on real hardware.

                          Approach

                          Add a frame-time governor that observes the single Brain render loop and, only under sustained over-budget load, eases the Brain's motion stepwise (dual-guard hysteresis before restoring, so it never oscillates) down to a full motion stop, then — if that still misses budget — hard-pauses to a static blurred field as the terminal valve. It never touches blur or tint: motion is the only give. The release criterion is a manual 60fps sign-off on the pinned reference laptop webview; a headless-Chromium rAF-interval trace is a pre-gate proxy only. HITL because only a human on the reference machine can close the gate.

                          Scope

                          In: the frame-time monitor + motion-ease governor (trip, ease ladder, hysteresis restore, terminal hard-pause); the paused-loop measurement guard (no phantom over-budget when the engine is paused); the blur/tint-never-degraded invariant; a dev force-full-tempo hook (pins full tempo AND disables the governor); a headless-Chromium rAF-trace proxy harness over a long-thread fixture, both themes; the manual perf-gate checklist + sign-off on the reference laptop, both themes.
                          Out: reducing blur radius or tint under load (the frosted look is the protected aesthetic; motion is the only give); dynamic per-frame backdrop sampling / adaptive-contrast glass (rejected in #56 as the biggest perf risk); the glass tokens and the motion engine themselves (owned by the glassed-components and full-motion slices; this slice only steers and protects them); node-cap / recency bounds and occluded-Panel paint-skipping (separate perf levers on the motion slice, not the release valve); any automated or CI substitute for the reference-laptop run (the gate is a deliberate manual sign-off).


                          Acceptance Criteria

                          • Trip + ease ladder: fed a frame-time sequence whose rolling p95 exceeds the 16.7ms budget continuously for a full sustained trip window, the governor steps the Brain's motion down one ease level (lower tempo); continued over-budget steps it further, down to a full motion stop. Below-budget input never triggers a step-down.
                          • Terminal valve: with motion already at a full stop and p95 still over budget for the sustained window, the governor hard-pauses the render loop to a static blurred field; it never steps past full-stop into any state that keeps painting motion.
                          • Hysteresis / no oscillation: on a frame sequence that hovers at the budget boundary (alternating just-over / just-under across windows), the governor does not change motion level every window; restoring one level up requires p95 to stay at or below the restore threshold (a fixed margin below budget) for the full, longer restore window. A single under-budget window never restores.
                          • Blur/tint invariant: across every governor action (ease, full-stop, hard-pause, restore), the glass blur-radius and tint-opacity tokens are byte-identical before and after; the governor exposes no path that writes a glass token.
                          • Rest = full fidelity: when the frame budget is being met and the engine reports at-rest/breathing, the governor holds motion at full tempo and never pre-emptively eases; full blur + full motion always apply at rest.
                          • Paused-loop inertness (no phantom over-budget): while the engine reports paused (window hidden, off-screen, or prefers-reduced-motion), the governor pauses its own measurement and discards the stalled inter-frame gaps, so a long paused stretch followed by resume never trips a step-down or the terminal hard-pause. Fed multi-second frame gaps tagged paused, the emitted motion level and the engine's pause state are unchanged.
                          • Force-full-tempo hook: enabling the dev hook pins the Brain at full tempo and disables the governor (so a gated run measures the un-eased worst case); disabling it restores normal governed behavior.
                          • Headless proxy harness: a headless-Chromium script loads the app with the force hook, scrolls a >=40-card thread continuously for >=10s in each theme, and emits a report of p95 and max frame time; the report is labeled a pre-gate proxy and its pass does not close the release gate.
                          • Perf gate (manual sign-off): on the reference laptop VS Code webview (battery-powered, pinned before the run), a >=10s continuous scroll of a >=40-card thread at full Brain tempo yields p95 <=16.7ms with zero frames >33ms, in both themes; recorded as a signed-off checklist artifact on the PR before merge.

                          Testing Decisions

                          • CREATE brain-perf-governor unit tests: drive the governor through an injected clock / frame-time source (external behavior = the emitted motion level and the engine's pause state, given frame times in). Cover: step-down ladder to full-stop on sustained over-budget; terminal hard-pause once motion is at full-stop and still over budget; hysteresis on a boundary-hovering sequence (assert no per-window flipping and that restore needs the full longer clear window below the restore threshold); the blur/tint invariant (snapshot the glass tokens before/after a full trip+restore cycle and assert equality); rest-inertness (below-budget + at-rest never eases); paused-loop inertness (feed multi-second gaps tagged paused and assert the motion level and pause state are unchanged — a stalled loop never registers a phantom over-budget frame or trips the fallback). No real rAF or wall clock — feed synthetic frame times.
                          • EXTEND the full-motion slice's engine motion tests ("extends slice 4 test surface"): assert the governor steers the same single tempo control slice 4 exposes and adds no second render loop or second frame-time clock — reuse its tick()/tempo assertions rather than re-deriving tempo behavior.
                          • CREATE a headless perf-trace smoke test: assert the harness boots the app with the force-full-tempo hook, scrolls the >=40-card fixture for >=10s in each theme, and produces a p95 + max-frame-time report object. This asserts the harness runs and reports — it is the pre-gate proxy, not the gate.
                          • Manual gate is not an automated test: it is a documented checklist executed on the reference laptop and signed off on the PR (this is why the slice is HITL). No test asserts the gate's numeric outcome in CI.

                          Key Decisions

                          • Budget + red line: p95 target = 16.7ms (one 60fps frame); the hard per-frame red line = 33ms (any single frame over this is a dropped frame and fails the gate).
                          • Trip condition: p95 over a rolling ~2s frame window exceeds 16.7ms continuously for a sustained ~2s trip window, then step down one ease level. Ease ladder: full tempo -> eased/calm (stepping down the tempo ladder toward its slowest) -> motion full-stop -> [terminal] hard-pause to a static blurred field.
                          • Hysteresis (dual-guard): restoring one level up requires BOTH a longer clear window (~2x the trip window) AND p95 at or below a restore threshold set a fixed margin below budget (~13ms), not merely below 16.7ms. Restoration is one level per clear window, never a jump straight back to full.
                          • Terminal valve = the engine's existing hard-pause (rAF stop), leaving the last high-blur frame as a static field; it is the only step past motion-full-stop, and only the return to a met budget (per hysteresis) resumes the loop.
                          • Governor levers, bounded: the governor's ONLY levers are the motion tempo control (from the full-motion slice) and the terminal hard-pause. It has no access to glass blur/tint tokens by construction.
                          • Paused-loop guard: the governor reads the engine's paused state and pauses its own measurement while paused (hidden / off-screen / prefers-reduced-motion), discarding the stalled inter-frame gaps so resume never false-trips the fallback.
                          • Force-full-tempo hook pins full tempo AND disables the governor, so the gate and the headless proxy both measure the un-eased worst case; if that passes on the reference laptop, the governor is a rarely-tripped safety net.
                          • Gate parameters (fixed): reference laptop VS Code webview, battery-powered and pinned before the run, >=40-card thread, >=10s continuous scroll, full Brain tempo, both themes, manual sign-off recorded on the PR. Headless Chromium is a proxy only and never substitutes for the sign-off.
                          • Data contract — governor input: a stream of per-frame durations (ms) plus the engine's current at-rest/active and paused state; output: a discrete motion level in {full, eased-N..., full-stop, hard-paused}. It reads frame times only from the existing loop; it does not run its own painting clock.

                          Constraints & Invariants

                          • The fallback MUST NOT reduce blur radius or tint opacity — ever, at any level (easing, full-stop, hard-pause, or restoring). Blur fidelity is non-negotiable; the frosted look is the protected aesthetic.
                          • Motion is the only give; the ease is discrete-stepwise, never a continuous flicker, and the dual-guard hysteresis must prevent per-window oscillation.
                          • The governor is inert at rest: full blur + full motion always apply when the budget is met; it must never pre-emptively ease.
                          • The headless-Chromium trace is a proxy and MUST NOT be recorded or presented as satisfying the release gate; only manual sign-off on the pinned reference laptop closes it.
                          • One render loop only: the governor observes and steers the existing single rAF loop — it must not spawn a second render loop or a second frame-time clock that itself burns frames.
                          • The governor must pause its own measurement whenever the engine is paused (window hidden, off-screen, or prefers-reduced-motion), so a stalled loop never registers phantom over-budget frames and false-trips the fallback.
                          • Amicode design-system law applies to any dev/gate affordance chrome; browser-first iteration (vite dev on the app), not VSIX rebuilds; npm run lint clean + app typecheck before the PR.
                          Prior Art / Patterns - The old branch's `?brainForceActive` URL param in `brain-atmosphere.tsx` pins the brain at full musical tempo for perf capture — reuse/rename it as the force-full-tempo hook, and extend it to also disable the governor. - The Brain engine's existing hard-pause is the terminal valve: `pause()`/`resume()` in the current `brain-engine.ts` (and `suspend()`/`resume()` in the old-branch `engine.ts`), driving the single rAF loop. - The `TEMPI` tempo ladder (largo -> presto) and the full-motion slice's `setActive` adaptive heartbeat (the old-branch `setActive`) are the motion lever the governor eases — "extends slice 4 test surface." - `glass-tokens.ts` (`GlassTier.blur` / `alpha`) and `glass.css` (`--glass-*-blur` / `-bg`) hold the blur+tint the invariant protects — the governor must never write them. - #56's "Pre-agreed perf fallback" and ADR 0002 set the law: motion is the give, blur fidelity never degrades, the laptop-webview 60fps gate is the real target and headless Chromium is only a proxy.

                          Source

                          Part of #56. Durable record: ADR packages/app/docs/adr/0002-brain-as-chat-background.md.
                          Blocked by #61
                          Blocked by #62

                          Metadata

                          Metadata

                          Assignees

                          No one assigned

                            Labels

                            hitlNeeds a human decision/review

                            Type

                            No type

                            Projects

                            No projects

                              Milestone

                              No milestone

                              Relationships

                              None yet

                              Development

                              No branches or pull requests

                              Issue actions

                              , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
                              Skip to content

                              Add the perf governor (ease motion, never blur) and gate 60fps on the reference laptop #63

                              Description

                              @kateebonner

                              Important

                              Problem

                              The Chat's expensive combination — high-radius backdrop-blur recomputed per frame across many glass cards over an animating Brain, while scrolling — can blow the 60fps budget on a real laptop webview (see #56 for the why). This slice builds the pre-agreed release valve and proves the budget actually holds on real hardware.

                              Approach

                              Add a frame-time governor that observes the single Brain render loop and, only under sustained over-budget load, eases the Brain's motion stepwise (dual-guard hysteresis before restoring, so it never oscillates) down to a full motion stop, then — if that still misses budget — hard-pauses to a static blurred field as the terminal valve. It never touches blur or tint: motion is the only give. The release criterion is a manual 60fps sign-off on the pinned reference laptop webview; a headless-Chromium rAF-interval trace is a pre-gate proxy only. HITL because only a human on the reference machine can close the gate.

                              Scope

                              In: the frame-time monitor + motion-ease governor (trip, ease ladder, hysteresis restore, terminal hard-pause); the paused-loop measurement guard (no phantom over-budget when the engine is paused); the blur/tint-never-degraded invariant; a dev force-full-tempo hook (pins full tempo AND disables the governor); a headless-Chromium rAF-trace proxy harness over a long-thread fixture, both themes; the manual perf-gate checklist + sign-off on the reference laptop, both themes.
                              Out: reducing blur radius or tint under load (the frosted look is the protected aesthetic; motion is the only give); dynamic per-frame backdrop sampling / adaptive-contrast glass (rejected in #56 as the biggest perf risk); the glass tokens and the motion engine themselves (owned by the glassed-components and full-motion slices; this slice only steers and protects them); node-cap / recency bounds and occluded-Panel paint-skipping (separate perf levers on the motion slice, not the release valve); any automated or CI substitute for the reference-laptop run (the gate is a deliberate manual sign-off).


                              Acceptance Criteria

                              • Trip + ease ladder: fed a frame-time sequence whose rolling p95 exceeds the 16.7ms budget continuously for a full sustained trip window, the governor steps the Brain's motion down one ease level (lower tempo); continued over-budget steps it further, down to a full motion stop. Below-budget input never triggers a step-down.
                              • Terminal valve: with motion already at a full stop and p95 still over budget for the sustained window, the governor hard-pauses the render loop to a static blurred field; it never steps past full-stop into any state that keeps painting motion.
                              • Hysteresis / no oscillation: on a frame sequence that hovers at the budget boundary (alternating just-over / just-under across windows), the governor does not change motion level every window; restoring one level up requires p95 to stay at or below the restore threshold (a fixed margin below budget) for the full, longer restore window. A single under-budget window never restores.
                              • Blur/tint invariant: across every governor action (ease, full-stop, hard-pause, restore), the glass blur-radius and tint-opacity tokens are byte-identical before and after; the governor exposes no path that writes a glass token.
                              • Rest = full fidelity: when the frame budget is being met and the engine reports at-rest/breathing, the governor holds motion at full tempo and never pre-emptively eases; full blur + full motion always apply at rest.
                              • Paused-loop inertness (no phantom over-budget): while the engine reports paused (window hidden, off-screen, or prefers-reduced-motion), the governor pauses its own measurement and discards the stalled inter-frame gaps, so a long paused stretch followed by resume never trips a step-down or the terminal hard-pause. Fed multi-second frame gaps tagged paused, the emitted motion level and the engine's pause state are unchanged.
                              • Force-full-tempo hook: enabling the dev hook pins the Brain at full tempo and disables the governor (so a gated run measures the un-eased worst case); disabling it restores normal governed behavior.
                              • Headless proxy harness: a headless-Chromium script loads the app with the force hook, scrolls a >=40-card thread continuously for >=10s in each theme, and emits a report of p95 and max frame time; the report is labeled a pre-gate proxy and its pass does not close the release gate.
                              • Perf gate (manual sign-off): on the reference laptop VS Code webview (battery-powered, pinned before the run), a >=10s continuous scroll of a >=40-card thread at full Brain tempo yields p95 <=16.7ms with zero frames >33ms, in both themes; recorded as a signed-off checklist artifact on the PR before merge.

                              Testing Decisions

                              • CREATE brain-perf-governor unit tests: drive the governor through an injected clock / frame-time source (external behavior = the emitted motion level and the engine's pause state, given frame times in). Cover: step-down ladder to full-stop on sustained over-budget; terminal hard-pause once motion is at full-stop and still over budget; hysteresis on a boundary-hovering sequence (assert no per-window flipping and that restore needs the full longer clear window below the restore threshold); the blur/tint invariant (snapshot the glass tokens before/after a full trip+restore cycle and assert equality); rest-inertness (below-budget + at-rest never eases); paused-loop inertness (feed multi-second gaps tagged paused and assert the motion level and pause state are unchanged — a stalled loop never registers a phantom over-budget frame or trips the fallback). No real rAF or wall clock — feed synthetic frame times.
                              • EXTEND the full-motion slice's engine motion tests ("extends slice 4 test surface"): assert the governor steers the same single tempo control slice 4 exposes and adds no second render loop or second frame-time clock — reuse its tick()/tempo assertions rather than re-deriving tempo behavior.
                              • CREATE a headless perf-trace smoke test: assert the harness boots the app with the force-full-tempo hook, scrolls the >=40-card fixture for >=10s in each theme, and produces a p95 + max-frame-time report object. This asserts the harness runs and reports — it is the pre-gate proxy, not the gate.
                              • Manual gate is not an automated test: it is a documented checklist executed on the reference laptop and signed off on the PR (this is why the slice is HITL). No test asserts the gate's numeric outcome in CI.

                              Key Decisions

                              • Budget + red line: p95 target = 16.7ms (one 60fps frame); the hard per-frame red line = 33ms (any single frame over this is a dropped frame and fails the gate).
                              • Trip condition: p95 over a rolling ~2s frame window exceeds 16.7ms continuously for a sustained ~2s trip window, then step down one ease level. Ease ladder: full tempo -> eased/calm (stepping down the tempo ladder toward its slowest) -> motion full-stop -> [terminal] hard-pause to a static blurred field.
                              • Hysteresis (dual-guard): restoring one level up requires BOTH a longer clear window (~2x the trip window) AND p95 at or below a restore threshold set a fixed margin below budget (~13ms), not merely below 16.7ms. Restoration is one level per clear window, never a jump straight back to full.
                              • Terminal valve = the engine's existing hard-pause (rAF stop), leaving the last high-blur frame as a static field; it is the only step past motion-full-stop, and only the return to a met budget (per hysteresis) resumes the loop.
                              • Governor levers, bounded: the governor's ONLY levers are the motion tempo control (from the full-motion slice) and the terminal hard-pause. It has no access to glass blur/tint tokens by construction.
                              • Paused-loop guard: the governor reads the engine's paused state and pauses its own measurement while paused (hidden / off-screen / prefers-reduced-motion), discarding the stalled inter-frame gaps so resume never false-trips the fallback.
                              • Force-full-tempo hook pins full tempo AND disables the governor, so the gate and the headless proxy both measure the un-eased worst case; if that passes on the reference laptop, the governor is a rarely-tripped safety net.
                              • Gate parameters (fixed): reference laptop VS Code webview, battery-powered and pinned before the run, >=40-card thread, >=10s continuous scroll, full Brain tempo, both themes, manual sign-off recorded on the PR. Headless Chromium is a proxy only and never substitutes for the sign-off.
                              • Data contract — governor input: a stream of per-frame durations (ms) plus the engine's current at-rest/active and paused state; output: a discrete motion level in {full, eased-N..., full-stop, hard-paused}. It reads frame times only from the existing loop; it does not run its own painting clock.

                              Constraints & Invariants

                              • The fallback MUST NOT reduce blur radius or tint opacity — ever, at any level (easing, full-stop, hard-pause, or restoring). Blur fidelity is non-negotiable; the frosted look is the protected aesthetic.
                              • Motion is the only give; the ease is discrete-stepwise, never a continuous flicker, and the dual-guard hysteresis must prevent per-window oscillation.
                              • The governor is inert at rest: full blur + full motion always apply when the budget is met; it must never pre-emptively ease.
                              • The headless-Chromium trace is a proxy and MUST NOT be recorded or presented as satisfying the release gate; only manual sign-off on the pinned reference laptop closes it.
                              • One render loop only: the governor observes and steers the existing single rAF loop — it must not spawn a second render loop or a second frame-time clock that itself burns frames.
                              • The governor must pause its own measurement whenever the engine is paused (window hidden, off-screen, or prefers-reduced-motion), so a stalled loop never registers phantom over-budget frames and false-trips the fallback.
                              • Amicode design-system law applies to any dev/gate affordance chrome; browser-first iteration (vite dev on the app), not VSIX rebuilds; npm run lint clean + app typecheck before the PR.
                              Prior Art / Patterns - The old branch's `?brainForceActive` URL param in `brain-atmosphere.tsx` pins the brain at full musical tempo for perf capture — reuse/rename it as the force-full-tempo hook, and extend it to also disable the governor. - The Brain engine's existing hard-pause is the terminal valve: `pause()`/`resume()` in the current `brain-engine.ts` (and `suspend()`/`resume()` in the old-branch `engine.ts`), driving the single rAF loop. - The `TEMPI` tempo ladder (largo -> presto) and the full-motion slice's `setActive` adaptive heartbeat (the old-branch `setActive`) are the motion lever the governor eases — "extends slice 4 test surface." - `glass-tokens.ts` (`GlassTier.blur` / `alpha`) and `glass.css` (`--glass-*-blur` / `-bg`) hold the blur+tint the invariant protects — the governor must never write them. - #56's "Pre-agreed perf fallback" and ADR 0002 set the law: motion is the give, blur fidelity never degrades, the laptop-webview 60fps gate is the real target and headless Chromium is only a proxy.

                              Source

                              Part of #56. Durable record: ADR packages/app/docs/adr/0002-brain-as-chat-background.md.
                              Blocked by #61
                              Blocked by #62

                              Metadata

                              Metadata

                              Assignees

                              No one assigned

                                Labels

                                hitlNeeds a human decision/review

                                Type

                                No type

                                Projects

                                No projects

                                  Milestone

                                  No milestone

                                  Relationships

                                  None yet

                                  Development

                                  No branches or pull requests

                                  Issue actions