← Back to Pull requests

fix(desktop): keep Kaipu in the Dock and Cmd+Tab after recording and camera toggles #366

Merged
csdev19 merged 12 files (487 lines) on Oct 25, 2026 02:21 UTC
View on GitHub
csdev19 csdev19 commented on Oct 25, 2026 01:08 UTC
Author

What

On macOS, Kaipu dropped out of the Dock and ⌘-Tab after the first recording of a session and after every camera toggle. The app kept working; only toggling Show in Dock & app switcher off and on brought it back. Reported on desktop 0.14.1.

Why

Two defects together (full chain in ADR 0029):

1. control-bar-window.ts and camera-bubble-window.ts called setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }) without skipTransformProcessType. Electron 39 then runs app.dock.hide() (Browser::DockHide → TransformProcessType(kProcessTransformToUIElementApplication)) to get a plain window over a full-screen app. That removes the Dock icon and the ⌘-Tab entry.
2. Since #255 (2026-10-07, "apply the macOS activation policy only on an actual transition") the policy setter skips any call that matches its cache. The cache said regular the whole time, so forceRegularPolicy() at start, applyDockPolicy() at stop, after the camera toggle and from ⌘⌃O were all no-ops. Before that fix the bug was masked by accident: app.dock.show() ran under a second before the bar was created, and Electron ignores a DockHide that lands within a second of a DockShow.

