The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): read the primary view's turn-busy directly, no `$petBusy` alias
kshitijk4poor82e87e9ff53b
diff --git a/apps/desktop/src/store/pet-overlay.ts b/apps/desktop/src/store/pet-overlay.tsindex 2ea6b332cec..532634adcdf 100644--- a/apps/desktop/src/store/pet-overlay.ts+++ b/apps/desktop/src/store/pet-overlay.ts@@ -1,16 +1,8 @@import { atom } from 'nanostores'+import { PRIMARY_SESSION_VIEW } from '@/app/chat/session-view'import { persistBoolean, persistString, storedBoolean, storedString } from '@/lib/storage'-import {- $petActivity,- $petBusy,- $petInfo,- $petUnread,- clearPetUnread,- type PetActivity,- type PetInfo-} from '@/store/pet'-import { $awaitingResponse } from '@/store/session'+import { $petActivity, $petInfo, $petUnread, clearPetUnread, type PetActivity, type PetInfo } from '@/store/pet'/*** Controller for the pop-out pet overlay (main-renderer side).@@ -23,8 +15,8 @@ import { $awaitingResponse } from '@/store/session'* in, submit a composer message) via `onControl`.** The overlay renders the same `PetSprite` / `PetBubble` as the in-window pet by- * mirroring the four reactive inputs of `$petState` (`$petInfo`, `$petActivity`,- * `$busy`, `$awaitingResponse`) into its own copies of those atoms — so the+ * mirroring the reactive inputs of `$petState` (`$petInfo`, `$petActivity`, the+ * primary view's turn-busy and awaiting-response) into its own copies of those atoms — so the* popped-out mascot is pixel-identical and needs zero bespoke render logic.*/@@ -152,8 +144,8 @@ function currentPayload(): PetOverlayStatePayload {return {info: $petInfo.get(),activity: $petActivity.get(),- busy: $petBusy.get(),- awaiting: $awaitingResponse.get(),+ busy: PRIMARY_SESSION_VIEW.$busy.get(),+ awaiting: PRIMARY_SESSION_VIEW.$awaitingResponse.get(),unread: $petUnread.get(),reaction: $petReaction.get()}@@ -189,8 +181,8 @@ function openOverlay(request: PetOverlayOpenRequest): void {stateUnsubs = [$petInfo.subscribe(pushNow),$petActivity.subscribe(pushNow),- $petBusy.subscribe(pushNow),- $awaitingResponse.subscribe(pushNow),+ PRIMARY_SESSION_VIEW.$busy.subscribe(pushNow),+ PRIMARY_SESSION_VIEW.$awaitingResponse.subscribe(pushNow),$petUnread.subscribe(pushNow),$petReaction.subscribe(pushNow)]diff --git a/apps/desktop/src/store/pet.test.ts b/apps/desktop/src/store/pet.test.tsindex 51396f8b956..a2b972829fc 100644--- a/apps/desktop/src/store/pet.test.ts+++ b/apps/desktop/src/store/pet.test.ts@@ -160,23 +160,17 @@ describe('$petState reads the active runtime slice, not the $busy mirror (#84434$petActivity.set({})})- it('animates a running tool while the active slice is busy even though $busy reads false', () => {+ it('follows the active slice, not the $busy mirror: runs while it is busy, idles the moment it settles', () => {$activeSessionId.set(runtimeId)publishSessionState(runtimeId, slice(true))$petActivity.set({ toolRunning: true })expect($petState.get()).toBe('run')expect($petAtRest.get()).toBe(false)- })-- it('drops to idle the moment the slice settles, even if no event cleared the steady flag', () => {- $activeSessionId.set(runtimeId)- publishSessionState(runtimeId, slice(true))- $petActivity.set({ toolRunning: true })- expect($petState.get()).toBe('run')// An interrupted turn flips busy→false without a tool.complete / message.complete.publishSessionState(runtimeId, slice(false))expect($petState.get()).toBe('idle')+ expect($petAtRest.get()).toBe(true)})})diff --git a/apps/desktop/src/store/pet.ts b/apps/desktop/src/store/pet.tsindex cfd9fdf44df..e009b8121ca 100644--- a/apps/desktop/src/store/pet.ts+++ b/apps/desktop/src/store/pet.ts@@ -186,7 +186,7 @@ export const setPetInfo = (info: PetInfo) => $petInfo.set(info)/*** Resolve the live activity state from the dedicated activity atom, falling back- * to the always-present `$busy` chat signal so the pet reacts out of the box.+ * to the primary session view's turn-busy so the pet reacts out of the box.** `awaitingInput` (a clarify/approval blocking on the user) is an explicit flag* on `$petActivity` — set by the controller from `$attentionSessionIds` and@@ -209,17 +209,6 @@ function deriveLivePetState(activity: PetActivity, busy: boolean): PetState {})}-/**- * Turn-busy of the session the pet is watching. The active runtime's own- * `$sessionStates` slice is authoritative; the global `$busy` mirror is an- * RAF-batched copy that can stay false for a whole turn (reclaimed session- * reopened after idle timeout, desktop-minted draft — #84434 / #84438) and is- * a leftover from whichever session last published while a stored session- * has no slice yet. Shared with the pop-out overlay push so both surfaces- * derive the pose from the same signal.- */-export const $petBusy = PRIMARY_SESSION_VIEW.$busy-/*** Opt-in: let the floating mascot wander around the window on its own while* idle. Pure desktop-client behavior (no agent/config dependency), so it lives@@ -253,8 +242,12 @@ export const $petRoamDir = atom<-1 | 0 | 1>(0)* on this — never on `$petState` itself, which would feed back on its own* `$petMotion`-driven pose and stall the wander.*/+// Turn-busy comes from the active runtime's own slice (`$primaryBusy` in+// session-view.tsx explains why the global `$busy` mirror can't be trusted:+// #84434 / #84438). The pop-out overlay push reads the same atom so both+// surfaces derive the pose from one signal.export const $petAtRest = computed(- [$petActivity, $petBusy],+ [$petActivity, PRIMARY_SESSION_VIEW.$busy],(activity, busy): boolean => deriveLivePetState(activity, busy) === 'idle')@@ -263,8 +256,11 @@ export const $petAtRest = computed(* a roam pose (walking → `run`, hopping → `jump`) show through, so the wander* reads as deliberate movement.*/-export const $petState = computed([$petActivity, $petBusy, $petMotion], (activity, busy, motion): PetState => {- const base = deriveLivePetState(activity, busy)+export const $petState = computed(+ [$petActivity, PRIMARY_SESSION_VIEW.$busy, $petMotion],+ (activity, busy, motion): PetState => {+ const base = deriveLivePetState(activity, busy)- return base === 'idle' && motion ? motion : base-})+ return base === 'idle' && motion ? motion : base+ }+)