Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(ide): a stranded drop overlay can no longer outlive the drag that raised it
rubenluetke10-beep3bf085833a4a
diff --git a/jarvis/ui/web/frontend/src/components/JarvisDock.tsx b/jarvis/ui/web/frontend/src/components/JarvisDock.tsxindex 1bd64fdb22..7f44995bfd 100644--- a/jarvis/ui/web/frontend/src/components/JarvisDock.tsx+++ b/jarvis/ui/web/frontend/src/components/JarvisDock.tsx@@ -1,4 +1,5 @@-import { useEffect, useRef, useState } from "react";+import { useCallback, useEffect, useRef, useState } from "react";+import { useDragSessionEnd } from "@/components/agentic/dragSessionEnd";import { getWSClient } from "@/hooks/useWebSocket";import { useOverlayStyle } from "@/hooks/useOverlayStyle";import { useEventStore } from "@/store/events";@@ -75,34 +76,13 @@ export function JarvisDock() {);// A native OS drag that leaves the window (or ends anywhere) must disarm the- // dock. The full-window catch layer has no dragleave of its own, so without- // this the bloom could stick after the cursor exits the window over the catch- // layer. Wired only while a file drag is armed.- useEffect(() => {- if (!fileArmed) return;- const disarm = () => setFileArmed(false);- const onWindowDragLeave = (e: DragEvent) => {- // relatedTarget === null + a viewport-edge cursor = the drag left the- // window entirely (not just moved between elements inside it).- if (- e.relatedTarget === null &&- (e.clientX <= 0 ||- e.clientY <= 0 ||- e.clientX >= window.innerWidth ||- e.clientY >= window.innerHeight)- ) {- setFileArmed(false);- }- };- window.addEventListener("drop", disarm);- window.addEventListener("dragend", disarm);- window.addEventListener("dragleave", onWindowDragLeave);- return () => {- window.removeEventListener("drop", disarm);- window.removeEventListener("dragend", disarm);- window.removeEventListener("dragleave", onWindowDragLeave);- };- }, [fileArmed]);+ // dock. The full-window catch layer has no dragleave of its own, and a drag+ // that ends outside the window sends no `drop` or `dragend` either, so the+ // end of the drag is detected by the heartbeat going quiet rather than+ // awaited (see components/agentic/dragSessionEnd, BUG-167). Wired only while+ // a file drag is armed.+ const disarmFile = useCallback(() => setFileArmed(false), []);+ useDragSessionEnd(fileArmed, disarmFile);/** Parse + dispatch the dropped mission. Shared by the dock and the catch* layer so a release anywhere near Jarvis behaves identically. */diff --git a/jarvis/ui/web/frontend/src/components/agentic/FolderPicker.tsx b/jarvis/ui/web/frontend/src/components/agentic/FolderPicker.tsxindex 434592fcaa..bc3e5b3faa 100644--- a/jarvis/ui/web/frontend/src/components/agentic/FolderPicker.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/FolderPicker.tsx@@ -56,6 +56,7 @@ import {} from "lucide-react";import { cn } from "@/lib/utils";import { waitForNativeDrop } from "@/lib/nativeDrop";+import { useDragSessionEnd } from "./dragSessionEnd";import { Button, Field, IconButton, SectionLabel } from "./controls";import {fetchFolders,@@ -333,6 +334,15 @@ export function FolderPicker({.catch((e) => setDropNote((e as Error).message));};+ // The same backstop every other drop target in the app needs: a drag that+ // ends outside the window sends no `dragleave`, `drop` or `dragend`, and the+ // highlight would otherwise sit over the folder list for good (BUG-167).+ const clearDragOver = useCallback(() => {+ dragDepth.current = 0;+ setDragOver(false);+ }, []);+ useDragSessionEnd(dragOver, clearDragOver);+const searchingMachine = searchHits !== null;return (diff --git a/jarvis/ui/web/frontend/src/components/agentic/VoiceBubble.tsx b/jarvis/ui/web/frontend/src/components/agentic/VoiceBubble.tsxindex 16a0737e5e..0d1569dd38 100644--- a/jarvis/ui/web/frontend/src/components/agentic/VoiceBubble.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/VoiceBubble.tsx@@ -85,6 +85,7 @@ import {isEmptyPayload,type PaneDropPayload,} from "./paneDrop";+import { useDragSessionEnd } from "./dragSessionEnd";import { VoiceOrb } from "./VoiceOrb";import { VoiceBubbleNotice } from "./VoiceBubbleNotice";import { useVoiceCall } from "./useVoiceCall";@@ -391,18 +392,12 @@ export function VoiceBubble({};}, [active, mounted]);- // A drag may leave the app without sending the orb a final dragleave.- // Clear only the hover state; reading/ready are real work and must remain.- useEffect(() => {- if (dropPhase !== "over") return;- const clear = () => setDropPhase("idle");- window.addEventListener("drop", clear);- window.addEventListener("dragend", clear);- return () => {- window.removeEventListener("drop", clear);- window.removeEventListener("dragend", clear);- };- }, [dropPhase]);+ // A drag may leave the app without sending the orb a final dragleave — and+ // without a `drop` or `dragend` either, when it ends outside the window+ // (BUG-167). Clear only the hover state; reading/ready are real work and+ // must remain.+ const clearDropHover = useCallback(() => setDropPhase("idle"), []);+ useDragSessionEnd(dropPhase === "over", clearDropHover);// ------------------------------------------------------------------ voiceconst closeBubble = useCallback(() => {diff --git a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceBar.tsx b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceBar.tsxindex 5e391a3a1b..a4375ef299 100644--- a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceBar.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceBar.tsx@@ -25,12 +25,13 @@* another one — it addresses the workspace by name instead of making the user* switch first, drop second, and remember which pane had focus.*/-import { useEffect, useRef, useState } from "react";+import { useCallback, useEffect, useRef, useState } from "react";import { Check, FolderGit2, Pencil, Plus, X } from "lucide-react";import { useT } from "@/i18n";import { cn } from "@/lib/utils";import type { WorkspaceCard } from "@/lib/agenticIdeApi";import { dragCarriesFiles, extractPaneDrop, type PaneDropPayload } from "./paneDrop";+import { useDragSessionEnd } from "./dragSessionEnd";/** Names remain useful through six tabs; after that, numbered icons scan better. */const COMPACT_FROM_WORKSPACES = 7;@@ -127,19 +128,13 @@ export function WorkspaceBar({const workspaceIdKey = workspaces.map((workspace) => workspace.id).join("\u0000");const full = maxWorkspaces !== null && workspaces.length >= maxWorkspaces;- // A drag that ends anywhere else owes this bar no `dragleave`, and a tab left+ // A drag that ends anywhere else owes this bar no `dragleave` — and no+ // `drop` or `dragend` either, once it ends outside the window. A tab left// highlighted over a workspace nobody dropped on is a lie about what will- // happen next. Watched globally, and only while something is actually armed.- useEffect(() => {- if (dropTarget === null) return;- const clear = () => setDropTarget(null);- window.addEventListener("drop", clear);- window.addEventListener("dragend", clear);- return () => {- window.removeEventListener("drop", clear);- window.removeEventListener("dragend", clear);- };- }, [dropTarget]);+ // happen next, so the end of the drag is detected rather than awaited (see+ // ./dragSessionEnd, BUG-167).+ const clearDropTarget = useCallback(() => setDropTarget(null), []);+ useDragSessionEnd(dropTarget !== null, clearDropTarget);/** Drag-drop handlers for one tab. Empty when the owner takes no drops. */const dropHandlersFor = (workspace: WorkspaceCard) => {diff --git a/jarvis/ui/web/frontend/src/components/agentic/dragSessionEnd.ts b/jarvis/ui/web/frontend/src/components/agentic/dragSessionEnd.tsnew file mode 100644index 0000000000..31801829e1--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/dragSessionEnd.ts@@ -0,0 +1,154 @@+/**+ * When a file drag is OVER — the one question every drop target in the app has+ * to answer, and the one the browser answers unreliably.+ *+ * Arming a drop zone is easy: `dragenter` says a drag arrived. Disarming it is+ * where the platform stops cooperating, because every event that is supposed+ * to mean "the drag ended" can go missing:+ *+ * * **`drop` fires only if the release happened in THIS document.** Let go over+ * another window, another application, or the desktop and the page hears+ * nothing at all.+ * * **`dragend` fires only on the drag's SOURCE element.** A drag out of+ * Explorer or Finder has no source in this page, so this never arrives for+ * exactly the drags a terminal pane cares about.+ * * **`dragleave` is not owed to a target the drag did not leave by moving.**+ * Escape, a release outside the window, or a drag captured by another window+ * all end the drag with the cursor still logically over the pane.+ *+ * Targets used to paper over this with one heuristic — a `dragleave` whose+ * `relatedTarget` is null while the cursor sits at the viewport edge — which+ * covers a drag dragged slowly out of the window and nothing else. Everything+ * else left the overlay standing over a live agent until the page was+ * reloaded, and because a pane's enter/leave counter was left non-zero too, no+ * later drag could ever take it back down: the pane stayed armed for the rest+ * of the session, and each further drag stranded one more pane (BUG-167).+ *+ * So the end of a drag is detected by its ABSENCE instead. While a drag is+ * anywhere over the document the browser repeats `dragover` on its own — the+ * drag-and-drop processing model runs roughly every 350 ms whether or not the+ * cursor moves. That repetition is a heartbeat: when it stops, the drag is no+ * longer over this window, whatever the reason and whichever event went+ * missing. Nothing has to be delivered for this to work; something has to stop+ * being delivered, and that cannot be swallowed.+ *+ * The fast signals are kept alongside it so an ordinary drop still disarms in+ * the same frame rather than after the heartbeat times out.+ */+import { useEffect } from "react";++/**+ * How long the heartbeat may go quiet before the drag counts as over.+ *+ * The spec's own drag loop is ~350 ms, so this allows three missed beats. Short+ * enough that a stranded overlay clears before the user reaches for the mouse+ * again, long enough that a busy main thread cannot fake the end of a drag that+ * is still in flight.+ */+const DRAG_IDLE_MS = 1_200;++/** Everything currently waiting to hear that the drag ended. */+const watchers = new Set<() => void>();++let idleTimer: ReturnType<typeof setTimeout> | null = null;+let installed = false;++/** Tell every armed target the drag is over, once. */+function endSession(): void {+ if (idleTimer !== null) {+ clearTimeout(idleTimer);+ idleTimer = null;+ }+ // Copied first: a watcher's callback removes it from the set, and mutating a+ // Set while iterating it is how a second watcher gets skipped.+ for (const watcher of Array.from(watchers)) watcher();+}++/** A drag is still here. Restart the countdown. */+function heartbeat(): void {+ if (idleTimer !== null) clearTimeout(idleTimer);+ idleTimer = setTimeout(endSession, DRAG_IDLE_MS);+}++/**+ * The drag left the WINDOW, rather than merely moving between elements inside+ * it — a null `relatedTarget` with the cursor on the viewport edge. Kept for+ * the speed: the heartbeat would catch this a second later anyway.+ */+function onDragLeave(event: DragEvent): void {+ if (event.relatedTarget !== null) return;+ if (+ event.clientX <= 0 ||+ event.clientY <= 0 ||+ event.clientX >= window.innerWidth ||+ event.clientY >= window.innerHeight+ ) {+ endSession();+ }+}++/**+ * A key or a mouse button. Neither reaches the page while a drag is running, so+ * either one arriving proves there is no drag — which is what makes a stranded+ * overlay heal itself the moment the user touches the app again, instead of+ * waiting for them to perform another drag.+ */+function onRealInput(): void {+ endSession();+}++function install(): void {+ if (installed) return;+ installed = true;+ // Capture throughout: a handler somewhere in the tree calling+ // `stopPropagation()` on a drop must not be able to keep the end of the drag+ // from reaching the targets that are armed because of it.+ window.addEventListener("dragover", heartbeat, true);+ window.addEventListener("drop", endSession, true);+ window.addEventListener("dragend", endSession, true);+ window.addEventListener("dragleave", onDragLeave, true);+ window.addEventListener("pointerdown", onRealInput, true);+ window.addEventListener("keydown", onRealInput, true);+ heartbeat();+}++function uninstall(): void {+ if (!installed) return;+ installed = false;+ window.removeEventListener("dragover", heartbeat, true);+ window.removeEventListener("drop", endSession, true);+ window.removeEventListener("dragend", endSession, true);+ window.removeEventListener("dragleave", onDragLeave, true);+ window.removeEventListener("pointerdown", onRealInput, true);+ window.removeEventListener("keydown", onRealInput, true);+ if (idleTimer !== null) {+ clearTimeout(idleTimer);+ idleTimer = null;+ }+}++/**+ * Watch for the end of the current drag while `armed`, and disarm when it comes.+ *+ * `onEnd` is read through a ref-free closure on purpose: the effect re-runs when+ * it changes, and callers pass a `useCallback`-stable function. It may be called+ * for a drag this target never saw — disarming something already disarmed is+ * free, and it is the reason a target stranded by an earlier drag comes back.+ */+export function useDragSessionEnd(armed: boolean, onEnd: () => void): void {+ useEffect(() => {+ if (!armed) return;+ watchers.add(onEnd);+ install();+ return () => {+ watchers.delete(onEnd);+ if (watchers.size === 0) uninstall();+ };+ }, [armed, onEnd]);+}++/** Test seam: forget every watcher and unwire the window. */+export function resetDragSessionForTests(): void {+ watchers.clear();+ uninstall();+}diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneFileDrag.test.ts b/jarvis/ui/web/frontend/src/components/agentic/paneFileDrag.test.tsindex 5b5906e674..77e682ea51 100644--- a/jarvis/ui/web/frontend/src/components/agentic/paneFileDrag.test.ts+++ b/jarvis/ui/web/frontend/src/components/agentic/paneFileDrag.test.ts@@ -1,7 +1,13 @@import { act, renderHook } from "@testing-library/react";-import { describe, expect, it, vi } from "vitest";+import { afterEach, describe, expect, it, vi } from "vitest";import type { DragEvent as ReactDragEvent } from "react";import { usePaneFileDrag } from "./paneFileDrag";+import { resetDragSessionForTests } from "./dragSessionEnd";++afterEach(() => {+ resetDragSessionForTests();+ vi.useRealTimers();+});/** A drag event as React hands it to a handler. */function dragEvent(types: string[]) {@@ -151,4 +157,80 @@ describe("arming a terminal pane for a file drop", () => {expect(result.current.dragging).toBe(true);});++ it("disarms when the drag simply stops existing — no drop, no dragend, no leave", () => {+ /*+ * BUG-167, the shape that stranded panes for a whole session: a drag+ * released over ANOTHER application ends without sending this document a+ * single event. Nothing arrives to be handled, so the end of the drag is+ * read off the `dragover` heartbeat going quiet instead.+ */+ vi.useFakeTimers();+ const { result } = renderHook(() => usePaneFileDrag(vi.fn()));+ act(() => result.current.handlers.onDragEnter(dragEvent(["Files"])));++ // Still in flight: the browser keeps repeating dragover on its own.+ act(() => {+ vi.advanceTimersByTime(800);+ window.dispatchEvent(new Event("dragover"));+ vi.advanceTimersByTime(800);+ });+ expect(result.current.dragging).toBe(true);++ act(() => vi.advanceTimersByTime(1_500));++ expect(result.current.dragging).toBe(false);+ });++ it("heals on the next click when a drag stranded it", () => {+ // A pointer event cannot reach the page while a drag is running, so one+ // arriving is proof there is no drag — and the user reaching for the mouse+ // is exactly when a stranded overlay has to go.+ const { result } = renderHook(() => usePaneFileDrag(vi.fn()));+ act(() => result.current.handlers.onDragEnter(dragEvent(["Files"])));++ act(() => {+ window.dispatchEvent(new Event("pointerdown"));+ });++ expect(result.current.dragging).toBe(false);+ });++ it("does not carry a stale enter count into the next drag", () => {+ /*+ * The reason BUG-167 was permanent rather than momentary. A drag that+ * ended without its `dragleave` left the counter at 1, and every later+ * drag then needed one leave MORE than it fired — so the pane could never+ * come back down again. A fresh drag starts from zero.+ */+ const { result } = renderHook(() => usePaneFileDrag(vi.fn()));+ act(() => result.current.handlers.onDragEnter(dragEvent(["Files"])));+ act(() => {+ window.dispatchEvent(new Event("pointerdown")); // stranded, then healed+ });++ act(() => result.current.handlers.onDragEnter(dragEvent(["Files"])));+ act(() => result.current.handlers.onDragLeave(dragEvent(["Files"])));++ expect(result.current.dragging).toBe(false);+ });++ it("takes every armed pane down together", () => {+ // The grid arms one pane per pane the drag crosses. They cannot each rely+ // on their own leave arriving, so the end of the drag is one event for all+ // of them.+ const first = renderHook(() => usePaneFileDrag(vi.fn()));+ const second = renderHook(() => usePaneFileDrag(vi.fn()));+ act(() => {+ first.result.current.handlers.onDragEnter(dragEvent(["Files"]));+ second.result.current.handlers.onDragEnter(dragEvent(["Files"]));+ });++ act(() => {+ window.dispatchEvent(new Event("dragend"));+ });++ expect(first.result.current.dragging).toBe(false);+ expect(second.result.current.dragging).toBe(false);+ });});diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneFileDrag.ts b/jarvis/ui/web/frontend/src/components/agentic/paneFileDrag.tsindex 3c3c406158..5f9f80a610 100644--- a/jarvis/ui/web/frontend/src/components/agentic/paneFileDrag.ts+++ b/jarvis/ui/web/frontend/src/components/agentic/paneFileDrag.ts@@ -11,19 +11,21 @@* * **`dragleave` is not guaranteed to arrive.** Release the drag over another* element, drop it outside the window, or cancel with Escape and the pane* that armed never hears the end of it — the overlay then sits over a live- * agent until the next drag happens to balance the books.+ * agent, and the counter below is left non-zero, so no LATER drag can bring+ * it down either: that pane stays armed for the rest of the session and each+ * further drag strands one more (BUG-167).*- * So the arming is gated on the payload, and the disarming has a window-level- * backstop that does not depend on a matching leave ever being delivered.+ * So the arming is gated on the payload, and the disarming does not depend on+ * any particular event arriving — see ./dragSessionEnd.*/import {useCallback,- useEffect,useRef,useState,type DragEvent as ReactDragEvent,} from "react";import { dragCarriesFiles } from "./paneDrop";+import { useDragSessionEnd } from "./dragSessionEnd";export interface PaneFileDragHandlers {onDragEnter: (e: ReactDragEvent) => void;@@ -58,33 +60,11 @@ export function usePaneFileDrag(setDragging(false);}, []);- // The backstop. A drag that ends anywhere other than on this pane owes it no- // `dragleave`, so the end of the drag is watched globally instead — and only- // while armed, which is the only time there is anything to take down.- useEffect(() => {- if (!dragging) return;- const onWindowDragLeave = (e: DragEvent) => {- // `relatedTarget === null` plus a cursor at the viewport edge means the- // drag left the WINDOW, not merely moved between elements inside it.- if (- e.relatedTarget === null &&- (e.clientX <= 0 ||- e.clientY <= 0 ||- e.clientX >= window.innerWidth ||- e.clientY >= window.innerHeight)- ) {- disarm();- }- };- window.addEventListener("drop", disarm);- window.addEventListener("dragend", disarm);- window.addEventListener("dragleave", onWindowDragLeave);- return () => {- window.removeEventListener("drop", disarm);- window.removeEventListener("dragend", disarm);- window.removeEventListener("dragleave", onWindowDragLeave);- };- }, [dragging, disarm]);+ // The backstop, and the only thing this pane can actually rely on: a drag+ // that ends anywhere other than on this pane owes it no `dragleave`, and a+ // drag out of Explorer owes the page no `dragend` either. Watched while+ // armed, which is the only time there is anything to take down.+ useDragSessionEnd(dragging, disarm);const handlers: PaneFileDragHandlers = {onDragEnter: (e) => {@@ -93,6 +73,12 @@ export function usePaneFileDrag(// whole IDE — every agent in the grid with it.e.preventDefault();if (!dragCarriesFiles(e.dataTransfer)) return;+ // No reset needed here, and deliberately not attempted: `dragging` has+ // not flipped yet inside the batch that crossed into a child, so a reset+ // read off it would zero the count mid-drag. What keeps the counter from+ // outliving a drag is that `disarm` zeroes it and now always runs — a+ // count that could only ever be wrong upwards is what made BUG-167+ // permanent rather than momentary.depth.current += 1;setDragging(true);},