Fix

  • Both recording panels are type: "panel" on macOS and pass skipTransformProcessType: true — the recipe the capture panel, overlays and toast already use.

  • The setter treats a call as unchanged only when its cache and app.dock.isVisible() (Electron reads the real NSRunningApplication.activationPolicy) agree. A Dock dropped behind its back is restored at the next re-assertion; a matching re-assertion still touches no AppKit state, so the blur fix stays intact.
  • Docs

  • ADR 0029 — floating windows never change the activation policy, and the policy setter checks AppKit before skipping (with reopen conditions).

  • Backlog page bug-app-lost-from-app-switcher (🟢 Ready to validate) with owner validation steps; follow-up note on bug-main-window-hides-on-blur; both pages added to the sidebar.
  • Verification

  • New tests: floating-window-policy.test.ts, plus cases in settings-store.test.ts and recording-hub.test.ts. All five fail on the previous sources and pass now.

  • Desktop suite: 258 files, 2239 tests green. check-types, oxlint, oxfmt clean on touched files. Docs site builds.
  • Owner QA (packaged build)

    1. Record once and stop; repeat with the camera on/off. Kaipu stays in ⌘-Tab and the Dock.
    2. Put another app in full screen and record it: the bar and bubble float over it, drag, and the bar's buttons respond without pulling the main window forward. This is the one behaviour I could not verify from here — the panels are now non-activating NSPanels.
    3. With the Dock setting off: record and stop; the app stays menu-bar only.
    4. ⌘⌃O brings the main window forward in every state above.

    🤖 Generated with Claude Code

    Diff: 487 lines (+477 / -10) across 12 files Reviewer: csdev19 Review duration: 73m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.70) × (1 − Review Confidence (0.79)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.70 · 487 lines diff across 12 files
    0.70
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.89 · 4 substantive comment(s)
    0.89
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    79%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.370
    Self Review self_review
    0.140
    Real PR Conversation Timeline
    6 items
    github-actions[bot] github-actions[bot] commented on code on Oct 25, 2026 01:08 UTC
    Code Review
    apps/kaipu-record/src/main/infrastructure/settings-store.ts:1
    @@ -77,19 +77,36 @@ type ActivationPolicy = "regular" | "accessory";
      */
     let appliedPolicy: ActivationPolicy | null = null;
     
    +/**
    + * Whether the process is a regular (Dock + Cmd+Tab) app right now, as AppKit
    + * sees it. Electron answers from NSRunningApplication's activation policy, so
    + * this reflects transforms made outside this module — the `app.dock.hide()`
    + * that `setVisibleOnAllWorkspaces(..., { visibleOnFullScreen: true })` runs
    + * unless `skipTransformProcessType` is set. See ADR 0029.
    + */
    +function isRegularNow(): boolean {
    +  return app.dock?.isVisible() ?? true;
    +}
    +
     function setActivationPolicy(policy: ActivationPolicy): void {
       if (process.platform !== "darwin") return;
    -  if (appliedPolicy === policy) return;
    +  // "Unchanged" is decided against the real process state, not the cache alone.
    +  // The cache by itself turned a Dock drop made outside this module into a
    +  // permanent one: the app vanished from Cmd+Tab after the first recording and
    +  // every re-assertion (stop, the rescue shortcut) was a no-op. See
    +  // backlog/bug-app-lost-from-app-switcher. The probe keeps the no-churn
    +  // property: a re-assertion that matches reality still touches nothing.
    +  if (appliedPolicy === policy && (policy === "regular") === isRegularNow()) return;

    Note (correctness): isVisible() probe may lag right after dock.show(), risking repeated show

    The ADR itself notes app.dock.isVisible() can lag after DockShow. If a re-assertion (e.g. recording stop followed closely by applyDockPolicy()/⌘⌃O) lands in that window, the probe reports not-regular and the setter calls app.dock.show() again on an active app. That is the window-churn this cache was introduced to prevent. The ADR calls this theoretical because setActivationPolicy runs synchronously first. It is untested against real AppKit, so keep it on the owner QA list (rapid start/stop and camera toggles).

    github-actions[bot] github-actions[bot] commented on code on Oct 25, 2026 01:08 UTC
    Code Review
    apps/documentation/src/content/docs/architecture/decisions/index.mdx:1
    @@ -13,6 +13,7 @@ Newest first.
     
     | ADR                                                               | Title                                                                                                                       | Status                                                       | Date       |
     | ----------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | ---------- |
    +| [0029](0029-floating-windows-never-change-the-activation-policy)  | Floating windows never change the activation policy, and the policy setter checks AppKit before skipping                    | Proposed — implemented, owner QA pending                     | 2026-10-24 |

    Note (adr): ADR 0029 status differs between the index and the ADR page

    The index lists 0029 as "Proposed — implemented, owner QA pending". The ADR page's status row says "Implemented on fix/dock-lost-after-floating-panels; owner QA outstanding". It also names a branch, which will go stale after merge. Use one status vocabulary in both places and drop the branch name.

    github-actions[bot] github-actions[bot] commented on Oct 25, 2026 01:08 UTC
    Reviewer

    Claude review of the whole pull request, at 9f67c3c: all 12 files reviewed.

    2 finding(s), 0 to fix; 2 on their lines. Reply in a comment's thread to answer it.

    Summary

    I found no blocking correctness or security problems in this PR. The settings-store probe, the two panel changes, the tests and the docs are consistent with each other. I left two notes. One is the app.dock.isVisible() lag risk, which only owner QA on a packaged build can settle. The other is that the ADR status wording differs between the index and the ADR page.

    <sub>Claude Sonnet 5.5 · $0.12</sub>

    <!-- claude-review sha=9f67c3c7947b9e0ee413a4fa5ec01c1ca481dcea -->

    csdev19 csdev19 commented on code on Oct 25, 2026 01:12 UTC
    Code Review
    apps/kaipu-record/src/main/infrastructure/settings-store.ts:1
    @@ -77,19 +77,36 @@ type ActivationPolicy = "regular" | "accessory";
      */
     let appliedPolicy: ActivationPolicy | null = null;
     
    +/**
    + * Whether the process is a regular (Dock + Cmd+Tab) app right now, as AppKit
    + * sees it. Electron answers from NSRunningApplication's activation policy, so
    + * this reflects transforms made outside this module — the `app.dock.hide()`
    + * that `setVisibleOnAllWorkspaces(..., { visibleOnFullScreen: true })` runs
    + * unless `skipTransformProcessType` is set. See ADR 0029.
    + */
    +function isRegularNow(): boolean {
    +  return app.dock?.isVisible() ?? true;
    +}
    +
     function setActivationPolicy(policy: ActivationPolicy): void {
       if (process.platform !== "darwin") return;
    -  if (appliedPolicy === policy) return;
    +  // "Unchanged" is decided against the real process state, not the cache alone.
    +  // The cache by itself turned a Dock drop made outside this module into a
    +  // permanent one: the app vanished from Cmd+Tab after the first recording and
    +  // every re-assertion (stop, the rescue shortcut) was a no-op. See
    +  // backlog/bug-app-lost-from-app-switcher. The probe keeps the no-churn
    +  // property: a re-assertion that matches reality still touches nothing.
    +  if (appliedPolicy === policy && (policy === "regular") === isRegularNow()) return;

    Measured rather than argued, on Electron 39.8.10 against real AppKit (a throwaway script creating the same windows): app.dock.isVisible() reads true immediately after app.setActivationPolicy("regular"), before app.dock.show() runs, and stays true at 1, 5, 20, 100 and 300 ms. The lag Electron documents is the transform it dispatches 1 ms later inside DockShow; the setter calls setActivationPolicy first, so a re-assertion landing in that window sees cache and probe agree and touches nothing — a repeated dock.show() cannot come from the probe. The same run confirmed the cause (a plain window joining full-screen Spaces without the flag flips the probe to false at once) and the recipe (a panel with the flag leaves it true). Recorded in bda1ea95: the ADR now states the measurement instead of calling the window theoretical, and the backlog QA list gains the rapid start/stop and camera-toggle step you asked for.

    csdev19 csdev19 commented on code on Oct 25, 2026 01:12 UTC
    Code Review
    apps/documentation/src/content/docs/architecture/decisions/index.mdx:1
    @@ -13,6 +13,7 @@ Newest first.
     
     | ADR                                                               | Title                                                                                                                       | Status                                                       | Date       |
     | ----------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | ---------- |
    +| [0029](0029-floating-windows-never-change-the-activation-policy)  | Floating windows never change the activation policy, and the policy setter checks AppKit before skipping                    | Proposed — implemented, owner QA pending                     | 2026-10-24 |

    Fixed in 17eb1cbf: both the index row and the ADR status row now read "Proposed — implemented in #366, owner QA pending"; the branch name is gone.

    Reviewers
    Assignees
    csdev19 csdev19
    Labels
    risk: low confidence: 79.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 70.2% (HIGH) · Higher = larger blast radius
    70.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 79.3% · Lower = rushed or shallow review
    79.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.5% · Safe to merge
    14.5%